]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9.1-3.6.6-201211051957.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.6.6-201211051957.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 471b83c..a290aa2 100644
255 --- a/Makefile
256 +++ b/Makefile
257 @@ -241,8 +241,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
258
259 HOSTCC = gcc
260 HOSTCXX = g++
261 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
262 -HOSTCXXFLAGS = -O2
263 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
264 +HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
265 +HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
266
267 # Decide whether to build built-in, modular, or both.
268 # Normally, just do built-in.
269 @@ -404,8 +405,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
270 # Rules shared between *config targets and build targets
271
272 # Basic helpers built in scripts/
273 -PHONY += scripts_basic
274 -scripts_basic:
275 +PHONY += scripts_basic gcc-plugins
276 +scripts_basic: gcc-plugins
277 $(Q)$(MAKE) $(build)=scripts/basic
278 $(Q)rm -f .tmp_quiet_recordmcount
279
280 @@ -561,6 +562,60 @@ else
281 KBUILD_CFLAGS += -O2
282 endif
283
284 +ifndef DISABLE_PAX_PLUGINS
285 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
286 +ifneq ($(PLUGINCC),)
287 +ifndef DISABLE_PAX_CONSTIFY_PLUGIN
288 +ifndef CONFIG_UML
289 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
290 +endif
291 +endif
292 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
293 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
294 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
295 +endif
296 +ifdef CONFIG_KALLOCSTAT_PLUGIN
297 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
298 +endif
299 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
300 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
301 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
302 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
303 +endif
304 +ifdef CONFIG_CHECKER_PLUGIN
305 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
306 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
307 +endif
308 +endif
309 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
310 +ifdef CONFIG_PAX_SIZE_OVERFLOW
311 +SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
312 +endif
313 +ifdef CONFIG_PAX_LATENT_ENTROPY
314 +LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
315 +endif
316 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
317 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
318 +GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS)
319 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
320 +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
321 +ifeq ($(KBUILD_EXTMOD),)
322 +gcc-plugins:
323 + $(Q)$(MAKE) $(build)=tools/gcc
324 +else
325 +gcc-plugins: ;
326 +endif
327 +else
328 +gcc-plugins:
329 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
330 + $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
331 +else
332 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
333 +endif
334 + $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
335 +endif
336 +endif
337 +
338 include $(srctree)/arch/$(SRCARCH)/Makefile
339
340 ifdef CONFIG_READABLE_ASM
341 @@ -715,7 +770,7 @@ export mod_strip_cmd
342
343
344 ifeq ($(KBUILD_EXTMOD),)
345 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
346 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
347
348 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
349 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
350 @@ -762,6 +817,8 @@ endif
351
352 # The actual objects are generated when descending,
353 # make sure no implicit rule kicks in
354 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
355 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
356 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
357
358 # Handle descending into subdirectories listed in $(vmlinux-dirs)
359 @@ -771,7 +828,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
360 # Error messages still appears in the original language
361
362 PHONY += $(vmlinux-dirs)
363 -$(vmlinux-dirs): prepare scripts
364 +$(vmlinux-dirs): gcc-plugins prepare scripts
365 $(Q)$(MAKE) $(build)=$@
366
367 # Store (new) KERNELRELASE string in include/config/kernel.release
368 @@ -815,6 +872,7 @@ prepare0: archprepare FORCE
369 $(Q)$(MAKE) $(build)=.
370
371 # All the preparing..
372 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
373 prepare: prepare0
374
375 # Generate some files
376 @@ -922,6 +980,8 @@ all: modules
377 # using awk while concatenating to the final file.
378
379 PHONY += modules
380 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
381 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
382 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
383 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
384 @$(kecho) ' Building modules, stage 2.';
385 @@ -937,7 +997,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
386
387 # Target to prepare building external modules
388 PHONY += modules_prepare
389 -modules_prepare: prepare scripts
390 +modules_prepare: gcc-plugins prepare scripts
391
392 # Target to install modules
393 PHONY += modules_install
394 @@ -994,7 +1054,7 @@ CLEAN_DIRS += $(MODVERDIR)
395 MRPROPER_DIRS += include/config usr/include include/generated \
396 arch/*/include/generated
397 MRPROPER_FILES += .config .config.old .version .old_version \
398 - include/linux/version.h \
399 + include/linux/version.h tools/gcc/size_overflow_hash.h\
400 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS
401
402 # clean - Delete most, but leave enough to build external modules
403 @@ -1032,6 +1092,7 @@ distclean: mrproper
404 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
405 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
406 -o -name '.*.rej' \
407 + -o -name '.*.rej' -o -name '*.so' \
408 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
409 -type f -print | xargs rm -f
410
411 @@ -1192,6 +1253,8 @@ PHONY += $(module-dirs) modules
412 $(module-dirs): crmodverdir $(objtree)/Module.symvers
413 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
414
415 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
416 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
417 modules: $(module-dirs)
418 @$(kecho) ' Building modules, stage 2.';
419 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
420 @@ -1326,17 +1389,21 @@ else
421 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
422 endif
423
424 -%.s: %.c prepare scripts FORCE
425 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
426 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
427 +%.s: %.c gcc-plugins prepare scripts FORCE
428 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
429 %.i: %.c prepare scripts FORCE
430 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
431 -%.o: %.c prepare scripts FORCE
432 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
433 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
434 +%.o: %.c gcc-plugins prepare scripts FORCE
435 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
436 %.lst: %.c prepare scripts FORCE
437 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
438 -%.s: %.S prepare scripts FORCE
439 +%.s: %.S gcc-plugins prepare scripts FORCE
440 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
441 -%.o: %.S prepare scripts FORCE
442 +%.o: %.S gcc-plugins prepare scripts FORCE
443 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
444 %.symtypes: %.c prepare scripts FORCE
445 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
446 @@ -1346,11 +1413,15 @@ endif
447 $(cmd_crmodverdir)
448 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
449 $(build)=$(build-dir)
450 -%/: prepare scripts FORCE
451 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
452 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
453 +%/: gcc-plugins prepare scripts FORCE
454 $(cmd_crmodverdir)
455 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
456 $(build)=$(build-dir)
457 -%.ko: prepare scripts FORCE
458 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
459 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
460 +%.ko: gcc-plugins prepare scripts FORCE
461 $(cmd_crmodverdir)
462 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
463 $(build)=$(build-dir) $(@:.ko=.o)
464 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
465 index c2cbe4f..f7264b4 100644
466 --- a/arch/alpha/include/asm/atomic.h
467 +++ b/arch/alpha/include/asm/atomic.h
468 @@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
469 #define atomic_dec(v) atomic_sub(1,(v))
470 #define atomic64_dec(v) atomic64_sub(1,(v))
471
472 +#define atomic64_read_unchecked(v) atomic64_read(v)
473 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
474 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
475 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
476 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
477 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
478 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
479 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
480 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
481 +
482 #define smp_mb__before_atomic_dec() smp_mb()
483 #define smp_mb__after_atomic_dec() smp_mb()
484 #define smp_mb__before_atomic_inc() smp_mb()
485 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
486 index ad368a9..fbe0f25 100644
487 --- a/arch/alpha/include/asm/cache.h
488 +++ b/arch/alpha/include/asm/cache.h
489 @@ -4,19 +4,19 @@
490 #ifndef __ARCH_ALPHA_CACHE_H
491 #define __ARCH_ALPHA_CACHE_H
492
493 +#include <linux/const.h>
494
495 /* Bytes per L1 (data) cache line. */
496 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
497 -# define L1_CACHE_BYTES 64
498 # define L1_CACHE_SHIFT 6
499 #else
500 /* Both EV4 and EV5 are write-through, read-allocate,
501 direct-mapped, physical.
502 */
503 -# define L1_CACHE_BYTES 32
504 # define L1_CACHE_SHIFT 5
505 #endif
506
507 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
508 #define SMP_CACHE_BYTES L1_CACHE_BYTES
509
510 #endif
511 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
512 index 968d999..d36b2df 100644
513 --- a/arch/alpha/include/asm/elf.h
514 +++ b/arch/alpha/include/asm/elf.h
515 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
516
517 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
518
519 +#ifdef CONFIG_PAX_ASLR
520 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
521 +
522 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
523 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
524 +#endif
525 +
526 /* $0 is set by ld.so to a pointer to a function which might be
527 registered using atexit. This provides a mean for the dynamic
528 linker to call DT_FINI functions for shared libraries that have
529 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
530 index bc2a0da..8ad11ee 100644
531 --- a/arch/alpha/include/asm/pgalloc.h
532 +++ b/arch/alpha/include/asm/pgalloc.h
533 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
534 pgd_set(pgd, pmd);
535 }
536
537 +static inline void
538 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
539 +{
540 + pgd_populate(mm, pgd, pmd);
541 +}
542 +
543 extern pgd_t *pgd_alloc(struct mm_struct *mm);
544
545 static inline void
546 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
547 index 81a4342..348b927 100644
548 --- a/arch/alpha/include/asm/pgtable.h
549 +++ b/arch/alpha/include/asm/pgtable.h
550 @@ -102,6 +102,17 @@ struct vm_area_struct;
551 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
552 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
553 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
554 +
555 +#ifdef CONFIG_PAX_PAGEEXEC
556 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
557 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
558 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
559 +#else
560 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
561 +# define PAGE_COPY_NOEXEC PAGE_COPY
562 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
563 +#endif
564 +
565 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
566
567 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
568 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
569 index 2fd00b7..cfd5069 100644
570 --- a/arch/alpha/kernel/module.c
571 +++ b/arch/alpha/kernel/module.c
572 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
573
574 /* The small sections were sorted to the end of the segment.
575 The following should definitely cover them. */
576 - gp = (u64)me->module_core + me->core_size - 0x8000;
577 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
578 got = sechdrs[me->arch.gotsecindex].sh_addr;
579
580 for (i = 0; i < n; i++) {
581 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
582 index bc1acdd..a922a6d 100644
583 --- a/arch/alpha/kernel/osf_sys.c
584 +++ b/arch/alpha/kernel/osf_sys.c
585 @@ -1312,7 +1312,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
586 /* At this point: (!vma || addr < vma->vm_end). */
587 if (limit - len < addr)
588 return -ENOMEM;
589 - if (!vma || addr + len <= vma->vm_start)
590 + if (check_heap_stack_gap(vma, addr, len))
591 return addr;
592 addr = vma->vm_end;
593 vma = vma->vm_next;
594 @@ -1348,6 +1348,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
595 merely specific addresses, but regions of memory -- perhaps
596 this feature should be incorporated into all ports? */
597
598 +#ifdef CONFIG_PAX_RANDMMAP
599 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
600 +#endif
601 +
602 if (addr) {
603 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
604 if (addr != (unsigned long) -ENOMEM)
605 @@ -1355,8 +1359,8 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
606 }
607
608 /* Next, try allocating at TASK_UNMAPPED_BASE. */
609 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
610 - len, limit);
611 + addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
612 +
613 if (addr != (unsigned long) -ENOMEM)
614 return addr;
615
616 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
617 index 0c4132d..88f0d53 100644
618 --- a/arch/alpha/mm/fault.c
619 +++ b/arch/alpha/mm/fault.c
620 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
621 __reload_thread(pcb);
622 }
623
624 +#ifdef CONFIG_PAX_PAGEEXEC
625 +/*
626 + * PaX: decide what to do with offenders (regs->pc = fault address)
627 + *
628 + * returns 1 when task should be killed
629 + * 2 when patched PLT trampoline was detected
630 + * 3 when unpatched PLT trampoline was detected
631 + */
632 +static int pax_handle_fetch_fault(struct pt_regs *regs)
633 +{
634 +
635 +#ifdef CONFIG_PAX_EMUPLT
636 + int err;
637 +
638 + do { /* PaX: patched PLT emulation #1 */
639 + unsigned int ldah, ldq, jmp;
640 +
641 + err = get_user(ldah, (unsigned int *)regs->pc);
642 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
643 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
644 +
645 + if (err)
646 + break;
647 +
648 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
649 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
650 + jmp == 0x6BFB0000U)
651 + {
652 + unsigned long r27, addr;
653 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
654 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
655 +
656 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
657 + err = get_user(r27, (unsigned long *)addr);
658 + if (err)
659 + break;
660 +
661 + regs->r27 = r27;
662 + regs->pc = r27;
663 + return 2;
664 + }
665 + } while (0);
666 +
667 + do { /* PaX: patched PLT emulation #2 */
668 + unsigned int ldah, lda, br;
669 +
670 + err = get_user(ldah, (unsigned int *)regs->pc);
671 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
672 + err |= get_user(br, (unsigned int *)(regs->pc+8));
673 +
674 + if (err)
675 + break;
676 +
677 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
678 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
679 + (br & 0xFFE00000U) == 0xC3E00000U)
680 + {
681 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
682 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
683 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
684 +
685 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
686 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
687 + return 2;
688 + }
689 + } while (0);
690 +
691 + do { /* PaX: unpatched PLT emulation */
692 + unsigned int br;
693 +
694 + err = get_user(br, (unsigned int *)regs->pc);
695 +
696 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
697 + unsigned int br2, ldq, nop, jmp;
698 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
699 +
700 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
701 + err = get_user(br2, (unsigned int *)addr);
702 + err |= get_user(ldq, (unsigned int *)(addr+4));
703 + err |= get_user(nop, (unsigned int *)(addr+8));
704 + err |= get_user(jmp, (unsigned int *)(addr+12));
705 + err |= get_user(resolver, (unsigned long *)(addr+16));
706 +
707 + if (err)
708 + break;
709 +
710 + if (br2 == 0xC3600000U &&
711 + ldq == 0xA77B000CU &&
712 + nop == 0x47FF041FU &&
713 + jmp == 0x6B7B0000U)
714 + {
715 + regs->r28 = regs->pc+4;
716 + regs->r27 = addr+16;
717 + regs->pc = resolver;
718 + return 3;
719 + }
720 + }
721 + } while (0);
722 +#endif
723 +
724 + return 1;
725 +}
726 +
727 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
728 +{
729 + unsigned long i;
730 +
731 + printk(KERN_ERR "PAX: bytes at PC: ");
732 + for (i = 0; i < 5; i++) {
733 + unsigned int c;
734 + if (get_user(c, (unsigned int *)pc+i))
735 + printk(KERN_CONT "???????? ");
736 + else
737 + printk(KERN_CONT "%08x ", c);
738 + }
739 + printk("\n");
740 +}
741 +#endif
742
743 /*
744 * This routine handles page faults. It determines the address,
745 @@ -133,8 +251,29 @@ retry:
746 good_area:
747 si_code = SEGV_ACCERR;
748 if (cause < 0) {
749 - if (!(vma->vm_flags & VM_EXEC))
750 + if (!(vma->vm_flags & VM_EXEC)) {
751 +
752 +#ifdef CONFIG_PAX_PAGEEXEC
753 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
754 + goto bad_area;
755 +
756 + up_read(&mm->mmap_sem);
757 + switch (pax_handle_fetch_fault(regs)) {
758 +
759 +#ifdef CONFIG_PAX_EMUPLT
760 + case 2:
761 + case 3:
762 + return;
763 +#endif
764 +
765 + }
766 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
767 + do_group_exit(SIGKILL);
768 +#else
769 goto bad_area;
770 +#endif
771 +
772 + }
773 } else if (!cause) {
774 /* Allow reads even for write-only mappings */
775 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
776 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
777 index c79f61f..9ac0642 100644
778 --- a/arch/arm/include/asm/atomic.h
779 +++ b/arch/arm/include/asm/atomic.h
780 @@ -17,17 +17,35 @@
781 #include <asm/barrier.h>
782 #include <asm/cmpxchg.h>
783
784 +#ifdef CONFIG_GENERIC_ATOMIC64
785 +#include <asm-generic/atomic64.h>
786 +#endif
787 +
788 #define ATOMIC_INIT(i) { (i) }
789
790 #ifdef __KERNEL__
791
792 +#define _ASM_EXTABLE(from, to) \
793 +" .pushsection __ex_table,\"a\"\n"\
794 +" .align 3\n" \
795 +" .long " #from ", " #to"\n" \
796 +" .popsection"
797 +
798 /*
799 * On ARM, ordinary assignment (str instruction) doesn't clear the local
800 * strex/ldrex monitor on some implementations. The reason we can use it for
801 * atomic_set() is the clrex or dummy strex done on every exception return.
802 */
803 #define atomic_read(v) (*(volatile int *)&(v)->counter)
804 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
805 +{
806 + return v->counter;
807 +}
808 #define atomic_set(v,i) (((v)->counter) = (i))
809 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
810 +{
811 + v->counter = i;
812 +}
813
814 #if __LINUX_ARM_ARCH__ >= 6
815
816 @@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
817 int result;
818
819 __asm__ __volatile__("@ atomic_add\n"
820 +"1: ldrex %1, [%3]\n"
821 +" adds %0, %1, %4\n"
822 +
823 +#ifdef CONFIG_PAX_REFCOUNT
824 +" bvc 3f\n"
825 +"2: bkpt 0xf103\n"
826 +"3:\n"
827 +#endif
828 +
829 +" strex %1, %0, [%3]\n"
830 +" teq %1, #0\n"
831 +" bne 1b"
832 +
833 +#ifdef CONFIG_PAX_REFCOUNT
834 +"\n4:\n"
835 + _ASM_EXTABLE(2b, 4b)
836 +#endif
837 +
838 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
839 + : "r" (&v->counter), "Ir" (i)
840 + : "cc");
841 +}
842 +
843 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
844 +{
845 + unsigned long tmp;
846 + int result;
847 +
848 + __asm__ __volatile__("@ atomic_add_unchecked\n"
849 "1: ldrex %0, [%3]\n"
850 " add %0, %0, %4\n"
851 " strex %1, %0, [%3]\n"
852 @@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
853 smp_mb();
854
855 __asm__ __volatile__("@ atomic_add_return\n"
856 +"1: ldrex %1, [%3]\n"
857 +" adds %0, %1, %4\n"
858 +
859 +#ifdef CONFIG_PAX_REFCOUNT
860 +" bvc 3f\n"
861 +" mov %0, %1\n"
862 +"2: bkpt 0xf103\n"
863 +"3:\n"
864 +#endif
865 +
866 +" strex %1, %0, [%3]\n"
867 +" teq %1, #0\n"
868 +" bne 1b"
869 +
870 +#ifdef CONFIG_PAX_REFCOUNT
871 +"\n4:\n"
872 + _ASM_EXTABLE(2b, 4b)
873 +#endif
874 +
875 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
876 + : "r" (&v->counter), "Ir" (i)
877 + : "cc");
878 +
879 + smp_mb();
880 +
881 + return result;
882 +}
883 +
884 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
885 +{
886 + unsigned long tmp;
887 + int result;
888 +
889 + smp_mb();
890 +
891 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
892 "1: ldrex %0, [%3]\n"
893 " add %0, %0, %4\n"
894 " strex %1, %0, [%3]\n"
895 @@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
896 int result;
897
898 __asm__ __volatile__("@ atomic_sub\n"
899 +"1: ldrex %1, [%3]\n"
900 +" subs %0, %1, %4\n"
901 +
902 +#ifdef CONFIG_PAX_REFCOUNT
903 +" bvc 3f\n"
904 +"2: bkpt 0xf103\n"
905 +"3:\n"
906 +#endif
907 +
908 +" strex %1, %0, [%3]\n"
909 +" teq %1, #0\n"
910 +" bne 1b"
911 +
912 +#ifdef CONFIG_PAX_REFCOUNT
913 +"\n4:\n"
914 + _ASM_EXTABLE(2b, 4b)
915 +#endif
916 +
917 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
918 + : "r" (&v->counter), "Ir" (i)
919 + : "cc");
920 +}
921 +
922 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
923 +{
924 + unsigned long tmp;
925 + int result;
926 +
927 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
928 "1: ldrex %0, [%3]\n"
929 " sub %0, %0, %4\n"
930 " strex %1, %0, [%3]\n"
931 @@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
932 smp_mb();
933
934 __asm__ __volatile__("@ atomic_sub_return\n"
935 -"1: ldrex %0, [%3]\n"
936 -" sub %0, %0, %4\n"
937 +"1: ldrex %1, [%3]\n"
938 +" subs %0, %1, %4\n"
939 +
940 +#ifdef CONFIG_PAX_REFCOUNT
941 +" bvc 3f\n"
942 +" mov %0, %1\n"
943 +"2: bkpt 0xf103\n"
944 +"3:\n"
945 +#endif
946 +
947 " strex %1, %0, [%3]\n"
948 " teq %1, #0\n"
949 " bne 1b"
950 +
951 +#ifdef CONFIG_PAX_REFCOUNT
952 +"\n4:\n"
953 + _ASM_EXTABLE(2b, 4b)
954 +#endif
955 +
956 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
957 : "r" (&v->counter), "Ir" (i)
958 : "cc");
959 @@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
960 return oldval;
961 }
962
963 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
964 +{
965 + unsigned long oldval, res;
966 +
967 + smp_mb();
968 +
969 + do {
970 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
971 + "ldrex %1, [%3]\n"
972 + "mov %0, #0\n"
973 + "teq %1, %4\n"
974 + "strexeq %0, %5, [%3]\n"
975 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
976 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
977 + : "cc");
978 + } while (res);
979 +
980 + smp_mb();
981 +
982 + return oldval;
983 +}
984 +
985 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
986 {
987 unsigned long tmp, tmp2;
988 @@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
989
990 return val;
991 }
992 +
993 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
994 +{
995 + return atomic_add_return(i, v);
996 +}
997 +
998 #define atomic_add(i, v) (void) atomic_add_return(i, v)
999 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1000 +{
1001 + (void) atomic_add_return(i, v);
1002 +}
1003
1004 static inline int atomic_sub_return(int i, atomic_t *v)
1005 {
1006 @@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1007 return val;
1008 }
1009 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1010 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1011 +{
1012 + (void) atomic_sub_return(i, v);
1013 +}
1014
1015 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1016 {
1017 @@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1018 return ret;
1019 }
1020
1021 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1022 +{
1023 + return atomic_cmpxchg(v, old, new);
1024 +}
1025 +
1026 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1027 {
1028 unsigned long flags;
1029 @@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1030 #endif /* __LINUX_ARM_ARCH__ */
1031
1032 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1033 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1034 +{
1035 + return xchg(&v->counter, new);
1036 +}
1037
1038 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1039 {
1040 @@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1041 }
1042
1043 #define atomic_inc(v) atomic_add(1, v)
1044 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1045 +{
1046 + atomic_add_unchecked(1, v);
1047 +}
1048 #define atomic_dec(v) atomic_sub(1, v)
1049 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1050 +{
1051 + atomic_sub_unchecked(1, v);
1052 +}
1053
1054 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1055 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1056 +{
1057 + return atomic_add_return_unchecked(1, v) == 0;
1058 +}
1059 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1060 #define atomic_inc_return(v) (atomic_add_return(1, v))
1061 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1062 +{
1063 + return atomic_add_return_unchecked(1, v);
1064 +}
1065 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1066 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1067
1068 @@ -241,6 +428,14 @@ typedef struct {
1069 u64 __aligned(8) counter;
1070 } atomic64_t;
1071
1072 +#ifdef CONFIG_PAX_REFCOUNT
1073 +typedef struct {
1074 + u64 __aligned(8) counter;
1075 +} atomic64_unchecked_t;
1076 +#else
1077 +typedef atomic64_t atomic64_unchecked_t;
1078 +#endif
1079 +
1080 #define ATOMIC64_INIT(i) { (i) }
1081
1082 static inline u64 atomic64_read(const atomic64_t *v)
1083 @@ -256,6 +451,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1084 return result;
1085 }
1086
1087 +static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1088 +{
1089 + u64 result;
1090 +
1091 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1092 +" ldrexd %0, %H0, [%1]"
1093 + : "=&r" (result)
1094 + : "r" (&v->counter), "Qo" (v->counter)
1095 + );
1096 +
1097 + return result;
1098 +}
1099 +
1100 static inline void atomic64_set(atomic64_t *v, u64 i)
1101 {
1102 u64 tmp;
1103 @@ -270,6 +478,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1104 : "cc");
1105 }
1106
1107 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1108 +{
1109 + u64 tmp;
1110 +
1111 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1112 +"1: ldrexd %0, %H0, [%2]\n"
1113 +" strexd %0, %3, %H3, [%2]\n"
1114 +" teq %0, #0\n"
1115 +" bne 1b"
1116 + : "=&r" (tmp), "=Qo" (v->counter)
1117 + : "r" (&v->counter), "r" (i)
1118 + : "cc");
1119 +}
1120 +
1121 static inline void atomic64_add(u64 i, atomic64_t *v)
1122 {
1123 u64 result;
1124 @@ -278,6 +500,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1125 __asm__ __volatile__("@ atomic64_add\n"
1126 "1: ldrexd %0, %H0, [%3]\n"
1127 " adds %0, %0, %4\n"
1128 +" adcs %H0, %H0, %H4\n"
1129 +
1130 +#ifdef CONFIG_PAX_REFCOUNT
1131 +" bvc 3f\n"
1132 +"2: bkpt 0xf103\n"
1133 +"3:\n"
1134 +#endif
1135 +
1136 +" strexd %1, %0, %H0, [%3]\n"
1137 +" teq %1, #0\n"
1138 +" bne 1b"
1139 +
1140 +#ifdef CONFIG_PAX_REFCOUNT
1141 +"\n4:\n"
1142 + _ASM_EXTABLE(2b, 4b)
1143 +#endif
1144 +
1145 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1146 + : "r" (&v->counter), "r" (i)
1147 + : "cc");
1148 +}
1149 +
1150 +static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1151 +{
1152 + u64 result;
1153 + unsigned long tmp;
1154 +
1155 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1156 +"1: ldrexd %0, %H0, [%3]\n"
1157 +" adds %0, %0, %4\n"
1158 " adc %H0, %H0, %H4\n"
1159 " strexd %1, %0, %H0, [%3]\n"
1160 " teq %1, #0\n"
1161 @@ -289,12 +541,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1162
1163 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1164 {
1165 - u64 result;
1166 - unsigned long tmp;
1167 + u64 result, tmp;
1168
1169 smp_mb();
1170
1171 __asm__ __volatile__("@ atomic64_add_return\n"
1172 +"1: ldrexd %1, %H1, [%3]\n"
1173 +" adds %0, %1, %4\n"
1174 +" adcs %H0, %H1, %H4\n"
1175 +
1176 +#ifdef CONFIG_PAX_REFCOUNT
1177 +" bvc 3f\n"
1178 +" mov %0, %1\n"
1179 +" mov %H0, %H1\n"
1180 +"2: bkpt 0xf103\n"
1181 +"3:\n"
1182 +#endif
1183 +
1184 +" strexd %1, %0, %H0, [%3]\n"
1185 +" teq %1, #0\n"
1186 +" bne 1b"
1187 +
1188 +#ifdef CONFIG_PAX_REFCOUNT
1189 +"\n4:\n"
1190 + _ASM_EXTABLE(2b, 4b)
1191 +#endif
1192 +
1193 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1194 + : "r" (&v->counter), "r" (i)
1195 + : "cc");
1196 +
1197 + smp_mb();
1198 +
1199 + return result;
1200 +}
1201 +
1202 +static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1203 +{
1204 + u64 result;
1205 + unsigned long tmp;
1206 +
1207 + smp_mb();
1208 +
1209 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1210 "1: ldrexd %0, %H0, [%3]\n"
1211 " adds %0, %0, %4\n"
1212 " adc %H0, %H0, %H4\n"
1213 @@ -318,6 +607,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1214 __asm__ __volatile__("@ atomic64_sub\n"
1215 "1: ldrexd %0, %H0, [%3]\n"
1216 " subs %0, %0, %4\n"
1217 +" sbcs %H0, %H0, %H4\n"
1218 +
1219 +#ifdef CONFIG_PAX_REFCOUNT
1220 +" bvc 3f\n"
1221 +"2: bkpt 0xf103\n"
1222 +"3:\n"
1223 +#endif
1224 +
1225 +" strexd %1, %0, %H0, [%3]\n"
1226 +" teq %1, #0\n"
1227 +" bne 1b"
1228 +
1229 +#ifdef CONFIG_PAX_REFCOUNT
1230 +"\n4:\n"
1231 + _ASM_EXTABLE(2b, 4b)
1232 +#endif
1233 +
1234 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1235 + : "r" (&v->counter), "r" (i)
1236 + : "cc");
1237 +}
1238 +
1239 +static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1240 +{
1241 + u64 result;
1242 + unsigned long tmp;
1243 +
1244 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1245 +"1: ldrexd %0, %H0, [%3]\n"
1246 +" subs %0, %0, %4\n"
1247 " sbc %H0, %H0, %H4\n"
1248 " strexd %1, %0, %H0, [%3]\n"
1249 " teq %1, #0\n"
1250 @@ -329,18 +648,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1251
1252 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1253 {
1254 - u64 result;
1255 - unsigned long tmp;
1256 + u64 result, tmp;
1257
1258 smp_mb();
1259
1260 __asm__ __volatile__("@ atomic64_sub_return\n"
1261 -"1: ldrexd %0, %H0, [%3]\n"
1262 -" subs %0, %0, %4\n"
1263 -" sbc %H0, %H0, %H4\n"
1264 +"1: ldrexd %1, %H1, [%3]\n"
1265 +" subs %0, %1, %4\n"
1266 +" sbcs %H0, %H1, %H4\n"
1267 +
1268 +#ifdef CONFIG_PAX_REFCOUNT
1269 +" bvc 3f\n"
1270 +" mov %0, %1\n"
1271 +" mov %H0, %H1\n"
1272 +"2: bkpt 0xf103\n"
1273 +"3:\n"
1274 +#endif
1275 +
1276 " strexd %1, %0, %H0, [%3]\n"
1277 " teq %1, #0\n"
1278 " bne 1b"
1279 +
1280 +#ifdef CONFIG_PAX_REFCOUNT
1281 +"\n4:\n"
1282 + _ASM_EXTABLE(2b, 4b)
1283 +#endif
1284 +
1285 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1286 : "r" (&v->counter), "r" (i)
1287 : "cc");
1288 @@ -374,6 +707,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1289 return oldval;
1290 }
1291
1292 +static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1293 +{
1294 + u64 oldval;
1295 + unsigned long res;
1296 +
1297 + smp_mb();
1298 +
1299 + do {
1300 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1301 + "ldrexd %1, %H1, [%3]\n"
1302 + "mov %0, #0\n"
1303 + "teq %1, %4\n"
1304 + "teqeq %H1, %H4\n"
1305 + "strexdeq %0, %5, %H5, [%3]"
1306 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1307 + : "r" (&ptr->counter), "r" (old), "r" (new)
1308 + : "cc");
1309 + } while (res);
1310 +
1311 + smp_mb();
1312 +
1313 + return oldval;
1314 +}
1315 +
1316 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1317 {
1318 u64 result;
1319 @@ -397,21 +754,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1320
1321 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1322 {
1323 - u64 result;
1324 - unsigned long tmp;
1325 + u64 result, tmp;
1326
1327 smp_mb();
1328
1329 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1330 -"1: ldrexd %0, %H0, [%3]\n"
1331 -" subs %0, %0, #1\n"
1332 -" sbc %H0, %H0, #0\n"
1333 +"1: ldrexd %1, %H1, [%3]\n"
1334 +" subs %0, %1, #1\n"
1335 +" sbcs %H0, %H1, #0\n"
1336 +
1337 +#ifdef CONFIG_PAX_REFCOUNT
1338 +" bvc 3f\n"
1339 +" mov %0, %1\n"
1340 +" mov %H0, %H1\n"
1341 +"2: bkpt 0xf103\n"
1342 +"3:\n"
1343 +#endif
1344 +
1345 " teq %H0, #0\n"
1346 -" bmi 2f\n"
1347 +" bmi 4f\n"
1348 " strexd %1, %0, %H0, [%3]\n"
1349 " teq %1, #0\n"
1350 " bne 1b\n"
1351 -"2:"
1352 +"4:\n"
1353 +
1354 +#ifdef CONFIG_PAX_REFCOUNT
1355 + _ASM_EXTABLE(2b, 4b)
1356 +#endif
1357 +
1358 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1359 : "r" (&v->counter)
1360 : "cc");
1361 @@ -434,13 +804,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1362 " teq %0, %5\n"
1363 " teqeq %H0, %H5\n"
1364 " moveq %1, #0\n"
1365 -" beq 2f\n"
1366 +" beq 4f\n"
1367 " adds %0, %0, %6\n"
1368 -" adc %H0, %H0, %H6\n"
1369 +" adcs %H0, %H0, %H6\n"
1370 +
1371 +#ifdef CONFIG_PAX_REFCOUNT
1372 +" bvc 3f\n"
1373 +"2: bkpt 0xf103\n"
1374 +"3:\n"
1375 +#endif
1376 +
1377 " strexd %2, %0, %H0, [%4]\n"
1378 " teq %2, #0\n"
1379 " bne 1b\n"
1380 -"2:"
1381 +"4:\n"
1382 +
1383 +#ifdef CONFIG_PAX_REFCOUNT
1384 + _ASM_EXTABLE(2b, 4b)
1385 +#endif
1386 +
1387 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1388 : "r" (&v->counter), "r" (u), "r" (a)
1389 : "cc");
1390 @@ -453,10 +835,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1391
1392 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1393 #define atomic64_inc(v) atomic64_add(1LL, (v))
1394 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1395 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1396 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1397 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1398 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1399 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1400 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1401 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1402 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1403 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1404 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1405 index 75fe66b..2255c86 100644
1406 --- a/arch/arm/include/asm/cache.h
1407 +++ b/arch/arm/include/asm/cache.h
1408 @@ -4,8 +4,10 @@
1409 #ifndef __ASMARM_CACHE_H
1410 #define __ASMARM_CACHE_H
1411
1412 +#include <linux/const.h>
1413 +
1414 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1415 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1416 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1417
1418 /*
1419 * Memory returned by kmalloc() may be used for DMA, so we must make
1420 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1421 index e4448e1..7bc86b7 100644
1422 --- a/arch/arm/include/asm/cacheflush.h
1423 +++ b/arch/arm/include/asm/cacheflush.h
1424 @@ -108,7 +108,7 @@ struct cpu_cache_fns {
1425 void (*dma_unmap_area)(const void *, size_t, int);
1426
1427 void (*dma_flush_range)(const void *, const void *);
1428 -};
1429 +} __no_const;
1430
1431 /*
1432 * Select the calling method
1433 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1434 index 7eb18c1..e38b6d2 100644
1435 --- a/arch/arm/include/asm/cmpxchg.h
1436 +++ b/arch/arm/include/asm/cmpxchg.h
1437 @@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1438
1439 #define xchg(ptr,x) \
1440 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1441 +#define xchg_unchecked(ptr,x) \
1442 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1443
1444 #include <asm-generic/cmpxchg-local.h>
1445
1446 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1447 index 38050b1..9d90e8b 100644
1448 --- a/arch/arm/include/asm/elf.h
1449 +++ b/arch/arm/include/asm/elf.h
1450 @@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1451 the loader. We need to make sure that it is out of the way of the program
1452 that it will "exec", and that there is sufficient room for the brk. */
1453
1454 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1455 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1456 +
1457 +#ifdef CONFIG_PAX_ASLR
1458 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1459 +
1460 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1461 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1462 +#endif
1463
1464 /* When the program starts, a1 contains a pointer to a function to be
1465 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1466 @@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1467 extern void elf_set_personality(const struct elf32_hdr *);
1468 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1469
1470 -struct mm_struct;
1471 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1472 -#define arch_randomize_brk arch_randomize_brk
1473 -
1474 #endif
1475 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1476 index 83eb2f7..ed77159 100644
1477 --- a/arch/arm/include/asm/kmap_types.h
1478 +++ b/arch/arm/include/asm/kmap_types.h
1479 @@ -4,6 +4,6 @@
1480 /*
1481 * This is the "bare minimum". AIO seems to require this.
1482 */
1483 -#define KM_TYPE_NR 16
1484 +#define KM_TYPE_NR 17
1485
1486 #endif
1487 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1488 index 53426c6..c7baff3 100644
1489 --- a/arch/arm/include/asm/outercache.h
1490 +++ b/arch/arm/include/asm/outercache.h
1491 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1492 #endif
1493 void (*set_debug)(unsigned long);
1494 void (*resume)(void);
1495 -};
1496 +} __no_const;
1497
1498 #ifdef CONFIG_OUTER_CACHE
1499
1500 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1501 index ecf9019..b71d9a1 100644
1502 --- a/arch/arm/include/asm/page.h
1503 +++ b/arch/arm/include/asm/page.h
1504 @@ -114,7 +114,7 @@ struct cpu_user_fns {
1505 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1506 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1507 unsigned long vaddr, struct vm_area_struct *vma);
1508 -};
1509 +} __no_const;
1510
1511 #ifdef MULTI_USER
1512 extern struct cpu_user_fns cpu_user;
1513 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1514 index 943504f..bf8d667 100644
1515 --- a/arch/arm/include/asm/pgalloc.h
1516 +++ b/arch/arm/include/asm/pgalloc.h
1517 @@ -43,6 +43,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1518 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1519 }
1520
1521 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1522 +{
1523 + pud_populate(mm, pud, pmd);
1524 +}
1525 +
1526 #else /* !CONFIG_ARM_LPAE */
1527
1528 /*
1529 @@ -51,6 +56,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1530 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1531 #define pmd_free(mm, pmd) do { } while (0)
1532 #define pud_populate(mm,pmd,pte) BUG()
1533 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1534
1535 #endif /* CONFIG_ARM_LPAE */
1536
1537 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
1538 index af7b0bd..6750a8c 100644
1539 --- a/arch/arm/include/asm/thread_info.h
1540 +++ b/arch/arm/include/asm/thread_info.h
1541 @@ -148,6 +148,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1542 #define TIF_NOTIFY_RESUME 2 /* callback before returning to user */
1543 #define TIF_SYSCALL_TRACE 8
1544 #define TIF_SYSCALL_AUDIT 9
1545 +
1546 +/* within 8 bits of TIF_SYSCALL_TRACE
1547 + to meet flexible second operand requirements
1548 +*/
1549 +#define TIF_GRSEC_SETXID 10
1550 +
1551 #define TIF_POLLING_NRFLAG 16
1552 #define TIF_USING_IWMMXT 17
1553 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
1554 @@ -163,9 +169,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1555 #define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG)
1556 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
1557 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
1558 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
1559
1560 /* Checks for any syscall work in entry-common.S */
1561 -#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
1562 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
1563 + _TIF_GRSEC_SETXID)
1564
1565 /*
1566 * Change these and you break ASM code in entry-common.S
1567 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1568 index 77bd79f..ad4cd27 100644
1569 --- a/arch/arm/include/asm/uaccess.h
1570 +++ b/arch/arm/include/asm/uaccess.h
1571 @@ -22,6 +22,8 @@
1572 #define VERIFY_READ 0
1573 #define VERIFY_WRITE 1
1574
1575 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
1576 +
1577 /*
1578 * The exception table consists of pairs of addresses: the first is the
1579 * address of an instruction that is allowed to fault, and the second is
1580 @@ -418,8 +420,23 @@ do { \
1581
1582
1583 #ifdef CONFIG_MMU
1584 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1585 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1586 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1587 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1588 +
1589 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1590 +{
1591 + if (!__builtin_constant_p(n))
1592 + check_object_size(to, n, false);
1593 + return ___copy_from_user(to, from, n);
1594 +}
1595 +
1596 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1597 +{
1598 + if (!__builtin_constant_p(n))
1599 + check_object_size(from, n, true);
1600 + return ___copy_to_user(to, from, n);
1601 +}
1602 +
1603 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1604 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1605 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1606 @@ -431,6 +448,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
1607
1608 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1609 {
1610 + if ((long)n < 0)
1611 + return n;
1612 +
1613 if (access_ok(VERIFY_READ, from, n))
1614 n = __copy_from_user(to, from, n);
1615 else /* security hole - plug it */
1616 @@ -440,6 +460,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1617
1618 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1619 {
1620 + if ((long)n < 0)
1621 + return n;
1622 +
1623 if (access_ok(VERIFY_WRITE, to, n))
1624 n = __copy_to_user(to, from, n);
1625 return n;
1626 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1627 index 60d3b73..9168db0 100644
1628 --- a/arch/arm/kernel/armksyms.c
1629 +++ b/arch/arm/kernel/armksyms.c
1630 @@ -89,8 +89,8 @@ EXPORT_SYMBOL(__memzero);
1631 #ifdef CONFIG_MMU
1632 EXPORT_SYMBOL(copy_page);
1633
1634 -EXPORT_SYMBOL(__copy_from_user);
1635 -EXPORT_SYMBOL(__copy_to_user);
1636 +EXPORT_SYMBOL(___copy_from_user);
1637 +EXPORT_SYMBOL(___copy_to_user);
1638 EXPORT_SYMBOL(__clear_user);
1639
1640 EXPORT_SYMBOL(__get_user_1);
1641 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
1642 index 693b744..e684262 100644
1643 --- a/arch/arm/kernel/process.c
1644 +++ b/arch/arm/kernel/process.c
1645 @@ -28,7 +28,6 @@
1646 #include <linux/tick.h>
1647 #include <linux/utsname.h>
1648 #include <linux/uaccess.h>
1649 -#include <linux/random.h>
1650 #include <linux/hw_breakpoint.h>
1651 #include <linux/cpuidle.h>
1652
1653 @@ -256,9 +255,10 @@ void machine_power_off(void)
1654 machine_shutdown();
1655 if (pm_power_off)
1656 pm_power_off();
1657 + BUG();
1658 }
1659
1660 -void machine_restart(char *cmd)
1661 +__noreturn void machine_restart(char *cmd)
1662 {
1663 machine_shutdown();
1664
1665 @@ -501,12 +501,6 @@ unsigned long get_wchan(struct task_struct *p)
1666 return 0;
1667 }
1668
1669 -unsigned long arch_randomize_brk(struct mm_struct *mm)
1670 -{
1671 - unsigned long range_end = mm->brk + 0x02000000;
1672 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
1673 -}
1674 -
1675 #ifdef CONFIG_MMU
1676 /*
1677 * The vectors page is always readable from user space for the
1678 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
1679 index 3e0fc5f..a42d2ec 100644
1680 --- a/arch/arm/kernel/ptrace.c
1681 +++ b/arch/arm/kernel/ptrace.c
1682 @@ -913,11 +913,20 @@ enum ptrace_syscall_dir {
1683 PTRACE_SYSCALL_EXIT,
1684 };
1685
1686 +#ifdef CONFIG_GRKERNSEC_SETXID
1687 +extern void gr_delayed_cred_worker(void);
1688 +#endif
1689 +
1690 static int ptrace_syscall_trace(struct pt_regs *regs, int scno,
1691 enum ptrace_syscall_dir dir)
1692 {
1693 unsigned long ip;
1694
1695 +#ifdef CONFIG_GRKERNSEC_SETXID
1696 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
1697 + gr_delayed_cred_worker();
1698 +#endif
1699 +
1700 if (!test_thread_flag(TIF_SYSCALL_TRACE))
1701 return scno;
1702
1703 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
1704 index a81dcec..ac42f0f 100644
1705 --- a/arch/arm/kernel/setup.c
1706 +++ b/arch/arm/kernel/setup.c
1707 @@ -112,13 +112,13 @@ struct processor processor __read_mostly;
1708 struct cpu_tlb_fns cpu_tlb __read_mostly;
1709 #endif
1710 #ifdef MULTI_USER
1711 -struct cpu_user_fns cpu_user __read_mostly;
1712 +struct cpu_user_fns cpu_user __read_only;
1713 #endif
1714 #ifdef MULTI_CACHE
1715 -struct cpu_cache_fns cpu_cache __read_mostly;
1716 +struct cpu_cache_fns cpu_cache __read_only;
1717 #endif
1718 #ifdef CONFIG_OUTER_CACHE
1719 -struct outer_cache_fns outer_cache __read_mostly;
1720 +struct outer_cache_fns outer_cache __read_only;
1721 EXPORT_SYMBOL(outer_cache);
1722 #endif
1723
1724 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
1725 index b0179b8..b54c6c1 100644
1726 --- a/arch/arm/kernel/traps.c
1727 +++ b/arch/arm/kernel/traps.c
1728 @@ -266,6 +266,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
1729 static int die_owner = -1;
1730 static unsigned int die_nest_count;
1731
1732 +extern void gr_handle_kernel_exploit(void);
1733 +
1734 static unsigned long oops_begin(void)
1735 {
1736 int cpu;
1737 @@ -308,6 +310,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
1738 panic("Fatal exception in interrupt");
1739 if (panic_on_oops)
1740 panic("Fatal exception");
1741 +
1742 + gr_handle_kernel_exploit();
1743 +
1744 if (signr)
1745 do_exit(signr);
1746 }
1747 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
1748 index 66a477a..bee61d3 100644
1749 --- a/arch/arm/lib/copy_from_user.S
1750 +++ b/arch/arm/lib/copy_from_user.S
1751 @@ -16,7 +16,7 @@
1752 /*
1753 * Prototype:
1754 *
1755 - * size_t __copy_from_user(void *to, const void *from, size_t n)
1756 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
1757 *
1758 * Purpose:
1759 *
1760 @@ -84,11 +84,11 @@
1761
1762 .text
1763
1764 -ENTRY(__copy_from_user)
1765 +ENTRY(___copy_from_user)
1766
1767 #include "copy_template.S"
1768
1769 -ENDPROC(__copy_from_user)
1770 +ENDPROC(___copy_from_user)
1771
1772 .pushsection .fixup,"ax"
1773 .align 0
1774 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
1775 index 6ee2f67..d1cce76 100644
1776 --- a/arch/arm/lib/copy_page.S
1777 +++ b/arch/arm/lib/copy_page.S
1778 @@ -10,6 +10,7 @@
1779 * ASM optimised string functions
1780 */
1781 #include <linux/linkage.h>
1782 +#include <linux/const.h>
1783 #include <asm/assembler.h>
1784 #include <asm/asm-offsets.h>
1785 #include <asm/cache.h>
1786 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
1787 index d066df6..df28194 100644
1788 --- a/arch/arm/lib/copy_to_user.S
1789 +++ b/arch/arm/lib/copy_to_user.S
1790 @@ -16,7 +16,7 @@
1791 /*
1792 * Prototype:
1793 *
1794 - * size_t __copy_to_user(void *to, const void *from, size_t n)
1795 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
1796 *
1797 * Purpose:
1798 *
1799 @@ -88,11 +88,11 @@
1800 .text
1801
1802 ENTRY(__copy_to_user_std)
1803 -WEAK(__copy_to_user)
1804 +WEAK(___copy_to_user)
1805
1806 #include "copy_template.S"
1807
1808 -ENDPROC(__copy_to_user)
1809 +ENDPROC(___copy_to_user)
1810 ENDPROC(__copy_to_user_std)
1811
1812 .pushsection .fixup,"ax"
1813 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
1814 index 025f742..8432b08 100644
1815 --- a/arch/arm/lib/uaccess_with_memcpy.c
1816 +++ b/arch/arm/lib/uaccess_with_memcpy.c
1817 @@ -104,7 +104,7 @@ out:
1818 }
1819
1820 unsigned long
1821 -__copy_to_user(void __user *to, const void *from, unsigned long n)
1822 +___copy_to_user(void __user *to, const void *from, unsigned long n)
1823 {
1824 /*
1825 * This test is stubbed out of the main function above to keep
1826 diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
1827 index 1201191..eabbb2c 100644
1828 --- a/arch/arm/mach-kirkwood/common.c
1829 +++ b/arch/arm/mach-kirkwood/common.c
1830 @@ -160,7 +160,7 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
1831 clk_gate_ops.disable(hw);
1832 }
1833
1834 -static struct clk_ops clk_gate_fn_ops;
1835 +static clk_ops_no_const clk_gate_fn_ops;
1836
1837 static struct clk __init *clk_register_gate_fn(struct device *dev,
1838 const char *name,
1839 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
1840 index 677357f..8828dda 100644
1841 --- a/arch/arm/mach-omap2/board-n8x0.c
1842 +++ b/arch/arm/mach-omap2/board-n8x0.c
1843 @@ -593,7 +593,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
1844 }
1845 #endif
1846
1847 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
1848 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
1849 .late_init = n8x0_menelaus_late_init,
1850 };
1851
1852 diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
1853 index 37afbd1..c22ad7c 100644
1854 --- a/arch/arm/mach-omap2/omap_hwmod.c
1855 +++ b/arch/arm/mach-omap2/omap_hwmod.c
1856 @@ -187,10 +187,10 @@ struct omap_hwmod_soc_ops {
1857 int (*is_hardreset_asserted)(struct omap_hwmod *oh,
1858 struct omap_hwmod_rst_info *ohri);
1859 int (*init_clkdm)(struct omap_hwmod *oh);
1860 -};
1861 +} __no_const;
1862
1863 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
1864 -static struct omap_hwmod_soc_ops soc_ops;
1865 +static struct omap_hwmod_soc_ops soc_ops __read_only;
1866
1867 /* omap_hwmod_list contains all registered struct omap_hwmods */
1868 static LIST_HEAD(omap_hwmod_list);
1869 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
1870 index c3bd834..e81ef02 100644
1871 --- a/arch/arm/mm/fault.c
1872 +++ b/arch/arm/mm/fault.c
1873 @@ -174,6 +174,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
1874 }
1875 #endif
1876
1877 +#ifdef CONFIG_PAX_PAGEEXEC
1878 + if (fsr & FSR_LNX_PF) {
1879 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
1880 + do_group_exit(SIGKILL);
1881 + }
1882 +#endif
1883 +
1884 tsk->thread.address = addr;
1885 tsk->thread.error_code = fsr;
1886 tsk->thread.trap_no = 14;
1887 @@ -397,6 +404,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
1888 }
1889 #endif /* CONFIG_MMU */
1890
1891 +#ifdef CONFIG_PAX_PAGEEXEC
1892 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1893 +{
1894 + long i;
1895 +
1896 + printk(KERN_ERR "PAX: bytes at PC: ");
1897 + for (i = 0; i < 20; i++) {
1898 + unsigned char c;
1899 + if (get_user(c, (__force unsigned char __user *)pc+i))
1900 + printk(KERN_CONT "?? ");
1901 + else
1902 + printk(KERN_CONT "%02x ", c);
1903 + }
1904 + printk("\n");
1905 +
1906 + printk(KERN_ERR "PAX: bytes at SP-4: ");
1907 + for (i = -1; i < 20; i++) {
1908 + unsigned long c;
1909 + if (get_user(c, (__force unsigned long __user *)sp+i))
1910 + printk(KERN_CONT "???????? ");
1911 + else
1912 + printk(KERN_CONT "%08lx ", c);
1913 + }
1914 + printk("\n");
1915 +}
1916 +#endif
1917 +
1918 /*
1919 * First Level Translation Fault Handler
1920 *
1921 @@ -574,6 +608,20 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
1922 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
1923 struct siginfo info;
1924
1925 +#ifdef CONFIG_PAX_REFCOUNT
1926 + if (fsr_fs(ifsr) == 2) {
1927 + unsigned int bkpt;
1928 +
1929 + if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
1930 + current->thread.error_code = ifsr;
1931 + current->thread.trap_no = 0;
1932 + pax_report_refcount_overflow(regs);
1933 + fixup_exception(regs);
1934 + return;
1935 + }
1936 + }
1937 +#endif
1938 +
1939 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
1940 return;
1941
1942 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
1943 index ce8cb19..3ec539d 100644
1944 --- a/arch/arm/mm/mmap.c
1945 +++ b/arch/arm/mm/mmap.c
1946 @@ -93,6 +93,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1947 if (len > TASK_SIZE)
1948 return -ENOMEM;
1949
1950 +#ifdef CONFIG_PAX_RANDMMAP
1951 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1952 +#endif
1953 +
1954 if (addr) {
1955 if (do_align)
1956 addr = COLOUR_ALIGN(addr, pgoff);
1957 @@ -100,15 +104,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1958 addr = PAGE_ALIGN(addr);
1959
1960 vma = find_vma(mm, addr);
1961 - if (TASK_SIZE - len >= addr &&
1962 - (!vma || addr + len <= vma->vm_start))
1963 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1964 return addr;
1965 }
1966 if (len > mm->cached_hole_size) {
1967 - start_addr = addr = mm->free_area_cache;
1968 + start_addr = addr = mm->free_area_cache;
1969 } else {
1970 - start_addr = addr = mm->mmap_base;
1971 - mm->cached_hole_size = 0;
1972 + start_addr = addr = mm->mmap_base;
1973 + mm->cached_hole_size = 0;
1974 }
1975
1976 full_search:
1977 @@ -124,14 +127,14 @@ full_search:
1978 * Start a new search - just in case we missed
1979 * some holes.
1980 */
1981 - if (start_addr != TASK_UNMAPPED_BASE) {
1982 - start_addr = addr = TASK_UNMAPPED_BASE;
1983 + if (start_addr != mm->mmap_base) {
1984 + start_addr = addr = mm->mmap_base;
1985 mm->cached_hole_size = 0;
1986 goto full_search;
1987 }
1988 return -ENOMEM;
1989 }
1990 - if (!vma || addr + len <= vma->vm_start) {
1991 + if (check_heap_stack_gap(vma, addr, len)) {
1992 /*
1993 * Remember the place where we stopped the search:
1994 */
1995 @@ -266,10 +269,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
1996
1997 if (mmap_is_legacy()) {
1998 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
1999 +
2000 +#ifdef CONFIG_PAX_RANDMMAP
2001 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2002 + mm->mmap_base += mm->delta_mmap;
2003 +#endif
2004 +
2005 mm->get_unmapped_area = arch_get_unmapped_area;
2006 mm->unmap_area = arch_unmap_area;
2007 } else {
2008 mm->mmap_base = mmap_base(random_factor);
2009 +
2010 +#ifdef CONFIG_PAX_RANDMMAP
2011 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2012 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
2013 +#endif
2014 +
2015 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
2016 mm->unmap_area = arch_unmap_area_topdown;
2017 }
2018 diff --git a/arch/arm/plat-orion/include/plat/addr-map.h b/arch/arm/plat-orion/include/plat/addr-map.h
2019 index fd556f7..af2e7d2 100644
2020 --- a/arch/arm/plat-orion/include/plat/addr-map.h
2021 +++ b/arch/arm/plat-orion/include/plat/addr-map.h
2022 @@ -26,7 +26,7 @@ struct orion_addr_map_cfg {
2023 value in bridge_virt_base */
2024 void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg,
2025 const int win);
2026 -};
2027 +} __no_const;
2028
2029 /*
2030 * Information needed to setup one address mapping.
2031 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
2032 index f5144cd..71f6d1f 100644
2033 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
2034 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
2035 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
2036 int (*started)(unsigned ch);
2037 int (*flush)(unsigned ch);
2038 int (*stop)(unsigned ch);
2039 -};
2040 +} __no_const;
2041
2042 extern void *samsung_dmadev_get_ops(void);
2043 extern void *s3c_dma_get_ops(void);
2044 diff --git a/arch/arm/plat-samsung/include/plat/ehci.h b/arch/arm/plat-samsung/include/plat/ehci.h
2045 index 5f28cae..3d23723 100644
2046 --- a/arch/arm/plat-samsung/include/plat/ehci.h
2047 +++ b/arch/arm/plat-samsung/include/plat/ehci.h
2048 @@ -14,7 +14,7 @@
2049 struct s5p_ehci_platdata {
2050 int (*phy_init)(struct platform_device *pdev, int type);
2051 int (*phy_exit)(struct platform_device *pdev, int type);
2052 -};
2053 +} __no_const;
2054
2055 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
2056
2057 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
2058 index c3a58a1..78fbf54 100644
2059 --- a/arch/avr32/include/asm/cache.h
2060 +++ b/arch/avr32/include/asm/cache.h
2061 @@ -1,8 +1,10 @@
2062 #ifndef __ASM_AVR32_CACHE_H
2063 #define __ASM_AVR32_CACHE_H
2064
2065 +#include <linux/const.h>
2066 +
2067 #define L1_CACHE_SHIFT 5
2068 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2069 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2070
2071 /*
2072 * Memory returned by kmalloc() may be used for DMA, so we must make
2073 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
2074 index 3b3159b..425ea94 100644
2075 --- a/arch/avr32/include/asm/elf.h
2076 +++ b/arch/avr32/include/asm/elf.h
2077 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
2078 the loader. We need to make sure that it is out of the way of the program
2079 that it will "exec", and that there is sufficient room for the brk. */
2080
2081 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2082 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2083
2084 +#ifdef CONFIG_PAX_ASLR
2085 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
2086 +
2087 +#define PAX_DELTA_MMAP_LEN 15
2088 +#define PAX_DELTA_STACK_LEN 15
2089 +#endif
2090
2091 /* This yields a mask that user programs can use to figure out what
2092 instruction set this CPU supports. This could be done in user space,
2093 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
2094 index 479330b..53717a8 100644
2095 --- a/arch/avr32/include/asm/kmap_types.h
2096 +++ b/arch/avr32/include/asm/kmap_types.h
2097 @@ -2,9 +2,9 @@
2098 #define __ASM_AVR32_KMAP_TYPES_H
2099
2100 #ifdef CONFIG_DEBUG_HIGHMEM
2101 -# define KM_TYPE_NR 29
2102 +# define KM_TYPE_NR 30
2103 #else
2104 -# define KM_TYPE_NR 14
2105 +# define KM_TYPE_NR 15
2106 #endif
2107
2108 #endif /* __ASM_AVR32_KMAP_TYPES_H */
2109 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
2110 index b92e609..b69c101 100644
2111 --- a/arch/avr32/mm/fault.c
2112 +++ b/arch/avr32/mm/fault.c
2113 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
2114
2115 int exception_trace = 1;
2116
2117 +#ifdef CONFIG_PAX_PAGEEXEC
2118 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2119 +{
2120 + unsigned long i;
2121 +
2122 + printk(KERN_ERR "PAX: bytes at PC: ");
2123 + for (i = 0; i < 20; i++) {
2124 + unsigned char c;
2125 + if (get_user(c, (unsigned char *)pc+i))
2126 + printk(KERN_CONT "???????? ");
2127 + else
2128 + printk(KERN_CONT "%02x ", c);
2129 + }
2130 + printk("\n");
2131 +}
2132 +#endif
2133 +
2134 /*
2135 * This routine handles page faults. It determines the address and the
2136 * problem, and then passes it off to one of the appropriate routines.
2137 @@ -173,6 +190,16 @@ bad_area:
2138 up_read(&mm->mmap_sem);
2139
2140 if (user_mode(regs)) {
2141 +
2142 +#ifdef CONFIG_PAX_PAGEEXEC
2143 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
2144 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
2145 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
2146 + do_group_exit(SIGKILL);
2147 + }
2148 + }
2149 +#endif
2150 +
2151 if (exception_trace && printk_ratelimit())
2152 printk("%s%s[%d]: segfault at %08lx pc %08lx "
2153 "sp %08lx ecr %lu\n",
2154 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
2155 index 568885a..f8008df 100644
2156 --- a/arch/blackfin/include/asm/cache.h
2157 +++ b/arch/blackfin/include/asm/cache.h
2158 @@ -7,6 +7,7 @@
2159 #ifndef __ARCH_BLACKFIN_CACHE_H
2160 #define __ARCH_BLACKFIN_CACHE_H
2161
2162 +#include <linux/const.h>
2163 #include <linux/linkage.h> /* for asmlinkage */
2164
2165 /*
2166 @@ -14,7 +15,7 @@
2167 * Blackfin loads 32 bytes for cache
2168 */
2169 #define L1_CACHE_SHIFT 5
2170 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2171 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2172 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2173
2174 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2175 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
2176 index aea2718..3639a60 100644
2177 --- a/arch/cris/include/arch-v10/arch/cache.h
2178 +++ b/arch/cris/include/arch-v10/arch/cache.h
2179 @@ -1,8 +1,9 @@
2180 #ifndef _ASM_ARCH_CACHE_H
2181 #define _ASM_ARCH_CACHE_H
2182
2183 +#include <linux/const.h>
2184 /* Etrax 100LX have 32-byte cache-lines. */
2185 -#define L1_CACHE_BYTES 32
2186 #define L1_CACHE_SHIFT 5
2187 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2188
2189 #endif /* _ASM_ARCH_CACHE_H */
2190 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
2191 index 7caf25d..ee65ac5 100644
2192 --- a/arch/cris/include/arch-v32/arch/cache.h
2193 +++ b/arch/cris/include/arch-v32/arch/cache.h
2194 @@ -1,11 +1,12 @@
2195 #ifndef _ASM_CRIS_ARCH_CACHE_H
2196 #define _ASM_CRIS_ARCH_CACHE_H
2197
2198 +#include <linux/const.h>
2199 #include <arch/hwregs/dma.h>
2200
2201 /* A cache-line is 32 bytes. */
2202 -#define L1_CACHE_BYTES 32
2203 #define L1_CACHE_SHIFT 5
2204 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2205
2206 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
2207
2208 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
2209 index b86329d..6709906 100644
2210 --- a/arch/frv/include/asm/atomic.h
2211 +++ b/arch/frv/include/asm/atomic.h
2212 @@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
2213 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
2214 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
2215
2216 +#define atomic64_read_unchecked(v) atomic64_read(v)
2217 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2218 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2219 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2220 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2221 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2222 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2223 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2224 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2225 +
2226 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
2227 {
2228 int c, old;
2229 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
2230 index 2797163..c2a401d 100644
2231 --- a/arch/frv/include/asm/cache.h
2232 +++ b/arch/frv/include/asm/cache.h
2233 @@ -12,10 +12,11 @@
2234 #ifndef __ASM_CACHE_H
2235 #define __ASM_CACHE_H
2236
2237 +#include <linux/const.h>
2238
2239 /* bytes per L1 cache line */
2240 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
2241 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2242 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2243
2244 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2245 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2246 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
2247 index 43901f2..0d8b865 100644
2248 --- a/arch/frv/include/asm/kmap_types.h
2249 +++ b/arch/frv/include/asm/kmap_types.h
2250 @@ -2,6 +2,6 @@
2251 #ifndef _ASM_KMAP_TYPES_H
2252 #define _ASM_KMAP_TYPES_H
2253
2254 -#define KM_TYPE_NR 17
2255 +#define KM_TYPE_NR 18
2256
2257 #endif
2258 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
2259 index 385fd30..6c3d97e 100644
2260 --- a/arch/frv/mm/elf-fdpic.c
2261 +++ b/arch/frv/mm/elf-fdpic.c
2262 @@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2263 if (addr) {
2264 addr = PAGE_ALIGN(addr);
2265 vma = find_vma(current->mm, addr);
2266 - if (TASK_SIZE - len >= addr &&
2267 - (!vma || addr + len <= vma->vm_start))
2268 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
2269 goto success;
2270 }
2271
2272 @@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2273 for (; vma; vma = vma->vm_next) {
2274 if (addr > limit)
2275 break;
2276 - if (addr + len <= vma->vm_start)
2277 + if (check_heap_stack_gap(vma, addr, len))
2278 goto success;
2279 addr = vma->vm_end;
2280 }
2281 @@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2282 for (; vma; vma = vma->vm_next) {
2283 if (addr > limit)
2284 break;
2285 - if (addr + len <= vma->vm_start)
2286 + if (check_heap_stack_gap(vma, addr, len))
2287 goto success;
2288 addr = vma->vm_end;
2289 }
2290 diff --git a/arch/h8300/include/asm/cache.h b/arch/h8300/include/asm/cache.h
2291 index c635028..6d9445a 100644
2292 --- a/arch/h8300/include/asm/cache.h
2293 +++ b/arch/h8300/include/asm/cache.h
2294 @@ -1,8 +1,10 @@
2295 #ifndef __ARCH_H8300_CACHE_H
2296 #define __ARCH_H8300_CACHE_H
2297
2298 +#include <linux/const.h>
2299 +
2300 /* bytes per L1 cache line */
2301 -#define L1_CACHE_BYTES 4
2302 +#define L1_CACHE_BYTES _AC(4,UL)
2303
2304 /* m68k-elf-gcc 2.95.2 doesn't like these */
2305
2306 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
2307 index 0f01de2..d37d309 100644
2308 --- a/arch/hexagon/include/asm/cache.h
2309 +++ b/arch/hexagon/include/asm/cache.h
2310 @@ -21,9 +21,11 @@
2311 #ifndef __ASM_CACHE_H
2312 #define __ASM_CACHE_H
2313
2314 +#include <linux/const.h>
2315 +
2316 /* Bytes per L1 cache line */
2317 -#define L1_CACHE_SHIFT (5)
2318 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2319 +#define L1_CACHE_SHIFT 5
2320 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2321
2322 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
2323 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
2324 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
2325 index 6e6fe18..a6ae668 100644
2326 --- a/arch/ia64/include/asm/atomic.h
2327 +++ b/arch/ia64/include/asm/atomic.h
2328 @@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
2329 #define atomic64_inc(v) atomic64_add(1, (v))
2330 #define atomic64_dec(v) atomic64_sub(1, (v))
2331
2332 +#define atomic64_read_unchecked(v) atomic64_read(v)
2333 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2334 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2335 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2336 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2337 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2338 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2339 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2340 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2341 +
2342 /* Atomic operations are already serializing */
2343 #define smp_mb__before_atomic_dec() barrier()
2344 #define smp_mb__after_atomic_dec() barrier()
2345 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
2346 index 988254a..e1ee885 100644
2347 --- a/arch/ia64/include/asm/cache.h
2348 +++ b/arch/ia64/include/asm/cache.h
2349 @@ -1,6 +1,7 @@
2350 #ifndef _ASM_IA64_CACHE_H
2351 #define _ASM_IA64_CACHE_H
2352
2353 +#include <linux/const.h>
2354
2355 /*
2356 * Copyright (C) 1998-2000 Hewlett-Packard Co
2357 @@ -9,7 +10,7 @@
2358
2359 /* Bytes per L1 (data) cache line. */
2360 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
2361 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2362 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2363
2364 #ifdef CONFIG_SMP
2365 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2366 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
2367 index b5298eb..67c6e62 100644
2368 --- a/arch/ia64/include/asm/elf.h
2369 +++ b/arch/ia64/include/asm/elf.h
2370 @@ -42,6 +42,13 @@
2371 */
2372 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
2373
2374 +#ifdef CONFIG_PAX_ASLR
2375 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
2376 +
2377 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2378 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2379 +#endif
2380 +
2381 #define PT_IA_64_UNWIND 0x70000001
2382
2383 /* IA-64 relocations: */
2384 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
2385 index 96a8d92..617a1cf 100644
2386 --- a/arch/ia64/include/asm/pgalloc.h
2387 +++ b/arch/ia64/include/asm/pgalloc.h
2388 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2389 pgd_val(*pgd_entry) = __pa(pud);
2390 }
2391
2392 +static inline void
2393 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2394 +{
2395 + pgd_populate(mm, pgd_entry, pud);
2396 +}
2397 +
2398 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
2399 {
2400 return quicklist_alloc(0, GFP_KERNEL, NULL);
2401 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2402 pud_val(*pud_entry) = __pa(pmd);
2403 }
2404
2405 +static inline void
2406 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2407 +{
2408 + pud_populate(mm, pud_entry, pmd);
2409 +}
2410 +
2411 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
2412 {
2413 return quicklist_alloc(0, GFP_KERNEL, NULL);
2414 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
2415 index 815810c..d60bd4c 100644
2416 --- a/arch/ia64/include/asm/pgtable.h
2417 +++ b/arch/ia64/include/asm/pgtable.h
2418 @@ -12,7 +12,7 @@
2419 * David Mosberger-Tang <davidm@hpl.hp.com>
2420 */
2421
2422 -
2423 +#include <linux/const.h>
2424 #include <asm/mman.h>
2425 #include <asm/page.h>
2426 #include <asm/processor.h>
2427 @@ -142,6 +142,17 @@
2428 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2429 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2430 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
2431 +
2432 +#ifdef CONFIG_PAX_PAGEEXEC
2433 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
2434 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2435 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2436 +#else
2437 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
2438 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
2439 +# define PAGE_COPY_NOEXEC PAGE_COPY
2440 +#endif
2441 +
2442 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
2443 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
2444 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
2445 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
2446 index 54ff557..70c88b7 100644
2447 --- a/arch/ia64/include/asm/spinlock.h
2448 +++ b/arch/ia64/include/asm/spinlock.h
2449 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
2450 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
2451
2452 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
2453 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
2454 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
2455 }
2456
2457 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
2458 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
2459 index 449c8c0..432a3d2 100644
2460 --- a/arch/ia64/include/asm/uaccess.h
2461 +++ b/arch/ia64/include/asm/uaccess.h
2462 @@ -257,7 +257,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2463 const void *__cu_from = (from); \
2464 long __cu_len = (n); \
2465 \
2466 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
2467 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
2468 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
2469 __cu_len; \
2470 })
2471 @@ -269,7 +269,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2472 long __cu_len = (n); \
2473 \
2474 __chk_user_ptr(__cu_from); \
2475 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
2476 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
2477 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
2478 __cu_len; \
2479 })
2480 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
2481 index 24603be..948052d 100644
2482 --- a/arch/ia64/kernel/module.c
2483 +++ b/arch/ia64/kernel/module.c
2484 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
2485 void
2486 module_free (struct module *mod, void *module_region)
2487 {
2488 - if (mod && mod->arch.init_unw_table &&
2489 - module_region == mod->module_init) {
2490 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
2491 unw_remove_unwind_table(mod->arch.init_unw_table);
2492 mod->arch.init_unw_table = NULL;
2493 }
2494 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
2495 }
2496
2497 static inline int
2498 +in_init_rx (const struct module *mod, uint64_t addr)
2499 +{
2500 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
2501 +}
2502 +
2503 +static inline int
2504 +in_init_rw (const struct module *mod, uint64_t addr)
2505 +{
2506 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
2507 +}
2508 +
2509 +static inline int
2510 in_init (const struct module *mod, uint64_t addr)
2511 {
2512 - return addr - (uint64_t) mod->module_init < mod->init_size;
2513 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
2514 +}
2515 +
2516 +static inline int
2517 +in_core_rx (const struct module *mod, uint64_t addr)
2518 +{
2519 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
2520 +}
2521 +
2522 +static inline int
2523 +in_core_rw (const struct module *mod, uint64_t addr)
2524 +{
2525 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
2526 }
2527
2528 static inline int
2529 in_core (const struct module *mod, uint64_t addr)
2530 {
2531 - return addr - (uint64_t) mod->module_core < mod->core_size;
2532 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
2533 }
2534
2535 static inline int
2536 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
2537 break;
2538
2539 case RV_BDREL:
2540 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
2541 + if (in_init_rx(mod, val))
2542 + val -= (uint64_t) mod->module_init_rx;
2543 + else if (in_init_rw(mod, val))
2544 + val -= (uint64_t) mod->module_init_rw;
2545 + else if (in_core_rx(mod, val))
2546 + val -= (uint64_t) mod->module_core_rx;
2547 + else if (in_core_rw(mod, val))
2548 + val -= (uint64_t) mod->module_core_rw;
2549 break;
2550
2551 case RV_LTV:
2552 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
2553 * addresses have been selected...
2554 */
2555 uint64_t gp;
2556 - if (mod->core_size > MAX_LTOFF)
2557 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
2558 /*
2559 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
2560 * at the end of the module.
2561 */
2562 - gp = mod->core_size - MAX_LTOFF / 2;
2563 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
2564 else
2565 - gp = mod->core_size / 2;
2566 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
2567 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
2568 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
2569 mod->arch.gp = gp;
2570 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
2571 }
2572 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
2573 index d9439ef..b9a4303 100644
2574 --- a/arch/ia64/kernel/sys_ia64.c
2575 +++ b/arch/ia64/kernel/sys_ia64.c
2576 @@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2577 if (REGION_NUMBER(addr) == RGN_HPAGE)
2578 addr = 0;
2579 #endif
2580 +
2581 +#ifdef CONFIG_PAX_RANDMMAP
2582 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2583 + addr = mm->free_area_cache;
2584 + else
2585 +#endif
2586 +
2587 if (!addr)
2588 addr = mm->free_area_cache;
2589
2590 @@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2591 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
2592 /* At this point: (!vma || addr < vma->vm_end). */
2593 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
2594 - if (start_addr != TASK_UNMAPPED_BASE) {
2595 + if (start_addr != mm->mmap_base) {
2596 /* Start a new search --- just in case we missed some holes. */
2597 - addr = TASK_UNMAPPED_BASE;
2598 + addr = mm->mmap_base;
2599 goto full_search;
2600 }
2601 return -ENOMEM;
2602 }
2603 - if (!vma || addr + len <= vma->vm_start) {
2604 + if (check_heap_stack_gap(vma, addr, len)) {
2605 /* Remember the address where we stopped this search: */
2606 mm->free_area_cache = addr + len;
2607 return addr;
2608 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
2609 index 0ccb28f..8992469 100644
2610 --- a/arch/ia64/kernel/vmlinux.lds.S
2611 +++ b/arch/ia64/kernel/vmlinux.lds.S
2612 @@ -198,7 +198,7 @@ SECTIONS {
2613 /* Per-cpu data: */
2614 . = ALIGN(PERCPU_PAGE_SIZE);
2615 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
2616 - __phys_per_cpu_start = __per_cpu_load;
2617 + __phys_per_cpu_start = per_cpu_load;
2618 /*
2619 * ensure percpu data fits
2620 * into percpu page size
2621 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
2622 index 8443daf..0a01e30 100644
2623 --- a/arch/ia64/mm/fault.c
2624 +++ b/arch/ia64/mm/fault.c
2625 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
2626 return pte_present(pte);
2627 }
2628
2629 +#ifdef CONFIG_PAX_PAGEEXEC
2630 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2631 +{
2632 + unsigned long i;
2633 +
2634 + printk(KERN_ERR "PAX: bytes at PC: ");
2635 + for (i = 0; i < 8; i++) {
2636 + unsigned int c;
2637 + if (get_user(c, (unsigned int *)pc+i))
2638 + printk(KERN_CONT "???????? ");
2639 + else
2640 + printk(KERN_CONT "%08x ", c);
2641 + }
2642 + printk("\n");
2643 +}
2644 +#endif
2645 +
2646 # define VM_READ_BIT 0
2647 # define VM_WRITE_BIT 1
2648 # define VM_EXEC_BIT 2
2649 @@ -149,8 +166,21 @@ retry:
2650 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
2651 goto bad_area;
2652
2653 - if ((vma->vm_flags & mask) != mask)
2654 + if ((vma->vm_flags & mask) != mask) {
2655 +
2656 +#ifdef CONFIG_PAX_PAGEEXEC
2657 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
2658 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
2659 + goto bad_area;
2660 +
2661 + up_read(&mm->mmap_sem);
2662 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
2663 + do_group_exit(SIGKILL);
2664 + }
2665 +#endif
2666 +
2667 goto bad_area;
2668 + }
2669
2670 /*
2671 * If for any reason at all we couldn't handle the fault, make
2672 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
2673 index 5ca674b..e0e1b70 100644
2674 --- a/arch/ia64/mm/hugetlbpage.c
2675 +++ b/arch/ia64/mm/hugetlbpage.c
2676 @@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
2677 /* At this point: (!vmm || addr < vmm->vm_end). */
2678 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
2679 return -ENOMEM;
2680 - if (!vmm || (addr + len) <= vmm->vm_start)
2681 + if (check_heap_stack_gap(vmm, addr, len))
2682 return addr;
2683 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
2684 }
2685 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
2686 index 0eab454..bd794f2 100644
2687 --- a/arch/ia64/mm/init.c
2688 +++ b/arch/ia64/mm/init.c
2689 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
2690 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
2691 vma->vm_end = vma->vm_start + PAGE_SIZE;
2692 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
2693 +
2694 +#ifdef CONFIG_PAX_PAGEEXEC
2695 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
2696 + vma->vm_flags &= ~VM_EXEC;
2697 +
2698 +#ifdef CONFIG_PAX_MPROTECT
2699 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
2700 + vma->vm_flags &= ~VM_MAYEXEC;
2701 +#endif
2702 +
2703 + }
2704 +#endif
2705 +
2706 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2707 down_write(&current->mm->mmap_sem);
2708 if (insert_vm_struct(current->mm, vma)) {
2709 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
2710 index 40b3ee9..8c2c112 100644
2711 --- a/arch/m32r/include/asm/cache.h
2712 +++ b/arch/m32r/include/asm/cache.h
2713 @@ -1,8 +1,10 @@
2714 #ifndef _ASM_M32R_CACHE_H
2715 #define _ASM_M32R_CACHE_H
2716
2717 +#include <linux/const.h>
2718 +
2719 /* L1 cache line size */
2720 #define L1_CACHE_SHIFT 4
2721 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2722 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2723
2724 #endif /* _ASM_M32R_CACHE_H */
2725 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
2726 index 82abd15..d95ae5d 100644
2727 --- a/arch/m32r/lib/usercopy.c
2728 +++ b/arch/m32r/lib/usercopy.c
2729 @@ -14,6 +14,9 @@
2730 unsigned long
2731 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2732 {
2733 + if ((long)n < 0)
2734 + return n;
2735 +
2736 prefetch(from);
2737 if (access_ok(VERIFY_WRITE, to, n))
2738 __copy_user(to,from,n);
2739 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2740 unsigned long
2741 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
2742 {
2743 + if ((long)n < 0)
2744 + return n;
2745 +
2746 prefetchw(to);
2747 if (access_ok(VERIFY_READ, from, n))
2748 __copy_user_zeroing(to,from,n);
2749 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
2750 index 0395c51..5f26031 100644
2751 --- a/arch/m68k/include/asm/cache.h
2752 +++ b/arch/m68k/include/asm/cache.h
2753 @@ -4,9 +4,11 @@
2754 #ifndef __ARCH_M68K_CACHE_H
2755 #define __ARCH_M68K_CACHE_H
2756
2757 +#include <linux/const.h>
2758 +
2759 /* bytes per L1 cache line */
2760 #define L1_CACHE_SHIFT 4
2761 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
2762 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2763
2764 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2765
2766 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
2767 index 4efe96a..60e8699 100644
2768 --- a/arch/microblaze/include/asm/cache.h
2769 +++ b/arch/microblaze/include/asm/cache.h
2770 @@ -13,11 +13,12 @@
2771 #ifndef _ASM_MICROBLAZE_CACHE_H
2772 #define _ASM_MICROBLAZE_CACHE_H
2773
2774 +#include <linux/const.h>
2775 #include <asm/registers.h>
2776
2777 #define L1_CACHE_SHIFT 5
2778 /* word-granular cache in microblaze */
2779 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2780 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2781
2782 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2783
2784 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
2785 index 3f4c5cb..3439c6e 100644
2786 --- a/arch/mips/include/asm/atomic.h
2787 +++ b/arch/mips/include/asm/atomic.h
2788 @@ -21,6 +21,10 @@
2789 #include <asm/cmpxchg.h>
2790 #include <asm/war.h>
2791
2792 +#ifdef CONFIG_GENERIC_ATOMIC64
2793 +#include <asm-generic/atomic64.h>
2794 +#endif
2795 +
2796 #define ATOMIC_INIT(i) { (i) }
2797
2798 /*
2799 @@ -765,6 +769,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2800 */
2801 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
2802
2803 +#define atomic64_read_unchecked(v) atomic64_read(v)
2804 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2805 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2806 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2807 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2808 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2809 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2810 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2811 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2812 +
2813 #endif /* CONFIG_64BIT */
2814
2815 /*
2816 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
2817 index b4db69f..8f3b093 100644
2818 --- a/arch/mips/include/asm/cache.h
2819 +++ b/arch/mips/include/asm/cache.h
2820 @@ -9,10 +9,11 @@
2821 #ifndef _ASM_CACHE_H
2822 #define _ASM_CACHE_H
2823
2824 +#include <linux/const.h>
2825 #include <kmalloc.h>
2826
2827 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
2828 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2829 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2830
2831 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2832 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2833 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
2834 index 455c0ac..ad65fbe 100644
2835 --- a/arch/mips/include/asm/elf.h
2836 +++ b/arch/mips/include/asm/elf.h
2837 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
2838 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2839 #endif
2840
2841 +#ifdef CONFIG_PAX_ASLR
2842 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2843 +
2844 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2845 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2846 +#endif
2847 +
2848 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2849 struct linux_binprm;
2850 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2851 int uses_interp);
2852
2853 -struct mm_struct;
2854 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2855 -#define arch_randomize_brk arch_randomize_brk
2856 -
2857 #endif /* _ASM_ELF_H */
2858 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
2859 index c1f6afa..38cc6e9 100644
2860 --- a/arch/mips/include/asm/exec.h
2861 +++ b/arch/mips/include/asm/exec.h
2862 @@ -12,6 +12,6 @@
2863 #ifndef _ASM_EXEC_H
2864 #define _ASM_EXEC_H
2865
2866 -extern unsigned long arch_align_stack(unsigned long sp);
2867 +#define arch_align_stack(x) ((x) & ~0xfUL)
2868
2869 #endif /* _ASM_EXEC_H */
2870 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
2871 index da9bd7d..91aa7ab 100644
2872 --- a/arch/mips/include/asm/page.h
2873 +++ b/arch/mips/include/asm/page.h
2874 @@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
2875 #ifdef CONFIG_CPU_MIPS32
2876 typedef struct { unsigned long pte_low, pte_high; } pte_t;
2877 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
2878 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
2879 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
2880 #else
2881 typedef struct { unsigned long long pte; } pte_t;
2882 #define pte_val(x) ((x).pte)
2883 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
2884 index 881d18b..cea38bc 100644
2885 --- a/arch/mips/include/asm/pgalloc.h
2886 +++ b/arch/mips/include/asm/pgalloc.h
2887 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2888 {
2889 set_pud(pud, __pud((unsigned long)pmd));
2890 }
2891 +
2892 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2893 +{
2894 + pud_populate(mm, pud, pmd);
2895 +}
2896 #endif
2897
2898 /*
2899 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
2900 index ca97e0e..cd08920 100644
2901 --- a/arch/mips/include/asm/thread_info.h
2902 +++ b/arch/mips/include/asm/thread_info.h
2903 @@ -111,6 +111,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
2904 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
2905 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
2906 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
2907 +/* li takes a 32bit immediate */
2908 +#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
2909 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
2910
2911 #ifdef CONFIG_MIPS32_O32
2912 @@ -134,15 +136,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
2913 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
2914 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
2915 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
2916 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
2917 +
2918 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2919
2920 /* work to do in syscall_trace_leave() */
2921 -#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
2922 +#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2923
2924 /* work to do on interrupt/exception return */
2925 #define _TIF_WORK_MASK (0x0000ffef & \
2926 ~(_TIF_SECCOMP | _TIF_SYSCALL_AUDIT))
2927 /* work to do on any return to u-space */
2928 -#define _TIF_ALLWORK_MASK (0x8000ffff & ~_TIF_SECCOMP)
2929 +#define _TIF_ALLWORK_MASK ((0x8000ffff & ~_TIF_SECCOMP) | _TIF_GRSEC_SETXID)
2930
2931 #endif /* __KERNEL__ */
2932
2933 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
2934 index 9fdd8bc..4bd7f1a 100644
2935 --- a/arch/mips/kernel/binfmt_elfn32.c
2936 +++ b/arch/mips/kernel/binfmt_elfn32.c
2937 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2938 #undef ELF_ET_DYN_BASE
2939 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2940
2941 +#ifdef CONFIG_PAX_ASLR
2942 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2943 +
2944 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2945 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2946 +#endif
2947 +
2948 #include <asm/processor.h>
2949 #include <linux/module.h>
2950 #include <linux/elfcore.h>
2951 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
2952 index ff44823..97f8906 100644
2953 --- a/arch/mips/kernel/binfmt_elfo32.c
2954 +++ b/arch/mips/kernel/binfmt_elfo32.c
2955 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2956 #undef ELF_ET_DYN_BASE
2957 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2958
2959 +#ifdef CONFIG_PAX_ASLR
2960 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2961 +
2962 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2963 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2964 +#endif
2965 +
2966 #include <asm/processor.h>
2967
2968 /*
2969 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
2970 index e9a5fd7..378809a 100644
2971 --- a/arch/mips/kernel/process.c
2972 +++ b/arch/mips/kernel/process.c
2973 @@ -480,15 +480,3 @@ unsigned long get_wchan(struct task_struct *task)
2974 out:
2975 return pc;
2976 }
2977 -
2978 -/*
2979 - * Don't forget that the stack pointer must be aligned on a 8 bytes
2980 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
2981 - */
2982 -unsigned long arch_align_stack(unsigned long sp)
2983 -{
2984 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2985 - sp -= get_random_int() & ~PAGE_MASK;
2986 -
2987 - return sp & ALMASK;
2988 -}
2989 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
2990 index 4812c6d..2069554 100644
2991 --- a/arch/mips/kernel/ptrace.c
2992 +++ b/arch/mips/kernel/ptrace.c
2993 @@ -528,6 +528,10 @@ static inline int audit_arch(void)
2994 return arch;
2995 }
2996
2997 +#ifdef CONFIG_GRKERNSEC_SETXID
2998 +extern void gr_delayed_cred_worker(void);
2999 +#endif
3000 +
3001 /*
3002 * Notification of system call entry/exit
3003 * - triggered by current->work.syscall_trace
3004 @@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
3005 /* do the secure computing check first */
3006 secure_computing_strict(regs->regs[2]);
3007
3008 +#ifdef CONFIG_GRKERNSEC_SETXID
3009 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3010 + gr_delayed_cred_worker();
3011 +#endif
3012 +
3013 if (!(current->ptrace & PT_PTRACED))
3014 goto out;
3015
3016 diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
3017 index a632bc1..0b77c7c 100644
3018 --- a/arch/mips/kernel/scall32-o32.S
3019 +++ b/arch/mips/kernel/scall32-o32.S
3020 @@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3021
3022 stack_done:
3023 lw t0, TI_FLAGS($28) # syscall tracing enabled?
3024 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3025 + li t1, _TIF_SYSCALL_WORK
3026 and t0, t1
3027 bnez t0, syscall_trace_entry # -> yes
3028
3029 diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
3030 index 3b5a5e9..e1ee86d 100644
3031 --- a/arch/mips/kernel/scall64-64.S
3032 +++ b/arch/mips/kernel/scall64-64.S
3033 @@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
3034
3035 sd a3, PT_R26(sp) # save a3 for syscall restarting
3036
3037 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3038 + li t1, _TIF_SYSCALL_WORK
3039 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3040 and t0, t1, t0
3041 bnez t0, syscall_trace_entry
3042 diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
3043 index 6be6f70..1859577 100644
3044 --- a/arch/mips/kernel/scall64-n32.S
3045 +++ b/arch/mips/kernel/scall64-n32.S
3046 @@ -53,7 +53,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
3047
3048 sd a3, PT_R26(sp) # save a3 for syscall restarting
3049
3050 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3051 + li t1, _TIF_SYSCALL_WORK
3052 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3053 and t0, t1, t0
3054 bnez t0, n32_syscall_trace_entry
3055 diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
3056 index 5422855..74e63a3 100644
3057 --- a/arch/mips/kernel/scall64-o32.S
3058 +++ b/arch/mips/kernel/scall64-o32.S
3059 @@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3060 PTR 4b, bad_stack
3061 .previous
3062
3063 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3064 + li t1, _TIF_SYSCALL_WORK
3065 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3066 and t0, t1, t0
3067 bnez t0, trace_a_syscall
3068 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
3069 index c14f6df..537e729 100644
3070 --- a/arch/mips/mm/fault.c
3071 +++ b/arch/mips/mm/fault.c
3072 @@ -27,6 +27,23 @@
3073 #include <asm/highmem.h> /* For VMALLOC_END */
3074 #include <linux/kdebug.h>
3075
3076 +#ifdef CONFIG_PAX_PAGEEXEC
3077 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3078 +{
3079 + unsigned long i;
3080 +
3081 + printk(KERN_ERR "PAX: bytes at PC: ");
3082 + for (i = 0; i < 5; i++) {
3083 + unsigned int c;
3084 + if (get_user(c, (unsigned int *)pc+i))
3085 + printk(KERN_CONT "???????? ");
3086 + else
3087 + printk(KERN_CONT "%08x ", c);
3088 + }
3089 + printk("\n");
3090 +}
3091 +#endif
3092 +
3093 /*
3094 * This routine handles page faults. It determines the address,
3095 * and the problem, and then passes it off to one of the appropriate
3096 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
3097 index 302d779..7d35bf8 100644
3098 --- a/arch/mips/mm/mmap.c
3099 +++ b/arch/mips/mm/mmap.c
3100 @@ -95,6 +95,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3101 do_color_align = 1;
3102
3103 /* requesting a specific address */
3104 +
3105 +#ifdef CONFIG_PAX_RANDMMAP
3106 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
3107 +#endif
3108 +
3109 if (addr) {
3110 if (do_color_align)
3111 addr = COLOUR_ALIGN(addr, pgoff);
3112 @@ -102,8 +107,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3113 addr = PAGE_ALIGN(addr);
3114
3115 vma = find_vma(mm, addr);
3116 - if (TASK_SIZE - len >= addr &&
3117 - (!vma || addr + len <= vma->vm_start))
3118 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len))
3119 return addr;
3120 }
3121
3122 @@ -118,7 +122,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3123 /* At this point: (!vma || addr < vma->vm_end). */
3124 if (TASK_SIZE - len < addr)
3125 return -ENOMEM;
3126 - if (!vma || addr + len <= vma->vm_start)
3127 + if (check_heap_stack_gap(vmm, addr, len))
3128 return addr;
3129 addr = vma->vm_end;
3130 if (do_color_align)
3131 @@ -145,7 +149,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3132 /* make sure it can fit in the remaining address space */
3133 if (likely(addr > len)) {
3134 vma = find_vma(mm, addr - len);
3135 - if (!vma || addr <= vma->vm_start) {
3136 + if (check_heap_stack_gap(vmm, addr - len, len))
3137 /* cache the address as a hint for next time */
3138 return mm->free_area_cache = addr - len;
3139 }
3140 @@ -165,7 +169,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3141 * return with success:
3142 */
3143 vma = find_vma(mm, addr);
3144 - if (likely(!vma || addr + len <= vma->vm_start)) {
3145 + if (check_heap_stack_gap(vmm, addr, len)) {
3146 /* cache the address as a hint for next time */
3147 return mm->free_area_cache = addr;
3148 }
3149 @@ -242,30 +246,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3150 mm->unmap_area = arch_unmap_area_topdown;
3151 }
3152 }
3153 -
3154 -static inline unsigned long brk_rnd(void)
3155 -{
3156 - unsigned long rnd = get_random_int();
3157 -
3158 - rnd = rnd << PAGE_SHIFT;
3159 - /* 8MB for 32bit, 256MB for 64bit */
3160 - if (TASK_IS_32BIT_ADDR)
3161 - rnd = rnd & 0x7ffffful;
3162 - else
3163 - rnd = rnd & 0xffffffful;
3164 -
3165 - return rnd;
3166 -}
3167 -
3168 -unsigned long arch_randomize_brk(struct mm_struct *mm)
3169 -{
3170 - unsigned long base = mm->brk;
3171 - unsigned long ret;
3172 -
3173 - ret = PAGE_ALIGN(base + brk_rnd());
3174 -
3175 - if (ret < mm->brk)
3176 - return mm->brk;
3177 -
3178 - return ret;
3179 -}
3180 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3181 index 967d144..db12197 100644
3182 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
3183 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3184 @@ -11,12 +11,14 @@
3185 #ifndef _ASM_PROC_CACHE_H
3186 #define _ASM_PROC_CACHE_H
3187
3188 +#include <linux/const.h>
3189 +
3190 /* L1 cache */
3191
3192 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3193 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
3194 -#define L1_CACHE_BYTES 16 /* bytes per entry */
3195 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
3196 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3197 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
3198
3199 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3200 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3201 index bcb5df2..84fabd2 100644
3202 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3203 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3204 @@ -16,13 +16,15 @@
3205 #ifndef _ASM_PROC_CACHE_H
3206 #define _ASM_PROC_CACHE_H
3207
3208 +#include <linux/const.h>
3209 +
3210 /*
3211 * L1 cache
3212 */
3213 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3214 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
3215 -#define L1_CACHE_BYTES 32 /* bytes per entry */
3216 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
3217 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3218 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
3219
3220 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3221 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
3222 index 4ce7a01..449202a 100644
3223 --- a/arch/openrisc/include/asm/cache.h
3224 +++ b/arch/openrisc/include/asm/cache.h
3225 @@ -19,11 +19,13 @@
3226 #ifndef __ASM_OPENRISC_CACHE_H
3227 #define __ASM_OPENRISC_CACHE_H
3228
3229 +#include <linux/const.h>
3230 +
3231 /* FIXME: How can we replace these with values from the CPU...
3232 * they shouldn't be hard-coded!
3233 */
3234
3235 -#define L1_CACHE_BYTES 16
3236 #define L1_CACHE_SHIFT 4
3237 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3238
3239 #endif /* __ASM_OPENRISC_CACHE_H */
3240 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
3241 index af9cf30..2aae9b2 100644
3242 --- a/arch/parisc/include/asm/atomic.h
3243 +++ b/arch/parisc/include/asm/atomic.h
3244 @@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3245
3246 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3247
3248 +#define atomic64_read_unchecked(v) atomic64_read(v)
3249 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3250 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3251 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3252 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3253 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3254 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3255 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3256 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3257 +
3258 #endif /* !CONFIG_64BIT */
3259
3260
3261 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
3262 index 47f11c7..3420df2 100644
3263 --- a/arch/parisc/include/asm/cache.h
3264 +++ b/arch/parisc/include/asm/cache.h
3265 @@ -5,6 +5,7 @@
3266 #ifndef __ARCH_PARISC_CACHE_H
3267 #define __ARCH_PARISC_CACHE_H
3268
3269 +#include <linux/const.h>
3270
3271 /*
3272 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
3273 @@ -15,13 +16,13 @@
3274 * just ruin performance.
3275 */
3276 #ifdef CONFIG_PA20
3277 -#define L1_CACHE_BYTES 64
3278 #define L1_CACHE_SHIFT 6
3279 #else
3280 -#define L1_CACHE_BYTES 32
3281 #define L1_CACHE_SHIFT 5
3282 #endif
3283
3284 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3285 +
3286 #ifndef __ASSEMBLY__
3287
3288 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3289 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
3290 index 19f6cb1..6c78cf2 100644
3291 --- a/arch/parisc/include/asm/elf.h
3292 +++ b/arch/parisc/include/asm/elf.h
3293 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
3294
3295 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
3296
3297 +#ifdef CONFIG_PAX_ASLR
3298 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
3299 +
3300 +#define PAX_DELTA_MMAP_LEN 16
3301 +#define PAX_DELTA_STACK_LEN 16
3302 +#endif
3303 +
3304 /* This yields a mask that user programs can use to figure out what
3305 instruction set this CPU supports. This could be done in user space,
3306 but it's not easy, and we've already done it here. */
3307 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
3308 index fc987a1..6e068ef 100644
3309 --- a/arch/parisc/include/asm/pgalloc.h
3310 +++ b/arch/parisc/include/asm/pgalloc.h
3311 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3312 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
3313 }
3314
3315 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3316 +{
3317 + pgd_populate(mm, pgd, pmd);
3318 +}
3319 +
3320 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
3321 {
3322 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
3323 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
3324 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
3325 #define pmd_free(mm, x) do { } while (0)
3326 #define pgd_populate(mm, pmd, pte) BUG()
3327 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
3328
3329 #endif
3330
3331 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
3332 index ee99f23..802b0a1 100644
3333 --- a/arch/parisc/include/asm/pgtable.h
3334 +++ b/arch/parisc/include/asm/pgtable.h
3335 @@ -212,6 +212,17 @@ struct vm_area_struct;
3336 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
3337 #define PAGE_COPY PAGE_EXECREAD
3338 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
3339 +
3340 +#ifdef CONFIG_PAX_PAGEEXEC
3341 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
3342 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3343 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3344 +#else
3345 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
3346 +# define PAGE_COPY_NOEXEC PAGE_COPY
3347 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
3348 +#endif
3349 +
3350 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
3351 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
3352 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
3353 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
3354 index 4ba2c93..f5e3974 100644
3355 --- a/arch/parisc/include/asm/uaccess.h
3356 +++ b/arch/parisc/include/asm/uaccess.h
3357 @@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
3358 const void __user *from,
3359 unsigned long n)
3360 {
3361 - int sz = __compiletime_object_size(to);
3362 + size_t sz = __compiletime_object_size(to);
3363 int ret = -EFAULT;
3364
3365 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
3366 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
3367 ret = __copy_from_user(to, from, n);
3368 else
3369 copy_from_user_overflow();
3370 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
3371 index 5e34ccf..672bc9c 100644
3372 --- a/arch/parisc/kernel/module.c
3373 +++ b/arch/parisc/kernel/module.c
3374 @@ -98,16 +98,38 @@
3375
3376 /* three functions to determine where in the module core
3377 * or init pieces the location is */
3378 +static inline int in_init_rx(struct module *me, void *loc)
3379 +{
3380 + return (loc >= me->module_init_rx &&
3381 + loc < (me->module_init_rx + me->init_size_rx));
3382 +}
3383 +
3384 +static inline int in_init_rw(struct module *me, void *loc)
3385 +{
3386 + return (loc >= me->module_init_rw &&
3387 + loc < (me->module_init_rw + me->init_size_rw));
3388 +}
3389 +
3390 static inline int in_init(struct module *me, void *loc)
3391 {
3392 - return (loc >= me->module_init &&
3393 - loc <= (me->module_init + me->init_size));
3394 + return in_init_rx(me, loc) || in_init_rw(me, loc);
3395 +}
3396 +
3397 +static inline int in_core_rx(struct module *me, void *loc)
3398 +{
3399 + return (loc >= me->module_core_rx &&
3400 + loc < (me->module_core_rx + me->core_size_rx));
3401 +}
3402 +
3403 +static inline int in_core_rw(struct module *me, void *loc)
3404 +{
3405 + return (loc >= me->module_core_rw &&
3406 + loc < (me->module_core_rw + me->core_size_rw));
3407 }
3408
3409 static inline int in_core(struct module *me, void *loc)
3410 {
3411 - return (loc >= me->module_core &&
3412 - loc <= (me->module_core + me->core_size));
3413 + return in_core_rx(me, loc) || in_core_rw(me, loc);
3414 }
3415
3416 static inline int in_local(struct module *me, void *loc)
3417 @@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
3418 }
3419
3420 /* align things a bit */
3421 - me->core_size = ALIGN(me->core_size, 16);
3422 - me->arch.got_offset = me->core_size;
3423 - me->core_size += gots * sizeof(struct got_entry);
3424 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3425 + me->arch.got_offset = me->core_size_rw;
3426 + me->core_size_rw += gots * sizeof(struct got_entry);
3427
3428 - me->core_size = ALIGN(me->core_size, 16);
3429 - me->arch.fdesc_offset = me->core_size;
3430 - me->core_size += fdescs * sizeof(Elf_Fdesc);
3431 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3432 + me->arch.fdesc_offset = me->core_size_rw;
3433 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
3434
3435 me->arch.got_max = gots;
3436 me->arch.fdesc_max = fdescs;
3437 @@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3438
3439 BUG_ON(value == 0);
3440
3441 - got = me->module_core + me->arch.got_offset;
3442 + got = me->module_core_rw + me->arch.got_offset;
3443 for (i = 0; got[i].addr; i++)
3444 if (got[i].addr == value)
3445 goto out;
3446 @@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3447 #ifdef CONFIG_64BIT
3448 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3449 {
3450 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
3451 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
3452
3453 if (!value) {
3454 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
3455 @@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3456
3457 /* Create new one */
3458 fdesc->addr = value;
3459 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3460 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3461 return (Elf_Addr)fdesc;
3462 }
3463 #endif /* CONFIG_64BIT */
3464 @@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
3465
3466 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
3467 end = table + sechdrs[me->arch.unwind_section].sh_size;
3468 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3469 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3470
3471 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
3472 me->arch.unwind_section, table, end, gp);
3473 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
3474 index 7426e40..30c8dbe 100644
3475 --- a/arch/parisc/kernel/sys_parisc.c
3476 +++ b/arch/parisc/kernel/sys_parisc.c
3477 @@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
3478 /* At this point: (!vma || addr < vma->vm_end). */
3479 if (TASK_SIZE - len < addr)
3480 return -ENOMEM;
3481 - if (!vma || addr + len <= vma->vm_start)
3482 + if (check_heap_stack_gap(vma, addr, len))
3483 return addr;
3484 addr = vma->vm_end;
3485 }
3486 @@ -79,7 +79,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
3487 /* At this point: (!vma || addr < vma->vm_end). */
3488 if (TASK_SIZE - len < addr)
3489 return -ENOMEM;
3490 - if (!vma || addr + len <= vma->vm_start)
3491 + if (check_heap_stack_gap(vma, addr, len))
3492 return addr;
3493 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
3494 if (addr < vma->vm_end) /* handle wraparound */
3495 @@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
3496 if (flags & MAP_FIXED)
3497 return addr;
3498 if (!addr)
3499 - addr = TASK_UNMAPPED_BASE;
3500 + addr = current->mm->mmap_base;
3501
3502 if (filp) {
3503 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
3504 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
3505 index 45ba99f..8e22c33 100644
3506 --- a/arch/parisc/kernel/traps.c
3507 +++ b/arch/parisc/kernel/traps.c
3508 @@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
3509
3510 down_read(&current->mm->mmap_sem);
3511 vma = find_vma(current->mm,regs->iaoq[0]);
3512 - if (vma && (regs->iaoq[0] >= vma->vm_start)
3513 - && (vma->vm_flags & VM_EXEC)) {
3514 -
3515 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
3516 fault_address = regs->iaoq[0];
3517 fault_space = regs->iasq[0];
3518
3519 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
3520 index 18162ce..94de376 100644
3521 --- a/arch/parisc/mm/fault.c
3522 +++ b/arch/parisc/mm/fault.c
3523 @@ -15,6 +15,7 @@
3524 #include <linux/sched.h>
3525 #include <linux/interrupt.h>
3526 #include <linux/module.h>
3527 +#include <linux/unistd.h>
3528
3529 #include <asm/uaccess.h>
3530 #include <asm/traps.h>
3531 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
3532 static unsigned long
3533 parisc_acctyp(unsigned long code, unsigned int inst)
3534 {
3535 - if (code == 6 || code == 16)
3536 + if (code == 6 || code == 7 || code == 16)
3537 return VM_EXEC;
3538
3539 switch (inst & 0xf0000000) {
3540 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
3541 }
3542 #endif
3543
3544 +#ifdef CONFIG_PAX_PAGEEXEC
3545 +/*
3546 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
3547 + *
3548 + * returns 1 when task should be killed
3549 + * 2 when rt_sigreturn trampoline was detected
3550 + * 3 when unpatched PLT trampoline was detected
3551 + */
3552 +static int pax_handle_fetch_fault(struct pt_regs *regs)
3553 +{
3554 +
3555 +#ifdef CONFIG_PAX_EMUPLT
3556 + int err;
3557 +
3558 + do { /* PaX: unpatched PLT emulation */
3559 + unsigned int bl, depwi;
3560 +
3561 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
3562 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
3563 +
3564 + if (err)
3565 + break;
3566 +
3567 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
3568 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
3569 +
3570 + err = get_user(ldw, (unsigned int *)addr);
3571 + err |= get_user(bv, (unsigned int *)(addr+4));
3572 + err |= get_user(ldw2, (unsigned int *)(addr+8));
3573 +
3574 + if (err)
3575 + break;
3576 +
3577 + if (ldw == 0x0E801096U &&
3578 + bv == 0xEAC0C000U &&
3579 + ldw2 == 0x0E881095U)
3580 + {
3581 + unsigned int resolver, map;
3582 +
3583 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
3584 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
3585 + if (err)
3586 + break;
3587 +
3588 + regs->gr[20] = instruction_pointer(regs)+8;
3589 + regs->gr[21] = map;
3590 + regs->gr[22] = resolver;
3591 + regs->iaoq[0] = resolver | 3UL;
3592 + regs->iaoq[1] = regs->iaoq[0] + 4;
3593 + return 3;
3594 + }
3595 + }
3596 + } while (0);
3597 +#endif
3598 +
3599 +#ifdef CONFIG_PAX_EMUTRAMP
3600 +
3601 +#ifndef CONFIG_PAX_EMUSIGRT
3602 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
3603 + return 1;
3604 +#endif
3605 +
3606 + do { /* PaX: rt_sigreturn emulation */
3607 + unsigned int ldi1, ldi2, bel, nop;
3608 +
3609 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
3610 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
3611 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
3612 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
3613 +
3614 + if (err)
3615 + break;
3616 +
3617 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
3618 + ldi2 == 0x3414015AU &&
3619 + bel == 0xE4008200U &&
3620 + nop == 0x08000240U)
3621 + {
3622 + regs->gr[25] = (ldi1 & 2) >> 1;
3623 + regs->gr[20] = __NR_rt_sigreturn;
3624 + regs->gr[31] = regs->iaoq[1] + 16;
3625 + regs->sr[0] = regs->iasq[1];
3626 + regs->iaoq[0] = 0x100UL;
3627 + regs->iaoq[1] = regs->iaoq[0] + 4;
3628 + regs->iasq[0] = regs->sr[2];
3629 + regs->iasq[1] = regs->sr[2];
3630 + return 2;
3631 + }
3632 + } while (0);
3633 +#endif
3634 +
3635 + return 1;
3636 +}
3637 +
3638 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3639 +{
3640 + unsigned long i;
3641 +
3642 + printk(KERN_ERR "PAX: bytes at PC: ");
3643 + for (i = 0; i < 5; i++) {
3644 + unsigned int c;
3645 + if (get_user(c, (unsigned int *)pc+i))
3646 + printk(KERN_CONT "???????? ");
3647 + else
3648 + printk(KERN_CONT "%08x ", c);
3649 + }
3650 + printk("\n");
3651 +}
3652 +#endif
3653 +
3654 int fixup_exception(struct pt_regs *regs)
3655 {
3656 const struct exception_table_entry *fix;
3657 @@ -192,8 +303,33 @@ good_area:
3658
3659 acc_type = parisc_acctyp(code,regs->iir);
3660
3661 - if ((vma->vm_flags & acc_type) != acc_type)
3662 + if ((vma->vm_flags & acc_type) != acc_type) {
3663 +
3664 +#ifdef CONFIG_PAX_PAGEEXEC
3665 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
3666 + (address & ~3UL) == instruction_pointer(regs))
3667 + {
3668 + up_read(&mm->mmap_sem);
3669 + switch (pax_handle_fetch_fault(regs)) {
3670 +
3671 +#ifdef CONFIG_PAX_EMUPLT
3672 + case 3:
3673 + return;
3674 +#endif
3675 +
3676 +#ifdef CONFIG_PAX_EMUTRAMP
3677 + case 2:
3678 + return;
3679 +#endif
3680 +
3681 + }
3682 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
3683 + do_group_exit(SIGKILL);
3684 + }
3685 +#endif
3686 +
3687 goto bad_area;
3688 + }
3689
3690 /*
3691 * If for any reason at all we couldn't handle the fault, make
3692 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
3693 index da29032..f76c24c 100644
3694 --- a/arch/powerpc/include/asm/atomic.h
3695 +++ b/arch/powerpc/include/asm/atomic.h
3696 @@ -522,6 +522,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
3697 return t1;
3698 }
3699
3700 +#define atomic64_read_unchecked(v) atomic64_read(v)
3701 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3702 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3703 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3704 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3705 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3706 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3707 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3708 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3709 +
3710 #endif /* __powerpc64__ */
3711
3712 #endif /* __KERNEL__ */
3713 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
3714 index 9e495c9..b6878e5 100644
3715 --- a/arch/powerpc/include/asm/cache.h
3716 +++ b/arch/powerpc/include/asm/cache.h
3717 @@ -3,6 +3,7 @@
3718
3719 #ifdef __KERNEL__
3720
3721 +#include <linux/const.h>
3722
3723 /* bytes per L1 cache line */
3724 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
3725 @@ -22,7 +23,7 @@
3726 #define L1_CACHE_SHIFT 7
3727 #endif
3728
3729 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3730 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3731
3732 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3733
3734 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
3735 index 3bf9cca..e7457d0 100644
3736 --- a/arch/powerpc/include/asm/elf.h
3737 +++ b/arch/powerpc/include/asm/elf.h
3738 @@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[ELF_NVSRHALFREG];
3739 the loader. We need to make sure that it is out of the way of the program
3740 that it will "exec", and that there is sufficient room for the brk. */
3741
3742 -extern unsigned long randomize_et_dyn(unsigned long base);
3743 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
3744 +#define ELF_ET_DYN_BASE (0x20000000)
3745 +
3746 +#ifdef CONFIG_PAX_ASLR
3747 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3748 +
3749 +#ifdef __powerpc64__
3750 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
3751 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
3752 +#else
3753 +#define PAX_DELTA_MMAP_LEN 15
3754 +#define PAX_DELTA_STACK_LEN 15
3755 +#endif
3756 +#endif
3757
3758 /*
3759 * Our registers are always unsigned longs, whether we're a 32 bit
3760 @@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3761 (0x7ff >> (PAGE_SHIFT - 12)) : \
3762 (0x3ffff >> (PAGE_SHIFT - 12)))
3763
3764 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3765 -#define arch_randomize_brk arch_randomize_brk
3766 -
3767 #endif /* __KERNEL__ */
3768
3769 /*
3770 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
3771 index 8196e9c..d83a9f3 100644
3772 --- a/arch/powerpc/include/asm/exec.h
3773 +++ b/arch/powerpc/include/asm/exec.h
3774 @@ -4,6 +4,6 @@
3775 #ifndef _ASM_POWERPC_EXEC_H
3776 #define _ASM_POWERPC_EXEC_H
3777
3778 -extern unsigned long arch_align_stack(unsigned long sp);
3779 +#define arch_align_stack(x) ((x) & ~0xfUL)
3780
3781 #endif /* _ASM_POWERPC_EXEC_H */
3782 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
3783 index 5acabbd..7ea14fa 100644
3784 --- a/arch/powerpc/include/asm/kmap_types.h
3785 +++ b/arch/powerpc/include/asm/kmap_types.h
3786 @@ -10,7 +10,7 @@
3787 * 2 of the License, or (at your option) any later version.
3788 */
3789
3790 -#define KM_TYPE_NR 16
3791 +#define KM_TYPE_NR 17
3792
3793 #endif /* __KERNEL__ */
3794 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
3795 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
3796 index d4a7f64..451de1c 100644
3797 --- a/arch/powerpc/include/asm/mman.h
3798 +++ b/arch/powerpc/include/asm/mman.h
3799 @@ -44,7 +44,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
3800 }
3801 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
3802
3803 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
3804 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
3805 {
3806 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
3807 }
3808 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
3809 index f072e97..b436dee 100644
3810 --- a/arch/powerpc/include/asm/page.h
3811 +++ b/arch/powerpc/include/asm/page.h
3812 @@ -220,8 +220,9 @@ extern long long virt_phys_offset;
3813 * and needs to be executable. This means the whole heap ends
3814 * up being executable.
3815 */
3816 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3817 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3818 +#define VM_DATA_DEFAULT_FLAGS32 \
3819 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3820 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3821
3822 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3823 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3824 @@ -249,6 +250,9 @@ extern long long virt_phys_offset;
3825 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
3826 #endif
3827
3828 +#define ktla_ktva(addr) (addr)
3829 +#define ktva_ktla(addr) (addr)
3830 +
3831 /*
3832 * Use the top bit of the higher-level page table entries to indicate whether
3833 * the entries we point to contain hugepages. This works because we know that
3834 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
3835 index fed85e6..da5c71b 100644
3836 --- a/arch/powerpc/include/asm/page_64.h
3837 +++ b/arch/powerpc/include/asm/page_64.h
3838 @@ -146,15 +146,18 @@ do { \
3839 * stack by default, so in the absence of a PT_GNU_STACK program header
3840 * we turn execute permission off.
3841 */
3842 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3843 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3844 +#define VM_STACK_DEFAULT_FLAGS32 \
3845 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3846 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3847
3848 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3849 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3850
3851 +#ifndef CONFIG_PAX_PAGEEXEC
3852 #define VM_STACK_DEFAULT_FLAGS \
3853 (is_32bit_task() ? \
3854 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
3855 +#endif
3856
3857 #include <asm-generic/getorder.h>
3858
3859 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
3860 index 292725c..f87ae14 100644
3861 --- a/arch/powerpc/include/asm/pgalloc-64.h
3862 +++ b/arch/powerpc/include/asm/pgalloc-64.h
3863 @@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
3864 #ifndef CONFIG_PPC_64K_PAGES
3865
3866 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
3867 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
3868
3869 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
3870 {
3871 @@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3872 pud_set(pud, (unsigned long)pmd);
3873 }
3874
3875 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3876 +{
3877 + pud_populate(mm, pud, pmd);
3878 +}
3879 +
3880 #define pmd_populate(mm, pmd, pte_page) \
3881 pmd_populate_kernel(mm, pmd, page_address(pte_page))
3882 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
3883 @@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3884 #else /* CONFIG_PPC_64K_PAGES */
3885
3886 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
3887 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
3888
3889 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
3890 pte_t *pte)
3891 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
3892 index 2e0e411..7899c68 100644
3893 --- a/arch/powerpc/include/asm/pgtable.h
3894 +++ b/arch/powerpc/include/asm/pgtable.h
3895 @@ -2,6 +2,7 @@
3896 #define _ASM_POWERPC_PGTABLE_H
3897 #ifdef __KERNEL__
3898
3899 +#include <linux/const.h>
3900 #ifndef __ASSEMBLY__
3901 #include <asm/processor.h> /* For TASK_SIZE */
3902 #include <asm/mmu.h>
3903 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
3904 index 4aad413..85d86bf 100644
3905 --- a/arch/powerpc/include/asm/pte-hash32.h
3906 +++ b/arch/powerpc/include/asm/pte-hash32.h
3907 @@ -21,6 +21,7 @@
3908 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
3909 #define _PAGE_USER 0x004 /* usermode access allowed */
3910 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
3911 +#define _PAGE_EXEC _PAGE_GUARDED
3912 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
3913 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
3914 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
3915 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
3916 index 6386086..6982225 100644
3917 --- a/arch/powerpc/include/asm/reg.h
3918 +++ b/arch/powerpc/include/asm/reg.h
3919 @@ -212,6 +212,7 @@
3920 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
3921 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
3922 #define DSISR_NOHPTE 0x40000000 /* no translation found */
3923 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
3924 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
3925 #define DSISR_ISSTORE 0x02000000 /* access was a store */
3926 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
3927 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
3928 index faf9352..ab2ccec 100644
3929 --- a/arch/powerpc/include/asm/thread_info.h
3930 +++ b/arch/powerpc/include/asm/thread_info.h
3931 @@ -97,12 +97,14 @@ static inline struct thread_info *current_thread_info(void)
3932 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
3933 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
3934 #define TIF_SINGLESTEP 8 /* singlestepping active */
3935 -#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
3936 #define TIF_SECCOMP 10 /* secure computing */
3937 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
3938 #define TIF_NOERROR 12 /* Force successful syscall return */
3939 #define TIF_NOTIFY_RESUME 13 /* callback before returning to user */
3940 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
3941 +#define TIF_MEMDIE 16 /* is terminating due to OOM killer */
3942 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
3943 +#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
3944
3945 /* as above, but as bit values */
3946 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
3947 @@ -119,8 +121,10 @@ static inline struct thread_info *current_thread_info(void)
3948 #define _TIF_NOERROR (1<<TIF_NOERROR)
3949 #define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
3950 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
3951 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
3952 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
3953 - _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
3954 + _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
3955 + _TIF_GRSEC_SETXID)
3956
3957 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
3958 _TIF_NOTIFY_RESUME)
3959 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
3960 index 17bb40c..353c98b 100644
3961 --- a/arch/powerpc/include/asm/uaccess.h
3962 +++ b/arch/powerpc/include/asm/uaccess.h
3963 @@ -13,6 +13,8 @@
3964 #define VERIFY_READ 0
3965 #define VERIFY_WRITE 1
3966
3967 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
3968 +
3969 /*
3970 * The fs value determines whether argument validity checking should be
3971 * performed or not. If get_fs() == USER_DS, checking is performed, with
3972 @@ -329,52 +331,6 @@ do { \
3973 extern unsigned long __copy_tofrom_user(void __user *to,
3974 const void __user *from, unsigned long size);
3975
3976 -#ifndef __powerpc64__
3977 -
3978 -static inline unsigned long copy_from_user(void *to,
3979 - const void __user *from, unsigned long n)
3980 -{
3981 - unsigned long over;
3982 -
3983 - if (access_ok(VERIFY_READ, from, n))
3984 - return __copy_tofrom_user((__force void __user *)to, from, n);
3985 - if ((unsigned long)from < TASK_SIZE) {
3986 - over = (unsigned long)from + n - TASK_SIZE;
3987 - return __copy_tofrom_user((__force void __user *)to, from,
3988 - n - over) + over;
3989 - }
3990 - return n;
3991 -}
3992 -
3993 -static inline unsigned long copy_to_user(void __user *to,
3994 - const void *from, unsigned long n)
3995 -{
3996 - unsigned long over;
3997 -
3998 - if (access_ok(VERIFY_WRITE, to, n))
3999 - return __copy_tofrom_user(to, (__force void __user *)from, n);
4000 - if ((unsigned long)to < TASK_SIZE) {
4001 - over = (unsigned long)to + n - TASK_SIZE;
4002 - return __copy_tofrom_user(to, (__force void __user *)from,
4003 - n - over) + over;
4004 - }
4005 - return n;
4006 -}
4007 -
4008 -#else /* __powerpc64__ */
4009 -
4010 -#define __copy_in_user(to, from, size) \
4011 - __copy_tofrom_user((to), (from), (size))
4012 -
4013 -extern unsigned long copy_from_user(void *to, const void __user *from,
4014 - unsigned long n);
4015 -extern unsigned long copy_to_user(void __user *to, const void *from,
4016 - unsigned long n);
4017 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
4018 - unsigned long n);
4019 -
4020 -#endif /* __powerpc64__ */
4021 -
4022 static inline unsigned long __copy_from_user_inatomic(void *to,
4023 const void __user *from, unsigned long n)
4024 {
4025 @@ -398,6 +354,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
4026 if (ret == 0)
4027 return 0;
4028 }
4029 +
4030 + if (!__builtin_constant_p(n))
4031 + check_object_size(to, n, false);
4032 +
4033 return __copy_tofrom_user((__force void __user *)to, from, n);
4034 }
4035
4036 @@ -424,6 +384,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
4037 if (ret == 0)
4038 return 0;
4039 }
4040 +
4041 + if (!__builtin_constant_p(n))
4042 + check_object_size(from, n, true);
4043 +
4044 return __copy_tofrom_user(to, (__force const void __user *)from, n);
4045 }
4046
4047 @@ -441,6 +405,92 @@ static inline unsigned long __copy_to_user(void __user *to,
4048 return __copy_to_user_inatomic(to, from, size);
4049 }
4050
4051 +#ifndef __powerpc64__
4052 +
4053 +static inline unsigned long __must_check copy_from_user(void *to,
4054 + const void __user *from, unsigned long n)
4055 +{
4056 + unsigned long over;
4057 +
4058 + if ((long)n < 0)
4059 + return n;
4060 +
4061 + if (access_ok(VERIFY_READ, from, n)) {
4062 + if (!__builtin_constant_p(n))
4063 + check_object_size(to, n, false);
4064 + return __copy_tofrom_user((__force void __user *)to, from, n);
4065 + }
4066 + if ((unsigned long)from < TASK_SIZE) {
4067 + over = (unsigned long)from + n - TASK_SIZE;
4068 + if (!__builtin_constant_p(n - over))
4069 + check_object_size(to, n - over, false);
4070 + return __copy_tofrom_user((__force void __user *)to, from,
4071 + n - over) + over;
4072 + }
4073 + return n;
4074 +}
4075 +
4076 +static inline unsigned long __must_check copy_to_user(void __user *to,
4077 + const void *from, unsigned long n)
4078 +{
4079 + unsigned long over;
4080 +
4081 + if ((long)n < 0)
4082 + return n;
4083 +
4084 + if (access_ok(VERIFY_WRITE, to, n)) {
4085 + if (!__builtin_constant_p(n))
4086 + check_object_size(from, n, true);
4087 + return __copy_tofrom_user(to, (__force void __user *)from, n);
4088 + }
4089 + if ((unsigned long)to < TASK_SIZE) {
4090 + over = (unsigned long)to + n - TASK_SIZE;
4091 + if (!__builtin_constant_p(n))
4092 + check_object_size(from, n - over, true);
4093 + return __copy_tofrom_user(to, (__force void __user *)from,
4094 + n - over) + over;
4095 + }
4096 + return n;
4097 +}
4098 +
4099 +#else /* __powerpc64__ */
4100 +
4101 +#define __copy_in_user(to, from, size) \
4102 + __copy_tofrom_user((to), (from), (size))
4103 +
4104 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
4105 +{
4106 + if ((long)n < 0 || n > INT_MAX)
4107 + return n;
4108 +
4109 + if (!__builtin_constant_p(n))
4110 + check_object_size(to, n, false);
4111 +
4112 + if (likely(access_ok(VERIFY_READ, from, n)))
4113 + n = __copy_from_user(to, from, n);
4114 + else
4115 + memset(to, 0, n);
4116 + return n;
4117 +}
4118 +
4119 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
4120 +{
4121 + if ((long)n < 0 || n > INT_MAX)
4122 + return n;
4123 +
4124 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
4125 + if (!__builtin_constant_p(n))
4126 + check_object_size(from, n, true);
4127 + n = __copy_to_user(to, from, n);
4128 + }
4129 + return n;
4130 +}
4131 +
4132 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
4133 + unsigned long n);
4134 +
4135 +#endif /* __powerpc64__ */
4136 +
4137 extern unsigned long __clear_user(void __user *addr, unsigned long size);
4138
4139 static inline unsigned long clear_user(void __user *addr, unsigned long size)
4140 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
4141 index 98be7f0..8ef62de 100644
4142 --- a/arch/powerpc/kernel/exceptions-64e.S
4143 +++ b/arch/powerpc/kernel/exceptions-64e.S
4144 @@ -661,6 +661,7 @@ storage_fault_common:
4145 std r14,_DAR(r1)
4146 std r15,_DSISR(r1)
4147 addi r3,r1,STACK_FRAME_OVERHEAD
4148 + bl .save_nvgprs
4149 mr r4,r14
4150 mr r5,r15
4151 ld r14,PACA_EXGEN+EX_R14(r13)
4152 @@ -669,8 +670,7 @@ storage_fault_common:
4153 cmpdi r3,0
4154 bne- 1f
4155 b .ret_from_except_lite
4156 -1: bl .save_nvgprs
4157 - mr r5,r3
4158 +1: mr r5,r3
4159 addi r3,r1,STACK_FRAME_OVERHEAD
4160 ld r4,_DAR(r1)
4161 bl .bad_page_fault
4162 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
4163 index 39aa97d..dc916ee 100644
4164 --- a/arch/powerpc/kernel/exceptions-64s.S
4165 +++ b/arch/powerpc/kernel/exceptions-64s.S
4166 @@ -890,10 +890,10 @@ handle_page_fault:
4167 11: ld r4,_DAR(r1)
4168 ld r5,_DSISR(r1)
4169 addi r3,r1,STACK_FRAME_OVERHEAD
4170 + bl .save_nvgprs
4171 bl .do_page_fault
4172 cmpdi r3,0
4173 beq+ 12f
4174 - bl .save_nvgprs
4175 mr r5,r3
4176 addi r3,r1,STACK_FRAME_OVERHEAD
4177 lwz r4,_DAR(r1)
4178 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
4179 index 2e3200c..72095ce 100644
4180 --- a/arch/powerpc/kernel/module_32.c
4181 +++ b/arch/powerpc/kernel/module_32.c
4182 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
4183 me->arch.core_plt_section = i;
4184 }
4185 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
4186 - printk("Module doesn't contain .plt or .init.plt sections.\n");
4187 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
4188 return -ENOEXEC;
4189 }
4190
4191 @@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
4192
4193 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
4194 /* Init, or core PLT? */
4195 - if (location >= mod->module_core
4196 - && location < mod->module_core + mod->core_size)
4197 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
4198 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
4199 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
4200 - else
4201 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
4202 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
4203 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
4204 + else {
4205 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
4206 + return ~0UL;
4207 + }
4208
4209 /* Find this entry, or if that fails, the next avail. entry */
4210 while (entry->jump[0]) {
4211 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
4212 index 1a1f2dd..f4d1bb4 100644
4213 --- a/arch/powerpc/kernel/process.c
4214 +++ b/arch/powerpc/kernel/process.c
4215 @@ -681,8 +681,8 @@ void show_regs(struct pt_regs * regs)
4216 * Lookup NIP late so we have the best change of getting the
4217 * above info out without failing
4218 */
4219 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
4220 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
4221 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
4222 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
4223 #endif
4224 show_stack(current, (unsigned long *) regs->gpr[1]);
4225 if (!user_mode(regs))
4226 @@ -1181,10 +1181,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4227 newsp = stack[0];
4228 ip = stack[STACK_FRAME_LR_SAVE];
4229 if (!firstframe || ip != lr) {
4230 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
4231 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
4232 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
4233 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
4234 - printk(" (%pS)",
4235 + printk(" (%pA)",
4236 (void *)current->ret_stack[curr_frame].ret);
4237 curr_frame--;
4238 }
4239 @@ -1204,7 +1204,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4240 struct pt_regs *regs = (struct pt_regs *)
4241 (sp + STACK_FRAME_OVERHEAD);
4242 lr = regs->link;
4243 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
4244 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
4245 regs->trap, (void *)regs->nip, (void *)lr);
4246 firstframe = 1;
4247 }
4248 @@ -1246,58 +1246,3 @@ void __ppc64_runlatch_off(void)
4249 mtspr(SPRN_CTRLT, ctrl);
4250 }
4251 #endif /* CONFIG_PPC64 */
4252 -
4253 -unsigned long arch_align_stack(unsigned long sp)
4254 -{
4255 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4256 - sp -= get_random_int() & ~PAGE_MASK;
4257 - return sp & ~0xf;
4258 -}
4259 -
4260 -static inline unsigned long brk_rnd(void)
4261 -{
4262 - unsigned long rnd = 0;
4263 -
4264 - /* 8MB for 32bit, 1GB for 64bit */
4265 - if (is_32bit_task())
4266 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
4267 - else
4268 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
4269 -
4270 - return rnd << PAGE_SHIFT;
4271 -}
4272 -
4273 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4274 -{
4275 - unsigned long base = mm->brk;
4276 - unsigned long ret;
4277 -
4278 -#ifdef CONFIG_PPC_STD_MMU_64
4279 - /*
4280 - * If we are using 1TB segments and we are allowed to randomise
4281 - * the heap, we can put it above 1TB so it is backed by a 1TB
4282 - * segment. Otherwise the heap will be in the bottom 1TB
4283 - * which always uses 256MB segments and this may result in a
4284 - * performance penalty.
4285 - */
4286 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
4287 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
4288 -#endif
4289 -
4290 - ret = PAGE_ALIGN(base + brk_rnd());
4291 -
4292 - if (ret < mm->brk)
4293 - return mm->brk;
4294 -
4295 - return ret;
4296 -}
4297 -
4298 -unsigned long randomize_et_dyn(unsigned long base)
4299 -{
4300 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4301 -
4302 - if (ret < base)
4303 - return base;
4304 -
4305 - return ret;
4306 -}
4307 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
4308 index c10fc28..c4ef063 100644
4309 --- a/arch/powerpc/kernel/ptrace.c
4310 +++ b/arch/powerpc/kernel/ptrace.c
4311 @@ -1660,6 +1660,10 @@ long arch_ptrace(struct task_struct *child, long request,
4312 return ret;
4313 }
4314
4315 +#ifdef CONFIG_GRKERNSEC_SETXID
4316 +extern void gr_delayed_cred_worker(void);
4317 +#endif
4318 +
4319 /*
4320 * We must return the syscall number to actually look up in the table.
4321 * This can be -1L to skip running any syscall at all.
4322 @@ -1670,6 +1674,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
4323
4324 secure_computing_strict(regs->gpr[0]);
4325
4326 +#ifdef CONFIG_GRKERNSEC_SETXID
4327 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4328 + gr_delayed_cred_worker();
4329 +#endif
4330 +
4331 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
4332 tracehook_report_syscall_entry(regs))
4333 /*
4334 @@ -1704,6 +1713,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
4335 {
4336 int step;
4337
4338 +#ifdef CONFIG_GRKERNSEC_SETXID
4339 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4340 + gr_delayed_cred_worker();
4341 +#endif
4342 +
4343 audit_syscall_exit(regs);
4344
4345 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
4346 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
4347 index 8b4c049..dcd6ef3 100644
4348 --- a/arch/powerpc/kernel/signal_32.c
4349 +++ b/arch/powerpc/kernel/signal_32.c
4350 @@ -852,7 +852,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
4351 /* Save user registers on the stack */
4352 frame = &rt_sf->uc.uc_mcontext;
4353 addr = frame;
4354 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
4355 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4356 if (save_user_regs(regs, frame, 0, 1))
4357 goto badframe;
4358 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
4359 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
4360 index d183f87..1867f1a 100644
4361 --- a/arch/powerpc/kernel/signal_64.c
4362 +++ b/arch/powerpc/kernel/signal_64.c
4363 @@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
4364 current->thread.fpscr.val = 0;
4365
4366 /* Set up to return from userspace. */
4367 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
4368 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4369 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
4370 } else {
4371 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
4372 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
4373 index ae0843f..f16372c 100644
4374 --- a/arch/powerpc/kernel/traps.c
4375 +++ b/arch/powerpc/kernel/traps.c
4376 @@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
4377 return flags;
4378 }
4379
4380 +extern void gr_handle_kernel_exploit(void);
4381 +
4382 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4383 int signr)
4384 {
4385 @@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4386 panic("Fatal exception in interrupt");
4387 if (panic_on_oops)
4388 panic("Fatal exception");
4389 +
4390 + gr_handle_kernel_exploit();
4391 +
4392 do_exit(signr);
4393 }
4394
4395 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
4396 index b67db22..38825d2 100644
4397 --- a/arch/powerpc/kernel/vdso.c
4398 +++ b/arch/powerpc/kernel/vdso.c
4399 @@ -34,6 +34,7 @@
4400 #include <asm/firmware.h>
4401 #include <asm/vdso.h>
4402 #include <asm/vdso_datapage.h>
4403 +#include <asm/mman.h>
4404
4405 #include "setup.h"
4406
4407 @@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4408 vdso_base = VDSO32_MBASE;
4409 #endif
4410
4411 - current->mm->context.vdso_base = 0;
4412 + current->mm->context.vdso_base = ~0UL;
4413
4414 /* vDSO has a problem and was disabled, just don't "enable" it for the
4415 * process
4416 @@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4417 vdso_base = get_unmapped_area(NULL, vdso_base,
4418 (vdso_pages << PAGE_SHIFT) +
4419 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
4420 - 0, 0);
4421 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
4422 if (IS_ERR_VALUE(vdso_base)) {
4423 rc = vdso_base;
4424 goto fail_mmapsem;
4425 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
4426 index 5eea6f3..5d10396 100644
4427 --- a/arch/powerpc/lib/usercopy_64.c
4428 +++ b/arch/powerpc/lib/usercopy_64.c
4429 @@ -9,22 +9,6 @@
4430 #include <linux/module.h>
4431 #include <asm/uaccess.h>
4432
4433 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4434 -{
4435 - if (likely(access_ok(VERIFY_READ, from, n)))
4436 - n = __copy_from_user(to, from, n);
4437 - else
4438 - memset(to, 0, n);
4439 - return n;
4440 -}
4441 -
4442 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4443 -{
4444 - if (likely(access_ok(VERIFY_WRITE, to, n)))
4445 - n = __copy_to_user(to, from, n);
4446 - return n;
4447 -}
4448 -
4449 unsigned long copy_in_user(void __user *to, const void __user *from,
4450 unsigned long n)
4451 {
4452 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
4453 return n;
4454 }
4455
4456 -EXPORT_SYMBOL(copy_from_user);
4457 -EXPORT_SYMBOL(copy_to_user);
4458 EXPORT_SYMBOL(copy_in_user);
4459
4460 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
4461 index 08ffcf5..a0ab912 100644
4462 --- a/arch/powerpc/mm/fault.c
4463 +++ b/arch/powerpc/mm/fault.c
4464 @@ -32,6 +32,10 @@
4465 #include <linux/perf_event.h>
4466 #include <linux/magic.h>
4467 #include <linux/ratelimit.h>
4468 +#include <linux/slab.h>
4469 +#include <linux/pagemap.h>
4470 +#include <linux/compiler.h>
4471 +#include <linux/unistd.h>
4472
4473 #include <asm/firmware.h>
4474 #include <asm/page.h>
4475 @@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
4476 }
4477 #endif
4478
4479 +#ifdef CONFIG_PAX_PAGEEXEC
4480 +/*
4481 + * PaX: decide what to do with offenders (regs->nip = fault address)
4482 + *
4483 + * returns 1 when task should be killed
4484 + */
4485 +static int pax_handle_fetch_fault(struct pt_regs *regs)
4486 +{
4487 + return 1;
4488 +}
4489 +
4490 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4491 +{
4492 + unsigned long i;
4493 +
4494 + printk(KERN_ERR "PAX: bytes at PC: ");
4495 + for (i = 0; i < 5; i++) {
4496 + unsigned int c;
4497 + if (get_user(c, (unsigned int __user *)pc+i))
4498 + printk(KERN_CONT "???????? ");
4499 + else
4500 + printk(KERN_CONT "%08x ", c);
4501 + }
4502 + printk("\n");
4503 +}
4504 +#endif
4505 +
4506 /*
4507 * Check whether the instruction at regs->nip is a store using
4508 * an update addressing form which will update r1.
4509 @@ -215,7 +246,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
4510 * indicate errors in DSISR but can validly be set in SRR1.
4511 */
4512 if (trap == 0x400)
4513 - error_code &= 0x48200000;
4514 + error_code &= 0x58200000;
4515 else
4516 is_write = error_code & DSISR_ISSTORE;
4517 #else
4518 @@ -366,7 +397,7 @@ good_area:
4519 * "undefined". Of those that can be set, this is the only
4520 * one which seems bad.
4521 */
4522 - if (error_code & 0x10000000)
4523 + if (error_code & DSISR_GUARDED)
4524 /* Guarded storage error. */
4525 goto bad_area;
4526 #endif /* CONFIG_8xx */
4527 @@ -381,7 +412,7 @@ good_area:
4528 * processors use the same I/D cache coherency mechanism
4529 * as embedded.
4530 */
4531 - if (error_code & DSISR_PROTFAULT)
4532 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
4533 goto bad_area;
4534 #endif /* CONFIG_PPC_STD_MMU */
4535
4536 @@ -463,6 +494,23 @@ bad_area:
4537 bad_area_nosemaphore:
4538 /* User mode accesses cause a SIGSEGV */
4539 if (user_mode(regs)) {
4540 +
4541 +#ifdef CONFIG_PAX_PAGEEXEC
4542 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4543 +#ifdef CONFIG_PPC_STD_MMU
4544 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
4545 +#else
4546 + if (is_exec && regs->nip == address) {
4547 +#endif
4548 + switch (pax_handle_fetch_fault(regs)) {
4549 + }
4550 +
4551 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
4552 + do_group_exit(SIGKILL);
4553 + }
4554 + }
4555 +#endif
4556 +
4557 _exception(SIGSEGV, regs, code, address);
4558 return 0;
4559 }
4560 diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
4561 index 67a42ed..1c7210c 100644
4562 --- a/arch/powerpc/mm/mmap_64.c
4563 +++ b/arch/powerpc/mm/mmap_64.c
4564 @@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4565 */
4566 if (mmap_is_legacy()) {
4567 mm->mmap_base = TASK_UNMAPPED_BASE;
4568 +
4569 +#ifdef CONFIG_PAX_RANDMMAP
4570 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4571 + mm->mmap_base += mm->delta_mmap;
4572 +#endif
4573 +
4574 mm->get_unmapped_area = arch_get_unmapped_area;
4575 mm->unmap_area = arch_unmap_area;
4576 } else {
4577 mm->mmap_base = mmap_base();
4578 +
4579 +#ifdef CONFIG_PAX_RANDMMAP
4580 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4581 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4582 +#endif
4583 +
4584 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4585 mm->unmap_area = arch_unmap_area_topdown;
4586 }
4587 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
4588 index 73709f7..6b90313 100644
4589 --- a/arch/powerpc/mm/slice.c
4590 +++ b/arch/powerpc/mm/slice.c
4591 @@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
4592 if ((mm->task_size - len) < addr)
4593 return 0;
4594 vma = find_vma(mm, addr);
4595 - return (!vma || (addr + len) <= vma->vm_start);
4596 + return check_heap_stack_gap(vma, addr, len);
4597 }
4598
4599 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
4600 @@ -256,7 +256,7 @@ full_search:
4601 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
4602 continue;
4603 }
4604 - if (!vma || addr + len <= vma->vm_start) {
4605 + if (check_heap_stack_gap(vma, addr, len)) {
4606 /*
4607 * Remember the place where we stopped the search:
4608 */
4609 @@ -313,10 +313,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4610 }
4611 }
4612
4613 - addr = mm->mmap_base;
4614 - while (addr > len) {
4615 + if (mm->mmap_base < len)
4616 + addr = -ENOMEM;
4617 + else
4618 + addr = mm->mmap_base - len;
4619 +
4620 + while (!IS_ERR_VALUE(addr)) {
4621 /* Go down by chunk size */
4622 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
4623 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
4624
4625 /* Check for hit with different page size */
4626 mask = slice_range_to_mask(addr, len);
4627 @@ -336,7 +340,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4628 * return with success:
4629 */
4630 vma = find_vma(mm, addr);
4631 - if (!vma || (addr + len) <= vma->vm_start) {
4632 + if (check_heap_stack_gap(vma, addr, len)) {
4633 /* remember the address as a hint for next time */
4634 if (use_cache)
4635 mm->free_area_cache = addr;
4636 @@ -348,7 +352,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4637 mm->cached_hole_size = vma->vm_start - addr;
4638
4639 /* try just below the current vma->vm_start */
4640 - addr = vma->vm_start;
4641 + addr = skip_heap_stack_gap(vma, len);
4642 }
4643
4644 /*
4645 @@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
4646 if (fixed && addr > (mm->task_size - len))
4647 return -EINVAL;
4648
4649 +#ifdef CONFIG_PAX_RANDMMAP
4650 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
4651 + addr = 0;
4652 +#endif
4653 +
4654 /* If hint, make sure it matches our alignment restrictions */
4655 if (!fixed && addr) {
4656 addr = _ALIGN_UP(addr, 1ul << pshift);
4657 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
4658 index c797832..ce575c8 100644
4659 --- a/arch/s390/include/asm/atomic.h
4660 +++ b/arch/s390/include/asm/atomic.h
4661 @@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
4662 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
4663 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4664
4665 +#define atomic64_read_unchecked(v) atomic64_read(v)
4666 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4667 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4668 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4669 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4670 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4671 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4672 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4673 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4674 +
4675 #define smp_mb__before_atomic_dec() smp_mb()
4676 #define smp_mb__after_atomic_dec() smp_mb()
4677 #define smp_mb__before_atomic_inc() smp_mb()
4678 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
4679 index 4d7ccac..d03d0ad 100644
4680 --- a/arch/s390/include/asm/cache.h
4681 +++ b/arch/s390/include/asm/cache.h
4682 @@ -9,8 +9,10 @@
4683 #ifndef __ARCH_S390_CACHE_H
4684 #define __ARCH_S390_CACHE_H
4685
4686 -#define L1_CACHE_BYTES 256
4687 +#include <linux/const.h>
4688 +
4689 #define L1_CACHE_SHIFT 8
4690 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4691 #define NET_SKB_PAD 32
4692
4693 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4694 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
4695 index 9b94a16..63d4034 100644
4696 --- a/arch/s390/include/asm/elf.h
4697 +++ b/arch/s390/include/asm/elf.h
4698 @@ -159,8 +159,14 @@ extern unsigned int vdso_enabled;
4699 the loader. We need to make sure that it is out of the way of the program
4700 that it will "exec", and that there is sufficient room for the brk. */
4701
4702 -extern unsigned long randomize_et_dyn(unsigned long base);
4703 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
4704 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
4705 +
4706 +#ifdef CONFIG_PAX_ASLR
4707 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
4708 +
4709 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4710 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4711 +#endif
4712
4713 /* This yields a mask that user programs can use to figure out what
4714 instruction set this CPU supports. */
4715 @@ -209,7 +215,4 @@ struct linux_binprm;
4716 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4717 int arch_setup_additional_pages(struct linux_binprm *, int);
4718
4719 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4720 -#define arch_randomize_brk arch_randomize_brk
4721 -
4722 #endif
4723 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
4724 index c4a93d6..4d2a9b4 100644
4725 --- a/arch/s390/include/asm/exec.h
4726 +++ b/arch/s390/include/asm/exec.h
4727 @@ -7,6 +7,6 @@
4728 #ifndef __ASM_EXEC_H
4729 #define __ASM_EXEC_H
4730
4731 -extern unsigned long arch_align_stack(unsigned long sp);
4732 +#define arch_align_stack(x) ((x) & ~0xfUL)
4733
4734 #endif /* __ASM_EXEC_H */
4735 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
4736 index a8ab18b..75ddbf0 100644
4737 --- a/arch/s390/include/asm/uaccess.h
4738 +++ b/arch/s390/include/asm/uaccess.h
4739 @@ -239,6 +239,10 @@ static inline unsigned long __must_check
4740 copy_to_user(void __user *to, const void *from, unsigned long n)
4741 {
4742 might_fault();
4743 +
4744 + if ((long)n < 0)
4745 + return n;
4746 +
4747 if (access_ok(VERIFY_WRITE, to, n))
4748 n = __copy_to_user(to, from, n);
4749 return n;
4750 @@ -264,6 +268,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
4751 static inline unsigned long __must_check
4752 __copy_from_user(void *to, const void __user *from, unsigned long n)
4753 {
4754 + if ((long)n < 0)
4755 + return n;
4756 +
4757 if (__builtin_constant_p(n) && (n <= 256))
4758 return uaccess.copy_from_user_small(n, from, to);
4759 else
4760 @@ -295,10 +302,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
4761 static inline unsigned long __must_check
4762 copy_from_user(void *to, const void __user *from, unsigned long n)
4763 {
4764 - unsigned int sz = __compiletime_object_size(to);
4765 + size_t sz = __compiletime_object_size(to);
4766
4767 might_fault();
4768 - if (unlikely(sz != -1 && sz < n)) {
4769 +
4770 + if ((long)n < 0)
4771 + return n;
4772 +
4773 + if (unlikely(sz != (size_t)-1 && sz < n)) {
4774 copy_from_user_overflow();
4775 return n;
4776 }
4777 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
4778 index 46412b1..e32874f 100644
4779 --- a/arch/s390/kernel/module.c
4780 +++ b/arch/s390/kernel/module.c
4781 @@ -160,11 +160,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
4782
4783 /* Increase core size by size of got & plt and set start
4784 offsets for got and plt. */
4785 - me->core_size = ALIGN(me->core_size, 4);
4786 - me->arch.got_offset = me->core_size;
4787 - me->core_size += me->arch.got_size;
4788 - me->arch.plt_offset = me->core_size;
4789 - me->core_size += me->arch.plt_size;
4790 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
4791 + me->arch.got_offset = me->core_size_rw;
4792 + me->core_size_rw += me->arch.got_size;
4793 + me->arch.plt_offset = me->core_size_rx;
4794 + me->core_size_rx += me->arch.plt_size;
4795 return 0;
4796 }
4797
4798 @@ -241,7 +241,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4799 if (info->got_initialized == 0) {
4800 Elf_Addr *gotent;
4801
4802 - gotent = me->module_core + me->arch.got_offset +
4803 + gotent = me->module_core_rw + me->arch.got_offset +
4804 info->got_offset;
4805 *gotent = val;
4806 info->got_initialized = 1;
4807 @@ -265,7 +265,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4808 else if (r_type == R_390_GOTENT ||
4809 r_type == R_390_GOTPLTENT)
4810 *(unsigned int *) loc =
4811 - (val + (Elf_Addr) me->module_core - loc) >> 1;
4812 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4813 else if (r_type == R_390_GOT64 ||
4814 r_type == R_390_GOTPLT64)
4815 *(unsigned long *) loc = val;
4816 @@ -279,7 +279,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4817 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4818 if (info->plt_initialized == 0) {
4819 unsigned int *ip;
4820 - ip = me->module_core + me->arch.plt_offset +
4821 + ip = me->module_core_rx + me->arch.plt_offset +
4822 info->plt_offset;
4823 #ifndef CONFIG_64BIT
4824 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4825 @@ -304,7 +304,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4826 val - loc + 0xffffUL < 0x1ffffeUL) ||
4827 (r_type == R_390_PLT32DBL &&
4828 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
4829 - val = (Elf_Addr) me->module_core +
4830 + val = (Elf_Addr) me->module_core_rx +
4831 me->arch.plt_offset +
4832 info->plt_offset;
4833 val += rela->r_addend - loc;
4834 @@ -326,7 +326,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4835 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4836 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4837 val = val + rela->r_addend -
4838 - ((Elf_Addr) me->module_core + me->arch.got_offset);
4839 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4840 if (r_type == R_390_GOTOFF16)
4841 *(unsigned short *) loc = val;
4842 else if (r_type == R_390_GOTOFF32)
4843 @@ -336,7 +336,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4844 break;
4845 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4846 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4847 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
4848 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4849 rela->r_addend - loc;
4850 if (r_type == R_390_GOTPC)
4851 *(unsigned int *) loc = val;
4852 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
4853 index 7331753..dd71de4 100644
4854 --- a/arch/s390/kernel/process.c
4855 +++ b/arch/s390/kernel/process.c
4856 @@ -316,39 +316,3 @@ unsigned long get_wchan(struct task_struct *p)
4857 }
4858 return 0;
4859 }
4860 -
4861 -unsigned long arch_align_stack(unsigned long sp)
4862 -{
4863 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4864 - sp -= get_random_int() & ~PAGE_MASK;
4865 - return sp & ~0xf;
4866 -}
4867 -
4868 -static inline unsigned long brk_rnd(void)
4869 -{
4870 - /* 8MB for 32bit, 1GB for 64bit */
4871 - if (is_32bit_task())
4872 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
4873 - else
4874 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
4875 -}
4876 -
4877 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4878 -{
4879 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
4880 -
4881 - if (ret < mm->brk)
4882 - return mm->brk;
4883 - return ret;
4884 -}
4885 -
4886 -unsigned long randomize_et_dyn(unsigned long base)
4887 -{
4888 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4889 -
4890 - if (!(current->flags & PF_RANDOMIZE))
4891 - return base;
4892 - if (ret < base)
4893 - return base;
4894 - return ret;
4895 -}
4896 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
4897 index c59a5ef..3fae59c 100644
4898 --- a/arch/s390/mm/mmap.c
4899 +++ b/arch/s390/mm/mmap.c
4900 @@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4901 */
4902 if (mmap_is_legacy()) {
4903 mm->mmap_base = TASK_UNMAPPED_BASE;
4904 +
4905 +#ifdef CONFIG_PAX_RANDMMAP
4906 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4907 + mm->mmap_base += mm->delta_mmap;
4908 +#endif
4909 +
4910 mm->get_unmapped_area = arch_get_unmapped_area;
4911 mm->unmap_area = arch_unmap_area;
4912 } else {
4913 mm->mmap_base = mmap_base();
4914 +
4915 +#ifdef CONFIG_PAX_RANDMMAP
4916 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4917 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4918 +#endif
4919 +
4920 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4921 mm->unmap_area = arch_unmap_area_topdown;
4922 }
4923 @@ -172,10 +184,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4924 */
4925 if (mmap_is_legacy()) {
4926 mm->mmap_base = TASK_UNMAPPED_BASE;
4927 +
4928 +#ifdef CONFIG_PAX_RANDMMAP
4929 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4930 + mm->mmap_base += mm->delta_mmap;
4931 +#endif
4932 +
4933 mm->get_unmapped_area = s390_get_unmapped_area;
4934 mm->unmap_area = arch_unmap_area;
4935 } else {
4936 mm->mmap_base = mmap_base();
4937 +
4938 +#ifdef CONFIG_PAX_RANDMMAP
4939 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4940 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4941 +#endif
4942 +
4943 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4944 mm->unmap_area = arch_unmap_area_topdown;
4945 }
4946 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
4947 index ae3d59f..f65f075 100644
4948 --- a/arch/score/include/asm/cache.h
4949 +++ b/arch/score/include/asm/cache.h
4950 @@ -1,7 +1,9 @@
4951 #ifndef _ASM_SCORE_CACHE_H
4952 #define _ASM_SCORE_CACHE_H
4953
4954 +#include <linux/const.h>
4955 +
4956 #define L1_CACHE_SHIFT 4
4957 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4958 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4959
4960 #endif /* _ASM_SCORE_CACHE_H */
4961 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
4962 index f9f3cd5..58ff438 100644
4963 --- a/arch/score/include/asm/exec.h
4964 +++ b/arch/score/include/asm/exec.h
4965 @@ -1,6 +1,6 @@
4966 #ifndef _ASM_SCORE_EXEC_H
4967 #define _ASM_SCORE_EXEC_H
4968
4969 -extern unsigned long arch_align_stack(unsigned long sp);
4970 +#define arch_align_stack(x) (x)
4971
4972 #endif /* _ASM_SCORE_EXEC_H */
4973 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
4974 index 637970c..0b6556b 100644
4975 --- a/arch/score/kernel/process.c
4976 +++ b/arch/score/kernel/process.c
4977 @@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_struct *task)
4978
4979 return task_pt_regs(task)->cp0_epc;
4980 }
4981 -
4982 -unsigned long arch_align_stack(unsigned long sp)
4983 -{
4984 - return sp;
4985 -}
4986 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
4987 index ef9e555..331bd29 100644
4988 --- a/arch/sh/include/asm/cache.h
4989 +++ b/arch/sh/include/asm/cache.h
4990 @@ -9,10 +9,11 @@
4991 #define __ASM_SH_CACHE_H
4992 #ifdef __KERNEL__
4993
4994 +#include <linux/const.h>
4995 #include <linux/init.h>
4996 #include <cpu/cache.h>
4997
4998 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4999 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5000
5001 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5002
5003 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
5004 index afeb710..d1d1289 100644
5005 --- a/arch/sh/mm/mmap.c
5006 +++ b/arch/sh/mm/mmap.c
5007 @@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
5008 addr = PAGE_ALIGN(addr);
5009
5010 vma = find_vma(mm, addr);
5011 - if (TASK_SIZE - len >= addr &&
5012 - (!vma || addr + len <= vma->vm_start))
5013 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5014 return addr;
5015 }
5016
5017 @@ -106,7 +105,7 @@ full_search:
5018 }
5019 return -ENOMEM;
5020 }
5021 - if (likely(!vma || addr + len <= vma->vm_start)) {
5022 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5023 /*
5024 * Remember the place where we stopped the search:
5025 */
5026 @@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5027 addr = PAGE_ALIGN(addr);
5028
5029 vma = find_vma(mm, addr);
5030 - if (TASK_SIZE - len >= addr &&
5031 - (!vma || addr + len <= vma->vm_start))
5032 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5033 return addr;
5034 }
5035
5036 @@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5037 /* make sure it can fit in the remaining address space */
5038 if (likely(addr > len)) {
5039 vma = find_vma(mm, addr-len);
5040 - if (!vma || addr <= vma->vm_start) {
5041 + if (check_heap_stack_gap(vma, addr - len, len)) {
5042 /* remember the address as a hint for next time */
5043 return (mm->free_area_cache = addr-len);
5044 }
5045 @@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5046 if (unlikely(mm->mmap_base < len))
5047 goto bottomup;
5048
5049 - addr = mm->mmap_base-len;
5050 - if (do_colour_align)
5051 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5052 + addr = mm->mmap_base - len;
5053
5054 do {
5055 + if (do_colour_align)
5056 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5057 /*
5058 * Lookup failure means no vma is above this address,
5059 * else if new region fits below vma->vm_start,
5060 * return with success:
5061 */
5062 vma = find_vma(mm, addr);
5063 - if (likely(!vma || addr+len <= vma->vm_start)) {
5064 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5065 /* remember the address as a hint for next time */
5066 return (mm->free_area_cache = addr);
5067 }
5068 @@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5069 mm->cached_hole_size = vma->vm_start - addr;
5070
5071 /* try just below the current vma->vm_start */
5072 - addr = vma->vm_start-len;
5073 - if (do_colour_align)
5074 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5075 - } while (likely(len < vma->vm_start));
5076 + addr = skip_heap_stack_gap(vma, len);
5077 + } while (!IS_ERR_VALUE(addr));
5078
5079 bottomup:
5080 /*
5081 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
5082 index ce35a1c..2e7b8f9 100644
5083 --- a/arch/sparc/include/asm/atomic_64.h
5084 +++ b/arch/sparc/include/asm/atomic_64.h
5085 @@ -14,18 +14,40 @@
5086 #define ATOMIC64_INIT(i) { (i) }
5087
5088 #define atomic_read(v) (*(volatile int *)&(v)->counter)
5089 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5090 +{
5091 + return v->counter;
5092 +}
5093 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
5094 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5095 +{
5096 + return v->counter;
5097 +}
5098
5099 #define atomic_set(v, i) (((v)->counter) = i)
5100 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5101 +{
5102 + v->counter = i;
5103 +}
5104 #define atomic64_set(v, i) (((v)->counter) = i)
5105 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5106 +{
5107 + v->counter = i;
5108 +}
5109
5110 extern void atomic_add(int, atomic_t *);
5111 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
5112 extern void atomic64_add(long, atomic64_t *);
5113 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
5114 extern void atomic_sub(int, atomic_t *);
5115 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
5116 extern void atomic64_sub(long, atomic64_t *);
5117 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
5118
5119 extern int atomic_add_ret(int, atomic_t *);
5120 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
5121 extern long atomic64_add_ret(long, atomic64_t *);
5122 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
5123 extern int atomic_sub_ret(int, atomic_t *);
5124 extern long atomic64_sub_ret(long, atomic64_t *);
5125
5126 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5127 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
5128
5129 #define atomic_inc_return(v) atomic_add_ret(1, v)
5130 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5131 +{
5132 + return atomic_add_ret_unchecked(1, v);
5133 +}
5134 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
5135 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
5136 +{
5137 + return atomic64_add_ret_unchecked(1, v);
5138 +}
5139
5140 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
5141 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
5142
5143 #define atomic_add_return(i, v) atomic_add_ret(i, v)
5144 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5145 +{
5146 + return atomic_add_ret_unchecked(i, v);
5147 +}
5148 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
5149 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
5150 +{
5151 + return atomic64_add_ret_unchecked(i, v);
5152 +}
5153
5154 /*
5155 * atomic_inc_and_test - increment and test
5156 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5157 * other cases.
5158 */
5159 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5160 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5161 +{
5162 + return atomic_inc_return_unchecked(v) == 0;
5163 +}
5164 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
5165
5166 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
5167 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5168 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
5169
5170 #define atomic_inc(v) atomic_add(1, v)
5171 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
5172 +{
5173 + atomic_add_unchecked(1, v);
5174 +}
5175 #define atomic64_inc(v) atomic64_add(1, v)
5176 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
5177 +{
5178 + atomic64_add_unchecked(1, v);
5179 +}
5180
5181 #define atomic_dec(v) atomic_sub(1, v)
5182 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
5183 +{
5184 + atomic_sub_unchecked(1, v);
5185 +}
5186 #define atomic64_dec(v) atomic64_sub(1, v)
5187 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
5188 +{
5189 + atomic64_sub_unchecked(1, v);
5190 +}
5191
5192 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
5193 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
5194
5195 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5196 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
5197 +{
5198 + return cmpxchg(&v->counter, old, new);
5199 +}
5200 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
5201 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5202 +{
5203 + return xchg(&v->counter, new);
5204 +}
5205
5206 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5207 {
5208 - int c, old;
5209 + int c, old, new;
5210 c = atomic_read(v);
5211 for (;;) {
5212 - if (unlikely(c == (u)))
5213 + if (unlikely(c == u))
5214 break;
5215 - old = atomic_cmpxchg((v), c, c + (a));
5216 +
5217 + asm volatile("addcc %2, %0, %0\n"
5218 +
5219 +#ifdef CONFIG_PAX_REFCOUNT
5220 + "tvs %%icc, 6\n"
5221 +#endif
5222 +
5223 + : "=r" (new)
5224 + : "0" (c), "ir" (a)
5225 + : "cc");
5226 +
5227 + old = atomic_cmpxchg(v, c, new);
5228 if (likely(old == c))
5229 break;
5230 c = old;
5231 @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5232 #define atomic64_cmpxchg(v, o, n) \
5233 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
5234 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
5235 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
5236 +{
5237 + return xchg(&v->counter, new);
5238 +}
5239
5240 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
5241 {
5242 - long c, old;
5243 + long c, old, new;
5244 c = atomic64_read(v);
5245 for (;;) {
5246 - if (unlikely(c == (u)))
5247 + if (unlikely(c == u))
5248 break;
5249 - old = atomic64_cmpxchg((v), c, c + (a));
5250 +
5251 + asm volatile("addcc %2, %0, %0\n"
5252 +
5253 +#ifdef CONFIG_PAX_REFCOUNT
5254 + "tvs %%xcc, 6\n"
5255 +#endif
5256 +
5257 + : "=r" (new)
5258 + : "0" (c), "ir" (a)
5259 + : "cc");
5260 +
5261 + old = atomic64_cmpxchg(v, c, new);
5262 if (likely(old == c))
5263 break;
5264 c = old;
5265 }
5266 - return c != (u);
5267 + return c != u;
5268 }
5269
5270 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5271 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
5272 index 5bb6991..5c2132e 100644
5273 --- a/arch/sparc/include/asm/cache.h
5274 +++ b/arch/sparc/include/asm/cache.h
5275 @@ -7,10 +7,12 @@
5276 #ifndef _SPARC_CACHE_H
5277 #define _SPARC_CACHE_H
5278
5279 +#include <linux/const.h>
5280 +
5281 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
5282
5283 #define L1_CACHE_SHIFT 5
5284 -#define L1_CACHE_BYTES 32
5285 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5286
5287 #ifdef CONFIG_SPARC32
5288 #define SMP_CACHE_BYTES_SHIFT 5
5289 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
5290 index 2d4d755..81b6662 100644
5291 --- a/arch/sparc/include/asm/elf_32.h
5292 +++ b/arch/sparc/include/asm/elf_32.h
5293 @@ -114,6 +114,13 @@ typedef struct {
5294
5295 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
5296
5297 +#ifdef CONFIG_PAX_ASLR
5298 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
5299 +
5300 +#define PAX_DELTA_MMAP_LEN 16
5301 +#define PAX_DELTA_STACK_LEN 16
5302 +#endif
5303 +
5304 /* This yields a mask that user programs can use to figure out what
5305 instruction set this cpu supports. This can NOT be done in userspace
5306 on Sparc. */
5307 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
5308 index 7df8b7f..4946269 100644
5309 --- a/arch/sparc/include/asm/elf_64.h
5310 +++ b/arch/sparc/include/asm/elf_64.h
5311 @@ -180,6 +180,13 @@ typedef struct {
5312 #define ELF_ET_DYN_BASE 0x0000010000000000UL
5313 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
5314
5315 +#ifdef CONFIG_PAX_ASLR
5316 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
5317 +
5318 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
5319 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
5320 +#endif
5321 +
5322 extern unsigned long sparc64_elf_hwcap;
5323 #define ELF_HWCAP sparc64_elf_hwcap
5324
5325 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
5326 index 9b1c36d..209298b 100644
5327 --- a/arch/sparc/include/asm/pgalloc_32.h
5328 +++ b/arch/sparc/include/asm/pgalloc_32.h
5329 @@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
5330 }
5331
5332 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
5333 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
5334
5335 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
5336 unsigned long address)
5337 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
5338 index 40b2d7a..22a665b 100644
5339 --- a/arch/sparc/include/asm/pgalloc_64.h
5340 +++ b/arch/sparc/include/asm/pgalloc_64.h
5341 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
5342 }
5343
5344 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
5345 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
5346
5347 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5348 {
5349 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
5350 index 6fc1348..390c50a 100644
5351 --- a/arch/sparc/include/asm/pgtable_32.h
5352 +++ b/arch/sparc/include/asm/pgtable_32.h
5353 @@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
5354 #define PAGE_SHARED SRMMU_PAGE_SHARED
5355 #define PAGE_COPY SRMMU_PAGE_COPY
5356 #define PAGE_READONLY SRMMU_PAGE_RDONLY
5357 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
5358 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
5359 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
5360 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
5361
5362 /* Top-level page directory - dummy used by init-mm.
5363 @@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
5364
5365 /* xwr */
5366 #define __P000 PAGE_NONE
5367 -#define __P001 PAGE_READONLY
5368 -#define __P010 PAGE_COPY
5369 -#define __P011 PAGE_COPY
5370 +#define __P001 PAGE_READONLY_NOEXEC
5371 +#define __P010 PAGE_COPY_NOEXEC
5372 +#define __P011 PAGE_COPY_NOEXEC
5373 #define __P100 PAGE_READONLY
5374 #define __P101 PAGE_READONLY
5375 #define __P110 PAGE_COPY
5376 #define __P111 PAGE_COPY
5377
5378 #define __S000 PAGE_NONE
5379 -#define __S001 PAGE_READONLY
5380 -#define __S010 PAGE_SHARED
5381 -#define __S011 PAGE_SHARED
5382 +#define __S001 PAGE_READONLY_NOEXEC
5383 +#define __S010 PAGE_SHARED_NOEXEC
5384 +#define __S011 PAGE_SHARED_NOEXEC
5385 #define __S100 PAGE_READONLY
5386 #define __S101 PAGE_READONLY
5387 #define __S110 PAGE_SHARED
5388 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
5389 index 79da178..c2eede8 100644
5390 --- a/arch/sparc/include/asm/pgtsrmmu.h
5391 +++ b/arch/sparc/include/asm/pgtsrmmu.h
5392 @@ -115,6 +115,11 @@
5393 SRMMU_EXEC | SRMMU_REF)
5394 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
5395 SRMMU_EXEC | SRMMU_REF)
5396 +
5397 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
5398 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5399 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5400 +
5401 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
5402 SRMMU_DIRTY | SRMMU_REF)
5403
5404 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
5405 index 9689176..63c18ea 100644
5406 --- a/arch/sparc/include/asm/spinlock_64.h
5407 +++ b/arch/sparc/include/asm/spinlock_64.h
5408 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
5409
5410 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
5411
5412 -static void inline arch_read_lock(arch_rwlock_t *lock)
5413 +static inline void arch_read_lock(arch_rwlock_t *lock)
5414 {
5415 unsigned long tmp1, tmp2;
5416
5417 __asm__ __volatile__ (
5418 "1: ldsw [%2], %0\n"
5419 " brlz,pn %0, 2f\n"
5420 -"4: add %0, 1, %1\n"
5421 +"4: addcc %0, 1, %1\n"
5422 +
5423 +#ifdef CONFIG_PAX_REFCOUNT
5424 +" tvs %%icc, 6\n"
5425 +#endif
5426 +
5427 " cas [%2], %0, %1\n"
5428 " cmp %0, %1\n"
5429 " bne,pn %%icc, 1b\n"
5430 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
5431 " .previous"
5432 : "=&r" (tmp1), "=&r" (tmp2)
5433 : "r" (lock)
5434 - : "memory");
5435 + : "memory", "cc");
5436 }
5437
5438 -static int inline arch_read_trylock(arch_rwlock_t *lock)
5439 +static inline int arch_read_trylock(arch_rwlock_t *lock)
5440 {
5441 int tmp1, tmp2;
5442
5443 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5444 "1: ldsw [%2], %0\n"
5445 " brlz,a,pn %0, 2f\n"
5446 " mov 0, %0\n"
5447 -" add %0, 1, %1\n"
5448 +" addcc %0, 1, %1\n"
5449 +
5450 +#ifdef CONFIG_PAX_REFCOUNT
5451 +" tvs %%icc, 6\n"
5452 +#endif
5453 +
5454 " cas [%2], %0, %1\n"
5455 " cmp %0, %1\n"
5456 " bne,pn %%icc, 1b\n"
5457 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5458 return tmp1;
5459 }
5460
5461 -static void inline arch_read_unlock(arch_rwlock_t *lock)
5462 +static inline void arch_read_unlock(arch_rwlock_t *lock)
5463 {
5464 unsigned long tmp1, tmp2;
5465
5466 __asm__ __volatile__(
5467 "1: lduw [%2], %0\n"
5468 -" sub %0, 1, %1\n"
5469 +" subcc %0, 1, %1\n"
5470 +
5471 +#ifdef CONFIG_PAX_REFCOUNT
5472 +" tvs %%icc, 6\n"
5473 +#endif
5474 +
5475 " cas [%2], %0, %1\n"
5476 " cmp %0, %1\n"
5477 " bne,pn %%xcc, 1b\n"
5478 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
5479 : "memory");
5480 }
5481
5482 -static void inline arch_write_lock(arch_rwlock_t *lock)
5483 +static inline void arch_write_lock(arch_rwlock_t *lock)
5484 {
5485 unsigned long mask, tmp1, tmp2;
5486
5487 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
5488 : "memory");
5489 }
5490
5491 -static void inline arch_write_unlock(arch_rwlock_t *lock)
5492 +static inline void arch_write_unlock(arch_rwlock_t *lock)
5493 {
5494 __asm__ __volatile__(
5495 " stw %%g0, [%0]"
5496 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
5497 : "memory");
5498 }
5499
5500 -static int inline arch_write_trylock(arch_rwlock_t *lock)
5501 +static inline int arch_write_trylock(arch_rwlock_t *lock)
5502 {
5503 unsigned long mask, tmp1, tmp2, result;
5504
5505 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
5506 index e6cd224..3a71793 100644
5507 --- a/arch/sparc/include/asm/thread_info_32.h
5508 +++ b/arch/sparc/include/asm/thread_info_32.h
5509 @@ -49,6 +49,8 @@ struct thread_info {
5510 unsigned long w_saved;
5511
5512 struct restart_block restart_block;
5513 +
5514 + unsigned long lowest_stack;
5515 };
5516
5517 /*
5518 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
5519 index cfa8c38..13f30d3 100644
5520 --- a/arch/sparc/include/asm/thread_info_64.h
5521 +++ b/arch/sparc/include/asm/thread_info_64.h
5522 @@ -63,6 +63,8 @@ struct thread_info {
5523 struct pt_regs *kern_una_regs;
5524 unsigned int kern_una_insn;
5525
5526 + unsigned long lowest_stack;
5527 +
5528 unsigned long fpregs[0] __attribute__ ((aligned(64)));
5529 };
5530
5531 @@ -193,10 +195,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
5532 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
5533 /* flag bit 6 is available */
5534 #define TIF_32BIT 7 /* 32-bit binary */
5535 -/* flag bit 8 is available */
5536 +#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
5537 #define TIF_SECCOMP 9 /* secure computing */
5538 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
5539 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
5540 +
5541 /* NOTE: Thread flags >= 12 should be ones we have no interest
5542 * in using in assembly, else we can't use the mask as
5543 * an immediate value in instructions such as andcc.
5544 @@ -215,12 +218,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
5545 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
5546 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
5547 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
5548 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5549
5550 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
5551 _TIF_DO_NOTIFY_RESUME_MASK | \
5552 _TIF_NEED_RESCHED)
5553 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
5554
5555 +#define _TIF_WORK_SYSCALL \
5556 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
5557 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
5558 +
5559 +
5560 /*
5561 * Thread-synchronous status.
5562 *
5563 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
5564 index 0167d26..9acd8ed 100644
5565 --- a/arch/sparc/include/asm/uaccess.h
5566 +++ b/arch/sparc/include/asm/uaccess.h
5567 @@ -1,5 +1,13 @@
5568 #ifndef ___ASM_SPARC_UACCESS_H
5569 #define ___ASM_SPARC_UACCESS_H
5570 +
5571 +#ifdef __KERNEL__
5572 +#ifndef __ASSEMBLY__
5573 +#include <linux/types.h>
5574 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
5575 +#endif
5576 +#endif
5577 +
5578 #if defined(__sparc__) && defined(__arch64__)
5579 #include <asm/uaccess_64.h>
5580 #else
5581 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
5582 index 53a28dd..50c38c3 100644
5583 --- a/arch/sparc/include/asm/uaccess_32.h
5584 +++ b/arch/sparc/include/asm/uaccess_32.h
5585 @@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
5586
5587 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5588 {
5589 - if (n && __access_ok((unsigned long) to, n))
5590 + if ((long)n < 0)
5591 + return n;
5592 +
5593 + if (n && __access_ok((unsigned long) to, n)) {
5594 + if (!__builtin_constant_p(n))
5595 + check_object_size(from, n, true);
5596 return __copy_user(to, (__force void __user *) from, n);
5597 - else
5598 + } else
5599 return n;
5600 }
5601
5602 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
5603 {
5604 + if ((long)n < 0)
5605 + return n;
5606 +
5607 + if (!__builtin_constant_p(n))
5608 + check_object_size(from, n, true);
5609 +
5610 return __copy_user(to, (__force void __user *) from, n);
5611 }
5612
5613 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5614 {
5615 - if (n && __access_ok((unsigned long) from, n))
5616 + if ((long)n < 0)
5617 + return n;
5618 +
5619 + if (n && __access_ok((unsigned long) from, n)) {
5620 + if (!__builtin_constant_p(n))
5621 + check_object_size(to, n, false);
5622 return __copy_user((__force void __user *) to, from, n);
5623 - else
5624 + } else
5625 return n;
5626 }
5627
5628 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
5629 {
5630 + if ((long)n < 0)
5631 + return n;
5632 +
5633 return __copy_user((__force void __user *) to, from, n);
5634 }
5635
5636 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
5637 index 7c831d8..d440ca7 100644
5638 --- a/arch/sparc/include/asm/uaccess_64.h
5639 +++ b/arch/sparc/include/asm/uaccess_64.h
5640 @@ -10,6 +10,7 @@
5641 #include <linux/compiler.h>
5642 #include <linux/string.h>
5643 #include <linux/thread_info.h>
5644 +#include <linux/kernel.h>
5645 #include <asm/asi.h>
5646 #include <asm/spitfire.h>
5647 #include <asm-generic/uaccess-unaligned.h>
5648 @@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
5649 static inline unsigned long __must_check
5650 copy_from_user(void *to, const void __user *from, unsigned long size)
5651 {
5652 - unsigned long ret = ___copy_from_user(to, from, size);
5653 + unsigned long ret;
5654
5655 + if ((long)size < 0 || size > INT_MAX)
5656 + return size;
5657 +
5658 + if (!__builtin_constant_p(size))
5659 + check_object_size(to, size, false);
5660 +
5661 + ret = ___copy_from_user(to, from, size);
5662 if (unlikely(ret))
5663 ret = copy_from_user_fixup(to, from, size);
5664
5665 @@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
5666 static inline unsigned long __must_check
5667 copy_to_user(void __user *to, const void *from, unsigned long size)
5668 {
5669 - unsigned long ret = ___copy_to_user(to, from, size);
5670 + unsigned long ret;
5671
5672 + if ((long)size < 0 || size > INT_MAX)
5673 + return size;
5674 +
5675 + if (!__builtin_constant_p(size))
5676 + check_object_size(from, size, true);
5677 +
5678 + ret = ___copy_to_user(to, from, size);
5679 if (unlikely(ret))
5680 ret = copy_to_user_fixup(to, from, size);
5681 return ret;
5682 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
5683 index 6cf591b..b49e65a 100644
5684 --- a/arch/sparc/kernel/Makefile
5685 +++ b/arch/sparc/kernel/Makefile
5686 @@ -3,7 +3,7 @@
5687 #
5688
5689 asflags-y := -ansi
5690 -ccflags-y := -Werror
5691 +#ccflags-y := -Werror
5692
5693 extra-y := head_$(BITS).o
5694
5695 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
5696 index 14006d8..8146238 100644
5697 --- a/arch/sparc/kernel/process_32.c
5698 +++ b/arch/sparc/kernel/process_32.c
5699 @@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
5700
5701 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
5702 r->psr, r->pc, r->npc, r->y, print_tainted());
5703 - printk("PC: <%pS>\n", (void *) r->pc);
5704 + printk("PC: <%pA>\n", (void *) r->pc);
5705 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5706 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
5707 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
5708 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5709 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
5710 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
5711 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
5712 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
5713
5714 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5715 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5716 @@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5717 rw = (struct reg_window32 *) fp;
5718 pc = rw->ins[7];
5719 printk("[%08lx : ", pc);
5720 - printk("%pS ] ", (void *) pc);
5721 + printk("%pA ] ", (void *) pc);
5722 fp = rw->ins[6];
5723 } while (++count < 16);
5724 printk("\n");
5725 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
5726 index aff0c72..9067b39 100644
5727 --- a/arch/sparc/kernel/process_64.c
5728 +++ b/arch/sparc/kernel/process_64.c
5729 @@ -179,14 +179,14 @@ static void show_regwindow(struct pt_regs *regs)
5730 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5731 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5732 if (regs->tstate & TSTATE_PRIV)
5733 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5734 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5735 }
5736
5737 void show_regs(struct pt_regs *regs)
5738 {
5739 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5740 regs->tpc, regs->tnpc, regs->y, print_tainted());
5741 - printk("TPC: <%pS>\n", (void *) regs->tpc);
5742 + printk("TPC: <%pA>\n", (void *) regs->tpc);
5743 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5744 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5745 regs->u_regs[3]);
5746 @@ -199,7 +199,7 @@ void show_regs(struct pt_regs *regs)
5747 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5748 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5749 regs->u_regs[15]);
5750 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5751 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5752 show_regwindow(regs);
5753 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5754 }
5755 @@ -284,7 +284,7 @@ void arch_trigger_all_cpu_backtrace(void)
5756 ((tp && tp->task) ? tp->task->pid : -1));
5757
5758 if (gp->tstate & TSTATE_PRIV) {
5759 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5760 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5761 (void *) gp->tpc,
5762 (void *) gp->o7,
5763 (void *) gp->i7,
5764 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
5765 index 484daba..0674139 100644
5766 --- a/arch/sparc/kernel/ptrace_64.c
5767 +++ b/arch/sparc/kernel/ptrace_64.c
5768 @@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
5769 return ret;
5770 }
5771
5772 +#ifdef CONFIG_GRKERNSEC_SETXID
5773 +extern void gr_delayed_cred_worker(void);
5774 +#endif
5775 +
5776 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5777 {
5778 int ret = 0;
5779 @@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5780 /* do the secure computing check first */
5781 secure_computing_strict(regs->u_regs[UREG_G1]);
5782
5783 +#ifdef CONFIG_GRKERNSEC_SETXID
5784 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5785 + gr_delayed_cred_worker();
5786 +#endif
5787 +
5788 if (test_thread_flag(TIF_SYSCALL_TRACE))
5789 ret = tracehook_report_syscall_entry(regs);
5790
5791 @@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5792
5793 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
5794 {
5795 +#ifdef CONFIG_GRKERNSEC_SETXID
5796 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5797 + gr_delayed_cred_worker();
5798 +#endif
5799 +
5800 audit_syscall_exit(regs);
5801
5802 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
5803 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
5804 index 0c9b31b..7cb7aee 100644
5805 --- a/arch/sparc/kernel/sys_sparc_32.c
5806 +++ b/arch/sparc/kernel/sys_sparc_32.c
5807 @@ -54,7 +54,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5808 if (len > TASK_SIZE - PAGE_SIZE)
5809 return -ENOMEM;
5810 if (!addr)
5811 - addr = TASK_UNMAPPED_BASE;
5812 + addr = current->mm->mmap_base;
5813
5814 if (flags & MAP_SHARED)
5815 addr = COLOUR_ALIGN(addr);
5816 @@ -65,7 +65,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5817 /* At this point: (!vmm || addr < vmm->vm_end). */
5818 if (TASK_SIZE - PAGE_SIZE - len < addr)
5819 return -ENOMEM;
5820 - if (!vmm || addr + len <= vmm->vm_start)
5821 + if (check_heap_stack_gap(vmm, addr, len))
5822 return addr;
5823 addr = vmm->vm_end;
5824 if (flags & MAP_SHARED)
5825 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
5826 index 11c6c96..3ec33e8 100644
5827 --- a/arch/sparc/kernel/sys_sparc_64.c
5828 +++ b/arch/sparc/kernel/sys_sparc_64.c
5829 @@ -107,7 +107,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5830 /* We do not accept a shared mapping if it would violate
5831 * cache aliasing constraints.
5832 */
5833 - if ((flags & MAP_SHARED) &&
5834 + if ((filp || (flags & MAP_SHARED)) &&
5835 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5836 return -EINVAL;
5837 return addr;
5838 @@ -122,6 +122,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5839 if (filp || (flags & MAP_SHARED))
5840 do_color_align = 1;
5841
5842 +#ifdef CONFIG_PAX_RANDMMAP
5843 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5844 +#endif
5845 +
5846 if (addr) {
5847 if (do_color_align)
5848 addr = COLOUR_ALIGN(addr, pgoff);
5849 @@ -129,15 +133,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5850 addr = PAGE_ALIGN(addr);
5851
5852 vma = find_vma(mm, addr);
5853 - if (task_size - len >= addr &&
5854 - (!vma || addr + len <= vma->vm_start))
5855 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5856 return addr;
5857 }
5858
5859 if (len > mm->cached_hole_size) {
5860 - start_addr = addr = mm->free_area_cache;
5861 + start_addr = addr = mm->free_area_cache;
5862 } else {
5863 - start_addr = addr = TASK_UNMAPPED_BASE;
5864 + start_addr = addr = mm->mmap_base;
5865 mm->cached_hole_size = 0;
5866 }
5867
5868 @@ -157,14 +160,14 @@ full_search:
5869 vma = find_vma(mm, VA_EXCLUDE_END);
5870 }
5871 if (unlikely(task_size < addr)) {
5872 - if (start_addr != TASK_UNMAPPED_BASE) {
5873 - start_addr = addr = TASK_UNMAPPED_BASE;
5874 + if (start_addr != mm->mmap_base) {
5875 + start_addr = addr = mm->mmap_base;
5876 mm->cached_hole_size = 0;
5877 goto full_search;
5878 }
5879 return -ENOMEM;
5880 }
5881 - if (likely(!vma || addr + len <= vma->vm_start)) {
5882 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5883 /*
5884 * Remember the place where we stopped the search:
5885 */
5886 @@ -198,7 +201,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5887 /* We do not accept a shared mapping if it would violate
5888 * cache aliasing constraints.
5889 */
5890 - if ((flags & MAP_SHARED) &&
5891 + if ((filp || (flags & MAP_SHARED)) &&
5892 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5893 return -EINVAL;
5894 return addr;
5895 @@ -219,8 +222,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5896 addr = PAGE_ALIGN(addr);
5897
5898 vma = find_vma(mm, addr);
5899 - if (task_size - len >= addr &&
5900 - (!vma || addr + len <= vma->vm_start))
5901 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5902 return addr;
5903 }
5904
5905 @@ -241,7 +243,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5906 /* make sure it can fit in the remaining address space */
5907 if (likely(addr > len)) {
5908 vma = find_vma(mm, addr-len);
5909 - if (!vma || addr <= vma->vm_start) {
5910 + if (check_heap_stack_gap(vma, addr - len, len)) {
5911 /* remember the address as a hint for next time */
5912 return (mm->free_area_cache = addr-len);
5913 }
5914 @@ -250,18 +252,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5915 if (unlikely(mm->mmap_base < len))
5916 goto bottomup;
5917
5918 - addr = mm->mmap_base-len;
5919 - if (do_color_align)
5920 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5921 + addr = mm->mmap_base - len;
5922
5923 do {
5924 + if (do_color_align)
5925 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5926 /*
5927 * Lookup failure means no vma is above this address,
5928 * else if new region fits below vma->vm_start,
5929 * return with success:
5930 */
5931 vma = find_vma(mm, addr);
5932 - if (likely(!vma || addr+len <= vma->vm_start)) {
5933 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5934 /* remember the address as a hint for next time */
5935 return (mm->free_area_cache = addr);
5936 }
5937 @@ -271,10 +273,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5938 mm->cached_hole_size = vma->vm_start - addr;
5939
5940 /* try just below the current vma->vm_start */
5941 - addr = vma->vm_start-len;
5942 - if (do_color_align)
5943 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5944 - } while (likely(len < vma->vm_start));
5945 + addr = skip_heap_stack_gap(vma, len);
5946 + } while (!IS_ERR_VALUE(addr));
5947
5948 bottomup:
5949 /*
5950 @@ -373,6 +373,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5951 gap == RLIM_INFINITY ||
5952 sysctl_legacy_va_layout) {
5953 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5954 +
5955 +#ifdef CONFIG_PAX_RANDMMAP
5956 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5957 + mm->mmap_base += mm->delta_mmap;
5958 +#endif
5959 +
5960 mm->get_unmapped_area = arch_get_unmapped_area;
5961 mm->unmap_area = arch_unmap_area;
5962 } else {
5963 @@ -385,6 +391,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5964 gap = (task_size / 6 * 5);
5965
5966 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
5967 +
5968 +#ifdef CONFIG_PAX_RANDMMAP
5969 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5970 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5971 +#endif
5972 +
5973 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5974 mm->unmap_area = arch_unmap_area_topdown;
5975 }
5976 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
5977 index 7f5f65d..3308382 100644
5978 --- a/arch/sparc/kernel/syscalls.S
5979 +++ b/arch/sparc/kernel/syscalls.S
5980 @@ -62,7 +62,7 @@ sys32_rt_sigreturn:
5981 #endif
5982 .align 32
5983 1: ldx [%g6 + TI_FLAGS], %l5
5984 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
5985 + andcc %l5, _TIF_WORK_SYSCALL, %g0
5986 be,pt %icc, rtrap
5987 nop
5988 call syscall_trace_leave
5989 @@ -179,7 +179,7 @@ linux_sparc_syscall32:
5990
5991 srl %i5, 0, %o5 ! IEU1
5992 srl %i2, 0, %o2 ! IEU0 Group
5993 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
5994 + andcc %l0, _TIF_WORK_SYSCALL, %g0
5995 bne,pn %icc, linux_syscall_trace32 ! CTI
5996 mov %i0, %l5 ! IEU1
5997 call %l7 ! CTI Group brk forced
5998 @@ -202,7 +202,7 @@ linux_sparc_syscall:
5999
6000 mov %i3, %o3 ! IEU1
6001 mov %i4, %o4 ! IEU0 Group
6002 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6003 + andcc %l0, _TIF_WORK_SYSCALL, %g0
6004 bne,pn %icc, linux_syscall_trace ! CTI Group
6005 mov %i0, %l5 ! IEU0
6006 2: call %l7 ! CTI Group brk forced
6007 @@ -218,7 +218,7 @@ ret_sys_call:
6008
6009 cmp %o0, -ERESTART_RESTARTBLOCK
6010 bgeu,pn %xcc, 1f
6011 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6012 + andcc %l0, _TIF_WORK_SYSCALL, %g0
6013 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
6014
6015 2:
6016 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
6017 index a5785ea..405c5f7 100644
6018 --- a/arch/sparc/kernel/traps_32.c
6019 +++ b/arch/sparc/kernel/traps_32.c
6020 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
6021 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
6022 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
6023
6024 +extern void gr_handle_kernel_exploit(void);
6025 +
6026 void die_if_kernel(char *str, struct pt_regs *regs)
6027 {
6028 static int die_counter;
6029 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6030 count++ < 30 &&
6031 (((unsigned long) rw) >= PAGE_OFFSET) &&
6032 !(((unsigned long) rw) & 0x7)) {
6033 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
6034 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
6035 (void *) rw->ins[7]);
6036 rw = (struct reg_window32 *)rw->ins[6];
6037 }
6038 }
6039 printk("Instruction DUMP:");
6040 instruction_dump ((unsigned long *) regs->pc);
6041 - if(regs->psr & PSR_PS)
6042 + if(regs->psr & PSR_PS) {
6043 + gr_handle_kernel_exploit();
6044 do_exit(SIGKILL);
6045 + }
6046 do_exit(SIGSEGV);
6047 }
6048
6049 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
6050 index 3b05e66..6ea2917 100644
6051 --- a/arch/sparc/kernel/traps_64.c
6052 +++ b/arch/sparc/kernel/traps_64.c
6053 @@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
6054 i + 1,
6055 p->trapstack[i].tstate, p->trapstack[i].tpc,
6056 p->trapstack[i].tnpc, p->trapstack[i].tt);
6057 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
6058 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
6059 }
6060 }
6061
6062 @@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
6063
6064 lvl -= 0x100;
6065 if (regs->tstate & TSTATE_PRIV) {
6066 +
6067 +#ifdef CONFIG_PAX_REFCOUNT
6068 + if (lvl == 6)
6069 + pax_report_refcount_overflow(regs);
6070 +#endif
6071 +
6072 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
6073 die_if_kernel(buffer, regs);
6074 }
6075 @@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
6076 void bad_trap_tl1(struct pt_regs *regs, long lvl)
6077 {
6078 char buffer[32];
6079 -
6080 +
6081 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
6082 0, lvl, SIGTRAP) == NOTIFY_STOP)
6083 return;
6084
6085 +#ifdef CONFIG_PAX_REFCOUNT
6086 + if (lvl == 6)
6087 + pax_report_refcount_overflow(regs);
6088 +#endif
6089 +
6090 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
6091
6092 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
6093 @@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
6094 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
6095 printk("%s" "ERROR(%d): ",
6096 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
6097 - printk("TPC<%pS>\n", (void *) regs->tpc);
6098 + printk("TPC<%pA>\n", (void *) regs->tpc);
6099 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
6100 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
6101 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
6102 @@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6103 smp_processor_id(),
6104 (type & 0x1) ? 'I' : 'D',
6105 regs->tpc);
6106 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
6107 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
6108 panic("Irrecoverable Cheetah+ parity error.");
6109 }
6110
6111 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6112 smp_processor_id(),
6113 (type & 0x1) ? 'I' : 'D',
6114 regs->tpc);
6115 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
6116 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
6117 }
6118
6119 struct sun4v_error_entry {
6120 @@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
6121
6122 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
6123 regs->tpc, tl);
6124 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
6125 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
6126 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6127 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
6128 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
6129 (void *) regs->u_regs[UREG_I7]);
6130 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
6131 "pte[%lx] error[%lx]\n",
6132 @@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
6133
6134 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
6135 regs->tpc, tl);
6136 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
6137 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
6138 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6139 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
6140 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
6141 (void *) regs->u_regs[UREG_I7]);
6142 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
6143 "pte[%lx] error[%lx]\n",
6144 @@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6145 fp = (unsigned long)sf->fp + STACK_BIAS;
6146 }
6147
6148 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6149 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6150 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6151 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
6152 int index = tsk->curr_ret_stack;
6153 if (tsk->ret_stack && index >= graph) {
6154 pc = tsk->ret_stack[index - graph].ret;
6155 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6156 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6157 graph++;
6158 }
6159 }
6160 @@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
6161 return (struct reg_window *) (fp + STACK_BIAS);
6162 }
6163
6164 +extern void gr_handle_kernel_exploit(void);
6165 +
6166 void die_if_kernel(char *str, struct pt_regs *regs)
6167 {
6168 static int die_counter;
6169 @@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6170 while (rw &&
6171 count++ < 30 &&
6172 kstack_valid(tp, (unsigned long) rw)) {
6173 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
6174 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
6175 (void *) rw->ins[7]);
6176
6177 rw = kernel_stack_up(rw);
6178 @@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6179 }
6180 user_instruction_dump ((unsigned int __user *) regs->tpc);
6181 }
6182 - if (regs->tstate & TSTATE_PRIV)
6183 + if (regs->tstate & TSTATE_PRIV) {
6184 + gr_handle_kernel_exploit();
6185 do_exit(SIGKILL);
6186 + }
6187 do_exit(SIGSEGV);
6188 }
6189 EXPORT_SYMBOL(die_if_kernel);
6190 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
6191 index f81d038..e7a4680 100644
6192 --- a/arch/sparc/kernel/unaligned_64.c
6193 +++ b/arch/sparc/kernel/unaligned_64.c
6194 @@ -278,7 +278,7 @@ static void log_unaligned(struct pt_regs *regs)
6195 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
6196
6197 if (__ratelimit(&ratelimit)) {
6198 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
6199 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
6200 regs->tpc, (void *) regs->tpc);
6201 }
6202 }
6203 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
6204 index dff4096..bd9a388 100644
6205 --- a/arch/sparc/lib/Makefile
6206 +++ b/arch/sparc/lib/Makefile
6207 @@ -2,7 +2,7 @@
6208 #
6209
6210 asflags-y := -ansi -DST_DIV0=0x02
6211 -ccflags-y := -Werror
6212 +#ccflags-y := -Werror
6213
6214 lib-$(CONFIG_SPARC32) += ashrdi3.o
6215 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
6216 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
6217 index 4d502da..527c48d 100644
6218 --- a/arch/sparc/lib/atomic_64.S
6219 +++ b/arch/sparc/lib/atomic_64.S
6220 @@ -17,7 +17,12 @@
6221 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6222 BACKOFF_SETUP(%o2)
6223 1: lduw [%o1], %g1
6224 - add %g1, %o0, %g7
6225 + addcc %g1, %o0, %g7
6226 +
6227 +#ifdef CONFIG_PAX_REFCOUNT
6228 + tvs %icc, 6
6229 +#endif
6230 +
6231 cas [%o1], %g1, %g7
6232 cmp %g1, %g7
6233 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6234 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6235 2: BACKOFF_SPIN(%o2, %o3, 1b)
6236 ENDPROC(atomic_add)
6237
6238 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6239 + BACKOFF_SETUP(%o2)
6240 +1: lduw [%o1], %g1
6241 + add %g1, %o0, %g7
6242 + cas [%o1], %g1, %g7
6243 + cmp %g1, %g7
6244 + bne,pn %icc, 2f
6245 + nop
6246 + retl
6247 + nop
6248 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6249 +ENDPROC(atomic_add_unchecked)
6250 +
6251 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6252 BACKOFF_SETUP(%o2)
6253 1: lduw [%o1], %g1
6254 - sub %g1, %o0, %g7
6255 + subcc %g1, %o0, %g7
6256 +
6257 +#ifdef CONFIG_PAX_REFCOUNT
6258 + tvs %icc, 6
6259 +#endif
6260 +
6261 cas [%o1], %g1, %g7
6262 cmp %g1, %g7
6263 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6264 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6265 2: BACKOFF_SPIN(%o2, %o3, 1b)
6266 ENDPROC(atomic_sub)
6267
6268 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6269 + BACKOFF_SETUP(%o2)
6270 +1: lduw [%o1], %g1
6271 + sub %g1, %o0, %g7
6272 + cas [%o1], %g1, %g7
6273 + cmp %g1, %g7
6274 + bne,pn %icc, 2f
6275 + nop
6276 + retl
6277 + nop
6278 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6279 +ENDPROC(atomic_sub_unchecked)
6280 +
6281 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6282 BACKOFF_SETUP(%o2)
6283 1: lduw [%o1], %g1
6284 - add %g1, %o0, %g7
6285 + addcc %g1, %o0, %g7
6286 +
6287 +#ifdef CONFIG_PAX_REFCOUNT
6288 + tvs %icc, 6
6289 +#endif
6290 +
6291 cas [%o1], %g1, %g7
6292 cmp %g1, %g7
6293 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6294 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6295 2: BACKOFF_SPIN(%o2, %o3, 1b)
6296 ENDPROC(atomic_add_ret)
6297
6298 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6299 + BACKOFF_SETUP(%o2)
6300 +1: lduw [%o1], %g1
6301 + addcc %g1, %o0, %g7
6302 + cas [%o1], %g1, %g7
6303 + cmp %g1, %g7
6304 + bne,pn %icc, 2f
6305 + add %g7, %o0, %g7
6306 + sra %g7, 0, %o0
6307 + retl
6308 + nop
6309 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6310 +ENDPROC(atomic_add_ret_unchecked)
6311 +
6312 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6313 BACKOFF_SETUP(%o2)
6314 1: lduw [%o1], %g1
6315 - sub %g1, %o0, %g7
6316 + subcc %g1, %o0, %g7
6317 +
6318 +#ifdef CONFIG_PAX_REFCOUNT
6319 + tvs %icc, 6
6320 +#endif
6321 +
6322 cas [%o1], %g1, %g7
6323 cmp %g1, %g7
6324 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6325 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
6326 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6327 BACKOFF_SETUP(%o2)
6328 1: ldx [%o1], %g1
6329 - add %g1, %o0, %g7
6330 + addcc %g1, %o0, %g7
6331 +
6332 +#ifdef CONFIG_PAX_REFCOUNT
6333 + tvs %xcc, 6
6334 +#endif
6335 +
6336 casx [%o1], %g1, %g7
6337 cmp %g1, %g7
6338 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6339 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6340 2: BACKOFF_SPIN(%o2, %o3, 1b)
6341 ENDPROC(atomic64_add)
6342
6343 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6344 + BACKOFF_SETUP(%o2)
6345 +1: ldx [%o1], %g1
6346 + addcc %g1, %o0, %g7
6347 + casx [%o1], %g1, %g7
6348 + cmp %g1, %g7
6349 + bne,pn %xcc, 2f
6350 + nop
6351 + retl
6352 + nop
6353 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6354 +ENDPROC(atomic64_add_unchecked)
6355 +
6356 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6357 BACKOFF_SETUP(%o2)
6358 1: ldx [%o1], %g1
6359 - sub %g1, %o0, %g7
6360 + subcc %g1, %o0, %g7
6361 +
6362 +#ifdef CONFIG_PAX_REFCOUNT
6363 + tvs %xcc, 6
6364 +#endif
6365 +
6366 casx [%o1], %g1, %g7
6367 cmp %g1, %g7
6368 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6369 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6370 2: BACKOFF_SPIN(%o2, %o3, 1b)
6371 ENDPROC(atomic64_sub)
6372
6373 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6374 + BACKOFF_SETUP(%o2)
6375 +1: ldx [%o1], %g1
6376 + subcc %g1, %o0, %g7
6377 + casx [%o1], %g1, %g7
6378 + cmp %g1, %g7
6379 + bne,pn %xcc, 2f
6380 + nop
6381 + retl
6382 + nop
6383 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6384 +ENDPROC(atomic64_sub_unchecked)
6385 +
6386 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6387 BACKOFF_SETUP(%o2)
6388 1: ldx [%o1], %g1
6389 - add %g1, %o0, %g7
6390 + addcc %g1, %o0, %g7
6391 +
6392 +#ifdef CONFIG_PAX_REFCOUNT
6393 + tvs %xcc, 6
6394 +#endif
6395 +
6396 casx [%o1], %g1, %g7
6397 cmp %g1, %g7
6398 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6399 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6400 2: BACKOFF_SPIN(%o2, %o3, 1b)
6401 ENDPROC(atomic64_add_ret)
6402
6403 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6404 + BACKOFF_SETUP(%o2)
6405 +1: ldx [%o1], %g1
6406 + addcc %g1, %o0, %g7
6407 + casx [%o1], %g1, %g7
6408 + cmp %g1, %g7
6409 + bne,pn %xcc, 2f
6410 + add %g7, %o0, %g7
6411 + mov %g7, %o0
6412 + retl
6413 + nop
6414 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6415 +ENDPROC(atomic64_add_ret_unchecked)
6416 +
6417 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6418 BACKOFF_SETUP(%o2)
6419 1: ldx [%o1], %g1
6420 - sub %g1, %o0, %g7
6421 + subcc %g1, %o0, %g7
6422 +
6423 +#ifdef CONFIG_PAX_REFCOUNT
6424 + tvs %xcc, 6
6425 +#endif
6426 +
6427 casx [%o1], %g1, %g7
6428 cmp %g1, %g7
6429 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6430 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
6431 index 3b31218..345c609 100644
6432 --- a/arch/sparc/lib/ksyms.c
6433 +++ b/arch/sparc/lib/ksyms.c
6434 @@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
6435
6436 /* Atomic counter implementation. */
6437 EXPORT_SYMBOL(atomic_add);
6438 +EXPORT_SYMBOL(atomic_add_unchecked);
6439 EXPORT_SYMBOL(atomic_add_ret);
6440 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
6441 EXPORT_SYMBOL(atomic_sub);
6442 +EXPORT_SYMBOL(atomic_sub_unchecked);
6443 EXPORT_SYMBOL(atomic_sub_ret);
6444 EXPORT_SYMBOL(atomic64_add);
6445 +EXPORT_SYMBOL(atomic64_add_unchecked);
6446 EXPORT_SYMBOL(atomic64_add_ret);
6447 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
6448 EXPORT_SYMBOL(atomic64_sub);
6449 +EXPORT_SYMBOL(atomic64_sub_unchecked);
6450 EXPORT_SYMBOL(atomic64_sub_ret);
6451
6452 /* Atomic bit operations. */
6453 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
6454 index 30c3ecc..736f015 100644
6455 --- a/arch/sparc/mm/Makefile
6456 +++ b/arch/sparc/mm/Makefile
6457 @@ -2,7 +2,7 @@
6458 #
6459
6460 asflags-y := -ansi
6461 -ccflags-y := -Werror
6462 +#ccflags-y := -Werror
6463
6464 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
6465 obj-y += fault_$(BITS).o
6466 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
6467 index 77ac917..baf45db 100644
6468 --- a/arch/sparc/mm/fault_32.c
6469 +++ b/arch/sparc/mm/fault_32.c
6470 @@ -21,6 +21,9 @@
6471 #include <linux/perf_event.h>
6472 #include <linux/interrupt.h>
6473 #include <linux/kdebug.h>
6474 +#include <linux/slab.h>
6475 +#include <linux/pagemap.h>
6476 +#include <linux/compiler.h>
6477
6478 #include <asm/page.h>
6479 #include <asm/pgtable.h>
6480 @@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
6481 return safe_compute_effective_address(regs, insn);
6482 }
6483
6484 +#ifdef CONFIG_PAX_PAGEEXEC
6485 +#ifdef CONFIG_PAX_DLRESOLVE
6486 +static void pax_emuplt_close(struct vm_area_struct *vma)
6487 +{
6488 + vma->vm_mm->call_dl_resolve = 0UL;
6489 +}
6490 +
6491 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6492 +{
6493 + unsigned int *kaddr;
6494 +
6495 + vmf->page = alloc_page(GFP_HIGHUSER);
6496 + if (!vmf->page)
6497 + return VM_FAULT_OOM;
6498 +
6499 + kaddr = kmap(vmf->page);
6500 + memset(kaddr, 0, PAGE_SIZE);
6501 + kaddr[0] = 0x9DE3BFA8U; /* save */
6502 + flush_dcache_page(vmf->page);
6503 + kunmap(vmf->page);
6504 + return VM_FAULT_MAJOR;
6505 +}
6506 +
6507 +static const struct vm_operations_struct pax_vm_ops = {
6508 + .close = pax_emuplt_close,
6509 + .fault = pax_emuplt_fault
6510 +};
6511 +
6512 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6513 +{
6514 + int ret;
6515 +
6516 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6517 + vma->vm_mm = current->mm;
6518 + vma->vm_start = addr;
6519 + vma->vm_end = addr + PAGE_SIZE;
6520 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6521 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6522 + vma->vm_ops = &pax_vm_ops;
6523 +
6524 + ret = insert_vm_struct(current->mm, vma);
6525 + if (ret)
6526 + return ret;
6527 +
6528 + ++current->mm->total_vm;
6529 + return 0;
6530 +}
6531 +#endif
6532 +
6533 +/*
6534 + * PaX: decide what to do with offenders (regs->pc = fault address)
6535 + *
6536 + * returns 1 when task should be killed
6537 + * 2 when patched PLT trampoline was detected
6538 + * 3 when unpatched PLT trampoline was detected
6539 + */
6540 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6541 +{
6542 +
6543 +#ifdef CONFIG_PAX_EMUPLT
6544 + int err;
6545 +
6546 + do { /* PaX: patched PLT emulation #1 */
6547 + unsigned int sethi1, sethi2, jmpl;
6548 +
6549 + err = get_user(sethi1, (unsigned int *)regs->pc);
6550 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6551 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6552 +
6553 + if (err)
6554 + break;
6555 +
6556 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6557 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6558 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6559 + {
6560 + unsigned int addr;
6561 +
6562 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6563 + addr = regs->u_regs[UREG_G1];
6564 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6565 + regs->pc = addr;
6566 + regs->npc = addr+4;
6567 + return 2;
6568 + }
6569 + } while (0);
6570 +
6571 + do { /* PaX: patched PLT emulation #2 */
6572 + unsigned int ba;
6573 +
6574 + err = get_user(ba, (unsigned int *)regs->pc);
6575 +
6576 + if (err)
6577 + break;
6578 +
6579 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6580 + unsigned int addr;
6581 +
6582 + if ((ba & 0xFFC00000U) == 0x30800000U)
6583 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6584 + else
6585 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6586 + regs->pc = addr;
6587 + regs->npc = addr+4;
6588 + return 2;
6589 + }
6590 + } while (0);
6591 +
6592 + do { /* PaX: patched PLT emulation #3 */
6593 + unsigned int sethi, bajmpl, nop;
6594 +
6595 + err = get_user(sethi, (unsigned int *)regs->pc);
6596 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
6597 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6598 +
6599 + if (err)
6600 + break;
6601 +
6602 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6603 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6604 + nop == 0x01000000U)
6605 + {
6606 + unsigned int addr;
6607 +
6608 + addr = (sethi & 0x003FFFFFU) << 10;
6609 + regs->u_regs[UREG_G1] = addr;
6610 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6611 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6612 + else
6613 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6614 + regs->pc = addr;
6615 + regs->npc = addr+4;
6616 + return 2;
6617 + }
6618 + } while (0);
6619 +
6620 + do { /* PaX: unpatched PLT emulation step 1 */
6621 + unsigned int sethi, ba, nop;
6622 +
6623 + err = get_user(sethi, (unsigned int *)regs->pc);
6624 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
6625 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6626 +
6627 + if (err)
6628 + break;
6629 +
6630 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6631 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6632 + nop == 0x01000000U)
6633 + {
6634 + unsigned int addr, save, call;
6635 +
6636 + if ((ba & 0xFFC00000U) == 0x30800000U)
6637 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6638 + else
6639 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6640 +
6641 + err = get_user(save, (unsigned int *)addr);
6642 + err |= get_user(call, (unsigned int *)(addr+4));
6643 + err |= get_user(nop, (unsigned int *)(addr+8));
6644 + if (err)
6645 + break;
6646 +
6647 +#ifdef CONFIG_PAX_DLRESOLVE
6648 + if (save == 0x9DE3BFA8U &&
6649 + (call & 0xC0000000U) == 0x40000000U &&
6650 + nop == 0x01000000U)
6651 + {
6652 + struct vm_area_struct *vma;
6653 + unsigned long call_dl_resolve;
6654 +
6655 + down_read(&current->mm->mmap_sem);
6656 + call_dl_resolve = current->mm->call_dl_resolve;
6657 + up_read(&current->mm->mmap_sem);
6658 + if (likely(call_dl_resolve))
6659 + goto emulate;
6660 +
6661 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6662 +
6663 + down_write(&current->mm->mmap_sem);
6664 + if (current->mm->call_dl_resolve) {
6665 + call_dl_resolve = current->mm->call_dl_resolve;
6666 + up_write(&current->mm->mmap_sem);
6667 + if (vma)
6668 + kmem_cache_free(vm_area_cachep, vma);
6669 + goto emulate;
6670 + }
6671 +
6672 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6673 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6674 + up_write(&current->mm->mmap_sem);
6675 + if (vma)
6676 + kmem_cache_free(vm_area_cachep, vma);
6677 + return 1;
6678 + }
6679 +
6680 + if (pax_insert_vma(vma, call_dl_resolve)) {
6681 + up_write(&current->mm->mmap_sem);
6682 + kmem_cache_free(vm_area_cachep, vma);
6683 + return 1;
6684 + }
6685 +
6686 + current->mm->call_dl_resolve = call_dl_resolve;
6687 + up_write(&current->mm->mmap_sem);
6688 +
6689 +emulate:
6690 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6691 + regs->pc = call_dl_resolve;
6692 + regs->npc = addr+4;
6693 + return 3;
6694 + }
6695 +#endif
6696 +
6697 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6698 + if ((save & 0xFFC00000U) == 0x05000000U &&
6699 + (call & 0xFFFFE000U) == 0x85C0A000U &&
6700 + nop == 0x01000000U)
6701 + {
6702 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6703 + regs->u_regs[UREG_G2] = addr + 4;
6704 + addr = (save & 0x003FFFFFU) << 10;
6705 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6706 + regs->pc = addr;
6707 + regs->npc = addr+4;
6708 + return 3;
6709 + }
6710 + }
6711 + } while (0);
6712 +
6713 + do { /* PaX: unpatched PLT emulation step 2 */
6714 + unsigned int save, call, nop;
6715 +
6716 + err = get_user(save, (unsigned int *)(regs->pc-4));
6717 + err |= get_user(call, (unsigned int *)regs->pc);
6718 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
6719 + if (err)
6720 + break;
6721 +
6722 + if (save == 0x9DE3BFA8U &&
6723 + (call & 0xC0000000U) == 0x40000000U &&
6724 + nop == 0x01000000U)
6725 + {
6726 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6727 +
6728 + regs->u_regs[UREG_RETPC] = regs->pc;
6729 + regs->pc = dl_resolve;
6730 + regs->npc = dl_resolve+4;
6731 + return 3;
6732 + }
6733 + } while (0);
6734 +#endif
6735 +
6736 + return 1;
6737 +}
6738 +
6739 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6740 +{
6741 + unsigned long i;
6742 +
6743 + printk(KERN_ERR "PAX: bytes at PC: ");
6744 + for (i = 0; i < 8; i++) {
6745 + unsigned int c;
6746 + if (get_user(c, (unsigned int *)pc+i))
6747 + printk(KERN_CONT "???????? ");
6748 + else
6749 + printk(KERN_CONT "%08x ", c);
6750 + }
6751 + printk("\n");
6752 +}
6753 +#endif
6754 +
6755 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6756 int text_fault)
6757 {
6758 @@ -230,6 +504,24 @@ good_area:
6759 if (!(vma->vm_flags & VM_WRITE))
6760 goto bad_area;
6761 } else {
6762 +
6763 +#ifdef CONFIG_PAX_PAGEEXEC
6764 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6765 + up_read(&mm->mmap_sem);
6766 + switch (pax_handle_fetch_fault(regs)) {
6767 +
6768 +#ifdef CONFIG_PAX_EMUPLT
6769 + case 2:
6770 + case 3:
6771 + return;
6772 +#endif
6773 +
6774 + }
6775 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6776 + do_group_exit(SIGKILL);
6777 + }
6778 +#endif
6779 +
6780 /* Allow reads even for write-only mappings */
6781 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
6782 goto bad_area;
6783 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6784 index 1fe0429..8dd5dd5 100644
6785 --- a/arch/sparc/mm/fault_64.c
6786 +++ b/arch/sparc/mm/fault_64.c
6787 @@ -21,6 +21,9 @@
6788 #include <linux/kprobes.h>
6789 #include <linux/kdebug.h>
6790 #include <linux/percpu.h>
6791 +#include <linux/slab.h>
6792 +#include <linux/pagemap.h>
6793 +#include <linux/compiler.h>
6794
6795 #include <asm/page.h>
6796 #include <asm/pgtable.h>
6797 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6798 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6799 regs->tpc);
6800 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6801 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6802 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6803 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6804 dump_stack();
6805 unhandled_fault(regs->tpc, current, regs);
6806 @@ -272,6 +275,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
6807 show_regs(regs);
6808 }
6809
6810 +#ifdef CONFIG_PAX_PAGEEXEC
6811 +#ifdef CONFIG_PAX_DLRESOLVE
6812 +static void pax_emuplt_close(struct vm_area_struct *vma)
6813 +{
6814 + vma->vm_mm->call_dl_resolve = 0UL;
6815 +}
6816 +
6817 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6818 +{
6819 + unsigned int *kaddr;
6820 +
6821 + vmf->page = alloc_page(GFP_HIGHUSER);
6822 + if (!vmf->page)
6823 + return VM_FAULT_OOM;
6824 +
6825 + kaddr = kmap(vmf->page);
6826 + memset(kaddr, 0, PAGE_SIZE);
6827 + kaddr[0] = 0x9DE3BFA8U; /* save */
6828 + flush_dcache_page(vmf->page);
6829 + kunmap(vmf->page);
6830 + return VM_FAULT_MAJOR;
6831 +}
6832 +
6833 +static const struct vm_operations_struct pax_vm_ops = {
6834 + .close = pax_emuplt_close,
6835 + .fault = pax_emuplt_fault
6836 +};
6837 +
6838 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6839 +{
6840 + int ret;
6841 +
6842 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6843 + vma->vm_mm = current->mm;
6844 + vma->vm_start = addr;
6845 + vma->vm_end = addr + PAGE_SIZE;
6846 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6847 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6848 + vma->vm_ops = &pax_vm_ops;
6849 +
6850 + ret = insert_vm_struct(current->mm, vma);
6851 + if (ret)
6852 + return ret;
6853 +
6854 + ++current->mm->total_vm;
6855 + return 0;
6856 +}
6857 +#endif
6858 +
6859 +/*
6860 + * PaX: decide what to do with offenders (regs->tpc = fault address)
6861 + *
6862 + * returns 1 when task should be killed
6863 + * 2 when patched PLT trampoline was detected
6864 + * 3 when unpatched PLT trampoline was detected
6865 + */
6866 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6867 +{
6868 +
6869 +#ifdef CONFIG_PAX_EMUPLT
6870 + int err;
6871 +
6872 + do { /* PaX: patched PLT emulation #1 */
6873 + unsigned int sethi1, sethi2, jmpl;
6874 +
6875 + err = get_user(sethi1, (unsigned int *)regs->tpc);
6876 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6877 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6878 +
6879 + if (err)
6880 + break;
6881 +
6882 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6883 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6884 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6885 + {
6886 + unsigned long addr;
6887 +
6888 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6889 + addr = regs->u_regs[UREG_G1];
6890 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6891 +
6892 + if (test_thread_flag(TIF_32BIT))
6893 + addr &= 0xFFFFFFFFUL;
6894 +
6895 + regs->tpc = addr;
6896 + regs->tnpc = addr+4;
6897 + return 2;
6898 + }
6899 + } while (0);
6900 +
6901 + do { /* PaX: patched PLT emulation #2 */
6902 + unsigned int ba;
6903 +
6904 + err = get_user(ba, (unsigned int *)regs->tpc);
6905 +
6906 + if (err)
6907 + break;
6908 +
6909 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6910 + unsigned long addr;
6911 +
6912 + if ((ba & 0xFFC00000U) == 0x30800000U)
6913 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6914 + else
6915 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6916 +
6917 + if (test_thread_flag(TIF_32BIT))
6918 + addr &= 0xFFFFFFFFUL;
6919 +
6920 + regs->tpc = addr;
6921 + regs->tnpc = addr+4;
6922 + return 2;
6923 + }
6924 + } while (0);
6925 +
6926 + do { /* PaX: patched PLT emulation #3 */
6927 + unsigned int sethi, bajmpl, nop;
6928 +
6929 + err = get_user(sethi, (unsigned int *)regs->tpc);
6930 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
6931 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6932 +
6933 + if (err)
6934 + break;
6935 +
6936 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6937 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6938 + nop == 0x01000000U)
6939 + {
6940 + unsigned long addr;
6941 +
6942 + addr = (sethi & 0x003FFFFFU) << 10;
6943 + regs->u_regs[UREG_G1] = addr;
6944 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6945 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6946 + else
6947 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6948 +
6949 + if (test_thread_flag(TIF_32BIT))
6950 + addr &= 0xFFFFFFFFUL;
6951 +
6952 + regs->tpc = addr;
6953 + regs->tnpc = addr+4;
6954 + return 2;
6955 + }
6956 + } while (0);
6957 +
6958 + do { /* PaX: patched PLT emulation #4 */
6959 + unsigned int sethi, mov1, call, mov2;
6960 +
6961 + err = get_user(sethi, (unsigned int *)regs->tpc);
6962 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
6963 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
6964 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
6965 +
6966 + if (err)
6967 + break;
6968 +
6969 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6970 + mov1 == 0x8210000FU &&
6971 + (call & 0xC0000000U) == 0x40000000U &&
6972 + mov2 == 0x9E100001U)
6973 + {
6974 + unsigned long addr;
6975 +
6976 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
6977 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
6978 +
6979 + if (test_thread_flag(TIF_32BIT))
6980 + addr &= 0xFFFFFFFFUL;
6981 +
6982 + regs->tpc = addr;
6983 + regs->tnpc = addr+4;
6984 + return 2;
6985 + }
6986 + } while (0);
6987 +
6988 + do { /* PaX: patched PLT emulation #5 */
6989 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
6990 +
6991 + err = get_user(sethi, (unsigned int *)regs->tpc);
6992 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
6993 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
6994 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
6995 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
6996 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
6997 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
6998 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
6999 +
7000 + if (err)
7001 + break;
7002 +
7003 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7004 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
7005 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7006 + (or1 & 0xFFFFE000U) == 0x82106000U &&
7007 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7008 + sllx == 0x83287020U &&
7009 + jmpl == 0x81C04005U &&
7010 + nop == 0x01000000U)
7011 + {
7012 + unsigned long addr;
7013 +
7014 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7015 + regs->u_regs[UREG_G1] <<= 32;
7016 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7017 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7018 + regs->tpc = addr;
7019 + regs->tnpc = addr+4;
7020 + return 2;
7021 + }
7022 + } while (0);
7023 +
7024 + do { /* PaX: patched PLT emulation #6 */
7025 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
7026 +
7027 + err = get_user(sethi, (unsigned int *)regs->tpc);
7028 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7029 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7030 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
7031 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
7032 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
7033 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
7034 +
7035 + if (err)
7036 + break;
7037 +
7038 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7039 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
7040 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7041 + sllx == 0x83287020U &&
7042 + (or & 0xFFFFE000U) == 0x8A116000U &&
7043 + jmpl == 0x81C04005U &&
7044 + nop == 0x01000000U)
7045 + {
7046 + unsigned long addr;
7047 +
7048 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
7049 + regs->u_regs[UREG_G1] <<= 32;
7050 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
7051 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7052 + regs->tpc = addr;
7053 + regs->tnpc = addr+4;
7054 + return 2;
7055 + }
7056 + } while (0);
7057 +
7058 + do { /* PaX: unpatched PLT emulation step 1 */
7059 + unsigned int sethi, ba, nop;
7060 +
7061 + err = get_user(sethi, (unsigned int *)regs->tpc);
7062 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7063 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7064 +
7065 + if (err)
7066 + break;
7067 +
7068 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7069 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7070 + nop == 0x01000000U)
7071 + {
7072 + unsigned long addr;
7073 + unsigned int save, call;
7074 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
7075 +
7076 + if ((ba & 0xFFC00000U) == 0x30800000U)
7077 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7078 + else
7079 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7080 +
7081 + if (test_thread_flag(TIF_32BIT))
7082 + addr &= 0xFFFFFFFFUL;
7083 +
7084 + err = get_user(save, (unsigned int *)addr);
7085 + err |= get_user(call, (unsigned int *)(addr+4));
7086 + err |= get_user(nop, (unsigned int *)(addr+8));
7087 + if (err)
7088 + break;
7089 +
7090 +#ifdef CONFIG_PAX_DLRESOLVE
7091 + if (save == 0x9DE3BFA8U &&
7092 + (call & 0xC0000000U) == 0x40000000U &&
7093 + nop == 0x01000000U)
7094 + {
7095 + struct vm_area_struct *vma;
7096 + unsigned long call_dl_resolve;
7097 +
7098 + down_read(&current->mm->mmap_sem);
7099 + call_dl_resolve = current->mm->call_dl_resolve;
7100 + up_read(&current->mm->mmap_sem);
7101 + if (likely(call_dl_resolve))
7102 + goto emulate;
7103 +
7104 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7105 +
7106 + down_write(&current->mm->mmap_sem);
7107 + if (current->mm->call_dl_resolve) {
7108 + call_dl_resolve = current->mm->call_dl_resolve;
7109 + up_write(&current->mm->mmap_sem);
7110 + if (vma)
7111 + kmem_cache_free(vm_area_cachep, vma);
7112 + goto emulate;
7113 + }
7114 +
7115 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7116 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7117 + up_write(&current->mm->mmap_sem);
7118 + if (vma)
7119 + kmem_cache_free(vm_area_cachep, vma);
7120 + return 1;
7121 + }
7122 +
7123 + if (pax_insert_vma(vma, call_dl_resolve)) {
7124 + up_write(&current->mm->mmap_sem);
7125 + kmem_cache_free(vm_area_cachep, vma);
7126 + return 1;
7127 + }
7128 +
7129 + current->mm->call_dl_resolve = call_dl_resolve;
7130 + up_write(&current->mm->mmap_sem);
7131 +
7132 +emulate:
7133 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7134 + regs->tpc = call_dl_resolve;
7135 + regs->tnpc = addr+4;
7136 + return 3;
7137 + }
7138 +#endif
7139 +
7140 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7141 + if ((save & 0xFFC00000U) == 0x05000000U &&
7142 + (call & 0xFFFFE000U) == 0x85C0A000U &&
7143 + nop == 0x01000000U)
7144 + {
7145 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7146 + regs->u_regs[UREG_G2] = addr + 4;
7147 + addr = (save & 0x003FFFFFU) << 10;
7148 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7149 +
7150 + if (test_thread_flag(TIF_32BIT))
7151 + addr &= 0xFFFFFFFFUL;
7152 +
7153 + regs->tpc = addr;
7154 + regs->tnpc = addr+4;
7155 + return 3;
7156 + }
7157 +
7158 + /* PaX: 64-bit PLT stub */
7159 + err = get_user(sethi1, (unsigned int *)addr);
7160 + err |= get_user(sethi2, (unsigned int *)(addr+4));
7161 + err |= get_user(or1, (unsigned int *)(addr+8));
7162 + err |= get_user(or2, (unsigned int *)(addr+12));
7163 + err |= get_user(sllx, (unsigned int *)(addr+16));
7164 + err |= get_user(add, (unsigned int *)(addr+20));
7165 + err |= get_user(jmpl, (unsigned int *)(addr+24));
7166 + err |= get_user(nop, (unsigned int *)(addr+28));
7167 + if (err)
7168 + break;
7169 +
7170 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
7171 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7172 + (or1 & 0xFFFFE000U) == 0x88112000U &&
7173 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7174 + sllx == 0x89293020U &&
7175 + add == 0x8A010005U &&
7176 + jmpl == 0x89C14000U &&
7177 + nop == 0x01000000U)
7178 + {
7179 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7180 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7181 + regs->u_regs[UREG_G4] <<= 32;
7182 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7183 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
7184 + regs->u_regs[UREG_G4] = addr + 24;
7185 + addr = regs->u_regs[UREG_G5];
7186 + regs->tpc = addr;
7187 + regs->tnpc = addr+4;
7188 + return 3;
7189 + }
7190 + }
7191 + } while (0);
7192 +
7193 +#ifdef CONFIG_PAX_DLRESOLVE
7194 + do { /* PaX: unpatched PLT emulation step 2 */
7195 + unsigned int save, call, nop;
7196 +
7197 + err = get_user(save, (unsigned int *)(regs->tpc-4));
7198 + err |= get_user(call, (unsigned int *)regs->tpc);
7199 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
7200 + if (err)
7201 + break;
7202 +
7203 + if (save == 0x9DE3BFA8U &&
7204 + (call & 0xC0000000U) == 0x40000000U &&
7205 + nop == 0x01000000U)
7206 + {
7207 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7208 +
7209 + if (test_thread_flag(TIF_32BIT))
7210 + dl_resolve &= 0xFFFFFFFFUL;
7211 +
7212 + regs->u_regs[UREG_RETPC] = regs->tpc;
7213 + regs->tpc = dl_resolve;
7214 + regs->tnpc = dl_resolve+4;
7215 + return 3;
7216 + }
7217 + } while (0);
7218 +#endif
7219 +
7220 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
7221 + unsigned int sethi, ba, nop;
7222 +
7223 + err = get_user(sethi, (unsigned int *)regs->tpc);
7224 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7225 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7226 +
7227 + if (err)
7228 + break;
7229 +
7230 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7231 + (ba & 0xFFF00000U) == 0x30600000U &&
7232 + nop == 0x01000000U)
7233 + {
7234 + unsigned long addr;
7235 +
7236 + addr = (sethi & 0x003FFFFFU) << 10;
7237 + regs->u_regs[UREG_G1] = addr;
7238 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7239 +
7240 + if (test_thread_flag(TIF_32BIT))
7241 + addr &= 0xFFFFFFFFUL;
7242 +
7243 + regs->tpc = addr;
7244 + regs->tnpc = addr+4;
7245 + return 2;
7246 + }
7247 + } while (0);
7248 +
7249 +#endif
7250 +
7251 + return 1;
7252 +}
7253 +
7254 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7255 +{
7256 + unsigned long i;
7257 +
7258 + printk(KERN_ERR "PAX: bytes at PC: ");
7259 + for (i = 0; i < 8; i++) {
7260 + unsigned int c;
7261 + if (get_user(c, (unsigned int *)pc+i))
7262 + printk(KERN_CONT "???????? ");
7263 + else
7264 + printk(KERN_CONT "%08x ", c);
7265 + }
7266 + printk("\n");
7267 +}
7268 +#endif
7269 +
7270 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
7271 {
7272 struct mm_struct *mm = current->mm;
7273 @@ -343,6 +806,29 @@ retry:
7274 if (!vma)
7275 goto bad_area;
7276
7277 +#ifdef CONFIG_PAX_PAGEEXEC
7278 + /* PaX: detect ITLB misses on non-exec pages */
7279 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
7280 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
7281 + {
7282 + if (address != regs->tpc)
7283 + goto good_area;
7284 +
7285 + up_read(&mm->mmap_sem);
7286 + switch (pax_handle_fetch_fault(regs)) {
7287 +
7288 +#ifdef CONFIG_PAX_EMUPLT
7289 + case 2:
7290 + case 3:
7291 + return;
7292 +#endif
7293 +
7294 + }
7295 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
7296 + do_group_exit(SIGKILL);
7297 + }
7298 +#endif
7299 +
7300 /* Pure DTLB misses do not tell us whether the fault causing
7301 * load/store/atomic was a write or not, it only says that there
7302 * was no match. So in such a case we (carefully) read the
7303 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
7304 index 07e1453..0a7d9e9 100644
7305 --- a/arch/sparc/mm/hugetlbpage.c
7306 +++ b/arch/sparc/mm/hugetlbpage.c
7307 @@ -67,7 +67,7 @@ full_search:
7308 }
7309 return -ENOMEM;
7310 }
7311 - if (likely(!vma || addr + len <= vma->vm_start)) {
7312 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7313 /*
7314 * Remember the place where we stopped the search:
7315 */
7316 @@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7317 /* make sure it can fit in the remaining address space */
7318 if (likely(addr > len)) {
7319 vma = find_vma(mm, addr-len);
7320 - if (!vma || addr <= vma->vm_start) {
7321 + if (check_heap_stack_gap(vma, addr - len, len)) {
7322 /* remember the address as a hint for next time */
7323 return (mm->free_area_cache = addr-len);
7324 }
7325 @@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7326 if (unlikely(mm->mmap_base < len))
7327 goto bottomup;
7328
7329 - addr = (mm->mmap_base-len) & HPAGE_MASK;
7330 + addr = mm->mmap_base - len;
7331
7332 do {
7333 + addr &= HPAGE_MASK;
7334 /*
7335 * Lookup failure means no vma is above this address,
7336 * else if new region fits below vma->vm_start,
7337 * return with success:
7338 */
7339 vma = find_vma(mm, addr);
7340 - if (likely(!vma || addr+len <= vma->vm_start)) {
7341 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7342 /* remember the address as a hint for next time */
7343 return (mm->free_area_cache = addr);
7344 }
7345 @@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7346 mm->cached_hole_size = vma->vm_start - addr;
7347
7348 /* try just below the current vma->vm_start */
7349 - addr = (vma->vm_start-len) & HPAGE_MASK;
7350 - } while (likely(len < vma->vm_start));
7351 + addr = skip_heap_stack_gap(vma, len);
7352 + } while (!IS_ERR_VALUE(addr));
7353
7354 bottomup:
7355 /*
7356 @@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
7357 if (addr) {
7358 addr = ALIGN(addr, HPAGE_SIZE);
7359 vma = find_vma(mm, addr);
7360 - if (task_size - len >= addr &&
7361 - (!vma || addr + len <= vma->vm_start))
7362 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
7363 return addr;
7364 }
7365 if (mm->get_unmapped_area == arch_get_unmapped_area)
7366 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
7367 index f4500c6..889656c 100644
7368 --- a/arch/tile/include/asm/atomic_64.h
7369 +++ b/arch/tile/include/asm/atomic_64.h
7370 @@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7371
7372 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7373
7374 +#define atomic64_read_unchecked(v) atomic64_read(v)
7375 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7376 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7377 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7378 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7379 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7380 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7381 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7382 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7383 +
7384 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
7385 #define smp_mb__before_atomic_dec() smp_mb()
7386 #define smp_mb__after_atomic_dec() smp_mb()
7387 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
7388 index a9a5299..0fce79e 100644
7389 --- a/arch/tile/include/asm/cache.h
7390 +++ b/arch/tile/include/asm/cache.h
7391 @@ -15,11 +15,12 @@
7392 #ifndef _ASM_TILE_CACHE_H
7393 #define _ASM_TILE_CACHE_H
7394
7395 +#include <linux/const.h>
7396 #include <arch/chip.h>
7397
7398 /* bytes per L1 data cache line */
7399 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
7400 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7401 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7402
7403 /* bytes per L2 cache line */
7404 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
7405 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
7406 index 9ab078a..d6635c2 100644
7407 --- a/arch/tile/include/asm/uaccess.h
7408 +++ b/arch/tile/include/asm/uaccess.h
7409 @@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
7410 const void __user *from,
7411 unsigned long n)
7412 {
7413 - int sz = __compiletime_object_size(to);
7414 + size_t sz = __compiletime_object_size(to);
7415
7416 - if (likely(sz == -1 || sz >= n))
7417 + if (likely(sz == (size_t)-1 || sz >= n))
7418 n = _copy_from_user(to, from, n);
7419 else
7420 copy_from_user_overflow();
7421 diff --git a/arch/um/Makefile b/arch/um/Makefile
7422 index 0970910..9f65c40 100644
7423 --- a/arch/um/Makefile
7424 +++ b/arch/um/Makefile
7425 @@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
7426 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
7427 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
7428
7429 +ifdef CONSTIFY_PLUGIN
7430 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7431 +endif
7432 +
7433 #This will adjust *FLAGS accordingly to the platform.
7434 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
7435
7436 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
7437 index 19e1bdd..3665b77 100644
7438 --- a/arch/um/include/asm/cache.h
7439 +++ b/arch/um/include/asm/cache.h
7440 @@ -1,6 +1,7 @@
7441 #ifndef __UM_CACHE_H
7442 #define __UM_CACHE_H
7443
7444 +#include <linux/const.h>
7445
7446 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
7447 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
7448 @@ -12,6 +13,6 @@
7449 # define L1_CACHE_SHIFT 5
7450 #endif
7451
7452 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7453 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7454
7455 #endif
7456 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
7457 index 2e0a6b1..a64d0f5 100644
7458 --- a/arch/um/include/asm/kmap_types.h
7459 +++ b/arch/um/include/asm/kmap_types.h
7460 @@ -8,6 +8,6 @@
7461
7462 /* No more #include "asm/arch/kmap_types.h" ! */
7463
7464 -#define KM_TYPE_NR 14
7465 +#define KM_TYPE_NR 15
7466
7467 #endif
7468 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
7469 index 7cfc3ce..cbd1a58 100644
7470 --- a/arch/um/include/asm/page.h
7471 +++ b/arch/um/include/asm/page.h
7472 @@ -14,6 +14,9 @@
7473 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
7474 #define PAGE_MASK (~(PAGE_SIZE-1))
7475
7476 +#define ktla_ktva(addr) (addr)
7477 +#define ktva_ktla(addr) (addr)
7478 +
7479 #ifndef __ASSEMBLY__
7480
7481 struct page;
7482 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
7483 index 0032f92..cd151e0 100644
7484 --- a/arch/um/include/asm/pgtable-3level.h
7485 +++ b/arch/um/include/asm/pgtable-3level.h
7486 @@ -58,6 +58,7 @@
7487 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
7488 #define pud_populate(mm, pud, pmd) \
7489 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
7490 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7491
7492 #ifdef CONFIG_64BIT
7493 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
7494 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
7495 index c5f5afa..6abce4b 100644
7496 --- a/arch/um/kernel/process.c
7497 +++ b/arch/um/kernel/process.c
7498 @@ -402,22 +402,6 @@ int singlestepping(void * t)
7499 return 2;
7500 }
7501
7502 -/*
7503 - * Only x86 and x86_64 have an arch_align_stack().
7504 - * All other arches have "#define arch_align_stack(x) (x)"
7505 - * in their asm/system.h
7506 - * As this is included in UML from asm-um/system-generic.h,
7507 - * we can use it to behave as the subarch does.
7508 - */
7509 -#ifndef arch_align_stack
7510 -unsigned long arch_align_stack(unsigned long sp)
7511 -{
7512 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7513 - sp -= get_random_int() % 8192;
7514 - return sp & ~0xf;
7515 -}
7516 -#endif
7517 -
7518 unsigned long get_wchan(struct task_struct *p)
7519 {
7520 unsigned long stack_page, sp, ip;
7521 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
7522 index ad8f795..2c7eec6 100644
7523 --- a/arch/unicore32/include/asm/cache.h
7524 +++ b/arch/unicore32/include/asm/cache.h
7525 @@ -12,8 +12,10 @@
7526 #ifndef __UNICORE_CACHE_H__
7527 #define __UNICORE_CACHE_H__
7528
7529 -#define L1_CACHE_SHIFT (5)
7530 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7531 +#include <linux/const.h>
7532 +
7533 +#define L1_CACHE_SHIFT 5
7534 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7535
7536 /*
7537 * Memory returned by kmalloc() may be used for DMA, so we must make
7538 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
7539 index 50a1d1f..c26369f 100644
7540 --- a/arch/x86/Kconfig
7541 +++ b/arch/x86/Kconfig
7542 @@ -220,7 +220,7 @@ config X86_HT
7543
7544 config X86_32_LAZY_GS
7545 def_bool y
7546 - depends on X86_32 && !CC_STACKPROTECTOR
7547 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
7548
7549 config ARCH_HWEIGHT_CFLAGS
7550 string
7551 @@ -1049,7 +1049,7 @@ choice
7552
7553 config NOHIGHMEM
7554 bool "off"
7555 - depends on !X86_NUMAQ
7556 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7557 ---help---
7558 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
7559 However, the address space of 32-bit x86 processors is only 4
7560 @@ -1086,7 +1086,7 @@ config NOHIGHMEM
7561
7562 config HIGHMEM4G
7563 bool "4GB"
7564 - depends on !X86_NUMAQ
7565 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7566 ---help---
7567 Select this if you have a 32-bit processor and between 1 and 4
7568 gigabytes of physical RAM.
7569 @@ -1140,7 +1140,7 @@ config PAGE_OFFSET
7570 hex
7571 default 0xB0000000 if VMSPLIT_3G_OPT
7572 default 0x80000000 if VMSPLIT_2G
7573 - default 0x78000000 if VMSPLIT_2G_OPT
7574 + default 0x70000000 if VMSPLIT_2G_OPT
7575 default 0x40000000 if VMSPLIT_1G
7576 default 0xC0000000
7577 depends on X86_32
7578 @@ -1528,6 +1528,7 @@ config SECCOMP
7579
7580 config CC_STACKPROTECTOR
7581 bool "Enable -fstack-protector buffer overflow detection"
7582 + depends on X86_64 || !PAX_MEMORY_UDEREF
7583 ---help---
7584 This option turns on the -fstack-protector GCC feature. This
7585 feature puts, at the beginning of functions, a canary value on
7586 @@ -1585,6 +1586,7 @@ config KEXEC_JUMP
7587 config PHYSICAL_START
7588 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
7589 default "0x1000000"
7590 + range 0x400000 0x40000000
7591 ---help---
7592 This gives the physical address where the kernel is loaded.
7593
7594 @@ -1648,6 +1650,7 @@ config X86_NEED_RELOCS
7595 config PHYSICAL_ALIGN
7596 hex "Alignment value to which kernel should be aligned" if X86_32
7597 default "0x1000000"
7598 + range 0x400000 0x1000000 if PAX_KERNEXEC
7599 range 0x2000 0x1000000
7600 ---help---
7601 This value puts the alignment restrictions on physical address
7602 @@ -1679,9 +1682,10 @@ config HOTPLUG_CPU
7603 Say N if you want to disable CPU hotplug.
7604
7605 config COMPAT_VDSO
7606 - def_bool y
7607 + def_bool n
7608 prompt "Compat VDSO support"
7609 depends on X86_32 || IA32_EMULATION
7610 + depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
7611 ---help---
7612 Map the 32-bit VDSO to the predictable old-style address too.
7613
7614 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
7615 index 706e12e..62e4feb 100644
7616 --- a/arch/x86/Kconfig.cpu
7617 +++ b/arch/x86/Kconfig.cpu
7618 @@ -334,7 +334,7 @@ config X86_PPRO_FENCE
7619
7620 config X86_F00F_BUG
7621 def_bool y
7622 - depends on M586MMX || M586TSC || M586 || M486 || M386
7623 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
7624
7625 config X86_INVD_BUG
7626 def_bool y
7627 @@ -358,7 +358,7 @@ config X86_POPAD_OK
7628
7629 config X86_ALIGNMENT_16
7630 def_bool y
7631 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7632 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7633
7634 config X86_INTEL_USERCOPY
7635 def_bool y
7636 @@ -404,7 +404,7 @@ config X86_CMPXCHG64
7637 # generates cmov.
7638 config X86_CMOV
7639 def_bool y
7640 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7641 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7642
7643 config X86_MINIMUM_CPU_FAMILY
7644 int
7645 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
7646 index b322f12..652d0d9 100644
7647 --- a/arch/x86/Kconfig.debug
7648 +++ b/arch/x86/Kconfig.debug
7649 @@ -84,7 +84,7 @@ config X86_PTDUMP
7650 config DEBUG_RODATA
7651 bool "Write protect kernel read-only data structures"
7652 default y
7653 - depends on DEBUG_KERNEL
7654 + depends on DEBUG_KERNEL && BROKEN
7655 ---help---
7656 Mark the kernel read-only data as write-protected in the pagetables,
7657 in order to catch accidental (and incorrect) writes to such const
7658 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
7659
7660 config DEBUG_SET_MODULE_RONX
7661 bool "Set loadable kernel module data as NX and text as RO"
7662 - depends on MODULES
7663 + depends on MODULES && BROKEN
7664 ---help---
7665 This option helps catch unintended modifications to loadable
7666 kernel module's text and read-only data. It also prevents execution
7667 @@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
7668
7669 config DEBUG_STRICT_USER_COPY_CHECKS
7670 bool "Strict copy size checks"
7671 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
7672 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
7673 ---help---
7674 Enabling this option turns a certain set of sanity checks for user
7675 copy operations into compile time failures.
7676 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
7677 index 05afcca..b6ecb51 100644
7678 --- a/arch/x86/Makefile
7679 +++ b/arch/x86/Makefile
7680 @@ -50,6 +50,7 @@ else
7681 UTS_MACHINE := x86_64
7682 CHECKFLAGS += -D__x86_64__ -m64
7683
7684 + biarch := $(call cc-option,-m64)
7685 KBUILD_AFLAGS += -m64
7686 KBUILD_CFLAGS += -m64
7687
7688 @@ -229,3 +230,12 @@ define archhelp
7689 echo ' FDARGS="..." arguments for the booted kernel'
7690 echo ' FDINITRD=file initrd for the booted kernel'
7691 endef
7692 +
7693 +define OLD_LD
7694 +
7695 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
7696 +*** Please upgrade your binutils to 2.18 or newer
7697 +endef
7698 +
7699 +archprepare:
7700 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
7701 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
7702 index f7535be..37db2d1 100644
7703 --- a/arch/x86/boot/Makefile
7704 +++ b/arch/x86/boot/Makefile
7705 @@ -64,6 +64,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
7706 $(call cc-option, -fno-stack-protector) \
7707 $(call cc-option, -mpreferred-stack-boundary=2)
7708 KBUILD_CFLAGS += $(call cc-option, -m32)
7709 +ifdef CONSTIFY_PLUGIN
7710 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7711 +endif
7712 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7713 GCOV_PROFILE := n
7714
7715 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7716 index 878e4b9..20537ab 100644
7717 --- a/arch/x86/boot/bitops.h
7718 +++ b/arch/x86/boot/bitops.h
7719 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7720 u8 v;
7721 const u32 *p = (const u32 *)addr;
7722
7723 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7724 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7725 return v;
7726 }
7727
7728 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7729
7730 static inline void set_bit(int nr, void *addr)
7731 {
7732 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7733 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7734 }
7735
7736 #endif /* BOOT_BITOPS_H */
7737 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7738 index 18997e5..83d9c67 100644
7739 --- a/arch/x86/boot/boot.h
7740 +++ b/arch/x86/boot/boot.h
7741 @@ -85,7 +85,7 @@ static inline void io_delay(void)
7742 static inline u16 ds(void)
7743 {
7744 u16 seg;
7745 - asm("movw %%ds,%0" : "=rm" (seg));
7746 + asm volatile("movw %%ds,%0" : "=rm" (seg));
7747 return seg;
7748 }
7749
7750 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
7751 static inline int memcmp(const void *s1, const void *s2, size_t len)
7752 {
7753 u8 diff;
7754 - asm("repe; cmpsb; setnz %0"
7755 + asm volatile("repe; cmpsb; setnz %0"
7756 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7757 return diff;
7758 }
7759 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7760 index 8a84501..b2d165f 100644
7761 --- a/arch/x86/boot/compressed/Makefile
7762 +++ b/arch/x86/boot/compressed/Makefile
7763 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
7764 KBUILD_CFLAGS += $(cflags-y)
7765 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
7766 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
7767 +ifdef CONSTIFY_PLUGIN
7768 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7769 +endif
7770
7771 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7772 GCOV_PROFILE := n
7773 diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
7774 index b3e0227..f2c02d5 100644
7775 --- a/arch/x86/boot/compressed/eboot.c
7776 +++ b/arch/x86/boot/compressed/eboot.c
7777 @@ -142,7 +142,6 @@ again:
7778 *addr = max_addr;
7779 }
7780
7781 -free_pool:
7782 efi_call_phys1(sys_table->boottime->free_pool, map);
7783
7784 fail:
7785 @@ -206,7 +205,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
7786 if (i == map_size / desc_size)
7787 status = EFI_NOT_FOUND;
7788
7789 -free_pool:
7790 efi_call_phys1(sys_table->boottime->free_pool, map);
7791 fail:
7792 return status;
7793 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7794 index aa4aaf1..6656f2f 100644
7795 --- a/arch/x86/boot/compressed/head_32.S
7796 +++ b/arch/x86/boot/compressed/head_32.S
7797 @@ -116,7 +116,7 @@ preferred_addr:
7798 notl %eax
7799 andl %eax, %ebx
7800 #else
7801 - movl $LOAD_PHYSICAL_ADDR, %ebx
7802 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7803 #endif
7804
7805 /* Target address to relocate to for decompression */
7806 @@ -202,7 +202,7 @@ relocated:
7807 * and where it was actually loaded.
7808 */
7809 movl %ebp, %ebx
7810 - subl $LOAD_PHYSICAL_ADDR, %ebx
7811 + subl $____LOAD_PHYSICAL_ADDR, %ebx
7812 jz 2f /* Nothing to be done if loaded at compiled addr. */
7813 /*
7814 * Process relocations.
7815 @@ -210,8 +210,7 @@ relocated:
7816
7817 1: subl $4, %edi
7818 movl (%edi), %ecx
7819 - testl %ecx, %ecx
7820 - jz 2f
7821 + jecxz 2f
7822 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7823 jmp 1b
7824 2:
7825 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7826 index 2c4b171..e1fa5b1 100644
7827 --- a/arch/x86/boot/compressed/head_64.S
7828 +++ b/arch/x86/boot/compressed/head_64.S
7829 @@ -91,7 +91,7 @@ ENTRY(startup_32)
7830 notl %eax
7831 andl %eax, %ebx
7832 #else
7833 - movl $LOAD_PHYSICAL_ADDR, %ebx
7834 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7835 #endif
7836
7837 /* Target address to relocate to for decompression */
7838 @@ -273,7 +273,7 @@ preferred_addr:
7839 notq %rax
7840 andq %rax, %rbp
7841 #else
7842 - movq $LOAD_PHYSICAL_ADDR, %rbp
7843 + movq $____LOAD_PHYSICAL_ADDR, %rbp
7844 #endif
7845
7846 /* Target address to relocate to for decompression */
7847 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7848 index 88f7ff6..ed695dd 100644
7849 --- a/arch/x86/boot/compressed/misc.c
7850 +++ b/arch/x86/boot/compressed/misc.c
7851 @@ -303,7 +303,7 @@ static void parse_elf(void *output)
7852 case PT_LOAD:
7853 #ifdef CONFIG_RELOCATABLE
7854 dest = output;
7855 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7856 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7857 #else
7858 dest = (void *)(phdr->p_paddr);
7859 #endif
7860 @@ -352,7 +352,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
7861 error("Destination address too large");
7862 #endif
7863 #ifndef CONFIG_RELOCATABLE
7864 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7865 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7866 error("Wrong destination address");
7867 #endif
7868
7869 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
7870 index 4d3ff03..e4972ff 100644
7871 --- a/arch/x86/boot/cpucheck.c
7872 +++ b/arch/x86/boot/cpucheck.c
7873 @@ -74,7 +74,7 @@ static int has_fpu(void)
7874 u16 fcw = -1, fsw = -1;
7875 u32 cr0;
7876
7877 - asm("movl %%cr0,%0" : "=r" (cr0));
7878 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
7879 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7880 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7881 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7882 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7883 {
7884 u32 f0, f1;
7885
7886 - asm("pushfl ; "
7887 + asm volatile("pushfl ; "
7888 "pushfl ; "
7889 "popl %0 ; "
7890 "movl %0,%1 ; "
7891 @@ -115,7 +115,7 @@ static void get_flags(void)
7892 set_bit(X86_FEATURE_FPU, cpu.flags);
7893
7894 if (has_eflag(X86_EFLAGS_ID)) {
7895 - asm("cpuid"
7896 + asm volatile("cpuid"
7897 : "=a" (max_intel_level),
7898 "=b" (cpu_vendor[0]),
7899 "=d" (cpu_vendor[1]),
7900 @@ -124,7 +124,7 @@ static void get_flags(void)
7901
7902 if (max_intel_level >= 0x00000001 &&
7903 max_intel_level <= 0x0000ffff) {
7904 - asm("cpuid"
7905 + asm volatile("cpuid"
7906 : "=a" (tfms),
7907 "=c" (cpu.flags[4]),
7908 "=d" (cpu.flags[0])
7909 @@ -136,7 +136,7 @@ static void get_flags(void)
7910 cpu.model += ((tfms >> 16) & 0xf) << 4;
7911 }
7912
7913 - asm("cpuid"
7914 + asm volatile("cpuid"
7915 : "=a" (max_amd_level)
7916 : "a" (0x80000000)
7917 : "ebx", "ecx", "edx");
7918 @@ -144,7 +144,7 @@ static void get_flags(void)
7919 if (max_amd_level >= 0x80000001 &&
7920 max_amd_level <= 0x8000ffff) {
7921 u32 eax = 0x80000001;
7922 - asm("cpuid"
7923 + asm volatile("cpuid"
7924 : "+a" (eax),
7925 "=c" (cpu.flags[6]),
7926 "=d" (cpu.flags[1])
7927 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7928 u32 ecx = MSR_K7_HWCR;
7929 u32 eax, edx;
7930
7931 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7932 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7933 eax &= ~(1 << 15);
7934 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7935 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7936
7937 get_flags(); /* Make sure it really did something */
7938 err = check_flags();
7939 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7940 u32 ecx = MSR_VIA_FCR;
7941 u32 eax, edx;
7942
7943 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7944 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7945 eax |= (1<<1)|(1<<7);
7946 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7947 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7948
7949 set_bit(X86_FEATURE_CX8, cpu.flags);
7950 err = check_flags();
7951 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7952 u32 eax, edx;
7953 u32 level = 1;
7954
7955 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7956 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7957 - asm("cpuid"
7958 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7959 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7960 + asm volatile("cpuid"
7961 : "+a" (level), "=d" (cpu.flags[0])
7962 : : "ecx", "ebx");
7963 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7964 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7965
7966 err = check_flags();
7967 }
7968 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
7969 index b4e15dd..8ac59ce 100644
7970 --- a/arch/x86/boot/header.S
7971 +++ b/arch/x86/boot/header.S
7972 @@ -391,10 +391,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
7973 # single linked list of
7974 # struct setup_data
7975
7976 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
7977 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
7978
7979 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
7980 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
7981 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
7982 +#else
7983 #define VO_INIT_SIZE (VO__end - VO__text)
7984 +#endif
7985 #if ZO_INIT_SIZE > VO_INIT_SIZE
7986 #define INIT_SIZE ZO_INIT_SIZE
7987 #else
7988 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
7989 index db75d07..8e6d0af 100644
7990 --- a/arch/x86/boot/memory.c
7991 +++ b/arch/x86/boot/memory.c
7992 @@ -19,7 +19,7 @@
7993
7994 static int detect_memory_e820(void)
7995 {
7996 - int count = 0;
7997 + unsigned int count = 0;
7998 struct biosregs ireg, oreg;
7999 struct e820entry *desc = boot_params.e820_map;
8000 static struct e820entry buf; /* static so it is zeroed */
8001 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
8002 index 11e8c6e..fdbb1ed 100644
8003 --- a/arch/x86/boot/video-vesa.c
8004 +++ b/arch/x86/boot/video-vesa.c
8005 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
8006
8007 boot_params.screen_info.vesapm_seg = oreg.es;
8008 boot_params.screen_info.vesapm_off = oreg.di;
8009 + boot_params.screen_info.vesapm_size = oreg.cx;
8010 }
8011
8012 /*
8013 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
8014 index 43eda28..5ab5fdb 100644
8015 --- a/arch/x86/boot/video.c
8016 +++ b/arch/x86/boot/video.c
8017 @@ -96,7 +96,7 @@ static void store_mode_params(void)
8018 static unsigned int get_entry(void)
8019 {
8020 char entry_buf[4];
8021 - int i, len = 0;
8022 + unsigned int i, len = 0;
8023 int key;
8024 unsigned int v;
8025
8026 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
8027 index 5b577d5..3c1fed4 100644
8028 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
8029 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
8030 @@ -8,6 +8,8 @@
8031 * including this sentence is retained in full.
8032 */
8033
8034 +#include <asm/alternative-asm.h>
8035 +
8036 .extern crypto_ft_tab
8037 .extern crypto_it_tab
8038 .extern crypto_fl_tab
8039 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
8040 je B192; \
8041 leaq 32(r9),r9;
8042
8043 +#define ret pax_force_retaddr 0, 1; ret
8044 +
8045 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
8046 movq r1,r2; \
8047 movq r3,r4; \
8048 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
8049 index 3470624..201259d 100644
8050 --- a/arch/x86/crypto/aesni-intel_asm.S
8051 +++ b/arch/x86/crypto/aesni-intel_asm.S
8052 @@ -31,6 +31,7 @@
8053
8054 #include <linux/linkage.h>
8055 #include <asm/inst.h>
8056 +#include <asm/alternative-asm.h>
8057
8058 #ifdef __x86_64__
8059 .data
8060 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
8061 pop %r14
8062 pop %r13
8063 pop %r12
8064 + pax_force_retaddr 0, 1
8065 ret
8066 +ENDPROC(aesni_gcm_dec)
8067
8068
8069 /*****************************************************************************
8070 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
8071 pop %r14
8072 pop %r13
8073 pop %r12
8074 + pax_force_retaddr 0, 1
8075 ret
8076 +ENDPROC(aesni_gcm_enc)
8077
8078 #endif
8079
8080 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
8081 pxor %xmm1, %xmm0
8082 movaps %xmm0, (TKEYP)
8083 add $0x10, TKEYP
8084 + pax_force_retaddr_bts
8085 ret
8086
8087 .align 4
8088 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
8089 shufps $0b01001110, %xmm2, %xmm1
8090 movaps %xmm1, 0x10(TKEYP)
8091 add $0x20, TKEYP
8092 + pax_force_retaddr_bts
8093 ret
8094
8095 .align 4
8096 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
8097
8098 movaps %xmm0, (TKEYP)
8099 add $0x10, TKEYP
8100 + pax_force_retaddr_bts
8101 ret
8102
8103 .align 4
8104 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
8105 pxor %xmm1, %xmm2
8106 movaps %xmm2, (TKEYP)
8107 add $0x10, TKEYP
8108 + pax_force_retaddr_bts
8109 ret
8110
8111 /*
8112 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
8113 #ifndef __x86_64__
8114 popl KEYP
8115 #endif
8116 + pax_force_retaddr 0, 1
8117 ret
8118 +ENDPROC(aesni_set_key)
8119
8120 /*
8121 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
8122 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
8123 popl KLEN
8124 popl KEYP
8125 #endif
8126 + pax_force_retaddr 0, 1
8127 ret
8128 +ENDPROC(aesni_enc)
8129
8130 /*
8131 * _aesni_enc1: internal ABI
8132 @@ -1959,6 +1972,7 @@ _aesni_enc1:
8133 AESENC KEY STATE
8134 movaps 0x70(TKEYP), KEY
8135 AESENCLAST KEY STATE
8136 + pax_force_retaddr_bts
8137 ret
8138
8139 /*
8140 @@ -2067,6 +2081,7 @@ _aesni_enc4:
8141 AESENCLAST KEY STATE2
8142 AESENCLAST KEY STATE3
8143 AESENCLAST KEY STATE4
8144 + pax_force_retaddr_bts
8145 ret
8146
8147 /*
8148 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
8149 popl KLEN
8150 popl KEYP
8151 #endif
8152 + pax_force_retaddr 0, 1
8153 ret
8154 +ENDPROC(aesni_dec)
8155
8156 /*
8157 * _aesni_dec1: internal ABI
8158 @@ -2146,6 +2163,7 @@ _aesni_dec1:
8159 AESDEC KEY STATE
8160 movaps 0x70(TKEYP), KEY
8161 AESDECLAST KEY STATE
8162 + pax_force_retaddr_bts
8163 ret
8164
8165 /*
8166 @@ -2254,6 +2272,7 @@ _aesni_dec4:
8167 AESDECLAST KEY STATE2
8168 AESDECLAST KEY STATE3
8169 AESDECLAST KEY STATE4
8170 + pax_force_retaddr_bts
8171 ret
8172
8173 /*
8174 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
8175 popl KEYP
8176 popl LEN
8177 #endif
8178 + pax_force_retaddr 0, 1
8179 ret
8180 +ENDPROC(aesni_ecb_enc)
8181
8182 /*
8183 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8184 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
8185 popl KEYP
8186 popl LEN
8187 #endif
8188 + pax_force_retaddr 0, 1
8189 ret
8190 +ENDPROC(aesni_ecb_dec)
8191
8192 /*
8193 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8194 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
8195 popl LEN
8196 popl IVP
8197 #endif
8198 + pax_force_retaddr 0, 1
8199 ret
8200 +ENDPROC(aesni_cbc_enc)
8201
8202 /*
8203 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8204 @@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
8205 popl LEN
8206 popl IVP
8207 #endif
8208 + pax_force_retaddr 0, 1
8209 ret
8210 +ENDPROC(aesni_cbc_dec)
8211
8212 #ifdef __x86_64__
8213 .align 16
8214 @@ -2526,6 +2553,7 @@ _aesni_inc_init:
8215 mov $1, TCTR_LOW
8216 MOVQ_R64_XMM TCTR_LOW INC
8217 MOVQ_R64_XMM CTR TCTR_LOW
8218 + pax_force_retaddr_bts
8219 ret
8220
8221 /*
8222 @@ -2554,6 +2582,7 @@ _aesni_inc:
8223 .Linc_low:
8224 movaps CTR, IV
8225 PSHUFB_XMM BSWAP_MASK IV
8226 + pax_force_retaddr_bts
8227 ret
8228
8229 /*
8230 @@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
8231 .Lctr_enc_ret:
8232 movups IV, (IVP)
8233 .Lctr_enc_just_ret:
8234 + pax_force_retaddr 0, 1
8235 ret
8236 +ENDPROC(aesni_ctr_enc)
8237 #endif
8238 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8239 index 391d245..67f35c2 100644
8240 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
8241 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8242 @@ -20,6 +20,8 @@
8243 *
8244 */
8245
8246 +#include <asm/alternative-asm.h>
8247 +
8248 .file "blowfish-x86_64-asm.S"
8249 .text
8250
8251 @@ -151,9 +153,11 @@ __blowfish_enc_blk:
8252 jnz __enc_xor;
8253
8254 write_block();
8255 + pax_force_retaddr 0, 1
8256 ret;
8257 __enc_xor:
8258 xor_block();
8259 + pax_force_retaddr 0, 1
8260 ret;
8261
8262 .align 8
8263 @@ -188,6 +192,7 @@ blowfish_dec_blk:
8264
8265 movq %r11, %rbp;
8266
8267 + pax_force_retaddr 0, 1
8268 ret;
8269
8270 /**********************************************************************
8271 @@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
8272
8273 popq %rbx;
8274 popq %rbp;
8275 + pax_force_retaddr 0, 1
8276 ret;
8277
8278 __enc_xor4:
8279 @@ -349,6 +355,7 @@ __enc_xor4:
8280
8281 popq %rbx;
8282 popq %rbp;
8283 + pax_force_retaddr 0, 1
8284 ret;
8285
8286 .align 8
8287 @@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
8288 popq %rbx;
8289 popq %rbp;
8290
8291 + pax_force_retaddr 0, 1
8292 ret;
8293
8294 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
8295 index 0b33743..7a56206 100644
8296 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
8297 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
8298 @@ -20,6 +20,8 @@
8299 *
8300 */
8301
8302 +#include <asm/alternative-asm.h>
8303 +
8304 .file "camellia-x86_64-asm_64.S"
8305 .text
8306
8307 @@ -229,12 +231,14 @@ __enc_done:
8308 enc_outunpack(mov, RT1);
8309
8310 movq RRBP, %rbp;
8311 + pax_force_retaddr 0, 1
8312 ret;
8313
8314 __enc_xor:
8315 enc_outunpack(xor, RT1);
8316
8317 movq RRBP, %rbp;
8318 + pax_force_retaddr 0, 1
8319 ret;
8320
8321 .global camellia_dec_blk;
8322 @@ -275,6 +279,7 @@ __dec_rounds16:
8323 dec_outunpack();
8324
8325 movq RRBP, %rbp;
8326 + pax_force_retaddr 0, 1
8327 ret;
8328
8329 /**********************************************************************
8330 @@ -468,6 +473,7 @@ __enc2_done:
8331
8332 movq RRBP, %rbp;
8333 popq %rbx;
8334 + pax_force_retaddr 0, 1
8335 ret;
8336
8337 __enc2_xor:
8338 @@ -475,6 +481,7 @@ __enc2_xor:
8339
8340 movq RRBP, %rbp;
8341 popq %rbx;
8342 + pax_force_retaddr 0, 1
8343 ret;
8344
8345 .global camellia_dec_blk_2way;
8346 @@ -517,4 +524,5 @@ __dec2_rounds16:
8347
8348 movq RRBP, %rbp;
8349 movq RXOR, %rbx;
8350 + pax_force_retaddr 0, 1
8351 ret;
8352 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8353 index 6214a9b..1f4fc9a 100644
8354 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
8355 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8356 @@ -1,3 +1,5 @@
8357 +#include <asm/alternative-asm.h>
8358 +
8359 # enter ECRYPT_encrypt_bytes
8360 .text
8361 .p2align 5
8362 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
8363 add %r11,%rsp
8364 mov %rdi,%rax
8365 mov %rsi,%rdx
8366 + pax_force_retaddr 0, 1
8367 ret
8368 # bytesatleast65:
8369 ._bytesatleast65:
8370 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
8371 add %r11,%rsp
8372 mov %rdi,%rax
8373 mov %rsi,%rdx
8374 + pax_force_retaddr
8375 ret
8376 # enter ECRYPT_ivsetup
8377 .text
8378 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
8379 add %r11,%rsp
8380 mov %rdi,%rax
8381 mov %rsi,%rdx
8382 + pax_force_retaddr
8383 ret
8384 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8385 index 504106b..4e50951 100644
8386 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8387 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8388 @@ -24,6 +24,8 @@
8389 *
8390 */
8391
8392 +#include <asm/alternative-asm.h>
8393 +
8394 .file "serpent-avx-x86_64-asm_64.S"
8395 .text
8396
8397 @@ -638,12 +640,14 @@ __serpent_enc_blk_8way_avx:
8398 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8399 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8400
8401 + pax_force_retaddr
8402 ret;
8403
8404 __enc_xor8:
8405 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8406 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8407
8408 + pax_force_retaddr
8409 ret;
8410
8411 .align 8
8412 @@ -701,4 +705,5 @@ serpent_dec_blk_8way_avx:
8413 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8414 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8415
8416 + pax_force_retaddr
8417 ret;
8418 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8419 index 3ee1ff0..cbc568b 100644
8420 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8421 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8422 @@ -24,6 +24,8 @@
8423 *
8424 */
8425
8426 +#include <asm/alternative-asm.h>
8427 +
8428 .file "serpent-sse2-x86_64-asm_64.S"
8429 .text
8430
8431 @@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
8432 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8433 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8434
8435 + pax_force_retaddr
8436 ret;
8437
8438 __enc_xor8:
8439 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8440 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8441
8442 + pax_force_retaddr
8443 ret;
8444
8445 .align 8
8446 @@ -755,4 +759,5 @@ serpent_dec_blk_8way:
8447 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8448 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8449
8450 + pax_force_retaddr
8451 ret;
8452 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
8453 index 49d6987..df66bd4 100644
8454 --- a/arch/x86/crypto/sha1_ssse3_asm.S
8455 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
8456 @@ -28,6 +28,8 @@
8457 * (at your option) any later version.
8458 */
8459
8460 +#include <asm/alternative-asm.h>
8461 +
8462 #define CTX %rdi // arg1
8463 #define BUF %rsi // arg2
8464 #define CNT %rdx // arg3
8465 @@ -104,6 +106,7 @@
8466 pop %r12
8467 pop %rbp
8468 pop %rbx
8469 + pax_force_retaddr 0, 1
8470 ret
8471
8472 .size \name, .-\name
8473 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8474 index 35f4557..16b379f 100644
8475 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8476 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8477 @@ -21,6 +21,8 @@
8478 *
8479 */
8480
8481 +#include <asm/alternative-asm.h>
8482 +
8483 .file "twofish-avx-x86_64-asm_64.S"
8484 .text
8485
8486 @@ -250,12 +252,14 @@ __twofish_enc_blk_8way:
8487 outunpack_blocks(%rsi, RC1, RD1, RA1, RB1, RK1, RX, RY, RK2);
8488 outunpack_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX, RY, RK2);
8489
8490 + pax_force_retaddr
8491 ret;
8492
8493 __enc_xor8:
8494 outunpack_xor_blocks(%rsi, RC1, RD1, RA1, RB1, RK1, RX, RY, RK2);
8495 outunpack_xor_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX, RY, RK2);
8496
8497 + pax_force_retaddr
8498 ret;
8499
8500 .align 8
8501 @@ -297,4 +301,5 @@ twofish_dec_blk_8way:
8502 outunpack_blocks(%rsi, RA1, RB1, RC1, RD1, RK1, RX, RY, RK2);
8503 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RK1, RX, RY, RK2);
8504
8505 + pax_force_retaddr
8506 ret;
8507 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8508 index 5b012a2..36d5364 100644
8509 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8510 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8511 @@ -20,6 +20,8 @@
8512 *
8513 */
8514
8515 +#include <asm/alternative-asm.h>
8516 +
8517 .file "twofish-x86_64-asm-3way.S"
8518 .text
8519
8520 @@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
8521 popq %r13;
8522 popq %r14;
8523 popq %r15;
8524 + pax_force_retaddr 0, 1
8525 ret;
8526
8527 __enc_xor3:
8528 @@ -271,6 +274,7 @@ __enc_xor3:
8529 popq %r13;
8530 popq %r14;
8531 popq %r15;
8532 + pax_force_retaddr 0, 1
8533 ret;
8534
8535 .global twofish_dec_blk_3way
8536 @@ -312,5 +316,6 @@ twofish_dec_blk_3way:
8537 popq %r13;
8538 popq %r14;
8539 popq %r15;
8540 + pax_force_retaddr 0, 1
8541 ret;
8542
8543 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
8544 index 7bcf3fc..f53832f 100644
8545 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
8546 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
8547 @@ -21,6 +21,7 @@
8548 .text
8549
8550 #include <asm/asm-offsets.h>
8551 +#include <asm/alternative-asm.h>
8552
8553 #define a_offset 0
8554 #define b_offset 4
8555 @@ -268,6 +269,7 @@ twofish_enc_blk:
8556
8557 popq R1
8558 movq $1,%rax
8559 + pax_force_retaddr 0, 1
8560 ret
8561
8562 twofish_dec_blk:
8563 @@ -319,4 +321,5 @@ twofish_dec_blk:
8564
8565 popq R1
8566 movq $1,%rax
8567 + pax_force_retaddr 0, 1
8568 ret
8569 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
8570 index 07b3a68..bd2a388 100644
8571 --- a/arch/x86/ia32/ia32_aout.c
8572 +++ b/arch/x86/ia32/ia32_aout.c
8573 @@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
8574 unsigned long dump_start, dump_size;
8575 struct user32 dump;
8576
8577 + memset(&dump, 0, sizeof(dump));
8578 +
8579 fs = get_fs();
8580 set_fs(KERNEL_DS);
8581 has_dumped = 1;
8582 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
8583 index 673ac9b..7a8c5df 100644
8584 --- a/arch/x86/ia32/ia32_signal.c
8585 +++ b/arch/x86/ia32/ia32_signal.c
8586 @@ -162,7 +162,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
8587 }
8588 seg = get_fs();
8589 set_fs(KERNEL_DS);
8590 - ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
8591 + ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
8592 set_fs(seg);
8593 if (ret >= 0 && uoss_ptr) {
8594 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
8595 @@ -361,7 +361,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
8596 */
8597 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8598 size_t frame_size,
8599 - void **fpstate)
8600 + void __user **fpstate)
8601 {
8602 unsigned long sp;
8603
8604 @@ -382,7 +382,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8605
8606 if (used_math()) {
8607 sp = sp - sig_xstate_ia32_size;
8608 - *fpstate = (struct _fpstate_ia32 *) sp;
8609 + *fpstate = (struct _fpstate_ia32 __user *) sp;
8610 if (save_i387_xstate_ia32(*fpstate) < 0)
8611 return (void __user *) -1L;
8612 }
8613 @@ -390,7 +390,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8614 sp -= frame_size;
8615 /* Align the stack pointer according to the i386 ABI,
8616 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8617 - sp = ((sp + 4) & -16ul) - 4;
8618 + sp = ((sp - 12) & -16ul) - 4;
8619 return (void __user *) sp;
8620 }
8621
8622 @@ -448,7 +448,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
8623 * These are actually not used anymore, but left because some
8624 * gdb versions depend on them as a marker.
8625 */
8626 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8627 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8628 } put_user_catch(err);
8629
8630 if (err)
8631 @@ -490,7 +490,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8632 0xb8,
8633 __NR_ia32_rt_sigreturn,
8634 0x80cd,
8635 - 0,
8636 + 0
8637 };
8638
8639 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8640 @@ -520,16 +520,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8641
8642 if (ka->sa.sa_flags & SA_RESTORER)
8643 restorer = ka->sa.sa_restorer;
8644 + else if (current->mm->context.vdso)
8645 + /* Return stub is in 32bit vsyscall page */
8646 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8647 else
8648 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8649 - rt_sigreturn);
8650 + restorer = &frame->retcode;
8651 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8652
8653 /*
8654 * Not actually used anymore, but left because some gdb
8655 * versions need it.
8656 */
8657 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8658 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8659 } put_user_catch(err);
8660
8661 if (err)
8662 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
8663 index 20e5f7b..f33c779 100644
8664 --- a/arch/x86/ia32/ia32entry.S
8665 +++ b/arch/x86/ia32/ia32entry.S
8666 @@ -14,8 +14,10 @@
8667 #include <asm/segment.h>
8668 #include <asm/irqflags.h>
8669 #include <asm/asm.h>
8670 +#include <asm/pgtable.h>
8671 #include <linux/linkage.h>
8672 #include <linux/err.h>
8673 +#include <asm/alternative-asm.h>
8674
8675 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
8676 #include <linux/elf-em.h>
8677 @@ -95,6 +97,32 @@ ENTRY(native_irq_enable_sysexit)
8678 ENDPROC(native_irq_enable_sysexit)
8679 #endif
8680
8681 + .macro pax_enter_kernel_user
8682 + pax_set_fptr_mask
8683 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8684 + call pax_enter_kernel_user
8685 +#endif
8686 + .endm
8687 +
8688 + .macro pax_exit_kernel_user
8689 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8690 + call pax_exit_kernel_user
8691 +#endif
8692 +#ifdef CONFIG_PAX_RANDKSTACK
8693 + pushq %rax
8694 + pushq %r11
8695 + call pax_randomize_kstack
8696 + popq %r11
8697 + popq %rax
8698 +#endif
8699 + .endm
8700 +
8701 +.macro pax_erase_kstack
8702 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8703 + call pax_erase_kstack
8704 +#endif
8705 +.endm
8706 +
8707 /*
8708 * 32bit SYSENTER instruction entry.
8709 *
8710 @@ -121,12 +149,6 @@ ENTRY(ia32_sysenter_target)
8711 CFI_REGISTER rsp,rbp
8712 SWAPGS_UNSAFE_STACK
8713 movq PER_CPU_VAR(kernel_stack), %rsp
8714 - addq $(KERNEL_STACK_OFFSET),%rsp
8715 - /*
8716 - * No need to follow this irqs on/off section: the syscall
8717 - * disabled irqs, here we enable it straight after entry:
8718 - */
8719 - ENABLE_INTERRUPTS(CLBR_NONE)
8720 movl %ebp,%ebp /* zero extension */
8721 pushq_cfi $__USER32_DS
8722 /*CFI_REL_OFFSET ss,0*/
8723 @@ -134,22 +156,42 @@ ENTRY(ia32_sysenter_target)
8724 CFI_REL_OFFSET rsp,0
8725 pushfq_cfi
8726 /*CFI_REL_OFFSET rflags,0*/
8727 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
8728 - CFI_REGISTER rip,r10
8729 + orl $X86_EFLAGS_IF,(%rsp)
8730 + GET_THREAD_INFO(%r11)
8731 + movl TI_sysenter_return(%r11), %r11d
8732 + CFI_REGISTER rip,r11
8733 pushq_cfi $__USER32_CS
8734 /*CFI_REL_OFFSET cs,0*/
8735 movl %eax, %eax
8736 - pushq_cfi %r10
8737 + pushq_cfi %r11
8738 CFI_REL_OFFSET rip,0
8739 pushq_cfi %rax
8740 cld
8741 SAVE_ARGS 0,1,0
8742 + pax_enter_kernel_user
8743 +
8744 +#ifdef CONFIG_PAX_RANDKSTACK
8745 + pax_erase_kstack
8746 +#endif
8747 +
8748 + /*
8749 + * No need to follow this irqs on/off section: the syscall
8750 + * disabled irqs, here we enable it straight after entry:
8751 + */
8752 + ENABLE_INTERRUPTS(CLBR_NONE)
8753 /* no need to do an access_ok check here because rbp has been
8754 32bit zero extended */
8755 +
8756 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8757 + mov $PAX_USER_SHADOW_BASE,%r11
8758 + add %r11,%rbp
8759 +#endif
8760 +
8761 1: movl (%rbp),%ebp
8762 _ASM_EXTABLE(1b,ia32_badarg)
8763 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8764 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8765 + GET_THREAD_INFO(%r11)
8766 + orl $TS_COMPAT,TI_status(%r11)
8767 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8768 CFI_REMEMBER_STATE
8769 jnz sysenter_tracesys
8770 cmpq $(IA32_NR_syscalls-1),%rax
8771 @@ -159,12 +201,15 @@ sysenter_do_call:
8772 sysenter_dispatch:
8773 call *ia32_sys_call_table(,%rax,8)
8774 movq %rax,RAX-ARGOFFSET(%rsp)
8775 + GET_THREAD_INFO(%r11)
8776 DISABLE_INTERRUPTS(CLBR_NONE)
8777 TRACE_IRQS_OFF
8778 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8779 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8780 jnz sysexit_audit
8781 sysexit_from_sys_call:
8782 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8783 + pax_exit_kernel_user
8784 + pax_erase_kstack
8785 + andl $~TS_COMPAT,TI_status(%r11)
8786 /* clear IF, that popfq doesn't enable interrupts early */
8787 andl $~0x200,EFLAGS-R11(%rsp)
8788 movl RIP-R11(%rsp),%edx /* User %eip */
8789 @@ -190,6 +235,9 @@ sysexit_from_sys_call:
8790 movl %eax,%esi /* 2nd arg: syscall number */
8791 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8792 call __audit_syscall_entry
8793 +
8794 + pax_erase_kstack
8795 +
8796 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8797 cmpq $(IA32_NR_syscalls-1),%rax
8798 ja ia32_badsys
8799 @@ -201,7 +249,7 @@ sysexit_from_sys_call:
8800 .endm
8801
8802 .macro auditsys_exit exit
8803 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8804 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8805 jnz ia32_ret_from_sys_call
8806 TRACE_IRQS_ON
8807 sti
8808 @@ -212,11 +260,12 @@ sysexit_from_sys_call:
8809 1: setbe %al /* 1 if error, 0 if not */
8810 movzbl %al,%edi /* zero-extend that into %edi */
8811 call __audit_syscall_exit
8812 + GET_THREAD_INFO(%r11)
8813 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
8814 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8815 cli
8816 TRACE_IRQS_OFF
8817 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8818 + testl %edi,TI_flags(%r11)
8819 jz \exit
8820 CLEAR_RREGS -ARGOFFSET
8821 jmp int_with_check
8822 @@ -234,7 +283,7 @@ sysexit_audit:
8823
8824 sysenter_tracesys:
8825 #ifdef CONFIG_AUDITSYSCALL
8826 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8827 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8828 jz sysenter_auditsys
8829 #endif
8830 SAVE_REST
8831 @@ -246,6 +295,9 @@ sysenter_tracesys:
8832 RESTORE_REST
8833 cmpq $(IA32_NR_syscalls-1),%rax
8834 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
8835 +
8836 + pax_erase_kstack
8837 +
8838 jmp sysenter_do_call
8839 CFI_ENDPROC
8840 ENDPROC(ia32_sysenter_target)
8841 @@ -273,19 +325,25 @@ ENDPROC(ia32_sysenter_target)
8842 ENTRY(ia32_cstar_target)
8843 CFI_STARTPROC32 simple
8844 CFI_SIGNAL_FRAME
8845 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8846 + CFI_DEF_CFA rsp,0
8847 CFI_REGISTER rip,rcx
8848 /*CFI_REGISTER rflags,r11*/
8849 SWAPGS_UNSAFE_STACK
8850 movl %esp,%r8d
8851 CFI_REGISTER rsp,r8
8852 movq PER_CPU_VAR(kernel_stack),%rsp
8853 + SAVE_ARGS 8*6,0,0
8854 + pax_enter_kernel_user
8855 +
8856 +#ifdef CONFIG_PAX_RANDKSTACK
8857 + pax_erase_kstack
8858 +#endif
8859 +
8860 /*
8861 * No need to follow this irqs on/off section: the syscall
8862 * disabled irqs and here we enable it straight after entry:
8863 */
8864 ENABLE_INTERRUPTS(CLBR_NONE)
8865 - SAVE_ARGS 8,0,0
8866 movl %eax,%eax /* zero extension */
8867 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8868 movq %rcx,RIP-ARGOFFSET(%rsp)
8869 @@ -301,10 +359,17 @@ ENTRY(ia32_cstar_target)
8870 /* no need to do an access_ok check here because r8 has been
8871 32bit zero extended */
8872 /* hardware stack frame is complete now */
8873 +
8874 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8875 + mov $PAX_USER_SHADOW_BASE,%r11
8876 + add %r11,%r8
8877 +#endif
8878 +
8879 1: movl (%r8),%r9d
8880 _ASM_EXTABLE(1b,ia32_badarg)
8881 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8882 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8883 + GET_THREAD_INFO(%r11)
8884 + orl $TS_COMPAT,TI_status(%r11)
8885 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8886 CFI_REMEMBER_STATE
8887 jnz cstar_tracesys
8888 cmpq $IA32_NR_syscalls-1,%rax
8889 @@ -314,12 +379,15 @@ cstar_do_call:
8890 cstar_dispatch:
8891 call *ia32_sys_call_table(,%rax,8)
8892 movq %rax,RAX-ARGOFFSET(%rsp)
8893 + GET_THREAD_INFO(%r11)
8894 DISABLE_INTERRUPTS(CLBR_NONE)
8895 TRACE_IRQS_OFF
8896 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8897 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8898 jnz sysretl_audit
8899 sysretl_from_sys_call:
8900 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8901 + pax_exit_kernel_user
8902 + pax_erase_kstack
8903 + andl $~TS_COMPAT,TI_status(%r11)
8904 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
8905 movl RIP-ARGOFFSET(%rsp),%ecx
8906 CFI_REGISTER rip,rcx
8907 @@ -347,7 +415,7 @@ sysretl_audit:
8908
8909 cstar_tracesys:
8910 #ifdef CONFIG_AUDITSYSCALL
8911 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8912 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8913 jz cstar_auditsys
8914 #endif
8915 xchgl %r9d,%ebp
8916 @@ -361,6 +429,9 @@ cstar_tracesys:
8917 xchgl %ebp,%r9d
8918 cmpq $(IA32_NR_syscalls-1),%rax
8919 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
8920 +
8921 + pax_erase_kstack
8922 +
8923 jmp cstar_do_call
8924 END(ia32_cstar_target)
8925
8926 @@ -401,19 +472,26 @@ ENTRY(ia32_syscall)
8927 CFI_REL_OFFSET rip,RIP-RIP
8928 PARAVIRT_ADJUST_EXCEPTION_FRAME
8929 SWAPGS
8930 - /*
8931 - * No need to follow this irqs on/off section: the syscall
8932 - * disabled irqs and here we enable it straight after entry:
8933 - */
8934 - ENABLE_INTERRUPTS(CLBR_NONE)
8935 movl %eax,%eax
8936 pushq_cfi %rax
8937 cld
8938 /* note the registers are not zero extended to the sf.
8939 this could be a problem. */
8940 SAVE_ARGS 0,1,0
8941 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8942 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8943 + pax_enter_kernel_user
8944 +
8945 +#ifdef CONFIG_PAX_RANDKSTACK
8946 + pax_erase_kstack
8947 +#endif
8948 +
8949 + /*
8950 + * No need to follow this irqs on/off section: the syscall
8951 + * disabled irqs and here we enable it straight after entry:
8952 + */
8953 + ENABLE_INTERRUPTS(CLBR_NONE)
8954 + GET_THREAD_INFO(%r11)
8955 + orl $TS_COMPAT,TI_status(%r11)
8956 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8957 jnz ia32_tracesys
8958 cmpq $(IA32_NR_syscalls-1),%rax
8959 ja ia32_badsys
8960 @@ -436,6 +514,9 @@ ia32_tracesys:
8961 RESTORE_REST
8962 cmpq $(IA32_NR_syscalls-1),%rax
8963 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
8964 +
8965 + pax_erase_kstack
8966 +
8967 jmp ia32_do_call
8968 END(ia32_syscall)
8969
8970 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
8971 index 4540bec..714d913 100644
8972 --- a/arch/x86/ia32/sys_ia32.c
8973 +++ b/arch/x86/ia32/sys_ia32.c
8974 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
8975 */
8976 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
8977 {
8978 - typeof(ubuf->st_uid) uid = 0;
8979 - typeof(ubuf->st_gid) gid = 0;
8980 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
8981 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
8982 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
8983 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
8984 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
8985 @@ -287,7 +287,7 @@ asmlinkage long sys32_sigaction(int sig, struct old_sigaction32 __user *act,
8986 return ret;
8987 }
8988
8989 -asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
8990 +asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
8991 int options)
8992 {
8993 return compat_sys_wait4(pid, stat_addr, options, NULL);
8994 @@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
8995 mm_segment_t old_fs = get_fs();
8996
8997 set_fs(KERNEL_DS);
8998 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
8999 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
9000 set_fs(old_fs);
9001 if (put_compat_timespec(&t, interval))
9002 return -EFAULT;
9003 @@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
9004 mm_segment_t old_fs = get_fs();
9005
9006 set_fs(KERNEL_DS);
9007 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
9008 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
9009 set_fs(old_fs);
9010 if (!ret) {
9011 switch (_NSIG_WORDS) {
9012 @@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
9013 if (copy_siginfo_from_user32(&info, uinfo))
9014 return -EFAULT;
9015 set_fs(KERNEL_DS);
9016 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
9017 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
9018 set_fs(old_fs);
9019 return ret;
9020 }
9021 @@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
9022 return -EFAULT;
9023
9024 set_fs(KERNEL_DS);
9025 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
9026 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
9027 count);
9028 set_fs(old_fs);
9029
9030 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
9031 index 952bd01..7692c6f 100644
9032 --- a/arch/x86/include/asm/alternative-asm.h
9033 +++ b/arch/x86/include/asm/alternative-asm.h
9034 @@ -15,6 +15,45 @@
9035 .endm
9036 #endif
9037
9038 +#ifdef KERNEXEC_PLUGIN
9039 + .macro pax_force_retaddr_bts rip=0
9040 + btsq $63,\rip(%rsp)
9041 + .endm
9042 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
9043 + .macro pax_force_retaddr rip=0, reload=0
9044 + btsq $63,\rip(%rsp)
9045 + .endm
9046 + .macro pax_force_fptr ptr
9047 + btsq $63,\ptr
9048 + .endm
9049 + .macro pax_set_fptr_mask
9050 + .endm
9051 +#endif
9052 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
9053 + .macro pax_force_retaddr rip=0, reload=0
9054 + .if \reload
9055 + pax_set_fptr_mask
9056 + .endif
9057 + orq %r10,\rip(%rsp)
9058 + .endm
9059 + .macro pax_force_fptr ptr
9060 + orq %r10,\ptr
9061 + .endm
9062 + .macro pax_set_fptr_mask
9063 + movabs $0x8000000000000000,%r10
9064 + .endm
9065 +#endif
9066 +#else
9067 + .macro pax_force_retaddr rip=0, reload=0
9068 + .endm
9069 + .macro pax_force_fptr ptr
9070 + .endm
9071 + .macro pax_force_retaddr_bts rip=0
9072 + .endm
9073 + .macro pax_set_fptr_mask
9074 + .endm
9075 +#endif
9076 +
9077 .macro altinstruction_entry orig alt feature orig_len alt_len
9078 .long \orig - .
9079 .long \alt - .
9080 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
9081 index 7078068..f58bcda 100644
9082 --- a/arch/x86/include/asm/alternative.h
9083 +++ b/arch/x86/include/asm/alternative.h
9084 @@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9085 ".section .discard,\"aw\",@progbits\n" \
9086 DISCARD_ENTRY(1) \
9087 ".previous\n" \
9088 - ".section .altinstr_replacement, \"ax\"\n" \
9089 + ".section .altinstr_replacement, \"a\"\n" \
9090 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
9091 ".previous"
9092
9093 @@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9094 DISCARD_ENTRY(1) \
9095 DISCARD_ENTRY(2) \
9096 ".previous\n" \
9097 - ".section .altinstr_replacement, \"ax\"\n" \
9098 + ".section .altinstr_replacement, \"a\"\n" \
9099 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
9100 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
9101 ".previous"
9102 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
9103 index f342612..b3fe911 100644
9104 --- a/arch/x86/include/asm/apic.h
9105 +++ b/arch/x86/include/asm/apic.h
9106 @@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
9107
9108 #ifdef CONFIG_X86_LOCAL_APIC
9109
9110 -extern unsigned int apic_verbosity;
9111 +extern int apic_verbosity;
9112 extern int local_apic_timer_c2_ok;
9113
9114 extern int disable_apic;
9115 @@ -391,7 +391,7 @@ struct apic {
9116 */
9117 int (*x86_32_numa_cpu_node)(int cpu);
9118 #endif
9119 -};
9120 +} __do_const;
9121
9122 /*
9123 * Pointer to the local APIC driver in use on this system (there's
9124 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
9125 index 20370c6..a2eb9b0 100644
9126 --- a/arch/x86/include/asm/apm.h
9127 +++ b/arch/x86/include/asm/apm.h
9128 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
9129 __asm__ __volatile__(APM_DO_ZERO_SEGS
9130 "pushl %%edi\n\t"
9131 "pushl %%ebp\n\t"
9132 - "lcall *%%cs:apm_bios_entry\n\t"
9133 + "lcall *%%ss:apm_bios_entry\n\t"
9134 "setc %%al\n\t"
9135 "popl %%ebp\n\t"
9136 "popl %%edi\n\t"
9137 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
9138 __asm__ __volatile__(APM_DO_ZERO_SEGS
9139 "pushl %%edi\n\t"
9140 "pushl %%ebp\n\t"
9141 - "lcall *%%cs:apm_bios_entry\n\t"
9142 + "lcall *%%ss:apm_bios_entry\n\t"
9143 "setc %%bl\n\t"
9144 "popl %%ebp\n\t"
9145 "popl %%edi\n\t"
9146 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
9147 index 58cb6d4..a4b806c 100644
9148 --- a/arch/x86/include/asm/atomic.h
9149 +++ b/arch/x86/include/asm/atomic.h
9150 @@ -22,7 +22,18 @@
9151 */
9152 static inline int atomic_read(const atomic_t *v)
9153 {
9154 - return (*(volatile int *)&(v)->counter);
9155 + return (*(volatile const int *)&(v)->counter);
9156 +}
9157 +
9158 +/**
9159 + * atomic_read_unchecked - read atomic variable
9160 + * @v: pointer of type atomic_unchecked_t
9161 + *
9162 + * Atomically reads the value of @v.
9163 + */
9164 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9165 +{
9166 + return (*(volatile const int *)&(v)->counter);
9167 }
9168
9169 /**
9170 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
9171 }
9172
9173 /**
9174 + * atomic_set_unchecked - set atomic variable
9175 + * @v: pointer of type atomic_unchecked_t
9176 + * @i: required value
9177 + *
9178 + * Atomically sets the value of @v to @i.
9179 + */
9180 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9181 +{
9182 + v->counter = i;
9183 +}
9184 +
9185 +/**
9186 * atomic_add - add integer to atomic variable
9187 * @i: integer value to add
9188 * @v: pointer of type atomic_t
9189 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
9190 */
9191 static inline void atomic_add(int i, atomic_t *v)
9192 {
9193 - asm volatile(LOCK_PREFIX "addl %1,%0"
9194 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
9195 +
9196 +#ifdef CONFIG_PAX_REFCOUNT
9197 + "jno 0f\n"
9198 + LOCK_PREFIX "subl %1,%0\n"
9199 + "int $4\n0:\n"
9200 + _ASM_EXTABLE(0b, 0b)
9201 +#endif
9202 +
9203 + : "+m" (v->counter)
9204 + : "ir" (i));
9205 +}
9206 +
9207 +/**
9208 + * atomic_add_unchecked - add integer to atomic variable
9209 + * @i: integer value to add
9210 + * @v: pointer of type atomic_unchecked_t
9211 + *
9212 + * Atomically adds @i to @v.
9213 + */
9214 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
9215 +{
9216 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
9217 : "+m" (v->counter)
9218 : "ir" (i));
9219 }
9220 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
9221 */
9222 static inline void atomic_sub(int i, atomic_t *v)
9223 {
9224 - asm volatile(LOCK_PREFIX "subl %1,%0"
9225 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
9226 +
9227 +#ifdef CONFIG_PAX_REFCOUNT
9228 + "jno 0f\n"
9229 + LOCK_PREFIX "addl %1,%0\n"
9230 + "int $4\n0:\n"
9231 + _ASM_EXTABLE(0b, 0b)
9232 +#endif
9233 +
9234 + : "+m" (v->counter)
9235 + : "ir" (i));
9236 +}
9237 +
9238 +/**
9239 + * atomic_sub_unchecked - subtract integer from atomic variable
9240 + * @i: integer value to subtract
9241 + * @v: pointer of type atomic_unchecked_t
9242 + *
9243 + * Atomically subtracts @i from @v.
9244 + */
9245 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
9246 +{
9247 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
9248 : "+m" (v->counter)
9249 : "ir" (i));
9250 }
9251 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9252 {
9253 unsigned char c;
9254
9255 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
9256 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
9257 +
9258 +#ifdef CONFIG_PAX_REFCOUNT
9259 + "jno 0f\n"
9260 + LOCK_PREFIX "addl %2,%0\n"
9261 + "int $4\n0:\n"
9262 + _ASM_EXTABLE(0b, 0b)
9263 +#endif
9264 +
9265 + "sete %1\n"
9266 : "+m" (v->counter), "=qm" (c)
9267 : "ir" (i) : "memory");
9268 return c;
9269 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9270 */
9271 static inline void atomic_inc(atomic_t *v)
9272 {
9273 - asm volatile(LOCK_PREFIX "incl %0"
9274 + asm volatile(LOCK_PREFIX "incl %0\n"
9275 +
9276 +#ifdef CONFIG_PAX_REFCOUNT
9277 + "jno 0f\n"
9278 + LOCK_PREFIX "decl %0\n"
9279 + "int $4\n0:\n"
9280 + _ASM_EXTABLE(0b, 0b)
9281 +#endif
9282 +
9283 + : "+m" (v->counter));
9284 +}
9285 +
9286 +/**
9287 + * atomic_inc_unchecked - increment atomic variable
9288 + * @v: pointer of type atomic_unchecked_t
9289 + *
9290 + * Atomically increments @v by 1.
9291 + */
9292 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9293 +{
9294 + asm volatile(LOCK_PREFIX "incl %0\n"
9295 : "+m" (v->counter));
9296 }
9297
9298 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
9299 */
9300 static inline void atomic_dec(atomic_t *v)
9301 {
9302 - asm volatile(LOCK_PREFIX "decl %0"
9303 + asm volatile(LOCK_PREFIX "decl %0\n"
9304 +
9305 +#ifdef CONFIG_PAX_REFCOUNT
9306 + "jno 0f\n"
9307 + LOCK_PREFIX "incl %0\n"
9308 + "int $4\n0:\n"
9309 + _ASM_EXTABLE(0b, 0b)
9310 +#endif
9311 +
9312 + : "+m" (v->counter));
9313 +}
9314 +
9315 +/**
9316 + * atomic_dec_unchecked - decrement atomic variable
9317 + * @v: pointer of type atomic_unchecked_t
9318 + *
9319 + * Atomically decrements @v by 1.
9320 + */
9321 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9322 +{
9323 + asm volatile(LOCK_PREFIX "decl %0\n"
9324 : "+m" (v->counter));
9325 }
9326
9327 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
9328 {
9329 unsigned char c;
9330
9331 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
9332 + asm volatile(LOCK_PREFIX "decl %0\n"
9333 +
9334 +#ifdef CONFIG_PAX_REFCOUNT
9335 + "jno 0f\n"
9336 + LOCK_PREFIX "incl %0\n"
9337 + "int $4\n0:\n"
9338 + _ASM_EXTABLE(0b, 0b)
9339 +#endif
9340 +
9341 + "sete %1\n"
9342 : "+m" (v->counter), "=qm" (c)
9343 : : "memory");
9344 return c != 0;
9345 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
9346 {
9347 unsigned char c;
9348
9349 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
9350 + asm volatile(LOCK_PREFIX "incl %0\n"
9351 +
9352 +#ifdef CONFIG_PAX_REFCOUNT
9353 + "jno 0f\n"
9354 + LOCK_PREFIX "decl %0\n"
9355 + "int $4\n0:\n"
9356 + _ASM_EXTABLE(0b, 0b)
9357 +#endif
9358 +
9359 + "sete %1\n"
9360 + : "+m" (v->counter), "=qm" (c)
9361 + : : "memory");
9362 + return c != 0;
9363 +}
9364 +
9365 +/**
9366 + * atomic_inc_and_test_unchecked - increment and test
9367 + * @v: pointer of type atomic_unchecked_t
9368 + *
9369 + * Atomically increments @v by 1
9370 + * and returns true if the result is zero, or false for all
9371 + * other cases.
9372 + */
9373 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9374 +{
9375 + unsigned char c;
9376 +
9377 + asm volatile(LOCK_PREFIX "incl %0\n"
9378 + "sete %1\n"
9379 : "+m" (v->counter), "=qm" (c)
9380 : : "memory");
9381 return c != 0;
9382 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
9383 {
9384 unsigned char c;
9385
9386 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
9387 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
9388 +
9389 +#ifdef CONFIG_PAX_REFCOUNT
9390 + "jno 0f\n"
9391 + LOCK_PREFIX "subl %2,%0\n"
9392 + "int $4\n0:\n"
9393 + _ASM_EXTABLE(0b, 0b)
9394 +#endif
9395 +
9396 + "sets %1\n"
9397 : "+m" (v->counter), "=qm" (c)
9398 : "ir" (i) : "memory");
9399 return c;
9400 @@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
9401 goto no_xadd;
9402 #endif
9403 /* Modern 486+ processor */
9404 - return i + xadd(&v->counter, i);
9405 + return i + xadd_check_overflow(&v->counter, i);
9406
9407 #ifdef CONFIG_M386
9408 no_xadd: /* Legacy 386 processor */
9409 @@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
9410 }
9411
9412 /**
9413 + * atomic_add_return_unchecked - add integer and return
9414 + * @i: integer value to add
9415 + * @v: pointer of type atomic_unchecked_t
9416 + *
9417 + * Atomically adds @i to @v and returns @i + @v
9418 + */
9419 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9420 +{
9421 +#ifdef CONFIG_M386
9422 + int __i;
9423 + unsigned long flags;
9424 + if (unlikely(boot_cpu_data.x86 <= 3))
9425 + goto no_xadd;
9426 +#endif
9427 + /* Modern 486+ processor */
9428 + return i + xadd(&v->counter, i);
9429 +
9430 +#ifdef CONFIG_M386
9431 +no_xadd: /* Legacy 386 processor */
9432 + raw_local_irq_save(flags);
9433 + __i = atomic_read_unchecked(v);
9434 + atomic_set_unchecked(v, i + __i);
9435 + raw_local_irq_restore(flags);
9436 + return i + __i;
9437 +#endif
9438 +}
9439 +
9440 +/**
9441 * atomic_sub_return - subtract integer and return
9442 * @v: pointer of type atomic_t
9443 * @i: integer value to subtract
9444 @@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
9445 }
9446
9447 #define atomic_inc_return(v) (atomic_add_return(1, v))
9448 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9449 +{
9450 + return atomic_add_return_unchecked(1, v);
9451 +}
9452 #define atomic_dec_return(v) (atomic_sub_return(1, v))
9453
9454 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9455 @@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9456 return cmpxchg(&v->counter, old, new);
9457 }
9458
9459 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9460 +{
9461 + return cmpxchg(&v->counter, old, new);
9462 +}
9463 +
9464 static inline int atomic_xchg(atomic_t *v, int new)
9465 {
9466 return xchg(&v->counter, new);
9467 }
9468
9469 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9470 +{
9471 + return xchg(&v->counter, new);
9472 +}
9473 +
9474 /**
9475 * __atomic_add_unless - add unless the number is already a given value
9476 * @v: pointer of type atomic_t
9477 @@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
9478 */
9479 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9480 {
9481 - int c, old;
9482 + int c, old, new;
9483 c = atomic_read(v);
9484 for (;;) {
9485 - if (unlikely(c == (u)))
9486 + if (unlikely(c == u))
9487 break;
9488 - old = atomic_cmpxchg((v), c, c + (a));
9489 +
9490 + asm volatile("addl %2,%0\n"
9491 +
9492 +#ifdef CONFIG_PAX_REFCOUNT
9493 + "jno 0f\n"
9494 + "subl %2,%0\n"
9495 + "int $4\n0:\n"
9496 + _ASM_EXTABLE(0b, 0b)
9497 +#endif
9498 +
9499 + : "=r" (new)
9500 + : "0" (c), "ir" (a));
9501 +
9502 + old = atomic_cmpxchg(v, c, new);
9503 if (likely(old == c))
9504 break;
9505 c = old;
9506 @@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9507 return c;
9508 }
9509
9510 +/**
9511 + * atomic_inc_not_zero_hint - increment if not null
9512 + * @v: pointer of type atomic_t
9513 + * @hint: probable value of the atomic before the increment
9514 + *
9515 + * This version of atomic_inc_not_zero() gives a hint of probable
9516 + * value of the atomic. This helps processor to not read the memory
9517 + * before doing the atomic read/modify/write cycle, lowering
9518 + * number of bus transactions on some arches.
9519 + *
9520 + * Returns: 0 if increment was not done, 1 otherwise.
9521 + */
9522 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9523 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9524 +{
9525 + int val, c = hint, new;
9526 +
9527 + /* sanity test, should be removed by compiler if hint is a constant */
9528 + if (!hint)
9529 + return __atomic_add_unless(v, 1, 0);
9530 +
9531 + do {
9532 + asm volatile("incl %0\n"
9533 +
9534 +#ifdef CONFIG_PAX_REFCOUNT
9535 + "jno 0f\n"
9536 + "decl %0\n"
9537 + "int $4\n0:\n"
9538 + _ASM_EXTABLE(0b, 0b)
9539 +#endif
9540 +
9541 + : "=r" (new)
9542 + : "0" (c));
9543 +
9544 + val = atomic_cmpxchg(v, c, new);
9545 + if (val == c)
9546 + return 1;
9547 + c = val;
9548 + } while (c);
9549 +
9550 + return 0;
9551 +}
9552
9553 /*
9554 * atomic_dec_if_positive - decrement by 1 if old value positive
9555 @@ -293,14 +552,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
9556 #endif
9557
9558 /* These are x86-specific, used by some header files */
9559 -#define atomic_clear_mask(mask, addr) \
9560 - asm volatile(LOCK_PREFIX "andl %0,%1" \
9561 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
9562 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
9563 +{
9564 + asm volatile(LOCK_PREFIX "andl %1,%0"
9565 + : "+m" (v->counter)
9566 + : "r" (~(mask))
9567 + : "memory");
9568 +}
9569
9570 -#define atomic_set_mask(mask, addr) \
9571 - asm volatile(LOCK_PREFIX "orl %0,%1" \
9572 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
9573 - : "memory")
9574 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9575 +{
9576 + asm volatile(LOCK_PREFIX "andl %1,%0"
9577 + : "+m" (v->counter)
9578 + : "r" (~(mask))
9579 + : "memory");
9580 +}
9581 +
9582 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
9583 +{
9584 + asm volatile(LOCK_PREFIX "orl %1,%0"
9585 + : "+m" (v->counter)
9586 + : "r" (mask)
9587 + : "memory");
9588 +}
9589 +
9590 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9591 +{
9592 + asm volatile(LOCK_PREFIX "orl %1,%0"
9593 + : "+m" (v->counter)
9594 + : "r" (mask)
9595 + : "memory");
9596 +}
9597
9598 /* Atomic operations are already serializing on x86 */
9599 #define smp_mb__before_atomic_dec() barrier()
9600 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
9601 index b154de7..aadebd8 100644
9602 --- a/arch/x86/include/asm/atomic64_32.h
9603 +++ b/arch/x86/include/asm/atomic64_32.h
9604 @@ -12,6 +12,14 @@ typedef struct {
9605 u64 __aligned(8) counter;
9606 } atomic64_t;
9607
9608 +#ifdef CONFIG_PAX_REFCOUNT
9609 +typedef struct {
9610 + u64 __aligned(8) counter;
9611 +} atomic64_unchecked_t;
9612 +#else
9613 +typedef atomic64_t atomic64_unchecked_t;
9614 +#endif
9615 +
9616 #define ATOMIC64_INIT(val) { (val) }
9617
9618 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
9619 @@ -37,21 +45,31 @@ typedef struct {
9620 ATOMIC64_DECL_ONE(sym##_386)
9621
9622 ATOMIC64_DECL_ONE(add_386);
9623 +ATOMIC64_DECL_ONE(add_unchecked_386);
9624 ATOMIC64_DECL_ONE(sub_386);
9625 +ATOMIC64_DECL_ONE(sub_unchecked_386);
9626 ATOMIC64_DECL_ONE(inc_386);
9627 +ATOMIC64_DECL_ONE(inc_unchecked_386);
9628 ATOMIC64_DECL_ONE(dec_386);
9629 +ATOMIC64_DECL_ONE(dec_unchecked_386);
9630 #endif
9631
9632 #define alternative_atomic64(f, out, in...) \
9633 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
9634
9635 ATOMIC64_DECL(read);
9636 +ATOMIC64_DECL(read_unchecked);
9637 ATOMIC64_DECL(set);
9638 +ATOMIC64_DECL(set_unchecked);
9639 ATOMIC64_DECL(xchg);
9640 ATOMIC64_DECL(add_return);
9641 +ATOMIC64_DECL(add_return_unchecked);
9642 ATOMIC64_DECL(sub_return);
9643 +ATOMIC64_DECL(sub_return_unchecked);
9644 ATOMIC64_DECL(inc_return);
9645 +ATOMIC64_DECL(inc_return_unchecked);
9646 ATOMIC64_DECL(dec_return);
9647 +ATOMIC64_DECL(dec_return_unchecked);
9648 ATOMIC64_DECL(dec_if_positive);
9649 ATOMIC64_DECL(inc_not_zero);
9650 ATOMIC64_DECL(add_unless);
9651 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
9652 }
9653
9654 /**
9655 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
9656 + * @p: pointer to type atomic64_unchecked_t
9657 + * @o: expected value
9658 + * @n: new value
9659 + *
9660 + * Atomically sets @v to @n if it was equal to @o and returns
9661 + * the old value.
9662 + */
9663 +
9664 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
9665 +{
9666 + return cmpxchg64(&v->counter, o, n);
9667 +}
9668 +
9669 +/**
9670 * atomic64_xchg - xchg atomic64 variable
9671 * @v: pointer to type atomic64_t
9672 * @n: value to assign
9673 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
9674 }
9675
9676 /**
9677 + * atomic64_set_unchecked - set atomic64 variable
9678 + * @v: pointer to type atomic64_unchecked_t
9679 + * @n: value to assign
9680 + *
9681 + * Atomically sets the value of @v to @n.
9682 + */
9683 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
9684 +{
9685 + unsigned high = (unsigned)(i >> 32);
9686 + unsigned low = (unsigned)i;
9687 + alternative_atomic64(set, /* no output */,
9688 + "S" (v), "b" (low), "c" (high)
9689 + : "eax", "edx", "memory");
9690 +}
9691 +
9692 +/**
9693 * atomic64_read - read atomic64 variable
9694 * @v: pointer to type atomic64_t
9695 *
9696 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
9697 }
9698
9699 /**
9700 + * atomic64_read_unchecked - read atomic64 variable
9701 + * @v: pointer to type atomic64_unchecked_t
9702 + *
9703 + * Atomically reads the value of @v and returns it.
9704 + */
9705 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
9706 +{
9707 + long long r;
9708 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
9709 + return r;
9710 + }
9711 +
9712 +/**
9713 * atomic64_add_return - add and return
9714 * @i: integer value to add
9715 * @v: pointer to type atomic64_t
9716 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
9717 return i;
9718 }
9719
9720 +/**
9721 + * atomic64_add_return_unchecked - add and return
9722 + * @i: integer value to add
9723 + * @v: pointer to type atomic64_unchecked_t
9724 + *
9725 + * Atomically adds @i to @v and returns @i + *@v
9726 + */
9727 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
9728 +{
9729 + alternative_atomic64(add_return_unchecked,
9730 + ASM_OUTPUT2("+A" (i), "+c" (v)),
9731 + ASM_NO_INPUT_CLOBBER("memory"));
9732 + return i;
9733 +}
9734 +
9735 /*
9736 * Other variants with different arithmetic operators:
9737 */
9738 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
9739 return a;
9740 }
9741
9742 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9743 +{
9744 + long long a;
9745 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
9746 + "S" (v) : "memory", "ecx");
9747 + return a;
9748 +}
9749 +
9750 static inline long long atomic64_dec_return(atomic64_t *v)
9751 {
9752 long long a;
9753 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
9754 }
9755
9756 /**
9757 + * atomic64_add_unchecked - add integer to atomic64 variable
9758 + * @i: integer value to add
9759 + * @v: pointer to type atomic64_unchecked_t
9760 + *
9761 + * Atomically adds @i to @v.
9762 + */
9763 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
9764 +{
9765 + __alternative_atomic64(add_unchecked, add_return_unchecked,
9766 + ASM_OUTPUT2("+A" (i), "+c" (v)),
9767 + ASM_NO_INPUT_CLOBBER("memory"));
9768 + return i;
9769 +}
9770 +
9771 +/**
9772 * atomic64_sub - subtract the atomic64 variable
9773 * @i: integer value to subtract
9774 * @v: pointer to type atomic64_t
9775 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
9776 index 0e1cbfc..5623683 100644
9777 --- a/arch/x86/include/asm/atomic64_64.h
9778 +++ b/arch/x86/include/asm/atomic64_64.h
9779 @@ -18,7 +18,19 @@
9780 */
9781 static inline long atomic64_read(const atomic64_t *v)
9782 {
9783 - return (*(volatile long *)&(v)->counter);
9784 + return (*(volatile const long *)&(v)->counter);
9785 +}
9786 +
9787 +/**
9788 + * atomic64_read_unchecked - read atomic64 variable
9789 + * @v: pointer of type atomic64_unchecked_t
9790 + *
9791 + * Atomically reads the value of @v.
9792 + * Doesn't imply a read memory barrier.
9793 + */
9794 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9795 +{
9796 + return (*(volatile const long *)&(v)->counter);
9797 }
9798
9799 /**
9800 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9801 }
9802
9803 /**
9804 + * atomic64_set_unchecked - set atomic64 variable
9805 + * @v: pointer to type atomic64_unchecked_t
9806 + * @i: required value
9807 + *
9808 + * Atomically sets the value of @v to @i.
9809 + */
9810 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9811 +{
9812 + v->counter = i;
9813 +}
9814 +
9815 +/**
9816 * atomic64_add - add integer to atomic64 variable
9817 * @i: integer value to add
9818 * @v: pointer to type atomic64_t
9819 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9820 */
9821 static inline void atomic64_add(long i, atomic64_t *v)
9822 {
9823 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
9824 +
9825 +#ifdef CONFIG_PAX_REFCOUNT
9826 + "jno 0f\n"
9827 + LOCK_PREFIX "subq %1,%0\n"
9828 + "int $4\n0:\n"
9829 + _ASM_EXTABLE(0b, 0b)
9830 +#endif
9831 +
9832 + : "=m" (v->counter)
9833 + : "er" (i), "m" (v->counter));
9834 +}
9835 +
9836 +/**
9837 + * atomic64_add_unchecked - add integer to atomic64 variable
9838 + * @i: integer value to add
9839 + * @v: pointer to type atomic64_unchecked_t
9840 + *
9841 + * Atomically adds @i to @v.
9842 + */
9843 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9844 +{
9845 asm volatile(LOCK_PREFIX "addq %1,%0"
9846 : "=m" (v->counter)
9847 : "er" (i), "m" (v->counter));
9848 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
9849 */
9850 static inline void atomic64_sub(long i, atomic64_t *v)
9851 {
9852 - asm volatile(LOCK_PREFIX "subq %1,%0"
9853 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9854 +
9855 +#ifdef CONFIG_PAX_REFCOUNT
9856 + "jno 0f\n"
9857 + LOCK_PREFIX "addq %1,%0\n"
9858 + "int $4\n0:\n"
9859 + _ASM_EXTABLE(0b, 0b)
9860 +#endif
9861 +
9862 + : "=m" (v->counter)
9863 + : "er" (i), "m" (v->counter));
9864 +}
9865 +
9866 +/**
9867 + * atomic64_sub_unchecked - subtract the atomic64 variable
9868 + * @i: integer value to subtract
9869 + * @v: pointer to type atomic64_unchecked_t
9870 + *
9871 + * Atomically subtracts @i from @v.
9872 + */
9873 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
9874 +{
9875 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9876 : "=m" (v->counter)
9877 : "er" (i), "m" (v->counter));
9878 }
9879 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9880 {
9881 unsigned char c;
9882
9883 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9884 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
9885 +
9886 +#ifdef CONFIG_PAX_REFCOUNT
9887 + "jno 0f\n"
9888 + LOCK_PREFIX "addq %2,%0\n"
9889 + "int $4\n0:\n"
9890 + _ASM_EXTABLE(0b, 0b)
9891 +#endif
9892 +
9893 + "sete %1\n"
9894 : "=m" (v->counter), "=qm" (c)
9895 : "er" (i), "m" (v->counter) : "memory");
9896 return c;
9897 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9898 */
9899 static inline void atomic64_inc(atomic64_t *v)
9900 {
9901 + asm volatile(LOCK_PREFIX "incq %0\n"
9902 +
9903 +#ifdef CONFIG_PAX_REFCOUNT
9904 + "jno 0f\n"
9905 + LOCK_PREFIX "decq %0\n"
9906 + "int $4\n0:\n"
9907 + _ASM_EXTABLE(0b, 0b)
9908 +#endif
9909 +
9910 + : "=m" (v->counter)
9911 + : "m" (v->counter));
9912 +}
9913 +
9914 +/**
9915 + * atomic64_inc_unchecked - increment atomic64 variable
9916 + * @v: pointer to type atomic64_unchecked_t
9917 + *
9918 + * Atomically increments @v by 1.
9919 + */
9920 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9921 +{
9922 asm volatile(LOCK_PREFIX "incq %0"
9923 : "=m" (v->counter)
9924 : "m" (v->counter));
9925 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
9926 */
9927 static inline void atomic64_dec(atomic64_t *v)
9928 {
9929 - asm volatile(LOCK_PREFIX "decq %0"
9930 + asm volatile(LOCK_PREFIX "decq %0\n"
9931 +
9932 +#ifdef CONFIG_PAX_REFCOUNT
9933 + "jno 0f\n"
9934 + LOCK_PREFIX "incq %0\n"
9935 + "int $4\n0:\n"
9936 + _ASM_EXTABLE(0b, 0b)
9937 +#endif
9938 +
9939 + : "=m" (v->counter)
9940 + : "m" (v->counter));
9941 +}
9942 +
9943 +/**
9944 + * atomic64_dec_unchecked - decrement atomic64 variable
9945 + * @v: pointer to type atomic64_t
9946 + *
9947 + * Atomically decrements @v by 1.
9948 + */
9949 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9950 +{
9951 + asm volatile(LOCK_PREFIX "decq %0\n"
9952 : "=m" (v->counter)
9953 : "m" (v->counter));
9954 }
9955 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
9956 {
9957 unsigned char c;
9958
9959 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
9960 + asm volatile(LOCK_PREFIX "decq %0\n"
9961 +
9962 +#ifdef CONFIG_PAX_REFCOUNT
9963 + "jno 0f\n"
9964 + LOCK_PREFIX "incq %0\n"
9965 + "int $4\n0:\n"
9966 + _ASM_EXTABLE(0b, 0b)
9967 +#endif
9968 +
9969 + "sete %1\n"
9970 : "=m" (v->counter), "=qm" (c)
9971 : "m" (v->counter) : "memory");
9972 return c != 0;
9973 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
9974 {
9975 unsigned char c;
9976
9977 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
9978 + asm volatile(LOCK_PREFIX "incq %0\n"
9979 +
9980 +#ifdef CONFIG_PAX_REFCOUNT
9981 + "jno 0f\n"
9982 + LOCK_PREFIX "decq %0\n"
9983 + "int $4\n0:\n"
9984 + _ASM_EXTABLE(0b, 0b)
9985 +#endif
9986 +
9987 + "sete %1\n"
9988 : "=m" (v->counter), "=qm" (c)
9989 : "m" (v->counter) : "memory");
9990 return c != 0;
9991 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9992 {
9993 unsigned char c;
9994
9995 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
9996 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
9997 +
9998 +#ifdef CONFIG_PAX_REFCOUNT
9999 + "jno 0f\n"
10000 + LOCK_PREFIX "subq %2,%0\n"
10001 + "int $4\n0:\n"
10002 + _ASM_EXTABLE(0b, 0b)
10003 +#endif
10004 +
10005 + "sets %1\n"
10006 : "=m" (v->counter), "=qm" (c)
10007 : "er" (i), "m" (v->counter) : "memory");
10008 return c;
10009 @@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
10010 */
10011 static inline long atomic64_add_return(long i, atomic64_t *v)
10012 {
10013 + return i + xadd_check_overflow(&v->counter, i);
10014 +}
10015 +
10016 +/**
10017 + * atomic64_add_return_unchecked - add and return
10018 + * @i: integer value to add
10019 + * @v: pointer to type atomic64_unchecked_t
10020 + *
10021 + * Atomically adds @i to @v and returns @i + @v
10022 + */
10023 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
10024 +{
10025 return i + xadd(&v->counter, i);
10026 }
10027
10028 @@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
10029 }
10030
10031 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
10032 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10033 +{
10034 + return atomic64_add_return_unchecked(1, v);
10035 +}
10036 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
10037
10038 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10039 @@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10040 return cmpxchg(&v->counter, old, new);
10041 }
10042
10043 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
10044 +{
10045 + return cmpxchg(&v->counter, old, new);
10046 +}
10047 +
10048 static inline long atomic64_xchg(atomic64_t *v, long new)
10049 {
10050 return xchg(&v->counter, new);
10051 @@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
10052 */
10053 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
10054 {
10055 - long c, old;
10056 + long c, old, new;
10057 c = atomic64_read(v);
10058 for (;;) {
10059 - if (unlikely(c == (u)))
10060 + if (unlikely(c == u))
10061 break;
10062 - old = atomic64_cmpxchg((v), c, c + (a));
10063 +
10064 + asm volatile("add %2,%0\n"
10065 +
10066 +#ifdef CONFIG_PAX_REFCOUNT
10067 + "jno 0f\n"
10068 + "sub %2,%0\n"
10069 + "int $4\n0:\n"
10070 + _ASM_EXTABLE(0b, 0b)
10071 +#endif
10072 +
10073 + : "=r" (new)
10074 + : "0" (c), "ir" (a));
10075 +
10076 + old = atomic64_cmpxchg(v, c, new);
10077 if (likely(old == c))
10078 break;
10079 c = old;
10080 }
10081 - return c != (u);
10082 + return c != u;
10083 }
10084
10085 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10086 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
10087 index 72f5009..2f8b9a9 100644
10088 --- a/arch/x86/include/asm/bitops.h
10089 +++ b/arch/x86/include/asm/bitops.h
10090 @@ -40,7 +40,7 @@
10091 * a mask operation on a byte.
10092 */
10093 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
10094 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
10095 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
10096 #define CONST_MASK(nr) (1 << ((nr) & 7))
10097
10098 /**
10099 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
10100 index b13fe63..0dab13a 100644
10101 --- a/arch/x86/include/asm/boot.h
10102 +++ b/arch/x86/include/asm/boot.h
10103 @@ -11,10 +11,15 @@
10104 #include <asm/pgtable_types.h>
10105
10106 /* Physical address where kernel should be loaded. */
10107 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10108 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10109 + (CONFIG_PHYSICAL_ALIGN - 1)) \
10110 & ~(CONFIG_PHYSICAL_ALIGN - 1))
10111
10112 +#ifndef __ASSEMBLY__
10113 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
10114 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
10115 +#endif
10116 +
10117 /* Minimum kernel alignment, as a power of two */
10118 #ifdef CONFIG_X86_64
10119 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
10120 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
10121 index 48f99f1..d78ebf9 100644
10122 --- a/arch/x86/include/asm/cache.h
10123 +++ b/arch/x86/include/asm/cache.h
10124 @@ -5,12 +5,13 @@
10125
10126 /* L1 cache line size */
10127 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10128 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10129 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10130
10131 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10132 +#define __read_only __attribute__((__section__(".data..read_only")))
10133
10134 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
10135 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
10136 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
10137
10138 #ifdef CONFIG_X86_VSMP
10139 #ifdef CONFIG_SMP
10140 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
10141 index 9863ee3..4a1f8e1 100644
10142 --- a/arch/x86/include/asm/cacheflush.h
10143 +++ b/arch/x86/include/asm/cacheflush.h
10144 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
10145 unsigned long pg_flags = pg->flags & _PGMT_MASK;
10146
10147 if (pg_flags == _PGMT_DEFAULT)
10148 - return -1;
10149 + return ~0UL;
10150 else if (pg_flags == _PGMT_WC)
10151 return _PAGE_CACHE_WC;
10152 else if (pg_flags == _PGMT_UC_MINUS)
10153 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
10154 index 46fc474..b02b0f9 100644
10155 --- a/arch/x86/include/asm/checksum_32.h
10156 +++ b/arch/x86/include/asm/checksum_32.h
10157 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
10158 int len, __wsum sum,
10159 int *src_err_ptr, int *dst_err_ptr);
10160
10161 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
10162 + int len, __wsum sum,
10163 + int *src_err_ptr, int *dst_err_ptr);
10164 +
10165 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
10166 + int len, __wsum sum,
10167 + int *src_err_ptr, int *dst_err_ptr);
10168 +
10169 /*
10170 * Note: when you get a NULL pointer exception here this means someone
10171 * passed in an incorrect kernel address to one of these functions.
10172 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
10173 int *err_ptr)
10174 {
10175 might_sleep();
10176 - return csum_partial_copy_generic((__force void *)src, dst,
10177 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
10178 len, sum, err_ptr, NULL);
10179 }
10180
10181 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
10182 {
10183 might_sleep();
10184 if (access_ok(VERIFY_WRITE, dst, len))
10185 - return csum_partial_copy_generic(src, (__force void *)dst,
10186 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
10187 len, sum, NULL, err_ptr);
10188
10189 if (len)
10190 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
10191 index 99480e5..d81165b 100644
10192 --- a/arch/x86/include/asm/cmpxchg.h
10193 +++ b/arch/x86/include/asm/cmpxchg.h
10194 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
10195 __compiletime_error("Bad argument size for cmpxchg");
10196 extern void __xadd_wrong_size(void)
10197 __compiletime_error("Bad argument size for xadd");
10198 +extern void __xadd_check_overflow_wrong_size(void)
10199 + __compiletime_error("Bad argument size for xadd_check_overflow");
10200 extern void __add_wrong_size(void)
10201 __compiletime_error("Bad argument size for add");
10202 +extern void __add_check_overflow_wrong_size(void)
10203 + __compiletime_error("Bad argument size for add_check_overflow");
10204
10205 /*
10206 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
10207 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
10208 __ret; \
10209 })
10210
10211 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
10212 + ({ \
10213 + __typeof__ (*(ptr)) __ret = (arg); \
10214 + switch (sizeof(*(ptr))) { \
10215 + case __X86_CASE_L: \
10216 + asm volatile (lock #op "l %0, %1\n" \
10217 + "jno 0f\n" \
10218 + "mov %0,%1\n" \
10219 + "int $4\n0:\n" \
10220 + _ASM_EXTABLE(0b, 0b) \
10221 + : "+r" (__ret), "+m" (*(ptr)) \
10222 + : : "memory", "cc"); \
10223 + break; \
10224 + case __X86_CASE_Q: \
10225 + asm volatile (lock #op "q %q0, %1\n" \
10226 + "jno 0f\n" \
10227 + "mov %0,%1\n" \
10228 + "int $4\n0:\n" \
10229 + _ASM_EXTABLE(0b, 0b) \
10230 + : "+r" (__ret), "+m" (*(ptr)) \
10231 + : : "memory", "cc"); \
10232 + break; \
10233 + default: \
10234 + __ ## op ## _check_overflow_wrong_size(); \
10235 + } \
10236 + __ret; \
10237 + })
10238 +
10239 /*
10240 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
10241 * Since this is generally used to protect other memory information, we
10242 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
10243 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
10244 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
10245
10246 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
10247 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
10248 +
10249 #define __add(ptr, inc, lock) \
10250 ({ \
10251 __typeof__ (*(ptr)) __ret = (inc); \
10252 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
10253 index 6b7ee5f..9d664b3 100644
10254 --- a/arch/x86/include/asm/cpufeature.h
10255 +++ b/arch/x86/include/asm/cpufeature.h
10256 @@ -202,13 +202,14 @@
10257 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
10258 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
10259 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
10260 -#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
10261 +#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
10262 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
10263 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
10264 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
10265 #define X86_FEATURE_RTM (9*32+11) /* Restricted Transactional Memory */
10266 #define X86_FEATURE_RDSEED (9*32+18) /* The RDSEED instruction */
10267 #define X86_FEATURE_ADX (9*32+19) /* The ADCX and ADOX instructions */
10268 +#define X86_FEATURE_SMAP (9*32+20) /* Supervisor Mode Access Prevention */
10269
10270 #if defined(__KERNEL__) && !defined(__ASSEMBLY__)
10271
10272 @@ -373,7 +374,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
10273 ".section .discard,\"aw\",@progbits\n"
10274 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
10275 ".previous\n"
10276 - ".section .altinstr_replacement,\"ax\"\n"
10277 + ".section .altinstr_replacement,\"a\"\n"
10278 "3: movb $1,%0\n"
10279 "4:\n"
10280 ".previous\n"
10281 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
10282 index 8bf1c06..f723dfd 100644
10283 --- a/arch/x86/include/asm/desc.h
10284 +++ b/arch/x86/include/asm/desc.h
10285 @@ -4,6 +4,7 @@
10286 #include <asm/desc_defs.h>
10287 #include <asm/ldt.h>
10288 #include <asm/mmu.h>
10289 +#include <asm/pgtable.h>
10290
10291 #include <linux/smp.h>
10292 #include <linux/percpu.h>
10293 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10294
10295 desc->type = (info->read_exec_only ^ 1) << 1;
10296 desc->type |= info->contents << 2;
10297 + desc->type |= info->seg_not_present ^ 1;
10298
10299 desc->s = 1;
10300 desc->dpl = 0x3;
10301 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10302 }
10303
10304 extern struct desc_ptr idt_descr;
10305 -extern gate_desc idt_table[];
10306 extern struct desc_ptr nmi_idt_descr;
10307 -extern gate_desc nmi_idt_table[];
10308 -
10309 -struct gdt_page {
10310 - struct desc_struct gdt[GDT_ENTRIES];
10311 -} __attribute__((aligned(PAGE_SIZE)));
10312 -
10313 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
10314 +extern gate_desc idt_table[256];
10315 +extern gate_desc nmi_idt_table[256];
10316
10317 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
10318 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
10319 {
10320 - return per_cpu(gdt_page, cpu).gdt;
10321 + return cpu_gdt_table[cpu];
10322 }
10323
10324 #ifdef CONFIG_X86_64
10325 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
10326 unsigned long base, unsigned dpl, unsigned flags,
10327 unsigned short seg)
10328 {
10329 - gate->a = (seg << 16) | (base & 0xffff);
10330 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
10331 + gate->gate.offset_low = base;
10332 + gate->gate.seg = seg;
10333 + gate->gate.reserved = 0;
10334 + gate->gate.type = type;
10335 + gate->gate.s = 0;
10336 + gate->gate.dpl = dpl;
10337 + gate->gate.p = 1;
10338 + gate->gate.offset_high = base >> 16;
10339 }
10340
10341 #endif
10342 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
10343
10344 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
10345 {
10346 + pax_open_kernel();
10347 memcpy(&idt[entry], gate, sizeof(*gate));
10348 + pax_close_kernel();
10349 }
10350
10351 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
10352 {
10353 + pax_open_kernel();
10354 memcpy(&ldt[entry], desc, 8);
10355 + pax_close_kernel();
10356 }
10357
10358 static inline void
10359 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
10360 default: size = sizeof(*gdt); break;
10361 }
10362
10363 + pax_open_kernel();
10364 memcpy(&gdt[entry], desc, size);
10365 + pax_close_kernel();
10366 }
10367
10368 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
10369 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
10370
10371 static inline void native_load_tr_desc(void)
10372 {
10373 + pax_open_kernel();
10374 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
10375 + pax_close_kernel();
10376 }
10377
10378 static inline void native_load_gdt(const struct desc_ptr *dtr)
10379 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
10380 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
10381 unsigned int i;
10382
10383 + pax_open_kernel();
10384 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
10385 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
10386 + pax_close_kernel();
10387 }
10388
10389 #define _LDT_empty(info) \
10390 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
10391 }
10392
10393 #ifdef CONFIG_X86_64
10394 -static inline void set_nmi_gate(int gate, void *addr)
10395 +static inline void set_nmi_gate(int gate, const void *addr)
10396 {
10397 gate_desc s;
10398
10399 @@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
10400 }
10401 #endif
10402
10403 -static inline void _set_gate(int gate, unsigned type, void *addr,
10404 +static inline void _set_gate(int gate, unsigned type, const void *addr,
10405 unsigned dpl, unsigned ist, unsigned seg)
10406 {
10407 gate_desc s;
10408 @@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
10409 * Pentium F0 0F bugfix can have resulted in the mapped
10410 * IDT being write-protected.
10411 */
10412 -static inline void set_intr_gate(unsigned int n, void *addr)
10413 +static inline void set_intr_gate(unsigned int n, const void *addr)
10414 {
10415 BUG_ON((unsigned)n > 0xFF);
10416 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
10417 @@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
10418 /*
10419 * This routine sets up an interrupt gate at directory privilege level 3.
10420 */
10421 -static inline void set_system_intr_gate(unsigned int n, void *addr)
10422 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
10423 {
10424 BUG_ON((unsigned)n > 0xFF);
10425 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
10426 }
10427
10428 -static inline void set_system_trap_gate(unsigned int n, void *addr)
10429 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
10430 {
10431 BUG_ON((unsigned)n > 0xFF);
10432 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
10433 }
10434
10435 -static inline void set_trap_gate(unsigned int n, void *addr)
10436 +static inline void set_trap_gate(unsigned int n, const void *addr)
10437 {
10438 BUG_ON((unsigned)n > 0xFF);
10439 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
10440 @@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
10441 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
10442 {
10443 BUG_ON((unsigned)n > 0xFF);
10444 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
10445 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
10446 }
10447
10448 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
10449 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
10450 {
10451 BUG_ON((unsigned)n > 0xFF);
10452 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
10453 }
10454
10455 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
10456 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
10457 {
10458 BUG_ON((unsigned)n > 0xFF);
10459 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
10460 }
10461
10462 +#ifdef CONFIG_X86_32
10463 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
10464 +{
10465 + struct desc_struct d;
10466 +
10467 + if (likely(limit))
10468 + limit = (limit - 1UL) >> PAGE_SHIFT;
10469 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
10470 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
10471 +}
10472 +#endif
10473 +
10474 #endif /* _ASM_X86_DESC_H */
10475 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
10476 index 278441f..b95a174 100644
10477 --- a/arch/x86/include/asm/desc_defs.h
10478 +++ b/arch/x86/include/asm/desc_defs.h
10479 @@ -31,6 +31,12 @@ struct desc_struct {
10480 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
10481 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
10482 };
10483 + struct {
10484 + u16 offset_low;
10485 + u16 seg;
10486 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
10487 + unsigned offset_high: 16;
10488 + } gate;
10489 };
10490 } __attribute__((packed));
10491
10492 diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
10493 index 3778256..c5d4fce 100644
10494 --- a/arch/x86/include/asm/e820.h
10495 +++ b/arch/x86/include/asm/e820.h
10496 @@ -69,7 +69,7 @@ struct e820map {
10497 #define ISA_START_ADDRESS 0xa0000
10498 #define ISA_END_ADDRESS 0x100000
10499
10500 -#define BIOS_BEGIN 0x000a0000
10501 +#define BIOS_BEGIN 0x000c0000
10502 #define BIOS_END 0x00100000
10503
10504 #define BIOS_ROM_BASE 0xffe00000
10505 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
10506 index 5939f44..f8845f6 100644
10507 --- a/arch/x86/include/asm/elf.h
10508 +++ b/arch/x86/include/asm/elf.h
10509 @@ -243,7 +243,25 @@ extern int force_personality32;
10510 the loader. We need to make sure that it is out of the way of the program
10511 that it will "exec", and that there is sufficient room for the brk. */
10512
10513 +#ifdef CONFIG_PAX_SEGMEXEC
10514 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
10515 +#else
10516 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
10517 +#endif
10518 +
10519 +#ifdef CONFIG_PAX_ASLR
10520 +#ifdef CONFIG_X86_32
10521 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
10522 +
10523 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10524 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10525 +#else
10526 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
10527 +
10528 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10529 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10530 +#endif
10531 +#endif
10532
10533 /* This yields a mask that user programs can use to figure out what
10534 instruction set this CPU supports. This could be done in user space,
10535 @@ -296,16 +314,12 @@ do { \
10536
10537 #define ARCH_DLINFO \
10538 do { \
10539 - if (vdso_enabled) \
10540 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10541 - (unsigned long)current->mm->context.vdso); \
10542 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10543 } while (0)
10544
10545 #define ARCH_DLINFO_X32 \
10546 do { \
10547 - if (vdso_enabled) \
10548 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10549 - (unsigned long)current->mm->context.vdso); \
10550 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10551 } while (0)
10552
10553 #define AT_SYSINFO 32
10554 @@ -320,7 +334,7 @@ else \
10555
10556 #endif /* !CONFIG_X86_32 */
10557
10558 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
10559 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
10560
10561 #define VDSO_ENTRY \
10562 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
10563 @@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
10564 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
10565 #define compat_arch_setup_additional_pages syscall32_setup_pages
10566
10567 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10568 -#define arch_randomize_brk arch_randomize_brk
10569 -
10570 /*
10571 * True on X86_32 or when emulating IA32 on X86_64
10572 */
10573 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10574 index 75ce3f4..882e801 100644
10575 --- a/arch/x86/include/asm/emergency-restart.h
10576 +++ b/arch/x86/include/asm/emergency-restart.h
10577 @@ -13,6 +13,6 @@ enum reboot_type {
10578
10579 extern enum reboot_type reboot_type;
10580
10581 -extern void machine_emergency_restart(void);
10582 +extern void machine_emergency_restart(void) __noreturn;
10583
10584 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10585 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
10586 index 75f4c6d..ee3eb8f 100644
10587 --- a/arch/x86/include/asm/fpu-internal.h
10588 +++ b/arch/x86/include/asm/fpu-internal.h
10589 @@ -86,6 +86,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10590 {
10591 int err;
10592
10593 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10594 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10595 + fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
10596 +#endif
10597 +
10598 /* See comment in fxsave() below. */
10599 #ifdef CONFIG_AS_FXSAVEQ
10600 asm volatile("1: fxrstorq %[fx]\n\t"
10601 @@ -115,6 +120,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10602 {
10603 int err;
10604
10605 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10606 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10607 + fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
10608 +#endif
10609 +
10610 /*
10611 * Clear the bytes not touched by the fxsave and reserved
10612 * for the SW usage.
10613 @@ -271,7 +281,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
10614 "emms\n\t" /* clear stack tags */
10615 "fildl %P[addr]", /* set F?P to defined value */
10616 X86_FEATURE_FXSAVE_LEAK,
10617 - [addr] "m" (tsk->thread.fpu.has_fpu));
10618 + [addr] "m" (init_tss[smp_processor_id()].x86_tss.sp0));
10619
10620 return fpu_restore_checking(&tsk->thread.fpu);
10621 }
10622 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10623 index 71ecbcb..bac10b7 100644
10624 --- a/arch/x86/include/asm/futex.h
10625 +++ b/arch/x86/include/asm/futex.h
10626 @@ -11,16 +11,18 @@
10627 #include <asm/processor.h>
10628
10629 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10630 + typecheck(u32 __user *, uaddr); \
10631 asm volatile("1:\t" insn "\n" \
10632 "2:\t.section .fixup,\"ax\"\n" \
10633 "3:\tmov\t%3, %1\n" \
10634 "\tjmp\t2b\n" \
10635 "\t.previous\n" \
10636 _ASM_EXTABLE(1b, 3b) \
10637 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10638 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10639 : "i" (-EFAULT), "0" (oparg), "1" (0))
10640
10641 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10642 + typecheck(u32 __user *, uaddr); \
10643 asm volatile("1:\tmovl %2, %0\n" \
10644 "\tmovl\t%0, %3\n" \
10645 "\t" insn "\n" \
10646 @@ -33,7 +35,7 @@
10647 _ASM_EXTABLE(1b, 4b) \
10648 _ASM_EXTABLE(2b, 4b) \
10649 : "=&a" (oldval), "=&r" (ret), \
10650 - "+m" (*uaddr), "=&r" (tem) \
10651 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10652 : "r" (oparg), "i" (-EFAULT), "1" (0))
10653
10654 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10655 @@ -60,10 +62,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10656
10657 switch (op) {
10658 case FUTEX_OP_SET:
10659 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10660 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10661 break;
10662 case FUTEX_OP_ADD:
10663 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10664 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10665 uaddr, oparg);
10666 break;
10667 case FUTEX_OP_OR:
10668 @@ -122,13 +124,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10669 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10670 return -EFAULT;
10671
10672 - asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10673 + asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10674 "2:\t.section .fixup, \"ax\"\n"
10675 "3:\tmov %3, %0\n"
10676 "\tjmp 2b\n"
10677 "\t.previous\n"
10678 _ASM_EXTABLE(1b, 3b)
10679 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10680 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10681 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10682 : "memory"
10683 );
10684 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10685 index eb92a6e..b98b2f4 100644
10686 --- a/arch/x86/include/asm/hw_irq.h
10687 +++ b/arch/x86/include/asm/hw_irq.h
10688 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10689 extern void enable_IO_APIC(void);
10690
10691 /* Statistics */
10692 -extern atomic_t irq_err_count;
10693 -extern atomic_t irq_mis_count;
10694 +extern atomic_unchecked_t irq_err_count;
10695 +extern atomic_unchecked_t irq_mis_count;
10696
10697 /* EISA */
10698 extern void eisa_set_level_irq(unsigned int irq);
10699 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10700 index d8e8eef..99f81ae 100644
10701 --- a/arch/x86/include/asm/io.h
10702 +++ b/arch/x86/include/asm/io.h
10703 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10704
10705 #include <linux/vmalloc.h>
10706
10707 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10708 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10709 +{
10710 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10711 +}
10712 +
10713 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10714 +{
10715 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10716 +}
10717 +
10718 /*
10719 * Convert a virtual cached pointer to an uncached pointer
10720 */
10721 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10722 index bba3cf8..06bc8da 100644
10723 --- a/arch/x86/include/asm/irqflags.h
10724 +++ b/arch/x86/include/asm/irqflags.h
10725 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10726 sti; \
10727 sysexit
10728
10729 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
10730 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10731 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
10732 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10733 +
10734 #else
10735 #define INTERRUPT_RETURN iret
10736 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10737 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10738 index 5478825..839e88c 100644
10739 --- a/arch/x86/include/asm/kprobes.h
10740 +++ b/arch/x86/include/asm/kprobes.h
10741 @@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
10742 #define RELATIVEJUMP_SIZE 5
10743 #define RELATIVECALL_OPCODE 0xe8
10744 #define RELATIVE_ADDR_SIZE 4
10745 -#define MAX_STACK_SIZE 64
10746 -#define MIN_STACK_SIZE(ADDR) \
10747 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10748 - THREAD_SIZE - (unsigned long)(ADDR))) \
10749 - ? (MAX_STACK_SIZE) \
10750 - : (((unsigned long)current_thread_info()) + \
10751 - THREAD_SIZE - (unsigned long)(ADDR)))
10752 +#define MAX_STACK_SIZE 64UL
10753 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10754
10755 #define flush_insn_slot(p) do { } while (0)
10756
10757 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10758 index 09155d6..d2e6df9 100644
10759 --- a/arch/x86/include/asm/kvm_host.h
10760 +++ b/arch/x86/include/asm/kvm_host.h
10761 @@ -694,7 +694,7 @@ struct kvm_x86_ops {
10762 int (*check_intercept)(struct kvm_vcpu *vcpu,
10763 struct x86_instruction_info *info,
10764 enum x86_intercept_stage stage);
10765 -};
10766 +} __do_const;
10767
10768 struct kvm_arch_async_pf {
10769 u32 token;
10770 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10771 index c8bed0d..e5721fa 100644
10772 --- a/arch/x86/include/asm/local.h
10773 +++ b/arch/x86/include/asm/local.h
10774 @@ -17,26 +17,58 @@ typedef struct {
10775
10776 static inline void local_inc(local_t *l)
10777 {
10778 - asm volatile(_ASM_INC "%0"
10779 + asm volatile(_ASM_INC "%0\n"
10780 +
10781 +#ifdef CONFIG_PAX_REFCOUNT
10782 + "jno 0f\n"
10783 + _ASM_DEC "%0\n"
10784 + "int $4\n0:\n"
10785 + _ASM_EXTABLE(0b, 0b)
10786 +#endif
10787 +
10788 : "+m" (l->a.counter));
10789 }
10790
10791 static inline void local_dec(local_t *l)
10792 {
10793 - asm volatile(_ASM_DEC "%0"
10794 + asm volatile(_ASM_DEC "%0\n"
10795 +
10796 +#ifdef CONFIG_PAX_REFCOUNT
10797 + "jno 0f\n"
10798 + _ASM_INC "%0\n"
10799 + "int $4\n0:\n"
10800 + _ASM_EXTABLE(0b, 0b)
10801 +#endif
10802 +
10803 : "+m" (l->a.counter));
10804 }
10805
10806 static inline void local_add(long i, local_t *l)
10807 {
10808 - asm volatile(_ASM_ADD "%1,%0"
10809 + asm volatile(_ASM_ADD "%1,%0\n"
10810 +
10811 +#ifdef CONFIG_PAX_REFCOUNT
10812 + "jno 0f\n"
10813 + _ASM_SUB "%1,%0\n"
10814 + "int $4\n0:\n"
10815 + _ASM_EXTABLE(0b, 0b)
10816 +#endif
10817 +
10818 : "+m" (l->a.counter)
10819 : "ir" (i));
10820 }
10821
10822 static inline void local_sub(long i, local_t *l)
10823 {
10824 - asm volatile(_ASM_SUB "%1,%0"
10825 + asm volatile(_ASM_SUB "%1,%0\n"
10826 +
10827 +#ifdef CONFIG_PAX_REFCOUNT
10828 + "jno 0f\n"
10829 + _ASM_ADD "%1,%0\n"
10830 + "int $4\n0:\n"
10831 + _ASM_EXTABLE(0b, 0b)
10832 +#endif
10833 +
10834 : "+m" (l->a.counter)
10835 : "ir" (i));
10836 }
10837 @@ -54,7 +86,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10838 {
10839 unsigned char c;
10840
10841 - asm volatile(_ASM_SUB "%2,%0; sete %1"
10842 + asm volatile(_ASM_SUB "%2,%0\n"
10843 +
10844 +#ifdef CONFIG_PAX_REFCOUNT
10845 + "jno 0f\n"
10846 + _ASM_ADD "%2,%0\n"
10847 + "int $4\n0:\n"
10848 + _ASM_EXTABLE(0b, 0b)
10849 +#endif
10850 +
10851 + "sete %1\n"
10852 : "+m" (l->a.counter), "=qm" (c)
10853 : "ir" (i) : "memory");
10854 return c;
10855 @@ -72,7 +113,16 @@ static inline int local_dec_and_test(local_t *l)
10856 {
10857 unsigned char c;
10858
10859 - asm volatile(_ASM_DEC "%0; sete %1"
10860 + asm volatile(_ASM_DEC "%0\n"
10861 +
10862 +#ifdef CONFIG_PAX_REFCOUNT
10863 + "jno 0f\n"
10864 + _ASM_INC "%0\n"
10865 + "int $4\n0:\n"
10866 + _ASM_EXTABLE(0b, 0b)
10867 +#endif
10868 +
10869 + "sete %1\n"
10870 : "+m" (l->a.counter), "=qm" (c)
10871 : : "memory");
10872 return c != 0;
10873 @@ -90,7 +140,16 @@ static inline int local_inc_and_test(local_t *l)
10874 {
10875 unsigned char c;
10876
10877 - asm volatile(_ASM_INC "%0; sete %1"
10878 + asm volatile(_ASM_INC "%0\n"
10879 +
10880 +#ifdef CONFIG_PAX_REFCOUNT
10881 + "jno 0f\n"
10882 + _ASM_DEC "%0\n"
10883 + "int $4\n0:\n"
10884 + _ASM_EXTABLE(0b, 0b)
10885 +#endif
10886 +
10887 + "sete %1\n"
10888 : "+m" (l->a.counter), "=qm" (c)
10889 : : "memory");
10890 return c != 0;
10891 @@ -109,7 +168,16 @@ static inline int local_add_negative(long i, local_t *l)
10892 {
10893 unsigned char c;
10894
10895 - asm volatile(_ASM_ADD "%2,%0; sets %1"
10896 + asm volatile(_ASM_ADD "%2,%0\n"
10897 +
10898 +#ifdef CONFIG_PAX_REFCOUNT
10899 + "jno 0f\n"
10900 + _ASM_SUB "%2,%0\n"
10901 + "int $4\n0:\n"
10902 + _ASM_EXTABLE(0b, 0b)
10903 +#endif
10904 +
10905 + "sets %1\n"
10906 : "+m" (l->a.counter), "=qm" (c)
10907 : "ir" (i) : "memory");
10908 return c;
10909 @@ -132,7 +200,15 @@ static inline long local_add_return(long i, local_t *l)
10910 #endif
10911 /* Modern 486+ processor */
10912 __i = i;
10913 - asm volatile(_ASM_XADD "%0, %1;"
10914 + asm volatile(_ASM_XADD "%0, %1\n"
10915 +
10916 +#ifdef CONFIG_PAX_REFCOUNT
10917 + "jno 0f\n"
10918 + _ASM_MOV "%0,%1\n"
10919 + "int $4\n0:\n"
10920 + _ASM_EXTABLE(0b, 0b)
10921 +#endif
10922 +
10923 : "+r" (i), "+m" (l->a.counter)
10924 : : "memory");
10925 return i + __i;
10926 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10927 index 593e51d..fa69c9a 100644
10928 --- a/arch/x86/include/asm/mman.h
10929 +++ b/arch/x86/include/asm/mman.h
10930 @@ -5,4 +5,14 @@
10931
10932 #include <asm-generic/mman.h>
10933
10934 +#ifdef __KERNEL__
10935 +#ifndef __ASSEMBLY__
10936 +#ifdef CONFIG_X86_32
10937 +#define arch_mmap_check i386_mmap_check
10938 +int i386_mmap_check(unsigned long addr, unsigned long len,
10939 + unsigned long flags);
10940 +#endif
10941 +#endif
10942 +#endif
10943 +
10944 #endif /* _ASM_X86_MMAN_H */
10945 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
10946 index 5f55e69..e20bfb1 100644
10947 --- a/arch/x86/include/asm/mmu.h
10948 +++ b/arch/x86/include/asm/mmu.h
10949 @@ -9,7 +9,7 @@
10950 * we put the segment information here.
10951 */
10952 typedef struct {
10953 - void *ldt;
10954 + struct desc_struct *ldt;
10955 int size;
10956
10957 #ifdef CONFIG_X86_64
10958 @@ -18,7 +18,19 @@ typedef struct {
10959 #endif
10960
10961 struct mutex lock;
10962 - void *vdso;
10963 + unsigned long vdso;
10964 +
10965 +#ifdef CONFIG_X86_32
10966 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10967 + unsigned long user_cs_base;
10968 + unsigned long user_cs_limit;
10969 +
10970 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10971 + cpumask_t cpu_user_cs_mask;
10972 +#endif
10973 +
10974 +#endif
10975 +#endif
10976 } mm_context_t;
10977
10978 #ifdef CONFIG_SMP
10979 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
10980 index cdbf367..adb37ac 100644
10981 --- a/arch/x86/include/asm/mmu_context.h
10982 +++ b/arch/x86/include/asm/mmu_context.h
10983 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
10984
10985 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
10986 {
10987 +
10988 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10989 + unsigned int i;
10990 + pgd_t *pgd;
10991 +
10992 + pax_open_kernel();
10993 + pgd = get_cpu_pgd(smp_processor_id());
10994 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
10995 + set_pgd_batched(pgd+i, native_make_pgd(0));
10996 + pax_close_kernel();
10997 +#endif
10998 +
10999 #ifdef CONFIG_SMP
11000 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
11001 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
11002 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11003 struct task_struct *tsk)
11004 {
11005 unsigned cpu = smp_processor_id();
11006 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11007 + int tlbstate = TLBSTATE_OK;
11008 +#endif
11009
11010 if (likely(prev != next)) {
11011 #ifdef CONFIG_SMP
11012 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11013 + tlbstate = this_cpu_read(cpu_tlbstate.state);
11014 +#endif
11015 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11016 this_cpu_write(cpu_tlbstate.active_mm, next);
11017 #endif
11018 cpumask_set_cpu(cpu, mm_cpumask(next));
11019
11020 /* Re-load page tables */
11021 +#ifdef CONFIG_PAX_PER_CPU_PGD
11022 + pax_open_kernel();
11023 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11024 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11025 + pax_close_kernel();
11026 + load_cr3(get_cpu_pgd(cpu));
11027 +#else
11028 load_cr3(next->pgd);
11029 +#endif
11030
11031 /* stop flush ipis for the previous mm */
11032 cpumask_clear_cpu(cpu, mm_cpumask(prev));
11033 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11034 */
11035 if (unlikely(prev->context.ldt != next->context.ldt))
11036 load_LDT_nolock(&next->context);
11037 - }
11038 +
11039 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
11040 + if (!(__supported_pte_mask & _PAGE_NX)) {
11041 + smp_mb__before_clear_bit();
11042 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
11043 + smp_mb__after_clear_bit();
11044 + cpu_set(cpu, next->context.cpu_user_cs_mask);
11045 + }
11046 +#endif
11047 +
11048 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11049 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
11050 + prev->context.user_cs_limit != next->context.user_cs_limit))
11051 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11052 #ifdef CONFIG_SMP
11053 + else if (unlikely(tlbstate != TLBSTATE_OK))
11054 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11055 +#endif
11056 +#endif
11057 +
11058 + }
11059 else {
11060 +
11061 +#ifdef CONFIG_PAX_PER_CPU_PGD
11062 + pax_open_kernel();
11063 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11064 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11065 + pax_close_kernel();
11066 + load_cr3(get_cpu_pgd(cpu));
11067 +#endif
11068 +
11069 +#ifdef CONFIG_SMP
11070 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11071 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
11072
11073 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11074 * tlb flush IPI delivery. We must reload CR3
11075 * to make sure to use no freed page tables.
11076 */
11077 +
11078 +#ifndef CONFIG_PAX_PER_CPU_PGD
11079 load_cr3(next->pgd);
11080 +#endif
11081 +
11082 load_LDT_nolock(&next->context);
11083 +
11084 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
11085 + if (!(__supported_pte_mask & _PAGE_NX))
11086 + cpu_set(cpu, next->context.cpu_user_cs_mask);
11087 +#endif
11088 +
11089 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11090 +#ifdef CONFIG_PAX_PAGEEXEC
11091 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
11092 +#endif
11093 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11094 +#endif
11095 +
11096 }
11097 +#endif
11098 }
11099 -#endif
11100 }
11101
11102 #define activate_mm(prev, next) \
11103 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
11104 index 9eae775..c914fea 100644
11105 --- a/arch/x86/include/asm/module.h
11106 +++ b/arch/x86/include/asm/module.h
11107 @@ -5,6 +5,7 @@
11108
11109 #ifdef CONFIG_X86_64
11110 /* X86_64 does not define MODULE_PROC_FAMILY */
11111 +#define MODULE_PROC_FAMILY ""
11112 #elif defined CONFIG_M386
11113 #define MODULE_PROC_FAMILY "386 "
11114 #elif defined CONFIG_M486
11115 @@ -59,8 +60,20 @@
11116 #error unknown processor family
11117 #endif
11118
11119 -#ifdef CONFIG_X86_32
11120 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
11121 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11122 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
11123 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
11124 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
11125 +#else
11126 +#define MODULE_PAX_KERNEXEC ""
11127 #endif
11128
11129 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11130 +#define MODULE_PAX_UDEREF "UDEREF "
11131 +#else
11132 +#define MODULE_PAX_UDEREF ""
11133 +#endif
11134 +
11135 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
11136 +
11137 #endif /* _ASM_X86_MODULE_H */
11138 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
11139 index 320f7bb..e89f8f8 100644
11140 --- a/arch/x86/include/asm/page_64_types.h
11141 +++ b/arch/x86/include/asm/page_64_types.h
11142 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
11143
11144 /* duplicated to the one in bootmem.h */
11145 extern unsigned long max_pfn;
11146 -extern unsigned long phys_base;
11147 +extern const unsigned long phys_base;
11148
11149 extern unsigned long __phys_addr(unsigned long);
11150 #define __phys_reloc_hide(x) (x)
11151 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
11152 index a0facf3..c017b15 100644
11153 --- a/arch/x86/include/asm/paravirt.h
11154 +++ b/arch/x86/include/asm/paravirt.h
11155 @@ -632,6 +632,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
11156 val);
11157 }
11158
11159 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11160 +{
11161 + pgdval_t val = native_pgd_val(pgd);
11162 +
11163 + if (sizeof(pgdval_t) > sizeof(long))
11164 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
11165 + val, (u64)val >> 32);
11166 + else
11167 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
11168 + val);
11169 +}
11170 +
11171 static inline void pgd_clear(pgd_t *pgdp)
11172 {
11173 set_pgd(pgdp, __pgd(0));
11174 @@ -713,6 +725,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
11175 pv_mmu_ops.set_fixmap(idx, phys, flags);
11176 }
11177
11178 +#ifdef CONFIG_PAX_KERNEXEC
11179 +static inline unsigned long pax_open_kernel(void)
11180 +{
11181 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
11182 +}
11183 +
11184 +static inline unsigned long pax_close_kernel(void)
11185 +{
11186 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
11187 +}
11188 +#else
11189 +static inline unsigned long pax_open_kernel(void) { return 0; }
11190 +static inline unsigned long pax_close_kernel(void) { return 0; }
11191 +#endif
11192 +
11193 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
11194
11195 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
11196 @@ -929,7 +956,7 @@ extern void default_banner(void);
11197
11198 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
11199 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
11200 -#define PARA_INDIRECT(addr) *%cs:addr
11201 +#define PARA_INDIRECT(addr) *%ss:addr
11202 #endif
11203
11204 #define INTERRUPT_RETURN \
11205 @@ -1004,6 +1031,21 @@ extern void default_banner(void);
11206 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
11207 CLBR_NONE, \
11208 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
11209 +
11210 +#define GET_CR0_INTO_RDI \
11211 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
11212 + mov %rax,%rdi
11213 +
11214 +#define SET_RDI_INTO_CR0 \
11215 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
11216 +
11217 +#define GET_CR3_INTO_RDI \
11218 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
11219 + mov %rax,%rdi
11220 +
11221 +#define SET_RDI_INTO_CR3 \
11222 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
11223 +
11224 #endif /* CONFIG_X86_32 */
11225
11226 #endif /* __ASSEMBLY__ */
11227 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
11228 index 142236e..6a6b4a6 100644
11229 --- a/arch/x86/include/asm/paravirt_types.h
11230 +++ b/arch/x86/include/asm/paravirt_types.h
11231 @@ -84,20 +84,20 @@ struct pv_init_ops {
11232 */
11233 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
11234 unsigned long addr, unsigned len);
11235 -};
11236 +} __no_const;
11237
11238
11239 struct pv_lazy_ops {
11240 /* Set deferred update mode, used for batching operations. */
11241 void (*enter)(void);
11242 void (*leave)(void);
11243 -};
11244 +} __no_const;
11245
11246 struct pv_time_ops {
11247 unsigned long long (*sched_clock)(void);
11248 unsigned long long (*steal_clock)(int cpu);
11249 unsigned long (*get_tsc_khz)(void);
11250 -};
11251 +} __no_const;
11252
11253 struct pv_cpu_ops {
11254 /* hooks for various privileged instructions */
11255 @@ -191,7 +191,7 @@ struct pv_cpu_ops {
11256
11257 void (*start_context_switch)(struct task_struct *prev);
11258 void (*end_context_switch)(struct task_struct *next);
11259 -};
11260 +} __no_const;
11261
11262 struct pv_irq_ops {
11263 /*
11264 @@ -222,7 +222,7 @@ struct pv_apic_ops {
11265 unsigned long start_eip,
11266 unsigned long start_esp);
11267 #endif
11268 -};
11269 +} __no_const;
11270
11271 struct pv_mmu_ops {
11272 unsigned long (*read_cr2)(void);
11273 @@ -312,6 +312,7 @@ struct pv_mmu_ops {
11274 struct paravirt_callee_save make_pud;
11275
11276 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
11277 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
11278 #endif /* PAGETABLE_LEVELS == 4 */
11279 #endif /* PAGETABLE_LEVELS >= 3 */
11280
11281 @@ -323,6 +324,12 @@ struct pv_mmu_ops {
11282 an mfn. We can tell which is which from the index. */
11283 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
11284 phys_addr_t phys, pgprot_t flags);
11285 +
11286 +#ifdef CONFIG_PAX_KERNEXEC
11287 + unsigned long (*pax_open_kernel)(void);
11288 + unsigned long (*pax_close_kernel)(void);
11289 +#endif
11290 +
11291 };
11292
11293 struct arch_spinlock;
11294 @@ -333,7 +340,7 @@ struct pv_lock_ops {
11295 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
11296 int (*spin_trylock)(struct arch_spinlock *lock);
11297 void (*spin_unlock)(struct arch_spinlock *lock);
11298 -};
11299 +} __no_const;
11300
11301 /* This contains all the paravirt structures: we get a convenient
11302 * number for each function using the offset which we use to indicate
11303 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
11304 index b4389a4..7024269 100644
11305 --- a/arch/x86/include/asm/pgalloc.h
11306 +++ b/arch/x86/include/asm/pgalloc.h
11307 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
11308 pmd_t *pmd, pte_t *pte)
11309 {
11310 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11311 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
11312 +}
11313 +
11314 +static inline void pmd_populate_user(struct mm_struct *mm,
11315 + pmd_t *pmd, pte_t *pte)
11316 +{
11317 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11318 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
11319 }
11320
11321 @@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
11322
11323 #ifdef CONFIG_X86_PAE
11324 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
11325 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
11326 +{
11327 + pud_populate(mm, pudp, pmd);
11328 +}
11329 #else /* !CONFIG_X86_PAE */
11330 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11331 {
11332 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11333 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
11334 }
11335 +
11336 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11337 +{
11338 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11339 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
11340 +}
11341 #endif /* CONFIG_X86_PAE */
11342
11343 #if PAGETABLE_LEVELS > 3
11344 @@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11345 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
11346 }
11347
11348 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11349 +{
11350 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
11351 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
11352 +}
11353 +
11354 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
11355 {
11356 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
11357 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
11358 index f2b489c..4f7e2e5 100644
11359 --- a/arch/x86/include/asm/pgtable-2level.h
11360 +++ b/arch/x86/include/asm/pgtable-2level.h
11361 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
11362
11363 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11364 {
11365 + pax_open_kernel();
11366 *pmdp = pmd;
11367 + pax_close_kernel();
11368 }
11369
11370 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11371 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
11372 index 4cc9f2b..5fd9226 100644
11373 --- a/arch/x86/include/asm/pgtable-3level.h
11374 +++ b/arch/x86/include/asm/pgtable-3level.h
11375 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11376
11377 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11378 {
11379 + pax_open_kernel();
11380 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
11381 + pax_close_kernel();
11382 }
11383
11384 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11385 {
11386 + pax_open_kernel();
11387 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
11388 + pax_close_kernel();
11389 }
11390
11391 /*
11392 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
11393 index c3520d7..cf742ef 100644
11394 --- a/arch/x86/include/asm/pgtable.h
11395 +++ b/arch/x86/include/asm/pgtable.h
11396 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11397
11398 #ifndef __PAGETABLE_PUD_FOLDED
11399 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
11400 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
11401 #define pgd_clear(pgd) native_pgd_clear(pgd)
11402 #endif
11403
11404 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11405
11406 #define arch_end_context_switch(prev) do {} while(0)
11407
11408 +#define pax_open_kernel() native_pax_open_kernel()
11409 +#define pax_close_kernel() native_pax_close_kernel()
11410 #endif /* CONFIG_PARAVIRT */
11411
11412 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
11413 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
11414 +
11415 +#ifdef CONFIG_PAX_KERNEXEC
11416 +static inline unsigned long native_pax_open_kernel(void)
11417 +{
11418 + unsigned long cr0;
11419 +
11420 + preempt_disable();
11421 + barrier();
11422 + cr0 = read_cr0() ^ X86_CR0_WP;
11423 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
11424 + write_cr0(cr0);
11425 + return cr0 ^ X86_CR0_WP;
11426 +}
11427 +
11428 +static inline unsigned long native_pax_close_kernel(void)
11429 +{
11430 + unsigned long cr0;
11431 +
11432 + cr0 = read_cr0() ^ X86_CR0_WP;
11433 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
11434 + write_cr0(cr0);
11435 + barrier();
11436 + preempt_enable_no_resched();
11437 + return cr0 ^ X86_CR0_WP;
11438 +}
11439 +#else
11440 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
11441 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
11442 +#endif
11443 +
11444 /*
11445 * The following only work if pte_present() is true.
11446 * Undefined behaviour if not..
11447 */
11448 +static inline int pte_user(pte_t pte)
11449 +{
11450 + return pte_val(pte) & _PAGE_USER;
11451 +}
11452 +
11453 static inline int pte_dirty(pte_t pte)
11454 {
11455 return pte_flags(pte) & _PAGE_DIRTY;
11456 @@ -195,9 +235,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
11457 return pte_clear_flags(pte, _PAGE_RW);
11458 }
11459
11460 +static inline pte_t pte_mkread(pte_t pte)
11461 +{
11462 + return __pte(pte_val(pte) | _PAGE_USER);
11463 +}
11464 +
11465 static inline pte_t pte_mkexec(pte_t pte)
11466 {
11467 - return pte_clear_flags(pte, _PAGE_NX);
11468 +#ifdef CONFIG_X86_PAE
11469 + if (__supported_pte_mask & _PAGE_NX)
11470 + return pte_clear_flags(pte, _PAGE_NX);
11471 + else
11472 +#endif
11473 + return pte_set_flags(pte, _PAGE_USER);
11474 +}
11475 +
11476 +static inline pte_t pte_exprotect(pte_t pte)
11477 +{
11478 +#ifdef CONFIG_X86_PAE
11479 + if (__supported_pte_mask & _PAGE_NX)
11480 + return pte_set_flags(pte, _PAGE_NX);
11481 + else
11482 +#endif
11483 + return pte_clear_flags(pte, _PAGE_USER);
11484 }
11485
11486 static inline pte_t pte_mkdirty(pte_t pte)
11487 @@ -389,6 +449,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
11488 #endif
11489
11490 #ifndef __ASSEMBLY__
11491 +
11492 +#ifdef CONFIG_PAX_PER_CPU_PGD
11493 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
11494 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
11495 +{
11496 + return cpu_pgd[cpu];
11497 +}
11498 +#endif
11499 +
11500 #include <linux/mm_types.h>
11501
11502 static inline int pte_none(pte_t pte)
11503 @@ -565,7 +634,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
11504
11505 static inline int pgd_bad(pgd_t pgd)
11506 {
11507 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
11508 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
11509 }
11510
11511 static inline int pgd_none(pgd_t pgd)
11512 @@ -588,7 +657,12 @@ static inline int pgd_none(pgd_t pgd)
11513 * pgd_offset() returns a (pgd_t *)
11514 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
11515 */
11516 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
11517 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
11518 +
11519 +#ifdef CONFIG_PAX_PER_CPU_PGD
11520 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
11521 +#endif
11522 +
11523 /*
11524 * a shortcut which implies the use of the kernel's pgd, instead
11525 * of a process's
11526 @@ -599,6 +673,20 @@ static inline int pgd_none(pgd_t pgd)
11527 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
11528 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
11529
11530 +#ifdef CONFIG_X86_32
11531 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
11532 +#else
11533 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
11534 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
11535 +
11536 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11537 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
11538 +#else
11539 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
11540 +#endif
11541 +
11542 +#endif
11543 +
11544 #ifndef __ASSEMBLY__
11545
11546 extern int direct_gbpages;
11547 @@ -763,11 +851,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
11548 * dst and src can be on the same page, but the range must not overlap,
11549 * and must not cross a page boundary.
11550 */
11551 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11552 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11553 {
11554 - memcpy(dst, src, count * sizeof(pgd_t));
11555 + pax_open_kernel();
11556 + while (count--)
11557 + *dst++ = *src++;
11558 + pax_close_kernel();
11559 }
11560
11561 +#ifdef CONFIG_PAX_PER_CPU_PGD
11562 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
11563 +#endif
11564 +
11565 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11566 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
11567 +#else
11568 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
11569 +#endif
11570
11571 #include <asm-generic/pgtable.h>
11572 #endif /* __ASSEMBLY__ */
11573 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11574 index 0c92113..34a77c6 100644
11575 --- a/arch/x86/include/asm/pgtable_32.h
11576 +++ b/arch/x86/include/asm/pgtable_32.h
11577 @@ -25,9 +25,6 @@
11578 struct mm_struct;
11579 struct vm_area_struct;
11580
11581 -extern pgd_t swapper_pg_dir[1024];
11582 -extern pgd_t initial_page_table[1024];
11583 -
11584 static inline void pgtable_cache_init(void) { }
11585 static inline void check_pgt_cache(void) { }
11586 void paging_init(void);
11587 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11588 # include <asm/pgtable-2level.h>
11589 #endif
11590
11591 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11592 +extern pgd_t initial_page_table[PTRS_PER_PGD];
11593 +#ifdef CONFIG_X86_PAE
11594 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11595 +#endif
11596 +
11597 #if defined(CONFIG_HIGHPTE)
11598 #define pte_offset_map(dir, address) \
11599 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
11600 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11601 /* Clear a kernel PTE and flush it from the TLB */
11602 #define kpte_clear_flush(ptep, vaddr) \
11603 do { \
11604 + pax_open_kernel(); \
11605 pte_clear(&init_mm, (vaddr), (ptep)); \
11606 + pax_close_kernel(); \
11607 __flush_tlb_one((vaddr)); \
11608 } while (0)
11609
11610 @@ -74,6 +79,9 @@ do { \
11611
11612 #endif /* !__ASSEMBLY__ */
11613
11614 +#define HAVE_ARCH_UNMAPPED_AREA
11615 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11616 +
11617 /*
11618 * kern_addr_valid() is (1) for FLATMEM and (0) for
11619 * SPARSEMEM and DISCONTIGMEM
11620 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11621 index ed5903b..c7fe163 100644
11622 --- a/arch/x86/include/asm/pgtable_32_types.h
11623 +++ b/arch/x86/include/asm/pgtable_32_types.h
11624 @@ -8,7 +8,7 @@
11625 */
11626 #ifdef CONFIG_X86_PAE
11627 # include <asm/pgtable-3level_types.h>
11628 -# define PMD_SIZE (1UL << PMD_SHIFT)
11629 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11630 # define PMD_MASK (~(PMD_SIZE - 1))
11631 #else
11632 # include <asm/pgtable-2level_types.h>
11633 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11634 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11635 #endif
11636
11637 +#ifdef CONFIG_PAX_KERNEXEC
11638 +#ifndef __ASSEMBLY__
11639 +extern unsigned char MODULES_EXEC_VADDR[];
11640 +extern unsigned char MODULES_EXEC_END[];
11641 +#endif
11642 +#include <asm/boot.h>
11643 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11644 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11645 +#else
11646 +#define ktla_ktva(addr) (addr)
11647 +#define ktva_ktla(addr) (addr)
11648 +#endif
11649 +
11650 #define MODULES_VADDR VMALLOC_START
11651 #define MODULES_END VMALLOC_END
11652 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11653 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11654 index 8251be0..4ea8b46 100644
11655 --- a/arch/x86/include/asm/pgtable_64.h
11656 +++ b/arch/x86/include/asm/pgtable_64.h
11657 @@ -16,10 +16,14 @@
11658
11659 extern pud_t level3_kernel_pgt[512];
11660 extern pud_t level3_ident_pgt[512];
11661 +extern pud_t level3_vmalloc_start_pgt[512];
11662 +extern pud_t level3_vmalloc_end_pgt[512];
11663 +extern pud_t level3_vmemmap_pgt[512];
11664 +extern pud_t level2_vmemmap_pgt[512];
11665 extern pmd_t level2_kernel_pgt[512];
11666 extern pmd_t level2_fixmap_pgt[512];
11667 -extern pmd_t level2_ident_pgt[512];
11668 -extern pgd_t init_level4_pgt[];
11669 +extern pmd_t level2_ident_pgt[512*2];
11670 +extern pgd_t init_level4_pgt[512];
11671
11672 #define swapper_pg_dir init_level4_pgt
11673
11674 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11675
11676 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11677 {
11678 + pax_open_kernel();
11679 *pmdp = pmd;
11680 + pax_close_kernel();
11681 }
11682
11683 static inline void native_pmd_clear(pmd_t *pmd)
11684 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
11685
11686 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11687 {
11688 + pax_open_kernel();
11689 *pudp = pud;
11690 + pax_close_kernel();
11691 }
11692
11693 static inline void native_pud_clear(pud_t *pud)
11694 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
11695
11696 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11697 {
11698 + pax_open_kernel();
11699 + *pgdp = pgd;
11700 + pax_close_kernel();
11701 +}
11702 +
11703 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11704 +{
11705 *pgdp = pgd;
11706 }
11707
11708 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11709 index 766ea16..5b96cb3 100644
11710 --- a/arch/x86/include/asm/pgtable_64_types.h
11711 +++ b/arch/x86/include/asm/pgtable_64_types.h
11712 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11713 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11714 #define MODULES_END _AC(0xffffffffff000000, UL)
11715 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11716 +#define MODULES_EXEC_VADDR MODULES_VADDR
11717 +#define MODULES_EXEC_END MODULES_END
11718 +
11719 +#define ktla_ktva(addr) (addr)
11720 +#define ktva_ktla(addr) (addr)
11721
11722 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11723 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11724 index 013286a..8b42f4f 100644
11725 --- a/arch/x86/include/asm/pgtable_types.h
11726 +++ b/arch/x86/include/asm/pgtable_types.h
11727 @@ -16,13 +16,12 @@
11728 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11729 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11730 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11731 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11732 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11733 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11734 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11735 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11736 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11737 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11738 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11739 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11740 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11741 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11742
11743 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11744 @@ -40,7 +39,6 @@
11745 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11746 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11747 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11748 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11749 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11750 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11751 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11752 @@ -57,8 +55,10 @@
11753
11754 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11755 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11756 -#else
11757 +#elif defined(CONFIG_KMEMCHECK)
11758 #define _PAGE_NX (_AT(pteval_t, 0))
11759 +#else
11760 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11761 #endif
11762
11763 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11764 @@ -96,6 +96,9 @@
11765 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11766 _PAGE_ACCESSED)
11767
11768 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
11769 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
11770 +
11771 #define __PAGE_KERNEL_EXEC \
11772 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11773 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11774 @@ -106,7 +109,7 @@
11775 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11776 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11777 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11778 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11779 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11780 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11781 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11782 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11783 @@ -168,8 +171,8 @@
11784 * bits are combined, this will alow user to access the high address mapped
11785 * VDSO in the presence of CONFIG_COMPAT_VDSO
11786 */
11787 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11788 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11789 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11790 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11791 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11792 #endif
11793
11794 @@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11795 {
11796 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11797 }
11798 +#endif
11799
11800 +#if PAGETABLE_LEVELS == 3
11801 +#include <asm-generic/pgtable-nopud.h>
11802 +#endif
11803 +
11804 +#if PAGETABLE_LEVELS == 2
11805 +#include <asm-generic/pgtable-nopmd.h>
11806 +#endif
11807 +
11808 +#ifndef __ASSEMBLY__
11809 #if PAGETABLE_LEVELS > 3
11810 typedef struct { pudval_t pud; } pud_t;
11811
11812 @@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11813 return pud.pud;
11814 }
11815 #else
11816 -#include <asm-generic/pgtable-nopud.h>
11817 -
11818 static inline pudval_t native_pud_val(pud_t pud)
11819 {
11820 return native_pgd_val(pud.pgd);
11821 @@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11822 return pmd.pmd;
11823 }
11824 #else
11825 -#include <asm-generic/pgtable-nopmd.h>
11826 -
11827 static inline pmdval_t native_pmd_val(pmd_t pmd)
11828 {
11829 return native_pgd_val(pmd.pud.pgd);
11830 @@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11831
11832 extern pteval_t __supported_pte_mask;
11833 extern void set_nx(void);
11834 -extern int nx_enabled;
11835
11836 #define pgprot_writecombine pgprot_writecombine
11837 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11838 diff --git a/arch/x86/include/asm/processor-flags.h b/arch/x86/include/asm/processor-flags.h
11839 index aea1d1d..680cf09 100644
11840 --- a/arch/x86/include/asm/processor-flags.h
11841 +++ b/arch/x86/include/asm/processor-flags.h
11842 @@ -65,6 +65,7 @@
11843 #define X86_CR4_PCIDE 0x00020000 /* enable PCID support */
11844 #define X86_CR4_OSXSAVE 0x00040000 /* enable xsave and xrestore */
11845 #define X86_CR4_SMEP 0x00100000 /* enable SMEP support */
11846 +#define X86_CR4_SMAP 0x00200000 /* enable SMAP support */
11847
11848 /*
11849 * x86-64 Task Priority Register, CR8
11850 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11851 index d048cad..45e350f 100644
11852 --- a/arch/x86/include/asm/processor.h
11853 +++ b/arch/x86/include/asm/processor.h
11854 @@ -289,7 +289,7 @@ struct tss_struct {
11855
11856 } ____cacheline_aligned;
11857
11858 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11859 +extern struct tss_struct init_tss[NR_CPUS];
11860
11861 /*
11862 * Save the original ist values for checking stack pointers during debugging
11863 @@ -822,11 +822,18 @@ static inline void spin_lock_prefetch(const void *x)
11864 */
11865 #define TASK_SIZE PAGE_OFFSET
11866 #define TASK_SIZE_MAX TASK_SIZE
11867 +
11868 +#ifdef CONFIG_PAX_SEGMEXEC
11869 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11870 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11871 +#else
11872 #define STACK_TOP TASK_SIZE
11873 -#define STACK_TOP_MAX STACK_TOP
11874 +#endif
11875 +
11876 +#define STACK_TOP_MAX TASK_SIZE
11877
11878 #define INIT_THREAD { \
11879 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11880 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11881 .vm86_info = NULL, \
11882 .sysenter_cs = __KERNEL_CS, \
11883 .io_bitmap_ptr = NULL, \
11884 @@ -840,7 +847,7 @@ static inline void spin_lock_prefetch(const void *x)
11885 */
11886 #define INIT_TSS { \
11887 .x86_tss = { \
11888 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11889 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11890 .ss0 = __KERNEL_DS, \
11891 .ss1 = __KERNEL_CS, \
11892 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11893 @@ -851,11 +858,7 @@ static inline void spin_lock_prefetch(const void *x)
11894 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11895
11896 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11897 -#define KSTK_TOP(info) \
11898 -({ \
11899 - unsigned long *__ptr = (unsigned long *)(info); \
11900 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11901 -})
11902 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11903
11904 /*
11905 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11906 @@ -870,7 +873,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11907 #define task_pt_regs(task) \
11908 ({ \
11909 struct pt_regs *__regs__; \
11910 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11911 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11912 __regs__ - 1; \
11913 })
11914
11915 @@ -880,13 +883,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11916 /*
11917 * User space process size. 47bits minus one guard page.
11918 */
11919 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11920 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11921
11922 /* This decides where the kernel will search for a free chunk of vm
11923 * space during mmap's.
11924 */
11925 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11926 - 0xc0000000 : 0xFFFFe000)
11927 + 0xc0000000 : 0xFFFFf000)
11928
11929 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
11930 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11931 @@ -897,11 +900,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11932 #define STACK_TOP_MAX TASK_SIZE_MAX
11933
11934 #define INIT_THREAD { \
11935 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11936 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11937 }
11938
11939 #define INIT_TSS { \
11940 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11941 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11942 }
11943
11944 /*
11945 @@ -929,6 +932,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
11946 */
11947 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11948
11949 +#ifdef CONFIG_PAX_SEGMEXEC
11950 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11951 +#endif
11952 +
11953 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11954
11955 /* Get/set a process' ability to use the timestamp counter instruction */
11956 @@ -989,12 +996,12 @@ extern bool cpu_has_amd_erratum(const int *);
11957 #define cpu_has_amd_erratum(x) (false)
11958 #endif /* CONFIG_CPU_SUP_AMD */
11959
11960 -extern unsigned long arch_align_stack(unsigned long sp);
11961 +#define arch_align_stack(x) ((x) & ~0xfUL)
11962 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11963
11964 void default_idle(void);
11965 bool set_pm_idle_to_default(void);
11966
11967 -void stop_this_cpu(void *dummy);
11968 +void stop_this_cpu(void *dummy) __noreturn;
11969
11970 #endif /* _ASM_X86_PROCESSOR_H */
11971 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
11972 index dcfde52..dbfea06 100644
11973 --- a/arch/x86/include/asm/ptrace.h
11974 +++ b/arch/x86/include/asm/ptrace.h
11975 @@ -155,28 +155,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
11976 }
11977
11978 /*
11979 - * user_mode_vm(regs) determines whether a register set came from user mode.
11980 + * user_mode(regs) determines whether a register set came from user mode.
11981 * This is true if V8086 mode was enabled OR if the register set was from
11982 * protected mode with RPL-3 CS value. This tricky test checks that with
11983 * one comparison. Many places in the kernel can bypass this full check
11984 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
11985 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
11986 + * be used.
11987 */
11988 -static inline int user_mode(struct pt_regs *regs)
11989 +static inline int user_mode_novm(struct pt_regs *regs)
11990 {
11991 #ifdef CONFIG_X86_32
11992 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
11993 #else
11994 - return !!(regs->cs & 3);
11995 + return !!(regs->cs & SEGMENT_RPL_MASK);
11996 #endif
11997 }
11998
11999 -static inline int user_mode_vm(struct pt_regs *regs)
12000 +static inline int user_mode(struct pt_regs *regs)
12001 {
12002 #ifdef CONFIG_X86_32
12003 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
12004 USER_RPL;
12005 #else
12006 - return user_mode(regs);
12007 + return user_mode_novm(regs);
12008 #endif
12009 }
12010
12011 @@ -192,15 +193,16 @@ static inline int v8086_mode(struct pt_regs *regs)
12012 #ifdef CONFIG_X86_64
12013 static inline bool user_64bit_mode(struct pt_regs *regs)
12014 {
12015 + unsigned long cs = regs->cs & 0xffff;
12016 #ifndef CONFIG_PARAVIRT
12017 /*
12018 * On non-paravirt systems, this is the only long mode CPL 3
12019 * selector. We do not allow long mode selectors in the LDT.
12020 */
12021 - return regs->cs == __USER_CS;
12022 + return cs == __USER_CS;
12023 #else
12024 /* Headers are too twisted for this to go in paravirt.h. */
12025 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
12026 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
12027 #endif
12028 }
12029 #endif
12030 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
12031 index fe1ec5b..dc5c3fe 100644
12032 --- a/arch/x86/include/asm/realmode.h
12033 +++ b/arch/x86/include/asm/realmode.h
12034 @@ -22,16 +22,14 @@ struct real_mode_header {
12035 #endif
12036 /* APM/BIOS reboot */
12037 u32 machine_real_restart_asm;
12038 -#ifdef CONFIG_X86_64
12039 u32 machine_real_restart_seg;
12040 -#endif
12041 };
12042
12043 /* This must match data at trampoline_32/64.S */
12044 struct trampoline_header {
12045 #ifdef CONFIG_X86_32
12046 u32 start;
12047 - u16 gdt_pad;
12048 + u16 boot_cs;
12049 u16 gdt_limit;
12050 u32 gdt_base;
12051 #else
12052 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
12053 index a82c4f1..ac45053 100644
12054 --- a/arch/x86/include/asm/reboot.h
12055 +++ b/arch/x86/include/asm/reboot.h
12056 @@ -6,13 +6,13 @@
12057 struct pt_regs;
12058
12059 struct machine_ops {
12060 - void (*restart)(char *cmd);
12061 - void (*halt)(void);
12062 - void (*power_off)(void);
12063 + void (* __noreturn restart)(char *cmd);
12064 + void (* __noreturn halt)(void);
12065 + void (* __noreturn power_off)(void);
12066 void (*shutdown)(void);
12067 void (*crash_shutdown)(struct pt_regs *);
12068 - void (*emergency_restart)(void);
12069 -};
12070 + void (* __noreturn emergency_restart)(void);
12071 +} __no_const;
12072
12073 extern struct machine_ops machine_ops;
12074
12075 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
12076 index 2dbe4a7..ce1db00 100644
12077 --- a/arch/x86/include/asm/rwsem.h
12078 +++ b/arch/x86/include/asm/rwsem.h
12079 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
12080 {
12081 asm volatile("# beginning down_read\n\t"
12082 LOCK_PREFIX _ASM_INC "(%1)\n\t"
12083 +
12084 +#ifdef CONFIG_PAX_REFCOUNT
12085 + "jno 0f\n"
12086 + LOCK_PREFIX _ASM_DEC "(%1)\n"
12087 + "int $4\n0:\n"
12088 + _ASM_EXTABLE(0b, 0b)
12089 +#endif
12090 +
12091 /* adds 0x00000001 */
12092 " jns 1f\n"
12093 " call call_rwsem_down_read_failed\n"
12094 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
12095 "1:\n\t"
12096 " mov %1,%2\n\t"
12097 " add %3,%2\n\t"
12098 +
12099 +#ifdef CONFIG_PAX_REFCOUNT
12100 + "jno 0f\n"
12101 + "sub %3,%2\n"
12102 + "int $4\n0:\n"
12103 + _ASM_EXTABLE(0b, 0b)
12104 +#endif
12105 +
12106 " jle 2f\n\t"
12107 LOCK_PREFIX " cmpxchg %2,%0\n\t"
12108 " jnz 1b\n\t"
12109 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
12110 long tmp;
12111 asm volatile("# beginning down_write\n\t"
12112 LOCK_PREFIX " xadd %1,(%2)\n\t"
12113 +
12114 +#ifdef CONFIG_PAX_REFCOUNT
12115 + "jno 0f\n"
12116 + "mov %1,(%2)\n"
12117 + "int $4\n0:\n"
12118 + _ASM_EXTABLE(0b, 0b)
12119 +#endif
12120 +
12121 /* adds 0xffff0001, returns the old value */
12122 " test %1,%1\n\t"
12123 /* was the count 0 before? */
12124 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
12125 long tmp;
12126 asm volatile("# beginning __up_read\n\t"
12127 LOCK_PREFIX " xadd %1,(%2)\n\t"
12128 +
12129 +#ifdef CONFIG_PAX_REFCOUNT
12130 + "jno 0f\n"
12131 + "mov %1,(%2)\n"
12132 + "int $4\n0:\n"
12133 + _ASM_EXTABLE(0b, 0b)
12134 +#endif
12135 +
12136 /* subtracts 1, returns the old value */
12137 " jns 1f\n\t"
12138 " call call_rwsem_wake\n" /* expects old value in %edx */
12139 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
12140 long tmp;
12141 asm volatile("# beginning __up_write\n\t"
12142 LOCK_PREFIX " xadd %1,(%2)\n\t"
12143 +
12144 +#ifdef CONFIG_PAX_REFCOUNT
12145 + "jno 0f\n"
12146 + "mov %1,(%2)\n"
12147 + "int $4\n0:\n"
12148 + _ASM_EXTABLE(0b, 0b)
12149 +#endif
12150 +
12151 /* subtracts 0xffff0001, returns the old value */
12152 " jns 1f\n\t"
12153 " call call_rwsem_wake\n" /* expects old value in %edx */
12154 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12155 {
12156 asm volatile("# beginning __downgrade_write\n\t"
12157 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
12158 +
12159 +#ifdef CONFIG_PAX_REFCOUNT
12160 + "jno 0f\n"
12161 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
12162 + "int $4\n0:\n"
12163 + _ASM_EXTABLE(0b, 0b)
12164 +#endif
12165 +
12166 /*
12167 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
12168 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
12169 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12170 */
12171 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12172 {
12173 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
12174 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
12175 +
12176 +#ifdef CONFIG_PAX_REFCOUNT
12177 + "jno 0f\n"
12178 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
12179 + "int $4\n0:\n"
12180 + _ASM_EXTABLE(0b, 0b)
12181 +#endif
12182 +
12183 : "+m" (sem->count)
12184 : "er" (delta));
12185 }
12186 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12187 */
12188 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
12189 {
12190 - return delta + xadd(&sem->count, delta);
12191 + return delta + xadd_check_overflow(&sem->count, delta);
12192 }
12193
12194 #endif /* __KERNEL__ */
12195 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
12196 index c48a950..c6d7468 100644
12197 --- a/arch/x86/include/asm/segment.h
12198 +++ b/arch/x86/include/asm/segment.h
12199 @@ -64,10 +64,15 @@
12200 * 26 - ESPFIX small SS
12201 * 27 - per-cpu [ offset to per-cpu data area ]
12202 * 28 - stack_canary-20 [ for stack protector ]
12203 - * 29 - unused
12204 - * 30 - unused
12205 + * 29 - PCI BIOS CS
12206 + * 30 - PCI BIOS DS
12207 * 31 - TSS for double fault handler
12208 */
12209 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
12210 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
12211 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
12212 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
12213 +
12214 #define GDT_ENTRY_TLS_MIN 6
12215 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
12216
12217 @@ -79,6 +84,8 @@
12218
12219 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
12220
12221 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
12222 +
12223 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
12224
12225 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
12226 @@ -104,6 +111,12 @@
12227 #define __KERNEL_STACK_CANARY 0
12228 #endif
12229
12230 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
12231 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
12232 +
12233 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
12234 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
12235 +
12236 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
12237
12238 /*
12239 @@ -141,7 +154,7 @@
12240 */
12241
12242 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
12243 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
12244 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
12245
12246
12247 #else
12248 @@ -165,6 +178,8 @@
12249 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
12250 #define __USER32_DS __USER_DS
12251
12252 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
12253 +
12254 #define GDT_ENTRY_TSS 8 /* needs two entries */
12255 #define GDT_ENTRY_LDT 10 /* needs two entries */
12256 #define GDT_ENTRY_TLS_MIN 12
12257 @@ -185,6 +200,7 @@
12258 #endif
12259
12260 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
12261 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
12262 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
12263 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
12264 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
12265 @@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
12266 {
12267 unsigned long __limit;
12268 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
12269 - return __limit + 1;
12270 + return __limit;
12271 }
12272
12273 #endif /* !__ASSEMBLY__ */
12274 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
12275 index 4f19a15..9e14f27 100644
12276 --- a/arch/x86/include/asm/smp.h
12277 +++ b/arch/x86/include/asm/smp.h
12278 @@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
12279 /* cpus sharing the last level cache: */
12280 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
12281 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
12282 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
12283 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
12284
12285 static inline struct cpumask *cpu_sibling_mask(int cpu)
12286 {
12287 @@ -79,7 +79,7 @@ struct smp_ops {
12288
12289 void (*send_call_func_ipi)(const struct cpumask *mask);
12290 void (*send_call_func_single_ipi)(int cpu);
12291 -};
12292 +} __no_const;
12293
12294 /* Globals due to paravirt */
12295 extern void set_cpu_sibling_map(int cpu);
12296 @@ -190,14 +190,8 @@ extern unsigned disabled_cpus __cpuinitdata;
12297 extern int safe_smp_processor_id(void);
12298
12299 #elif defined(CONFIG_X86_64_SMP)
12300 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12301 -
12302 -#define stack_smp_processor_id() \
12303 -({ \
12304 - struct thread_info *ti; \
12305 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
12306 - ti->cpu; \
12307 -})
12308 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12309 +#define stack_smp_processor_id() raw_smp_processor_id()
12310 #define safe_smp_processor_id() smp_processor_id()
12311
12312 #endif
12313 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
12314 index 33692ea..350a534 100644
12315 --- a/arch/x86/include/asm/spinlock.h
12316 +++ b/arch/x86/include/asm/spinlock.h
12317 @@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
12318 static inline void arch_read_lock(arch_rwlock_t *rw)
12319 {
12320 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
12321 +
12322 +#ifdef CONFIG_PAX_REFCOUNT
12323 + "jno 0f\n"
12324 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
12325 + "int $4\n0:\n"
12326 + _ASM_EXTABLE(0b, 0b)
12327 +#endif
12328 +
12329 "jns 1f\n"
12330 "call __read_lock_failed\n\t"
12331 "1:\n"
12332 @@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
12333 static inline void arch_write_lock(arch_rwlock_t *rw)
12334 {
12335 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
12336 +
12337 +#ifdef CONFIG_PAX_REFCOUNT
12338 + "jno 0f\n"
12339 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
12340 + "int $4\n0:\n"
12341 + _ASM_EXTABLE(0b, 0b)
12342 +#endif
12343 +
12344 "jz 1f\n"
12345 "call __write_lock_failed\n\t"
12346 "1:\n"
12347 @@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
12348
12349 static inline void arch_read_unlock(arch_rwlock_t *rw)
12350 {
12351 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
12352 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
12353 +
12354 +#ifdef CONFIG_PAX_REFCOUNT
12355 + "jno 0f\n"
12356 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
12357 + "int $4\n0:\n"
12358 + _ASM_EXTABLE(0b, 0b)
12359 +#endif
12360 +
12361 :"+m" (rw->lock) : : "memory");
12362 }
12363
12364 static inline void arch_write_unlock(arch_rwlock_t *rw)
12365 {
12366 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
12367 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
12368 +
12369 +#ifdef CONFIG_PAX_REFCOUNT
12370 + "jno 0f\n"
12371 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
12372 + "int $4\n0:\n"
12373 + _ASM_EXTABLE(0b, 0b)
12374 +#endif
12375 +
12376 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
12377 }
12378
12379 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
12380 index 6a99859..03cb807 100644
12381 --- a/arch/x86/include/asm/stackprotector.h
12382 +++ b/arch/x86/include/asm/stackprotector.h
12383 @@ -47,7 +47,7 @@
12384 * head_32 for boot CPU and setup_per_cpu_areas() for others.
12385 */
12386 #define GDT_STACK_CANARY_INIT \
12387 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
12388 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
12389
12390 /*
12391 * Initialize the stackprotector canary value.
12392 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
12393
12394 static inline void load_stack_canary_segment(void)
12395 {
12396 -#ifdef CONFIG_X86_32
12397 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
12398 asm volatile ("mov %0, %%gs" : : "r" (0));
12399 #endif
12400 }
12401 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
12402 index 70bbe39..4ae2bd4 100644
12403 --- a/arch/x86/include/asm/stacktrace.h
12404 +++ b/arch/x86/include/asm/stacktrace.h
12405 @@ -11,28 +11,20 @@
12406
12407 extern int kstack_depth_to_print;
12408
12409 -struct thread_info;
12410 +struct task_struct;
12411 struct stacktrace_ops;
12412
12413 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
12414 - unsigned long *stack,
12415 - unsigned long bp,
12416 - const struct stacktrace_ops *ops,
12417 - void *data,
12418 - unsigned long *end,
12419 - int *graph);
12420 +typedef unsigned long walk_stack_t(struct task_struct *task,
12421 + void *stack_start,
12422 + unsigned long *stack,
12423 + unsigned long bp,
12424 + const struct stacktrace_ops *ops,
12425 + void *data,
12426 + unsigned long *end,
12427 + int *graph);
12428
12429 -extern unsigned long
12430 -print_context_stack(struct thread_info *tinfo,
12431 - unsigned long *stack, unsigned long bp,
12432 - const struct stacktrace_ops *ops, void *data,
12433 - unsigned long *end, int *graph);
12434 -
12435 -extern unsigned long
12436 -print_context_stack_bp(struct thread_info *tinfo,
12437 - unsigned long *stack, unsigned long bp,
12438 - const struct stacktrace_ops *ops, void *data,
12439 - unsigned long *end, int *graph);
12440 +extern walk_stack_t print_context_stack;
12441 +extern walk_stack_t print_context_stack_bp;
12442
12443 /* Generic stack tracer with callbacks */
12444
12445 @@ -40,7 +32,7 @@ struct stacktrace_ops {
12446 void (*address)(void *data, unsigned long address, int reliable);
12447 /* On negative return stop dumping */
12448 int (*stack)(void *data, char *name);
12449 - walk_stack_t walk_stack;
12450 + walk_stack_t *walk_stack;
12451 };
12452
12453 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
12454 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
12455 index 4ec45b3..a4f0a8a 100644
12456 --- a/arch/x86/include/asm/switch_to.h
12457 +++ b/arch/x86/include/asm/switch_to.h
12458 @@ -108,7 +108,7 @@ do { \
12459 "call __switch_to\n\t" \
12460 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
12461 __switch_canary \
12462 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
12463 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
12464 "movq %%rax,%%rdi\n\t" \
12465 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
12466 "jnz ret_from_fork\n\t" \
12467 @@ -119,7 +119,7 @@ do { \
12468 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
12469 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
12470 [_tif_fork] "i" (_TIF_FORK), \
12471 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
12472 + [thread_info] "m" (current_tinfo), \
12473 [current_task] "m" (current_task) \
12474 __switch_canary_iparam \
12475 : "memory", "cc" __EXTRA_CLOBBER)
12476 diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
12477 index 3fda9db4..4ca1c61 100644
12478 --- a/arch/x86/include/asm/sys_ia32.h
12479 +++ b/arch/x86/include/asm/sys_ia32.h
12480 @@ -40,7 +40,7 @@ asmlinkage long sys32_sigaction(int, struct old_sigaction32 __user *,
12481 struct old_sigaction32 __user *);
12482 asmlinkage long sys32_alarm(unsigned int);
12483
12484 -asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
12485 +asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
12486 asmlinkage long sys32_sysfs(int, u32, u32);
12487
12488 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
12489 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
12490 index 89f794f..1422765 100644
12491 --- a/arch/x86/include/asm/thread_info.h
12492 +++ b/arch/x86/include/asm/thread_info.h
12493 @@ -10,6 +10,7 @@
12494 #include <linux/compiler.h>
12495 #include <asm/page.h>
12496 #include <asm/types.h>
12497 +#include <asm/percpu.h>
12498
12499 /*
12500 * low level task data that entry.S needs immediate access to
12501 @@ -24,7 +25,6 @@ struct exec_domain;
12502 #include <linux/atomic.h>
12503
12504 struct thread_info {
12505 - struct task_struct *task; /* main task structure */
12506 struct exec_domain *exec_domain; /* execution domain */
12507 __u32 flags; /* low level flags */
12508 __u32 status; /* thread synchronous flags */
12509 @@ -34,19 +34,13 @@ struct thread_info {
12510 mm_segment_t addr_limit;
12511 struct restart_block restart_block;
12512 void __user *sysenter_return;
12513 -#ifdef CONFIG_X86_32
12514 - unsigned long previous_esp; /* ESP of the previous stack in
12515 - case of nested (IRQ) stacks
12516 - */
12517 - __u8 supervisor_stack[0];
12518 -#endif
12519 + unsigned long lowest_stack;
12520 unsigned int sig_on_uaccess_error:1;
12521 unsigned int uaccess_err:1; /* uaccess failed */
12522 };
12523
12524 -#define INIT_THREAD_INFO(tsk) \
12525 +#define INIT_THREAD_INFO \
12526 { \
12527 - .task = &tsk, \
12528 .exec_domain = &default_exec_domain, \
12529 .flags = 0, \
12530 .cpu = 0, \
12531 @@ -57,7 +51,7 @@ struct thread_info {
12532 }, \
12533 }
12534
12535 -#define init_thread_info (init_thread_union.thread_info)
12536 +#define init_thread_info (init_thread_union.stack)
12537 #define init_stack (init_thread_union.stack)
12538
12539 #else /* !__ASSEMBLY__ */
12540 @@ -98,6 +92,7 @@ struct thread_info {
12541 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
12542 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
12543 #define TIF_X32 30 /* 32-bit native x86-64 binary */
12544 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
12545
12546 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
12547 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
12548 @@ -122,16 +117,18 @@ struct thread_info {
12549 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
12550 #define _TIF_ADDR32 (1 << TIF_ADDR32)
12551 #define _TIF_X32 (1 << TIF_X32)
12552 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
12553
12554 /* work to do in syscall_trace_enter() */
12555 #define _TIF_WORK_SYSCALL_ENTRY \
12556 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
12557 - _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT)
12558 + _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
12559 + _TIF_GRSEC_SETXID)
12560
12561 /* work to do in syscall_trace_leave() */
12562 #define _TIF_WORK_SYSCALL_EXIT \
12563 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
12564 - _TIF_SYSCALL_TRACEPOINT)
12565 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
12566
12567 /* work to do on interrupt/exception return */
12568 #define _TIF_WORK_MASK \
12569 @@ -141,7 +138,8 @@ struct thread_info {
12570
12571 /* work to do on any return to user space */
12572 #define _TIF_ALLWORK_MASK \
12573 - ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT)
12574 + ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
12575 + _TIF_GRSEC_SETXID)
12576
12577 /* Only used for 64 bit */
12578 #define _TIF_DO_NOTIFY_MASK \
12579 @@ -157,45 +155,40 @@ struct thread_info {
12580
12581 #define PREEMPT_ACTIVE 0x10000000
12582
12583 -#ifdef CONFIG_X86_32
12584 -
12585 -#define STACK_WARN (THREAD_SIZE/8)
12586 -/*
12587 - * macros/functions for gaining access to the thread information structure
12588 - *
12589 - * preempt_count needs to be 1 initially, until the scheduler is functional.
12590 - */
12591 -#ifndef __ASSEMBLY__
12592 -
12593 -
12594 -/* how to get the current stack pointer from C */
12595 -register unsigned long current_stack_pointer asm("esp") __used;
12596 -
12597 -/* how to get the thread information struct from C */
12598 -static inline struct thread_info *current_thread_info(void)
12599 -{
12600 - return (struct thread_info *)
12601 - (current_stack_pointer & ~(THREAD_SIZE - 1));
12602 -}
12603 -
12604 -#else /* !__ASSEMBLY__ */
12605 -
12606 +#ifdef __ASSEMBLY__
12607 /* how to get the thread information struct from ASM */
12608 #define GET_THREAD_INFO(reg) \
12609 - movl $-THREAD_SIZE, reg; \
12610 - andl %esp, reg
12611 + mov PER_CPU_VAR(current_tinfo), reg
12612
12613 /* use this one if reg already contains %esp */
12614 -#define GET_THREAD_INFO_WITH_ESP(reg) \
12615 - andl $-THREAD_SIZE, reg
12616 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12617 +#else
12618 +/* how to get the thread information struct from C */
12619 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12620 +
12621 +static __always_inline struct thread_info *current_thread_info(void)
12622 +{
12623 + return this_cpu_read_stable(current_tinfo);
12624 +}
12625 +#endif
12626 +
12627 +#ifdef CONFIG_X86_32
12628 +
12629 +#define STACK_WARN (THREAD_SIZE/8)
12630 +/*
12631 + * macros/functions for gaining access to the thread information structure
12632 + *
12633 + * preempt_count needs to be 1 initially, until the scheduler is functional.
12634 + */
12635 +#ifndef __ASSEMBLY__
12636 +
12637 +/* how to get the current stack pointer from C */
12638 +register unsigned long current_stack_pointer asm("esp") __used;
12639
12640 #endif
12641
12642 #else /* X86_32 */
12643
12644 -#include <asm/percpu.h>
12645 -#define KERNEL_STACK_OFFSET (5*8)
12646 -
12647 /*
12648 * macros/functions for gaining access to the thread information structure
12649 * preempt_count needs to be 1 initially, until the scheduler is functional.
12650 @@ -203,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
12651 #ifndef __ASSEMBLY__
12652 DECLARE_PER_CPU(unsigned long, kernel_stack);
12653
12654 -static inline struct thread_info *current_thread_info(void)
12655 -{
12656 - struct thread_info *ti;
12657 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
12658 - KERNEL_STACK_OFFSET - THREAD_SIZE);
12659 - return ti;
12660 -}
12661 -
12662 -#else /* !__ASSEMBLY__ */
12663 -
12664 -/* how to get the thread information struct from ASM */
12665 -#define GET_THREAD_INFO(reg) \
12666 - movq PER_CPU_VAR(kernel_stack),reg ; \
12667 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12668 -
12669 -/*
12670 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
12671 - * a certain register (to be used in assembler memory operands).
12672 - */
12673 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
12674 -
12675 +/* how to get the current stack pointer from C */
12676 +register unsigned long current_stack_pointer asm("rsp") __used;
12677 #endif
12678
12679 #endif /* !X86_32 */
12680 @@ -284,5 +258,12 @@ static inline bool is_ia32_task(void)
12681 extern void arch_task_cache_init(void);
12682 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12683 extern void arch_release_task_struct(struct task_struct *tsk);
12684 +
12685 +#define __HAVE_THREAD_FUNCTIONS
12686 +#define task_thread_info(task) (&(task)->tinfo)
12687 +#define task_stack_page(task) ((task)->stack)
12688 +#define setup_thread_stack(p, org) do {} while (0)
12689 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12690 +
12691 #endif
12692 #endif /* _ASM_X86_THREAD_INFO_H */
12693 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12694 index e1f3a17..1ab364d 100644
12695 --- a/arch/x86/include/asm/uaccess.h
12696 +++ b/arch/x86/include/asm/uaccess.h
12697 @@ -7,12 +7,15 @@
12698 #include <linux/compiler.h>
12699 #include <linux/thread_info.h>
12700 #include <linux/string.h>
12701 +#include <linux/sched.h>
12702 #include <asm/asm.h>
12703 #include <asm/page.h>
12704
12705 #define VERIFY_READ 0
12706 #define VERIFY_WRITE 1
12707
12708 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
12709 +
12710 /*
12711 * The fs value determines whether argument validity checking should be
12712 * performed or not. If get_fs() == USER_DS, checking is performed, with
12713 @@ -28,7 +31,12 @@
12714
12715 #define get_ds() (KERNEL_DS)
12716 #define get_fs() (current_thread_info()->addr_limit)
12717 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12718 +void __set_fs(mm_segment_t x);
12719 +void set_fs(mm_segment_t x);
12720 +#else
12721 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12722 +#endif
12723
12724 #define segment_eq(a, b) ((a).seg == (b).seg)
12725
12726 @@ -76,8 +84,33 @@
12727 * checks that the pointer is in the user space range - after calling
12728 * this function, memory access functions may still return -EFAULT.
12729 */
12730 -#define access_ok(type, addr, size) \
12731 - (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12732 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12733 +#define access_ok(type, addr, size) \
12734 +({ \
12735 + long __size = size; \
12736 + unsigned long __addr = (unsigned long)addr; \
12737 + unsigned long __addr_ao = __addr & PAGE_MASK; \
12738 + unsigned long __end_ao = __addr + __size - 1; \
12739 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
12740 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12741 + while(__addr_ao <= __end_ao) { \
12742 + char __c_ao; \
12743 + __addr_ao += PAGE_SIZE; \
12744 + if (__size > PAGE_SIZE) \
12745 + cond_resched(); \
12746 + if (__get_user(__c_ao, (char __user *)__addr)) \
12747 + break; \
12748 + if (type != VERIFY_WRITE) { \
12749 + __addr = __addr_ao; \
12750 + continue; \
12751 + } \
12752 + if (__put_user(__c_ao, (char __user *)__addr)) \
12753 + break; \
12754 + __addr = __addr_ao; \
12755 + } \
12756 + } \
12757 + __ret_ao; \
12758 +})
12759
12760 /*
12761 * The exception table consists of pairs of addresses relative to the
12762 @@ -188,12 +221,20 @@ extern int __get_user_bad(void);
12763 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12764 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12765
12766 -
12767 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12768 +#define __copyuser_seg "gs;"
12769 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12770 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12771 +#else
12772 +#define __copyuser_seg
12773 +#define __COPYUSER_SET_ES
12774 +#define __COPYUSER_RESTORE_ES
12775 +#endif
12776
12777 #ifdef CONFIG_X86_32
12778 #define __put_user_asm_u64(x, addr, err, errret) \
12779 - asm volatile("1: movl %%eax,0(%2)\n" \
12780 - "2: movl %%edx,4(%2)\n" \
12781 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12782 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12783 "3:\n" \
12784 ".section .fixup,\"ax\"\n" \
12785 "4: movl %3,%0\n" \
12786 @@ -205,8 +246,8 @@ extern int __get_user_bad(void);
12787 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12788
12789 #define __put_user_asm_ex_u64(x, addr) \
12790 - asm volatile("1: movl %%eax,0(%1)\n" \
12791 - "2: movl %%edx,4(%1)\n" \
12792 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12793 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12794 "3:\n" \
12795 _ASM_EXTABLE_EX(1b, 2b) \
12796 _ASM_EXTABLE_EX(2b, 3b) \
12797 @@ -258,7 +299,7 @@ extern void __put_user_8(void);
12798 __typeof__(*(ptr)) __pu_val; \
12799 __chk_user_ptr(ptr); \
12800 might_fault(); \
12801 - __pu_val = x; \
12802 + __pu_val = (x); \
12803 switch (sizeof(*(ptr))) { \
12804 case 1: \
12805 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12806 @@ -379,7 +420,7 @@ do { \
12807 } while (0)
12808
12809 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12810 - asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12811 + asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12812 "2:\n" \
12813 ".section .fixup,\"ax\"\n" \
12814 "3: mov %3,%0\n" \
12815 @@ -387,7 +428,7 @@ do { \
12816 " jmp 2b\n" \
12817 ".previous\n" \
12818 _ASM_EXTABLE(1b, 3b) \
12819 - : "=r" (err), ltype(x) \
12820 + : "=r" (err), ltype (x) \
12821 : "m" (__m(addr)), "i" (errret), "0" (err))
12822
12823 #define __get_user_size_ex(x, ptr, size) \
12824 @@ -412,7 +453,7 @@ do { \
12825 } while (0)
12826
12827 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12828 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12829 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12830 "2:\n" \
12831 _ASM_EXTABLE_EX(1b, 2b) \
12832 : ltype(x) : "m" (__m(addr)))
12833 @@ -429,13 +470,24 @@ do { \
12834 int __gu_err; \
12835 unsigned long __gu_val; \
12836 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12837 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
12838 + (x) = (__typeof__(*(ptr)))__gu_val; \
12839 __gu_err; \
12840 })
12841
12842 /* FIXME: this hack is definitely wrong -AK */
12843 struct __large_struct { unsigned long buf[100]; };
12844 -#define __m(x) (*(struct __large_struct __user *)(x))
12845 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12846 +#define ____m(x) \
12847 +({ \
12848 + unsigned long ____x = (unsigned long)(x); \
12849 + if (____x < PAX_USER_SHADOW_BASE) \
12850 + ____x += PAX_USER_SHADOW_BASE; \
12851 + (void __user *)____x; \
12852 +})
12853 +#else
12854 +#define ____m(x) (x)
12855 +#endif
12856 +#define __m(x) (*(struct __large_struct __user *)____m(x))
12857
12858 /*
12859 * Tell gcc we read from memory instead of writing: this is because
12860 @@ -443,7 +495,7 @@ struct __large_struct { unsigned long buf[100]; };
12861 * aliasing issues.
12862 */
12863 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12864 - asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12865 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12866 "2:\n" \
12867 ".section .fixup,\"ax\"\n" \
12868 "3: mov %3,%0\n" \
12869 @@ -451,10 +503,10 @@ struct __large_struct { unsigned long buf[100]; };
12870 ".previous\n" \
12871 _ASM_EXTABLE(1b, 3b) \
12872 : "=r"(err) \
12873 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12874 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12875
12876 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12877 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12878 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12879 "2:\n" \
12880 _ASM_EXTABLE_EX(1b, 2b) \
12881 : : ltype(x), "m" (__m(addr)))
12882 @@ -493,8 +545,12 @@ struct __large_struct { unsigned long buf[100]; };
12883 * On error, the variable @x is set to zero.
12884 */
12885
12886 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12887 +#define __get_user(x, ptr) get_user((x), (ptr))
12888 +#else
12889 #define __get_user(x, ptr) \
12890 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12891 +#endif
12892
12893 /**
12894 * __put_user: - Write a simple value into user space, with less checking.
12895 @@ -516,8 +572,12 @@ struct __large_struct { unsigned long buf[100]; };
12896 * Returns zero on success, or -EFAULT on error.
12897 */
12898
12899 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12900 +#define __put_user(x, ptr) put_user((x), (ptr))
12901 +#else
12902 #define __put_user(x, ptr) \
12903 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12904 +#endif
12905
12906 #define __get_user_unaligned __get_user
12907 #define __put_user_unaligned __put_user
12908 @@ -535,7 +595,7 @@ struct __large_struct { unsigned long buf[100]; };
12909 #define get_user_ex(x, ptr) do { \
12910 unsigned long __gue_val; \
12911 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12912 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
12913 + (x) = (__typeof__(*(ptr)))__gue_val; \
12914 } while (0)
12915
12916 #ifdef CONFIG_X86_WP_WORKS_OK
12917 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12918 index 576e39b..ccd0a39 100644
12919 --- a/arch/x86/include/asm/uaccess_32.h
12920 +++ b/arch/x86/include/asm/uaccess_32.h
12921 @@ -11,15 +11,15 @@
12922 #include <asm/page.h>
12923
12924 unsigned long __must_check __copy_to_user_ll
12925 - (void __user *to, const void *from, unsigned long n);
12926 + (void __user *to, const void *from, unsigned long n) __size_overflow(3);
12927 unsigned long __must_check __copy_from_user_ll
12928 - (void *to, const void __user *from, unsigned long n);
12929 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12930 unsigned long __must_check __copy_from_user_ll_nozero
12931 - (void *to, const void __user *from, unsigned long n);
12932 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12933 unsigned long __must_check __copy_from_user_ll_nocache
12934 - (void *to, const void __user *from, unsigned long n);
12935 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12936 unsigned long __must_check __copy_from_user_ll_nocache_nozero
12937 - (void *to, const void __user *from, unsigned long n);
12938 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12939
12940 /**
12941 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
12942 @@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
12943 static __always_inline unsigned long __must_check
12944 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12945 {
12946 + if ((long)n < 0)
12947 + return n;
12948 +
12949 if (__builtin_constant_p(n)) {
12950 unsigned long ret;
12951
12952 @@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12953 return ret;
12954 }
12955 }
12956 + if (!__builtin_constant_p(n))
12957 + check_object_size(from, n, true);
12958 return __copy_to_user_ll(to, from, n);
12959 }
12960
12961 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
12962 __copy_to_user(void __user *to, const void *from, unsigned long n)
12963 {
12964 might_fault();
12965 +
12966 return __copy_to_user_inatomic(to, from, n);
12967 }
12968
12969 static __always_inline unsigned long
12970 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12971 {
12972 + if ((long)n < 0)
12973 + return n;
12974 +
12975 /* Avoid zeroing the tail if the copy fails..
12976 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
12977 * but as the zeroing behaviour is only significant when n is not
12978 @@ -137,6 +146,10 @@ static __always_inline unsigned long
12979 __copy_from_user(void *to, const void __user *from, unsigned long n)
12980 {
12981 might_fault();
12982 +
12983 + if ((long)n < 0)
12984 + return n;
12985 +
12986 if (__builtin_constant_p(n)) {
12987 unsigned long ret;
12988
12989 @@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
12990 return ret;
12991 }
12992 }
12993 + if (!__builtin_constant_p(n))
12994 + check_object_size(to, n, false);
12995 return __copy_from_user_ll(to, from, n);
12996 }
12997
12998 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
12999 const void __user *from, unsigned long n)
13000 {
13001 might_fault();
13002 +
13003 + if ((long)n < 0)
13004 + return n;
13005 +
13006 if (__builtin_constant_p(n)) {
13007 unsigned long ret;
13008
13009 @@ -181,15 +200,19 @@ static __always_inline unsigned long
13010 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
13011 unsigned long n)
13012 {
13013 - return __copy_from_user_ll_nocache_nozero(to, from, n);
13014 + if ((long)n < 0)
13015 + return n;
13016 +
13017 + return __copy_from_user_ll_nocache_nozero(to, from, n);
13018 }
13019
13020 -unsigned long __must_check copy_to_user(void __user *to,
13021 - const void *from, unsigned long n);
13022 -unsigned long __must_check _copy_from_user(void *to,
13023 - const void __user *from,
13024 - unsigned long n);
13025 -
13026 +extern void copy_to_user_overflow(void)
13027 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13028 + __compiletime_error("copy_to_user() buffer size is not provably correct")
13029 +#else
13030 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
13031 +#endif
13032 +;
13033
13034 extern void copy_from_user_overflow(void)
13035 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13036 @@ -199,21 +222,65 @@ extern void copy_from_user_overflow(void)
13037 #endif
13038 ;
13039
13040 -static inline unsigned long __must_check copy_from_user(void *to,
13041 - const void __user *from,
13042 - unsigned long n)
13043 +/**
13044 + * copy_to_user: - Copy a block of data into user space.
13045 + * @to: Destination address, in user space.
13046 + * @from: Source address, in kernel space.
13047 + * @n: Number of bytes to copy.
13048 + *
13049 + * Context: User context only. This function may sleep.
13050 + *
13051 + * Copy data from kernel space to user space.
13052 + *
13053 + * Returns number of bytes that could not be copied.
13054 + * On success, this will be zero.
13055 + */
13056 +static inline unsigned long __must_check
13057 +copy_to_user(void __user *to, const void *from, unsigned long n)
13058 {
13059 - int sz = __compiletime_object_size(to);
13060 + size_t sz = __compiletime_object_size(from);
13061
13062 - if (likely(sz == -1 || sz >= n))
13063 - n = _copy_from_user(to, from, n);
13064 - else
13065 + if (unlikely(sz != (size_t)-1 && sz < n))
13066 + copy_to_user_overflow();
13067 + else if (access_ok(VERIFY_WRITE, to, n))
13068 + n = __copy_to_user(to, from, n);
13069 + return n;
13070 +}
13071 +
13072 +/**
13073 + * copy_from_user: - Copy a block of data from user space.
13074 + * @to: Destination address, in kernel space.
13075 + * @from: Source address, in user space.
13076 + * @n: Number of bytes to copy.
13077 + *
13078 + * Context: User context only. This function may sleep.
13079 + *
13080 + * Copy data from user space to kernel space.
13081 + *
13082 + * Returns number of bytes that could not be copied.
13083 + * On success, this will be zero.
13084 + *
13085 + * If some data could not be copied, this function will pad the copied
13086 + * data to the requested size using zero bytes.
13087 + */
13088 +static inline unsigned long __must_check
13089 +copy_from_user(void *to, const void __user *from, unsigned long n)
13090 +{
13091 + size_t sz = __compiletime_object_size(to);
13092 +
13093 + if (unlikely(sz != (size_t)-1 && sz < n))
13094 copy_from_user_overflow();
13095 -
13096 + else if (access_ok(VERIFY_READ, from, n))
13097 + n = __copy_from_user(to, from, n);
13098 + else if ((long)n > 0) {
13099 + if (!__builtin_constant_p(n))
13100 + check_object_size(to, n, false);
13101 + memset(to, 0, n);
13102 + }
13103 return n;
13104 }
13105
13106 -unsigned long __must_check clear_user(void __user *mem, unsigned long len);
13107 -unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
13108 +unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13109 +unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13110
13111 #endif /* _ASM_X86_UACCESS_32_H */
13112 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
13113 index d8def8b..ac7fc15 100644
13114 --- a/arch/x86/include/asm/uaccess_64.h
13115 +++ b/arch/x86/include/asm/uaccess_64.h
13116 @@ -10,6 +10,9 @@
13117 #include <asm/alternative.h>
13118 #include <asm/cpufeature.h>
13119 #include <asm/page.h>
13120 +#include <asm/pgtable.h>
13121 +
13122 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
13123
13124 /*
13125 * Copy To/From Userspace
13126 @@ -17,13 +20,13 @@
13127
13128 /* Handles exceptions in both to and from, but doesn't do access_ok */
13129 __must_check unsigned long
13130 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
13131 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
13132 __must_check unsigned long
13133 -copy_user_generic_string(void *to, const void *from, unsigned len);
13134 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
13135 __must_check unsigned long
13136 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
13137 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
13138
13139 -static __always_inline __must_check unsigned long
13140 +static __always_inline __must_check __size_overflow(3) unsigned long
13141 copy_user_generic(void *to, const void *from, unsigned len)
13142 {
13143 unsigned ret;
13144 @@ -41,142 +44,238 @@ copy_user_generic(void *to, const void *from, unsigned len)
13145 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
13146 "=d" (len)),
13147 "1" (to), "2" (from), "3" (len)
13148 - : "memory", "rcx", "r8", "r9", "r10", "r11");
13149 + : "memory", "rcx", "r8", "r9", "r11");
13150 return ret;
13151 }
13152
13153 +static __always_inline __must_check unsigned long
13154 +__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
13155 +static __always_inline __must_check unsigned long
13156 +__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
13157 __must_check unsigned long
13158 -_copy_to_user(void __user *to, const void *from, unsigned len);
13159 -__must_check unsigned long
13160 -_copy_from_user(void *to, const void __user *from, unsigned len);
13161 -__must_check unsigned long
13162 -copy_in_user(void __user *to, const void __user *from, unsigned len);
13163 +copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
13164 +
13165 +extern void copy_to_user_overflow(void)
13166 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13167 + __compiletime_error("copy_to_user() buffer size is not provably correct")
13168 +#else
13169 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
13170 +#endif
13171 +;
13172 +
13173 +extern void copy_from_user_overflow(void)
13174 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13175 + __compiletime_error("copy_from_user() buffer size is not provably correct")
13176 +#else
13177 + __compiletime_warning("copy_from_user() buffer size is not provably correct")
13178 +#endif
13179 +;
13180
13181 static inline unsigned long __must_check copy_from_user(void *to,
13182 const void __user *from,
13183 unsigned long n)
13184 {
13185 - int sz = __compiletime_object_size(to);
13186 -
13187 might_fault();
13188 - if (likely(sz == -1 || sz >= n))
13189 - n = _copy_from_user(to, from, n);
13190 -#ifdef CONFIG_DEBUG_VM
13191 - else
13192 - WARN(1, "Buffer overflow detected!\n");
13193 -#endif
13194 +
13195 + if (access_ok(VERIFY_READ, from, n))
13196 + n = __copy_from_user(to, from, n);
13197 + else if (n < INT_MAX) {
13198 + if (!__builtin_constant_p(n))
13199 + check_object_size(to, n, false);
13200 + memset(to, 0, n);
13201 + }
13202 return n;
13203 }
13204
13205 static __always_inline __must_check
13206 -int copy_to_user(void __user *dst, const void *src, unsigned size)
13207 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
13208 {
13209 might_fault();
13210
13211 - return _copy_to_user(dst, src, size);
13212 + if (access_ok(VERIFY_WRITE, dst, size))
13213 + size = __copy_to_user(dst, src, size);
13214 + return size;
13215 }
13216
13217 static __always_inline __must_check
13218 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
13219 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
13220 {
13221 - int ret = 0;
13222 + size_t sz = __compiletime_object_size(dst);
13223 + unsigned ret = 0;
13224
13225 might_fault();
13226 - if (!__builtin_constant_p(size))
13227 - return copy_user_generic(dst, (__force void *)src, size);
13228 +
13229 + if (size > INT_MAX)
13230 + return size;
13231 +
13232 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13233 + if (!__access_ok(VERIFY_READ, src, size))
13234 + return size;
13235 +#endif
13236 +
13237 + if (unlikely(sz != (size_t)-1 && sz < size)) {
13238 + copy_from_user_overflow();
13239 + return size;
13240 + }
13241 +
13242 + if (!__builtin_constant_p(size)) {
13243 + check_object_size(dst, size, false);
13244 +
13245 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13246 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13247 + src += PAX_USER_SHADOW_BASE;
13248 +#endif
13249 +
13250 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13251 + }
13252 switch (size) {
13253 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
13254 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
13255 ret, "b", "b", "=q", 1);
13256 return ret;
13257 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
13258 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
13259 ret, "w", "w", "=r", 2);
13260 return ret;
13261 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
13262 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
13263 ret, "l", "k", "=r", 4);
13264 return ret;
13265 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
13266 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13267 ret, "q", "", "=r", 8);
13268 return ret;
13269 case 10:
13270 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13271 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13272 ret, "q", "", "=r", 10);
13273 if (unlikely(ret))
13274 return ret;
13275 __get_user_asm(*(u16 *)(8 + (char *)dst),
13276 - (u16 __user *)(8 + (char __user *)src),
13277 + (const u16 __user *)(8 + (const char __user *)src),
13278 ret, "w", "w", "=r", 2);
13279 return ret;
13280 case 16:
13281 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13282 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13283 ret, "q", "", "=r", 16);
13284 if (unlikely(ret))
13285 return ret;
13286 __get_user_asm(*(u64 *)(8 + (char *)dst),
13287 - (u64 __user *)(8 + (char __user *)src),
13288 + (const u64 __user *)(8 + (const char __user *)src),
13289 ret, "q", "", "=r", 8);
13290 return ret;
13291 default:
13292 - return copy_user_generic(dst, (__force void *)src, size);
13293 +
13294 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13295 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13296 + src += PAX_USER_SHADOW_BASE;
13297 +#endif
13298 +
13299 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13300 }
13301 }
13302
13303 static __always_inline __must_check
13304 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
13305 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
13306 {
13307 - int ret = 0;
13308 + size_t sz = __compiletime_object_size(src);
13309 + unsigned ret = 0;
13310
13311 might_fault();
13312 - if (!__builtin_constant_p(size))
13313 - return copy_user_generic((__force void *)dst, src, size);
13314 +
13315 + if (size > INT_MAX)
13316 + return size;
13317 +
13318 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13319 + if (!__access_ok(VERIFY_WRITE, dst, size))
13320 + return size;
13321 +#endif
13322 +
13323 + if (unlikely(sz != (size_t)-1 && sz < size)) {
13324 + copy_to_user_overflow();
13325 + return size;
13326 + }
13327 +
13328 + if (!__builtin_constant_p(size)) {
13329 + check_object_size(src, size, true);
13330 +
13331 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13332 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13333 + dst += PAX_USER_SHADOW_BASE;
13334 +#endif
13335 +
13336 + return copy_user_generic((__force_kernel void *)dst, src, size);
13337 + }
13338 switch (size) {
13339 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
13340 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
13341 ret, "b", "b", "iq", 1);
13342 return ret;
13343 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
13344 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
13345 ret, "w", "w", "ir", 2);
13346 return ret;
13347 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
13348 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
13349 ret, "l", "k", "ir", 4);
13350 return ret;
13351 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
13352 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13353 ret, "q", "", "er", 8);
13354 return ret;
13355 case 10:
13356 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13357 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13358 ret, "q", "", "er", 10);
13359 if (unlikely(ret))
13360 return ret;
13361 asm("":::"memory");
13362 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
13363 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
13364 ret, "w", "w", "ir", 2);
13365 return ret;
13366 case 16:
13367 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13368 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13369 ret, "q", "", "er", 16);
13370 if (unlikely(ret))
13371 return ret;
13372 asm("":::"memory");
13373 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
13374 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
13375 ret, "q", "", "er", 8);
13376 return ret;
13377 default:
13378 - return copy_user_generic((__force void *)dst, src, size);
13379 +
13380 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13381 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13382 + dst += PAX_USER_SHADOW_BASE;
13383 +#endif
13384 +
13385 + return copy_user_generic((__force_kernel void *)dst, src, size);
13386 }
13387 }
13388
13389 static __always_inline __must_check
13390 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13391 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
13392 {
13393 - int ret = 0;
13394 + unsigned ret = 0;
13395
13396 might_fault();
13397 - if (!__builtin_constant_p(size))
13398 - return copy_user_generic((__force void *)dst,
13399 - (__force void *)src, size);
13400 +
13401 + if (size > INT_MAX)
13402 + return size;
13403 +
13404 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13405 + if (!__access_ok(VERIFY_READ, src, size))
13406 + return size;
13407 + if (!__access_ok(VERIFY_WRITE, dst, size))
13408 + return size;
13409 +#endif
13410 +
13411 + if (!__builtin_constant_p(size)) {
13412 +
13413 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13414 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13415 + src += PAX_USER_SHADOW_BASE;
13416 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13417 + dst += PAX_USER_SHADOW_BASE;
13418 +#endif
13419 +
13420 + return copy_user_generic((__force_kernel void *)dst,
13421 + (__force_kernel const void *)src, size);
13422 + }
13423 switch (size) {
13424 case 1: {
13425 u8 tmp;
13426 - __get_user_asm(tmp, (u8 __user *)src,
13427 + __get_user_asm(tmp, (const u8 __user *)src,
13428 ret, "b", "b", "=q", 1);
13429 if (likely(!ret))
13430 __put_user_asm(tmp, (u8 __user *)dst,
13431 @@ -185,7 +284,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13432 }
13433 case 2: {
13434 u16 tmp;
13435 - __get_user_asm(tmp, (u16 __user *)src,
13436 + __get_user_asm(tmp, (const u16 __user *)src,
13437 ret, "w", "w", "=r", 2);
13438 if (likely(!ret))
13439 __put_user_asm(tmp, (u16 __user *)dst,
13440 @@ -195,7 +294,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13441
13442 case 4: {
13443 u32 tmp;
13444 - __get_user_asm(tmp, (u32 __user *)src,
13445 + __get_user_asm(tmp, (const u32 __user *)src,
13446 ret, "l", "k", "=r", 4);
13447 if (likely(!ret))
13448 __put_user_asm(tmp, (u32 __user *)dst,
13449 @@ -204,7 +303,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13450 }
13451 case 8: {
13452 u64 tmp;
13453 - __get_user_asm(tmp, (u64 __user *)src,
13454 + __get_user_asm(tmp, (const u64 __user *)src,
13455 ret, "q", "", "=r", 8);
13456 if (likely(!ret))
13457 __put_user_asm(tmp, (u64 __user *)dst,
13458 @@ -212,44 +311,89 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13459 return ret;
13460 }
13461 default:
13462 - return copy_user_generic((__force void *)dst,
13463 - (__force void *)src, size);
13464 +
13465 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13466 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13467 + src += PAX_USER_SHADOW_BASE;
13468 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13469 + dst += PAX_USER_SHADOW_BASE;
13470 +#endif
13471 +
13472 + return copy_user_generic((__force_kernel void *)dst,
13473 + (__force_kernel const void *)src, size);
13474 }
13475 }
13476
13477 -__must_check unsigned long clear_user(void __user *mem, unsigned long len);
13478 -__must_check unsigned long __clear_user(void __user *mem, unsigned long len);
13479 +__must_check unsigned long clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13480 +__must_check unsigned long __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13481
13482 static __must_check __always_inline int
13483 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
13484 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
13485 {
13486 - return copy_user_generic(dst, (__force const void *)src, size);
13487 + if (size > INT_MAX)
13488 + return size;
13489 +
13490 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13491 + if (!__access_ok(VERIFY_READ, src, size))
13492 + return size;
13493 +
13494 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13495 + src += PAX_USER_SHADOW_BASE;
13496 +#endif
13497 +
13498 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13499 }
13500
13501 -static __must_check __always_inline int
13502 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
13503 +static __must_check __always_inline unsigned long
13504 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
13505 {
13506 - return copy_user_generic((__force void *)dst, src, size);
13507 + if (size > INT_MAX)
13508 + return size;
13509 +
13510 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13511 + if (!__access_ok(VERIFY_WRITE, dst, size))
13512 + return size;
13513 +
13514 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13515 + dst += PAX_USER_SHADOW_BASE;
13516 +#endif
13517 +
13518 + return copy_user_generic((__force_kernel void *)dst, src, size);
13519 }
13520
13521 -extern long __copy_user_nocache(void *dst, const void __user *src,
13522 - unsigned size, int zerorest);
13523 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
13524 + unsigned long size, int zerorest) __size_overflow(3);
13525
13526 -static inline int
13527 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
13528 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
13529 {
13530 might_sleep();
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, 1);
13541 }
13542
13543 -static inline int
13544 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13545 - unsigned size)
13546 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13547 + unsigned long size)
13548 {
13549 + if (size > INT_MAX)
13550 + return size;
13551 +
13552 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13553 + if (!__access_ok(VERIFY_READ, src, size))
13554 + return size;
13555 +#endif
13556 +
13557 return __copy_user_nocache(dst, src, size, 0);
13558 }
13559
13560 -unsigned long
13561 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
13562 +extern unsigned long
13563 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
13564
13565 #endif /* _ASM_X86_UACCESS_64_H */
13566 diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
13567 index bb05228..d763d5b 100644
13568 --- a/arch/x86/include/asm/vdso.h
13569 +++ b/arch/x86/include/asm/vdso.h
13570 @@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
13571 #define VDSO32_SYMBOL(base, name) \
13572 ({ \
13573 extern const char VDSO32_##name[]; \
13574 - (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13575 + (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13576 })
13577 #endif
13578
13579 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
13580 index 5b238981..77fdd78 100644
13581 --- a/arch/x86/include/asm/word-at-a-time.h
13582 +++ b/arch/x86/include/asm/word-at-a-time.h
13583 @@ -11,7 +11,7 @@
13584 * and shift, for example.
13585 */
13586 struct word_at_a_time {
13587 - const unsigned long one_bits, high_bits;
13588 + unsigned long one_bits, high_bits;
13589 };
13590
13591 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
13592 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13593 index 38155f6..e4184ba 100644
13594 --- a/arch/x86/include/asm/x86_init.h
13595 +++ b/arch/x86/include/asm/x86_init.h
13596 @@ -29,7 +29,7 @@ struct x86_init_mpparse {
13597 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13598 void (*find_smp_config)(void);
13599 void (*get_smp_config)(unsigned int early);
13600 -};
13601 +} __no_const;
13602
13603 /**
13604 * struct x86_init_resources - platform specific resource related ops
13605 @@ -43,7 +43,7 @@ struct x86_init_resources {
13606 void (*probe_roms)(void);
13607 void (*reserve_resources)(void);
13608 char *(*memory_setup)(void);
13609 -};
13610 +} __no_const;
13611
13612 /**
13613 * struct x86_init_irqs - platform specific interrupt setup
13614 @@ -56,7 +56,7 @@ struct x86_init_irqs {
13615 void (*pre_vector_init)(void);
13616 void (*intr_init)(void);
13617 void (*trap_init)(void);
13618 -};
13619 +} __no_const;
13620
13621 /**
13622 * struct x86_init_oem - oem platform specific customizing functions
13623 @@ -66,7 +66,7 @@ struct x86_init_irqs {
13624 struct x86_init_oem {
13625 void (*arch_setup)(void);
13626 void (*banner)(void);
13627 -};
13628 +} __no_const;
13629
13630 /**
13631 * struct x86_init_mapping - platform specific initial kernel pagetable setup
13632 @@ -77,7 +77,7 @@ struct x86_init_oem {
13633 */
13634 struct x86_init_mapping {
13635 void (*pagetable_reserve)(u64 start, u64 end);
13636 -};
13637 +} __no_const;
13638
13639 /**
13640 * struct x86_init_paging - platform specific paging functions
13641 @@ -87,7 +87,7 @@ struct x86_init_mapping {
13642 struct x86_init_paging {
13643 void (*pagetable_setup_start)(pgd_t *base);
13644 void (*pagetable_setup_done)(pgd_t *base);
13645 -};
13646 +} __no_const;
13647
13648 /**
13649 * struct x86_init_timers - platform specific timer setup
13650 @@ -102,7 +102,7 @@ struct x86_init_timers {
13651 void (*tsc_pre_init)(void);
13652 void (*timer_init)(void);
13653 void (*wallclock_init)(void);
13654 -};
13655 +} __no_const;
13656
13657 /**
13658 * struct x86_init_iommu - platform specific iommu setup
13659 @@ -110,7 +110,7 @@ struct x86_init_timers {
13660 */
13661 struct x86_init_iommu {
13662 int (*iommu_init)(void);
13663 -};
13664 +} __no_const;
13665
13666 /**
13667 * struct x86_init_pci - platform specific pci init functions
13668 @@ -124,7 +124,7 @@ struct x86_init_pci {
13669 int (*init)(void);
13670 void (*init_irq)(void);
13671 void (*fixup_irqs)(void);
13672 -};
13673 +} __no_const;
13674
13675 /**
13676 * struct x86_init_ops - functions for platform specific setup
13677 @@ -140,7 +140,7 @@ struct x86_init_ops {
13678 struct x86_init_timers timers;
13679 struct x86_init_iommu iommu;
13680 struct x86_init_pci pci;
13681 -};
13682 +} __no_const;
13683
13684 /**
13685 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13686 @@ -151,7 +151,7 @@ struct x86_cpuinit_ops {
13687 void (*setup_percpu_clockev)(void);
13688 void (*early_percpu_clock_init)(void);
13689 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
13690 -};
13691 +} __no_const;
13692
13693 /**
13694 * struct x86_platform_ops - platform specific runtime functions
13695 @@ -177,7 +177,7 @@ struct x86_platform_ops {
13696 void (*save_sched_clock_state)(void);
13697 void (*restore_sched_clock_state)(void);
13698 void (*apic_post_init)(void);
13699 -};
13700 +} __no_const;
13701
13702 struct pci_dev;
13703
13704 @@ -186,14 +186,14 @@ struct x86_msi_ops {
13705 void (*teardown_msi_irq)(unsigned int irq);
13706 void (*teardown_msi_irqs)(struct pci_dev *dev);
13707 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
13708 -};
13709 +} __no_const;
13710
13711 struct x86_io_apic_ops {
13712 void (*init) (void);
13713 unsigned int (*read) (unsigned int apic, unsigned int reg);
13714 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
13715 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
13716 -};
13717 +} __no_const;
13718
13719 extern struct x86_init_ops x86_init;
13720 extern struct x86_cpuinit_ops x86_cpuinit;
13721 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13722 index 8a1b6f9..a29c4e4 100644
13723 --- a/arch/x86/include/asm/xsave.h
13724 +++ b/arch/x86/include/asm/xsave.h
13725 @@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13726 {
13727 int err;
13728
13729 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13730 + if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
13731 + buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
13732 +#endif
13733 +
13734 /*
13735 * Clear the xsave header first, so that reserved fields are
13736 * initialized to zero.
13737 @@ -93,10 +98,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13738 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13739 {
13740 int err;
13741 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13742 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
13743 u32 lmask = mask;
13744 u32 hmask = mask >> 32;
13745
13746 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13747 + if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
13748 + xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
13749 +#endif
13750 +
13751 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13752 "2:\n"
13753 ".section .fixup,\"ax\"\n"
13754 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13755 index 1b8e5a0..354fd59 100644
13756 --- a/arch/x86/kernel/acpi/sleep.c
13757 +++ b/arch/x86/kernel/acpi/sleep.c
13758 @@ -69,8 +69,12 @@ int acpi_suspend_lowlevel(void)
13759 #else /* CONFIG_64BIT */
13760 #ifdef CONFIG_SMP
13761 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13762 +
13763 + pax_open_kernel();
13764 early_gdt_descr.address =
13765 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13766 + pax_close_kernel();
13767 +
13768 initial_gs = per_cpu_offset(smp_processor_id());
13769 #endif
13770 initial_code = (unsigned long)wakeup_long64;
13771 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13772 index 13ab720..95d5442 100644
13773 --- a/arch/x86/kernel/acpi/wakeup_32.S
13774 +++ b/arch/x86/kernel/acpi/wakeup_32.S
13775 @@ -30,13 +30,11 @@ wakeup_pmode_return:
13776 # and restore the stack ... but you need gdt for this to work
13777 movl saved_context_esp, %esp
13778
13779 - movl %cs:saved_magic, %eax
13780 - cmpl $0x12345678, %eax
13781 + cmpl $0x12345678, saved_magic
13782 jne bogus_magic
13783
13784 # jump to place where we left off
13785 - movl saved_eip, %eax
13786 - jmp *%eax
13787 + jmp *(saved_eip)
13788
13789 bogus_magic:
13790 jmp bogus_magic
13791 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13792 index ced4534..3e75d69 100644
13793 --- a/arch/x86/kernel/alternative.c
13794 +++ b/arch/x86/kernel/alternative.c
13795 @@ -281,6 +281,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13796 */
13797 for (a = start; a < end; a++) {
13798 instr = (u8 *)&a->instr_offset + a->instr_offset;
13799 +
13800 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13801 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13802 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13803 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13804 +#endif
13805 +
13806 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13807 BUG_ON(a->replacementlen > a->instrlen);
13808 BUG_ON(a->instrlen > sizeof(insnbuf));
13809 @@ -312,10 +319,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13810 for (poff = start; poff < end; poff++) {
13811 u8 *ptr = (u8 *)poff + *poff;
13812
13813 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13814 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13815 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13816 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13817 +#endif
13818 +
13819 if (!*poff || ptr < text || ptr >= text_end)
13820 continue;
13821 /* turn DS segment override prefix into lock prefix */
13822 - if (*ptr == 0x3e)
13823 + if (*ktla_ktva(ptr) == 0x3e)
13824 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13825 };
13826 mutex_unlock(&text_mutex);
13827 @@ -333,10 +346,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13828 for (poff = start; poff < end; poff++) {
13829 u8 *ptr = (u8 *)poff + *poff;
13830
13831 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13832 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13833 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13834 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13835 +#endif
13836 +
13837 if (!*poff || ptr < text || ptr >= text_end)
13838 continue;
13839 /* turn lock prefix into DS segment override prefix */
13840 - if (*ptr == 0xf0)
13841 + if (*ktla_ktva(ptr) == 0xf0)
13842 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13843 };
13844 mutex_unlock(&text_mutex);
13845 @@ -505,7 +524,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13846
13847 BUG_ON(p->len > MAX_PATCH_LEN);
13848 /* prep the buffer with the original instructions */
13849 - memcpy(insnbuf, p->instr, p->len);
13850 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13851 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13852 (unsigned long)p->instr, p->len);
13853
13854 @@ -573,7 +592,7 @@ void __init alternative_instructions(void)
13855 if (smp_alt_once)
13856 free_init_pages("SMP alternatives",
13857 (unsigned long)__smp_locks,
13858 - (unsigned long)__smp_locks_end);
13859 + PAGE_ALIGN((unsigned long)__smp_locks_end));
13860
13861 restart_nmi();
13862 }
13863 @@ -590,13 +609,17 @@ void __init alternative_instructions(void)
13864 * instructions. And on the local CPU you need to be protected again NMI or MCE
13865 * handlers seeing an inconsistent instruction while you patch.
13866 */
13867 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
13868 +void *__kprobes text_poke_early(void *addr, const void *opcode,
13869 size_t len)
13870 {
13871 unsigned long flags;
13872 local_irq_save(flags);
13873 - memcpy(addr, opcode, len);
13874 +
13875 + pax_open_kernel();
13876 + memcpy(ktla_ktva(addr), opcode, len);
13877 sync_core();
13878 + pax_close_kernel();
13879 +
13880 local_irq_restore(flags);
13881 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13882 that causes hangs on some VIA CPUs. */
13883 @@ -618,36 +641,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
13884 */
13885 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13886 {
13887 - unsigned long flags;
13888 - char *vaddr;
13889 + unsigned char *vaddr = ktla_ktva(addr);
13890 struct page *pages[2];
13891 - int i;
13892 + size_t i;
13893
13894 if (!core_kernel_text((unsigned long)addr)) {
13895 - pages[0] = vmalloc_to_page(addr);
13896 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13897 + pages[0] = vmalloc_to_page(vaddr);
13898 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13899 } else {
13900 - pages[0] = virt_to_page(addr);
13901 + pages[0] = virt_to_page(vaddr);
13902 WARN_ON(!PageReserved(pages[0]));
13903 - pages[1] = virt_to_page(addr + PAGE_SIZE);
13904 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13905 }
13906 BUG_ON(!pages[0]);
13907 - local_irq_save(flags);
13908 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13909 - if (pages[1])
13910 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13911 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13912 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13913 - clear_fixmap(FIX_TEXT_POKE0);
13914 - if (pages[1])
13915 - clear_fixmap(FIX_TEXT_POKE1);
13916 - local_flush_tlb();
13917 - sync_core();
13918 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
13919 - that causes hangs on some VIA CPUs. */
13920 + text_poke_early(addr, opcode, len);
13921 for (i = 0; i < len; i++)
13922 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13923 - local_irq_restore(flags);
13924 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13925 return addr;
13926 }
13927
13928 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13929 index 24deb30..94a3426 100644
13930 --- a/arch/x86/kernel/apic/apic.c
13931 +++ b/arch/x86/kernel/apic/apic.c
13932 @@ -185,7 +185,7 @@ int first_system_vector = 0xfe;
13933 /*
13934 * Debug level, exported for io_apic.c
13935 */
13936 -unsigned int apic_verbosity;
13937 +int apic_verbosity;
13938
13939 int pic_mode;
13940
13941 @@ -1923,7 +1923,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13942 apic_write(APIC_ESR, 0);
13943 v1 = apic_read(APIC_ESR);
13944 ack_APIC_irq();
13945 - atomic_inc(&irq_err_count);
13946 + atomic_inc_unchecked(&irq_err_count);
13947
13948 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
13949 smp_processor_id(), v0 , v1);
13950 @@ -2155,7 +2155,9 @@ void __init apic_set_eoi_write(void (*eoi_write)(u32 reg, u32 v))
13951 for (drv = __apicdrivers; drv < __apicdrivers_end; drv++) {
13952 /* Should happen once for each apic */
13953 WARN_ON((*drv)->eoi_write == eoi_write);
13954 - (*drv)->eoi_write = eoi_write;
13955 + pax_open_kernel();
13956 + *(void **)&(*drv)->eoi_write = eoi_write;
13957 + pax_close_kernel();
13958 }
13959 }
13960
13961 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13962 index c265593..137c4ac 100644
13963 --- a/arch/x86/kernel/apic/io_apic.c
13964 +++ b/arch/x86/kernel/apic/io_apic.c
13965 @@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13966 }
13967 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13968
13969 -void lock_vector_lock(void)
13970 +void lock_vector_lock(void) __acquires(vector_lock)
13971 {
13972 /* Used to the online set of cpus does not change
13973 * during assign_irq_vector.
13974 @@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
13975 raw_spin_lock(&vector_lock);
13976 }
13977
13978 -void unlock_vector_lock(void)
13979 +void unlock_vector_lock(void) __releases(vector_lock)
13980 {
13981 raw_spin_unlock(&vector_lock);
13982 }
13983 @@ -2408,7 +2408,7 @@ static void ack_apic_edge(struct irq_data *data)
13984 ack_APIC_irq();
13985 }
13986
13987 -atomic_t irq_mis_count;
13988 +atomic_unchecked_t irq_mis_count;
13989
13990 #ifdef CONFIG_GENERIC_PENDING_IRQ
13991 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
13992 @@ -2549,7 +2549,7 @@ static void ack_apic_level(struct irq_data *data)
13993 * at the cpu.
13994 */
13995 if (!(v & (1 << (i & 0x1f)))) {
13996 - atomic_inc(&irq_mis_count);
13997 + atomic_inc_unchecked(&irq_mis_count);
13998
13999 eoi_ioapic_irq(irq, cfg);
14000 }
14001 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
14002 index d65464e..1035d31 100644
14003 --- a/arch/x86/kernel/apm_32.c
14004 +++ b/arch/x86/kernel/apm_32.c
14005 @@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
14006 * This is for buggy BIOS's that refer to (real mode) segment 0x40
14007 * even though they are called in protected mode.
14008 */
14009 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
14010 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
14011 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
14012
14013 static const char driver_version[] = "1.16ac"; /* no spaces */
14014 @@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
14015 BUG_ON(cpu != 0);
14016 gdt = get_cpu_gdt_table(cpu);
14017 save_desc_40 = gdt[0x40 / 8];
14018 +
14019 + pax_open_kernel();
14020 gdt[0x40 / 8] = bad_bios_desc;
14021 + pax_close_kernel();
14022
14023 apm_irq_save(flags);
14024 APM_DO_SAVE_SEGS;
14025 @@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
14026 &call->esi);
14027 APM_DO_RESTORE_SEGS;
14028 apm_irq_restore(flags);
14029 +
14030 + pax_open_kernel();
14031 gdt[0x40 / 8] = save_desc_40;
14032 + pax_close_kernel();
14033 +
14034 put_cpu();
14035
14036 return call->eax & 0xff;
14037 @@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void *_call)
14038 BUG_ON(cpu != 0);
14039 gdt = get_cpu_gdt_table(cpu);
14040 save_desc_40 = gdt[0x40 / 8];
14041 +
14042 + pax_open_kernel();
14043 gdt[0x40 / 8] = bad_bios_desc;
14044 + pax_close_kernel();
14045
14046 apm_irq_save(flags);
14047 APM_DO_SAVE_SEGS;
14048 @@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void *_call)
14049 &call->eax);
14050 APM_DO_RESTORE_SEGS;
14051 apm_irq_restore(flags);
14052 +
14053 + pax_open_kernel();
14054 gdt[0x40 / 8] = save_desc_40;
14055 + pax_close_kernel();
14056 +
14057 put_cpu();
14058 return error;
14059 }
14060 @@ -2345,12 +2359,15 @@ static int __init apm_init(void)
14061 * code to that CPU.
14062 */
14063 gdt = get_cpu_gdt_table(0);
14064 +
14065 + pax_open_kernel();
14066 set_desc_base(&gdt[APM_CS >> 3],
14067 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
14068 set_desc_base(&gdt[APM_CS_16 >> 3],
14069 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
14070 set_desc_base(&gdt[APM_DS >> 3],
14071 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
14072 + pax_close_kernel();
14073
14074 proc_create("apm", 0, NULL, &apm_file_ops);
14075
14076 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
14077 index 68de2dc..1f3c720 100644
14078 --- a/arch/x86/kernel/asm-offsets.c
14079 +++ b/arch/x86/kernel/asm-offsets.c
14080 @@ -33,6 +33,8 @@ void common(void) {
14081 OFFSET(TI_status, thread_info, status);
14082 OFFSET(TI_addr_limit, thread_info, addr_limit);
14083 OFFSET(TI_preempt_count, thread_info, preempt_count);
14084 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
14085 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
14086
14087 BLANK();
14088 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
14089 @@ -53,8 +55,26 @@ void common(void) {
14090 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
14091 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
14092 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
14093 +
14094 +#ifdef CONFIG_PAX_KERNEXEC
14095 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
14096 #endif
14097
14098 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14099 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
14100 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
14101 +#ifdef CONFIG_X86_64
14102 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
14103 +#endif
14104 +#endif
14105 +
14106 +#endif
14107 +
14108 + BLANK();
14109 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
14110 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
14111 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
14112 +
14113 #ifdef CONFIG_XEN
14114 BLANK();
14115 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
14116 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
14117 index 1b4754f..fbb4227 100644
14118 --- a/arch/x86/kernel/asm-offsets_64.c
14119 +++ b/arch/x86/kernel/asm-offsets_64.c
14120 @@ -76,6 +76,7 @@ int main(void)
14121 BLANK();
14122 #undef ENTRY
14123
14124 + DEFINE(TSS_size, sizeof(struct tss_struct));
14125 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
14126 BLANK();
14127
14128 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
14129 index d30a6a9..79becab 100644
14130 --- a/arch/x86/kernel/cpu/Makefile
14131 +++ b/arch/x86/kernel/cpu/Makefile
14132 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
14133 CFLAGS_REMOVE_perf_event.o = -pg
14134 endif
14135
14136 -# Make sure load_percpu_segment has no stackprotector
14137 -nostackp := $(call cc-option, -fno-stack-protector)
14138 -CFLAGS_common.o := $(nostackp)
14139 -
14140 obj-y := intel_cacheinfo.o scattered.o topology.o
14141 obj-y += proc.o capflags.o powerflags.o common.o
14142 obj-y += vmware.o hypervisor.o mshyperv.o
14143 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
14144 index 9d92e19..49d7d79 100644
14145 --- a/arch/x86/kernel/cpu/amd.c
14146 +++ b/arch/x86/kernel/cpu/amd.c
14147 @@ -724,7 +724,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
14148 unsigned int size)
14149 {
14150 /* AMD errata T13 (order #21922) */
14151 - if ((c->x86 == 6)) {
14152 + if (c->x86 == 6) {
14153 /* Duron Rev A0 */
14154 if (c->x86_model == 3 && c->x86_mask == 0)
14155 size = 64;
14156 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
14157 index a5fbc3c..2254849 100644
14158 --- a/arch/x86/kernel/cpu/common.c
14159 +++ b/arch/x86/kernel/cpu/common.c
14160 @@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
14161
14162 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
14163
14164 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
14165 -#ifdef CONFIG_X86_64
14166 - /*
14167 - * We need valid kernel segments for data and code in long mode too
14168 - * IRET will check the segment types kkeil 2000/10/28
14169 - * Also sysret mandates a special GDT layout
14170 - *
14171 - * TLS descriptors are currently at a different place compared to i386.
14172 - * Hopefully nobody expects them at a fixed place (Wine?)
14173 - */
14174 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
14175 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
14176 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
14177 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
14178 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
14179 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
14180 -#else
14181 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
14182 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14183 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
14184 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
14185 - /*
14186 - * Segments used for calling PnP BIOS have byte granularity.
14187 - * They code segments and data segments have fixed 64k limits,
14188 - * the transfer segment sizes are set at run time.
14189 - */
14190 - /* 32-bit code */
14191 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14192 - /* 16-bit code */
14193 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14194 - /* 16-bit data */
14195 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
14196 - /* 16-bit data */
14197 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
14198 - /* 16-bit data */
14199 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
14200 - /*
14201 - * The APM segments have byte granularity and their bases
14202 - * are set at run time. All have 64k limits.
14203 - */
14204 - /* 32-bit code */
14205 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14206 - /* 16-bit code */
14207 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14208 - /* data */
14209 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
14210 -
14211 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14212 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14213 - GDT_STACK_CANARY_INIT
14214 -#endif
14215 -} };
14216 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
14217 -
14218 static int __init x86_xsave_setup(char *s)
14219 {
14220 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
14221 @@ -376,7 +322,7 @@ void switch_to_new_gdt(int cpu)
14222 {
14223 struct desc_ptr gdt_descr;
14224
14225 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
14226 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
14227 gdt_descr.size = GDT_SIZE - 1;
14228 load_gdt(&gdt_descr);
14229 /* Reload the per-cpu base */
14230 @@ -872,6 +818,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
14231 /* Filter out anything that depends on CPUID levels we don't have */
14232 filter_cpuid_features(c, true);
14233
14234 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
14235 + setup_clear_cpu_cap(X86_FEATURE_SEP);
14236 +#endif
14237 +
14238 /* If the model name is still unset, do table lookup. */
14239 if (!c->x86_model_id[0]) {
14240 const char *p;
14241 @@ -1054,10 +1004,12 @@ static __init int setup_disablecpuid(char *arg)
14242 }
14243 __setup("clearcpuid=", setup_disablecpuid);
14244
14245 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
14246 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
14247 +
14248 #ifdef CONFIG_X86_64
14249 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
14250 -struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
14251 - (unsigned long) nmi_idt_table };
14252 +struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
14253
14254 DEFINE_PER_CPU_FIRST(union irq_stack_union,
14255 irq_stack_union) __aligned(PAGE_SIZE);
14256 @@ -1071,7 +1023,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
14257 EXPORT_PER_CPU_SYMBOL(current_task);
14258
14259 DEFINE_PER_CPU(unsigned long, kernel_stack) =
14260 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
14261 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
14262 EXPORT_PER_CPU_SYMBOL(kernel_stack);
14263
14264 DEFINE_PER_CPU(char *, irq_stack_ptr) =
14265 @@ -1165,7 +1117,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
14266 {
14267 memset(regs, 0, sizeof(struct pt_regs));
14268 regs->fs = __KERNEL_PERCPU;
14269 - regs->gs = __KERNEL_STACK_CANARY;
14270 + savesegment(gs, regs->gs);
14271
14272 return regs;
14273 }
14274 @@ -1220,7 +1172,7 @@ void __cpuinit cpu_init(void)
14275 int i;
14276
14277 cpu = stack_smp_processor_id();
14278 - t = &per_cpu(init_tss, cpu);
14279 + t = init_tss + cpu;
14280 oist = &per_cpu(orig_ist, cpu);
14281
14282 #ifdef CONFIG_NUMA
14283 @@ -1246,7 +1198,7 @@ void __cpuinit cpu_init(void)
14284 switch_to_new_gdt(cpu);
14285 loadsegment(fs, 0);
14286
14287 - load_idt((const struct desc_ptr *)&idt_descr);
14288 + load_idt(&idt_descr);
14289
14290 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
14291 syscall_init();
14292 @@ -1255,7 +1207,6 @@ void __cpuinit cpu_init(void)
14293 wrmsrl(MSR_KERNEL_GS_BASE, 0);
14294 barrier();
14295
14296 - x86_configure_nx();
14297 if (cpu != 0)
14298 enable_x2apic();
14299
14300 @@ -1311,7 +1262,7 @@ void __cpuinit cpu_init(void)
14301 {
14302 int cpu = smp_processor_id();
14303 struct task_struct *curr = current;
14304 - struct tss_struct *t = &per_cpu(init_tss, cpu);
14305 + struct tss_struct *t = init_tss + cpu;
14306 struct thread_struct *thread = &curr->thread;
14307
14308 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
14309 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
14310 index 0a4ce29..f211176 100644
14311 --- a/arch/x86/kernel/cpu/intel.c
14312 +++ b/arch/x86/kernel/cpu/intel.c
14313 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
14314 * Update the IDT descriptor and reload the IDT so that
14315 * it uses the read-only mapped virtual address.
14316 */
14317 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
14318 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
14319 load_idt(&idt_descr);
14320 }
14321 #endif
14322 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
14323 index 292d025..b520c94 100644
14324 --- a/arch/x86/kernel/cpu/mcheck/mce.c
14325 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
14326 @@ -45,6 +45,7 @@
14327 #include <asm/processor.h>
14328 #include <asm/mce.h>
14329 #include <asm/msr.h>
14330 +#include <asm/local.h>
14331
14332 #include "mce-internal.h"
14333
14334 @@ -253,7 +254,7 @@ static void print_mce(struct mce *m)
14335 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
14336 m->cs, m->ip);
14337
14338 - if (m->cs == __KERNEL_CS)
14339 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
14340 print_symbol("{%s}", m->ip);
14341 pr_cont("\n");
14342 }
14343 @@ -286,10 +287,10 @@ static void print_mce(struct mce *m)
14344
14345 #define PANIC_TIMEOUT 5 /* 5 seconds */
14346
14347 -static atomic_t mce_paniced;
14348 +static atomic_unchecked_t mce_paniced;
14349
14350 static int fake_panic;
14351 -static atomic_t mce_fake_paniced;
14352 +static atomic_unchecked_t mce_fake_paniced;
14353
14354 /* Panic in progress. Enable interrupts and wait for final IPI */
14355 static void wait_for_panic(void)
14356 @@ -313,7 +314,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14357 /*
14358 * Make sure only one CPU runs in machine check panic
14359 */
14360 - if (atomic_inc_return(&mce_paniced) > 1)
14361 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
14362 wait_for_panic();
14363 barrier();
14364
14365 @@ -321,7 +322,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14366 console_verbose();
14367 } else {
14368 /* Don't log too much for fake panic */
14369 - if (atomic_inc_return(&mce_fake_paniced) > 1)
14370 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
14371 return;
14372 }
14373 /* First print corrected ones that are still unlogged */
14374 @@ -693,7 +694,7 @@ static int mce_timed_out(u64 *t)
14375 * might have been modified by someone else.
14376 */
14377 rmb();
14378 - if (atomic_read(&mce_paniced))
14379 + if (atomic_read_unchecked(&mce_paniced))
14380 wait_for_panic();
14381 if (!monarch_timeout)
14382 goto out;
14383 @@ -1619,7 +1620,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
14384 }
14385
14386 /* Call the installed machine check handler for this CPU setup. */
14387 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
14388 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
14389 unexpected_machine_check;
14390
14391 /*
14392 @@ -1642,7 +1643,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14393 return;
14394 }
14395
14396 + pax_open_kernel();
14397 machine_check_vector = do_machine_check;
14398 + pax_close_kernel();
14399
14400 __mcheck_cpu_init_generic();
14401 __mcheck_cpu_init_vendor(c);
14402 @@ -1656,7 +1659,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14403 */
14404
14405 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
14406 -static int mce_chrdev_open_count; /* #times opened */
14407 +static local_t mce_chrdev_open_count; /* #times opened */
14408 static int mce_chrdev_open_exclu; /* already open exclusive? */
14409
14410 static int mce_chrdev_open(struct inode *inode, struct file *file)
14411 @@ -1664,7 +1667,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14412 spin_lock(&mce_chrdev_state_lock);
14413
14414 if (mce_chrdev_open_exclu ||
14415 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
14416 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
14417 spin_unlock(&mce_chrdev_state_lock);
14418
14419 return -EBUSY;
14420 @@ -1672,7 +1675,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14421
14422 if (file->f_flags & O_EXCL)
14423 mce_chrdev_open_exclu = 1;
14424 - mce_chrdev_open_count++;
14425 + local_inc(&mce_chrdev_open_count);
14426
14427 spin_unlock(&mce_chrdev_state_lock);
14428
14429 @@ -1683,7 +1686,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
14430 {
14431 spin_lock(&mce_chrdev_state_lock);
14432
14433 - mce_chrdev_open_count--;
14434 + local_dec(&mce_chrdev_open_count);
14435 mce_chrdev_open_exclu = 0;
14436
14437 spin_unlock(&mce_chrdev_state_lock);
14438 @@ -2407,7 +2410,7 @@ struct dentry *mce_get_debugfs_dir(void)
14439 static void mce_reset(void)
14440 {
14441 cpu_missing = 0;
14442 - atomic_set(&mce_fake_paniced, 0);
14443 + atomic_set_unchecked(&mce_fake_paniced, 0);
14444 atomic_set(&mce_executing, 0);
14445 atomic_set(&mce_callin, 0);
14446 atomic_set(&global_nwo, 0);
14447 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
14448 index 2d5454c..51987eb 100644
14449 --- a/arch/x86/kernel/cpu/mcheck/p5.c
14450 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
14451 @@ -11,6 +11,7 @@
14452 #include <asm/processor.h>
14453 #include <asm/mce.h>
14454 #include <asm/msr.h>
14455 +#include <asm/pgtable.h>
14456
14457 /* By default disabled */
14458 int mce_p5_enabled __read_mostly;
14459 @@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
14460 if (!cpu_has(c, X86_FEATURE_MCE))
14461 return;
14462
14463 + pax_open_kernel();
14464 machine_check_vector = pentium_machine_check;
14465 + pax_close_kernel();
14466 /* Make sure the vector pointer is visible before we enable MCEs: */
14467 wmb();
14468
14469 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
14470 index 2d7998f..17c9de1 100644
14471 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
14472 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
14473 @@ -10,6 +10,7 @@
14474 #include <asm/processor.h>
14475 #include <asm/mce.h>
14476 #include <asm/msr.h>
14477 +#include <asm/pgtable.h>
14478
14479 /* Machine check handler for WinChip C6: */
14480 static void winchip_machine_check(struct pt_regs *regs, long error_code)
14481 @@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
14482 {
14483 u32 lo, hi;
14484
14485 + pax_open_kernel();
14486 machine_check_vector = winchip_machine_check;
14487 + pax_close_kernel();
14488 /* Make sure the vector pointer is visible before we enable MCEs: */
14489 wmb();
14490
14491 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
14492 index 6b96110..0da73eb 100644
14493 --- a/arch/x86/kernel/cpu/mtrr/main.c
14494 +++ b/arch/x86/kernel/cpu/mtrr/main.c
14495 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
14496 u64 size_or_mask, size_and_mask;
14497 static bool mtrr_aps_delayed_init;
14498
14499 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
14500 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
14501
14502 const struct mtrr_ops *mtrr_if;
14503
14504 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
14505 index df5e41f..816c719 100644
14506 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
14507 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
14508 @@ -25,7 +25,7 @@ struct mtrr_ops {
14509 int (*validate_add_page)(unsigned long base, unsigned long size,
14510 unsigned int type);
14511 int (*have_wrcomb)(void);
14512 -};
14513 +} __do_const;
14514
14515 extern int generic_get_free_region(unsigned long base, unsigned long size,
14516 int replace_reg);
14517 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
14518 index 915b876..171f845 100644
14519 --- a/arch/x86/kernel/cpu/perf_event.c
14520 +++ b/arch/x86/kernel/cpu/perf_event.c
14521 @@ -1757,7 +1757,7 @@ static unsigned long get_segment_base(unsigned int segment)
14522 if (idx > GDT_ENTRIES)
14523 return 0;
14524
14525 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
14526 + desc = get_cpu_gdt_table(smp_processor_id());
14527 }
14528
14529 return get_desc_base(desc + idx);
14530 @@ -1847,7 +1847,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
14531 break;
14532
14533 perf_callchain_store(entry, frame.return_address);
14534 - fp = frame.next_frame;
14535 + fp = (const void __force_user *)frame.next_frame;
14536 }
14537 }
14538
14539 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
14540 index 6bca492..36e4496 100644
14541 --- a/arch/x86/kernel/cpu/perf_event_intel.c
14542 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
14543 @@ -1947,10 +1947,10 @@ __init int intel_pmu_init(void)
14544 * v2 and above have a perf capabilities MSR
14545 */
14546 if (version > 1) {
14547 - u64 capabilities;
14548 + u64 capabilities = x86_pmu.intel_cap.capabilities;
14549
14550 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
14551 - x86_pmu.intel_cap.capabilities = capabilities;
14552 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
14553 + x86_pmu.intel_cap.capabilities = capabilities;
14554 }
14555
14556 intel_ds_init();
14557 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
14558 index 13ad899..f642b9a 100644
14559 --- a/arch/x86/kernel/crash.c
14560 +++ b/arch/x86/kernel/crash.c
14561 @@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
14562 {
14563 #ifdef CONFIG_X86_32
14564 struct pt_regs fixed_regs;
14565 -#endif
14566
14567 -#ifdef CONFIG_X86_32
14568 - if (!user_mode_vm(regs)) {
14569 + if (!user_mode(regs)) {
14570 crash_fixup_ss_esp(&fixed_regs, regs);
14571 regs = &fixed_regs;
14572 }
14573 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14574 index 37250fe..bf2ec74 100644
14575 --- a/arch/x86/kernel/doublefault_32.c
14576 +++ b/arch/x86/kernel/doublefault_32.c
14577 @@ -11,7 +11,7 @@
14578
14579 #define DOUBLEFAULT_STACKSIZE (1024)
14580 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14581 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14582 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14583
14584 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14585
14586 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
14587 unsigned long gdt, tss;
14588
14589 store_gdt(&gdt_desc);
14590 - gdt = gdt_desc.address;
14591 + gdt = (unsigned long)gdt_desc.address;
14592
14593 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14594
14595 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14596 /* 0x2 bit is always set */
14597 .flags = X86_EFLAGS_SF | 0x2,
14598 .sp = STACK_START,
14599 - .es = __USER_DS,
14600 + .es = __KERNEL_DS,
14601 .cs = __KERNEL_CS,
14602 .ss = __KERNEL_DS,
14603 - .ds = __USER_DS,
14604 + .ds = __KERNEL_DS,
14605 .fs = __KERNEL_PERCPU,
14606
14607 .__cr3 = __pa_nodebug(swapper_pg_dir),
14608 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14609 index ae42418b..787c16b 100644
14610 --- a/arch/x86/kernel/dumpstack.c
14611 +++ b/arch/x86/kernel/dumpstack.c
14612 @@ -2,6 +2,9 @@
14613 * Copyright (C) 1991, 1992 Linus Torvalds
14614 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14615 */
14616 +#ifdef CONFIG_GRKERNSEC_HIDESYM
14617 +#define __INCLUDED_BY_HIDESYM 1
14618 +#endif
14619 #include <linux/kallsyms.h>
14620 #include <linux/kprobes.h>
14621 #include <linux/uaccess.h>
14622 @@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
14623 static void
14624 print_ftrace_graph_addr(unsigned long addr, void *data,
14625 const struct stacktrace_ops *ops,
14626 - struct thread_info *tinfo, int *graph)
14627 + struct task_struct *task, int *graph)
14628 {
14629 - struct task_struct *task;
14630 unsigned long ret_addr;
14631 int index;
14632
14633 if (addr != (unsigned long)return_to_handler)
14634 return;
14635
14636 - task = tinfo->task;
14637 index = task->curr_ret_stack;
14638
14639 if (!task->ret_stack || index < *graph)
14640 @@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14641 static inline void
14642 print_ftrace_graph_addr(unsigned long addr, void *data,
14643 const struct stacktrace_ops *ops,
14644 - struct thread_info *tinfo, int *graph)
14645 + struct task_struct *task, int *graph)
14646 { }
14647 #endif
14648
14649 @@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14650 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14651 */
14652
14653 -static inline int valid_stack_ptr(struct thread_info *tinfo,
14654 - void *p, unsigned int size, void *end)
14655 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14656 {
14657 - void *t = tinfo;
14658 if (end) {
14659 if (p < end && p >= (end-THREAD_SIZE))
14660 return 1;
14661 @@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14662 }
14663
14664 unsigned long
14665 -print_context_stack(struct thread_info *tinfo,
14666 +print_context_stack(struct task_struct *task, void *stack_start,
14667 unsigned long *stack, unsigned long bp,
14668 const struct stacktrace_ops *ops, void *data,
14669 unsigned long *end, int *graph)
14670 {
14671 struct stack_frame *frame = (struct stack_frame *)bp;
14672
14673 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14674 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14675 unsigned long addr;
14676
14677 addr = *stack;
14678 @@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
14679 } else {
14680 ops->address(data, addr, 0);
14681 }
14682 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14683 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14684 }
14685 stack++;
14686 }
14687 @@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
14688 EXPORT_SYMBOL_GPL(print_context_stack);
14689
14690 unsigned long
14691 -print_context_stack_bp(struct thread_info *tinfo,
14692 +print_context_stack_bp(struct task_struct *task, void *stack_start,
14693 unsigned long *stack, unsigned long bp,
14694 const struct stacktrace_ops *ops, void *data,
14695 unsigned long *end, int *graph)
14696 @@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14697 struct stack_frame *frame = (struct stack_frame *)bp;
14698 unsigned long *ret_addr = &frame->return_address;
14699
14700 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
14701 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
14702 unsigned long addr = *ret_addr;
14703
14704 if (!__kernel_text_address(addr))
14705 @@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14706 ops->address(data, addr, 1);
14707 frame = frame->next_frame;
14708 ret_addr = &frame->return_address;
14709 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14710 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14711 }
14712
14713 return (unsigned long)frame;
14714 @@ -189,7 +188,7 @@ void dump_stack(void)
14715
14716 bp = stack_frame(current, NULL);
14717 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14718 - current->pid, current->comm, print_tainted(),
14719 + task_pid_nr(current), current->comm, print_tainted(),
14720 init_utsname()->release,
14721 (int)strcspn(init_utsname()->version, " "),
14722 init_utsname()->version);
14723 @@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
14724 }
14725 EXPORT_SYMBOL_GPL(oops_begin);
14726
14727 +extern void gr_handle_kernel_exploit(void);
14728 +
14729 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14730 {
14731 if (regs && kexec_should_crash(current))
14732 @@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14733 panic("Fatal exception in interrupt");
14734 if (panic_on_oops)
14735 panic("Fatal exception");
14736 - do_exit(signr);
14737 +
14738 + gr_handle_kernel_exploit();
14739 +
14740 + do_group_exit(signr);
14741 }
14742
14743 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14744 @@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14745 print_modules();
14746 show_regs(regs);
14747 #ifdef CONFIG_X86_32
14748 - if (user_mode_vm(regs)) {
14749 + if (user_mode(regs)) {
14750 sp = regs->sp;
14751 ss = regs->ss & 0xffff;
14752 } else {
14753 @@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14754 unsigned long flags = oops_begin();
14755 int sig = SIGSEGV;
14756
14757 - if (!user_mode_vm(regs))
14758 + if (!user_mode(regs))
14759 report_bug(regs->ip, regs);
14760
14761 if (__die(str, regs, err))
14762 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14763 index 1038a41..ac7e5f6 100644
14764 --- a/arch/x86/kernel/dumpstack_32.c
14765 +++ b/arch/x86/kernel/dumpstack_32.c
14766 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14767 bp = stack_frame(task, regs);
14768
14769 for (;;) {
14770 - struct thread_info *context;
14771 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14772
14773 - context = (struct thread_info *)
14774 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14775 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14776 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14777
14778 - stack = (unsigned long *)context->previous_esp;
14779 - if (!stack)
14780 + if (stack_start == task_stack_page(task))
14781 break;
14782 + stack = *(unsigned long **)stack_start;
14783 if (ops->stack(data, "IRQ") < 0)
14784 break;
14785 touch_nmi_watchdog();
14786 @@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
14787 {
14788 int i;
14789
14790 - __show_regs(regs, !user_mode_vm(regs));
14791 + __show_regs(regs, !user_mode(regs));
14792
14793 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
14794 TASK_COMM_LEN, current->comm, task_pid_nr(current),
14795 @@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
14796 * When in-kernel, we also print out the stack and code at the
14797 * time of the fault..
14798 */
14799 - if (!user_mode_vm(regs)) {
14800 + if (!user_mode(regs)) {
14801 unsigned int code_prologue = code_bytes * 43 / 64;
14802 unsigned int code_len = code_bytes;
14803 unsigned char c;
14804 u8 *ip;
14805 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
14806
14807 pr_emerg("Stack:\n");
14808 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14809
14810 pr_emerg("Code:");
14811
14812 - ip = (u8 *)regs->ip - code_prologue;
14813 + ip = (u8 *)regs->ip - code_prologue + cs_base;
14814 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14815 /* try starting at IP */
14816 - ip = (u8 *)regs->ip;
14817 + ip = (u8 *)regs->ip + cs_base;
14818 code_len = code_len - code_prologue + 1;
14819 }
14820 for (i = 0; i < code_len; i++, ip++) {
14821 @@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
14822 pr_cont(" Bad EIP value.");
14823 break;
14824 }
14825 - if (ip == (u8 *)regs->ip)
14826 + if (ip == (u8 *)regs->ip + cs_base)
14827 pr_cont(" <%02x>", c);
14828 else
14829 pr_cont(" %02x", c);
14830 @@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
14831 {
14832 unsigned short ud2;
14833
14834 + ip = ktla_ktva(ip);
14835 if (ip < PAGE_OFFSET)
14836 return 0;
14837 if (probe_kernel_address((unsigned short *)ip, ud2))
14838 @@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
14839
14840 return ud2 == 0x0b0f;
14841 }
14842 +
14843 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14844 +void pax_check_alloca(unsigned long size)
14845 +{
14846 + unsigned long sp = (unsigned long)&sp, stack_left;
14847 +
14848 + /* all kernel stacks are of the same size */
14849 + stack_left = sp & (THREAD_SIZE - 1);
14850 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14851 +}
14852 +EXPORT_SYMBOL(pax_check_alloca);
14853 +#endif
14854 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14855 index b653675..33190c0 100644
14856 --- a/arch/x86/kernel/dumpstack_64.c
14857 +++ b/arch/x86/kernel/dumpstack_64.c
14858 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14859 unsigned long *irq_stack_end =
14860 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14861 unsigned used = 0;
14862 - struct thread_info *tinfo;
14863 int graph = 0;
14864 unsigned long dummy;
14865 + void *stack_start;
14866
14867 if (!task)
14868 task = current;
14869 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14870 * current stack address. If the stacks consist of nested
14871 * exceptions
14872 */
14873 - tinfo = task_thread_info(task);
14874 for (;;) {
14875 char *id;
14876 unsigned long *estack_end;
14877 +
14878 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14879 &used, &id);
14880
14881 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14882 if (ops->stack(data, id) < 0)
14883 break;
14884
14885 - bp = ops->walk_stack(tinfo, stack, bp, ops,
14886 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14887 data, estack_end, &graph);
14888 ops->stack(data, "<EOE>");
14889 /*
14890 @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14891 * second-to-last pointer (index -2 to end) in the
14892 * exception stack:
14893 */
14894 + if ((u16)estack_end[-1] != __KERNEL_DS)
14895 + goto out;
14896 stack = (unsigned long *) estack_end[-2];
14897 continue;
14898 }
14899 @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14900 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14901 if (ops->stack(data, "IRQ") < 0)
14902 break;
14903 - bp = ops->walk_stack(tinfo, stack, bp,
14904 + bp = ops->walk_stack(task, irq_stack, stack, bp,
14905 ops, data, irq_stack_end, &graph);
14906 /*
14907 * We link to the next stack (which would be
14908 @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14909 /*
14910 * This handles the process stack:
14911 */
14912 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14913 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14914 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14915 +out:
14916 put_cpu();
14917 }
14918 EXPORT_SYMBOL(dump_trace);
14919 @@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
14920
14921 return ud2 == 0x0b0f;
14922 }
14923 +
14924 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14925 +void pax_check_alloca(unsigned long size)
14926 +{
14927 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14928 + unsigned cpu, used;
14929 + char *id;
14930 +
14931 + /* check the process stack first */
14932 + stack_start = (unsigned long)task_stack_page(current);
14933 + stack_end = stack_start + THREAD_SIZE;
14934 + if (likely(stack_start <= sp && sp < stack_end)) {
14935 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
14936 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14937 + return;
14938 + }
14939 +
14940 + cpu = get_cpu();
14941 +
14942 + /* check the irq stacks */
14943 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14944 + stack_start = stack_end - IRQ_STACK_SIZE;
14945 + if (stack_start <= sp && sp < stack_end) {
14946 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14947 + put_cpu();
14948 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14949 + return;
14950 + }
14951 +
14952 + /* check the exception stacks */
14953 + used = 0;
14954 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14955 + stack_start = stack_end - EXCEPTION_STKSZ;
14956 + if (stack_end && stack_start <= sp && sp < stack_end) {
14957 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14958 + put_cpu();
14959 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14960 + return;
14961 + }
14962 +
14963 + put_cpu();
14964 +
14965 + /* unknown stack */
14966 + BUG();
14967 +}
14968 +EXPORT_SYMBOL(pax_check_alloca);
14969 +#endif
14970 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14971 index 9b9f18b..9fcaa04 100644
14972 --- a/arch/x86/kernel/early_printk.c
14973 +++ b/arch/x86/kernel/early_printk.c
14974 @@ -7,6 +7,7 @@
14975 #include <linux/pci_regs.h>
14976 #include <linux/pci_ids.h>
14977 #include <linux/errno.h>
14978 +#include <linux/sched.h>
14979 #include <asm/io.h>
14980 #include <asm/processor.h>
14981 #include <asm/fcntl.h>
14982 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
14983 index 8f8e8ee..3617d6e 100644
14984 --- a/arch/x86/kernel/entry_32.S
14985 +++ b/arch/x86/kernel/entry_32.S
14986 @@ -176,13 +176,153 @@
14987 /*CFI_REL_OFFSET gs, PT_GS*/
14988 .endm
14989 .macro SET_KERNEL_GS reg
14990 +
14991 +#ifdef CONFIG_CC_STACKPROTECTOR
14992 movl $(__KERNEL_STACK_CANARY), \reg
14993 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14994 + movl $(__USER_DS), \reg
14995 +#else
14996 + xorl \reg, \reg
14997 +#endif
14998 +
14999 movl \reg, %gs
15000 .endm
15001
15002 #endif /* CONFIG_X86_32_LAZY_GS */
15003
15004 -.macro SAVE_ALL
15005 +.macro pax_enter_kernel
15006 +#ifdef CONFIG_PAX_KERNEXEC
15007 + call pax_enter_kernel
15008 +#endif
15009 +.endm
15010 +
15011 +.macro pax_exit_kernel
15012 +#ifdef CONFIG_PAX_KERNEXEC
15013 + call pax_exit_kernel
15014 +#endif
15015 +.endm
15016 +
15017 +#ifdef CONFIG_PAX_KERNEXEC
15018 +ENTRY(pax_enter_kernel)
15019 +#ifdef CONFIG_PARAVIRT
15020 + pushl %eax
15021 + pushl %ecx
15022 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
15023 + mov %eax, %esi
15024 +#else
15025 + mov %cr0, %esi
15026 +#endif
15027 + bts $16, %esi
15028 + jnc 1f
15029 + mov %cs, %esi
15030 + cmp $__KERNEL_CS, %esi
15031 + jz 3f
15032 + ljmp $__KERNEL_CS, $3f
15033 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
15034 +2:
15035 +#ifdef CONFIG_PARAVIRT
15036 + mov %esi, %eax
15037 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
15038 +#else
15039 + mov %esi, %cr0
15040 +#endif
15041 +3:
15042 +#ifdef CONFIG_PARAVIRT
15043 + popl %ecx
15044 + popl %eax
15045 +#endif
15046 + ret
15047 +ENDPROC(pax_enter_kernel)
15048 +
15049 +ENTRY(pax_exit_kernel)
15050 +#ifdef CONFIG_PARAVIRT
15051 + pushl %eax
15052 + pushl %ecx
15053 +#endif
15054 + mov %cs, %esi
15055 + cmp $__KERNEXEC_KERNEL_CS, %esi
15056 + jnz 2f
15057 +#ifdef CONFIG_PARAVIRT
15058 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
15059 + mov %eax, %esi
15060 +#else
15061 + mov %cr0, %esi
15062 +#endif
15063 + btr $16, %esi
15064 + ljmp $__KERNEL_CS, $1f
15065 +1:
15066 +#ifdef CONFIG_PARAVIRT
15067 + mov %esi, %eax
15068 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
15069 +#else
15070 + mov %esi, %cr0
15071 +#endif
15072 +2:
15073 +#ifdef CONFIG_PARAVIRT
15074 + popl %ecx
15075 + popl %eax
15076 +#endif
15077 + ret
15078 +ENDPROC(pax_exit_kernel)
15079 +#endif
15080 +
15081 +.macro pax_erase_kstack
15082 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15083 + call pax_erase_kstack
15084 +#endif
15085 +.endm
15086 +
15087 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15088 +/*
15089 + * ebp: thread_info
15090 + */
15091 +ENTRY(pax_erase_kstack)
15092 + pushl %edi
15093 + pushl %ecx
15094 + pushl %eax
15095 +
15096 + mov TI_lowest_stack(%ebp), %edi
15097 + mov $-0xBEEF, %eax
15098 + std
15099 +
15100 +1: mov %edi, %ecx
15101 + and $THREAD_SIZE_asm - 1, %ecx
15102 + shr $2, %ecx
15103 + repne scasl
15104 + jecxz 2f
15105 +
15106 + cmp $2*16, %ecx
15107 + jc 2f
15108 +
15109 + mov $2*16, %ecx
15110 + repe scasl
15111 + jecxz 2f
15112 + jne 1b
15113 +
15114 +2: cld
15115 + mov %esp, %ecx
15116 + sub %edi, %ecx
15117 +
15118 + cmp $THREAD_SIZE_asm, %ecx
15119 + jb 3f
15120 + ud2
15121 +3:
15122 +
15123 + shr $2, %ecx
15124 + rep stosl
15125 +
15126 + mov TI_task_thread_sp0(%ebp), %edi
15127 + sub $128, %edi
15128 + mov %edi, TI_lowest_stack(%ebp)
15129 +
15130 + popl %eax
15131 + popl %ecx
15132 + popl %edi
15133 + ret
15134 +ENDPROC(pax_erase_kstack)
15135 +#endif
15136 +
15137 +.macro __SAVE_ALL _DS
15138 cld
15139 PUSH_GS
15140 pushl_cfi %fs
15141 @@ -205,7 +345,7 @@
15142 CFI_REL_OFFSET ecx, 0
15143 pushl_cfi %ebx
15144 CFI_REL_OFFSET ebx, 0
15145 - movl $(__USER_DS), %edx
15146 + movl $\_DS, %edx
15147 movl %edx, %ds
15148 movl %edx, %es
15149 movl $(__KERNEL_PERCPU), %edx
15150 @@ -213,6 +353,15 @@
15151 SET_KERNEL_GS %edx
15152 .endm
15153
15154 +.macro SAVE_ALL
15155 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
15156 + __SAVE_ALL __KERNEL_DS
15157 + pax_enter_kernel
15158 +#else
15159 + __SAVE_ALL __USER_DS
15160 +#endif
15161 +.endm
15162 +
15163 .macro RESTORE_INT_REGS
15164 popl_cfi %ebx
15165 CFI_RESTORE ebx
15166 @@ -296,7 +445,7 @@ ENTRY(ret_from_fork)
15167 popfl_cfi
15168 jmp syscall_exit
15169 CFI_ENDPROC
15170 -END(ret_from_fork)
15171 +ENDPROC(ret_from_fork)
15172
15173 /*
15174 * Interrupt exit functions should be protected against kprobes
15175 @@ -329,7 +478,15 @@ ret_from_intr:
15176 andl $SEGMENT_RPL_MASK, %eax
15177 #endif
15178 cmpl $USER_RPL, %eax
15179 +
15180 +#ifdef CONFIG_PAX_KERNEXEC
15181 + jae resume_userspace
15182 +
15183 + pax_exit_kernel
15184 + jmp resume_kernel
15185 +#else
15186 jb resume_kernel # not returning to v8086 or userspace
15187 +#endif
15188
15189 ENTRY(resume_userspace)
15190 LOCKDEP_SYS_EXIT
15191 @@ -341,8 +498,8 @@ ENTRY(resume_userspace)
15192 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
15193 # int/exception return?
15194 jne work_pending
15195 - jmp restore_all
15196 -END(ret_from_exception)
15197 + jmp restore_all_pax
15198 +ENDPROC(ret_from_exception)
15199
15200 #ifdef CONFIG_PREEMPT
15201 ENTRY(resume_kernel)
15202 @@ -357,7 +514,7 @@ need_resched:
15203 jz restore_all
15204 call preempt_schedule_irq
15205 jmp need_resched
15206 -END(resume_kernel)
15207 +ENDPROC(resume_kernel)
15208 #endif
15209 CFI_ENDPROC
15210 /*
15211 @@ -391,28 +548,43 @@ sysenter_past_esp:
15212 /*CFI_REL_OFFSET cs, 0*/
15213 /*
15214 * Push current_thread_info()->sysenter_return to the stack.
15215 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
15216 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
15217 */
15218 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
15219 + pushl_cfi $0
15220 CFI_REL_OFFSET eip, 0
15221
15222 pushl_cfi %eax
15223 SAVE_ALL
15224 + GET_THREAD_INFO(%ebp)
15225 + movl TI_sysenter_return(%ebp),%ebp
15226 + movl %ebp,PT_EIP(%esp)
15227 ENABLE_INTERRUPTS(CLBR_NONE)
15228
15229 /*
15230 * Load the potential sixth argument from user stack.
15231 * Careful about security.
15232 */
15233 + movl PT_OLDESP(%esp),%ebp
15234 +
15235 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15236 + mov PT_OLDSS(%esp),%ds
15237 +1: movl %ds:(%ebp),%ebp
15238 + push %ss
15239 + pop %ds
15240 +#else
15241 cmpl $__PAGE_OFFSET-3,%ebp
15242 jae syscall_fault
15243 1: movl (%ebp),%ebp
15244 +#endif
15245 +
15246 movl %ebp,PT_EBP(%esp)
15247 _ASM_EXTABLE(1b,syscall_fault)
15248
15249 GET_THREAD_INFO(%ebp)
15250
15251 +#ifdef CONFIG_PAX_RANDKSTACK
15252 + pax_erase_kstack
15253 +#endif
15254 +
15255 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
15256 jnz sysenter_audit
15257 sysenter_do_call:
15258 @@ -427,12 +599,24 @@ sysenter_do_call:
15259 testl $_TIF_ALLWORK_MASK, %ecx
15260 jne sysexit_audit
15261 sysenter_exit:
15262 +
15263 +#ifdef CONFIG_PAX_RANDKSTACK
15264 + pushl_cfi %eax
15265 + movl %esp, %eax
15266 + call pax_randomize_kstack
15267 + popl_cfi %eax
15268 +#endif
15269 +
15270 + pax_erase_kstack
15271 +
15272 /* if something modifies registers it must also disable sysexit */
15273 movl PT_EIP(%esp), %edx
15274 movl PT_OLDESP(%esp), %ecx
15275 xorl %ebp,%ebp
15276 TRACE_IRQS_ON
15277 1: mov PT_FS(%esp), %fs
15278 +2: mov PT_DS(%esp), %ds
15279 +3: mov PT_ES(%esp), %es
15280 PTGS_TO_GS
15281 ENABLE_INTERRUPTS_SYSEXIT
15282
15283 @@ -449,6 +633,9 @@ sysenter_audit:
15284 movl %eax,%edx /* 2nd arg: syscall number */
15285 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
15286 call __audit_syscall_entry
15287 +
15288 + pax_erase_kstack
15289 +
15290 pushl_cfi %ebx
15291 movl PT_EAX(%esp),%eax /* reload syscall number */
15292 jmp sysenter_do_call
15293 @@ -474,10 +661,16 @@ sysexit_audit:
15294
15295 CFI_ENDPROC
15296 .pushsection .fixup,"ax"
15297 -2: movl $0,PT_FS(%esp)
15298 +4: movl $0,PT_FS(%esp)
15299 + jmp 1b
15300 +5: movl $0,PT_DS(%esp)
15301 + jmp 1b
15302 +6: movl $0,PT_ES(%esp)
15303 jmp 1b
15304 .popsection
15305 - _ASM_EXTABLE(1b,2b)
15306 + _ASM_EXTABLE(1b,4b)
15307 + _ASM_EXTABLE(2b,5b)
15308 + _ASM_EXTABLE(3b,6b)
15309 PTGS_TO_GS_EX
15310 ENDPROC(ia32_sysenter_target)
15311
15312 @@ -491,6 +684,11 @@ ENTRY(system_call)
15313 pushl_cfi %eax # save orig_eax
15314 SAVE_ALL
15315 GET_THREAD_INFO(%ebp)
15316 +
15317 +#ifdef CONFIG_PAX_RANDKSTACK
15318 + pax_erase_kstack
15319 +#endif
15320 +
15321 # system call tracing in operation / emulation
15322 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
15323 jnz syscall_trace_entry
15324 @@ -509,6 +707,15 @@ syscall_exit:
15325 testl $_TIF_ALLWORK_MASK, %ecx # current->work
15326 jne syscall_exit_work
15327
15328 +restore_all_pax:
15329 +
15330 +#ifdef CONFIG_PAX_RANDKSTACK
15331 + movl %esp, %eax
15332 + call pax_randomize_kstack
15333 +#endif
15334 +
15335 + pax_erase_kstack
15336 +
15337 restore_all:
15338 TRACE_IRQS_IRET
15339 restore_all_notrace:
15340 @@ -565,14 +772,34 @@ ldt_ss:
15341 * compensating for the offset by changing to the ESPFIX segment with
15342 * a base address that matches for the difference.
15343 */
15344 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
15345 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
15346 mov %esp, %edx /* load kernel esp */
15347 mov PT_OLDESP(%esp), %eax /* load userspace esp */
15348 mov %dx, %ax /* eax: new kernel esp */
15349 sub %eax, %edx /* offset (low word is 0) */
15350 +#ifdef CONFIG_SMP
15351 + movl PER_CPU_VAR(cpu_number), %ebx
15352 + shll $PAGE_SHIFT_asm, %ebx
15353 + addl $cpu_gdt_table, %ebx
15354 +#else
15355 + movl $cpu_gdt_table, %ebx
15356 +#endif
15357 shr $16, %edx
15358 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
15359 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
15360 +
15361 +#ifdef CONFIG_PAX_KERNEXEC
15362 + mov %cr0, %esi
15363 + btr $16, %esi
15364 + mov %esi, %cr0
15365 +#endif
15366 +
15367 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
15368 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
15369 +
15370 +#ifdef CONFIG_PAX_KERNEXEC
15371 + bts $16, %esi
15372 + mov %esi, %cr0
15373 +#endif
15374 +
15375 pushl_cfi $__ESPFIX_SS
15376 pushl_cfi %eax /* new kernel esp */
15377 /* Disable interrupts, but do not irqtrace this section: we
15378 @@ -601,35 +828,23 @@ work_resched:
15379 movl TI_flags(%ebp), %ecx
15380 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
15381 # than syscall tracing?
15382 - jz restore_all
15383 + jz restore_all_pax
15384 testb $_TIF_NEED_RESCHED, %cl
15385 jnz work_resched
15386
15387 work_notifysig: # deal with pending signals and
15388 # notify-resume requests
15389 + movl %esp, %eax
15390 #ifdef CONFIG_VM86
15391 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
15392 - movl %esp, %eax
15393 - jne work_notifysig_v86 # returning to kernel-space or
15394 + jz 1f # returning to kernel-space or
15395 # vm86-space
15396 - TRACE_IRQS_ON
15397 - ENABLE_INTERRUPTS(CLBR_NONE)
15398 - movb PT_CS(%esp), %bl
15399 - andb $SEGMENT_RPL_MASK, %bl
15400 - cmpb $USER_RPL, %bl
15401 - jb resume_kernel
15402 - xorl %edx, %edx
15403 - call do_notify_resume
15404 - jmp resume_userspace
15405
15406 - ALIGN
15407 -work_notifysig_v86:
15408 pushl_cfi %ecx # save ti_flags for do_notify_resume
15409 call save_v86_state # %eax contains pt_regs pointer
15410 popl_cfi %ecx
15411 movl %eax, %esp
15412 -#else
15413 - movl %esp, %eax
15414 +1:
15415 #endif
15416 TRACE_IRQS_ON
15417 ENABLE_INTERRUPTS(CLBR_NONE)
15418 @@ -640,7 +855,7 @@ work_notifysig_v86:
15419 xorl %edx, %edx
15420 call do_notify_resume
15421 jmp resume_userspace
15422 -END(work_pending)
15423 +ENDPROC(work_pending)
15424
15425 # perform syscall exit tracing
15426 ALIGN
15427 @@ -648,11 +863,14 @@ syscall_trace_entry:
15428 movl $-ENOSYS,PT_EAX(%esp)
15429 movl %esp, %eax
15430 call syscall_trace_enter
15431 +
15432 + pax_erase_kstack
15433 +
15434 /* What it returned is what we'll actually use. */
15435 cmpl $(NR_syscalls), %eax
15436 jnae syscall_call
15437 jmp syscall_exit
15438 -END(syscall_trace_entry)
15439 +ENDPROC(syscall_trace_entry)
15440
15441 # perform syscall exit tracing
15442 ALIGN
15443 @@ -665,20 +883,24 @@ syscall_exit_work:
15444 movl %esp, %eax
15445 call syscall_trace_leave
15446 jmp resume_userspace
15447 -END(syscall_exit_work)
15448 +ENDPROC(syscall_exit_work)
15449 CFI_ENDPROC
15450
15451 RING0_INT_FRAME # can't unwind into user space anyway
15452 syscall_fault:
15453 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15454 + push %ss
15455 + pop %ds
15456 +#endif
15457 GET_THREAD_INFO(%ebp)
15458 movl $-EFAULT,PT_EAX(%esp)
15459 jmp resume_userspace
15460 -END(syscall_fault)
15461 +ENDPROC(syscall_fault)
15462
15463 syscall_badsys:
15464 movl $-ENOSYS,PT_EAX(%esp)
15465 jmp resume_userspace
15466 -END(syscall_badsys)
15467 +ENDPROC(syscall_badsys)
15468 CFI_ENDPROC
15469 /*
15470 * End of kprobes section
15471 @@ -750,6 +972,36 @@ ENTRY(ptregs_clone)
15472 CFI_ENDPROC
15473 ENDPROC(ptregs_clone)
15474
15475 + ALIGN;
15476 +ENTRY(kernel_execve)
15477 + CFI_STARTPROC
15478 + pushl_cfi %ebp
15479 + sub $PT_OLDSS+4,%esp
15480 + pushl_cfi %edi
15481 + pushl_cfi %ecx
15482 + pushl_cfi %eax
15483 + lea 3*4(%esp),%edi
15484 + mov $PT_OLDSS/4+1,%ecx
15485 + xorl %eax,%eax
15486 + rep stosl
15487 + popl_cfi %eax
15488 + popl_cfi %ecx
15489 + popl_cfi %edi
15490 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
15491 + pushl_cfi %esp
15492 + call sys_execve
15493 + add $4,%esp
15494 + CFI_ADJUST_CFA_OFFSET -4
15495 + GET_THREAD_INFO(%ebp)
15496 + test %eax,%eax
15497 + jz syscall_exit
15498 + add $PT_OLDSS+4,%esp
15499 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
15500 + popl_cfi %ebp
15501 + ret
15502 + CFI_ENDPROC
15503 +ENDPROC(kernel_execve)
15504 +
15505 .macro FIXUP_ESPFIX_STACK
15506 /*
15507 * Switch back for ESPFIX stack to the normal zerobased stack
15508 @@ -759,8 +1011,15 @@ ENDPROC(ptregs_clone)
15509 * normal stack and adjusts ESP with the matching offset.
15510 */
15511 /* fixup the stack */
15512 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
15513 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
15514 +#ifdef CONFIG_SMP
15515 + movl PER_CPU_VAR(cpu_number), %ebx
15516 + shll $PAGE_SHIFT_asm, %ebx
15517 + addl $cpu_gdt_table, %ebx
15518 +#else
15519 + movl $cpu_gdt_table, %ebx
15520 +#endif
15521 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
15522 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
15523 shl $16, %eax
15524 addl %esp, %eax /* the adjusted stack pointer */
15525 pushl_cfi $__KERNEL_DS
15526 @@ -813,7 +1072,7 @@ vector=vector+1
15527 .endr
15528 2: jmp common_interrupt
15529 .endr
15530 -END(irq_entries_start)
15531 +ENDPROC(irq_entries_start)
15532
15533 .previous
15534 END(interrupt)
15535 @@ -861,7 +1120,7 @@ ENTRY(coprocessor_error)
15536 pushl_cfi $do_coprocessor_error
15537 jmp error_code
15538 CFI_ENDPROC
15539 -END(coprocessor_error)
15540 +ENDPROC(coprocessor_error)
15541
15542 ENTRY(simd_coprocessor_error)
15543 RING0_INT_FRAME
15544 @@ -882,7 +1141,7 @@ ENTRY(simd_coprocessor_error)
15545 #endif
15546 jmp error_code
15547 CFI_ENDPROC
15548 -END(simd_coprocessor_error)
15549 +ENDPROC(simd_coprocessor_error)
15550
15551 ENTRY(device_not_available)
15552 RING0_INT_FRAME
15553 @@ -890,18 +1149,18 @@ ENTRY(device_not_available)
15554 pushl_cfi $do_device_not_available
15555 jmp error_code
15556 CFI_ENDPROC
15557 -END(device_not_available)
15558 +ENDPROC(device_not_available)
15559
15560 #ifdef CONFIG_PARAVIRT
15561 ENTRY(native_iret)
15562 iret
15563 _ASM_EXTABLE(native_iret, iret_exc)
15564 -END(native_iret)
15565 +ENDPROC(native_iret)
15566
15567 ENTRY(native_irq_enable_sysexit)
15568 sti
15569 sysexit
15570 -END(native_irq_enable_sysexit)
15571 +ENDPROC(native_irq_enable_sysexit)
15572 #endif
15573
15574 ENTRY(overflow)
15575 @@ -910,7 +1169,7 @@ ENTRY(overflow)
15576 pushl_cfi $do_overflow
15577 jmp error_code
15578 CFI_ENDPROC
15579 -END(overflow)
15580 +ENDPROC(overflow)
15581
15582 ENTRY(bounds)
15583 RING0_INT_FRAME
15584 @@ -918,7 +1177,7 @@ ENTRY(bounds)
15585 pushl_cfi $do_bounds
15586 jmp error_code
15587 CFI_ENDPROC
15588 -END(bounds)
15589 +ENDPROC(bounds)
15590
15591 ENTRY(invalid_op)
15592 RING0_INT_FRAME
15593 @@ -926,7 +1185,7 @@ ENTRY(invalid_op)
15594 pushl_cfi $do_invalid_op
15595 jmp error_code
15596 CFI_ENDPROC
15597 -END(invalid_op)
15598 +ENDPROC(invalid_op)
15599
15600 ENTRY(coprocessor_segment_overrun)
15601 RING0_INT_FRAME
15602 @@ -934,35 +1193,35 @@ ENTRY(coprocessor_segment_overrun)
15603 pushl_cfi $do_coprocessor_segment_overrun
15604 jmp error_code
15605 CFI_ENDPROC
15606 -END(coprocessor_segment_overrun)
15607 +ENDPROC(coprocessor_segment_overrun)
15608
15609 ENTRY(invalid_TSS)
15610 RING0_EC_FRAME
15611 pushl_cfi $do_invalid_TSS
15612 jmp error_code
15613 CFI_ENDPROC
15614 -END(invalid_TSS)
15615 +ENDPROC(invalid_TSS)
15616
15617 ENTRY(segment_not_present)
15618 RING0_EC_FRAME
15619 pushl_cfi $do_segment_not_present
15620 jmp error_code
15621 CFI_ENDPROC
15622 -END(segment_not_present)
15623 +ENDPROC(segment_not_present)
15624
15625 ENTRY(stack_segment)
15626 RING0_EC_FRAME
15627 pushl_cfi $do_stack_segment
15628 jmp error_code
15629 CFI_ENDPROC
15630 -END(stack_segment)
15631 +ENDPROC(stack_segment)
15632
15633 ENTRY(alignment_check)
15634 RING0_EC_FRAME
15635 pushl_cfi $do_alignment_check
15636 jmp error_code
15637 CFI_ENDPROC
15638 -END(alignment_check)
15639 +ENDPROC(alignment_check)
15640
15641 ENTRY(divide_error)
15642 RING0_INT_FRAME
15643 @@ -970,7 +1229,7 @@ ENTRY(divide_error)
15644 pushl_cfi $do_divide_error
15645 jmp error_code
15646 CFI_ENDPROC
15647 -END(divide_error)
15648 +ENDPROC(divide_error)
15649
15650 #ifdef CONFIG_X86_MCE
15651 ENTRY(machine_check)
15652 @@ -979,7 +1238,7 @@ ENTRY(machine_check)
15653 pushl_cfi machine_check_vector
15654 jmp error_code
15655 CFI_ENDPROC
15656 -END(machine_check)
15657 +ENDPROC(machine_check)
15658 #endif
15659
15660 ENTRY(spurious_interrupt_bug)
15661 @@ -988,7 +1247,7 @@ ENTRY(spurious_interrupt_bug)
15662 pushl_cfi $do_spurious_interrupt_bug
15663 jmp error_code
15664 CFI_ENDPROC
15665 -END(spurious_interrupt_bug)
15666 +ENDPROC(spurious_interrupt_bug)
15667 /*
15668 * End of kprobes section
15669 */
15670 @@ -1102,7 +1361,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
15671
15672 ENTRY(mcount)
15673 ret
15674 -END(mcount)
15675 +ENDPROC(mcount)
15676
15677 ENTRY(ftrace_caller)
15678 cmpl $0, function_trace_stop
15679 @@ -1131,7 +1390,7 @@ ftrace_graph_call:
15680 .globl ftrace_stub
15681 ftrace_stub:
15682 ret
15683 -END(ftrace_caller)
15684 +ENDPROC(ftrace_caller)
15685
15686 #else /* ! CONFIG_DYNAMIC_FTRACE */
15687
15688 @@ -1167,7 +1426,7 @@ trace:
15689 popl %ecx
15690 popl %eax
15691 jmp ftrace_stub
15692 -END(mcount)
15693 +ENDPROC(mcount)
15694 #endif /* CONFIG_DYNAMIC_FTRACE */
15695 #endif /* CONFIG_FUNCTION_TRACER */
15696
15697 @@ -1188,7 +1447,7 @@ ENTRY(ftrace_graph_caller)
15698 popl %ecx
15699 popl %eax
15700 ret
15701 -END(ftrace_graph_caller)
15702 +ENDPROC(ftrace_graph_caller)
15703
15704 .globl return_to_handler
15705 return_to_handler:
15706 @@ -1243,15 +1502,18 @@ error_code:
15707 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15708 REG_TO_PTGS %ecx
15709 SET_KERNEL_GS %ecx
15710 - movl $(__USER_DS), %ecx
15711 + movl $(__KERNEL_DS), %ecx
15712 movl %ecx, %ds
15713 movl %ecx, %es
15714 +
15715 + pax_enter_kernel
15716 +
15717 TRACE_IRQS_OFF
15718 movl %esp,%eax # pt_regs pointer
15719 call *%edi
15720 jmp ret_from_exception
15721 CFI_ENDPROC
15722 -END(page_fault)
15723 +ENDPROC(page_fault)
15724
15725 /*
15726 * Debug traps and NMI can happen at the one SYSENTER instruction
15727 @@ -1293,7 +1555,7 @@ debug_stack_correct:
15728 call do_debug
15729 jmp ret_from_exception
15730 CFI_ENDPROC
15731 -END(debug)
15732 +ENDPROC(debug)
15733
15734 /*
15735 * NMI is doubly nasty. It can happen _while_ we're handling
15736 @@ -1330,6 +1592,9 @@ nmi_stack_correct:
15737 xorl %edx,%edx # zero error code
15738 movl %esp,%eax # pt_regs pointer
15739 call do_nmi
15740 +
15741 + pax_exit_kernel
15742 +
15743 jmp restore_all_notrace
15744 CFI_ENDPROC
15745
15746 @@ -1366,12 +1631,15 @@ nmi_espfix_stack:
15747 FIXUP_ESPFIX_STACK # %eax == %esp
15748 xorl %edx,%edx # zero error code
15749 call do_nmi
15750 +
15751 + pax_exit_kernel
15752 +
15753 RESTORE_REGS
15754 lss 12+4(%esp), %esp # back to espfix stack
15755 CFI_ADJUST_CFA_OFFSET -24
15756 jmp irq_return
15757 CFI_ENDPROC
15758 -END(nmi)
15759 +ENDPROC(nmi)
15760
15761 ENTRY(int3)
15762 RING0_INT_FRAME
15763 @@ -1383,14 +1651,14 @@ ENTRY(int3)
15764 call do_int3
15765 jmp ret_from_exception
15766 CFI_ENDPROC
15767 -END(int3)
15768 +ENDPROC(int3)
15769
15770 ENTRY(general_protection)
15771 RING0_EC_FRAME
15772 pushl_cfi $do_general_protection
15773 jmp error_code
15774 CFI_ENDPROC
15775 -END(general_protection)
15776 +ENDPROC(general_protection)
15777
15778 #ifdef CONFIG_KVM_GUEST
15779 ENTRY(async_page_fault)
15780 @@ -1398,7 +1666,7 @@ ENTRY(async_page_fault)
15781 pushl_cfi $do_async_page_fault
15782 jmp error_code
15783 CFI_ENDPROC
15784 -END(async_page_fault)
15785 +ENDPROC(async_page_fault)
15786 #endif
15787
15788 /*
15789 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15790 index dcdd0ea..de0bb2d 100644
15791 --- a/arch/x86/kernel/entry_64.S
15792 +++ b/arch/x86/kernel/entry_64.S
15793 @@ -57,6 +57,8 @@
15794 #include <asm/percpu.h>
15795 #include <asm/asm.h>
15796 #include <linux/err.h>
15797 +#include <asm/pgtable.h>
15798 +#include <asm/alternative-asm.h>
15799
15800 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15801 #include <linux/elf-em.h>
15802 @@ -70,8 +72,9 @@
15803 #ifdef CONFIG_FUNCTION_TRACER
15804 #ifdef CONFIG_DYNAMIC_FTRACE
15805 ENTRY(mcount)
15806 + pax_force_retaddr
15807 retq
15808 -END(mcount)
15809 +ENDPROC(mcount)
15810
15811 ENTRY(ftrace_caller)
15812 cmpl $0, function_trace_stop
15813 @@ -94,8 +97,9 @@ GLOBAL(ftrace_graph_call)
15814 #endif
15815
15816 GLOBAL(ftrace_stub)
15817 + pax_force_retaddr
15818 retq
15819 -END(ftrace_caller)
15820 +ENDPROC(ftrace_caller)
15821
15822 #else /* ! CONFIG_DYNAMIC_FTRACE */
15823 ENTRY(mcount)
15824 @@ -114,6 +118,7 @@ ENTRY(mcount)
15825 #endif
15826
15827 GLOBAL(ftrace_stub)
15828 + pax_force_retaddr
15829 retq
15830
15831 trace:
15832 @@ -123,12 +128,13 @@ trace:
15833 movq 8(%rbp), %rsi
15834 subq $MCOUNT_INSN_SIZE, %rdi
15835
15836 + pax_force_fptr ftrace_trace_function
15837 call *ftrace_trace_function
15838
15839 MCOUNT_RESTORE_FRAME
15840
15841 jmp ftrace_stub
15842 -END(mcount)
15843 +ENDPROC(mcount)
15844 #endif /* CONFIG_DYNAMIC_FTRACE */
15845 #endif /* CONFIG_FUNCTION_TRACER */
15846
15847 @@ -148,8 +154,9 @@ ENTRY(ftrace_graph_caller)
15848
15849 MCOUNT_RESTORE_FRAME
15850
15851 + pax_force_retaddr
15852 retq
15853 -END(ftrace_graph_caller)
15854 +ENDPROC(ftrace_graph_caller)
15855
15856 GLOBAL(return_to_handler)
15857 subq $24, %rsp
15858 @@ -165,6 +172,7 @@ GLOBAL(return_to_handler)
15859 movq 8(%rsp), %rdx
15860 movq (%rsp), %rax
15861 addq $24, %rsp
15862 + pax_force_fptr %rdi
15863 jmp *%rdi
15864 #endif
15865
15866 @@ -180,6 +188,280 @@ ENTRY(native_usergs_sysret64)
15867 ENDPROC(native_usergs_sysret64)
15868 #endif /* CONFIG_PARAVIRT */
15869
15870 + .macro ljmpq sel, off
15871 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15872 + .byte 0x48; ljmp *1234f(%rip)
15873 + .pushsection .rodata
15874 + .align 16
15875 + 1234: .quad \off; .word \sel
15876 + .popsection
15877 +#else
15878 + pushq $\sel
15879 + pushq $\off
15880 + lretq
15881 +#endif
15882 + .endm
15883 +
15884 + .macro pax_enter_kernel
15885 + pax_set_fptr_mask
15886 +#ifdef CONFIG_PAX_KERNEXEC
15887 + call pax_enter_kernel
15888 +#endif
15889 + .endm
15890 +
15891 + .macro pax_exit_kernel
15892 +#ifdef CONFIG_PAX_KERNEXEC
15893 + call pax_exit_kernel
15894 +#endif
15895 + .endm
15896 +
15897 +#ifdef CONFIG_PAX_KERNEXEC
15898 +ENTRY(pax_enter_kernel)
15899 + pushq %rdi
15900 +
15901 +#ifdef CONFIG_PARAVIRT
15902 + PV_SAVE_REGS(CLBR_RDI)
15903 +#endif
15904 +
15905 + GET_CR0_INTO_RDI
15906 + bts $16,%rdi
15907 + jnc 3f
15908 + mov %cs,%edi
15909 + cmp $__KERNEL_CS,%edi
15910 + jnz 2f
15911 +1:
15912 +
15913 +#ifdef CONFIG_PARAVIRT
15914 + PV_RESTORE_REGS(CLBR_RDI)
15915 +#endif
15916 +
15917 + popq %rdi
15918 + pax_force_retaddr
15919 + retq
15920 +
15921 +2: ljmpq __KERNEL_CS,1f
15922 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
15923 +4: SET_RDI_INTO_CR0
15924 + jmp 1b
15925 +ENDPROC(pax_enter_kernel)
15926 +
15927 +ENTRY(pax_exit_kernel)
15928 + pushq %rdi
15929 +
15930 +#ifdef CONFIG_PARAVIRT
15931 + PV_SAVE_REGS(CLBR_RDI)
15932 +#endif
15933 +
15934 + mov %cs,%rdi
15935 + cmp $__KERNEXEC_KERNEL_CS,%edi
15936 + jz 2f
15937 +1:
15938 +
15939 +#ifdef CONFIG_PARAVIRT
15940 + PV_RESTORE_REGS(CLBR_RDI);
15941 +#endif
15942 +
15943 + popq %rdi
15944 + pax_force_retaddr
15945 + retq
15946 +
15947 +2: GET_CR0_INTO_RDI
15948 + btr $16,%rdi
15949 + ljmpq __KERNEL_CS,3f
15950 +3: SET_RDI_INTO_CR0
15951 + jmp 1b
15952 +#ifdef CONFIG_PARAVIRT
15953 + PV_RESTORE_REGS(CLBR_RDI);
15954 +#endif
15955 +
15956 + popq %rdi
15957 + pax_force_retaddr
15958 + retq
15959 +ENDPROC(pax_exit_kernel)
15960 +#endif
15961 +
15962 + .macro pax_enter_kernel_user
15963 + pax_set_fptr_mask
15964 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15965 + call pax_enter_kernel_user
15966 +#endif
15967 + .endm
15968 +
15969 + .macro pax_exit_kernel_user
15970 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15971 + call pax_exit_kernel_user
15972 +#endif
15973 +#ifdef CONFIG_PAX_RANDKSTACK
15974 + pushq %rax
15975 + call pax_randomize_kstack
15976 + popq %rax
15977 +#endif
15978 + .endm
15979 +
15980 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15981 +ENTRY(pax_enter_kernel_user)
15982 + pushq %rdi
15983 + pushq %rbx
15984 +
15985 +#ifdef CONFIG_PARAVIRT
15986 + PV_SAVE_REGS(CLBR_RDI)
15987 +#endif
15988 +
15989 + GET_CR3_INTO_RDI
15990 + mov %rdi,%rbx
15991 + add $__START_KERNEL_map,%rbx
15992 + sub phys_base(%rip),%rbx
15993 +
15994 +#ifdef CONFIG_PARAVIRT
15995 + pushq %rdi
15996 + cmpl $0, pv_info+PARAVIRT_enabled
15997 + jz 1f
15998 + i = 0
15999 + .rept USER_PGD_PTRS
16000 + mov i*8(%rbx),%rsi
16001 + mov $0,%sil
16002 + lea i*8(%rbx),%rdi
16003 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
16004 + i = i + 1
16005 + .endr
16006 + jmp 2f
16007 +1:
16008 +#endif
16009 +
16010 + i = 0
16011 + .rept USER_PGD_PTRS
16012 + movb $0,i*8(%rbx)
16013 + i = i + 1
16014 + .endr
16015 +
16016 +#ifdef CONFIG_PARAVIRT
16017 +2: popq %rdi
16018 +#endif
16019 + SET_RDI_INTO_CR3
16020 +
16021 +#ifdef CONFIG_PAX_KERNEXEC
16022 + GET_CR0_INTO_RDI
16023 + bts $16,%rdi
16024 + SET_RDI_INTO_CR0
16025 +#endif
16026 +
16027 +#ifdef CONFIG_PARAVIRT
16028 + PV_RESTORE_REGS(CLBR_RDI)
16029 +#endif
16030 +
16031 + popq %rbx
16032 + popq %rdi
16033 + pax_force_retaddr
16034 + retq
16035 +ENDPROC(pax_enter_kernel_user)
16036 +
16037 +ENTRY(pax_exit_kernel_user)
16038 + push %rdi
16039 +
16040 +#ifdef CONFIG_PARAVIRT
16041 + pushq %rbx
16042 + PV_SAVE_REGS(CLBR_RDI)
16043 +#endif
16044 +
16045 +#ifdef CONFIG_PAX_KERNEXEC
16046 + GET_CR0_INTO_RDI
16047 + btr $16,%rdi
16048 + SET_RDI_INTO_CR0
16049 +#endif
16050 +
16051 + GET_CR3_INTO_RDI
16052 + add $__START_KERNEL_map,%rdi
16053 + sub phys_base(%rip),%rdi
16054 +
16055 +#ifdef CONFIG_PARAVIRT
16056 + cmpl $0, pv_info+PARAVIRT_enabled
16057 + jz 1f
16058 + mov %rdi,%rbx
16059 + i = 0
16060 + .rept USER_PGD_PTRS
16061 + mov i*8(%rbx),%rsi
16062 + mov $0x67,%sil
16063 + lea i*8(%rbx),%rdi
16064 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
16065 + i = i + 1
16066 + .endr
16067 + jmp 2f
16068 +1:
16069 +#endif
16070 +
16071 + i = 0
16072 + .rept USER_PGD_PTRS
16073 + movb $0x67,i*8(%rdi)
16074 + i = i + 1
16075 + .endr
16076 +
16077 +#ifdef CONFIG_PARAVIRT
16078 +2: PV_RESTORE_REGS(CLBR_RDI)
16079 + popq %rbx
16080 +#endif
16081 +
16082 + popq %rdi
16083 + pax_force_retaddr
16084 + retq
16085 +ENDPROC(pax_exit_kernel_user)
16086 +#endif
16087 +
16088 +.macro pax_erase_kstack
16089 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16090 + call pax_erase_kstack
16091 +#endif
16092 +.endm
16093 +
16094 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16095 +ENTRY(pax_erase_kstack)
16096 + pushq %rdi
16097 + pushq %rcx
16098 + pushq %rax
16099 + pushq %r11
16100 +
16101 + GET_THREAD_INFO(%r11)
16102 + mov TI_lowest_stack(%r11), %rdi
16103 + mov $-0xBEEF, %rax
16104 + std
16105 +
16106 +1: mov %edi, %ecx
16107 + and $THREAD_SIZE_asm - 1, %ecx
16108 + shr $3, %ecx
16109 + repne scasq
16110 + jecxz 2f
16111 +
16112 + cmp $2*8, %ecx
16113 + jc 2f
16114 +
16115 + mov $2*8, %ecx
16116 + repe scasq
16117 + jecxz 2f
16118 + jne 1b
16119 +
16120 +2: cld
16121 + mov %esp, %ecx
16122 + sub %edi, %ecx
16123 +
16124 + cmp $THREAD_SIZE_asm, %rcx
16125 + jb 3f
16126 + ud2
16127 +3:
16128 +
16129 + shr $3, %ecx
16130 + rep stosq
16131 +
16132 + mov TI_task_thread_sp0(%r11), %rdi
16133 + sub $256, %rdi
16134 + mov %rdi, TI_lowest_stack(%r11)
16135 +
16136 + popq %r11
16137 + popq %rax
16138 + popq %rcx
16139 + popq %rdi
16140 + pax_force_retaddr
16141 + ret
16142 +ENDPROC(pax_erase_kstack)
16143 +#endif
16144
16145 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
16146 #ifdef CONFIG_TRACE_IRQFLAGS
16147 @@ -271,8 +553,8 @@ ENDPROC(native_usergs_sysret64)
16148 .endm
16149
16150 .macro UNFAKE_STACK_FRAME
16151 - addq $8*6, %rsp
16152 - CFI_ADJUST_CFA_OFFSET -(6*8)
16153 + addq $8*6 + ARG_SKIP, %rsp
16154 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
16155 .endm
16156
16157 /*
16158 @@ -359,7 +641,7 @@ ENDPROC(native_usergs_sysret64)
16159 movq %rsp, %rsi
16160
16161 leaq -RBP(%rsp),%rdi /* arg1 for handler */
16162 - testl $3, CS-RBP(%rsi)
16163 + testb $3, CS-RBP(%rsi)
16164 je 1f
16165 SWAPGS
16166 /*
16167 @@ -394,9 +676,10 @@ ENTRY(save_rest)
16168 movq_cfi r15, R15+16
16169 movq %r11, 8(%rsp) /* return address */
16170 FIXUP_TOP_OF_STACK %r11, 16
16171 + pax_force_retaddr
16172 ret
16173 CFI_ENDPROC
16174 -END(save_rest)
16175 +ENDPROC(save_rest)
16176
16177 /* save complete stack frame */
16178 .pushsection .kprobes.text, "ax"
16179 @@ -425,9 +708,10 @@ ENTRY(save_paranoid)
16180 js 1f /* negative -> in kernel */
16181 SWAPGS
16182 xorl %ebx,%ebx
16183 -1: ret
16184 +1: pax_force_retaddr_bts
16185 + ret
16186 CFI_ENDPROC
16187 -END(save_paranoid)
16188 +ENDPROC(save_paranoid)
16189 .popsection
16190
16191 /*
16192 @@ -449,7 +733,7 @@ ENTRY(ret_from_fork)
16193
16194 RESTORE_REST
16195
16196 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16197 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16198 jz retint_restore_args
16199
16200 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
16201 @@ -459,7 +743,7 @@ ENTRY(ret_from_fork)
16202 jmp ret_from_sys_call # go to the SYSRET fastpath
16203
16204 CFI_ENDPROC
16205 -END(ret_from_fork)
16206 +ENDPROC(ret_from_fork)
16207
16208 /*
16209 * System call entry. Up to 6 arguments in registers are supported.
16210 @@ -495,7 +779,7 @@ END(ret_from_fork)
16211 ENTRY(system_call)
16212 CFI_STARTPROC simple
16213 CFI_SIGNAL_FRAME
16214 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
16215 + CFI_DEF_CFA rsp,0
16216 CFI_REGISTER rip,rcx
16217 /*CFI_REGISTER rflags,r11*/
16218 SWAPGS_UNSAFE_STACK
16219 @@ -508,16 +792,23 @@ GLOBAL(system_call_after_swapgs)
16220
16221 movq %rsp,PER_CPU_VAR(old_rsp)
16222 movq PER_CPU_VAR(kernel_stack),%rsp
16223 + SAVE_ARGS 8*6,0
16224 + pax_enter_kernel_user
16225 +
16226 +#ifdef CONFIG_PAX_RANDKSTACK
16227 + pax_erase_kstack
16228 +#endif
16229 +
16230 /*
16231 * No need to follow this irqs off/on section - it's straight
16232 * and short:
16233 */
16234 ENABLE_INTERRUPTS(CLBR_NONE)
16235 - SAVE_ARGS 8,0
16236 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
16237 movq %rcx,RIP-ARGOFFSET(%rsp)
16238 CFI_REL_OFFSET rip,RIP-ARGOFFSET
16239 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16240 + GET_THREAD_INFO(%rcx)
16241 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
16242 jnz tracesys
16243 system_call_fastpath:
16244 #if __SYSCALL_MASK == ~0
16245 @@ -527,7 +818,7 @@ system_call_fastpath:
16246 cmpl $__NR_syscall_max,%eax
16247 #endif
16248 ja badsys
16249 - movq %r10,%rcx
16250 + movq R10-ARGOFFSET(%rsp),%rcx
16251 call *sys_call_table(,%rax,8) # XXX: rip relative
16252 movq %rax,RAX-ARGOFFSET(%rsp)
16253 /*
16254 @@ -541,10 +832,13 @@ sysret_check:
16255 LOCKDEP_SYS_EXIT
16256 DISABLE_INTERRUPTS(CLBR_NONE)
16257 TRACE_IRQS_OFF
16258 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
16259 + GET_THREAD_INFO(%rcx)
16260 + movl TI_flags(%rcx),%edx
16261 andl %edi,%edx
16262 jnz sysret_careful
16263 CFI_REMEMBER_STATE
16264 + pax_exit_kernel_user
16265 + pax_erase_kstack
16266 /*
16267 * sysretq will re-enable interrupts:
16268 */
16269 @@ -596,14 +890,18 @@ badsys:
16270 * jump back to the normal fast path.
16271 */
16272 auditsys:
16273 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
16274 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
16275 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
16276 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
16277 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
16278 movq %rax,%rsi /* 2nd arg: syscall number */
16279 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
16280 call __audit_syscall_entry
16281 +
16282 + pax_erase_kstack
16283 +
16284 LOAD_ARGS 0 /* reload call-clobbered registers */
16285 + pax_set_fptr_mask
16286 jmp system_call_fastpath
16287
16288 /*
16289 @@ -624,7 +922,7 @@ sysret_audit:
16290 /* Do syscall tracing */
16291 tracesys:
16292 #ifdef CONFIG_AUDITSYSCALL
16293 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16294 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
16295 jz auditsys
16296 #endif
16297 SAVE_REST
16298 @@ -632,12 +930,16 @@ tracesys:
16299 FIXUP_TOP_OF_STACK %rdi
16300 movq %rsp,%rdi
16301 call syscall_trace_enter
16302 +
16303 + pax_erase_kstack
16304 +
16305 /*
16306 * Reload arg registers from stack in case ptrace changed them.
16307 * We don't reload %rax because syscall_trace_enter() returned
16308 * the value it wants us to use in the table lookup.
16309 */
16310 LOAD_ARGS ARGOFFSET, 1
16311 + pax_set_fptr_mask
16312 RESTORE_REST
16313 #if __SYSCALL_MASK == ~0
16314 cmpq $__NR_syscall_max,%rax
16315 @@ -646,7 +948,7 @@ tracesys:
16316 cmpl $__NR_syscall_max,%eax
16317 #endif
16318 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
16319 - movq %r10,%rcx /* fixup for C */
16320 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
16321 call *sys_call_table(,%rax,8)
16322 movq %rax,RAX-ARGOFFSET(%rsp)
16323 /* Use IRET because user could have changed frame */
16324 @@ -667,7 +969,9 @@ GLOBAL(int_with_check)
16325 andl %edi,%edx
16326 jnz int_careful
16327 andl $~TS_COMPAT,TI_status(%rcx)
16328 - jmp retint_swapgs
16329 + pax_exit_kernel_user
16330 + pax_erase_kstack
16331 + jmp retint_swapgs_pax
16332
16333 /* Either reschedule or signal or syscall exit tracking needed. */
16334 /* First do a reschedule test. */
16335 @@ -713,7 +1017,7 @@ int_restore_rest:
16336 TRACE_IRQS_OFF
16337 jmp int_with_check
16338 CFI_ENDPROC
16339 -END(system_call)
16340 +ENDPROC(system_call)
16341
16342 /*
16343 * Certain special system calls that need to save a complete full stack frame.
16344 @@ -729,7 +1033,7 @@ ENTRY(\label)
16345 call \func
16346 jmp ptregscall_common
16347 CFI_ENDPROC
16348 -END(\label)
16349 +ENDPROC(\label)
16350 .endm
16351
16352 PTREGSCALL stub_clone, sys_clone, %r8
16353 @@ -747,9 +1051,10 @@ ENTRY(ptregscall_common)
16354 movq_cfi_restore R12+8, r12
16355 movq_cfi_restore RBP+8, rbp
16356 movq_cfi_restore RBX+8, rbx
16357 + pax_force_retaddr
16358 ret $REST_SKIP /* pop extended registers */
16359 CFI_ENDPROC
16360 -END(ptregscall_common)
16361 +ENDPROC(ptregscall_common)
16362
16363 ENTRY(stub_execve)
16364 CFI_STARTPROC
16365 @@ -764,7 +1069,7 @@ ENTRY(stub_execve)
16366 RESTORE_REST
16367 jmp int_ret_from_sys_call
16368 CFI_ENDPROC
16369 -END(stub_execve)
16370 +ENDPROC(stub_execve)
16371
16372 /*
16373 * sigreturn is special because it needs to restore all registers on return.
16374 @@ -782,7 +1087,7 @@ ENTRY(stub_rt_sigreturn)
16375 RESTORE_REST
16376 jmp int_ret_from_sys_call
16377 CFI_ENDPROC
16378 -END(stub_rt_sigreturn)
16379 +ENDPROC(stub_rt_sigreturn)
16380
16381 #ifdef CONFIG_X86_X32_ABI
16382 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
16383 @@ -851,7 +1156,7 @@ vector=vector+1
16384 2: jmp common_interrupt
16385 .endr
16386 CFI_ENDPROC
16387 -END(irq_entries_start)
16388 +ENDPROC(irq_entries_start)
16389
16390 .previous
16391 END(interrupt)
16392 @@ -871,6 +1176,16 @@ END(interrupt)
16393 subq $ORIG_RAX-RBP, %rsp
16394 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
16395 SAVE_ARGS_IRQ
16396 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16397 + testb $3, CS(%rdi)
16398 + jnz 1f
16399 + pax_enter_kernel
16400 + jmp 2f
16401 +1: pax_enter_kernel_user
16402 +2:
16403 +#else
16404 + pax_enter_kernel
16405 +#endif
16406 call \func
16407 .endm
16408
16409 @@ -902,7 +1217,7 @@ ret_from_intr:
16410
16411 exit_intr:
16412 GET_THREAD_INFO(%rcx)
16413 - testl $3,CS-ARGOFFSET(%rsp)
16414 + testb $3,CS-ARGOFFSET(%rsp)
16415 je retint_kernel
16416
16417 /* Interrupt came from user space */
16418 @@ -924,12 +1239,16 @@ retint_swapgs: /* return to user-space */
16419 * The iretq could re-enable interrupts:
16420 */
16421 DISABLE_INTERRUPTS(CLBR_ANY)
16422 + pax_exit_kernel_user
16423 +retint_swapgs_pax:
16424 TRACE_IRQS_IRETQ
16425 SWAPGS
16426 jmp restore_args
16427
16428 retint_restore_args: /* return to kernel space */
16429 DISABLE_INTERRUPTS(CLBR_ANY)
16430 + pax_exit_kernel
16431 + pax_force_retaddr RIP-ARGOFFSET
16432 /*
16433 * The iretq could re-enable interrupts:
16434 */
16435 @@ -1012,7 +1331,7 @@ ENTRY(retint_kernel)
16436 #endif
16437
16438 CFI_ENDPROC
16439 -END(common_interrupt)
16440 +ENDPROC(common_interrupt)
16441 /*
16442 * End of kprobes section
16443 */
16444 @@ -1029,7 +1348,7 @@ ENTRY(\sym)
16445 interrupt \do_sym
16446 jmp ret_from_intr
16447 CFI_ENDPROC
16448 -END(\sym)
16449 +ENDPROC(\sym)
16450 .endm
16451
16452 #ifdef CONFIG_SMP
16453 @@ -1084,12 +1403,22 @@ ENTRY(\sym)
16454 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16455 call error_entry
16456 DEFAULT_FRAME 0
16457 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16458 + testb $3, CS(%rsp)
16459 + jnz 1f
16460 + pax_enter_kernel
16461 + jmp 2f
16462 +1: pax_enter_kernel_user
16463 +2:
16464 +#else
16465 + pax_enter_kernel
16466 +#endif
16467 movq %rsp,%rdi /* pt_regs pointer */
16468 xorl %esi,%esi /* no error code */
16469 call \do_sym
16470 jmp error_exit /* %ebx: no swapgs flag */
16471 CFI_ENDPROC
16472 -END(\sym)
16473 +ENDPROC(\sym)
16474 .endm
16475
16476 .macro paranoidzeroentry sym do_sym
16477 @@ -1101,15 +1430,25 @@ ENTRY(\sym)
16478 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16479 call save_paranoid
16480 TRACE_IRQS_OFF
16481 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16482 + testb $3, CS(%rsp)
16483 + jnz 1f
16484 + pax_enter_kernel
16485 + jmp 2f
16486 +1: pax_enter_kernel_user
16487 +2:
16488 +#else
16489 + pax_enter_kernel
16490 +#endif
16491 movq %rsp,%rdi /* pt_regs pointer */
16492 xorl %esi,%esi /* no error code */
16493 call \do_sym
16494 jmp paranoid_exit /* %ebx: no swapgs flag */
16495 CFI_ENDPROC
16496 -END(\sym)
16497 +ENDPROC(\sym)
16498 .endm
16499
16500 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
16501 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
16502 .macro paranoidzeroentry_ist sym do_sym ist
16503 ENTRY(\sym)
16504 INTR_FRAME
16505 @@ -1119,14 +1458,30 @@ ENTRY(\sym)
16506 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16507 call save_paranoid
16508 TRACE_IRQS_OFF_DEBUG
16509 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16510 + testb $3, CS(%rsp)
16511 + jnz 1f
16512 + pax_enter_kernel
16513 + jmp 2f
16514 +1: pax_enter_kernel_user
16515 +2:
16516 +#else
16517 + pax_enter_kernel
16518 +#endif
16519 movq %rsp,%rdi /* pt_regs pointer */
16520 xorl %esi,%esi /* no error code */
16521 +#ifdef CONFIG_SMP
16522 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
16523 + lea init_tss(%r12), %r12
16524 +#else
16525 + lea init_tss(%rip), %r12
16526 +#endif
16527 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16528 call \do_sym
16529 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16530 jmp paranoid_exit /* %ebx: no swapgs flag */
16531 CFI_ENDPROC
16532 -END(\sym)
16533 +ENDPROC(\sym)
16534 .endm
16535
16536 .macro errorentry sym do_sym
16537 @@ -1137,13 +1492,23 @@ ENTRY(\sym)
16538 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16539 call error_entry
16540 DEFAULT_FRAME 0
16541 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16542 + testb $3, CS(%rsp)
16543 + jnz 1f
16544 + pax_enter_kernel
16545 + jmp 2f
16546 +1: pax_enter_kernel_user
16547 +2:
16548 +#else
16549 + pax_enter_kernel
16550 +#endif
16551 movq %rsp,%rdi /* pt_regs pointer */
16552 movq ORIG_RAX(%rsp),%rsi /* get error code */
16553 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16554 call \do_sym
16555 jmp error_exit /* %ebx: no swapgs flag */
16556 CFI_ENDPROC
16557 -END(\sym)
16558 +ENDPROC(\sym)
16559 .endm
16560
16561 /* error code is on the stack already */
16562 @@ -1156,13 +1521,23 @@ ENTRY(\sym)
16563 call save_paranoid
16564 DEFAULT_FRAME 0
16565 TRACE_IRQS_OFF
16566 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16567 + testb $3, CS(%rsp)
16568 + jnz 1f
16569 + pax_enter_kernel
16570 + jmp 2f
16571 +1: pax_enter_kernel_user
16572 +2:
16573 +#else
16574 + pax_enter_kernel
16575 +#endif
16576 movq %rsp,%rdi /* pt_regs pointer */
16577 movq ORIG_RAX(%rsp),%rsi /* get error code */
16578 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16579 call \do_sym
16580 jmp paranoid_exit /* %ebx: no swapgs flag */
16581 CFI_ENDPROC
16582 -END(\sym)
16583 +ENDPROC(\sym)
16584 .endm
16585
16586 zeroentry divide_error do_divide_error
16587 @@ -1192,9 +1567,10 @@ gs_change:
16588 2: mfence /* workaround */
16589 SWAPGS
16590 popfq_cfi
16591 + pax_force_retaddr
16592 ret
16593 CFI_ENDPROC
16594 -END(native_load_gs_index)
16595 +ENDPROC(native_load_gs_index)
16596
16597 _ASM_EXTABLE(gs_change,bad_gs)
16598 .section .fixup,"ax"
16599 @@ -1213,13 +1589,14 @@ ENTRY(kernel_thread_helper)
16600 * Here we are in the child and the registers are set as they were
16601 * at kernel_thread() invocation in the parent.
16602 */
16603 + pax_force_fptr %rsi
16604 call *%rsi
16605 # exit
16606 mov %eax, %edi
16607 call do_exit
16608 ud2 # padding for call trace
16609 CFI_ENDPROC
16610 -END(kernel_thread_helper)
16611 +ENDPROC(kernel_thread_helper)
16612
16613 /*
16614 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
16615 @@ -1246,11 +1623,11 @@ ENTRY(kernel_execve)
16616 RESTORE_REST
16617 testq %rax,%rax
16618 je int_ret_from_sys_call
16619 - RESTORE_ARGS
16620 UNFAKE_STACK_FRAME
16621 + pax_force_retaddr
16622 ret
16623 CFI_ENDPROC
16624 -END(kernel_execve)
16625 +ENDPROC(kernel_execve)
16626
16627 /* Call softirq on interrupt stack. Interrupts are off. */
16628 ENTRY(call_softirq)
16629 @@ -1268,9 +1645,10 @@ ENTRY(call_softirq)
16630 CFI_DEF_CFA_REGISTER rsp
16631 CFI_ADJUST_CFA_OFFSET -8
16632 decl PER_CPU_VAR(irq_count)
16633 + pax_force_retaddr
16634 ret
16635 CFI_ENDPROC
16636 -END(call_softirq)
16637 +ENDPROC(call_softirq)
16638
16639 #ifdef CONFIG_XEN
16640 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16641 @@ -1308,7 +1686,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16642 decl PER_CPU_VAR(irq_count)
16643 jmp error_exit
16644 CFI_ENDPROC
16645 -END(xen_do_hypervisor_callback)
16646 +ENDPROC(xen_do_hypervisor_callback)
16647
16648 /*
16649 * Hypervisor uses this for application faults while it executes.
16650 @@ -1367,7 +1745,7 @@ ENTRY(xen_failsafe_callback)
16651 SAVE_ALL
16652 jmp error_exit
16653 CFI_ENDPROC
16654 -END(xen_failsafe_callback)
16655 +ENDPROC(xen_failsafe_callback)
16656
16657 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
16658 xen_hvm_callback_vector xen_evtchn_do_upcall
16659 @@ -1416,16 +1794,31 @@ ENTRY(paranoid_exit)
16660 TRACE_IRQS_OFF_DEBUG
16661 testl %ebx,%ebx /* swapgs needed? */
16662 jnz paranoid_restore
16663 - testl $3,CS(%rsp)
16664 + testb $3,CS(%rsp)
16665 jnz paranoid_userspace
16666 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16667 + pax_exit_kernel
16668 + TRACE_IRQS_IRETQ 0
16669 + SWAPGS_UNSAFE_STACK
16670 + RESTORE_ALL 8
16671 + pax_force_retaddr_bts
16672 + jmp irq_return
16673 +#endif
16674 paranoid_swapgs:
16675 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16676 + pax_exit_kernel_user
16677 +#else
16678 + pax_exit_kernel
16679 +#endif
16680 TRACE_IRQS_IRETQ 0
16681 SWAPGS_UNSAFE_STACK
16682 RESTORE_ALL 8
16683 jmp irq_return
16684 paranoid_restore:
16685 + pax_exit_kernel
16686 TRACE_IRQS_IRETQ_DEBUG 0
16687 RESTORE_ALL 8
16688 + pax_force_retaddr_bts
16689 jmp irq_return
16690 paranoid_userspace:
16691 GET_THREAD_INFO(%rcx)
16692 @@ -1454,7 +1847,7 @@ paranoid_schedule:
16693 TRACE_IRQS_OFF
16694 jmp paranoid_userspace
16695 CFI_ENDPROC
16696 -END(paranoid_exit)
16697 +ENDPROC(paranoid_exit)
16698
16699 /*
16700 * Exception entry point. This expects an error code/orig_rax on the stack.
16701 @@ -1481,12 +1874,13 @@ ENTRY(error_entry)
16702 movq_cfi r14, R14+8
16703 movq_cfi r15, R15+8
16704 xorl %ebx,%ebx
16705 - testl $3,CS+8(%rsp)
16706 + testb $3,CS+8(%rsp)
16707 je error_kernelspace
16708 error_swapgs:
16709 SWAPGS
16710 error_sti:
16711 TRACE_IRQS_OFF
16712 + pax_force_retaddr_bts
16713 ret
16714
16715 /*
16716 @@ -1513,7 +1907,7 @@ bstep_iret:
16717 movq %rcx,RIP+8(%rsp)
16718 jmp error_swapgs
16719 CFI_ENDPROC
16720 -END(error_entry)
16721 +ENDPROC(error_entry)
16722
16723
16724 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16725 @@ -1533,7 +1927,7 @@ ENTRY(error_exit)
16726 jnz retint_careful
16727 jmp retint_swapgs
16728 CFI_ENDPROC
16729 -END(error_exit)
16730 +ENDPROC(error_exit)
16731
16732 /*
16733 * Test if a given stack is an NMI stack or not.
16734 @@ -1591,9 +1985,11 @@ ENTRY(nmi)
16735 * If %cs was not the kernel segment, then the NMI triggered in user
16736 * space, which means it is definitely not nested.
16737 */
16738 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
16739 + je 1f
16740 cmpl $__KERNEL_CS, 16(%rsp)
16741 jne first_nmi
16742 -
16743 +1:
16744 /*
16745 * Check the special variable on the stack to see if NMIs are
16746 * executing.
16747 @@ -1752,6 +2148,17 @@ end_repeat_nmi:
16748 */
16749 movq %cr2, %r12
16750
16751 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16752 + testb $3, CS(%rsp)
16753 + jnz 1f
16754 + pax_enter_kernel
16755 + jmp 2f
16756 +1: pax_enter_kernel_user
16757 +2:
16758 +#else
16759 + pax_enter_kernel
16760 +#endif
16761 +
16762 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16763 movq %rsp,%rdi
16764 movq $-1,%rsi
16765 @@ -1767,21 +2174,32 @@ end_repeat_nmi:
16766 testl %ebx,%ebx /* swapgs needed? */
16767 jnz nmi_restore
16768 nmi_swapgs:
16769 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16770 + pax_exit_kernel_user
16771 +#else
16772 + pax_exit_kernel
16773 +#endif
16774 SWAPGS_UNSAFE_STACK
16775 + RESTORE_ALL 8
16776 + /* Clear the NMI executing stack variable */
16777 + movq $0, 10*8(%rsp)
16778 + jmp irq_return
16779 nmi_restore:
16780 + pax_exit_kernel
16781 RESTORE_ALL 8
16782 + pax_force_retaddr_bts
16783 /* Clear the NMI executing stack variable */
16784 movq $0, 10*8(%rsp)
16785 jmp irq_return
16786 CFI_ENDPROC
16787 -END(nmi)
16788 +ENDPROC(nmi)
16789
16790 ENTRY(ignore_sysret)
16791 CFI_STARTPROC
16792 mov $-ENOSYS,%eax
16793 sysret
16794 CFI_ENDPROC
16795 -END(ignore_sysret)
16796 +ENDPROC(ignore_sysret)
16797
16798 /*
16799 * End of kprobes section
16800 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16801 index c3a7cb4..3ad00dc 100644
16802 --- a/arch/x86/kernel/ftrace.c
16803 +++ b/arch/x86/kernel/ftrace.c
16804 @@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
16805 {
16806 unsigned char replaced[MCOUNT_INSN_SIZE];
16807
16808 + ip = ktla_ktva(ip);
16809 +
16810 /*
16811 * Note: Due to modules and __init, code can
16812 * disappear and change, we need to protect against faulting
16813 @@ -212,7 +214,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16814 unsigned char old[MCOUNT_INSN_SIZE], *new;
16815 int ret;
16816
16817 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16818 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16819 new = ftrace_call_replace(ip, (unsigned long)func);
16820
16821 /* See comment above by declaration of modifying_ftrace_code */
16822 @@ -605,6 +607,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16823 {
16824 unsigned char code[MCOUNT_INSN_SIZE];
16825
16826 + ip = ktla_ktva(ip);
16827 +
16828 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16829 return -EFAULT;
16830
16831 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16832 index c18f59d..9c0c9f6 100644
16833 --- a/arch/x86/kernel/head32.c
16834 +++ b/arch/x86/kernel/head32.c
16835 @@ -18,6 +18,7 @@
16836 #include <asm/io_apic.h>
16837 #include <asm/bios_ebda.h>
16838 #include <asm/tlbflush.h>
16839 +#include <asm/boot.h>
16840
16841 static void __init i386_default_early_setup(void)
16842 {
16843 @@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
16844
16845 void __init i386_start_kernel(void)
16846 {
16847 - memblock_reserve(__pa_symbol(&_text),
16848 - __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16849 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16850
16851 #ifdef CONFIG_BLK_DEV_INITRD
16852 /* Reserve INITRD */
16853 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16854 index d42ab17..87b9555 100644
16855 --- a/arch/x86/kernel/head_32.S
16856 +++ b/arch/x86/kernel/head_32.S
16857 @@ -26,6 +26,12 @@
16858 /* Physical address */
16859 #define pa(X) ((X) - __PAGE_OFFSET)
16860
16861 +#ifdef CONFIG_PAX_KERNEXEC
16862 +#define ta(X) (X)
16863 +#else
16864 +#define ta(X) ((X) - __PAGE_OFFSET)
16865 +#endif
16866 +
16867 /*
16868 * References to members of the new_cpu_data structure.
16869 */
16870 @@ -55,11 +61,7 @@
16871 * and small than max_low_pfn, otherwise will waste some page table entries
16872 */
16873
16874 -#if PTRS_PER_PMD > 1
16875 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16876 -#else
16877 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16878 -#endif
16879 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16880
16881 /* Number of possible pages in the lowmem region */
16882 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16883 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16884 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16885
16886 /*
16887 + * Real beginning of normal "text" segment
16888 + */
16889 +ENTRY(stext)
16890 +ENTRY(_stext)
16891 +
16892 +/*
16893 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16894 * %esi points to the real-mode code as a 32-bit pointer.
16895 * CS and DS must be 4 GB flat segments, but we don't depend on
16896 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16897 * can.
16898 */
16899 __HEAD
16900 +
16901 +#ifdef CONFIG_PAX_KERNEXEC
16902 + jmp startup_32
16903 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16904 +.fill PAGE_SIZE-5,1,0xcc
16905 +#endif
16906 +
16907 ENTRY(startup_32)
16908 movl pa(stack_start),%ecx
16909
16910 @@ -106,6 +121,59 @@ ENTRY(startup_32)
16911 2:
16912 leal -__PAGE_OFFSET(%ecx),%esp
16913
16914 +#ifdef CONFIG_SMP
16915 + movl $pa(cpu_gdt_table),%edi
16916 + movl $__per_cpu_load,%eax
16917 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
16918 + rorl $16,%eax
16919 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
16920 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
16921 + movl $__per_cpu_end - 1,%eax
16922 + subl $__per_cpu_start,%eax
16923 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
16924 +#endif
16925 +
16926 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16927 + movl $NR_CPUS,%ecx
16928 + movl $pa(cpu_gdt_table),%edi
16929 +1:
16930 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16931 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16932 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16933 + addl $PAGE_SIZE_asm,%edi
16934 + loop 1b
16935 +#endif
16936 +
16937 +#ifdef CONFIG_PAX_KERNEXEC
16938 + movl $pa(boot_gdt),%edi
16939 + movl $__LOAD_PHYSICAL_ADDR,%eax
16940 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
16941 + rorl $16,%eax
16942 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
16943 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
16944 + rorl $16,%eax
16945 +
16946 + ljmp $(__BOOT_CS),$1f
16947 +1:
16948 +
16949 + movl $NR_CPUS,%ecx
16950 + movl $pa(cpu_gdt_table),%edi
16951 + addl $__PAGE_OFFSET,%eax
16952 +1:
16953 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
16954 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
16955 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
16956 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
16957 + rorl $16,%eax
16958 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
16959 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
16960 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
16961 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
16962 + rorl $16,%eax
16963 + addl $PAGE_SIZE_asm,%edi
16964 + loop 1b
16965 +#endif
16966 +
16967 /*
16968 * Clear BSS first so that there are no surprises...
16969 */
16970 @@ -196,8 +264,11 @@ ENTRY(startup_32)
16971 movl %eax, pa(max_pfn_mapped)
16972
16973 /* Do early initialization of the fixmap area */
16974 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16975 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
16976 +#ifdef CONFIG_COMPAT_VDSO
16977 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
16978 +#else
16979 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
16980 +#endif
16981 #else /* Not PAE */
16982
16983 page_pde_offset = (__PAGE_OFFSET >> 20);
16984 @@ -227,8 +298,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16985 movl %eax, pa(max_pfn_mapped)
16986
16987 /* Do early initialization of the fixmap area */
16988 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16989 - movl %eax,pa(initial_page_table+0xffc)
16990 +#ifdef CONFIG_COMPAT_VDSO
16991 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
16992 +#else
16993 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
16994 +#endif
16995 #endif
16996
16997 #ifdef CONFIG_PARAVIRT
16998 @@ -242,9 +316,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16999 cmpl $num_subarch_entries, %eax
17000 jae bad_subarch
17001
17002 - movl pa(subarch_entries)(,%eax,4), %eax
17003 - subl $__PAGE_OFFSET, %eax
17004 - jmp *%eax
17005 + jmp *pa(subarch_entries)(,%eax,4)
17006
17007 bad_subarch:
17008 WEAK(lguest_entry)
17009 @@ -256,10 +328,10 @@ WEAK(xen_entry)
17010 __INITDATA
17011
17012 subarch_entries:
17013 - .long default_entry /* normal x86/PC */
17014 - .long lguest_entry /* lguest hypervisor */
17015 - .long xen_entry /* Xen hypervisor */
17016 - .long default_entry /* Moorestown MID */
17017 + .long ta(default_entry) /* normal x86/PC */
17018 + .long ta(lguest_entry) /* lguest hypervisor */
17019 + .long ta(xen_entry) /* Xen hypervisor */
17020 + .long ta(default_entry) /* Moorestown MID */
17021 num_subarch_entries = (. - subarch_entries) / 4
17022 .previous
17023 #else
17024 @@ -310,6 +382,7 @@ default_entry:
17025 orl %edx,%eax
17026 movl %eax,%cr4
17027
17028 +#ifdef CONFIG_X86_PAE
17029 testb $X86_CR4_PAE, %al # check if PAE is enabled
17030 jz 6f
17031
17032 @@ -338,6 +411,9 @@ default_entry:
17033 /* Make changes effective */
17034 wrmsr
17035
17036 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
17037 +#endif
17038 +
17039 6:
17040
17041 /*
17042 @@ -436,14 +512,20 @@ is386: movl $2,%ecx # set MP
17043 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
17044 movl %eax,%ss # after changing gdt.
17045
17046 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
17047 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
17048 movl %eax,%ds
17049 movl %eax,%es
17050
17051 movl $(__KERNEL_PERCPU), %eax
17052 movl %eax,%fs # set this cpu's percpu
17053
17054 +#ifdef CONFIG_CC_STACKPROTECTOR
17055 movl $(__KERNEL_STACK_CANARY),%eax
17056 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
17057 + movl $(__USER_DS),%eax
17058 +#else
17059 + xorl %eax,%eax
17060 +#endif
17061 movl %eax,%gs
17062
17063 xorl %eax,%eax # Clear LDT
17064 @@ -520,8 +602,11 @@ setup_once:
17065 * relocation. Manually set base address in stack canary
17066 * segment descriptor.
17067 */
17068 - movl $gdt_page,%eax
17069 + movl $cpu_gdt_table,%eax
17070 movl $stack_canary,%ecx
17071 +#ifdef CONFIG_SMP
17072 + addl $__per_cpu_load,%ecx
17073 +#endif
17074 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
17075 shrl $16, %ecx
17076 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
17077 @@ -552,7 +637,7 @@ ENDPROC(early_idt_handlers)
17078 /* This is global to keep gas from relaxing the jumps */
17079 ENTRY(early_idt_handler)
17080 cld
17081 - cmpl $2,%ss:early_recursion_flag
17082 + cmpl $1,%ss:early_recursion_flag
17083 je hlt_loop
17084 incl %ss:early_recursion_flag
17085
17086 @@ -590,8 +675,8 @@ ENTRY(early_idt_handler)
17087 pushl (20+6*4)(%esp) /* trapno */
17088 pushl $fault_msg
17089 call printk
17090 -#endif
17091 call dump_stack
17092 +#endif
17093 hlt_loop:
17094 hlt
17095 jmp hlt_loop
17096 @@ -610,8 +695,11 @@ ENDPROC(early_idt_handler)
17097 /* This is the default interrupt "handler" :-) */
17098 ALIGN
17099 ignore_int:
17100 - cld
17101 #ifdef CONFIG_PRINTK
17102 + cmpl $2,%ss:early_recursion_flag
17103 + je hlt_loop
17104 + incl %ss:early_recursion_flag
17105 + cld
17106 pushl %eax
17107 pushl %ecx
17108 pushl %edx
17109 @@ -620,9 +708,6 @@ ignore_int:
17110 movl $(__KERNEL_DS),%eax
17111 movl %eax,%ds
17112 movl %eax,%es
17113 - cmpl $2,early_recursion_flag
17114 - je hlt_loop
17115 - incl early_recursion_flag
17116 pushl 16(%esp)
17117 pushl 24(%esp)
17118 pushl 32(%esp)
17119 @@ -656,29 +741,43 @@ ENTRY(setup_once_ref)
17120 /*
17121 * BSS section
17122 */
17123 -__PAGE_ALIGNED_BSS
17124 - .align PAGE_SIZE
17125 #ifdef CONFIG_X86_PAE
17126 +.section .initial_pg_pmd,"a",@progbits
17127 initial_pg_pmd:
17128 .fill 1024*KPMDS,4,0
17129 #else
17130 +.section .initial_page_table,"a",@progbits
17131 ENTRY(initial_page_table)
17132 .fill 1024,4,0
17133 #endif
17134 +.section .initial_pg_fixmap,"a",@progbits
17135 initial_pg_fixmap:
17136 .fill 1024,4,0
17137 +.section .empty_zero_page,"a",@progbits
17138 ENTRY(empty_zero_page)
17139 .fill 4096,1,0
17140 +.section .swapper_pg_dir,"a",@progbits
17141 ENTRY(swapper_pg_dir)
17142 +#ifdef CONFIG_X86_PAE
17143 + .fill 4,8,0
17144 +#else
17145 .fill 1024,4,0
17146 +#endif
17147 +
17148 +/*
17149 + * The IDT has to be page-aligned to simplify the Pentium
17150 + * F0 0F bug workaround.. We have a special link segment
17151 + * for this.
17152 + */
17153 +.section .idt,"a",@progbits
17154 +ENTRY(idt_table)
17155 + .fill 256,8,0
17156
17157 /*
17158 * This starts the data section.
17159 */
17160 #ifdef CONFIG_X86_PAE
17161 -__PAGE_ALIGNED_DATA
17162 - /* Page-aligned for the benefit of paravirt? */
17163 - .align PAGE_SIZE
17164 +.section .initial_page_table,"a",@progbits
17165 ENTRY(initial_page_table)
17166 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
17167 # if KPMDS == 3
17168 @@ -697,12 +796,20 @@ ENTRY(initial_page_table)
17169 # error "Kernel PMDs should be 1, 2 or 3"
17170 # endif
17171 .align PAGE_SIZE /* needs to be page-sized too */
17172 +
17173 +#ifdef CONFIG_PAX_PER_CPU_PGD
17174 +ENTRY(cpu_pgd)
17175 + .rept NR_CPUS
17176 + .fill 4,8,0
17177 + .endr
17178 +#endif
17179 +
17180 #endif
17181
17182 .data
17183 .balign 4
17184 ENTRY(stack_start)
17185 - .long init_thread_union+THREAD_SIZE
17186 + .long init_thread_union+THREAD_SIZE-8
17187
17188 __INITRODATA
17189 int_msg:
17190 @@ -730,7 +837,7 @@ fault_msg:
17191 * segment size, and 32-bit linear address value:
17192 */
17193
17194 - .data
17195 +.section .rodata,"a",@progbits
17196 .globl boot_gdt_descr
17197 .globl idt_descr
17198
17199 @@ -739,7 +846,7 @@ fault_msg:
17200 .word 0 # 32 bit align gdt_desc.address
17201 boot_gdt_descr:
17202 .word __BOOT_DS+7
17203 - .long boot_gdt - __PAGE_OFFSET
17204 + .long pa(boot_gdt)
17205
17206 .word 0 # 32-bit align idt_desc.address
17207 idt_descr:
17208 @@ -750,7 +857,7 @@ idt_descr:
17209 .word 0 # 32 bit align gdt_desc.address
17210 ENTRY(early_gdt_descr)
17211 .word GDT_ENTRIES*8-1
17212 - .long gdt_page /* Overwritten for secondary CPUs */
17213 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
17214
17215 /*
17216 * The boot_gdt must mirror the equivalent in setup.S and is
17217 @@ -759,5 +866,65 @@ ENTRY(early_gdt_descr)
17218 .align L1_CACHE_BYTES
17219 ENTRY(boot_gdt)
17220 .fill GDT_ENTRY_BOOT_CS,8,0
17221 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
17222 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
17223 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
17224 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
17225 +
17226 + .align PAGE_SIZE_asm
17227 +ENTRY(cpu_gdt_table)
17228 + .rept NR_CPUS
17229 + .quad 0x0000000000000000 /* NULL descriptor */
17230 + .quad 0x0000000000000000 /* 0x0b reserved */
17231 + .quad 0x0000000000000000 /* 0x13 reserved */
17232 + .quad 0x0000000000000000 /* 0x1b reserved */
17233 +
17234 +#ifdef CONFIG_PAX_KERNEXEC
17235 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
17236 +#else
17237 + .quad 0x0000000000000000 /* 0x20 unused */
17238 +#endif
17239 +
17240 + .quad 0x0000000000000000 /* 0x28 unused */
17241 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
17242 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
17243 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
17244 + .quad 0x0000000000000000 /* 0x4b reserved */
17245 + .quad 0x0000000000000000 /* 0x53 reserved */
17246 + .quad 0x0000000000000000 /* 0x5b reserved */
17247 +
17248 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
17249 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
17250 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
17251 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
17252 +
17253 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
17254 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
17255 +
17256 + /*
17257 + * Segments used for calling PnP BIOS have byte granularity.
17258 + * The code segments and data segments have fixed 64k limits,
17259 + * the transfer segment sizes are set at run time.
17260 + */
17261 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
17262 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
17263 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
17264 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
17265 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
17266 +
17267 + /*
17268 + * The APM segments have byte granularity and their bases
17269 + * are set at run time. All have 64k limits.
17270 + */
17271 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
17272 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
17273 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
17274 +
17275 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
17276 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
17277 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
17278 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
17279 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
17280 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
17281 +
17282 + /* Be sure this is zeroed to avoid false validations in Xen */
17283 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
17284 + .endr
17285 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
17286 index 94bf9cc..400455a 100644
17287 --- a/arch/x86/kernel/head_64.S
17288 +++ b/arch/x86/kernel/head_64.S
17289 @@ -20,6 +20,8 @@
17290 #include <asm/processor-flags.h>
17291 #include <asm/percpu.h>
17292 #include <asm/nops.h>
17293 +#include <asm/cpufeature.h>
17294 +#include <asm/alternative-asm.h>
17295
17296 #ifdef CONFIG_PARAVIRT
17297 #include <asm/asm-offsets.h>
17298 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
17299 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
17300 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
17301 L3_START_KERNEL = pud_index(__START_KERNEL_map)
17302 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
17303 +L3_VMALLOC_START = pud_index(VMALLOC_START)
17304 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
17305 +L3_VMALLOC_END = pud_index(VMALLOC_END)
17306 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
17307 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
17308
17309 .text
17310 __HEAD
17311 @@ -88,35 +96,23 @@ startup_64:
17312 */
17313 addq %rbp, init_level4_pgt + 0(%rip)
17314 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
17315 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
17316 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
17317 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
17318 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
17319
17320 addq %rbp, level3_ident_pgt + 0(%rip)
17321 +#ifndef CONFIG_XEN
17322 + addq %rbp, level3_ident_pgt + 8(%rip)
17323 +#endif
17324
17325 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
17326 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
17327 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
17328 +
17329 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
17330 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
17331
17332 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
17333 -
17334 - /* Add an Identity mapping if I am above 1G */
17335 - leaq _text(%rip), %rdi
17336 - andq $PMD_PAGE_MASK, %rdi
17337 -
17338 - movq %rdi, %rax
17339 - shrq $PUD_SHIFT, %rax
17340 - andq $(PTRS_PER_PUD - 1), %rax
17341 - jz ident_complete
17342 -
17343 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
17344 - leaq level3_ident_pgt(%rip), %rbx
17345 - movq %rdx, 0(%rbx, %rax, 8)
17346 -
17347 - movq %rdi, %rax
17348 - shrq $PMD_SHIFT, %rax
17349 - andq $(PTRS_PER_PMD - 1), %rax
17350 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
17351 - leaq level2_spare_pgt(%rip), %rbx
17352 - movq %rdx, 0(%rbx, %rax, 8)
17353 -ident_complete:
17354 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
17355
17356 /*
17357 * Fixup the kernel text+data virtual addresses. Note that
17358 @@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
17359 * after the boot processor executes this code.
17360 */
17361
17362 - /* Enable PAE mode and PGE */
17363 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
17364 + /* Enable PAE mode and PSE/PGE */
17365 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17366 movq %rax, %cr4
17367
17368 /* Setup early boot stage 4 level pagetables. */
17369 @@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
17370 movl $MSR_EFER, %ecx
17371 rdmsr
17372 btsl $_EFER_SCE, %eax /* Enable System Call */
17373 - btl $20,%edi /* No Execute supported? */
17374 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
17375 jnc 1f
17376 btsl $_EFER_NX, %eax
17377 + leaq init_level4_pgt(%rip), %rdi
17378 +#ifndef CONFIG_EFI
17379 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
17380 +#endif
17381 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
17382 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
17383 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
17384 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
17385 1: wrmsr /* Make changes effective */
17386
17387 /* Setup cr0 */
17388 @@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
17389 * jump. In addition we need to ensure %cs is set so we make this
17390 * a far return.
17391 */
17392 + pax_set_fptr_mask
17393 movq initial_code(%rip),%rax
17394 pushq $0 # fake return address to stop unwinder
17395 pushq $__KERNEL_CS # set correct cs
17396 @@ -268,7 +273,7 @@ ENTRY(secondary_startup_64)
17397 bad_address:
17398 jmp bad_address
17399
17400 - .section ".init.text","ax"
17401 + __INIT
17402 .globl early_idt_handlers
17403 early_idt_handlers:
17404 # 104(%rsp) %rflags
17405 @@ -347,11 +352,15 @@ ENTRY(early_idt_handler)
17406 addq $16,%rsp # drop vector number and error code
17407 decl early_recursion_flag(%rip)
17408 INTERRUPT_RETURN
17409 + .previous
17410
17411 + __INITDATA
17412 .balign 4
17413 early_recursion_flag:
17414 .long 0
17415 + .previous
17416
17417 + .section .rodata,"a",@progbits
17418 #ifdef CONFIG_EARLY_PRINTK
17419 early_idt_msg:
17420 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
17421 @@ -360,6 +369,7 @@ early_idt_ripmsg:
17422 #endif /* CONFIG_EARLY_PRINTK */
17423 .previous
17424
17425 + .section .rodata,"a",@progbits
17426 #define NEXT_PAGE(name) \
17427 .balign PAGE_SIZE; \
17428 ENTRY(name)
17429 @@ -372,7 +382,6 @@ ENTRY(name)
17430 i = i + 1 ; \
17431 .endr
17432
17433 - .data
17434 /*
17435 * This default setting generates an ident mapping at address 0x100000
17436 * and a mapping for the kernel that precisely maps virtual address
17437 @@ -383,13 +392,41 @@ NEXT_PAGE(init_level4_pgt)
17438 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17439 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
17440 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17441 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
17442 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
17443 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
17444 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
17445 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
17446 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17447 .org init_level4_pgt + L4_START_KERNEL*8, 0
17448 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
17449 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
17450
17451 +#ifdef CONFIG_PAX_PER_CPU_PGD
17452 +NEXT_PAGE(cpu_pgd)
17453 + .rept NR_CPUS
17454 + .fill 512,8,0
17455 + .endr
17456 +#endif
17457 +
17458 NEXT_PAGE(level3_ident_pgt)
17459 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17460 +#ifdef CONFIG_XEN
17461 .fill 511,8,0
17462 +#else
17463 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
17464 + .fill 510,8,0
17465 +#endif
17466 +
17467 +NEXT_PAGE(level3_vmalloc_start_pgt)
17468 + .fill 512,8,0
17469 +
17470 +NEXT_PAGE(level3_vmalloc_end_pgt)
17471 + .fill 512,8,0
17472 +
17473 +NEXT_PAGE(level3_vmemmap_pgt)
17474 + .fill L3_VMEMMAP_START,8,0
17475 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17476
17477 NEXT_PAGE(level3_kernel_pgt)
17478 .fill L3_START_KERNEL,8,0
17479 @@ -397,20 +434,23 @@ NEXT_PAGE(level3_kernel_pgt)
17480 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
17481 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17482
17483 +NEXT_PAGE(level2_vmemmap_pgt)
17484 + .fill 512,8,0
17485 +
17486 NEXT_PAGE(level2_fixmap_pgt)
17487 - .fill 506,8,0
17488 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17489 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
17490 - .fill 5,8,0
17491 + .fill 507,8,0
17492 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
17493 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
17494 + .fill 4,8,0
17495
17496 -NEXT_PAGE(level1_fixmap_pgt)
17497 +NEXT_PAGE(level1_vsyscall_pgt)
17498 .fill 512,8,0
17499
17500 -NEXT_PAGE(level2_ident_pgt)
17501 - /* Since I easily can, map the first 1G.
17502 + /* Since I easily can, map the first 2G.
17503 * Don't set NX because code runs from these pages.
17504 */
17505 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
17506 +NEXT_PAGE(level2_ident_pgt)
17507 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
17508
17509 NEXT_PAGE(level2_kernel_pgt)
17510 /*
17511 @@ -423,37 +463,59 @@ NEXT_PAGE(level2_kernel_pgt)
17512 * If you want to increase this then increase MODULES_VADDR
17513 * too.)
17514 */
17515 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
17516 - KERNEL_IMAGE_SIZE/PMD_SIZE)
17517 -
17518 -NEXT_PAGE(level2_spare_pgt)
17519 - .fill 512, 8, 0
17520 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
17521
17522 #undef PMDS
17523 #undef NEXT_PAGE
17524
17525 - .data
17526 + .align PAGE_SIZE
17527 +ENTRY(cpu_gdt_table)
17528 + .rept NR_CPUS
17529 + .quad 0x0000000000000000 /* NULL descriptor */
17530 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
17531 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
17532 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
17533 + .quad 0x00cffb000000ffff /* __USER32_CS */
17534 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
17535 + .quad 0x00affb000000ffff /* __USER_CS */
17536 +
17537 +#ifdef CONFIG_PAX_KERNEXEC
17538 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
17539 +#else
17540 + .quad 0x0 /* unused */
17541 +#endif
17542 +
17543 + .quad 0,0 /* TSS */
17544 + .quad 0,0 /* LDT */
17545 + .quad 0,0,0 /* three TLS descriptors */
17546 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
17547 + /* asm/segment.h:GDT_ENTRIES must match this */
17548 +
17549 + /* zero the remaining page */
17550 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
17551 + .endr
17552 +
17553 .align 16
17554 .globl early_gdt_descr
17555 early_gdt_descr:
17556 .word GDT_ENTRIES*8-1
17557 early_gdt_descr_base:
17558 - .quad INIT_PER_CPU_VAR(gdt_page)
17559 + .quad cpu_gdt_table
17560
17561 ENTRY(phys_base)
17562 /* This must match the first entry in level2_kernel_pgt */
17563 .quad 0x0000000000000000
17564
17565 #include "../../x86/xen/xen-head.S"
17566 -
17567 - .section .bss, "aw", @nobits
17568 +
17569 + .section .rodata,"a",@progbits
17570 .align L1_CACHE_BYTES
17571 ENTRY(idt_table)
17572 - .skip IDT_ENTRIES * 16
17573 + .fill 512,8,0
17574
17575 .align L1_CACHE_BYTES
17576 ENTRY(nmi_idt_table)
17577 - .skip IDT_ENTRIES * 16
17578 + .fill 512,8,0
17579
17580 __PAGE_ALIGNED_BSS
17581 .align PAGE_SIZE
17582 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17583 index 9c3bd4a..e1d9b35 100644
17584 --- a/arch/x86/kernel/i386_ksyms_32.c
17585 +++ b/arch/x86/kernel/i386_ksyms_32.c
17586 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
17587 EXPORT_SYMBOL(cmpxchg8b_emu);
17588 #endif
17589
17590 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
17591 +
17592 /* Networking helper routines. */
17593 EXPORT_SYMBOL(csum_partial_copy_generic);
17594 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17595 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17596
17597 EXPORT_SYMBOL(__get_user_1);
17598 EXPORT_SYMBOL(__get_user_2);
17599 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17600
17601 EXPORT_SYMBOL(csum_partial);
17602 EXPORT_SYMBOL(empty_zero_page);
17603 +
17604 +#ifdef CONFIG_PAX_KERNEXEC
17605 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17606 +#endif
17607 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
17608 index f250431..54097e7 100644
17609 --- a/arch/x86/kernel/i387.c
17610 +++ b/arch/x86/kernel/i387.c
17611 @@ -59,7 +59,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
17612 static inline bool interrupted_user_mode(void)
17613 {
17614 struct pt_regs *regs = get_irq_regs();
17615 - return regs && user_mode_vm(regs);
17616 + return regs && user_mode(regs);
17617 }
17618
17619 /*
17620 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17621 index 36d1853..bf25736 100644
17622 --- a/arch/x86/kernel/i8259.c
17623 +++ b/arch/x86/kernel/i8259.c
17624 @@ -209,7 +209,7 @@ spurious_8259A_irq:
17625 "spurious 8259A interrupt: IRQ%d.\n", irq);
17626 spurious_irq_mask |= irqmask;
17627 }
17628 - atomic_inc(&irq_err_count);
17629 + atomic_inc_unchecked(&irq_err_count);
17630 /*
17631 * Theoretically we do not have to handle this IRQ,
17632 * but in Linux this does not cause problems and is
17633 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17634 index 8c96897..be66bfa 100644
17635 --- a/arch/x86/kernel/ioport.c
17636 +++ b/arch/x86/kernel/ioport.c
17637 @@ -6,6 +6,7 @@
17638 #include <linux/sched.h>
17639 #include <linux/kernel.h>
17640 #include <linux/capability.h>
17641 +#include <linux/security.h>
17642 #include <linux/errno.h>
17643 #include <linux/types.h>
17644 #include <linux/ioport.h>
17645 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17646
17647 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17648 return -EINVAL;
17649 +#ifdef CONFIG_GRKERNSEC_IO
17650 + if (turn_on && grsec_disable_privio) {
17651 + gr_handle_ioperm();
17652 + return -EPERM;
17653 + }
17654 +#endif
17655 if (turn_on && !capable(CAP_SYS_RAWIO))
17656 return -EPERM;
17657
17658 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17659 * because the ->io_bitmap_max value must match the bitmap
17660 * contents:
17661 */
17662 - tss = &per_cpu(init_tss, get_cpu());
17663 + tss = init_tss + get_cpu();
17664
17665 if (turn_on)
17666 bitmap_clear(t->io_bitmap_ptr, from, num);
17667 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17668 return -EINVAL;
17669 /* Trying to gain more privileges? */
17670 if (level > old) {
17671 +#ifdef CONFIG_GRKERNSEC_IO
17672 + if (grsec_disable_privio) {
17673 + gr_handle_iopl();
17674 + return -EPERM;
17675 + }
17676 +#endif
17677 if (!capable(CAP_SYS_RAWIO))
17678 return -EPERM;
17679 }
17680 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17681 index d44f782..31ab01e 100644
17682 --- a/arch/x86/kernel/irq.c
17683 +++ b/arch/x86/kernel/irq.c
17684 @@ -18,7 +18,7 @@
17685 #include <asm/mce.h>
17686 #include <asm/hw_irq.h>
17687
17688 -atomic_t irq_err_count;
17689 +atomic_unchecked_t irq_err_count;
17690
17691 /* Function pointer for generic interrupt vector handling */
17692 void (*x86_platform_ipi_callback)(void) = NULL;
17693 @@ -121,9 +121,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17694 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17695 seq_printf(p, " Machine check polls\n");
17696 #endif
17697 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17698 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17699 #if defined(CONFIG_X86_IO_APIC)
17700 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17701 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17702 #endif
17703 return 0;
17704 }
17705 @@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17706
17707 u64 arch_irq_stat(void)
17708 {
17709 - u64 sum = atomic_read(&irq_err_count);
17710 + u64 sum = atomic_read_unchecked(&irq_err_count);
17711
17712 #ifdef CONFIG_X86_IO_APIC
17713 - sum += atomic_read(&irq_mis_count);
17714 + sum += atomic_read_unchecked(&irq_mis_count);
17715 #endif
17716 return sum;
17717 }
17718 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17719 index 344faf8..355f60d 100644
17720 --- a/arch/x86/kernel/irq_32.c
17721 +++ b/arch/x86/kernel/irq_32.c
17722 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
17723 __asm__ __volatile__("andl %%esp,%0" :
17724 "=r" (sp) : "0" (THREAD_SIZE - 1));
17725
17726 - return sp < (sizeof(struct thread_info) + STACK_WARN);
17727 + return sp < STACK_WARN;
17728 }
17729
17730 static void print_stack_overflow(void)
17731 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
17732 * per-CPU IRQ handling contexts (thread information and stack)
17733 */
17734 union irq_ctx {
17735 - struct thread_info tinfo;
17736 - u32 stack[THREAD_SIZE/sizeof(u32)];
17737 + unsigned long previous_esp;
17738 + u32 stack[THREAD_SIZE/sizeof(u32)];
17739 } __attribute__((aligned(THREAD_SIZE)));
17740
17741 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17742 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
17743 static inline int
17744 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17745 {
17746 - union irq_ctx *curctx, *irqctx;
17747 + union irq_ctx *irqctx;
17748 u32 *isp, arg1, arg2;
17749
17750 - curctx = (union irq_ctx *) current_thread_info();
17751 irqctx = __this_cpu_read(hardirq_ctx);
17752
17753 /*
17754 @@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17755 * handler) we can't do that and just have to keep using the
17756 * current stack (which is the irq stack already after all)
17757 */
17758 - if (unlikely(curctx == irqctx))
17759 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17760 return 0;
17761
17762 /* build the stack frame on the IRQ stack */
17763 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17764 - irqctx->tinfo.task = curctx->tinfo.task;
17765 - irqctx->tinfo.previous_esp = current_stack_pointer;
17766 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17767 + irqctx->previous_esp = current_stack_pointer;
17768
17769 - /* Copy the preempt_count so that the [soft]irq checks work. */
17770 - irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
17771 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17772 + __set_fs(MAKE_MM_SEG(0));
17773 +#endif
17774
17775 if (unlikely(overflow))
17776 call_on_stack(print_stack_overflow, isp);
17777 @@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17778 : "0" (irq), "1" (desc), "2" (isp),
17779 "D" (desc->handle_irq)
17780 : "memory", "cc", "ecx");
17781 +
17782 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17783 + __set_fs(current_thread_info()->addr_limit);
17784 +#endif
17785 +
17786 return 1;
17787 }
17788
17789 @@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17790 */
17791 void __cpuinit irq_ctx_init(int cpu)
17792 {
17793 - union irq_ctx *irqctx;
17794 -
17795 if (per_cpu(hardirq_ctx, cpu))
17796 return;
17797
17798 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17799 - THREADINFO_GFP,
17800 - THREAD_SIZE_ORDER));
17801 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17802 - irqctx->tinfo.cpu = cpu;
17803 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17804 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17805 -
17806 - per_cpu(hardirq_ctx, cpu) = irqctx;
17807 -
17808 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17809 - THREADINFO_GFP,
17810 - THREAD_SIZE_ORDER));
17811 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17812 - irqctx->tinfo.cpu = cpu;
17813 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17814 -
17815 - per_cpu(softirq_ctx, cpu) = irqctx;
17816 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17817 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17818 +
17819 + printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17820 + cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17821
17822 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17823 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17824 @@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
17825 asmlinkage void do_softirq(void)
17826 {
17827 unsigned long flags;
17828 - struct thread_info *curctx;
17829 union irq_ctx *irqctx;
17830 u32 *isp;
17831
17832 @@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
17833 local_irq_save(flags);
17834
17835 if (local_softirq_pending()) {
17836 - curctx = current_thread_info();
17837 irqctx = __this_cpu_read(softirq_ctx);
17838 - irqctx->tinfo.task = curctx->task;
17839 - irqctx->tinfo.previous_esp = current_stack_pointer;
17840 + irqctx->previous_esp = current_stack_pointer;
17841
17842 /* build the stack frame on the softirq stack */
17843 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17844 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17845 +
17846 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17847 + __set_fs(MAKE_MM_SEG(0));
17848 +#endif
17849
17850 call_on_stack(__do_softirq, isp);
17851 +
17852 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17853 + __set_fs(current_thread_info()->addr_limit);
17854 +#endif
17855 +
17856 /*
17857 * Shouldn't happen, we returned above if in_interrupt():
17858 */
17859 @@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
17860 if (unlikely(!desc))
17861 return false;
17862
17863 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17864 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17865 if (unlikely(overflow))
17866 print_stack_overflow();
17867 desc->handle_irq(irq, desc);
17868 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17869 index d04d3ec..ea4b374 100644
17870 --- a/arch/x86/kernel/irq_64.c
17871 +++ b/arch/x86/kernel/irq_64.c
17872 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17873 u64 estack_top, estack_bottom;
17874 u64 curbase = (u64)task_stack_page(current);
17875
17876 - if (user_mode_vm(regs))
17877 + if (user_mode(regs))
17878 return;
17879
17880 if (regs->sp >= curbase + sizeof(struct thread_info) +
17881 diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
17882 index dc1404b..bbc43e7 100644
17883 --- a/arch/x86/kernel/kdebugfs.c
17884 +++ b/arch/x86/kernel/kdebugfs.c
17885 @@ -27,7 +27,7 @@ struct setup_data_node {
17886 u32 len;
17887 };
17888
17889 -static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17890 +static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
17891 size_t count, loff_t *ppos)
17892 {
17893 struct setup_data_node *node = file->private_data;
17894 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17895 index 3f61904..873cea9 100644
17896 --- a/arch/x86/kernel/kgdb.c
17897 +++ b/arch/x86/kernel/kgdb.c
17898 @@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17899 #ifdef CONFIG_X86_32
17900 switch (regno) {
17901 case GDB_SS:
17902 - if (!user_mode_vm(regs))
17903 + if (!user_mode(regs))
17904 *(unsigned long *)mem = __KERNEL_DS;
17905 break;
17906 case GDB_SP:
17907 - if (!user_mode_vm(regs))
17908 + if (!user_mode(regs))
17909 *(unsigned long *)mem = kernel_stack_pointer(regs);
17910 break;
17911 case GDB_GS:
17912 @@ -476,12 +476,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17913 case 'k':
17914 /* clear the trace bit */
17915 linux_regs->flags &= ~X86_EFLAGS_TF;
17916 - atomic_set(&kgdb_cpu_doing_single_step, -1);
17917 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17918
17919 /* set the trace bit if we're stepping */
17920 if (remcomInBuffer[0] == 's') {
17921 linux_regs->flags |= X86_EFLAGS_TF;
17922 - atomic_set(&kgdb_cpu_doing_single_step,
17923 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17924 raw_smp_processor_id());
17925 }
17926
17927 @@ -546,7 +546,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17928
17929 switch (cmd) {
17930 case DIE_DEBUG:
17931 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17932 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17933 if (user_mode(regs))
17934 return single_step_cont(regs, args);
17935 break;
17936 diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
17937 index c5e410e..da6aaf9 100644
17938 --- a/arch/x86/kernel/kprobes-opt.c
17939 +++ b/arch/x86/kernel/kprobes-opt.c
17940 @@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17941 * Verify if the address gap is in 2GB range, because this uses
17942 * a relative jump.
17943 */
17944 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
17945 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
17946 if (abs(rel) > 0x7fffffff)
17947 return -ERANGE;
17948
17949 @@ -359,11 +359,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17950 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
17951
17952 /* Set probe function call */
17953 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
17954 + synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
17955
17956 /* Set returning jmp instruction at the tail of out-of-line buffer */
17957 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
17958 - (u8 *)op->kp.addr + op->optinsn.size);
17959 + (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
17960
17961 flush_icache_range((unsigned long) buf,
17962 (unsigned long) buf + TMPL_END_IDX +
17963 @@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
17964 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
17965
17966 /* Backup instructions which will be replaced by jump address */
17967 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
17968 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
17969 RELATIVE_ADDR_SIZE);
17970
17971 insn_buf[0] = RELATIVEJUMP_OPCODE;
17972 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17973 index e2f751e..dffa2a0 100644
17974 --- a/arch/x86/kernel/kprobes.c
17975 +++ b/arch/x86/kernel/kprobes.c
17976 @@ -120,8 +120,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
17977 } __attribute__((packed)) *insn;
17978
17979 insn = (struct __arch_relative_insn *)from;
17980 +
17981 + pax_open_kernel();
17982 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
17983 insn->op = op;
17984 + pax_close_kernel();
17985 }
17986
17987 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
17988 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
17989 kprobe_opcode_t opcode;
17990 kprobe_opcode_t *orig_opcodes = opcodes;
17991
17992 - if (search_exception_tables((unsigned long)opcodes))
17993 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
17994 return 0; /* Page fault may occur on this address. */
17995
17996 retry:
17997 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17998 /* Another subsystem puts a breakpoint, failed to recover */
17999 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
18000 return 0;
18001 + pax_open_kernel();
18002 memcpy(dest, insn.kaddr, insn.length);
18003 + pax_close_kernel();
18004
18005 #ifdef CONFIG_X86_64
18006 if (insn_rip_relative(&insn)) {
18007 @@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
18008 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
18009 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
18010 disp = (u8 *) dest + insn_offset_displacement(&insn);
18011 + pax_open_kernel();
18012 *(s32 *) disp = (s32) newdisp;
18013 + pax_close_kernel();
18014 }
18015 #endif
18016 return insn.length;
18017 @@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
18018 * nor set current_kprobe, because it doesn't use single
18019 * stepping.
18020 */
18021 - regs->ip = (unsigned long)p->ainsn.insn;
18022 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
18023 preempt_enable_no_resched();
18024 return;
18025 }
18026 @@ -504,7 +511,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
18027 if (p->opcode == BREAKPOINT_INSTRUCTION)
18028 regs->ip = (unsigned long)p->addr;
18029 else
18030 - regs->ip = (unsigned long)p->ainsn.insn;
18031 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
18032 }
18033
18034 /*
18035 @@ -583,7 +590,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
18036 setup_singlestep(p, regs, kcb, 0);
18037 return 1;
18038 }
18039 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
18040 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
18041 /*
18042 * The breakpoint instruction was removed right
18043 * after we hit it. Another cpu has removed
18044 @@ -628,6 +635,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
18045 " movq %rax, 152(%rsp)\n"
18046 RESTORE_REGS_STRING
18047 " popfq\n"
18048 +#ifdef KERNEXEC_PLUGIN
18049 + " btsq $63,(%rsp)\n"
18050 +#endif
18051 #else
18052 " pushf\n"
18053 SAVE_REGS_STRING
18054 @@ -765,7 +775,7 @@ static void __kprobes
18055 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
18056 {
18057 unsigned long *tos = stack_addr(regs);
18058 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
18059 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
18060 unsigned long orig_ip = (unsigned long)p->addr;
18061 kprobe_opcode_t *insn = p->ainsn.insn;
18062
18063 @@ -947,7 +957,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
18064 struct die_args *args = data;
18065 int ret = NOTIFY_DONE;
18066
18067 - if (args->regs && user_mode_vm(args->regs))
18068 + if (args->regs && user_mode(args->regs))
18069 return ret;
18070
18071 switch (val) {
18072 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
18073 index ebc9873..1b9724b 100644
18074 --- a/arch/x86/kernel/ldt.c
18075 +++ b/arch/x86/kernel/ldt.c
18076 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
18077 if (reload) {
18078 #ifdef CONFIG_SMP
18079 preempt_disable();
18080 - load_LDT(pc);
18081 + load_LDT_nolock(pc);
18082 if (!cpumask_equal(mm_cpumask(current->mm),
18083 cpumask_of(smp_processor_id())))
18084 smp_call_function(flush_ldt, current->mm, 1);
18085 preempt_enable();
18086 #else
18087 - load_LDT(pc);
18088 + load_LDT_nolock(pc);
18089 #endif
18090 }
18091 if (oldsize) {
18092 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
18093 return err;
18094
18095 for (i = 0; i < old->size; i++)
18096 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
18097 + write_ldt_entry(new->ldt, i, old->ldt + i);
18098 return 0;
18099 }
18100
18101 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
18102 retval = copy_ldt(&mm->context, &old_mm->context);
18103 mutex_unlock(&old_mm->context.lock);
18104 }
18105 +
18106 + if (tsk == current) {
18107 + mm->context.vdso = 0;
18108 +
18109 +#ifdef CONFIG_X86_32
18110 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
18111 + mm->context.user_cs_base = 0UL;
18112 + mm->context.user_cs_limit = ~0UL;
18113 +
18114 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18115 + cpus_clear(mm->context.cpu_user_cs_mask);
18116 +#endif
18117 +
18118 +#endif
18119 +#endif
18120 +
18121 + }
18122 +
18123 return retval;
18124 }
18125
18126 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
18127 }
18128 }
18129
18130 +#ifdef CONFIG_PAX_SEGMEXEC
18131 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
18132 + error = -EINVAL;
18133 + goto out_unlock;
18134 + }
18135 +#endif
18136 +
18137 fill_ldt(&ldt, &ldt_info);
18138 if (oldmode)
18139 ldt.avl = 0;
18140 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
18141 index 5b19e4d..6476a76 100644
18142 --- a/arch/x86/kernel/machine_kexec_32.c
18143 +++ b/arch/x86/kernel/machine_kexec_32.c
18144 @@ -26,7 +26,7 @@
18145 #include <asm/cacheflush.h>
18146 #include <asm/debugreg.h>
18147
18148 -static void set_idt(void *newidt, __u16 limit)
18149 +static void set_idt(struct desc_struct *newidt, __u16 limit)
18150 {
18151 struct desc_ptr curidt;
18152
18153 @@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
18154 }
18155
18156
18157 -static void set_gdt(void *newgdt, __u16 limit)
18158 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
18159 {
18160 struct desc_ptr curgdt;
18161
18162 @@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
18163 }
18164
18165 control_page = page_address(image->control_code_page);
18166 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
18167 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
18168
18169 relocate_kernel_ptr = control_page;
18170 page_list[PA_CONTROL_PAGE] = __pa(control_page);
18171 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
18172 index 0327e2b..e43737b 100644
18173 --- a/arch/x86/kernel/microcode_intel.c
18174 +++ b/arch/x86/kernel/microcode_intel.c
18175 @@ -430,13 +430,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
18176
18177 static int get_ucode_user(void *to, const void *from, size_t n)
18178 {
18179 - return copy_from_user(to, from, n);
18180 + return copy_from_user(to, (const void __force_user *)from, n);
18181 }
18182
18183 static enum ucode_state
18184 request_microcode_user(int cpu, const void __user *buf, size_t size)
18185 {
18186 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
18187 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
18188 }
18189
18190 static void microcode_fini_cpu(int cpu)
18191 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
18192 index 216a4d7..b328f09 100644
18193 --- a/arch/x86/kernel/module.c
18194 +++ b/arch/x86/kernel/module.c
18195 @@ -43,15 +43,60 @@ do { \
18196 } while (0)
18197 #endif
18198
18199 -void *module_alloc(unsigned long size)
18200 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
18201 {
18202 - if (PAGE_ALIGN(size) > MODULES_LEN)
18203 + if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
18204 return NULL;
18205 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
18206 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
18207 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
18208 -1, __builtin_return_address(0));
18209 }
18210
18211 +void *module_alloc(unsigned long size)
18212 +{
18213 +
18214 +#ifdef CONFIG_PAX_KERNEXEC
18215 + return __module_alloc(size, PAGE_KERNEL);
18216 +#else
18217 + return __module_alloc(size, PAGE_KERNEL_EXEC);
18218 +#endif
18219 +
18220 +}
18221 +
18222 +#ifdef CONFIG_PAX_KERNEXEC
18223 +#ifdef CONFIG_X86_32
18224 +void *module_alloc_exec(unsigned long size)
18225 +{
18226 + struct vm_struct *area;
18227 +
18228 + if (size == 0)
18229 + return NULL;
18230 +
18231 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
18232 + return area ? area->addr : NULL;
18233 +}
18234 +EXPORT_SYMBOL(module_alloc_exec);
18235 +
18236 +void module_free_exec(struct module *mod, void *module_region)
18237 +{
18238 + vunmap(module_region);
18239 +}
18240 +EXPORT_SYMBOL(module_free_exec);
18241 +#else
18242 +void module_free_exec(struct module *mod, void *module_region)
18243 +{
18244 + module_free(mod, module_region);
18245 +}
18246 +EXPORT_SYMBOL(module_free_exec);
18247 +
18248 +void *module_alloc_exec(unsigned long size)
18249 +{
18250 + return __module_alloc(size, PAGE_KERNEL_RX);
18251 +}
18252 +EXPORT_SYMBOL(module_alloc_exec);
18253 +#endif
18254 +#endif
18255 +
18256 #ifdef CONFIG_X86_32
18257 int apply_relocate(Elf32_Shdr *sechdrs,
18258 const char *strtab,
18259 @@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18260 unsigned int i;
18261 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
18262 Elf32_Sym *sym;
18263 - uint32_t *location;
18264 + uint32_t *plocation, location;
18265
18266 DEBUGP("Applying relocate section %u to %u\n",
18267 relsec, sechdrs[relsec].sh_info);
18268 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
18269 /* This is where to make the change */
18270 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
18271 - + rel[i].r_offset;
18272 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
18273 + location = (uint32_t)plocation;
18274 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
18275 + plocation = ktla_ktva((void *)plocation);
18276 /* This is the symbol it is referring to. Note that all
18277 undefined symbols have been resolved. */
18278 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
18279 @@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18280 switch (ELF32_R_TYPE(rel[i].r_info)) {
18281 case R_386_32:
18282 /* We add the value into the location given */
18283 - *location += sym->st_value;
18284 + pax_open_kernel();
18285 + *plocation += sym->st_value;
18286 + pax_close_kernel();
18287 break;
18288 case R_386_PC32:
18289 /* Add the value, subtract its position */
18290 - *location += sym->st_value - (uint32_t)location;
18291 + pax_open_kernel();
18292 + *plocation += sym->st_value - location;
18293 + pax_close_kernel();
18294 break;
18295 default:
18296 pr_err("%s: Unknown relocation: %u\n",
18297 @@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
18298 case R_X86_64_NONE:
18299 break;
18300 case R_X86_64_64:
18301 + pax_open_kernel();
18302 *(u64 *)loc = val;
18303 + pax_close_kernel();
18304 break;
18305 case R_X86_64_32:
18306 + pax_open_kernel();
18307 *(u32 *)loc = val;
18308 + pax_close_kernel();
18309 if (val != *(u32 *)loc)
18310 goto overflow;
18311 break;
18312 case R_X86_64_32S:
18313 + pax_open_kernel();
18314 *(s32 *)loc = val;
18315 + pax_close_kernel();
18316 if ((s64)val != *(s32 *)loc)
18317 goto overflow;
18318 break;
18319 case R_X86_64_PC32:
18320 val -= (u64)loc;
18321 + pax_open_kernel();
18322 *(u32 *)loc = val;
18323 + pax_close_kernel();
18324 +
18325 #if 0
18326 if ((s64)val != *(s32 *)loc)
18327 goto overflow;
18328 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
18329 index f84f5c5..e27e54b 100644
18330 --- a/arch/x86/kernel/nmi.c
18331 +++ b/arch/x86/kernel/nmi.c
18332 @@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
18333 dotraplinkage notrace __kprobes void
18334 do_nmi(struct pt_regs *regs, long error_code)
18335 {
18336 +
18337 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18338 + if (!user_mode(regs)) {
18339 + unsigned long cs = regs->cs & 0xFFFF;
18340 + unsigned long ip = ktva_ktla(regs->ip);
18341 +
18342 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
18343 + regs->ip = ip;
18344 + }
18345 +#endif
18346 +
18347 nmi_nesting_preprocess(regs);
18348
18349 nmi_enter();
18350 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
18351 index 676b8c7..870ba04 100644
18352 --- a/arch/x86/kernel/paravirt-spinlocks.c
18353 +++ b/arch/x86/kernel/paravirt-spinlocks.c
18354 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
18355 arch_spin_lock(lock);
18356 }
18357
18358 -struct pv_lock_ops pv_lock_ops = {
18359 +struct pv_lock_ops pv_lock_ops __read_only = {
18360 #ifdef CONFIG_SMP
18361 .spin_is_locked = __ticket_spin_is_locked,
18362 .spin_is_contended = __ticket_spin_is_contended,
18363 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
18364 index 17fff18..7bb2088 100644
18365 --- a/arch/x86/kernel/paravirt.c
18366 +++ b/arch/x86/kernel/paravirt.c
18367 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
18368 {
18369 return x;
18370 }
18371 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18372 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
18373 +#endif
18374
18375 void __init default_banner(void)
18376 {
18377 @@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
18378 if (opfunc == NULL)
18379 /* If there's no function, patch it with a ud2a (BUG) */
18380 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
18381 - else if (opfunc == _paravirt_nop)
18382 + else if (opfunc == (void *)_paravirt_nop)
18383 /* If the operation is a nop, then nop the callsite */
18384 ret = paravirt_patch_nop();
18385
18386 /* identity functions just return their single argument */
18387 - else if (opfunc == _paravirt_ident_32)
18388 + else if (opfunc == (void *)_paravirt_ident_32)
18389 ret = paravirt_patch_ident_32(insnbuf, len);
18390 - else if (opfunc == _paravirt_ident_64)
18391 + else if (opfunc == (void *)_paravirt_ident_64)
18392 ret = paravirt_patch_ident_64(insnbuf, len);
18393 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18394 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
18395 + ret = paravirt_patch_ident_64(insnbuf, len);
18396 +#endif
18397
18398 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
18399 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
18400 @@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
18401 if (insn_len > len || start == NULL)
18402 insn_len = len;
18403 else
18404 - memcpy(insnbuf, start, insn_len);
18405 + memcpy(insnbuf, ktla_ktva(start), insn_len);
18406
18407 return insn_len;
18408 }
18409 @@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
18410 preempt_enable();
18411 }
18412
18413 -struct pv_info pv_info = {
18414 +struct pv_info pv_info __read_only = {
18415 .name = "bare hardware",
18416 .paravirt_enabled = 0,
18417 .kernel_rpl = 0,
18418 @@ -315,16 +322,16 @@ struct pv_info pv_info = {
18419 #endif
18420 };
18421
18422 -struct pv_init_ops pv_init_ops = {
18423 +struct pv_init_ops pv_init_ops __read_only = {
18424 .patch = native_patch,
18425 };
18426
18427 -struct pv_time_ops pv_time_ops = {
18428 +struct pv_time_ops pv_time_ops __read_only = {
18429 .sched_clock = native_sched_clock,
18430 .steal_clock = native_steal_clock,
18431 };
18432
18433 -struct pv_irq_ops pv_irq_ops = {
18434 +struct pv_irq_ops pv_irq_ops __read_only = {
18435 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
18436 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
18437 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
18438 @@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
18439 #endif
18440 };
18441
18442 -struct pv_cpu_ops pv_cpu_ops = {
18443 +struct pv_cpu_ops pv_cpu_ops __read_only = {
18444 .cpuid = native_cpuid,
18445 .get_debugreg = native_get_debugreg,
18446 .set_debugreg = native_set_debugreg,
18447 @@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
18448 .end_context_switch = paravirt_nop,
18449 };
18450
18451 -struct pv_apic_ops pv_apic_ops = {
18452 +struct pv_apic_ops pv_apic_ops __read_only = {
18453 #ifdef CONFIG_X86_LOCAL_APIC
18454 .startup_ipi_hook = paravirt_nop,
18455 #endif
18456 };
18457
18458 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
18459 +#ifdef CONFIG_X86_32
18460 +#ifdef CONFIG_X86_PAE
18461 +/* 64-bit pagetable entries */
18462 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
18463 +#else
18464 /* 32-bit pagetable entries */
18465 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
18466 +#endif
18467 #else
18468 /* 64-bit pagetable entries */
18469 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
18470 #endif
18471
18472 -struct pv_mmu_ops pv_mmu_ops = {
18473 +struct pv_mmu_ops pv_mmu_ops __read_only = {
18474
18475 .read_cr2 = native_read_cr2,
18476 .write_cr2 = native_write_cr2,
18477 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
18478 .make_pud = PTE_IDENT,
18479
18480 .set_pgd = native_set_pgd,
18481 + .set_pgd_batched = native_set_pgd_batched,
18482 #endif
18483 #endif /* PAGETABLE_LEVELS >= 3 */
18484
18485 @@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18486 },
18487
18488 .set_fixmap = native_set_fixmap,
18489 +
18490 +#ifdef CONFIG_PAX_KERNEXEC
18491 + .pax_open_kernel = native_pax_open_kernel,
18492 + .pax_close_kernel = native_pax_close_kernel,
18493 +#endif
18494 +
18495 };
18496
18497 EXPORT_SYMBOL_GPL(pv_time_ops);
18498 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
18499 index 35ccf75..7a15747 100644
18500 --- a/arch/x86/kernel/pci-iommu_table.c
18501 +++ b/arch/x86/kernel/pci-iommu_table.c
18502 @@ -2,7 +2,7 @@
18503 #include <asm/iommu_table.h>
18504 #include <linux/string.h>
18505 #include <linux/kallsyms.h>
18506 -
18507 +#include <linux/sched.h>
18508
18509 #define DEBUG 1
18510
18511 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18512 index ef6a845..8028ed3 100644
18513 --- a/arch/x86/kernel/process.c
18514 +++ b/arch/x86/kernel/process.c
18515 @@ -36,7 +36,8 @@
18516 * section. Since TSS's are completely CPU-local, we want them
18517 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
18518 */
18519 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
18520 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
18521 +EXPORT_SYMBOL(init_tss);
18522
18523 #ifdef CONFIG_X86_64
18524 static DEFINE_PER_CPU(unsigned char, is_idle);
18525 @@ -94,7 +95,7 @@ void arch_task_cache_init(void)
18526 task_xstate_cachep =
18527 kmem_cache_create("task_xstate", xstate_size,
18528 __alignof__(union thread_xstate),
18529 - SLAB_PANIC | SLAB_NOTRACK, NULL);
18530 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18531 }
18532
18533 static inline void drop_fpu(struct task_struct *tsk)
18534 @@ -117,7 +118,7 @@ void exit_thread(void)
18535 unsigned long *bp = t->io_bitmap_ptr;
18536
18537 if (bp) {
18538 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18539 + struct tss_struct *tss = init_tss + get_cpu();
18540
18541 t->io_bitmap_ptr = NULL;
18542 clear_thread_flag(TIF_IO_BITMAP);
18543 @@ -148,7 +149,7 @@ void show_regs_common(void)
18544 board = dmi_get_system_info(DMI_BOARD_NAME);
18545
18546 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
18547 - current->pid, current->comm, print_tainted(),
18548 + task_pid_nr(current), current->comm, print_tainted(),
18549 init_utsname()->release,
18550 (int)strcspn(init_utsname()->version, " "),
18551 init_utsname()->version,
18552 @@ -161,6 +162,9 @@ void flush_thread(void)
18553 {
18554 struct task_struct *tsk = current;
18555
18556 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18557 + loadsegment(gs, 0);
18558 +#endif
18559 flush_ptrace_hw_breakpoint(tsk);
18560 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18561 drop_fpu(tsk);
18562 @@ -318,10 +322,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18563 regs.di = (unsigned long) arg;
18564
18565 #ifdef CONFIG_X86_32
18566 - regs.ds = __USER_DS;
18567 - regs.es = __USER_DS;
18568 + regs.ds = __KERNEL_DS;
18569 + regs.es = __KERNEL_DS;
18570 regs.fs = __KERNEL_PERCPU;
18571 - regs.gs = __KERNEL_STACK_CANARY;
18572 + savesegment(gs, regs.gs);
18573 #else
18574 regs.ss = __KERNEL_DS;
18575 #endif
18576 @@ -407,7 +411,7 @@ static void __exit_idle(void)
18577 void exit_idle(void)
18578 {
18579 /* idle loop has pid 0 */
18580 - if (current->pid)
18581 + if (task_pid_nr(current))
18582 return;
18583 __exit_idle();
18584 }
18585 @@ -516,7 +520,7 @@ bool set_pm_idle_to_default(void)
18586
18587 return ret;
18588 }
18589 -void stop_this_cpu(void *dummy)
18590 +__noreturn void stop_this_cpu(void *dummy)
18591 {
18592 local_irq_disable();
18593 /*
18594 @@ -744,16 +748,37 @@ static int __init idle_setup(char *str)
18595 }
18596 early_param("idle", idle_setup);
18597
18598 -unsigned long arch_align_stack(unsigned long sp)
18599 +#ifdef CONFIG_PAX_RANDKSTACK
18600 +void pax_randomize_kstack(struct pt_regs *regs)
18601 {
18602 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18603 - sp -= get_random_int() % 8192;
18604 - return sp & ~0xf;
18605 -}
18606 + struct thread_struct *thread = &current->thread;
18607 + unsigned long time;
18608
18609 -unsigned long arch_randomize_brk(struct mm_struct *mm)
18610 -{
18611 - unsigned long range_end = mm->brk + 0x02000000;
18612 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18613 -}
18614 + if (!randomize_va_space)
18615 + return;
18616 +
18617 + if (v8086_mode(regs))
18618 + return;
18619
18620 + rdtscl(time);
18621 +
18622 + /* P4 seems to return a 0 LSB, ignore it */
18623 +#ifdef CONFIG_MPENTIUM4
18624 + time &= 0x3EUL;
18625 + time <<= 2;
18626 +#elif defined(CONFIG_X86_64)
18627 + time &= 0xFUL;
18628 + time <<= 4;
18629 +#else
18630 + time &= 0x1FUL;
18631 + time <<= 3;
18632 +#endif
18633 +
18634 + thread->sp0 ^= time;
18635 + load_sp0(init_tss + smp_processor_id(), thread);
18636 +
18637 +#ifdef CONFIG_X86_64
18638 + this_cpu_write(kernel_stack, thread->sp0);
18639 +#endif
18640 +}
18641 +#endif
18642 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18643 index 516fa18..80bd9e6 100644
18644 --- a/arch/x86/kernel/process_32.c
18645 +++ b/arch/x86/kernel/process_32.c
18646 @@ -64,6 +64,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18647 unsigned long thread_saved_pc(struct task_struct *tsk)
18648 {
18649 return ((unsigned long *)tsk->thread.sp)[3];
18650 +//XXX return tsk->thread.eip;
18651 }
18652
18653 void __show_regs(struct pt_regs *regs, int all)
18654 @@ -73,15 +74,14 @@ void __show_regs(struct pt_regs *regs, int all)
18655 unsigned long sp;
18656 unsigned short ss, gs;
18657
18658 - if (user_mode_vm(regs)) {
18659 + if (user_mode(regs)) {
18660 sp = regs->sp;
18661 ss = regs->ss & 0xffff;
18662 - gs = get_user_gs(regs);
18663 } else {
18664 sp = kernel_stack_pointer(regs);
18665 savesegment(ss, ss);
18666 - savesegment(gs, gs);
18667 }
18668 + gs = get_user_gs(regs);
18669
18670 show_regs_common();
18671
18672 @@ -134,13 +134,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18673 struct task_struct *tsk;
18674 int err;
18675
18676 - childregs = task_pt_regs(p);
18677 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18678 *childregs = *regs;
18679 childregs->ax = 0;
18680 childregs->sp = sp;
18681
18682 p->thread.sp = (unsigned long) childregs;
18683 p->thread.sp0 = (unsigned long) (childregs+1);
18684 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18685
18686 p->thread.ip = (unsigned long) ret_from_fork;
18687
18688 @@ -231,7 +232,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18689 struct thread_struct *prev = &prev_p->thread,
18690 *next = &next_p->thread;
18691 int cpu = smp_processor_id();
18692 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18693 + struct tss_struct *tss = init_tss + cpu;
18694 fpu_switch_t fpu;
18695
18696 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18697 @@ -255,6 +256,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18698 */
18699 lazy_save_gs(prev->gs);
18700
18701 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18702 + __set_fs(task_thread_info(next_p)->addr_limit);
18703 +#endif
18704 +
18705 /*
18706 * Load the per-thread Thread-Local Storage descriptor.
18707 */
18708 @@ -285,6 +290,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18709 */
18710 arch_end_context_switch(next_p);
18711
18712 + this_cpu_write(current_task, next_p);
18713 + this_cpu_write(current_tinfo, &next_p->tinfo);
18714 +
18715 /*
18716 * Restore %gs if needed (which is common)
18717 */
18718 @@ -293,8 +301,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18719
18720 switch_fpu_finish(next_p, fpu);
18721
18722 - this_cpu_write(current_task, next_p);
18723 -
18724 return prev_p;
18725 }
18726
18727 @@ -324,4 +330,3 @@ unsigned long get_wchan(struct task_struct *p)
18728 } while (count++ < 16);
18729 return 0;
18730 }
18731 -
18732 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18733 index 0a980c9..1d0e689 100644
18734 --- a/arch/x86/kernel/process_64.c
18735 +++ b/arch/x86/kernel/process_64.c
18736 @@ -153,8 +153,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18737 struct pt_regs *childregs;
18738 struct task_struct *me = current;
18739
18740 - childregs = ((struct pt_regs *)
18741 - (THREAD_SIZE + task_stack_page(p))) - 1;
18742 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18743 *childregs = *regs;
18744
18745 childregs->ax = 0;
18746 @@ -166,6 +165,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18747 p->thread.sp = (unsigned long) childregs;
18748 p->thread.sp0 = (unsigned long) (childregs+1);
18749 p->thread.usersp = me->thread.usersp;
18750 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18751
18752 set_tsk_thread_flag(p, TIF_FORK);
18753
18754 @@ -271,7 +271,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18755 struct thread_struct *prev = &prev_p->thread;
18756 struct thread_struct *next = &next_p->thread;
18757 int cpu = smp_processor_id();
18758 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18759 + struct tss_struct *tss = init_tss + cpu;
18760 unsigned fsindex, gsindex;
18761 fpu_switch_t fpu;
18762
18763 @@ -353,10 +353,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18764 prev->usersp = this_cpu_read(old_rsp);
18765 this_cpu_write(old_rsp, next->usersp);
18766 this_cpu_write(current_task, next_p);
18767 + this_cpu_write(current_tinfo, &next_p->tinfo);
18768
18769 - this_cpu_write(kernel_stack,
18770 - (unsigned long)task_stack_page(next_p) +
18771 - THREAD_SIZE - KERNEL_STACK_OFFSET);
18772 + this_cpu_write(kernel_stack, next->sp0);
18773
18774 /*
18775 * Now maybe reload the debug registers and handle I/O bitmaps
18776 @@ -425,12 +424,11 @@ unsigned long get_wchan(struct task_struct *p)
18777 if (!p || p == current || p->state == TASK_RUNNING)
18778 return 0;
18779 stack = (unsigned long)task_stack_page(p);
18780 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18781 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18782 return 0;
18783 fp = *(u64 *)(p->thread.sp);
18784 do {
18785 - if (fp < (unsigned long)stack ||
18786 - fp >= (unsigned long)stack+THREAD_SIZE)
18787 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18788 return 0;
18789 ip = *(u64 *)(fp+8);
18790 if (!in_sched_functions(ip))
18791 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18792 index c4c6a5c..905f440 100644
18793 --- a/arch/x86/kernel/ptrace.c
18794 +++ b/arch/x86/kernel/ptrace.c
18795 @@ -824,7 +824,7 @@ long arch_ptrace(struct task_struct *child, long request,
18796 unsigned long addr, unsigned long data)
18797 {
18798 int ret;
18799 - unsigned long __user *datap = (unsigned long __user *)data;
18800 + unsigned long __user *datap = (__force unsigned long __user *)data;
18801
18802 switch (request) {
18803 /* read the word at location addr in the USER area. */
18804 @@ -909,14 +909,14 @@ long arch_ptrace(struct task_struct *child, long request,
18805 if ((int) addr < 0)
18806 return -EIO;
18807 ret = do_get_thread_area(child, addr,
18808 - (struct user_desc __user *)data);
18809 + (__force struct user_desc __user *) data);
18810 break;
18811
18812 case PTRACE_SET_THREAD_AREA:
18813 if ((int) addr < 0)
18814 return -EIO;
18815 ret = do_set_thread_area(child, addr,
18816 - (struct user_desc __user *)data, 0);
18817 + (__force struct user_desc __user *) data, 0);
18818 break;
18819 #endif
18820
18821 @@ -1426,7 +1426,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18822 memset(info, 0, sizeof(*info));
18823 info->si_signo = SIGTRAP;
18824 info->si_code = si_code;
18825 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18826 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18827 }
18828
18829 void user_single_step_siginfo(struct task_struct *tsk,
18830 @@ -1455,6 +1455,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
18831 # define IS_IA32 0
18832 #endif
18833
18834 +#ifdef CONFIG_GRKERNSEC_SETXID
18835 +extern void gr_delayed_cred_worker(void);
18836 +#endif
18837 +
18838 /*
18839 * We must return the syscall number to actually look up in the table.
18840 * This can be -1L to skip running any syscall at all.
18841 @@ -1463,6 +1467,11 @@ long syscall_trace_enter(struct pt_regs *regs)
18842 {
18843 long ret = 0;
18844
18845 +#ifdef CONFIG_GRKERNSEC_SETXID
18846 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18847 + gr_delayed_cred_worker();
18848 +#endif
18849 +
18850 /*
18851 * If we stepped into a sysenter/syscall insn, it trapped in
18852 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
18853 @@ -1511,6 +1520,11 @@ void syscall_trace_leave(struct pt_regs *regs)
18854 {
18855 bool step;
18856
18857 +#ifdef CONFIG_GRKERNSEC_SETXID
18858 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18859 + gr_delayed_cred_worker();
18860 +#endif
18861 +
18862 audit_syscall_exit(regs);
18863
18864 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
18865 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18866 index 42eb330..139955c 100644
18867 --- a/arch/x86/kernel/pvclock.c
18868 +++ b/arch/x86/kernel/pvclock.c
18869 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18870 return pv_tsc_khz;
18871 }
18872
18873 -static atomic64_t last_value = ATOMIC64_INIT(0);
18874 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18875
18876 void pvclock_resume(void)
18877 {
18878 - atomic64_set(&last_value, 0);
18879 + atomic64_set_unchecked(&last_value, 0);
18880 }
18881
18882 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18883 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18884 * updating at the same time, and one of them could be slightly behind,
18885 * making the assumption that last_value always go forward fail to hold.
18886 */
18887 - last = atomic64_read(&last_value);
18888 + last = atomic64_read_unchecked(&last_value);
18889 do {
18890 if (ret < last)
18891 return last;
18892 - last = atomic64_cmpxchg(&last_value, last, ret);
18893 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18894 } while (unlikely(last != ret));
18895
18896 return ret;
18897 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18898 index 52190a9..8074389 100644
18899 --- a/arch/x86/kernel/reboot.c
18900 +++ b/arch/x86/kernel/reboot.c
18901 @@ -36,7 +36,7 @@ void (*pm_power_off)(void);
18902 EXPORT_SYMBOL(pm_power_off);
18903
18904 static const struct desc_ptr no_idt = {};
18905 -static int reboot_mode;
18906 +static unsigned short reboot_mode;
18907 enum reboot_type reboot_type = BOOT_ACPI;
18908 int reboot_force;
18909
18910 @@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
18911
18912 void __noreturn machine_real_restart(unsigned int type)
18913 {
18914 +
18915 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18916 + struct desc_struct *gdt;
18917 +#endif
18918 +
18919 local_irq_disable();
18920
18921 /*
18922 @@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
18923
18924 /* Jump to the identity-mapped low memory code */
18925 #ifdef CONFIG_X86_32
18926 - asm volatile("jmpl *%0" : :
18927 +
18928 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
18929 + gdt = get_cpu_gdt_table(smp_processor_id());
18930 + pax_open_kernel();
18931 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18932 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
18933 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
18934 + loadsegment(ds, __KERNEL_DS);
18935 + loadsegment(es, __KERNEL_DS);
18936 + loadsegment(ss, __KERNEL_DS);
18937 +#endif
18938 +#ifdef CONFIG_PAX_KERNEXEC
18939 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
18940 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
18941 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
18942 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
18943 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
18944 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
18945 +#endif
18946 + pax_close_kernel();
18947 +#endif
18948 +
18949 + asm volatile("ljmpl *%0" : :
18950 "rm" (real_mode_header->machine_real_restart_asm),
18951 "a" (type));
18952 #else
18953 @@ -539,7 +566,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
18954 * try to force a triple fault and then cycle between hitting the keyboard
18955 * controller and doing that
18956 */
18957 -static void native_machine_emergency_restart(void)
18958 +static void __noreturn native_machine_emergency_restart(void)
18959 {
18960 int i;
18961 int attempt = 0;
18962 @@ -662,13 +689,13 @@ void native_machine_shutdown(void)
18963 #endif
18964 }
18965
18966 -static void __machine_emergency_restart(int emergency)
18967 +static void __noreturn __machine_emergency_restart(int emergency)
18968 {
18969 reboot_emergency = emergency;
18970 machine_ops.emergency_restart();
18971 }
18972
18973 -static void native_machine_restart(char *__unused)
18974 +static void __noreturn native_machine_restart(char *__unused)
18975 {
18976 pr_notice("machine restart\n");
18977
18978 @@ -677,7 +704,7 @@ static void native_machine_restart(char *__unused)
18979 __machine_emergency_restart(0);
18980 }
18981
18982 -static void native_machine_halt(void)
18983 +static void __noreturn native_machine_halt(void)
18984 {
18985 /* Stop other cpus and apics */
18986 machine_shutdown();
18987 @@ -687,7 +714,7 @@ static void native_machine_halt(void)
18988 stop_this_cpu(NULL);
18989 }
18990
18991 -static void native_machine_power_off(void)
18992 +static void __noreturn native_machine_power_off(void)
18993 {
18994 if (pm_power_off) {
18995 if (!reboot_force)
18996 @@ -696,6 +723,7 @@ static void native_machine_power_off(void)
18997 }
18998 /* A fallback in case there is no PM info available */
18999 tboot_shutdown(TB_SHUTDOWN_HALT);
19000 + unreachable();
19001 }
19002
19003 struct machine_ops machine_ops = {
19004 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
19005 index 7a6f3b3..bed145d7 100644
19006 --- a/arch/x86/kernel/relocate_kernel_64.S
19007 +++ b/arch/x86/kernel/relocate_kernel_64.S
19008 @@ -11,6 +11,7 @@
19009 #include <asm/kexec.h>
19010 #include <asm/processor-flags.h>
19011 #include <asm/pgtable_types.h>
19012 +#include <asm/alternative-asm.h>
19013
19014 /*
19015 * Must be relocatable PIC code callable as a C function
19016 @@ -160,13 +161,14 @@ identity_mapped:
19017 xorq %rbp, %rbp
19018 xorq %r8, %r8
19019 xorq %r9, %r9
19020 - xorq %r10, %r9
19021 + xorq %r10, %r10
19022 xorq %r11, %r11
19023 xorq %r12, %r12
19024 xorq %r13, %r13
19025 xorq %r14, %r14
19026 xorq %r15, %r15
19027
19028 + pax_force_retaddr 0, 1
19029 ret
19030
19031 1:
19032 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
19033 index 5cee802..bc22bc3 100644
19034 --- a/arch/x86/kernel/setup.c
19035 +++ b/arch/x86/kernel/setup.c
19036 @@ -440,7 +440,7 @@ static void __init parse_setup_data(void)
19037
19038 switch (data->type) {
19039 case SETUP_E820_EXT:
19040 - parse_e820_ext(data);
19041 + parse_e820_ext((struct setup_data __force_kernel *)data);
19042 break;
19043 case SETUP_DTB:
19044 add_dtb(pa_data);
19045 @@ -632,7 +632,7 @@ static void __init trim_bios_range(void)
19046 * area (640->1Mb) as ram even though it is not.
19047 * take them out.
19048 */
19049 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
19050 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
19051 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
19052 }
19053
19054 @@ -755,14 +755,14 @@ void __init setup_arch(char **cmdline_p)
19055
19056 if (!boot_params.hdr.root_flags)
19057 root_mountflags &= ~MS_RDONLY;
19058 - init_mm.start_code = (unsigned long) _text;
19059 - init_mm.end_code = (unsigned long) _etext;
19060 + init_mm.start_code = ktla_ktva((unsigned long) _text);
19061 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
19062 init_mm.end_data = (unsigned long) _edata;
19063 init_mm.brk = _brk_end;
19064
19065 - code_resource.start = virt_to_phys(_text);
19066 - code_resource.end = virt_to_phys(_etext)-1;
19067 - data_resource.start = virt_to_phys(_etext);
19068 + code_resource.start = virt_to_phys(ktla_ktva(_text));
19069 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
19070 + data_resource.start = virt_to_phys(_sdata);
19071 data_resource.end = virt_to_phys(_edata)-1;
19072 bss_resource.start = virt_to_phys(&__bss_start);
19073 bss_resource.end = virt_to_phys(&__bss_stop)-1;
19074 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
19075 index 5cdff03..5810740 100644
19076 --- a/arch/x86/kernel/setup_percpu.c
19077 +++ b/arch/x86/kernel/setup_percpu.c
19078 @@ -21,19 +21,17 @@
19079 #include <asm/cpu.h>
19080 #include <asm/stackprotector.h>
19081
19082 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
19083 +#ifdef CONFIG_SMP
19084 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
19085 EXPORT_PER_CPU_SYMBOL(cpu_number);
19086 +#endif
19087
19088 -#ifdef CONFIG_X86_64
19089 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
19090 -#else
19091 -#define BOOT_PERCPU_OFFSET 0
19092 -#endif
19093
19094 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
19095 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
19096
19097 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
19098 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
19099 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
19100 };
19101 EXPORT_SYMBOL(__per_cpu_offset);
19102 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
19103 {
19104 #ifdef CONFIG_X86_32
19105 struct desc_struct gdt;
19106 + unsigned long base = per_cpu_offset(cpu);
19107
19108 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
19109 - 0x2 | DESCTYPE_S, 0x8);
19110 - gdt.s = 1;
19111 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
19112 + 0x83 | DESCTYPE_S, 0xC);
19113 write_gdt_entry(get_cpu_gdt_table(cpu),
19114 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
19115 #endif
19116 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
19117 /* alrighty, percpu areas up and running */
19118 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
19119 for_each_possible_cpu(cpu) {
19120 +#ifdef CONFIG_CC_STACKPROTECTOR
19121 +#ifdef CONFIG_X86_32
19122 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
19123 +#endif
19124 +#endif
19125 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
19126 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
19127 per_cpu(cpu_number, cpu) = cpu;
19128 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
19129 */
19130 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
19131 #endif
19132 +#ifdef CONFIG_CC_STACKPROTECTOR
19133 +#ifdef CONFIG_X86_32
19134 + if (!cpu)
19135 + per_cpu(stack_canary.canary, cpu) = canary;
19136 +#endif
19137 +#endif
19138 /*
19139 * Up to this point, the boot CPU has been using .init.data
19140 * area. Reload any changed state for the boot CPU.
19141 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
19142 index b280908..6de349e 100644
19143 --- a/arch/x86/kernel/signal.c
19144 +++ b/arch/x86/kernel/signal.c
19145 @@ -194,7 +194,7 @@ static unsigned long align_sigframe(unsigned long sp)
19146 * Align the stack pointer according to the i386 ABI,
19147 * i.e. so that on function entry ((sp + 4) & 15) == 0.
19148 */
19149 - sp = ((sp + 4) & -16ul) - 4;
19150 + sp = ((sp - 12) & -16ul) - 4;
19151 #else /* !CONFIG_X86_32 */
19152 sp = round_down(sp, 16) - 8;
19153 #endif
19154 @@ -245,11 +245,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
19155 * Return an always-bogus address instead so we will die with SIGSEGV.
19156 */
19157 if (onsigstack && !likely(on_sig_stack(sp)))
19158 - return (void __user *)-1L;
19159 + return (__force void __user *)-1L;
19160
19161 /* save i387 state */
19162 if (used_math() && save_i387_xstate(*fpstate) < 0)
19163 - return (void __user *)-1L;
19164 + return (__force void __user *)-1L;
19165
19166 return (void __user *)sp;
19167 }
19168 @@ -304,9 +304,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19169 }
19170
19171 if (current->mm->context.vdso)
19172 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19173 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19174 else
19175 - restorer = &frame->retcode;
19176 + restorer = (void __user *)&frame->retcode;
19177 if (ka->sa.sa_flags & SA_RESTORER)
19178 restorer = ka->sa.sa_restorer;
19179
19180 @@ -320,7 +320,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19181 * reasons and because gdb uses it as a signature to notice
19182 * signal handler stack frames.
19183 */
19184 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
19185 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
19186
19187 if (err)
19188 return -EFAULT;
19189 @@ -374,7 +374,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19190 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
19191
19192 /* Set up to return from userspace. */
19193 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19194 + if (current->mm->context.vdso)
19195 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19196 + else
19197 + restorer = (void __user *)&frame->retcode;
19198 if (ka->sa.sa_flags & SA_RESTORER)
19199 restorer = ka->sa.sa_restorer;
19200 put_user_ex(restorer, &frame->pretcode);
19201 @@ -386,7 +389,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19202 * reasons and because gdb uses it as a signature to notice
19203 * signal handler stack frames.
19204 */
19205 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
19206 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
19207 } put_user_catch(err);
19208
19209 if (err)
19210 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
19211 index 7c5a8c3..88d422f 100644
19212 --- a/arch/x86/kernel/smpboot.c
19213 +++ b/arch/x86/kernel/smpboot.c
19214 @@ -670,6 +670,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19215 idle->thread.sp = (unsigned long) (((struct pt_regs *)
19216 (THREAD_SIZE + task_stack_page(idle))) - 1);
19217 per_cpu(current_task, cpu) = idle;
19218 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
19219
19220 #ifdef CONFIG_X86_32
19221 /* Stack for startup_32 can be just as for start_secondary onwards */
19222 @@ -677,11 +678,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19223 #else
19224 clear_tsk_thread_flag(idle, TIF_FORK);
19225 initial_gs = per_cpu_offset(cpu);
19226 - per_cpu(kernel_stack, cpu) =
19227 - (unsigned long)task_stack_page(idle) -
19228 - KERNEL_STACK_OFFSET + THREAD_SIZE;
19229 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
19230 #endif
19231 +
19232 + pax_open_kernel();
19233 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19234 + pax_close_kernel();
19235 +
19236 initial_code = (unsigned long)start_secondary;
19237 stack_start = idle->thread.sp;
19238
19239 @@ -817,6 +820,12 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
19240
19241 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
19242
19243 +#ifdef CONFIG_PAX_PER_CPU_PGD
19244 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
19245 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19246 + KERNEL_PGD_PTRS);
19247 +#endif
19248 +
19249 err = do_boot_cpu(apicid, cpu, tidle);
19250 if (err) {
19251 pr_debug("do_boot_cpu failed %d\n", err);
19252 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
19253 index c346d11..d43b163 100644
19254 --- a/arch/x86/kernel/step.c
19255 +++ b/arch/x86/kernel/step.c
19256 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19257 struct desc_struct *desc;
19258 unsigned long base;
19259
19260 - seg &= ~7UL;
19261 + seg >>= 3;
19262
19263 mutex_lock(&child->mm->context.lock);
19264 - if (unlikely((seg >> 3) >= child->mm->context.size))
19265 + if (unlikely(seg >= child->mm->context.size))
19266 addr = -1L; /* bogus selector, access would fault */
19267 else {
19268 desc = child->mm->context.ldt + seg;
19269 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19270 addr += base;
19271 }
19272 mutex_unlock(&child->mm->context.lock);
19273 - }
19274 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
19275 + addr = ktla_ktva(addr);
19276
19277 return addr;
19278 }
19279 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19280 unsigned char opcode[15];
19281 unsigned long addr = convert_ip_to_linear(child, regs);
19282
19283 + if (addr == -EINVAL)
19284 + return 0;
19285 +
19286 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
19287 for (i = 0; i < copied; i++) {
19288 switch (opcode[i]) {
19289 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
19290 index 0b0cb5f..db6b9ed 100644
19291 --- a/arch/x86/kernel/sys_i386_32.c
19292 +++ b/arch/x86/kernel/sys_i386_32.c
19293 @@ -24,17 +24,224 @@
19294
19295 #include <asm/syscalls.h>
19296
19297 -/*
19298 - * Do a system call from kernel instead of calling sys_execve so we
19299 - * end up with proper pt_regs.
19300 - */
19301 -int kernel_execve(const char *filename,
19302 - const char *const argv[],
19303 - const char *const envp[])
19304 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
19305 {
19306 - long __res;
19307 - asm volatile ("int $0x80"
19308 - : "=a" (__res)
19309 - : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
19310 - return __res;
19311 + unsigned long pax_task_size = TASK_SIZE;
19312 +
19313 +#ifdef CONFIG_PAX_SEGMEXEC
19314 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
19315 + pax_task_size = SEGMEXEC_TASK_SIZE;
19316 +#endif
19317 +
19318 + if (len > pax_task_size || addr > pax_task_size - len)
19319 + return -EINVAL;
19320 +
19321 + return 0;
19322 +}
19323 +
19324 +unsigned long
19325 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
19326 + unsigned long len, unsigned long pgoff, unsigned long flags)
19327 +{
19328 + struct mm_struct *mm = current->mm;
19329 + struct vm_area_struct *vma;
19330 + unsigned long start_addr, pax_task_size = TASK_SIZE;
19331 +
19332 +#ifdef CONFIG_PAX_SEGMEXEC
19333 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19334 + pax_task_size = SEGMEXEC_TASK_SIZE;
19335 +#endif
19336 +
19337 + pax_task_size -= PAGE_SIZE;
19338 +
19339 + if (len > pax_task_size)
19340 + return -ENOMEM;
19341 +
19342 + if (flags & MAP_FIXED)
19343 + return addr;
19344 +
19345 +#ifdef CONFIG_PAX_RANDMMAP
19346 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19347 +#endif
19348 +
19349 + if (addr) {
19350 + addr = PAGE_ALIGN(addr);
19351 + if (pax_task_size - len >= addr) {
19352 + vma = find_vma(mm, addr);
19353 + if (check_heap_stack_gap(vma, addr, len))
19354 + return addr;
19355 + }
19356 + }
19357 + if (len > mm->cached_hole_size) {
19358 + start_addr = addr = mm->free_area_cache;
19359 + } else {
19360 + start_addr = addr = mm->mmap_base;
19361 + mm->cached_hole_size = 0;
19362 + }
19363 +
19364 +#ifdef CONFIG_PAX_PAGEEXEC
19365 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
19366 + start_addr = 0x00110000UL;
19367 +
19368 +#ifdef CONFIG_PAX_RANDMMAP
19369 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19370 + start_addr += mm->delta_mmap & 0x03FFF000UL;
19371 +#endif
19372 +
19373 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
19374 + start_addr = addr = mm->mmap_base;
19375 + else
19376 + addr = start_addr;
19377 + }
19378 +#endif
19379 +
19380 +full_search:
19381 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
19382 + /* At this point: (!vma || addr < vma->vm_end). */
19383 + if (pax_task_size - len < addr) {
19384 + /*
19385 + * Start a new search - just in case we missed
19386 + * some holes.
19387 + */
19388 + if (start_addr != mm->mmap_base) {
19389 + start_addr = addr = mm->mmap_base;
19390 + mm->cached_hole_size = 0;
19391 + goto full_search;
19392 + }
19393 + return -ENOMEM;
19394 + }
19395 + if (check_heap_stack_gap(vma, addr, len))
19396 + break;
19397 + if (addr + mm->cached_hole_size < vma->vm_start)
19398 + mm->cached_hole_size = vma->vm_start - addr;
19399 + addr = vma->vm_end;
19400 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
19401 + start_addr = addr = mm->mmap_base;
19402 + mm->cached_hole_size = 0;
19403 + goto full_search;
19404 + }
19405 + }
19406 +
19407 + /*
19408 + * Remember the place where we stopped the search:
19409 + */
19410 + mm->free_area_cache = addr + len;
19411 + return addr;
19412 +}
19413 +
19414 +unsigned long
19415 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19416 + const unsigned long len, const unsigned long pgoff,
19417 + const unsigned long flags)
19418 +{
19419 + struct vm_area_struct *vma;
19420 + struct mm_struct *mm = current->mm;
19421 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
19422 +
19423 +#ifdef CONFIG_PAX_SEGMEXEC
19424 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19425 + pax_task_size = SEGMEXEC_TASK_SIZE;
19426 +#endif
19427 +
19428 + pax_task_size -= PAGE_SIZE;
19429 +
19430 + /* requested length too big for entire address space */
19431 + if (len > pax_task_size)
19432 + return -ENOMEM;
19433 +
19434 + if (flags & MAP_FIXED)
19435 + return addr;
19436 +
19437 +#ifdef CONFIG_PAX_PAGEEXEC
19438 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19439 + goto bottomup;
19440 +#endif
19441 +
19442 +#ifdef CONFIG_PAX_RANDMMAP
19443 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19444 +#endif
19445 +
19446 + /* requesting a specific address */
19447 + if (addr) {
19448 + addr = PAGE_ALIGN(addr);
19449 + if (pax_task_size - len >= addr) {
19450 + vma = find_vma(mm, addr);
19451 + if (check_heap_stack_gap(vma, addr, len))
19452 + return addr;
19453 + }
19454 + }
19455 +
19456 + /* check if free_area_cache is useful for us */
19457 + if (len <= mm->cached_hole_size) {
19458 + mm->cached_hole_size = 0;
19459 + mm->free_area_cache = mm->mmap_base;
19460 + }
19461 +
19462 + /* either no address requested or can't fit in requested address hole */
19463 + addr = mm->free_area_cache;
19464 +
19465 + /* make sure it can fit in the remaining address space */
19466 + if (addr > len) {
19467 + vma = find_vma(mm, addr-len);
19468 + if (check_heap_stack_gap(vma, addr - len, len))
19469 + /* remember the address as a hint for next time */
19470 + return (mm->free_area_cache = addr-len);
19471 + }
19472 +
19473 + if (mm->mmap_base < len)
19474 + goto bottomup;
19475 +
19476 + addr = mm->mmap_base-len;
19477 +
19478 + do {
19479 + /*
19480 + * Lookup failure means no vma is above this address,
19481 + * else if new region fits below vma->vm_start,
19482 + * return with success:
19483 + */
19484 + vma = find_vma(mm, addr);
19485 + if (check_heap_stack_gap(vma, addr, len))
19486 + /* remember the address as a hint for next time */
19487 + return (mm->free_area_cache = addr);
19488 +
19489 + /* remember the largest hole we saw so far */
19490 + if (addr + mm->cached_hole_size < vma->vm_start)
19491 + mm->cached_hole_size = vma->vm_start - addr;
19492 +
19493 + /* try just below the current vma->vm_start */
19494 + addr = skip_heap_stack_gap(vma, len);
19495 + } while (!IS_ERR_VALUE(addr));
19496 +
19497 +bottomup:
19498 + /*
19499 + * A failed mmap() very likely causes application failure,
19500 + * so fall back to the bottom-up function here. This scenario
19501 + * can happen with large stack limits and large mmap()
19502 + * allocations.
19503 + */
19504 +
19505 +#ifdef CONFIG_PAX_SEGMEXEC
19506 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19507 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19508 + else
19509 +#endif
19510 +
19511 + mm->mmap_base = TASK_UNMAPPED_BASE;
19512 +
19513 +#ifdef CONFIG_PAX_RANDMMAP
19514 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19515 + mm->mmap_base += mm->delta_mmap;
19516 +#endif
19517 +
19518 + mm->free_area_cache = mm->mmap_base;
19519 + mm->cached_hole_size = ~0UL;
19520 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19521 + /*
19522 + * Restore the topdown base:
19523 + */
19524 + mm->mmap_base = base;
19525 + mm->free_area_cache = base;
19526 + mm->cached_hole_size = ~0UL;
19527 +
19528 + return addr;
19529 }
19530 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19531 index b4d3c39..82bb73b 100644
19532 --- a/arch/x86/kernel/sys_x86_64.c
19533 +++ b/arch/x86/kernel/sys_x86_64.c
19534 @@ -95,8 +95,8 @@ out:
19535 return error;
19536 }
19537
19538 -static void find_start_end(unsigned long flags, unsigned long *begin,
19539 - unsigned long *end)
19540 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
19541 + unsigned long *begin, unsigned long *end)
19542 {
19543 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
19544 unsigned long new_begin;
19545 @@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19546 *begin = new_begin;
19547 }
19548 } else {
19549 - *begin = TASK_UNMAPPED_BASE;
19550 + *begin = mm->mmap_base;
19551 *end = TASK_SIZE;
19552 }
19553 }
19554 @@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19555 if (flags & MAP_FIXED)
19556 return addr;
19557
19558 - find_start_end(flags, &begin, &end);
19559 + find_start_end(mm, flags, &begin, &end);
19560
19561 if (len > end)
19562 return -ENOMEM;
19563
19564 +#ifdef CONFIG_PAX_RANDMMAP
19565 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19566 +#endif
19567 +
19568 if (addr) {
19569 addr = PAGE_ALIGN(addr);
19570 vma = find_vma(mm, addr);
19571 - if (end - len >= addr &&
19572 - (!vma || addr + len <= vma->vm_start))
19573 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19574 return addr;
19575 }
19576 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
19577 @@ -172,7 +175,7 @@ full_search:
19578 }
19579 return -ENOMEM;
19580 }
19581 - if (!vma || addr + len <= vma->vm_start) {
19582 + if (check_heap_stack_gap(vma, addr, len)) {
19583 /*
19584 * Remember the place where we stopped the search:
19585 */
19586 @@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19587 {
19588 struct vm_area_struct *vma;
19589 struct mm_struct *mm = current->mm;
19590 - unsigned long addr = addr0, start_addr;
19591 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
19592
19593 /* requested length too big for entire address space */
19594 if (len > TASK_SIZE)
19595 @@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19596 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
19597 goto bottomup;
19598
19599 +#ifdef CONFIG_PAX_RANDMMAP
19600 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19601 +#endif
19602 +
19603 /* requesting a specific address */
19604 if (addr) {
19605 addr = PAGE_ALIGN(addr);
19606 - vma = find_vma(mm, addr);
19607 - if (TASK_SIZE - len >= addr &&
19608 - (!vma || addr + len <= vma->vm_start))
19609 - return addr;
19610 + if (TASK_SIZE - len >= addr) {
19611 + vma = find_vma(mm, addr);
19612 + if (check_heap_stack_gap(vma, addr, len))
19613 + return addr;
19614 + }
19615 }
19616
19617 /* check if free_area_cache is useful for us */
19618 @@ -240,7 +248,7 @@ try_again:
19619 * return with success:
19620 */
19621 vma = find_vma(mm, addr);
19622 - if (!vma || addr+len <= vma->vm_start)
19623 + if (check_heap_stack_gap(vma, addr, len))
19624 /* remember the address as a hint for next time */
19625 return mm->free_area_cache = addr;
19626
19627 @@ -249,8 +257,8 @@ try_again:
19628 mm->cached_hole_size = vma->vm_start - addr;
19629
19630 /* try just below the current vma->vm_start */
19631 - addr = vma->vm_start-len;
19632 - } while (len < vma->vm_start);
19633 + addr = skip_heap_stack_gap(vma, len);
19634 + } while (!IS_ERR_VALUE(addr));
19635
19636 fail:
19637 /*
19638 @@ -270,13 +278,21 @@ bottomup:
19639 * can happen with large stack limits and large mmap()
19640 * allocations.
19641 */
19642 + mm->mmap_base = TASK_UNMAPPED_BASE;
19643 +
19644 +#ifdef CONFIG_PAX_RANDMMAP
19645 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19646 + mm->mmap_base += mm->delta_mmap;
19647 +#endif
19648 +
19649 + mm->free_area_cache = mm->mmap_base;
19650 mm->cached_hole_size = ~0UL;
19651 - mm->free_area_cache = TASK_UNMAPPED_BASE;
19652 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19653 /*
19654 * Restore the topdown base:
19655 */
19656 - mm->free_area_cache = mm->mmap_base;
19657 + mm->mmap_base = base;
19658 + mm->free_area_cache = base;
19659 mm->cached_hole_size = ~0UL;
19660
19661 return addr;
19662 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19663 index f84fe00..93fe08f 100644
19664 --- a/arch/x86/kernel/tboot.c
19665 +++ b/arch/x86/kernel/tboot.c
19666 @@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
19667
19668 void tboot_shutdown(u32 shutdown_type)
19669 {
19670 - void (*shutdown)(void);
19671 + void (* __noreturn shutdown)(void);
19672
19673 if (!tboot_enabled())
19674 return;
19675 @@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
19676
19677 switch_to_tboot_pt();
19678
19679 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19680 + shutdown = (void *)tboot->shutdown_entry;
19681 shutdown();
19682
19683 /* should not reach here */
19684 @@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19685 return 0;
19686 }
19687
19688 -static atomic_t ap_wfs_count;
19689 +static atomic_unchecked_t ap_wfs_count;
19690
19691 static int tboot_wait_for_aps(int num_aps)
19692 {
19693 @@ -324,9 +324,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19694 {
19695 switch (action) {
19696 case CPU_DYING:
19697 - atomic_inc(&ap_wfs_count);
19698 + atomic_inc_unchecked(&ap_wfs_count);
19699 if (num_online_cpus() == 1)
19700 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19701 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19702 return NOTIFY_BAD;
19703 break;
19704 }
19705 @@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
19706
19707 tboot_create_trampoline();
19708
19709 - atomic_set(&ap_wfs_count, 0);
19710 + atomic_set_unchecked(&ap_wfs_count, 0);
19711 register_hotcpu_notifier(&tboot_cpu_notifier);
19712
19713 acpi_os_set_prepare_sleep(&tboot_sleep);
19714 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19715 index 24d3c91..d06b473 100644
19716 --- a/arch/x86/kernel/time.c
19717 +++ b/arch/x86/kernel/time.c
19718 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19719 {
19720 unsigned long pc = instruction_pointer(regs);
19721
19722 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19723 + if (!user_mode(regs) && in_lock_functions(pc)) {
19724 #ifdef CONFIG_FRAME_POINTER
19725 - return *(unsigned long *)(regs->bp + sizeof(long));
19726 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19727 #else
19728 unsigned long *sp =
19729 (unsigned long *)kernel_stack_pointer(regs);
19730 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19731 * or above a saved flags. Eflags has bits 22-31 zero,
19732 * kernel addresses don't.
19733 */
19734 +
19735 +#ifdef CONFIG_PAX_KERNEXEC
19736 + return ktla_ktva(sp[0]);
19737 +#else
19738 if (sp[0] >> 22)
19739 return sp[0];
19740 if (sp[1] >> 22)
19741 return sp[1];
19742 #endif
19743 +
19744 +#endif
19745 }
19746 return pc;
19747 }
19748 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19749 index 9d9d2f9..cad418a 100644
19750 --- a/arch/x86/kernel/tls.c
19751 +++ b/arch/x86/kernel/tls.c
19752 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19753 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19754 return -EINVAL;
19755
19756 +#ifdef CONFIG_PAX_SEGMEXEC
19757 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19758 + return -EINVAL;
19759 +#endif
19760 +
19761 set_tls_desc(p, idx, &info, 1);
19762
19763 return 0;
19764 @@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
19765
19766 if (kbuf)
19767 info = kbuf;
19768 - else if (__copy_from_user(infobuf, ubuf, count))
19769 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
19770 return -EFAULT;
19771 else
19772 info = infobuf;
19773 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19774 index b481341..5918bbe 100644
19775 --- a/arch/x86/kernel/traps.c
19776 +++ b/arch/x86/kernel/traps.c
19777 @@ -70,12 +70,6 @@ asmlinkage int system_call(void);
19778
19779 /* Do we ignore FPU interrupts ? */
19780 char ignore_fpu_irq;
19781 -
19782 -/*
19783 - * The IDT has to be page-aligned to simplify the Pentium
19784 - * F0 0F bug workaround.
19785 - */
19786 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19787 #endif
19788
19789 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19790 @@ -108,13 +102,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19791 }
19792
19793 static void __kprobes
19794 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19795 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19796 long error_code, siginfo_t *info)
19797 {
19798 struct task_struct *tsk = current;
19799
19800 #ifdef CONFIG_X86_32
19801 - if (regs->flags & X86_VM_MASK) {
19802 + if (v8086_mode(regs)) {
19803 /*
19804 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19805 * On nmi (interrupt 2), do_trap should not be called.
19806 @@ -125,7 +119,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19807 }
19808 #endif
19809
19810 - if (!user_mode(regs))
19811 + if (!user_mode_novm(regs))
19812 goto kernel_trap;
19813
19814 #ifdef CONFIG_X86_32
19815 @@ -147,7 +141,7 @@ trap_signal:
19816 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
19817 printk_ratelimit()) {
19818 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19819 - tsk->comm, tsk->pid, str,
19820 + tsk->comm, task_pid_nr(tsk), str,
19821 regs->ip, regs->sp, error_code);
19822 print_vma_addr(" in ", regs->ip);
19823 pr_cont("\n");
19824 @@ -164,8 +158,20 @@ kernel_trap:
19825 if (!fixup_exception(regs)) {
19826 tsk->thread.error_code = error_code;
19827 tsk->thread.trap_nr = trapnr;
19828 +
19829 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19830 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19831 + str = "PAX: suspicious stack segment fault";
19832 +#endif
19833 +
19834 die(str, regs, error_code);
19835 }
19836 +
19837 +#ifdef CONFIG_PAX_REFCOUNT
19838 + if (trapnr == 4)
19839 + pax_report_refcount_overflow(regs);
19840 +#endif
19841 +
19842 return;
19843
19844 #ifdef CONFIG_X86_32
19845 @@ -258,14 +264,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
19846 conditional_sti(regs);
19847
19848 #ifdef CONFIG_X86_32
19849 - if (regs->flags & X86_VM_MASK)
19850 + if (v8086_mode(regs))
19851 goto gp_in_vm86;
19852 #endif
19853
19854 tsk = current;
19855 - if (!user_mode(regs))
19856 + if (!user_mode_novm(regs))
19857 goto gp_in_kernel;
19858
19859 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19860 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
19861 + struct mm_struct *mm = tsk->mm;
19862 + unsigned long limit;
19863 +
19864 + down_write(&mm->mmap_sem);
19865 + limit = mm->context.user_cs_limit;
19866 + if (limit < TASK_SIZE) {
19867 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
19868 + up_write(&mm->mmap_sem);
19869 + return;
19870 + }
19871 + up_write(&mm->mmap_sem);
19872 + }
19873 +#endif
19874 +
19875 tsk->thread.error_code = error_code;
19876 tsk->thread.trap_nr = X86_TRAP_GP;
19877
19878 @@ -297,6 +319,13 @@ gp_in_kernel:
19879 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
19880 X86_TRAP_GP, SIGSEGV) == NOTIFY_STOP)
19881 return;
19882 +
19883 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19884 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
19885 + die("PAX: suspicious general protection fault", regs, error_code);
19886 + else
19887 +#endif
19888 +
19889 die("general protection fault", regs, error_code);
19890 }
19891
19892 @@ -432,7 +461,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19893 /* It's safe to allow irq's after DR6 has been saved */
19894 preempt_conditional_sti(regs);
19895
19896 - if (regs->flags & X86_VM_MASK) {
19897 + if (v8086_mode(regs)) {
19898 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
19899 X86_TRAP_DB);
19900 preempt_conditional_cli(regs);
19901 @@ -447,7 +476,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19902 * We already checked v86 mode above, so we can check for kernel mode
19903 * by just checking the CPL of CS.
19904 */
19905 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
19906 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
19907 tsk->thread.debugreg6 &= ~DR_STEP;
19908 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
19909 regs->flags &= ~X86_EFLAGS_TF;
19910 @@ -478,7 +507,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
19911 return;
19912 conditional_sti(regs);
19913
19914 - if (!user_mode_vm(regs))
19915 + if (!user_mode(regs))
19916 {
19917 if (!fixup_exception(regs)) {
19918 task->thread.error_code = error_code;
19919 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
19920 index 36fd420..7e5892d 100644
19921 --- a/arch/x86/kernel/uprobes.c
19922 +++ b/arch/x86/kernel/uprobes.c
19923 @@ -607,7 +607,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
19924 int ret = NOTIFY_DONE;
19925
19926 /* We are only interested in userspace traps */
19927 - if (regs && !user_mode_vm(regs))
19928 + if (regs && !user_mode(regs))
19929 return NOTIFY_DONE;
19930
19931 switch (val) {
19932 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
19933 index b9242ba..50c5edd 100644
19934 --- a/arch/x86/kernel/verify_cpu.S
19935 +++ b/arch/x86/kernel/verify_cpu.S
19936 @@ -20,6 +20,7 @@
19937 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
19938 * arch/x86/kernel/trampoline_64.S: secondary processor verification
19939 * arch/x86/kernel/head_32.S: processor startup
19940 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
19941 *
19942 * verify_cpu, returns the status of longmode and SSE in register %eax.
19943 * 0: Success 1: Failure
19944 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
19945 index 54abcc0..eb6c848 100644
19946 --- a/arch/x86/kernel/vm86_32.c
19947 +++ b/arch/x86/kernel/vm86_32.c
19948 @@ -43,6 +43,7 @@
19949 #include <linux/ptrace.h>
19950 #include <linux/audit.h>
19951 #include <linux/stddef.h>
19952 +#include <linux/grsecurity.h>
19953
19954 #include <asm/uaccess.h>
19955 #include <asm/io.h>
19956 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
19957 do_exit(SIGSEGV);
19958 }
19959
19960 - tss = &per_cpu(init_tss, get_cpu());
19961 + tss = init_tss + get_cpu();
19962 current->thread.sp0 = current->thread.saved_sp0;
19963 current->thread.sysenter_cs = __KERNEL_CS;
19964 load_sp0(tss, &current->thread);
19965 @@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
19966 struct task_struct *tsk;
19967 int tmp, ret = -EPERM;
19968
19969 +#ifdef CONFIG_GRKERNSEC_VM86
19970 + if (!capable(CAP_SYS_RAWIO)) {
19971 + gr_handle_vm86();
19972 + goto out;
19973 + }
19974 +#endif
19975 +
19976 tsk = current;
19977 if (tsk->thread.saved_sp0)
19978 goto out;
19979 @@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
19980 int tmp, ret;
19981 struct vm86plus_struct __user *v86;
19982
19983 +#ifdef CONFIG_GRKERNSEC_VM86
19984 + if (!capable(CAP_SYS_RAWIO)) {
19985 + gr_handle_vm86();
19986 + ret = -EPERM;
19987 + goto out;
19988 + }
19989 +#endif
19990 +
19991 tsk = current;
19992 switch (cmd) {
19993 case VM86_REQUEST_IRQ:
19994 @@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
19995 tsk->thread.saved_fs = info->regs32->fs;
19996 tsk->thread.saved_gs = get_user_gs(info->regs32);
19997
19998 - tss = &per_cpu(init_tss, get_cpu());
19999 + tss = init_tss + get_cpu();
20000 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
20001 if (cpu_has_sep)
20002 tsk->thread.sysenter_cs = 0;
20003 @@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
20004 goto cannot_handle;
20005 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
20006 goto cannot_handle;
20007 - intr_ptr = (unsigned long __user *) (i << 2);
20008 + intr_ptr = (__force unsigned long __user *) (i << 2);
20009 if (get_user(segoffs, intr_ptr))
20010 goto cannot_handle;
20011 if ((segoffs >> 16) == BIOSSEG)
20012 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
20013 index 22a1530..8fbaaad 100644
20014 --- a/arch/x86/kernel/vmlinux.lds.S
20015 +++ b/arch/x86/kernel/vmlinux.lds.S
20016 @@ -26,6 +26,13 @@
20017 #include <asm/page_types.h>
20018 #include <asm/cache.h>
20019 #include <asm/boot.h>
20020 +#include <asm/segment.h>
20021 +
20022 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20023 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
20024 +#else
20025 +#define __KERNEL_TEXT_OFFSET 0
20026 +#endif
20027
20028 #undef i386 /* in case the preprocessor is a 32bit one */
20029
20030 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
20031
20032 PHDRS {
20033 text PT_LOAD FLAGS(5); /* R_E */
20034 +#ifdef CONFIG_X86_32
20035 + module PT_LOAD FLAGS(5); /* R_E */
20036 +#endif
20037 +#ifdef CONFIG_XEN
20038 + rodata PT_LOAD FLAGS(5); /* R_E */
20039 +#else
20040 + rodata PT_LOAD FLAGS(4); /* R__ */
20041 +#endif
20042 data PT_LOAD FLAGS(6); /* RW_ */
20043 -#ifdef CONFIG_X86_64
20044 + init.begin PT_LOAD FLAGS(6); /* RW_ */
20045 #ifdef CONFIG_SMP
20046 percpu PT_LOAD FLAGS(6); /* RW_ */
20047 #endif
20048 + text.init PT_LOAD FLAGS(5); /* R_E */
20049 + text.exit PT_LOAD FLAGS(5); /* R_E */
20050 init PT_LOAD FLAGS(7); /* RWE */
20051 -#endif
20052 note PT_NOTE FLAGS(0); /* ___ */
20053 }
20054
20055 SECTIONS
20056 {
20057 #ifdef CONFIG_X86_32
20058 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
20059 - phys_startup_32 = startup_32 - LOAD_OFFSET;
20060 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
20061 #else
20062 - . = __START_KERNEL;
20063 - phys_startup_64 = startup_64 - LOAD_OFFSET;
20064 + . = __START_KERNEL;
20065 #endif
20066
20067 /* Text and read-only data */
20068 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
20069 - _text = .;
20070 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20071 /* bootstrapping code */
20072 +#ifdef CONFIG_X86_32
20073 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20074 +#else
20075 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20076 +#endif
20077 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20078 + _text = .;
20079 HEAD_TEXT
20080 #ifdef CONFIG_X86_32
20081 . = ALIGN(PAGE_SIZE);
20082 @@ -108,13 +128,48 @@ SECTIONS
20083 IRQENTRY_TEXT
20084 *(.fixup)
20085 *(.gnu.warning)
20086 - /* End of text section */
20087 - _etext = .;
20088 } :text = 0x9090
20089
20090 - NOTES :text :note
20091 + . += __KERNEL_TEXT_OFFSET;
20092
20093 - EXCEPTION_TABLE(16) :text = 0x9090
20094 +#ifdef CONFIG_X86_32
20095 + . = ALIGN(PAGE_SIZE);
20096 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
20097 +
20098 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
20099 + MODULES_EXEC_VADDR = .;
20100 + BYTE(0)
20101 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
20102 + . = ALIGN(HPAGE_SIZE) - 1;
20103 + MODULES_EXEC_END = .;
20104 +#endif
20105 +
20106 + } :module
20107 +#endif
20108 +
20109 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
20110 + /* End of text section */
20111 + BYTE(0)
20112 + _etext = . - __KERNEL_TEXT_OFFSET;
20113 + }
20114 +
20115 +#ifdef CONFIG_X86_32
20116 + . = ALIGN(PAGE_SIZE);
20117 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
20118 + *(.idt)
20119 + . = ALIGN(PAGE_SIZE);
20120 + *(.empty_zero_page)
20121 + *(.initial_pg_fixmap)
20122 + *(.initial_pg_pmd)
20123 + *(.initial_page_table)
20124 + *(.swapper_pg_dir)
20125 + } :rodata
20126 +#endif
20127 +
20128 + . = ALIGN(PAGE_SIZE);
20129 + NOTES :rodata :note
20130 +
20131 + EXCEPTION_TABLE(16) :rodata
20132
20133 #if defined(CONFIG_DEBUG_RODATA)
20134 /* .text should occupy whole number of pages */
20135 @@ -126,16 +181,20 @@ SECTIONS
20136
20137 /* Data */
20138 .data : AT(ADDR(.data) - LOAD_OFFSET) {
20139 +
20140 +#ifdef CONFIG_PAX_KERNEXEC
20141 + . = ALIGN(HPAGE_SIZE);
20142 +#else
20143 + . = ALIGN(PAGE_SIZE);
20144 +#endif
20145 +
20146 /* Start of data section */
20147 _sdata = .;
20148
20149 /* init_task */
20150 INIT_TASK_DATA(THREAD_SIZE)
20151
20152 -#ifdef CONFIG_X86_32
20153 - /* 32 bit has nosave before _edata */
20154 NOSAVE_DATA
20155 -#endif
20156
20157 PAGE_ALIGNED_DATA(PAGE_SIZE)
20158
20159 @@ -176,12 +235,19 @@ SECTIONS
20160 #endif /* CONFIG_X86_64 */
20161
20162 /* Init code and data - will be freed after init */
20163 - . = ALIGN(PAGE_SIZE);
20164 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
20165 + BYTE(0)
20166 +
20167 +#ifdef CONFIG_PAX_KERNEXEC
20168 + . = ALIGN(HPAGE_SIZE);
20169 +#else
20170 + . = ALIGN(PAGE_SIZE);
20171 +#endif
20172 +
20173 __init_begin = .; /* paired with __init_end */
20174 - }
20175 + } :init.begin
20176
20177 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
20178 +#ifdef CONFIG_SMP
20179 /*
20180 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
20181 * output PHDR, so the next output section - .init.text - should
20182 @@ -190,12 +256,27 @@ SECTIONS
20183 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
20184 #endif
20185
20186 - INIT_TEXT_SECTION(PAGE_SIZE)
20187 -#ifdef CONFIG_X86_64
20188 - :init
20189 -#endif
20190 + . = ALIGN(PAGE_SIZE);
20191 + init_begin = .;
20192 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
20193 + VMLINUX_SYMBOL(_sinittext) = .;
20194 + INIT_TEXT
20195 + VMLINUX_SYMBOL(_einittext) = .;
20196 + . = ALIGN(PAGE_SIZE);
20197 + } :text.init
20198
20199 - INIT_DATA_SECTION(16)
20200 + /*
20201 + * .exit.text is discard at runtime, not link time, to deal with
20202 + * references from .altinstructions and .eh_frame
20203 + */
20204 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20205 + EXIT_TEXT
20206 + . = ALIGN(16);
20207 + } :text.exit
20208 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
20209 +
20210 + . = ALIGN(PAGE_SIZE);
20211 + INIT_DATA_SECTION(16) :init
20212
20213 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
20214 __x86_cpu_dev_start = .;
20215 @@ -257,19 +338,12 @@ SECTIONS
20216 }
20217
20218 . = ALIGN(8);
20219 - /*
20220 - * .exit.text is discard at runtime, not link time, to deal with
20221 - * references from .altinstructions and .eh_frame
20222 - */
20223 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
20224 - EXIT_TEXT
20225 - }
20226
20227 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
20228 EXIT_DATA
20229 }
20230
20231 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
20232 +#ifndef CONFIG_SMP
20233 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
20234 #endif
20235
20236 @@ -288,16 +362,10 @@ SECTIONS
20237 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
20238 __smp_locks = .;
20239 *(.smp_locks)
20240 - . = ALIGN(PAGE_SIZE);
20241 __smp_locks_end = .;
20242 + . = ALIGN(PAGE_SIZE);
20243 }
20244
20245 -#ifdef CONFIG_X86_64
20246 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
20247 - NOSAVE_DATA
20248 - }
20249 -#endif
20250 -
20251 /* BSS */
20252 . = ALIGN(PAGE_SIZE);
20253 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
20254 @@ -313,6 +381,7 @@ SECTIONS
20255 __brk_base = .;
20256 . += 64 * 1024; /* 64k alignment slop space */
20257 *(.brk_reservation) /* areas brk users have reserved */
20258 + . = ALIGN(HPAGE_SIZE);
20259 __brk_limit = .;
20260 }
20261
20262 @@ -339,13 +408,12 @@ SECTIONS
20263 * for the boot processor.
20264 */
20265 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
20266 -INIT_PER_CPU(gdt_page);
20267 INIT_PER_CPU(irq_stack_union);
20268
20269 /*
20270 * Build-time check on the image size:
20271 */
20272 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
20273 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
20274 "kernel image bigger than KERNEL_IMAGE_SIZE");
20275
20276 #ifdef CONFIG_SMP
20277 diff --git a/arch/x86/kernel/vsmp_64.c b/arch/x86/kernel/vsmp_64.c
20278 index 992f890..fc38904 100644
20279 --- a/arch/x86/kernel/vsmp_64.c
20280 +++ b/arch/x86/kernel/vsmp_64.c
20281 @@ -217,8 +217,8 @@ static void fill_vector_allocation_domain(int cpu, struct cpumask *retmask,
20282 static void vsmp_apic_post_init(void)
20283 {
20284 /* need to update phys_pkg_id */
20285 - apic->phys_pkg_id = apicid_phys_pkg_id;
20286 - apic->vector_allocation_domain = fill_vector_allocation_domain;
20287 + *(void **)&apic->phys_pkg_id = apicid_phys_pkg_id;
20288 + *(void **)&apic->vector_allocation_domain = fill_vector_allocation_domain;
20289 }
20290
20291 void __init vsmp_init(void)
20292 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
20293 index 8d141b3..40a0fe4 100644
20294 --- a/arch/x86/kernel/vsyscall_64.c
20295 +++ b/arch/x86/kernel/vsyscall_64.c
20296 @@ -56,15 +56,13 @@
20297 DEFINE_VVAR(int, vgetcpu_mode);
20298 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
20299
20300 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
20301 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
20302
20303 static int __init vsyscall_setup(char *str)
20304 {
20305 if (str) {
20306 if (!strcmp("emulate", str))
20307 vsyscall_mode = EMULATE;
20308 - else if (!strcmp("native", str))
20309 - vsyscall_mode = NATIVE;
20310 else if (!strcmp("none", str))
20311 vsyscall_mode = NONE;
20312 else
20313 @@ -306,8 +304,7 @@ done:
20314 return true;
20315
20316 sigsegv:
20317 - force_sig(SIGSEGV, current);
20318 - return true;
20319 + do_group_exit(SIGKILL);
20320 }
20321
20322 /*
20323 @@ -360,10 +357,7 @@ void __init map_vsyscall(void)
20324 extern char __vvar_page;
20325 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
20326
20327 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
20328 - vsyscall_mode == NATIVE
20329 - ? PAGE_KERNEL_VSYSCALL
20330 - : PAGE_KERNEL_VVAR);
20331 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
20332 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
20333 (unsigned long)VSYSCALL_START);
20334
20335 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
20336 index 6020f6f..bedd6e3 100644
20337 --- a/arch/x86/kernel/x8664_ksyms_64.c
20338 +++ b/arch/x86/kernel/x8664_ksyms_64.c
20339 @@ -30,8 +30,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
20340 EXPORT_SYMBOL(copy_user_generic_unrolled);
20341 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
20342 EXPORT_SYMBOL(__copy_user_nocache);
20343 -EXPORT_SYMBOL(_copy_from_user);
20344 -EXPORT_SYMBOL(_copy_to_user);
20345
20346 EXPORT_SYMBOL(copy_page);
20347 EXPORT_SYMBOL(clear_page);
20348 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
20349 index 3d3e207..1a73ab2 100644
20350 --- a/arch/x86/kernel/xsave.c
20351 +++ b/arch/x86/kernel/xsave.c
20352 @@ -132,7 +132,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
20353 fx_sw_user->xstate_size > fx_sw_user->extended_size)
20354 return -EINVAL;
20355
20356 - err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
20357 + err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
20358 fx_sw_user->extended_size -
20359 FP_XSTATE_MAGIC2_SIZE));
20360 if (err)
20361 @@ -268,7 +268,7 @@ fx_only:
20362 * the other extended state.
20363 */
20364 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
20365 - return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
20366 + return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
20367 }
20368
20369 /*
20370 @@ -297,7 +297,7 @@ int restore_i387_xstate(void __user *buf)
20371 if (use_xsave())
20372 err = restore_user_xstate(buf);
20373 else
20374 - err = fxrstor_checking((__force struct i387_fxsave_struct *)
20375 + err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
20376 buf);
20377 if (unlikely(err)) {
20378 /*
20379 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
20380 index 0595f13..b544fa3 100644
20381 --- a/arch/x86/kvm/cpuid.c
20382 +++ b/arch/x86/kvm/cpuid.c
20383 @@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
20384 struct kvm_cpuid2 *cpuid,
20385 struct kvm_cpuid_entry2 __user *entries)
20386 {
20387 - int r;
20388 + int r, i;
20389
20390 r = -E2BIG;
20391 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
20392 goto out;
20393 r = -EFAULT;
20394 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
20395 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20396 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20397 goto out;
20398 + for (i = 0; i < cpuid->nent; ++i) {
20399 + struct kvm_cpuid_entry2 cpuid_entry;
20400 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
20401 + goto out;
20402 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
20403 + }
20404 vcpu->arch.cpuid_nent = cpuid->nent;
20405 kvm_apic_set_version(vcpu);
20406 kvm_x86_ops->cpuid_update(vcpu);
20407 @@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20408 struct kvm_cpuid2 *cpuid,
20409 struct kvm_cpuid_entry2 __user *entries)
20410 {
20411 - int r;
20412 + int r, i;
20413
20414 r = -E2BIG;
20415 if (cpuid->nent < vcpu->arch.cpuid_nent)
20416 goto out;
20417 r = -EFAULT;
20418 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20419 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20420 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20421 goto out;
20422 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20423 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20424 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20425 + goto out;
20426 + }
20427 return 0;
20428
20429 out:
20430 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20431 index a3b57a2..ebbe732 100644
20432 --- a/arch/x86/kvm/emulate.c
20433 +++ b/arch/x86/kvm/emulate.c
20434 @@ -256,6 +256,7 @@ struct gprefix {
20435
20436 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
20437 do { \
20438 + unsigned long _tmp; \
20439 __asm__ __volatile__ ( \
20440 _PRE_EFLAGS("0", "4", "2") \
20441 _op _suffix " %"_x"3,%1; " \
20442 @@ -270,8 +271,6 @@ struct gprefix {
20443 /* Raw emulation: instruction has two explicit operands. */
20444 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
20445 do { \
20446 - unsigned long _tmp; \
20447 - \
20448 switch ((ctxt)->dst.bytes) { \
20449 case 2: \
20450 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
20451 @@ -287,7 +286,6 @@ struct gprefix {
20452
20453 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20454 do { \
20455 - unsigned long _tmp; \
20456 switch ((ctxt)->dst.bytes) { \
20457 case 1: \
20458 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20459 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20460 index ce87878..ab48aa3 100644
20461 --- a/arch/x86/kvm/lapic.c
20462 +++ b/arch/x86/kvm/lapic.c
20463 @@ -54,7 +54,7 @@
20464 #define APIC_BUS_CYCLE_NS 1
20465
20466 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20467 -#define apic_debug(fmt, arg...)
20468 +#define apic_debug(fmt, arg...) do {} while (0)
20469
20470 #define APIC_LVT_NUM 6
20471 /* 14 is the version for Xeon and Pentium 8.4.8*/
20472 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20473 index bb7cf01..0348a05 100644
20474 --- a/arch/x86/kvm/paging_tmpl.h
20475 +++ b/arch/x86/kvm/paging_tmpl.h
20476 @@ -196,7 +196,7 @@ retry_walk:
20477 if (unlikely(kvm_is_error_hva(host_addr)))
20478 goto error;
20479
20480 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20481 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20482 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20483 goto error;
20484
20485 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20486 index baead95..90feeb4 100644
20487 --- a/arch/x86/kvm/svm.c
20488 +++ b/arch/x86/kvm/svm.c
20489 @@ -3516,7 +3516,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20490 int cpu = raw_smp_processor_id();
20491
20492 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20493 +
20494 + pax_open_kernel();
20495 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20496 + pax_close_kernel();
20497 +
20498 load_TR_desc();
20499 }
20500
20501 @@ -3894,6 +3898,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20502 #endif
20503 #endif
20504
20505 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20506 + __set_fs(current_thread_info()->addr_limit);
20507 +#endif
20508 +
20509 reload_tss(vcpu);
20510
20511 local_irq_disable();
20512 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20513 index b1eb202..254e292 100644
20514 --- a/arch/x86/kvm/vmx.c
20515 +++ b/arch/x86/kvm/vmx.c
20516 @@ -1331,7 +1331,11 @@ static void reload_tss(void)
20517 struct desc_struct *descs;
20518
20519 descs = (void *)gdt->address;
20520 +
20521 + pax_open_kernel();
20522 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20523 + pax_close_kernel();
20524 +
20525 load_TR_desc();
20526 }
20527
20528 @@ -1541,6 +1545,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
20529 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
20530 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
20531
20532 +#ifdef CONFIG_PAX_PER_CPU_PGD
20533 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
20534 +#endif
20535 +
20536 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
20537 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
20538 vmx->loaded_vmcs->cpu = cpu;
20539 @@ -2674,8 +2682,11 @@ static __init int hardware_setup(void)
20540 if (!cpu_has_vmx_flexpriority())
20541 flexpriority_enabled = 0;
20542
20543 - if (!cpu_has_vmx_tpr_shadow())
20544 - kvm_x86_ops->update_cr8_intercept = NULL;
20545 + if (!cpu_has_vmx_tpr_shadow()) {
20546 + pax_open_kernel();
20547 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
20548 + pax_close_kernel();
20549 + }
20550
20551 if (enable_ept && !cpu_has_vmx_ept_2m_page())
20552 kvm_disable_largepages();
20553 @@ -3745,7 +3756,10 @@ static void vmx_set_constant_host_state(void)
20554
20555 vmcs_writel(HOST_CR0, read_cr0() | X86_CR0_TS); /* 22.2.3 */
20556 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
20557 +
20558 +#ifndef CONFIG_PAX_PER_CPU_PGD
20559 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
20560 +#endif
20561
20562 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
20563 #ifdef CONFIG_X86_64
20564 @@ -3767,7 +3781,7 @@ static void vmx_set_constant_host_state(void)
20565 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20566
20567 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
20568 - vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
20569 + vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
20570
20571 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20572 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20573 @@ -6321,6 +6335,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20574 "jmp .Lkvm_vmx_return \n\t"
20575 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
20576 ".Lkvm_vmx_return: "
20577 +
20578 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20579 + "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
20580 + ".Lkvm_vmx_return2: "
20581 +#endif
20582 +
20583 /* Save guest registers, load host registers, keep flags */
20584 "mov %0, %c[wordsize](%%"R"sp) \n\t"
20585 "pop %0 \n\t"
20586 @@ -6369,6 +6389,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20587 #endif
20588 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20589 [wordsize]"i"(sizeof(ulong))
20590 +
20591 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20592 + ,[cs]"i"(__KERNEL_CS)
20593 +#endif
20594 +
20595 : "cc", "memory"
20596 , R"ax", R"bx", R"di", R"si"
20597 #ifdef CONFIG_X86_64
20598 @@ -6376,7 +6401,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20599 #endif
20600 );
20601
20602 -#ifndef CONFIG_X86_64
20603 +#ifdef CONFIG_X86_32
20604 /*
20605 * The sysexit path does not restore ds/es, so we must set them to
20606 * a reasonable value ourselves.
20607 @@ -6385,8 +6410,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20608 * may be executed in interrupt context, which saves and restore segments
20609 * around it, nullifying its effect.
20610 */
20611 - loadsegment(ds, __USER_DS);
20612 - loadsegment(es, __USER_DS);
20613 + loadsegment(ds, __KERNEL_DS);
20614 + loadsegment(es, __KERNEL_DS);
20615 + loadsegment(ss, __KERNEL_DS);
20616 +
20617 +#ifdef CONFIG_PAX_KERNEXEC
20618 + loadsegment(fs, __KERNEL_PERCPU);
20619 +#endif
20620 +
20621 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20622 + __set_fs(current_thread_info()->addr_limit);
20623 +#endif
20624 +
20625 #endif
20626
20627 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
20628 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20629 index 2966c84..207d0cb 100644
20630 --- a/arch/x86/kvm/x86.c
20631 +++ b/arch/x86/kvm/x86.c
20632 @@ -1379,8 +1379,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20633 {
20634 struct kvm *kvm = vcpu->kvm;
20635 int lm = is_long_mode(vcpu);
20636 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20637 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20638 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20639 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20640 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20641 : kvm->arch.xen_hvm_config.blob_size_32;
20642 u32 page_num = data & ~PAGE_MASK;
20643 @@ -2243,6 +2243,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20644 if (n < msr_list.nmsrs)
20645 goto out;
20646 r = -EFAULT;
20647 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20648 + goto out;
20649 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20650 num_msrs_to_save * sizeof(u32)))
20651 goto out;
20652 @@ -2368,7 +2370,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20653 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20654 struct kvm_interrupt *irq)
20655 {
20656 - if (irq->irq < 0 || irq->irq >= 256)
20657 + if (irq->irq >= 256)
20658 return -EINVAL;
20659 if (irqchip_in_kernel(vcpu->kvm))
20660 return -ENXIO;
20661 @@ -4889,7 +4891,7 @@ static void kvm_set_mmio_spte_mask(void)
20662 kvm_mmu_set_mmio_spte_mask(mask);
20663 }
20664
20665 -int kvm_arch_init(void *opaque)
20666 +int kvm_arch_init(const void *opaque)
20667 {
20668 int r;
20669 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
20670 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
20671 index 642d880..cc9ebac 100644
20672 --- a/arch/x86/lguest/boot.c
20673 +++ b/arch/x86/lguest/boot.c
20674 @@ -1116,12 +1116,12 @@ static u32 lguest_apic_safe_wait_icr_idle(void)
20675
20676 static void set_lguest_basic_apic_ops(void)
20677 {
20678 - apic->read = lguest_apic_read;
20679 - apic->write = lguest_apic_write;
20680 - apic->icr_read = lguest_apic_icr_read;
20681 - apic->icr_write = lguest_apic_icr_write;
20682 - apic->wait_icr_idle = lguest_apic_wait_icr_idle;
20683 - apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
20684 + *(void **)&apic->read = lguest_apic_read;
20685 + *(void **)&apic->write = lguest_apic_write;
20686 + *(void **)&apic->icr_read = lguest_apic_icr_read;
20687 + *(void **)&apic->icr_write = lguest_apic_icr_write;
20688 + *(void **)&apic->wait_icr_idle = lguest_apic_wait_icr_idle;
20689 + *(void **)&apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
20690 };
20691 #endif
20692
20693 @@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
20694 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
20695 * Launcher to reboot us.
20696 */
20697 -static void lguest_restart(char *reason)
20698 +static __noreturn void lguest_restart(char *reason)
20699 {
20700 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
20701 + BUG();
20702 }
20703
20704 /*G:050
20705 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20706 index 00933d5..3a64af9 100644
20707 --- a/arch/x86/lib/atomic64_386_32.S
20708 +++ b/arch/x86/lib/atomic64_386_32.S
20709 @@ -48,6 +48,10 @@ BEGIN(read)
20710 movl (v), %eax
20711 movl 4(v), %edx
20712 RET_ENDP
20713 +BEGIN(read_unchecked)
20714 + movl (v), %eax
20715 + movl 4(v), %edx
20716 +RET_ENDP
20717 #undef v
20718
20719 #define v %esi
20720 @@ -55,6 +59,10 @@ BEGIN(set)
20721 movl %ebx, (v)
20722 movl %ecx, 4(v)
20723 RET_ENDP
20724 +BEGIN(set_unchecked)
20725 + movl %ebx, (v)
20726 + movl %ecx, 4(v)
20727 +RET_ENDP
20728 #undef v
20729
20730 #define v %esi
20731 @@ -70,6 +78,20 @@ RET_ENDP
20732 BEGIN(add)
20733 addl %eax, (v)
20734 adcl %edx, 4(v)
20735 +
20736 +#ifdef CONFIG_PAX_REFCOUNT
20737 + jno 0f
20738 + subl %eax, (v)
20739 + sbbl %edx, 4(v)
20740 + int $4
20741 +0:
20742 + _ASM_EXTABLE(0b, 0b)
20743 +#endif
20744 +
20745 +RET_ENDP
20746 +BEGIN(add_unchecked)
20747 + addl %eax, (v)
20748 + adcl %edx, 4(v)
20749 RET_ENDP
20750 #undef v
20751
20752 @@ -77,6 +99,24 @@ RET_ENDP
20753 BEGIN(add_return)
20754 addl (v), %eax
20755 adcl 4(v), %edx
20756 +
20757 +#ifdef CONFIG_PAX_REFCOUNT
20758 + into
20759 +1234:
20760 + _ASM_EXTABLE(1234b, 2f)
20761 +#endif
20762 +
20763 + movl %eax, (v)
20764 + movl %edx, 4(v)
20765 +
20766 +#ifdef CONFIG_PAX_REFCOUNT
20767 +2:
20768 +#endif
20769 +
20770 +RET_ENDP
20771 +BEGIN(add_return_unchecked)
20772 + addl (v), %eax
20773 + adcl 4(v), %edx
20774 movl %eax, (v)
20775 movl %edx, 4(v)
20776 RET_ENDP
20777 @@ -86,6 +126,20 @@ RET_ENDP
20778 BEGIN(sub)
20779 subl %eax, (v)
20780 sbbl %edx, 4(v)
20781 +
20782 +#ifdef CONFIG_PAX_REFCOUNT
20783 + jno 0f
20784 + addl %eax, (v)
20785 + adcl %edx, 4(v)
20786 + int $4
20787 +0:
20788 + _ASM_EXTABLE(0b, 0b)
20789 +#endif
20790 +
20791 +RET_ENDP
20792 +BEGIN(sub_unchecked)
20793 + subl %eax, (v)
20794 + sbbl %edx, 4(v)
20795 RET_ENDP
20796 #undef v
20797
20798 @@ -96,6 +150,27 @@ BEGIN(sub_return)
20799 sbbl $0, %edx
20800 addl (v), %eax
20801 adcl 4(v), %edx
20802 +
20803 +#ifdef CONFIG_PAX_REFCOUNT
20804 + into
20805 +1234:
20806 + _ASM_EXTABLE(1234b, 2f)
20807 +#endif
20808 +
20809 + movl %eax, (v)
20810 + movl %edx, 4(v)
20811 +
20812 +#ifdef CONFIG_PAX_REFCOUNT
20813 +2:
20814 +#endif
20815 +
20816 +RET_ENDP
20817 +BEGIN(sub_return_unchecked)
20818 + negl %edx
20819 + negl %eax
20820 + sbbl $0, %edx
20821 + addl (v), %eax
20822 + adcl 4(v), %edx
20823 movl %eax, (v)
20824 movl %edx, 4(v)
20825 RET_ENDP
20826 @@ -105,6 +180,20 @@ RET_ENDP
20827 BEGIN(inc)
20828 addl $1, (v)
20829 adcl $0, 4(v)
20830 +
20831 +#ifdef CONFIG_PAX_REFCOUNT
20832 + jno 0f
20833 + subl $1, (v)
20834 + sbbl $0, 4(v)
20835 + int $4
20836 +0:
20837 + _ASM_EXTABLE(0b, 0b)
20838 +#endif
20839 +
20840 +RET_ENDP
20841 +BEGIN(inc_unchecked)
20842 + addl $1, (v)
20843 + adcl $0, 4(v)
20844 RET_ENDP
20845 #undef v
20846
20847 @@ -114,6 +203,26 @@ BEGIN(inc_return)
20848 movl 4(v), %edx
20849 addl $1, %eax
20850 adcl $0, %edx
20851 +
20852 +#ifdef CONFIG_PAX_REFCOUNT
20853 + into
20854 +1234:
20855 + _ASM_EXTABLE(1234b, 2f)
20856 +#endif
20857 +
20858 + movl %eax, (v)
20859 + movl %edx, 4(v)
20860 +
20861 +#ifdef CONFIG_PAX_REFCOUNT
20862 +2:
20863 +#endif
20864 +
20865 +RET_ENDP
20866 +BEGIN(inc_return_unchecked)
20867 + movl (v), %eax
20868 + movl 4(v), %edx
20869 + addl $1, %eax
20870 + adcl $0, %edx
20871 movl %eax, (v)
20872 movl %edx, 4(v)
20873 RET_ENDP
20874 @@ -123,6 +232,20 @@ RET_ENDP
20875 BEGIN(dec)
20876 subl $1, (v)
20877 sbbl $0, 4(v)
20878 +
20879 +#ifdef CONFIG_PAX_REFCOUNT
20880 + jno 0f
20881 + addl $1, (v)
20882 + adcl $0, 4(v)
20883 + int $4
20884 +0:
20885 + _ASM_EXTABLE(0b, 0b)
20886 +#endif
20887 +
20888 +RET_ENDP
20889 +BEGIN(dec_unchecked)
20890 + subl $1, (v)
20891 + sbbl $0, 4(v)
20892 RET_ENDP
20893 #undef v
20894
20895 @@ -132,6 +255,26 @@ BEGIN(dec_return)
20896 movl 4(v), %edx
20897 subl $1, %eax
20898 sbbl $0, %edx
20899 +
20900 +#ifdef CONFIG_PAX_REFCOUNT
20901 + into
20902 +1234:
20903 + _ASM_EXTABLE(1234b, 2f)
20904 +#endif
20905 +
20906 + movl %eax, (v)
20907 + movl %edx, 4(v)
20908 +
20909 +#ifdef CONFIG_PAX_REFCOUNT
20910 +2:
20911 +#endif
20912 +
20913 +RET_ENDP
20914 +BEGIN(dec_return_unchecked)
20915 + movl (v), %eax
20916 + movl 4(v), %edx
20917 + subl $1, %eax
20918 + sbbl $0, %edx
20919 movl %eax, (v)
20920 movl %edx, 4(v)
20921 RET_ENDP
20922 @@ -143,6 +286,13 @@ BEGIN(add_unless)
20923 adcl %edx, %edi
20924 addl (v), %eax
20925 adcl 4(v), %edx
20926 +
20927 +#ifdef CONFIG_PAX_REFCOUNT
20928 + into
20929 +1234:
20930 + _ASM_EXTABLE(1234b, 2f)
20931 +#endif
20932 +
20933 cmpl %eax, %ecx
20934 je 3f
20935 1:
20936 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
20937 1:
20938 addl $1, %eax
20939 adcl $0, %edx
20940 +
20941 +#ifdef CONFIG_PAX_REFCOUNT
20942 + into
20943 +1234:
20944 + _ASM_EXTABLE(1234b, 2f)
20945 +#endif
20946 +
20947 movl %eax, (v)
20948 movl %edx, 4(v)
20949 movl $1, %eax
20950 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
20951 movl 4(v), %edx
20952 subl $1, %eax
20953 sbbl $0, %edx
20954 +
20955 +#ifdef CONFIG_PAX_REFCOUNT
20956 + into
20957 +1234:
20958 + _ASM_EXTABLE(1234b, 1f)
20959 +#endif
20960 +
20961 js 1f
20962 movl %eax, (v)
20963 movl %edx, 4(v)
20964 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
20965 index f5cc9eb..51fa319 100644
20966 --- a/arch/x86/lib/atomic64_cx8_32.S
20967 +++ b/arch/x86/lib/atomic64_cx8_32.S
20968 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
20969 CFI_STARTPROC
20970
20971 read64 %ecx
20972 + pax_force_retaddr
20973 ret
20974 CFI_ENDPROC
20975 ENDPROC(atomic64_read_cx8)
20976
20977 +ENTRY(atomic64_read_unchecked_cx8)
20978 + CFI_STARTPROC
20979 +
20980 + read64 %ecx
20981 + pax_force_retaddr
20982 + ret
20983 + CFI_ENDPROC
20984 +ENDPROC(atomic64_read_unchecked_cx8)
20985 +
20986 ENTRY(atomic64_set_cx8)
20987 CFI_STARTPROC
20988
20989 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
20990 cmpxchg8b (%esi)
20991 jne 1b
20992
20993 + pax_force_retaddr
20994 ret
20995 CFI_ENDPROC
20996 ENDPROC(atomic64_set_cx8)
20997
20998 +ENTRY(atomic64_set_unchecked_cx8)
20999 + CFI_STARTPROC
21000 +
21001 +1:
21002 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
21003 + * are atomic on 586 and newer */
21004 + cmpxchg8b (%esi)
21005 + jne 1b
21006 +
21007 + pax_force_retaddr
21008 + ret
21009 + CFI_ENDPROC
21010 +ENDPROC(atomic64_set_unchecked_cx8)
21011 +
21012 ENTRY(atomic64_xchg_cx8)
21013 CFI_STARTPROC
21014
21015 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
21016 cmpxchg8b (%esi)
21017 jne 1b
21018
21019 + pax_force_retaddr
21020 ret
21021 CFI_ENDPROC
21022 ENDPROC(atomic64_xchg_cx8)
21023
21024 -.macro addsub_return func ins insc
21025 -ENTRY(atomic64_\func\()_return_cx8)
21026 +.macro addsub_return func ins insc unchecked=""
21027 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21028 CFI_STARTPROC
21029 SAVE ebp
21030 SAVE ebx
21031 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
21032 movl %edx, %ecx
21033 \ins\()l %esi, %ebx
21034 \insc\()l %edi, %ecx
21035 +
21036 +.ifb \unchecked
21037 +#ifdef CONFIG_PAX_REFCOUNT
21038 + into
21039 +2:
21040 + _ASM_EXTABLE(2b, 3f)
21041 +#endif
21042 +.endif
21043 +
21044 LOCK_PREFIX
21045 cmpxchg8b (%ebp)
21046 jne 1b
21047 -
21048 -10:
21049 movl %ebx, %eax
21050 movl %ecx, %edx
21051 +
21052 +.ifb \unchecked
21053 +#ifdef CONFIG_PAX_REFCOUNT
21054 +3:
21055 +#endif
21056 +.endif
21057 +
21058 RESTORE edi
21059 RESTORE esi
21060 RESTORE ebx
21061 RESTORE ebp
21062 + pax_force_retaddr
21063 ret
21064 CFI_ENDPROC
21065 -ENDPROC(atomic64_\func\()_return_cx8)
21066 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21067 .endm
21068
21069 addsub_return add add adc
21070 addsub_return sub sub sbb
21071 +addsub_return add add adc _unchecked
21072 +addsub_return sub sub sbb _unchecked
21073
21074 -.macro incdec_return func ins insc
21075 -ENTRY(atomic64_\func\()_return_cx8)
21076 +.macro incdec_return func ins insc unchecked=""
21077 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21078 CFI_STARTPROC
21079 SAVE ebx
21080
21081 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
21082 movl %edx, %ecx
21083 \ins\()l $1, %ebx
21084 \insc\()l $0, %ecx
21085 +
21086 +.ifb \unchecked
21087 +#ifdef CONFIG_PAX_REFCOUNT
21088 + into
21089 +2:
21090 + _ASM_EXTABLE(2b, 3f)
21091 +#endif
21092 +.endif
21093 +
21094 LOCK_PREFIX
21095 cmpxchg8b (%esi)
21096 jne 1b
21097
21098 -10:
21099 movl %ebx, %eax
21100 movl %ecx, %edx
21101 +
21102 +.ifb \unchecked
21103 +#ifdef CONFIG_PAX_REFCOUNT
21104 +3:
21105 +#endif
21106 +.endif
21107 +
21108 RESTORE ebx
21109 + pax_force_retaddr
21110 ret
21111 CFI_ENDPROC
21112 -ENDPROC(atomic64_\func\()_return_cx8)
21113 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21114 .endm
21115
21116 incdec_return inc add adc
21117 incdec_return dec sub sbb
21118 +incdec_return inc add adc _unchecked
21119 +incdec_return dec sub sbb _unchecked
21120
21121 ENTRY(atomic64_dec_if_positive_cx8)
21122 CFI_STARTPROC
21123 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
21124 movl %edx, %ecx
21125 subl $1, %ebx
21126 sbb $0, %ecx
21127 +
21128 +#ifdef CONFIG_PAX_REFCOUNT
21129 + into
21130 +1234:
21131 + _ASM_EXTABLE(1234b, 2f)
21132 +#endif
21133 +
21134 js 2f
21135 LOCK_PREFIX
21136 cmpxchg8b (%esi)
21137 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
21138 movl %ebx, %eax
21139 movl %ecx, %edx
21140 RESTORE ebx
21141 + pax_force_retaddr
21142 ret
21143 CFI_ENDPROC
21144 ENDPROC(atomic64_dec_if_positive_cx8)
21145 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
21146 movl %edx, %ecx
21147 addl %ebp, %ebx
21148 adcl %edi, %ecx
21149 +
21150 +#ifdef CONFIG_PAX_REFCOUNT
21151 + into
21152 +1234:
21153 + _ASM_EXTABLE(1234b, 3f)
21154 +#endif
21155 +
21156 LOCK_PREFIX
21157 cmpxchg8b (%esi)
21158 jne 1b
21159 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
21160 CFI_ADJUST_CFA_OFFSET -8
21161 RESTORE ebx
21162 RESTORE ebp
21163 + pax_force_retaddr
21164 ret
21165 4:
21166 cmpl %edx, 4(%esp)
21167 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
21168 xorl %ecx, %ecx
21169 addl $1, %ebx
21170 adcl %edx, %ecx
21171 +
21172 +#ifdef CONFIG_PAX_REFCOUNT
21173 + into
21174 +1234:
21175 + _ASM_EXTABLE(1234b, 3f)
21176 +#endif
21177 +
21178 LOCK_PREFIX
21179 cmpxchg8b (%esi)
21180 jne 1b
21181 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
21182 movl $1, %eax
21183 3:
21184 RESTORE ebx
21185 + pax_force_retaddr
21186 ret
21187 CFI_ENDPROC
21188 ENDPROC(atomic64_inc_not_zero_cx8)
21189 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
21190 index 2af5df3..62b1a5a 100644
21191 --- a/arch/x86/lib/checksum_32.S
21192 +++ b/arch/x86/lib/checksum_32.S
21193 @@ -29,7 +29,8 @@
21194 #include <asm/dwarf2.h>
21195 #include <asm/errno.h>
21196 #include <asm/asm.h>
21197 -
21198 +#include <asm/segment.h>
21199 +
21200 /*
21201 * computes a partial checksum, e.g. for TCP/UDP fragments
21202 */
21203 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
21204
21205 #define ARGBASE 16
21206 #define FP 12
21207 -
21208 -ENTRY(csum_partial_copy_generic)
21209 +
21210 +ENTRY(csum_partial_copy_generic_to_user)
21211 CFI_STARTPROC
21212 +
21213 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21214 + pushl_cfi %gs
21215 + popl_cfi %es
21216 + jmp csum_partial_copy_generic
21217 +#endif
21218 +
21219 +ENTRY(csum_partial_copy_generic_from_user)
21220 +
21221 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21222 + pushl_cfi %gs
21223 + popl_cfi %ds
21224 +#endif
21225 +
21226 +ENTRY(csum_partial_copy_generic)
21227 subl $4,%esp
21228 CFI_ADJUST_CFA_OFFSET 4
21229 pushl_cfi %edi
21230 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
21231 jmp 4f
21232 SRC(1: movw (%esi), %bx )
21233 addl $2, %esi
21234 -DST( movw %bx, (%edi) )
21235 +DST( movw %bx, %es:(%edi) )
21236 addl $2, %edi
21237 addw %bx, %ax
21238 adcl $0, %eax
21239 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
21240 SRC(1: movl (%esi), %ebx )
21241 SRC( movl 4(%esi), %edx )
21242 adcl %ebx, %eax
21243 -DST( movl %ebx, (%edi) )
21244 +DST( movl %ebx, %es:(%edi) )
21245 adcl %edx, %eax
21246 -DST( movl %edx, 4(%edi) )
21247 +DST( movl %edx, %es:4(%edi) )
21248
21249 SRC( movl 8(%esi), %ebx )
21250 SRC( movl 12(%esi), %edx )
21251 adcl %ebx, %eax
21252 -DST( movl %ebx, 8(%edi) )
21253 +DST( movl %ebx, %es:8(%edi) )
21254 adcl %edx, %eax
21255 -DST( movl %edx, 12(%edi) )
21256 +DST( movl %edx, %es:12(%edi) )
21257
21258 SRC( movl 16(%esi), %ebx )
21259 SRC( movl 20(%esi), %edx )
21260 adcl %ebx, %eax
21261 -DST( movl %ebx, 16(%edi) )
21262 +DST( movl %ebx, %es:16(%edi) )
21263 adcl %edx, %eax
21264 -DST( movl %edx, 20(%edi) )
21265 +DST( movl %edx, %es:20(%edi) )
21266
21267 SRC( movl 24(%esi), %ebx )
21268 SRC( movl 28(%esi), %edx )
21269 adcl %ebx, %eax
21270 -DST( movl %ebx, 24(%edi) )
21271 +DST( movl %ebx, %es:24(%edi) )
21272 adcl %edx, %eax
21273 -DST( movl %edx, 28(%edi) )
21274 +DST( movl %edx, %es:28(%edi) )
21275
21276 lea 32(%esi), %esi
21277 lea 32(%edi), %edi
21278 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
21279 shrl $2, %edx # This clears CF
21280 SRC(3: movl (%esi), %ebx )
21281 adcl %ebx, %eax
21282 -DST( movl %ebx, (%edi) )
21283 +DST( movl %ebx, %es:(%edi) )
21284 lea 4(%esi), %esi
21285 lea 4(%edi), %edi
21286 dec %edx
21287 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
21288 jb 5f
21289 SRC( movw (%esi), %cx )
21290 leal 2(%esi), %esi
21291 -DST( movw %cx, (%edi) )
21292 +DST( movw %cx, %es:(%edi) )
21293 leal 2(%edi), %edi
21294 je 6f
21295 shll $16,%ecx
21296 SRC(5: movb (%esi), %cl )
21297 -DST( movb %cl, (%edi) )
21298 +DST( movb %cl, %es:(%edi) )
21299 6: addl %ecx, %eax
21300 adcl $0, %eax
21301 7:
21302 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
21303
21304 6001:
21305 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21306 - movl $-EFAULT, (%ebx)
21307 + movl $-EFAULT, %ss:(%ebx)
21308
21309 # zero the complete destination - computing the rest
21310 # is too much work
21311 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
21312
21313 6002:
21314 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21315 - movl $-EFAULT,(%ebx)
21316 + movl $-EFAULT,%ss:(%ebx)
21317 jmp 5000b
21318
21319 .previous
21320
21321 + pushl_cfi %ss
21322 + popl_cfi %ds
21323 + pushl_cfi %ss
21324 + popl_cfi %es
21325 popl_cfi %ebx
21326 CFI_RESTORE ebx
21327 popl_cfi %esi
21328 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
21329 popl_cfi %ecx # equivalent to addl $4,%esp
21330 ret
21331 CFI_ENDPROC
21332 -ENDPROC(csum_partial_copy_generic)
21333 +ENDPROC(csum_partial_copy_generic_to_user)
21334
21335 #else
21336
21337 /* Version for PentiumII/PPro */
21338
21339 #define ROUND1(x) \
21340 + nop; nop; nop; \
21341 SRC(movl x(%esi), %ebx ) ; \
21342 addl %ebx, %eax ; \
21343 - DST(movl %ebx, x(%edi) ) ;
21344 + DST(movl %ebx, %es:x(%edi)) ;
21345
21346 #define ROUND(x) \
21347 + nop; nop; nop; \
21348 SRC(movl x(%esi), %ebx ) ; \
21349 adcl %ebx, %eax ; \
21350 - DST(movl %ebx, x(%edi) ) ;
21351 + DST(movl %ebx, %es:x(%edi)) ;
21352
21353 #define ARGBASE 12
21354 -
21355 -ENTRY(csum_partial_copy_generic)
21356 +
21357 +ENTRY(csum_partial_copy_generic_to_user)
21358 CFI_STARTPROC
21359 +
21360 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21361 + pushl_cfi %gs
21362 + popl_cfi %es
21363 + jmp csum_partial_copy_generic
21364 +#endif
21365 +
21366 +ENTRY(csum_partial_copy_generic_from_user)
21367 +
21368 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21369 + pushl_cfi %gs
21370 + popl_cfi %ds
21371 +#endif
21372 +
21373 +ENTRY(csum_partial_copy_generic)
21374 pushl_cfi %ebx
21375 CFI_REL_OFFSET ebx, 0
21376 pushl_cfi %edi
21377 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
21378 subl %ebx, %edi
21379 lea -1(%esi),%edx
21380 andl $-32,%edx
21381 - lea 3f(%ebx,%ebx), %ebx
21382 + lea 3f(%ebx,%ebx,2), %ebx
21383 testl %esi, %esi
21384 jmp *%ebx
21385 1: addl $64,%esi
21386 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
21387 jb 5f
21388 SRC( movw (%esi), %dx )
21389 leal 2(%esi), %esi
21390 -DST( movw %dx, (%edi) )
21391 +DST( movw %dx, %es:(%edi) )
21392 leal 2(%edi), %edi
21393 je 6f
21394 shll $16,%edx
21395 5:
21396 SRC( movb (%esi), %dl )
21397 -DST( movb %dl, (%edi) )
21398 +DST( movb %dl, %es:(%edi) )
21399 6: addl %edx, %eax
21400 adcl $0, %eax
21401 7:
21402 .section .fixup, "ax"
21403 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21404 - movl $-EFAULT, (%ebx)
21405 + movl $-EFAULT, %ss:(%ebx)
21406 # zero the complete destination (computing the rest is too much work)
21407 movl ARGBASE+8(%esp),%edi # dst
21408 movl ARGBASE+12(%esp),%ecx # len
21409 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
21410 rep; stosb
21411 jmp 7b
21412 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21413 - movl $-EFAULT, (%ebx)
21414 + movl $-EFAULT, %ss:(%ebx)
21415 jmp 7b
21416 .previous
21417
21418 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21419 + pushl_cfi %ss
21420 + popl_cfi %ds
21421 + pushl_cfi %ss
21422 + popl_cfi %es
21423 +#endif
21424 +
21425 popl_cfi %esi
21426 CFI_RESTORE esi
21427 popl_cfi %edi
21428 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
21429 CFI_RESTORE ebx
21430 ret
21431 CFI_ENDPROC
21432 -ENDPROC(csum_partial_copy_generic)
21433 +ENDPROC(csum_partial_copy_generic_to_user)
21434
21435 #undef ROUND
21436 #undef ROUND1
21437 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21438 index f2145cf..cea889d 100644
21439 --- a/arch/x86/lib/clear_page_64.S
21440 +++ b/arch/x86/lib/clear_page_64.S
21441 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21442 movl $4096/8,%ecx
21443 xorl %eax,%eax
21444 rep stosq
21445 + pax_force_retaddr
21446 ret
21447 CFI_ENDPROC
21448 ENDPROC(clear_page_c)
21449 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21450 movl $4096,%ecx
21451 xorl %eax,%eax
21452 rep stosb
21453 + pax_force_retaddr
21454 ret
21455 CFI_ENDPROC
21456 ENDPROC(clear_page_c_e)
21457 @@ -43,6 +45,7 @@ ENTRY(clear_page)
21458 leaq 64(%rdi),%rdi
21459 jnz .Lloop
21460 nop
21461 + pax_force_retaddr
21462 ret
21463 CFI_ENDPROC
21464 .Lclear_page_end:
21465 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
21466
21467 #include <asm/cpufeature.h>
21468
21469 - .section .altinstr_replacement,"ax"
21470 + .section .altinstr_replacement,"a"
21471 1: .byte 0xeb /* jmp <disp8> */
21472 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21473 2: .byte 0xeb /* jmp <disp8> */
21474 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21475 index 1e572c5..2a162cd 100644
21476 --- a/arch/x86/lib/cmpxchg16b_emu.S
21477 +++ b/arch/x86/lib/cmpxchg16b_emu.S
21478 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21479
21480 popf
21481 mov $1, %al
21482 + pax_force_retaddr
21483 ret
21484
21485 not_same:
21486 popf
21487 xor %al,%al
21488 + pax_force_retaddr
21489 ret
21490
21491 CFI_ENDPROC
21492 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21493 index 6b34d04..dccb07f 100644
21494 --- a/arch/x86/lib/copy_page_64.S
21495 +++ b/arch/x86/lib/copy_page_64.S
21496 @@ -9,6 +9,7 @@ copy_page_c:
21497 CFI_STARTPROC
21498 movl $4096/8,%ecx
21499 rep movsq
21500 + pax_force_retaddr
21501 ret
21502 CFI_ENDPROC
21503 ENDPROC(copy_page_c)
21504 @@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
21505
21506 ENTRY(copy_page)
21507 CFI_STARTPROC
21508 - subq $2*8,%rsp
21509 - CFI_ADJUST_CFA_OFFSET 2*8
21510 + subq $3*8,%rsp
21511 + CFI_ADJUST_CFA_OFFSET 3*8
21512 movq %rbx,(%rsp)
21513 CFI_REL_OFFSET rbx, 0
21514 movq %r12,1*8(%rsp)
21515 CFI_REL_OFFSET r12, 1*8
21516 + movq %r13,2*8(%rsp)
21517 + CFI_REL_OFFSET r13, 2*8
21518
21519 movl $(4096/64)-5,%ecx
21520 .p2align 4
21521 @@ -37,7 +40,7 @@ ENTRY(copy_page)
21522 movq 16 (%rsi), %rdx
21523 movq 24 (%rsi), %r8
21524 movq 32 (%rsi), %r9
21525 - movq 40 (%rsi), %r10
21526 + movq 40 (%rsi), %r13
21527 movq 48 (%rsi), %r11
21528 movq 56 (%rsi), %r12
21529
21530 @@ -48,7 +51,7 @@ ENTRY(copy_page)
21531 movq %rdx, 16 (%rdi)
21532 movq %r8, 24 (%rdi)
21533 movq %r9, 32 (%rdi)
21534 - movq %r10, 40 (%rdi)
21535 + movq %r13, 40 (%rdi)
21536 movq %r11, 48 (%rdi)
21537 movq %r12, 56 (%rdi)
21538
21539 @@ -67,7 +70,7 @@ ENTRY(copy_page)
21540 movq 16 (%rsi), %rdx
21541 movq 24 (%rsi), %r8
21542 movq 32 (%rsi), %r9
21543 - movq 40 (%rsi), %r10
21544 + movq 40 (%rsi), %r13
21545 movq 48 (%rsi), %r11
21546 movq 56 (%rsi), %r12
21547
21548 @@ -76,7 +79,7 @@ ENTRY(copy_page)
21549 movq %rdx, 16 (%rdi)
21550 movq %r8, 24 (%rdi)
21551 movq %r9, 32 (%rdi)
21552 - movq %r10, 40 (%rdi)
21553 + movq %r13, 40 (%rdi)
21554 movq %r11, 48 (%rdi)
21555 movq %r12, 56 (%rdi)
21556
21557 @@ -89,8 +92,11 @@ ENTRY(copy_page)
21558 CFI_RESTORE rbx
21559 movq 1*8(%rsp),%r12
21560 CFI_RESTORE r12
21561 - addq $2*8,%rsp
21562 - CFI_ADJUST_CFA_OFFSET -2*8
21563 + movq 2*8(%rsp),%r13
21564 + CFI_RESTORE r13
21565 + addq $3*8,%rsp
21566 + CFI_ADJUST_CFA_OFFSET -3*8
21567 + pax_force_retaddr
21568 ret
21569 .Lcopy_page_end:
21570 CFI_ENDPROC
21571 @@ -101,7 +107,7 @@ ENDPROC(copy_page)
21572
21573 #include <asm/cpufeature.h>
21574
21575 - .section .altinstr_replacement,"ax"
21576 + .section .altinstr_replacement,"a"
21577 1: .byte 0xeb /* jmp <disp8> */
21578 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21579 2:
21580 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21581 index 5b2995f..78e7644 100644
21582 --- a/arch/x86/lib/copy_user_64.S
21583 +++ b/arch/x86/lib/copy_user_64.S
21584 @@ -17,6 +17,7 @@
21585 #include <asm/cpufeature.h>
21586 #include <asm/alternative-asm.h>
21587 #include <asm/asm.h>
21588 +#include <asm/pgtable.h>
21589
21590 /*
21591 * By placing feature2 after feature1 in altinstructions section, we logically
21592 @@ -30,7 +31,7 @@
21593 .byte 0xe9 /* 32bit jump */
21594 .long \orig-1f /* by default jump to orig */
21595 1:
21596 - .section .altinstr_replacement,"ax"
21597 + .section .altinstr_replacement,"a"
21598 2: .byte 0xe9 /* near jump with 32bit immediate */
21599 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
21600 3: .byte 0xe9 /* near jump with 32bit immediate */
21601 @@ -69,47 +70,20 @@
21602 #endif
21603 .endm
21604
21605 -/* Standard copy_to_user with segment limit checking */
21606 -ENTRY(_copy_to_user)
21607 - CFI_STARTPROC
21608 - GET_THREAD_INFO(%rax)
21609 - movq %rdi,%rcx
21610 - addq %rdx,%rcx
21611 - jc bad_to_user
21612 - cmpq TI_addr_limit(%rax),%rcx
21613 - ja bad_to_user
21614 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21615 - copy_user_generic_unrolled,copy_user_generic_string, \
21616 - copy_user_enhanced_fast_string
21617 - CFI_ENDPROC
21618 -ENDPROC(_copy_to_user)
21619 -
21620 -/* Standard copy_from_user with segment limit checking */
21621 -ENTRY(_copy_from_user)
21622 - CFI_STARTPROC
21623 - GET_THREAD_INFO(%rax)
21624 - movq %rsi,%rcx
21625 - addq %rdx,%rcx
21626 - jc bad_from_user
21627 - cmpq TI_addr_limit(%rax),%rcx
21628 - ja bad_from_user
21629 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21630 - copy_user_generic_unrolled,copy_user_generic_string, \
21631 - copy_user_enhanced_fast_string
21632 - CFI_ENDPROC
21633 -ENDPROC(_copy_from_user)
21634 -
21635 .section .fixup,"ax"
21636 /* must zero dest */
21637 ENTRY(bad_from_user)
21638 bad_from_user:
21639 CFI_STARTPROC
21640 + testl %edx,%edx
21641 + js bad_to_user
21642 movl %edx,%ecx
21643 xorl %eax,%eax
21644 rep
21645 stosb
21646 bad_to_user:
21647 movl %edx,%eax
21648 + pax_force_retaddr
21649 ret
21650 CFI_ENDPROC
21651 ENDPROC(bad_from_user)
21652 @@ -139,19 +113,19 @@ ENTRY(copy_user_generic_unrolled)
21653 jz 17f
21654 1: movq (%rsi),%r8
21655 2: movq 1*8(%rsi),%r9
21656 -3: movq 2*8(%rsi),%r10
21657 +3: movq 2*8(%rsi),%rax
21658 4: movq 3*8(%rsi),%r11
21659 5: movq %r8,(%rdi)
21660 6: movq %r9,1*8(%rdi)
21661 -7: movq %r10,2*8(%rdi)
21662 +7: movq %rax,2*8(%rdi)
21663 8: movq %r11,3*8(%rdi)
21664 9: movq 4*8(%rsi),%r8
21665 10: movq 5*8(%rsi),%r9
21666 -11: movq 6*8(%rsi),%r10
21667 +11: movq 6*8(%rsi),%rax
21668 12: movq 7*8(%rsi),%r11
21669 13: movq %r8,4*8(%rdi)
21670 14: movq %r9,5*8(%rdi)
21671 -15: movq %r10,6*8(%rdi)
21672 +15: movq %rax,6*8(%rdi)
21673 16: movq %r11,7*8(%rdi)
21674 leaq 64(%rsi),%rsi
21675 leaq 64(%rdi),%rdi
21676 @@ -177,6 +151,7 @@ ENTRY(copy_user_generic_unrolled)
21677 decl %ecx
21678 jnz 21b
21679 23: xor %eax,%eax
21680 + pax_force_retaddr
21681 ret
21682
21683 .section .fixup,"ax"
21684 @@ -246,6 +221,7 @@ ENTRY(copy_user_generic_string)
21685 3: rep
21686 movsb
21687 4: xorl %eax,%eax
21688 + pax_force_retaddr
21689 ret
21690
21691 .section .fixup,"ax"
21692 @@ -279,6 +255,7 @@ ENTRY(copy_user_enhanced_fast_string)
21693 1: rep
21694 movsb
21695 2: xorl %eax,%eax
21696 + pax_force_retaddr
21697 ret
21698
21699 .section .fixup,"ax"
21700 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21701 index cacddc7..09d49e4 100644
21702 --- a/arch/x86/lib/copy_user_nocache_64.S
21703 +++ b/arch/x86/lib/copy_user_nocache_64.S
21704 @@ -8,6 +8,7 @@
21705
21706 #include <linux/linkage.h>
21707 #include <asm/dwarf2.h>
21708 +#include <asm/alternative-asm.h>
21709
21710 #define FIX_ALIGNMENT 1
21711
21712 @@ -15,6 +16,7 @@
21713 #include <asm/asm-offsets.h>
21714 #include <asm/thread_info.h>
21715 #include <asm/asm.h>
21716 +#include <asm/pgtable.h>
21717
21718 .macro ALIGN_DESTINATION
21719 #ifdef FIX_ALIGNMENT
21720 @@ -48,6 +50,15 @@
21721 */
21722 ENTRY(__copy_user_nocache)
21723 CFI_STARTPROC
21724 +
21725 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21726 + mov $PAX_USER_SHADOW_BASE,%rcx
21727 + cmp %rcx,%rsi
21728 + jae 1f
21729 + add %rcx,%rsi
21730 +1:
21731 +#endif
21732 +
21733 cmpl $8,%edx
21734 jb 20f /* less then 8 bytes, go to byte copy loop */
21735 ALIGN_DESTINATION
21736 @@ -57,19 +68,19 @@ ENTRY(__copy_user_nocache)
21737 jz 17f
21738 1: movq (%rsi),%r8
21739 2: movq 1*8(%rsi),%r9
21740 -3: movq 2*8(%rsi),%r10
21741 +3: movq 2*8(%rsi),%rax
21742 4: movq 3*8(%rsi),%r11
21743 5: movnti %r8,(%rdi)
21744 6: movnti %r9,1*8(%rdi)
21745 -7: movnti %r10,2*8(%rdi)
21746 +7: movnti %rax,2*8(%rdi)
21747 8: movnti %r11,3*8(%rdi)
21748 9: movq 4*8(%rsi),%r8
21749 10: movq 5*8(%rsi),%r9
21750 -11: movq 6*8(%rsi),%r10
21751 +11: movq 6*8(%rsi),%rax
21752 12: movq 7*8(%rsi),%r11
21753 13: movnti %r8,4*8(%rdi)
21754 14: movnti %r9,5*8(%rdi)
21755 -15: movnti %r10,6*8(%rdi)
21756 +15: movnti %rax,6*8(%rdi)
21757 16: movnti %r11,7*8(%rdi)
21758 leaq 64(%rsi),%rsi
21759 leaq 64(%rdi),%rdi
21760 @@ -96,6 +107,7 @@ ENTRY(__copy_user_nocache)
21761 jnz 21b
21762 23: xorl %eax,%eax
21763 sfence
21764 + pax_force_retaddr
21765 ret
21766
21767 .section .fixup,"ax"
21768 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21769 index 2419d5f..953ee51 100644
21770 --- a/arch/x86/lib/csum-copy_64.S
21771 +++ b/arch/x86/lib/csum-copy_64.S
21772 @@ -9,6 +9,7 @@
21773 #include <asm/dwarf2.h>
21774 #include <asm/errno.h>
21775 #include <asm/asm.h>
21776 +#include <asm/alternative-asm.h>
21777
21778 /*
21779 * Checksum copy with exception handling.
21780 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
21781 CFI_RESTORE rbp
21782 addq $7*8, %rsp
21783 CFI_ADJUST_CFA_OFFSET -7*8
21784 + pax_force_retaddr 0, 1
21785 ret
21786 CFI_RESTORE_STATE
21787
21788 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21789 index 25b7ae8..3b52ccd 100644
21790 --- a/arch/x86/lib/csum-wrappers_64.c
21791 +++ b/arch/x86/lib/csum-wrappers_64.c
21792 @@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21793 len -= 2;
21794 }
21795 }
21796 - isum = csum_partial_copy_generic((__force const void *)src,
21797 +
21798 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21799 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21800 + src += PAX_USER_SHADOW_BASE;
21801 +#endif
21802 +
21803 + isum = csum_partial_copy_generic((const void __force_kernel *)src,
21804 dst, len, isum, errp, NULL);
21805 if (unlikely(*errp))
21806 goto out_err;
21807 @@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21808 }
21809
21810 *errp = 0;
21811 - return csum_partial_copy_generic(src, (void __force *)dst,
21812 +
21813 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21814 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
21815 + dst += PAX_USER_SHADOW_BASE;
21816 +#endif
21817 +
21818 + return csum_partial_copy_generic(src, (void __force_kernel *)dst,
21819 len, isum, NULL, errp);
21820 }
21821 EXPORT_SYMBOL(csum_partial_copy_to_user);
21822 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21823 index b33b1fb..219f389 100644
21824 --- a/arch/x86/lib/getuser.S
21825 +++ b/arch/x86/lib/getuser.S
21826 @@ -33,15 +33,38 @@
21827 #include <asm/asm-offsets.h>
21828 #include <asm/thread_info.h>
21829 #include <asm/asm.h>
21830 +#include <asm/segment.h>
21831 +#include <asm/pgtable.h>
21832 +#include <asm/alternative-asm.h>
21833 +
21834 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21835 +#define __copyuser_seg gs;
21836 +#else
21837 +#define __copyuser_seg
21838 +#endif
21839
21840 .text
21841 ENTRY(__get_user_1)
21842 CFI_STARTPROC
21843 +
21844 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21845 GET_THREAD_INFO(%_ASM_DX)
21846 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21847 jae bad_get_user
21848 -1: movzb (%_ASM_AX),%edx
21849 +
21850 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21851 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21852 + cmp %_ASM_DX,%_ASM_AX
21853 + jae 1234f
21854 + add %_ASM_DX,%_ASM_AX
21855 +1234:
21856 +#endif
21857 +
21858 +#endif
21859 +
21860 +1: __copyuser_seg movzb (%_ASM_AX),%edx
21861 xor %eax,%eax
21862 + pax_force_retaddr
21863 ret
21864 CFI_ENDPROC
21865 ENDPROC(__get_user_1)
21866 @@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
21867 ENTRY(__get_user_2)
21868 CFI_STARTPROC
21869 add $1,%_ASM_AX
21870 +
21871 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21872 jc bad_get_user
21873 GET_THREAD_INFO(%_ASM_DX)
21874 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21875 jae bad_get_user
21876 -2: movzwl -1(%_ASM_AX),%edx
21877 +
21878 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21879 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21880 + cmp %_ASM_DX,%_ASM_AX
21881 + jae 1234f
21882 + add %_ASM_DX,%_ASM_AX
21883 +1234:
21884 +#endif
21885 +
21886 +#endif
21887 +
21888 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
21889 xor %eax,%eax
21890 + pax_force_retaddr
21891 ret
21892 CFI_ENDPROC
21893 ENDPROC(__get_user_2)
21894 @@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
21895 ENTRY(__get_user_4)
21896 CFI_STARTPROC
21897 add $3,%_ASM_AX
21898 +
21899 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21900 jc bad_get_user
21901 GET_THREAD_INFO(%_ASM_DX)
21902 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21903 jae bad_get_user
21904 -3: mov -3(%_ASM_AX),%edx
21905 +
21906 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21907 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21908 + cmp %_ASM_DX,%_ASM_AX
21909 + jae 1234f
21910 + add %_ASM_DX,%_ASM_AX
21911 +1234:
21912 +#endif
21913 +
21914 +#endif
21915 +
21916 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
21917 xor %eax,%eax
21918 + pax_force_retaddr
21919 ret
21920 CFI_ENDPROC
21921 ENDPROC(__get_user_4)
21922 @@ -80,8 +131,18 @@ ENTRY(__get_user_8)
21923 GET_THREAD_INFO(%_ASM_DX)
21924 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21925 jae bad_get_user
21926 +
21927 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21928 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21929 + cmp %_ASM_DX,%_ASM_AX
21930 + jae 1234f
21931 + add %_ASM_DX,%_ASM_AX
21932 +1234:
21933 +#endif
21934 +
21935 4: movq -7(%_ASM_AX),%_ASM_DX
21936 xor %eax,%eax
21937 + pax_force_retaddr
21938 ret
21939 CFI_ENDPROC
21940 ENDPROC(__get_user_8)
21941 @@ -91,6 +152,7 @@ bad_get_user:
21942 CFI_STARTPROC
21943 xor %edx,%edx
21944 mov $(-EFAULT),%_ASM_AX
21945 + pax_force_retaddr
21946 ret
21947 CFI_ENDPROC
21948 END(bad_get_user)
21949 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
21950 index b1e6c4b..21ae8fc 100644
21951 --- a/arch/x86/lib/insn.c
21952 +++ b/arch/x86/lib/insn.c
21953 @@ -21,6 +21,11 @@
21954 #include <linux/string.h>
21955 #include <asm/inat.h>
21956 #include <asm/insn.h>
21957 +#ifdef __KERNEL__
21958 +#include <asm/pgtable_types.h>
21959 +#else
21960 +#define ktla_ktva(addr) addr
21961 +#endif
21962
21963 /* Verify next sizeof(t) bytes can be on the same instruction */
21964 #define validate_next(t, insn, n) \
21965 @@ -49,8 +54,8 @@
21966 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
21967 {
21968 memset(insn, 0, sizeof(*insn));
21969 - insn->kaddr = kaddr;
21970 - insn->next_byte = kaddr;
21971 + insn->kaddr = ktla_ktva(kaddr);
21972 + insn->next_byte = ktla_ktva(kaddr);
21973 insn->x86_64 = x86_64 ? 1 : 0;
21974 insn->opnd_bytes = 4;
21975 if (x86_64)
21976 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
21977 index 05a95e7..326f2fa 100644
21978 --- a/arch/x86/lib/iomap_copy_64.S
21979 +++ b/arch/x86/lib/iomap_copy_64.S
21980 @@ -17,6 +17,7 @@
21981
21982 #include <linux/linkage.h>
21983 #include <asm/dwarf2.h>
21984 +#include <asm/alternative-asm.h>
21985
21986 /*
21987 * override generic version in lib/iomap_copy.c
21988 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
21989 CFI_STARTPROC
21990 movl %edx,%ecx
21991 rep movsd
21992 + pax_force_retaddr
21993 ret
21994 CFI_ENDPROC
21995 ENDPROC(__iowrite32_copy)
21996 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
21997 index 1c273be..da9cc0e 100644
21998 --- a/arch/x86/lib/memcpy_64.S
21999 +++ b/arch/x86/lib/memcpy_64.S
22000 @@ -33,6 +33,7 @@
22001 rep movsq
22002 movl %edx, %ecx
22003 rep movsb
22004 + pax_force_retaddr
22005 ret
22006 .Lmemcpy_e:
22007 .previous
22008 @@ -49,6 +50,7 @@
22009 movq %rdi, %rax
22010 movq %rdx, %rcx
22011 rep movsb
22012 + pax_force_retaddr
22013 ret
22014 .Lmemcpy_e_e:
22015 .previous
22016 @@ -76,13 +78,13 @@ ENTRY(memcpy)
22017 */
22018 movq 0*8(%rsi), %r8
22019 movq 1*8(%rsi), %r9
22020 - movq 2*8(%rsi), %r10
22021 + movq 2*8(%rsi), %rcx
22022 movq 3*8(%rsi), %r11
22023 leaq 4*8(%rsi), %rsi
22024
22025 movq %r8, 0*8(%rdi)
22026 movq %r9, 1*8(%rdi)
22027 - movq %r10, 2*8(%rdi)
22028 + movq %rcx, 2*8(%rdi)
22029 movq %r11, 3*8(%rdi)
22030 leaq 4*8(%rdi), %rdi
22031 jae .Lcopy_forward_loop
22032 @@ -105,12 +107,12 @@ ENTRY(memcpy)
22033 subq $0x20, %rdx
22034 movq -1*8(%rsi), %r8
22035 movq -2*8(%rsi), %r9
22036 - movq -3*8(%rsi), %r10
22037 + movq -3*8(%rsi), %rcx
22038 movq -4*8(%rsi), %r11
22039 leaq -4*8(%rsi), %rsi
22040 movq %r8, -1*8(%rdi)
22041 movq %r9, -2*8(%rdi)
22042 - movq %r10, -3*8(%rdi)
22043 + movq %rcx, -3*8(%rdi)
22044 movq %r11, -4*8(%rdi)
22045 leaq -4*8(%rdi), %rdi
22046 jae .Lcopy_backward_loop
22047 @@ -130,12 +132,13 @@ ENTRY(memcpy)
22048 */
22049 movq 0*8(%rsi), %r8
22050 movq 1*8(%rsi), %r9
22051 - movq -2*8(%rsi, %rdx), %r10
22052 + movq -2*8(%rsi, %rdx), %rcx
22053 movq -1*8(%rsi, %rdx), %r11
22054 movq %r8, 0*8(%rdi)
22055 movq %r9, 1*8(%rdi)
22056 - movq %r10, -2*8(%rdi, %rdx)
22057 + movq %rcx, -2*8(%rdi, %rdx)
22058 movq %r11, -1*8(%rdi, %rdx)
22059 + pax_force_retaddr
22060 retq
22061 .p2align 4
22062 .Lless_16bytes:
22063 @@ -148,6 +151,7 @@ ENTRY(memcpy)
22064 movq -1*8(%rsi, %rdx), %r9
22065 movq %r8, 0*8(%rdi)
22066 movq %r9, -1*8(%rdi, %rdx)
22067 + pax_force_retaddr
22068 retq
22069 .p2align 4
22070 .Lless_8bytes:
22071 @@ -161,6 +165,7 @@ ENTRY(memcpy)
22072 movl -4(%rsi, %rdx), %r8d
22073 movl %ecx, (%rdi)
22074 movl %r8d, -4(%rdi, %rdx)
22075 + pax_force_retaddr
22076 retq
22077 .p2align 4
22078 .Lless_3bytes:
22079 @@ -179,6 +184,7 @@ ENTRY(memcpy)
22080 movb %cl, (%rdi)
22081
22082 .Lend:
22083 + pax_force_retaddr
22084 retq
22085 CFI_ENDPROC
22086 ENDPROC(memcpy)
22087 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
22088 index ee16461..c39c199 100644
22089 --- a/arch/x86/lib/memmove_64.S
22090 +++ b/arch/x86/lib/memmove_64.S
22091 @@ -61,13 +61,13 @@ ENTRY(memmove)
22092 5:
22093 sub $0x20, %rdx
22094 movq 0*8(%rsi), %r11
22095 - movq 1*8(%rsi), %r10
22096 + movq 1*8(%rsi), %rcx
22097 movq 2*8(%rsi), %r9
22098 movq 3*8(%rsi), %r8
22099 leaq 4*8(%rsi), %rsi
22100
22101 movq %r11, 0*8(%rdi)
22102 - movq %r10, 1*8(%rdi)
22103 + movq %rcx, 1*8(%rdi)
22104 movq %r9, 2*8(%rdi)
22105 movq %r8, 3*8(%rdi)
22106 leaq 4*8(%rdi), %rdi
22107 @@ -81,10 +81,10 @@ ENTRY(memmove)
22108 4:
22109 movq %rdx, %rcx
22110 movq -8(%rsi, %rdx), %r11
22111 - lea -8(%rdi, %rdx), %r10
22112 + lea -8(%rdi, %rdx), %r9
22113 shrq $3, %rcx
22114 rep movsq
22115 - movq %r11, (%r10)
22116 + movq %r11, (%r9)
22117 jmp 13f
22118 .Lmemmove_end_forward:
22119
22120 @@ -95,14 +95,14 @@ ENTRY(memmove)
22121 7:
22122 movq %rdx, %rcx
22123 movq (%rsi), %r11
22124 - movq %rdi, %r10
22125 + movq %rdi, %r9
22126 leaq -8(%rsi, %rdx), %rsi
22127 leaq -8(%rdi, %rdx), %rdi
22128 shrq $3, %rcx
22129 std
22130 rep movsq
22131 cld
22132 - movq %r11, (%r10)
22133 + movq %r11, (%r9)
22134 jmp 13f
22135
22136 /*
22137 @@ -127,13 +127,13 @@ ENTRY(memmove)
22138 8:
22139 subq $0x20, %rdx
22140 movq -1*8(%rsi), %r11
22141 - movq -2*8(%rsi), %r10
22142 + movq -2*8(%rsi), %rcx
22143 movq -3*8(%rsi), %r9
22144 movq -4*8(%rsi), %r8
22145 leaq -4*8(%rsi), %rsi
22146
22147 movq %r11, -1*8(%rdi)
22148 - movq %r10, -2*8(%rdi)
22149 + movq %rcx, -2*8(%rdi)
22150 movq %r9, -3*8(%rdi)
22151 movq %r8, -4*8(%rdi)
22152 leaq -4*8(%rdi), %rdi
22153 @@ -151,11 +151,11 @@ ENTRY(memmove)
22154 * Move data from 16 bytes to 31 bytes.
22155 */
22156 movq 0*8(%rsi), %r11
22157 - movq 1*8(%rsi), %r10
22158 + movq 1*8(%rsi), %rcx
22159 movq -2*8(%rsi, %rdx), %r9
22160 movq -1*8(%rsi, %rdx), %r8
22161 movq %r11, 0*8(%rdi)
22162 - movq %r10, 1*8(%rdi)
22163 + movq %rcx, 1*8(%rdi)
22164 movq %r9, -2*8(%rdi, %rdx)
22165 movq %r8, -1*8(%rdi, %rdx)
22166 jmp 13f
22167 @@ -167,9 +167,9 @@ ENTRY(memmove)
22168 * Move data from 8 bytes to 15 bytes.
22169 */
22170 movq 0*8(%rsi), %r11
22171 - movq -1*8(%rsi, %rdx), %r10
22172 + movq -1*8(%rsi, %rdx), %r9
22173 movq %r11, 0*8(%rdi)
22174 - movq %r10, -1*8(%rdi, %rdx)
22175 + movq %r9, -1*8(%rdi, %rdx)
22176 jmp 13f
22177 10:
22178 cmpq $4, %rdx
22179 @@ -178,9 +178,9 @@ ENTRY(memmove)
22180 * Move data from 4 bytes to 7 bytes.
22181 */
22182 movl (%rsi), %r11d
22183 - movl -4(%rsi, %rdx), %r10d
22184 + movl -4(%rsi, %rdx), %r9d
22185 movl %r11d, (%rdi)
22186 - movl %r10d, -4(%rdi, %rdx)
22187 + movl %r9d, -4(%rdi, %rdx)
22188 jmp 13f
22189 11:
22190 cmp $2, %rdx
22191 @@ -189,9 +189,9 @@ ENTRY(memmove)
22192 * Move data from 2 bytes to 3 bytes.
22193 */
22194 movw (%rsi), %r11w
22195 - movw -2(%rsi, %rdx), %r10w
22196 + movw -2(%rsi, %rdx), %r9w
22197 movw %r11w, (%rdi)
22198 - movw %r10w, -2(%rdi, %rdx)
22199 + movw %r9w, -2(%rdi, %rdx)
22200 jmp 13f
22201 12:
22202 cmp $1, %rdx
22203 @@ -202,6 +202,7 @@ ENTRY(memmove)
22204 movb (%rsi), %r11b
22205 movb %r11b, (%rdi)
22206 13:
22207 + pax_force_retaddr
22208 retq
22209 CFI_ENDPROC
22210
22211 @@ -210,6 +211,7 @@ ENTRY(memmove)
22212 /* Forward moving data. */
22213 movq %rdx, %rcx
22214 rep movsb
22215 + pax_force_retaddr
22216 retq
22217 .Lmemmove_end_forward_efs:
22218 .previous
22219 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
22220 index 2dcb380..963660a 100644
22221 --- a/arch/x86/lib/memset_64.S
22222 +++ b/arch/x86/lib/memset_64.S
22223 @@ -30,6 +30,7 @@
22224 movl %edx,%ecx
22225 rep stosb
22226 movq %r9,%rax
22227 + pax_force_retaddr
22228 ret
22229 .Lmemset_e:
22230 .previous
22231 @@ -52,6 +53,7 @@
22232 movq %rdx,%rcx
22233 rep stosb
22234 movq %r9,%rax
22235 + pax_force_retaddr
22236 ret
22237 .Lmemset_e_e:
22238 .previous
22239 @@ -59,7 +61,7 @@
22240 ENTRY(memset)
22241 ENTRY(__memset)
22242 CFI_STARTPROC
22243 - movq %rdi,%r10
22244 + movq %rdi,%r11
22245
22246 /* expand byte value */
22247 movzbl %sil,%ecx
22248 @@ -117,7 +119,8 @@ ENTRY(__memset)
22249 jnz .Lloop_1
22250
22251 .Lende:
22252 - movq %r10,%rax
22253 + movq %r11,%rax
22254 + pax_force_retaddr
22255 ret
22256
22257 CFI_RESTORE_STATE
22258 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
22259 index c9f2d9b..e7fd2c0 100644
22260 --- a/arch/x86/lib/mmx_32.c
22261 +++ b/arch/x86/lib/mmx_32.c
22262 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22263 {
22264 void *p;
22265 int i;
22266 + unsigned long cr0;
22267
22268 if (unlikely(in_interrupt()))
22269 return __memcpy(to, from, len);
22270 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22271 kernel_fpu_begin();
22272
22273 __asm__ __volatile__ (
22274 - "1: prefetch (%0)\n" /* This set is 28 bytes */
22275 - " prefetch 64(%0)\n"
22276 - " prefetch 128(%0)\n"
22277 - " prefetch 192(%0)\n"
22278 - " prefetch 256(%0)\n"
22279 + "1: prefetch (%1)\n" /* This set is 28 bytes */
22280 + " prefetch 64(%1)\n"
22281 + " prefetch 128(%1)\n"
22282 + " prefetch 192(%1)\n"
22283 + " prefetch 256(%1)\n"
22284 "2: \n"
22285 ".section .fixup, \"ax\"\n"
22286 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22287 + "3: \n"
22288 +
22289 +#ifdef CONFIG_PAX_KERNEXEC
22290 + " movl %%cr0, %0\n"
22291 + " movl %0, %%eax\n"
22292 + " andl $0xFFFEFFFF, %%eax\n"
22293 + " movl %%eax, %%cr0\n"
22294 +#endif
22295 +
22296 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22297 +
22298 +#ifdef CONFIG_PAX_KERNEXEC
22299 + " movl %0, %%cr0\n"
22300 +#endif
22301 +
22302 " jmp 2b\n"
22303 ".previous\n"
22304 _ASM_EXTABLE(1b, 3b)
22305 - : : "r" (from));
22306 + : "=&r" (cr0) : "r" (from) : "ax");
22307
22308 for ( ; i > 5; i--) {
22309 __asm__ __volatile__ (
22310 - "1: prefetch 320(%0)\n"
22311 - "2: movq (%0), %%mm0\n"
22312 - " movq 8(%0), %%mm1\n"
22313 - " movq 16(%0), %%mm2\n"
22314 - " movq 24(%0), %%mm3\n"
22315 - " movq %%mm0, (%1)\n"
22316 - " movq %%mm1, 8(%1)\n"
22317 - " movq %%mm2, 16(%1)\n"
22318 - " movq %%mm3, 24(%1)\n"
22319 - " movq 32(%0), %%mm0\n"
22320 - " movq 40(%0), %%mm1\n"
22321 - " movq 48(%0), %%mm2\n"
22322 - " movq 56(%0), %%mm3\n"
22323 - " movq %%mm0, 32(%1)\n"
22324 - " movq %%mm1, 40(%1)\n"
22325 - " movq %%mm2, 48(%1)\n"
22326 - " movq %%mm3, 56(%1)\n"
22327 + "1: prefetch 320(%1)\n"
22328 + "2: movq (%1), %%mm0\n"
22329 + " movq 8(%1), %%mm1\n"
22330 + " movq 16(%1), %%mm2\n"
22331 + " movq 24(%1), %%mm3\n"
22332 + " movq %%mm0, (%2)\n"
22333 + " movq %%mm1, 8(%2)\n"
22334 + " movq %%mm2, 16(%2)\n"
22335 + " movq %%mm3, 24(%2)\n"
22336 + " movq 32(%1), %%mm0\n"
22337 + " movq 40(%1), %%mm1\n"
22338 + " movq 48(%1), %%mm2\n"
22339 + " movq 56(%1), %%mm3\n"
22340 + " movq %%mm0, 32(%2)\n"
22341 + " movq %%mm1, 40(%2)\n"
22342 + " movq %%mm2, 48(%2)\n"
22343 + " movq %%mm3, 56(%2)\n"
22344 ".section .fixup, \"ax\"\n"
22345 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22346 + "3:\n"
22347 +
22348 +#ifdef CONFIG_PAX_KERNEXEC
22349 + " movl %%cr0, %0\n"
22350 + " movl %0, %%eax\n"
22351 + " andl $0xFFFEFFFF, %%eax\n"
22352 + " movl %%eax, %%cr0\n"
22353 +#endif
22354 +
22355 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22356 +
22357 +#ifdef CONFIG_PAX_KERNEXEC
22358 + " movl %0, %%cr0\n"
22359 +#endif
22360 +
22361 " jmp 2b\n"
22362 ".previous\n"
22363 _ASM_EXTABLE(1b, 3b)
22364 - : : "r" (from), "r" (to) : "memory");
22365 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22366
22367 from += 64;
22368 to += 64;
22369 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22370 static void fast_copy_page(void *to, void *from)
22371 {
22372 int i;
22373 + unsigned long cr0;
22374
22375 kernel_fpu_begin();
22376
22377 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22378 * but that is for later. -AV
22379 */
22380 __asm__ __volatile__(
22381 - "1: prefetch (%0)\n"
22382 - " prefetch 64(%0)\n"
22383 - " prefetch 128(%0)\n"
22384 - " prefetch 192(%0)\n"
22385 - " prefetch 256(%0)\n"
22386 + "1: prefetch (%1)\n"
22387 + " prefetch 64(%1)\n"
22388 + " prefetch 128(%1)\n"
22389 + " prefetch 192(%1)\n"
22390 + " prefetch 256(%1)\n"
22391 "2: \n"
22392 ".section .fixup, \"ax\"\n"
22393 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22394 + "3: \n"
22395 +
22396 +#ifdef CONFIG_PAX_KERNEXEC
22397 + " movl %%cr0, %0\n"
22398 + " movl %0, %%eax\n"
22399 + " andl $0xFFFEFFFF, %%eax\n"
22400 + " movl %%eax, %%cr0\n"
22401 +#endif
22402 +
22403 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22404 +
22405 +#ifdef CONFIG_PAX_KERNEXEC
22406 + " movl %0, %%cr0\n"
22407 +#endif
22408 +
22409 " jmp 2b\n"
22410 ".previous\n"
22411 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22412 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22413
22414 for (i = 0; i < (4096-320)/64; i++) {
22415 __asm__ __volatile__ (
22416 - "1: prefetch 320(%0)\n"
22417 - "2: movq (%0), %%mm0\n"
22418 - " movntq %%mm0, (%1)\n"
22419 - " movq 8(%0), %%mm1\n"
22420 - " movntq %%mm1, 8(%1)\n"
22421 - " movq 16(%0), %%mm2\n"
22422 - " movntq %%mm2, 16(%1)\n"
22423 - " movq 24(%0), %%mm3\n"
22424 - " movntq %%mm3, 24(%1)\n"
22425 - " movq 32(%0), %%mm4\n"
22426 - " movntq %%mm4, 32(%1)\n"
22427 - " movq 40(%0), %%mm5\n"
22428 - " movntq %%mm5, 40(%1)\n"
22429 - " movq 48(%0), %%mm6\n"
22430 - " movntq %%mm6, 48(%1)\n"
22431 - " movq 56(%0), %%mm7\n"
22432 - " movntq %%mm7, 56(%1)\n"
22433 + "1: prefetch 320(%1)\n"
22434 + "2: movq (%1), %%mm0\n"
22435 + " movntq %%mm0, (%2)\n"
22436 + " movq 8(%1), %%mm1\n"
22437 + " movntq %%mm1, 8(%2)\n"
22438 + " movq 16(%1), %%mm2\n"
22439 + " movntq %%mm2, 16(%2)\n"
22440 + " movq 24(%1), %%mm3\n"
22441 + " movntq %%mm3, 24(%2)\n"
22442 + " movq 32(%1), %%mm4\n"
22443 + " movntq %%mm4, 32(%2)\n"
22444 + " movq 40(%1), %%mm5\n"
22445 + " movntq %%mm5, 40(%2)\n"
22446 + " movq 48(%1), %%mm6\n"
22447 + " movntq %%mm6, 48(%2)\n"
22448 + " movq 56(%1), %%mm7\n"
22449 + " movntq %%mm7, 56(%2)\n"
22450 ".section .fixup, \"ax\"\n"
22451 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22452 + "3:\n"
22453 +
22454 +#ifdef CONFIG_PAX_KERNEXEC
22455 + " movl %%cr0, %0\n"
22456 + " movl %0, %%eax\n"
22457 + " andl $0xFFFEFFFF, %%eax\n"
22458 + " movl %%eax, %%cr0\n"
22459 +#endif
22460 +
22461 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22462 +
22463 +#ifdef CONFIG_PAX_KERNEXEC
22464 + " movl %0, %%cr0\n"
22465 +#endif
22466 +
22467 " jmp 2b\n"
22468 ".previous\n"
22469 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22470 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22471
22472 from += 64;
22473 to += 64;
22474 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22475 static void fast_copy_page(void *to, void *from)
22476 {
22477 int i;
22478 + unsigned long cr0;
22479
22480 kernel_fpu_begin();
22481
22482 __asm__ __volatile__ (
22483 - "1: prefetch (%0)\n"
22484 - " prefetch 64(%0)\n"
22485 - " prefetch 128(%0)\n"
22486 - " prefetch 192(%0)\n"
22487 - " prefetch 256(%0)\n"
22488 + "1: prefetch (%1)\n"
22489 + " prefetch 64(%1)\n"
22490 + " prefetch 128(%1)\n"
22491 + " prefetch 192(%1)\n"
22492 + " prefetch 256(%1)\n"
22493 "2: \n"
22494 ".section .fixup, \"ax\"\n"
22495 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22496 + "3: \n"
22497 +
22498 +#ifdef CONFIG_PAX_KERNEXEC
22499 + " movl %%cr0, %0\n"
22500 + " movl %0, %%eax\n"
22501 + " andl $0xFFFEFFFF, %%eax\n"
22502 + " movl %%eax, %%cr0\n"
22503 +#endif
22504 +
22505 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22506 +
22507 +#ifdef CONFIG_PAX_KERNEXEC
22508 + " movl %0, %%cr0\n"
22509 +#endif
22510 +
22511 " jmp 2b\n"
22512 ".previous\n"
22513 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22514 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22515
22516 for (i = 0; i < 4096/64; i++) {
22517 __asm__ __volatile__ (
22518 - "1: prefetch 320(%0)\n"
22519 - "2: movq (%0), %%mm0\n"
22520 - " movq 8(%0), %%mm1\n"
22521 - " movq 16(%0), %%mm2\n"
22522 - " movq 24(%0), %%mm3\n"
22523 - " movq %%mm0, (%1)\n"
22524 - " movq %%mm1, 8(%1)\n"
22525 - " movq %%mm2, 16(%1)\n"
22526 - " movq %%mm3, 24(%1)\n"
22527 - " movq 32(%0), %%mm0\n"
22528 - " movq 40(%0), %%mm1\n"
22529 - " movq 48(%0), %%mm2\n"
22530 - " movq 56(%0), %%mm3\n"
22531 - " movq %%mm0, 32(%1)\n"
22532 - " movq %%mm1, 40(%1)\n"
22533 - " movq %%mm2, 48(%1)\n"
22534 - " movq %%mm3, 56(%1)\n"
22535 + "1: prefetch 320(%1)\n"
22536 + "2: movq (%1), %%mm0\n"
22537 + " movq 8(%1), %%mm1\n"
22538 + " movq 16(%1), %%mm2\n"
22539 + " movq 24(%1), %%mm3\n"
22540 + " movq %%mm0, (%2)\n"
22541 + " movq %%mm1, 8(%2)\n"
22542 + " movq %%mm2, 16(%2)\n"
22543 + " movq %%mm3, 24(%2)\n"
22544 + " movq 32(%1), %%mm0\n"
22545 + " movq 40(%1), %%mm1\n"
22546 + " movq 48(%1), %%mm2\n"
22547 + " movq 56(%1), %%mm3\n"
22548 + " movq %%mm0, 32(%2)\n"
22549 + " movq %%mm1, 40(%2)\n"
22550 + " movq %%mm2, 48(%2)\n"
22551 + " movq %%mm3, 56(%2)\n"
22552 ".section .fixup, \"ax\"\n"
22553 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22554 + "3:\n"
22555 +
22556 +#ifdef CONFIG_PAX_KERNEXEC
22557 + " movl %%cr0, %0\n"
22558 + " movl %0, %%eax\n"
22559 + " andl $0xFFFEFFFF, %%eax\n"
22560 + " movl %%eax, %%cr0\n"
22561 +#endif
22562 +
22563 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22564 +
22565 +#ifdef CONFIG_PAX_KERNEXEC
22566 + " movl %0, %%cr0\n"
22567 +#endif
22568 +
22569 " jmp 2b\n"
22570 ".previous\n"
22571 _ASM_EXTABLE(1b, 3b)
22572 - : : "r" (from), "r" (to) : "memory");
22573 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22574
22575 from += 64;
22576 to += 64;
22577 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22578 index f6d13ee..aca5f0b 100644
22579 --- a/arch/x86/lib/msr-reg.S
22580 +++ b/arch/x86/lib/msr-reg.S
22581 @@ -3,6 +3,7 @@
22582 #include <asm/dwarf2.h>
22583 #include <asm/asm.h>
22584 #include <asm/msr.h>
22585 +#include <asm/alternative-asm.h>
22586
22587 #ifdef CONFIG_X86_64
22588 /*
22589 @@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
22590 CFI_STARTPROC
22591 pushq_cfi %rbx
22592 pushq_cfi %rbp
22593 - movq %rdi, %r10 /* Save pointer */
22594 + movq %rdi, %r9 /* Save pointer */
22595 xorl %r11d, %r11d /* Return value */
22596 movl (%rdi), %eax
22597 movl 4(%rdi), %ecx
22598 @@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
22599 movl 28(%rdi), %edi
22600 CFI_REMEMBER_STATE
22601 1: \op
22602 -2: movl %eax, (%r10)
22603 +2: movl %eax, (%r9)
22604 movl %r11d, %eax /* Return value */
22605 - movl %ecx, 4(%r10)
22606 - movl %edx, 8(%r10)
22607 - movl %ebx, 12(%r10)
22608 - movl %ebp, 20(%r10)
22609 - movl %esi, 24(%r10)
22610 - movl %edi, 28(%r10)
22611 + movl %ecx, 4(%r9)
22612 + movl %edx, 8(%r9)
22613 + movl %ebx, 12(%r9)
22614 + movl %ebp, 20(%r9)
22615 + movl %esi, 24(%r9)
22616 + movl %edi, 28(%r9)
22617 popq_cfi %rbp
22618 popq_cfi %rbx
22619 + pax_force_retaddr
22620 ret
22621 3:
22622 CFI_RESTORE_STATE
22623 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22624 index 7f951c8..ebd573a 100644
22625 --- a/arch/x86/lib/putuser.S
22626 +++ b/arch/x86/lib/putuser.S
22627 @@ -15,7 +15,9 @@
22628 #include <asm/thread_info.h>
22629 #include <asm/errno.h>
22630 #include <asm/asm.h>
22631 -
22632 +#include <asm/segment.h>
22633 +#include <asm/pgtable.h>
22634 +#include <asm/alternative-asm.h>
22635
22636 /*
22637 * __put_user_X
22638 @@ -29,52 +31,119 @@
22639 * as they get called from within inline assembly.
22640 */
22641
22642 -#define ENTER CFI_STARTPROC ; \
22643 - GET_THREAD_INFO(%_ASM_BX)
22644 -#define EXIT ret ; \
22645 +#define ENTER CFI_STARTPROC
22646 +#define EXIT pax_force_retaddr; ret ; \
22647 CFI_ENDPROC
22648
22649 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22650 +#define _DEST %_ASM_CX,%_ASM_BX
22651 +#else
22652 +#define _DEST %_ASM_CX
22653 +#endif
22654 +
22655 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22656 +#define __copyuser_seg gs;
22657 +#else
22658 +#define __copyuser_seg
22659 +#endif
22660 +
22661 .text
22662 ENTRY(__put_user_1)
22663 ENTER
22664 +
22665 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22666 + GET_THREAD_INFO(%_ASM_BX)
22667 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22668 jae bad_put_user
22669 -1: movb %al,(%_ASM_CX)
22670 +
22671 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22672 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22673 + cmp %_ASM_BX,%_ASM_CX
22674 + jb 1234f
22675 + xor %ebx,%ebx
22676 +1234:
22677 +#endif
22678 +
22679 +#endif
22680 +
22681 +1: __copyuser_seg movb %al,(_DEST)
22682 xor %eax,%eax
22683 EXIT
22684 ENDPROC(__put_user_1)
22685
22686 ENTRY(__put_user_2)
22687 ENTER
22688 +
22689 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22690 + GET_THREAD_INFO(%_ASM_BX)
22691 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22692 sub $1,%_ASM_BX
22693 cmp %_ASM_BX,%_ASM_CX
22694 jae bad_put_user
22695 -2: movw %ax,(%_ASM_CX)
22696 +
22697 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22698 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22699 + cmp %_ASM_BX,%_ASM_CX
22700 + jb 1234f
22701 + xor %ebx,%ebx
22702 +1234:
22703 +#endif
22704 +
22705 +#endif
22706 +
22707 +2: __copyuser_seg movw %ax,(_DEST)
22708 xor %eax,%eax
22709 EXIT
22710 ENDPROC(__put_user_2)
22711
22712 ENTRY(__put_user_4)
22713 ENTER
22714 +
22715 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22716 + GET_THREAD_INFO(%_ASM_BX)
22717 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22718 sub $3,%_ASM_BX
22719 cmp %_ASM_BX,%_ASM_CX
22720 jae bad_put_user
22721 -3: movl %eax,(%_ASM_CX)
22722 +
22723 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22724 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22725 + cmp %_ASM_BX,%_ASM_CX
22726 + jb 1234f
22727 + xor %ebx,%ebx
22728 +1234:
22729 +#endif
22730 +
22731 +#endif
22732 +
22733 +3: __copyuser_seg movl %eax,(_DEST)
22734 xor %eax,%eax
22735 EXIT
22736 ENDPROC(__put_user_4)
22737
22738 ENTRY(__put_user_8)
22739 ENTER
22740 +
22741 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22742 + GET_THREAD_INFO(%_ASM_BX)
22743 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22744 sub $7,%_ASM_BX
22745 cmp %_ASM_BX,%_ASM_CX
22746 jae bad_put_user
22747 -4: mov %_ASM_AX,(%_ASM_CX)
22748 +
22749 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22750 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22751 + cmp %_ASM_BX,%_ASM_CX
22752 + jb 1234f
22753 + xor %ebx,%ebx
22754 +1234:
22755 +#endif
22756 +
22757 +#endif
22758 +
22759 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
22760 #ifdef CONFIG_X86_32
22761 -5: movl %edx,4(%_ASM_CX)
22762 +5: __copyuser_seg movl %edx,4(_DEST)
22763 #endif
22764 xor %eax,%eax
22765 EXIT
22766 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22767 index 1cad221..de671ee 100644
22768 --- a/arch/x86/lib/rwlock.S
22769 +++ b/arch/x86/lib/rwlock.S
22770 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22771 FRAME
22772 0: LOCK_PREFIX
22773 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22774 +
22775 +#ifdef CONFIG_PAX_REFCOUNT
22776 + jno 1234f
22777 + LOCK_PREFIX
22778 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22779 + int $4
22780 +1234:
22781 + _ASM_EXTABLE(1234b, 1234b)
22782 +#endif
22783 +
22784 1: rep; nop
22785 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22786 jne 1b
22787 LOCK_PREFIX
22788 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22789 +
22790 +#ifdef CONFIG_PAX_REFCOUNT
22791 + jno 1234f
22792 + LOCK_PREFIX
22793 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22794 + int $4
22795 +1234:
22796 + _ASM_EXTABLE(1234b, 1234b)
22797 +#endif
22798 +
22799 jnz 0b
22800 ENDFRAME
22801 + pax_force_retaddr
22802 ret
22803 CFI_ENDPROC
22804 END(__write_lock_failed)
22805 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22806 FRAME
22807 0: LOCK_PREFIX
22808 READ_LOCK_SIZE(inc) (%__lock_ptr)
22809 +
22810 +#ifdef CONFIG_PAX_REFCOUNT
22811 + jno 1234f
22812 + LOCK_PREFIX
22813 + READ_LOCK_SIZE(dec) (%__lock_ptr)
22814 + int $4
22815 +1234:
22816 + _ASM_EXTABLE(1234b, 1234b)
22817 +#endif
22818 +
22819 1: rep; nop
22820 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22821 js 1b
22822 LOCK_PREFIX
22823 READ_LOCK_SIZE(dec) (%__lock_ptr)
22824 +
22825 +#ifdef CONFIG_PAX_REFCOUNT
22826 + jno 1234f
22827 + LOCK_PREFIX
22828 + READ_LOCK_SIZE(inc) (%__lock_ptr)
22829 + int $4
22830 +1234:
22831 + _ASM_EXTABLE(1234b, 1234b)
22832 +#endif
22833 +
22834 js 0b
22835 ENDFRAME
22836 + pax_force_retaddr
22837 ret
22838 CFI_ENDPROC
22839 END(__read_lock_failed)
22840 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22841 index 5dff5f0..cadebf4 100644
22842 --- a/arch/x86/lib/rwsem.S
22843 +++ b/arch/x86/lib/rwsem.S
22844 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22845 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22846 CFI_RESTORE __ASM_REG(dx)
22847 restore_common_regs
22848 + pax_force_retaddr
22849 ret
22850 CFI_ENDPROC
22851 ENDPROC(call_rwsem_down_read_failed)
22852 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22853 movq %rax,%rdi
22854 call rwsem_down_write_failed
22855 restore_common_regs
22856 + pax_force_retaddr
22857 ret
22858 CFI_ENDPROC
22859 ENDPROC(call_rwsem_down_write_failed)
22860 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
22861 movq %rax,%rdi
22862 call rwsem_wake
22863 restore_common_regs
22864 -1: ret
22865 +1: pax_force_retaddr
22866 + ret
22867 CFI_ENDPROC
22868 ENDPROC(call_rwsem_wake)
22869
22870 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
22871 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22872 CFI_RESTORE __ASM_REG(dx)
22873 restore_common_regs
22874 + pax_force_retaddr
22875 ret
22876 CFI_ENDPROC
22877 ENDPROC(call_rwsem_downgrade_wake)
22878 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22879 index a63efd6..ccecad8 100644
22880 --- a/arch/x86/lib/thunk_64.S
22881 +++ b/arch/x86/lib/thunk_64.S
22882 @@ -8,6 +8,7 @@
22883 #include <linux/linkage.h>
22884 #include <asm/dwarf2.h>
22885 #include <asm/calling.h>
22886 +#include <asm/alternative-asm.h>
22887
22888 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
22889 .macro THUNK name, func, put_ret_addr_in_rdi=0
22890 @@ -41,5 +42,6 @@
22891 SAVE_ARGS
22892 restore:
22893 RESTORE_ARGS
22894 + pax_force_retaddr
22895 ret
22896 CFI_ENDPROC
22897 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
22898 index 1781b2f..90368dd 100644
22899 --- a/arch/x86/lib/usercopy_32.c
22900 +++ b/arch/x86/lib/usercopy_32.c
22901 @@ -42,10 +42,12 @@ do { \
22902 int __d0; \
22903 might_fault(); \
22904 __asm__ __volatile__( \
22905 + __COPYUSER_SET_ES \
22906 "0: rep; stosl\n" \
22907 " movl %2,%0\n" \
22908 "1: rep; stosb\n" \
22909 "2:\n" \
22910 + __COPYUSER_RESTORE_ES \
22911 ".section .fixup,\"ax\"\n" \
22912 "3: lea 0(%2,%0,4),%0\n" \
22913 " jmp 2b\n" \
22914 @@ -97,7 +99,7 @@ EXPORT_SYMBOL(__clear_user);
22915
22916 #ifdef CONFIG_X86_INTEL_USERCOPY
22917 static unsigned long
22918 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
22919 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
22920 {
22921 int d0, d1;
22922 __asm__ __volatile__(
22923 @@ -109,36 +111,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22924 " .align 2,0x90\n"
22925 "3: movl 0(%4), %%eax\n"
22926 "4: movl 4(%4), %%edx\n"
22927 - "5: movl %%eax, 0(%3)\n"
22928 - "6: movl %%edx, 4(%3)\n"
22929 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
22930 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
22931 "7: movl 8(%4), %%eax\n"
22932 "8: movl 12(%4),%%edx\n"
22933 - "9: movl %%eax, 8(%3)\n"
22934 - "10: movl %%edx, 12(%3)\n"
22935 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
22936 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
22937 "11: movl 16(%4), %%eax\n"
22938 "12: movl 20(%4), %%edx\n"
22939 - "13: movl %%eax, 16(%3)\n"
22940 - "14: movl %%edx, 20(%3)\n"
22941 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
22942 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
22943 "15: movl 24(%4), %%eax\n"
22944 "16: movl 28(%4), %%edx\n"
22945 - "17: movl %%eax, 24(%3)\n"
22946 - "18: movl %%edx, 28(%3)\n"
22947 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
22948 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
22949 "19: movl 32(%4), %%eax\n"
22950 "20: movl 36(%4), %%edx\n"
22951 - "21: movl %%eax, 32(%3)\n"
22952 - "22: movl %%edx, 36(%3)\n"
22953 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
22954 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
22955 "23: movl 40(%4), %%eax\n"
22956 "24: movl 44(%4), %%edx\n"
22957 - "25: movl %%eax, 40(%3)\n"
22958 - "26: movl %%edx, 44(%3)\n"
22959 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
22960 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
22961 "27: movl 48(%4), %%eax\n"
22962 "28: movl 52(%4), %%edx\n"
22963 - "29: movl %%eax, 48(%3)\n"
22964 - "30: movl %%edx, 52(%3)\n"
22965 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
22966 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
22967 "31: movl 56(%4), %%eax\n"
22968 "32: movl 60(%4), %%edx\n"
22969 - "33: movl %%eax, 56(%3)\n"
22970 - "34: movl %%edx, 60(%3)\n"
22971 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
22972 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
22973 " addl $-64, %0\n"
22974 " addl $64, %4\n"
22975 " addl $64, %3\n"
22976 @@ -148,10 +150,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22977 " shrl $2, %0\n"
22978 " andl $3, %%eax\n"
22979 " cld\n"
22980 + __COPYUSER_SET_ES
22981 "99: rep; movsl\n"
22982 "36: movl %%eax, %0\n"
22983 "37: rep; movsb\n"
22984 "100:\n"
22985 + __COPYUSER_RESTORE_ES
22986 ".section .fixup,\"ax\"\n"
22987 "101: lea 0(%%eax,%0,4),%0\n"
22988 " jmp 100b\n"
22989 @@ -201,46 +205,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22990 }
22991
22992 static unsigned long
22993 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
22994 +{
22995 + int d0, d1;
22996 + __asm__ __volatile__(
22997 + " .align 2,0x90\n"
22998 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
22999 + " cmpl $67, %0\n"
23000 + " jbe 3f\n"
23001 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
23002 + " .align 2,0x90\n"
23003 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
23004 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
23005 + "5: movl %%eax, 0(%3)\n"
23006 + "6: movl %%edx, 4(%3)\n"
23007 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
23008 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
23009 + "9: movl %%eax, 8(%3)\n"
23010 + "10: movl %%edx, 12(%3)\n"
23011 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
23012 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
23013 + "13: movl %%eax, 16(%3)\n"
23014 + "14: movl %%edx, 20(%3)\n"
23015 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
23016 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
23017 + "17: movl %%eax, 24(%3)\n"
23018 + "18: movl %%edx, 28(%3)\n"
23019 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
23020 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
23021 + "21: movl %%eax, 32(%3)\n"
23022 + "22: movl %%edx, 36(%3)\n"
23023 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
23024 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
23025 + "25: movl %%eax, 40(%3)\n"
23026 + "26: movl %%edx, 44(%3)\n"
23027 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
23028 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
23029 + "29: movl %%eax, 48(%3)\n"
23030 + "30: movl %%edx, 52(%3)\n"
23031 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
23032 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
23033 + "33: movl %%eax, 56(%3)\n"
23034 + "34: movl %%edx, 60(%3)\n"
23035 + " addl $-64, %0\n"
23036 + " addl $64, %4\n"
23037 + " addl $64, %3\n"
23038 + " cmpl $63, %0\n"
23039 + " ja 1b\n"
23040 + "35: movl %0, %%eax\n"
23041 + " shrl $2, %0\n"
23042 + " andl $3, %%eax\n"
23043 + " cld\n"
23044 + "99: rep; "__copyuser_seg" movsl\n"
23045 + "36: movl %%eax, %0\n"
23046 + "37: rep; "__copyuser_seg" movsb\n"
23047 + "100:\n"
23048 + ".section .fixup,\"ax\"\n"
23049 + "101: lea 0(%%eax,%0,4),%0\n"
23050 + " jmp 100b\n"
23051 + ".previous\n"
23052 + _ASM_EXTABLE(1b,100b)
23053 + _ASM_EXTABLE(2b,100b)
23054 + _ASM_EXTABLE(3b,100b)
23055 + _ASM_EXTABLE(4b,100b)
23056 + _ASM_EXTABLE(5b,100b)
23057 + _ASM_EXTABLE(6b,100b)
23058 + _ASM_EXTABLE(7b,100b)
23059 + _ASM_EXTABLE(8b,100b)
23060 + _ASM_EXTABLE(9b,100b)
23061 + _ASM_EXTABLE(10b,100b)
23062 + _ASM_EXTABLE(11b,100b)
23063 + _ASM_EXTABLE(12b,100b)
23064 + _ASM_EXTABLE(13b,100b)
23065 + _ASM_EXTABLE(14b,100b)
23066 + _ASM_EXTABLE(15b,100b)
23067 + _ASM_EXTABLE(16b,100b)
23068 + _ASM_EXTABLE(17b,100b)
23069 + _ASM_EXTABLE(18b,100b)
23070 + _ASM_EXTABLE(19b,100b)
23071 + _ASM_EXTABLE(20b,100b)
23072 + _ASM_EXTABLE(21b,100b)
23073 + _ASM_EXTABLE(22b,100b)
23074 + _ASM_EXTABLE(23b,100b)
23075 + _ASM_EXTABLE(24b,100b)
23076 + _ASM_EXTABLE(25b,100b)
23077 + _ASM_EXTABLE(26b,100b)
23078 + _ASM_EXTABLE(27b,100b)
23079 + _ASM_EXTABLE(28b,100b)
23080 + _ASM_EXTABLE(29b,100b)
23081 + _ASM_EXTABLE(30b,100b)
23082 + _ASM_EXTABLE(31b,100b)
23083 + _ASM_EXTABLE(32b,100b)
23084 + _ASM_EXTABLE(33b,100b)
23085 + _ASM_EXTABLE(34b,100b)
23086 + _ASM_EXTABLE(35b,100b)
23087 + _ASM_EXTABLE(36b,100b)
23088 + _ASM_EXTABLE(37b,100b)
23089 + _ASM_EXTABLE(99b,101b)
23090 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
23091 + : "1"(to), "2"(from), "0"(size)
23092 + : "eax", "edx", "memory");
23093 + return size;
23094 +}
23095 +
23096 +static unsigned long __size_overflow(3)
23097 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23098 {
23099 int d0, d1;
23100 __asm__ __volatile__(
23101 " .align 2,0x90\n"
23102 - "0: movl 32(%4), %%eax\n"
23103 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23104 " cmpl $67, %0\n"
23105 " jbe 2f\n"
23106 - "1: movl 64(%4), %%eax\n"
23107 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23108 " .align 2,0x90\n"
23109 - "2: movl 0(%4), %%eax\n"
23110 - "21: movl 4(%4), %%edx\n"
23111 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23112 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23113 " movl %%eax, 0(%3)\n"
23114 " movl %%edx, 4(%3)\n"
23115 - "3: movl 8(%4), %%eax\n"
23116 - "31: movl 12(%4),%%edx\n"
23117 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23118 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23119 " movl %%eax, 8(%3)\n"
23120 " movl %%edx, 12(%3)\n"
23121 - "4: movl 16(%4), %%eax\n"
23122 - "41: movl 20(%4), %%edx\n"
23123 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23124 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23125 " movl %%eax, 16(%3)\n"
23126 " movl %%edx, 20(%3)\n"
23127 - "10: movl 24(%4), %%eax\n"
23128 - "51: movl 28(%4), %%edx\n"
23129 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23130 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23131 " movl %%eax, 24(%3)\n"
23132 " movl %%edx, 28(%3)\n"
23133 - "11: movl 32(%4), %%eax\n"
23134 - "61: movl 36(%4), %%edx\n"
23135 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23136 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23137 " movl %%eax, 32(%3)\n"
23138 " movl %%edx, 36(%3)\n"
23139 - "12: movl 40(%4), %%eax\n"
23140 - "71: movl 44(%4), %%edx\n"
23141 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23142 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23143 " movl %%eax, 40(%3)\n"
23144 " movl %%edx, 44(%3)\n"
23145 - "13: movl 48(%4), %%eax\n"
23146 - "81: movl 52(%4), %%edx\n"
23147 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23148 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23149 " movl %%eax, 48(%3)\n"
23150 " movl %%edx, 52(%3)\n"
23151 - "14: movl 56(%4), %%eax\n"
23152 - "91: movl 60(%4), %%edx\n"
23153 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23154 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23155 " movl %%eax, 56(%3)\n"
23156 " movl %%edx, 60(%3)\n"
23157 " addl $-64, %0\n"
23158 @@ -252,9 +360,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23159 " shrl $2, %0\n"
23160 " andl $3, %%eax\n"
23161 " cld\n"
23162 - "6: rep; movsl\n"
23163 + "6: rep; "__copyuser_seg" movsl\n"
23164 " movl %%eax,%0\n"
23165 - "7: rep; movsb\n"
23166 + "7: rep; "__copyuser_seg" movsb\n"
23167 "8:\n"
23168 ".section .fixup,\"ax\"\n"
23169 "9: lea 0(%%eax,%0,4),%0\n"
23170 @@ -297,48 +405,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23171 * hyoshiok@miraclelinux.com
23172 */
23173
23174 -static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23175 +static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
23176 const void __user *from, unsigned long size)
23177 {
23178 int d0, d1;
23179
23180 __asm__ __volatile__(
23181 " .align 2,0x90\n"
23182 - "0: movl 32(%4), %%eax\n"
23183 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23184 " cmpl $67, %0\n"
23185 " jbe 2f\n"
23186 - "1: movl 64(%4), %%eax\n"
23187 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23188 " .align 2,0x90\n"
23189 - "2: movl 0(%4), %%eax\n"
23190 - "21: movl 4(%4), %%edx\n"
23191 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23192 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23193 " movnti %%eax, 0(%3)\n"
23194 " movnti %%edx, 4(%3)\n"
23195 - "3: movl 8(%4), %%eax\n"
23196 - "31: movl 12(%4),%%edx\n"
23197 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23198 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23199 " movnti %%eax, 8(%3)\n"
23200 " movnti %%edx, 12(%3)\n"
23201 - "4: movl 16(%4), %%eax\n"
23202 - "41: movl 20(%4), %%edx\n"
23203 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23204 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23205 " movnti %%eax, 16(%3)\n"
23206 " movnti %%edx, 20(%3)\n"
23207 - "10: movl 24(%4), %%eax\n"
23208 - "51: movl 28(%4), %%edx\n"
23209 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23210 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23211 " movnti %%eax, 24(%3)\n"
23212 " movnti %%edx, 28(%3)\n"
23213 - "11: movl 32(%4), %%eax\n"
23214 - "61: movl 36(%4), %%edx\n"
23215 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23216 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23217 " movnti %%eax, 32(%3)\n"
23218 " movnti %%edx, 36(%3)\n"
23219 - "12: movl 40(%4), %%eax\n"
23220 - "71: movl 44(%4), %%edx\n"
23221 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23222 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23223 " movnti %%eax, 40(%3)\n"
23224 " movnti %%edx, 44(%3)\n"
23225 - "13: movl 48(%4), %%eax\n"
23226 - "81: movl 52(%4), %%edx\n"
23227 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23228 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23229 " movnti %%eax, 48(%3)\n"
23230 " movnti %%edx, 52(%3)\n"
23231 - "14: movl 56(%4), %%eax\n"
23232 - "91: movl 60(%4), %%edx\n"
23233 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23234 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23235 " movnti %%eax, 56(%3)\n"
23236 " movnti %%edx, 60(%3)\n"
23237 " addl $-64, %0\n"
23238 @@ -351,9 +459,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23239 " shrl $2, %0\n"
23240 " andl $3, %%eax\n"
23241 " cld\n"
23242 - "6: rep; movsl\n"
23243 + "6: rep; "__copyuser_seg" movsl\n"
23244 " movl %%eax,%0\n"
23245 - "7: rep; movsb\n"
23246 + "7: rep; "__copyuser_seg" movsb\n"
23247 "8:\n"
23248 ".section .fixup,\"ax\"\n"
23249 "9: lea 0(%%eax,%0,4),%0\n"
23250 @@ -391,48 +499,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23251 return size;
23252 }
23253
23254 -static unsigned long __copy_user_intel_nocache(void *to,
23255 +static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
23256 const void __user *from, unsigned long size)
23257 {
23258 int d0, d1;
23259
23260 __asm__ __volatile__(
23261 " .align 2,0x90\n"
23262 - "0: movl 32(%4), %%eax\n"
23263 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23264 " cmpl $67, %0\n"
23265 " jbe 2f\n"
23266 - "1: movl 64(%4), %%eax\n"
23267 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23268 " .align 2,0x90\n"
23269 - "2: movl 0(%4), %%eax\n"
23270 - "21: movl 4(%4), %%edx\n"
23271 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23272 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23273 " movnti %%eax, 0(%3)\n"
23274 " movnti %%edx, 4(%3)\n"
23275 - "3: movl 8(%4), %%eax\n"
23276 - "31: movl 12(%4),%%edx\n"
23277 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23278 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23279 " movnti %%eax, 8(%3)\n"
23280 " movnti %%edx, 12(%3)\n"
23281 - "4: movl 16(%4), %%eax\n"
23282 - "41: movl 20(%4), %%edx\n"
23283 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23284 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23285 " movnti %%eax, 16(%3)\n"
23286 " movnti %%edx, 20(%3)\n"
23287 - "10: movl 24(%4), %%eax\n"
23288 - "51: movl 28(%4), %%edx\n"
23289 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23290 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23291 " movnti %%eax, 24(%3)\n"
23292 " movnti %%edx, 28(%3)\n"
23293 - "11: movl 32(%4), %%eax\n"
23294 - "61: movl 36(%4), %%edx\n"
23295 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23296 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23297 " movnti %%eax, 32(%3)\n"
23298 " movnti %%edx, 36(%3)\n"
23299 - "12: movl 40(%4), %%eax\n"
23300 - "71: movl 44(%4), %%edx\n"
23301 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23302 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23303 " movnti %%eax, 40(%3)\n"
23304 " movnti %%edx, 44(%3)\n"
23305 - "13: movl 48(%4), %%eax\n"
23306 - "81: movl 52(%4), %%edx\n"
23307 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23308 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23309 " movnti %%eax, 48(%3)\n"
23310 " movnti %%edx, 52(%3)\n"
23311 - "14: movl 56(%4), %%eax\n"
23312 - "91: movl 60(%4), %%edx\n"
23313 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23314 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23315 " movnti %%eax, 56(%3)\n"
23316 " movnti %%edx, 60(%3)\n"
23317 " addl $-64, %0\n"
23318 @@ -445,9 +553,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23319 " shrl $2, %0\n"
23320 " andl $3, %%eax\n"
23321 " cld\n"
23322 - "6: rep; movsl\n"
23323 + "6: rep; "__copyuser_seg" movsl\n"
23324 " movl %%eax,%0\n"
23325 - "7: rep; movsb\n"
23326 + "7: rep; "__copyuser_seg" movsb\n"
23327 "8:\n"
23328 ".section .fixup,\"ax\"\n"
23329 "9: lea 0(%%eax,%0,4),%0\n"
23330 @@ -487,32 +595,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23331 */
23332 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23333 unsigned long size);
23334 -unsigned long __copy_user_intel(void __user *to, const void *from,
23335 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23336 + unsigned long size);
23337 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23338 unsigned long size);
23339 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23340 const void __user *from, unsigned long size);
23341 #endif /* CONFIG_X86_INTEL_USERCOPY */
23342
23343 /* Generic arbitrary sized copy. */
23344 -#define __copy_user(to, from, size) \
23345 +#define __copy_user(to, from, size, prefix, set, restore) \
23346 do { \
23347 int __d0, __d1, __d2; \
23348 __asm__ __volatile__( \
23349 + set \
23350 " cmp $7,%0\n" \
23351 " jbe 1f\n" \
23352 " movl %1,%0\n" \
23353 " negl %0\n" \
23354 " andl $7,%0\n" \
23355 " subl %0,%3\n" \
23356 - "4: rep; movsb\n" \
23357 + "4: rep; "prefix"movsb\n" \
23358 " movl %3,%0\n" \
23359 " shrl $2,%0\n" \
23360 " andl $3,%3\n" \
23361 " .align 2,0x90\n" \
23362 - "0: rep; movsl\n" \
23363 + "0: rep; "prefix"movsl\n" \
23364 " movl %3,%0\n" \
23365 - "1: rep; movsb\n" \
23366 + "1: rep; "prefix"movsb\n" \
23367 "2:\n" \
23368 + restore \
23369 ".section .fixup,\"ax\"\n" \
23370 "5: addl %3,%0\n" \
23371 " jmp 2b\n" \
23372 @@ -537,14 +649,14 @@ do { \
23373 " negl %0\n" \
23374 " andl $7,%0\n" \
23375 " subl %0,%3\n" \
23376 - "4: rep; movsb\n" \
23377 + "4: rep; "__copyuser_seg"movsb\n" \
23378 " movl %3,%0\n" \
23379 " shrl $2,%0\n" \
23380 " andl $3,%3\n" \
23381 " .align 2,0x90\n" \
23382 - "0: rep; movsl\n" \
23383 + "0: rep; "__copyuser_seg"movsl\n" \
23384 " movl %3,%0\n" \
23385 - "1: rep; movsb\n" \
23386 + "1: rep; "__copyuser_seg"movsb\n" \
23387 "2:\n" \
23388 ".section .fixup,\"ax\"\n" \
23389 "5: addl %3,%0\n" \
23390 @@ -627,9 +739,9 @@ survive:
23391 }
23392 #endif
23393 if (movsl_is_ok(to, from, n))
23394 - __copy_user(to, from, n);
23395 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23396 else
23397 - n = __copy_user_intel(to, from, n);
23398 + n = __generic_copy_to_user_intel(to, from, n);
23399 return n;
23400 }
23401 EXPORT_SYMBOL(__copy_to_user_ll);
23402 @@ -649,10 +761,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23403 unsigned long n)
23404 {
23405 if (movsl_is_ok(to, from, n))
23406 - __copy_user(to, from, n);
23407 + __copy_user(to, from, n, __copyuser_seg, "", "");
23408 else
23409 - n = __copy_user_intel((void __user *)to,
23410 - (const void *)from, n);
23411 + n = __generic_copy_from_user_intel(to, from, n);
23412 return n;
23413 }
23414 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23415 @@ -679,65 +790,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23416 if (n > 64 && cpu_has_xmm2)
23417 n = __copy_user_intel_nocache(to, from, n);
23418 else
23419 - __copy_user(to, from, n);
23420 + __copy_user(to, from, n, __copyuser_seg, "", "");
23421 #else
23422 - __copy_user(to, from, n);
23423 + __copy_user(to, from, n, __copyuser_seg, "", "");
23424 #endif
23425 return n;
23426 }
23427 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23428
23429 -/**
23430 - * copy_to_user: - Copy a block of data into user space.
23431 - * @to: Destination address, in user space.
23432 - * @from: Source address, in kernel space.
23433 - * @n: Number of bytes to copy.
23434 - *
23435 - * Context: User context only. This function may sleep.
23436 - *
23437 - * Copy data from kernel space to user space.
23438 - *
23439 - * Returns number of bytes that could not be copied.
23440 - * On success, this will be zero.
23441 - */
23442 -unsigned long
23443 -copy_to_user(void __user *to, const void *from, unsigned long n)
23444 -{
23445 - if (access_ok(VERIFY_WRITE, to, n))
23446 - n = __copy_to_user(to, from, n);
23447 - return n;
23448 -}
23449 -EXPORT_SYMBOL(copy_to_user);
23450 -
23451 -/**
23452 - * copy_from_user: - Copy a block of data from user space.
23453 - * @to: Destination address, in kernel space.
23454 - * @from: Source address, in user space.
23455 - * @n: Number of bytes to copy.
23456 - *
23457 - * Context: User context only. This function may sleep.
23458 - *
23459 - * Copy data from user space to kernel space.
23460 - *
23461 - * Returns number of bytes that could not be copied.
23462 - * On success, this will be zero.
23463 - *
23464 - * If some data could not be copied, this function will pad the copied
23465 - * data to the requested size using zero bytes.
23466 - */
23467 -unsigned long
23468 -_copy_from_user(void *to, const void __user *from, unsigned long n)
23469 -{
23470 - if (access_ok(VERIFY_READ, from, n))
23471 - n = __copy_from_user(to, from, n);
23472 - else
23473 - memset(to, 0, n);
23474 - return n;
23475 -}
23476 -EXPORT_SYMBOL(_copy_from_user);
23477 -
23478 void copy_from_user_overflow(void)
23479 {
23480 WARN(1, "Buffer overflow detected!\n");
23481 }
23482 EXPORT_SYMBOL(copy_from_user_overflow);
23483 +
23484 +void copy_to_user_overflow(void)
23485 +{
23486 + WARN(1, "Buffer overflow detected!\n");
23487 +}
23488 +EXPORT_SYMBOL(copy_to_user_overflow);
23489 +
23490 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23491 +void __set_fs(mm_segment_t x)
23492 +{
23493 + switch (x.seg) {
23494 + case 0:
23495 + loadsegment(gs, 0);
23496 + break;
23497 + case TASK_SIZE_MAX:
23498 + loadsegment(gs, __USER_DS);
23499 + break;
23500 + case -1UL:
23501 + loadsegment(gs, __KERNEL_DS);
23502 + break;
23503 + default:
23504 + BUG();
23505 + }
23506 + return;
23507 +}
23508 +EXPORT_SYMBOL(__set_fs);
23509 +
23510 +void set_fs(mm_segment_t x)
23511 +{
23512 + current_thread_info()->addr_limit = x;
23513 + __set_fs(x);
23514 +}
23515 +EXPORT_SYMBOL(set_fs);
23516 +#endif
23517 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23518 index e5b130b..6690d31 100644
23519 --- a/arch/x86/lib/usercopy_64.c
23520 +++ b/arch/x86/lib/usercopy_64.c
23521 @@ -16,6 +16,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23522 {
23523 long __d0;
23524 might_fault();
23525 +
23526 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23527 + if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
23528 + addr += PAX_USER_SHADOW_BASE;
23529 +#endif
23530 +
23531 /* no memory constraint because it doesn't change any memory gcc knows
23532 about */
23533 asm volatile(
23534 @@ -52,12 +58,20 @@ unsigned long clear_user(void __user *to, unsigned long n)
23535 }
23536 EXPORT_SYMBOL(clear_user);
23537
23538 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23539 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23540 {
23541 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23542 - return copy_user_generic((__force void *)to, (__force void *)from, len);
23543 - }
23544 - return len;
23545 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23546 +
23547 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23548 + if ((unsigned long)to < PAX_USER_SHADOW_BASE)
23549 + to += PAX_USER_SHADOW_BASE;
23550 + if ((unsigned long)from < PAX_USER_SHADOW_BASE)
23551 + from += PAX_USER_SHADOW_BASE;
23552 +#endif
23553 +
23554 + return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
23555 + }
23556 + return len;
23557 }
23558 EXPORT_SYMBOL(copy_in_user);
23559
23560 @@ -67,7 +81,7 @@ EXPORT_SYMBOL(copy_in_user);
23561 * it is not necessary to optimize tail handling.
23562 */
23563 unsigned long
23564 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23565 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23566 {
23567 char c;
23568 unsigned zero_len;
23569 @@ -84,3 +98,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23570 break;
23571 return len;
23572 }
23573 +
23574 +void copy_from_user_overflow(void)
23575 +{
23576 + WARN(1, "Buffer overflow detected!\n");
23577 +}
23578 +EXPORT_SYMBOL(copy_from_user_overflow);
23579 +
23580 +void copy_to_user_overflow(void)
23581 +{
23582 + WARN(1, "Buffer overflow detected!\n");
23583 +}
23584 +EXPORT_SYMBOL(copy_to_user_overflow);
23585 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23586 index 903ec1e..c4166b2 100644
23587 --- a/arch/x86/mm/extable.c
23588 +++ b/arch/x86/mm/extable.c
23589 @@ -6,12 +6,24 @@
23590 static inline unsigned long
23591 ex_insn_addr(const struct exception_table_entry *x)
23592 {
23593 - return (unsigned long)&x->insn + x->insn;
23594 + unsigned long reloc = 0;
23595 +
23596 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23597 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23598 +#endif
23599 +
23600 + return (unsigned long)&x->insn + x->insn + reloc;
23601 }
23602 static inline unsigned long
23603 ex_fixup_addr(const struct exception_table_entry *x)
23604 {
23605 - return (unsigned long)&x->fixup + x->fixup;
23606 + unsigned long reloc = 0;
23607 +
23608 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23609 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23610 +#endif
23611 +
23612 + return (unsigned long)&x->fixup + x->fixup + reloc;
23613 }
23614
23615 int fixup_exception(struct pt_regs *regs)
23616 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
23617 unsigned long new_ip;
23618
23619 #ifdef CONFIG_PNPBIOS
23620 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23621 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23622 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23623 extern u32 pnp_bios_is_utter_crap;
23624 pnp_bios_is_utter_crap = 1;
23625 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
23626 i += 4;
23627 p->fixup -= i;
23628 i += 4;
23629 +
23630 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23631 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
23632 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23633 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23634 +#endif
23635 +
23636 }
23637 }
23638
23639 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23640 index 76dcd9d..e9dffde 100644
23641 --- a/arch/x86/mm/fault.c
23642 +++ b/arch/x86/mm/fault.c
23643 @@ -13,11 +13,18 @@
23644 #include <linux/perf_event.h> /* perf_sw_event */
23645 #include <linux/hugetlb.h> /* hstate_index_to_shift */
23646 #include <linux/prefetch.h> /* prefetchw */
23647 +#include <linux/unistd.h>
23648 +#include <linux/compiler.h>
23649
23650 #include <asm/traps.h> /* dotraplinkage, ... */
23651 #include <asm/pgalloc.h> /* pgd_*(), ... */
23652 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23653 #include <asm/fixmap.h> /* VSYSCALL_START */
23654 +#include <asm/tlbflush.h>
23655 +
23656 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23657 +#include <asm/stacktrace.h>
23658 +#endif
23659
23660 /*
23661 * Page fault error code bits:
23662 @@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
23663 int ret = 0;
23664
23665 /* kprobe_running() needs smp_processor_id() */
23666 - if (kprobes_built_in() && !user_mode_vm(regs)) {
23667 + if (kprobes_built_in() && !user_mode(regs)) {
23668 preempt_disable();
23669 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23670 ret = 1;
23671 @@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23672 return !instr_lo || (instr_lo>>1) == 1;
23673 case 0x00:
23674 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23675 - if (probe_kernel_address(instr, opcode))
23676 + if (user_mode(regs)) {
23677 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23678 + return 0;
23679 + } else if (probe_kernel_address(instr, opcode))
23680 return 0;
23681
23682 *prefetch = (instr_lo == 0xF) &&
23683 @@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23684 while (instr < max_instr) {
23685 unsigned char opcode;
23686
23687 - if (probe_kernel_address(instr, opcode))
23688 + if (user_mode(regs)) {
23689 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23690 + break;
23691 + } else if (probe_kernel_address(instr, opcode))
23692 break;
23693
23694 instr++;
23695 @@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23696 force_sig_info(si_signo, &info, tsk);
23697 }
23698
23699 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23700 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23701 +#endif
23702 +
23703 +#ifdef CONFIG_PAX_EMUTRAMP
23704 +static int pax_handle_fetch_fault(struct pt_regs *regs);
23705 +#endif
23706 +
23707 +#ifdef CONFIG_PAX_PAGEEXEC
23708 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23709 +{
23710 + pgd_t *pgd;
23711 + pud_t *pud;
23712 + pmd_t *pmd;
23713 +
23714 + pgd = pgd_offset(mm, address);
23715 + if (!pgd_present(*pgd))
23716 + return NULL;
23717 + pud = pud_offset(pgd, address);
23718 + if (!pud_present(*pud))
23719 + return NULL;
23720 + pmd = pmd_offset(pud, address);
23721 + if (!pmd_present(*pmd))
23722 + return NULL;
23723 + return pmd;
23724 +}
23725 +#endif
23726 +
23727 DEFINE_SPINLOCK(pgd_lock);
23728 LIST_HEAD(pgd_list);
23729
23730 @@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
23731 for (address = VMALLOC_START & PMD_MASK;
23732 address >= TASK_SIZE && address < FIXADDR_TOP;
23733 address += PMD_SIZE) {
23734 +
23735 +#ifdef CONFIG_PAX_PER_CPU_PGD
23736 + unsigned long cpu;
23737 +#else
23738 struct page *page;
23739 +#endif
23740
23741 spin_lock(&pgd_lock);
23742 +
23743 +#ifdef CONFIG_PAX_PER_CPU_PGD
23744 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23745 + pgd_t *pgd = get_cpu_pgd(cpu);
23746 + pmd_t *ret;
23747 +#else
23748 list_for_each_entry(page, &pgd_list, lru) {
23749 + pgd_t *pgd = page_address(page);
23750 spinlock_t *pgt_lock;
23751 pmd_t *ret;
23752
23753 @@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
23754 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23755
23756 spin_lock(pgt_lock);
23757 - ret = vmalloc_sync_one(page_address(page), address);
23758 +#endif
23759 +
23760 + ret = vmalloc_sync_one(pgd, address);
23761 +
23762 +#ifndef CONFIG_PAX_PER_CPU_PGD
23763 spin_unlock(pgt_lock);
23764 +#endif
23765
23766 if (!ret)
23767 break;
23768 @@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23769 * an interrupt in the middle of a task switch..
23770 */
23771 pgd_paddr = read_cr3();
23772 +
23773 +#ifdef CONFIG_PAX_PER_CPU_PGD
23774 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23775 +#endif
23776 +
23777 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23778 if (!pmd_k)
23779 return -1;
23780 @@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23781 * happen within a race in page table update. In the later
23782 * case just flush:
23783 */
23784 +
23785 +#ifdef CONFIG_PAX_PER_CPU_PGD
23786 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23787 + pgd = pgd_offset_cpu(smp_processor_id(), address);
23788 +#else
23789 pgd = pgd_offset(current->active_mm, address);
23790 +#endif
23791 +
23792 pgd_ref = pgd_offset_k(address);
23793 if (pgd_none(*pgd_ref))
23794 return -1;
23795 @@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23796 static int is_errata100(struct pt_regs *regs, unsigned long address)
23797 {
23798 #ifdef CONFIG_X86_64
23799 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23800 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23801 return 1;
23802 #endif
23803 return 0;
23804 @@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23805 }
23806
23807 static const char nx_warning[] = KERN_CRIT
23808 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23809 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23810
23811 static void
23812 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23813 @@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23814 if (!oops_may_print())
23815 return;
23816
23817 - if (error_code & PF_INSTR) {
23818 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23819 unsigned int level;
23820
23821 pte_t *pte = lookup_address(address, &level);
23822
23823 if (pte && pte_present(*pte) && !pte_exec(*pte))
23824 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
23825 + printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
23826 }
23827
23828 +#ifdef CONFIG_PAX_KERNEXEC
23829 + if (init_mm.start_code <= address && address < init_mm.end_code) {
23830 + if (current->signal->curr_ip)
23831 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23832 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23833 + else
23834 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23835 + current->comm, task_pid_nr(current), current_uid(), current_euid());
23836 + }
23837 +#endif
23838 +
23839 printk(KERN_ALERT "BUG: unable to handle kernel ");
23840 if (address < PAGE_SIZE)
23841 printk(KERN_CONT "NULL pointer dereference");
23842 @@ -748,6 +829,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23843 }
23844 #endif
23845
23846 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23847 + if (pax_is_fetch_fault(regs, error_code, address)) {
23848 +
23849 +#ifdef CONFIG_PAX_EMUTRAMP
23850 + switch (pax_handle_fetch_fault(regs)) {
23851 + case 2:
23852 + return;
23853 + }
23854 +#endif
23855 +
23856 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23857 + do_group_exit(SIGKILL);
23858 + }
23859 +#endif
23860 +
23861 if (unlikely(show_unhandled_signals))
23862 show_signal_msg(regs, error_code, address, tsk);
23863
23864 @@ -844,7 +940,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23865 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23866 printk(KERN_ERR
23867 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
23868 - tsk->comm, tsk->pid, address);
23869 + tsk->comm, task_pid_nr(tsk), address);
23870 code = BUS_MCEERR_AR;
23871 }
23872 #endif
23873 @@ -900,6 +996,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
23874 return 1;
23875 }
23876
23877 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23878 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
23879 +{
23880 + pte_t *pte;
23881 + pmd_t *pmd;
23882 + spinlock_t *ptl;
23883 + unsigned char pte_mask;
23884 +
23885 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
23886 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
23887 + return 0;
23888 +
23889 + /* PaX: it's our fault, let's handle it if we can */
23890 +
23891 + /* PaX: take a look at read faults before acquiring any locks */
23892 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
23893 + /* instruction fetch attempt from a protected page in user mode */
23894 + up_read(&mm->mmap_sem);
23895 +
23896 +#ifdef CONFIG_PAX_EMUTRAMP
23897 + switch (pax_handle_fetch_fault(regs)) {
23898 + case 2:
23899 + return 1;
23900 + }
23901 +#endif
23902 +
23903 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23904 + do_group_exit(SIGKILL);
23905 + }
23906 +
23907 + pmd = pax_get_pmd(mm, address);
23908 + if (unlikely(!pmd))
23909 + return 0;
23910 +
23911 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
23912 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
23913 + pte_unmap_unlock(pte, ptl);
23914 + return 0;
23915 + }
23916 +
23917 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
23918 + /* write attempt to a protected page in user mode */
23919 + pte_unmap_unlock(pte, ptl);
23920 + return 0;
23921 + }
23922 +
23923 +#ifdef CONFIG_SMP
23924 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
23925 +#else
23926 + if (likely(address > get_limit(regs->cs)))
23927 +#endif
23928 + {
23929 + set_pte(pte, pte_mkread(*pte));
23930 + __flush_tlb_one(address);
23931 + pte_unmap_unlock(pte, ptl);
23932 + up_read(&mm->mmap_sem);
23933 + return 1;
23934 + }
23935 +
23936 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
23937 +
23938 + /*
23939 + * PaX: fill DTLB with user rights and retry
23940 + */
23941 + __asm__ __volatile__ (
23942 + "orb %2,(%1)\n"
23943 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
23944 +/*
23945 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
23946 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
23947 + * page fault when examined during a TLB load attempt. this is true not only
23948 + * for PTEs holding a non-present entry but also present entries that will
23949 + * raise a page fault (such as those set up by PaX, or the copy-on-write
23950 + * mechanism). in effect it means that we do *not* need to flush the TLBs
23951 + * for our target pages since their PTEs are simply not in the TLBs at all.
23952 +
23953 + * the best thing in omitting it is that we gain around 15-20% speed in the
23954 + * fast path of the page fault handler and can get rid of tracing since we
23955 + * can no longer flush unintended entries.
23956 + */
23957 + "invlpg (%0)\n"
23958 +#endif
23959 + __copyuser_seg"testb $0,(%0)\n"
23960 + "xorb %3,(%1)\n"
23961 + :
23962 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
23963 + : "memory", "cc");
23964 + pte_unmap_unlock(pte, ptl);
23965 + up_read(&mm->mmap_sem);
23966 + return 1;
23967 +}
23968 +#endif
23969 +
23970 /*
23971 * Handle a spurious fault caused by a stale TLB entry.
23972 *
23973 @@ -972,6 +1161,9 @@ int show_unhandled_signals = 1;
23974 static inline int
23975 access_error(unsigned long error_code, struct vm_area_struct *vma)
23976 {
23977 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
23978 + return 1;
23979 +
23980 if (error_code & PF_WRITE) {
23981 /* write, present and write, not present: */
23982 if (unlikely(!(vma->vm_flags & VM_WRITE)))
23983 @@ -1005,18 +1197,33 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23984 {
23985 struct vm_area_struct *vma;
23986 struct task_struct *tsk;
23987 - unsigned long address;
23988 struct mm_struct *mm;
23989 int fault;
23990 int write = error_code & PF_WRITE;
23991 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
23992 (write ? FAULT_FLAG_WRITE : 0);
23993
23994 - tsk = current;
23995 - mm = tsk->mm;
23996 -
23997 /* Get the faulting address: */
23998 - address = read_cr2();
23999 + unsigned long address = read_cr2();
24000 +
24001 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24002 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
24003 + if (!search_exception_tables(regs->ip)) {
24004 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
24005 + bad_area_nosemaphore(regs, error_code, address);
24006 + return;
24007 + }
24008 + if (address < PAX_USER_SHADOW_BASE) {
24009 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
24010 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
24011 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
24012 + } else
24013 + address -= PAX_USER_SHADOW_BASE;
24014 + }
24015 +#endif
24016 +
24017 + tsk = current;
24018 + mm = tsk->mm;
24019
24020 /*
24021 * Detect and handle instructions that would cause a page fault for
24022 @@ -1077,7 +1284,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24023 * User-mode registers count as a user access even for any
24024 * potential system fault or CPU buglet:
24025 */
24026 - if (user_mode_vm(regs)) {
24027 + if (user_mode(regs)) {
24028 local_irq_enable();
24029 error_code |= PF_USER;
24030 } else {
24031 @@ -1132,6 +1339,11 @@ retry:
24032 might_sleep();
24033 }
24034
24035 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
24036 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
24037 + return;
24038 +#endif
24039 +
24040 vma = find_vma(mm, address);
24041 if (unlikely(!vma)) {
24042 bad_area(regs, error_code, address);
24043 @@ -1143,18 +1355,24 @@ retry:
24044 bad_area(regs, error_code, address);
24045 return;
24046 }
24047 - if (error_code & PF_USER) {
24048 - /*
24049 - * Accessing the stack below %sp is always a bug.
24050 - * The large cushion allows instructions like enter
24051 - * and pusha to work. ("enter $65535, $31" pushes
24052 - * 32 pointers and then decrements %sp by 65535.)
24053 - */
24054 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
24055 - bad_area(regs, error_code, address);
24056 - return;
24057 - }
24058 + /*
24059 + * Accessing the stack below %sp is always a bug.
24060 + * The large cushion allows instructions like enter
24061 + * and pusha to work. ("enter $65535, $31" pushes
24062 + * 32 pointers and then decrements %sp by 65535.)
24063 + */
24064 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
24065 + bad_area(regs, error_code, address);
24066 + return;
24067 }
24068 +
24069 +#ifdef CONFIG_PAX_SEGMEXEC
24070 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
24071 + bad_area(regs, error_code, address);
24072 + return;
24073 + }
24074 +#endif
24075 +
24076 if (unlikely(expand_stack(vma, address))) {
24077 bad_area(regs, error_code, address);
24078 return;
24079 @@ -1209,3 +1427,292 @@ good_area:
24080
24081 up_read(&mm->mmap_sem);
24082 }
24083 +
24084 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24085 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
24086 +{
24087 + struct mm_struct *mm = current->mm;
24088 + unsigned long ip = regs->ip;
24089 +
24090 + if (v8086_mode(regs))
24091 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
24092 +
24093 +#ifdef CONFIG_PAX_PAGEEXEC
24094 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
24095 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
24096 + return true;
24097 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
24098 + return true;
24099 + return false;
24100 + }
24101 +#endif
24102 +
24103 +#ifdef CONFIG_PAX_SEGMEXEC
24104 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
24105 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
24106 + return true;
24107 + return false;
24108 + }
24109 +#endif
24110 +
24111 + return false;
24112 +}
24113 +#endif
24114 +
24115 +#ifdef CONFIG_PAX_EMUTRAMP
24116 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
24117 +{
24118 + int err;
24119 +
24120 + do { /* PaX: libffi trampoline emulation */
24121 + unsigned char mov, jmp;
24122 + unsigned int addr1, addr2;
24123 +
24124 +#ifdef CONFIG_X86_64
24125 + if ((regs->ip + 9) >> 32)
24126 + break;
24127 +#endif
24128 +
24129 + err = get_user(mov, (unsigned char __user *)regs->ip);
24130 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24131 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24132 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24133 +
24134 + if (err)
24135 + break;
24136 +
24137 + if (mov == 0xB8 && jmp == 0xE9) {
24138 + regs->ax = addr1;
24139 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24140 + return 2;
24141 + }
24142 + } while (0);
24143 +
24144 + do { /* PaX: gcc trampoline emulation #1 */
24145 + unsigned char mov1, mov2;
24146 + unsigned short jmp;
24147 + unsigned int addr1, addr2;
24148 +
24149 +#ifdef CONFIG_X86_64
24150 + if ((regs->ip + 11) >> 32)
24151 + break;
24152 +#endif
24153 +
24154 + err = get_user(mov1, (unsigned char __user *)regs->ip);
24155 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24156 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
24157 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24158 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
24159 +
24160 + if (err)
24161 + break;
24162 +
24163 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
24164 + regs->cx = addr1;
24165 + regs->ax = addr2;
24166 + regs->ip = addr2;
24167 + return 2;
24168 + }
24169 + } while (0);
24170 +
24171 + do { /* PaX: gcc trampoline emulation #2 */
24172 + unsigned char mov, jmp;
24173 + unsigned int addr1, addr2;
24174 +
24175 +#ifdef CONFIG_X86_64
24176 + if ((regs->ip + 9) >> 32)
24177 + break;
24178 +#endif
24179 +
24180 + err = get_user(mov, (unsigned char __user *)regs->ip);
24181 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24182 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24183 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24184 +
24185 + if (err)
24186 + break;
24187 +
24188 + if (mov == 0xB9 && jmp == 0xE9) {
24189 + regs->cx = addr1;
24190 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24191 + return 2;
24192 + }
24193 + } while (0);
24194 +
24195 + return 1; /* PaX in action */
24196 +}
24197 +
24198 +#ifdef CONFIG_X86_64
24199 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
24200 +{
24201 + int err;
24202 +
24203 + do { /* PaX: libffi trampoline emulation */
24204 + unsigned short mov1, mov2, jmp1;
24205 + unsigned char stcclc, jmp2;
24206 + unsigned long addr1, addr2;
24207 +
24208 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24209 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24210 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24211 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24212 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
24213 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
24214 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
24215 +
24216 + if (err)
24217 + break;
24218 +
24219 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24220 + regs->r11 = addr1;
24221 + regs->r10 = addr2;
24222 + if (stcclc == 0xF8)
24223 + regs->flags &= ~X86_EFLAGS_CF;
24224 + else
24225 + regs->flags |= X86_EFLAGS_CF;
24226 + regs->ip = addr1;
24227 + return 2;
24228 + }
24229 + } while (0);
24230 +
24231 + do { /* PaX: gcc trampoline emulation #1 */
24232 + unsigned short mov1, mov2, jmp1;
24233 + unsigned char jmp2;
24234 + unsigned int addr1;
24235 + unsigned long addr2;
24236 +
24237 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24238 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
24239 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
24240 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
24241 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
24242 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
24243 +
24244 + if (err)
24245 + break;
24246 +
24247 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24248 + regs->r11 = addr1;
24249 + regs->r10 = addr2;
24250 + regs->ip = addr1;
24251 + return 2;
24252 + }
24253 + } while (0);
24254 +
24255 + do { /* PaX: gcc trampoline emulation #2 */
24256 + unsigned short mov1, mov2, jmp1;
24257 + unsigned char jmp2;
24258 + unsigned long addr1, addr2;
24259 +
24260 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24261 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24262 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24263 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24264 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
24265 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
24266 +
24267 + if (err)
24268 + break;
24269 +
24270 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24271 + regs->r11 = addr1;
24272 + regs->r10 = addr2;
24273 + regs->ip = addr1;
24274 + return 2;
24275 + }
24276 + } while (0);
24277 +
24278 + return 1; /* PaX in action */
24279 +}
24280 +#endif
24281 +
24282 +/*
24283 + * PaX: decide what to do with offenders (regs->ip = fault address)
24284 + *
24285 + * returns 1 when task should be killed
24286 + * 2 when gcc trampoline was detected
24287 + */
24288 +static int pax_handle_fetch_fault(struct pt_regs *regs)
24289 +{
24290 + if (v8086_mode(regs))
24291 + return 1;
24292 +
24293 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24294 + return 1;
24295 +
24296 +#ifdef CONFIG_X86_32
24297 + return pax_handle_fetch_fault_32(regs);
24298 +#else
24299 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24300 + return pax_handle_fetch_fault_32(regs);
24301 + else
24302 + return pax_handle_fetch_fault_64(regs);
24303 +#endif
24304 +}
24305 +#endif
24306 +
24307 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24308 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24309 +{
24310 + long i;
24311 +
24312 + printk(KERN_ERR "PAX: bytes at PC: ");
24313 + for (i = 0; i < 20; i++) {
24314 + unsigned char c;
24315 + if (get_user(c, (unsigned char __force_user *)pc+i))
24316 + printk(KERN_CONT "?? ");
24317 + else
24318 + printk(KERN_CONT "%02x ", c);
24319 + }
24320 + printk("\n");
24321 +
24322 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24323 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
24324 + unsigned long c;
24325 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
24326 +#ifdef CONFIG_X86_32
24327 + printk(KERN_CONT "???????? ");
24328 +#else
24329 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24330 + printk(KERN_CONT "???????? ???????? ");
24331 + else
24332 + printk(KERN_CONT "???????????????? ");
24333 +#endif
24334 + } else {
24335 +#ifdef CONFIG_X86_64
24336 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24337 + printk(KERN_CONT "%08x ", (unsigned int)c);
24338 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24339 + } else
24340 +#endif
24341 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24342 + }
24343 + }
24344 + printk("\n");
24345 +}
24346 +#endif
24347 +
24348 +/**
24349 + * probe_kernel_write(): safely attempt to write to a location
24350 + * @dst: address to write to
24351 + * @src: pointer to the data that shall be written
24352 + * @size: size of the data chunk
24353 + *
24354 + * Safely write to address @dst from the buffer at @src. If a kernel fault
24355 + * happens, handle that and return -EFAULT.
24356 + */
24357 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24358 +{
24359 + long ret;
24360 + mm_segment_t old_fs = get_fs();
24361 +
24362 + set_fs(KERNEL_DS);
24363 + pagefault_disable();
24364 + pax_open_kernel();
24365 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24366 + pax_close_kernel();
24367 + pagefault_enable();
24368 + set_fs(old_fs);
24369 +
24370 + return ret ? -EFAULT : 0;
24371 +}
24372 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24373 index dd74e46..7d26398 100644
24374 --- a/arch/x86/mm/gup.c
24375 +++ b/arch/x86/mm/gup.c
24376 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24377 addr = start;
24378 len = (unsigned long) nr_pages << PAGE_SHIFT;
24379 end = start + len;
24380 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24381 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24382 (void __user *)start, len)))
24383 return 0;
24384
24385 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24386 index 6f31ee5..8ee4164 100644
24387 --- a/arch/x86/mm/highmem_32.c
24388 +++ b/arch/x86/mm/highmem_32.c
24389 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24390 idx = type + KM_TYPE_NR*smp_processor_id();
24391 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24392 BUG_ON(!pte_none(*(kmap_pte-idx)));
24393 +
24394 + pax_open_kernel();
24395 set_pte(kmap_pte-idx, mk_pte(page, prot));
24396 + pax_close_kernel();
24397 +
24398 arch_flush_lazy_mmu_mode();
24399
24400 return (void *)vaddr;
24401 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24402 index b91e485..d00e7c9 100644
24403 --- a/arch/x86/mm/hugetlbpage.c
24404 +++ b/arch/x86/mm/hugetlbpage.c
24405 @@ -277,13 +277,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24406 struct hstate *h = hstate_file(file);
24407 struct mm_struct *mm = current->mm;
24408 struct vm_area_struct *vma;
24409 - unsigned long start_addr;
24410 + unsigned long start_addr, pax_task_size = TASK_SIZE;
24411 +
24412 +#ifdef CONFIG_PAX_SEGMEXEC
24413 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24414 + pax_task_size = SEGMEXEC_TASK_SIZE;
24415 +#endif
24416 +
24417 + pax_task_size -= PAGE_SIZE;
24418
24419 if (len > mm->cached_hole_size) {
24420 - start_addr = mm->free_area_cache;
24421 + start_addr = mm->free_area_cache;
24422 } else {
24423 - start_addr = TASK_UNMAPPED_BASE;
24424 - mm->cached_hole_size = 0;
24425 + start_addr = mm->mmap_base;
24426 + mm->cached_hole_size = 0;
24427 }
24428
24429 full_search:
24430 @@ -291,26 +298,27 @@ full_search:
24431
24432 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24433 /* At this point: (!vma || addr < vma->vm_end). */
24434 - if (TASK_SIZE - len < addr) {
24435 + if (pax_task_size - len < addr) {
24436 /*
24437 * Start a new search - just in case we missed
24438 * some holes.
24439 */
24440 - if (start_addr != TASK_UNMAPPED_BASE) {
24441 - start_addr = TASK_UNMAPPED_BASE;
24442 + if (start_addr != mm->mmap_base) {
24443 + start_addr = mm->mmap_base;
24444 mm->cached_hole_size = 0;
24445 goto full_search;
24446 }
24447 return -ENOMEM;
24448 }
24449 - if (!vma || addr + len <= vma->vm_start) {
24450 - mm->free_area_cache = addr + len;
24451 - return addr;
24452 - }
24453 + if (check_heap_stack_gap(vma, addr, len))
24454 + break;
24455 if (addr + mm->cached_hole_size < vma->vm_start)
24456 mm->cached_hole_size = vma->vm_start - addr;
24457 addr = ALIGN(vma->vm_end, huge_page_size(h));
24458 }
24459 +
24460 + mm->free_area_cache = addr + len;
24461 + return addr;
24462 }
24463
24464 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24465 @@ -321,9 +329,8 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24466 struct mm_struct *mm = current->mm;
24467 struct vm_area_struct *vma;
24468 unsigned long base = mm->mmap_base;
24469 - unsigned long addr = addr0;
24470 + unsigned long addr;
24471 unsigned long largest_hole = mm->cached_hole_size;
24472 - unsigned long start_addr;
24473
24474 /* don't allow allocations above current base */
24475 if (mm->free_area_cache > base)
24476 @@ -333,16 +340,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24477 largest_hole = 0;
24478 mm->free_area_cache = base;
24479 }
24480 -try_again:
24481 - start_addr = mm->free_area_cache;
24482
24483 /* make sure it can fit in the remaining address space */
24484 if (mm->free_area_cache < len)
24485 goto fail;
24486
24487 /* either no address requested or can't fit in requested address hole */
24488 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
24489 + addr = mm->free_area_cache - len;
24490 do {
24491 + addr &= huge_page_mask(h);
24492 /*
24493 * Lookup failure means no vma is above this address,
24494 * i.e. return with success:
24495 @@ -351,10 +357,10 @@ try_again:
24496 if (!vma)
24497 return addr;
24498
24499 - if (addr + len <= vma->vm_start) {
24500 + if (check_heap_stack_gap(vma, addr, len)) {
24501 /* remember the address as a hint for next time */
24502 - mm->cached_hole_size = largest_hole;
24503 - return (mm->free_area_cache = addr);
24504 + mm->cached_hole_size = largest_hole;
24505 + return (mm->free_area_cache = addr);
24506 } else if (mm->free_area_cache == vma->vm_end) {
24507 /* pull free_area_cache down to the first hole */
24508 mm->free_area_cache = vma->vm_start;
24509 @@ -363,29 +369,34 @@ try_again:
24510
24511 /* remember the largest hole we saw so far */
24512 if (addr + largest_hole < vma->vm_start)
24513 - largest_hole = vma->vm_start - addr;
24514 + largest_hole = vma->vm_start - addr;
24515
24516 /* try just below the current vma->vm_start */
24517 - addr = (vma->vm_start - len) & huge_page_mask(h);
24518 - } while (len <= vma->vm_start);
24519 + addr = skip_heap_stack_gap(vma, len);
24520 + } while (!IS_ERR_VALUE(addr));
24521
24522 fail:
24523 /*
24524 - * if hint left us with no space for the requested
24525 - * mapping then try again:
24526 - */
24527 - if (start_addr != base) {
24528 - mm->free_area_cache = base;
24529 - largest_hole = 0;
24530 - goto try_again;
24531 - }
24532 - /*
24533 * A failed mmap() very likely causes application failure,
24534 * so fall back to the bottom-up function here. This scenario
24535 * can happen with large stack limits and large mmap()
24536 * allocations.
24537 */
24538 - mm->free_area_cache = TASK_UNMAPPED_BASE;
24539 +
24540 +#ifdef CONFIG_PAX_SEGMEXEC
24541 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24542 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24543 + else
24544 +#endif
24545 +
24546 + mm->mmap_base = TASK_UNMAPPED_BASE;
24547 +
24548 +#ifdef CONFIG_PAX_RANDMMAP
24549 + if (mm->pax_flags & MF_PAX_RANDMMAP)
24550 + mm->mmap_base += mm->delta_mmap;
24551 +#endif
24552 +
24553 + mm->free_area_cache = mm->mmap_base;
24554 mm->cached_hole_size = ~0UL;
24555 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24556 len, pgoff, flags);
24557 @@ -393,6 +404,7 @@ fail:
24558 /*
24559 * Restore the topdown base:
24560 */
24561 + mm->mmap_base = base;
24562 mm->free_area_cache = base;
24563 mm->cached_hole_size = ~0UL;
24564
24565 @@ -406,10 +418,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24566 struct hstate *h = hstate_file(file);
24567 struct mm_struct *mm = current->mm;
24568 struct vm_area_struct *vma;
24569 + unsigned long pax_task_size = TASK_SIZE;
24570
24571 if (len & ~huge_page_mask(h))
24572 return -EINVAL;
24573 - if (len > TASK_SIZE)
24574 +
24575 +#ifdef CONFIG_PAX_SEGMEXEC
24576 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24577 + pax_task_size = SEGMEXEC_TASK_SIZE;
24578 +#endif
24579 +
24580 + pax_task_size -= PAGE_SIZE;
24581 +
24582 + if (len > pax_task_size)
24583 return -ENOMEM;
24584
24585 if (flags & MAP_FIXED) {
24586 @@ -421,8 +442,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24587 if (addr) {
24588 addr = ALIGN(addr, huge_page_size(h));
24589 vma = find_vma(mm, addr);
24590 - if (TASK_SIZE - len >= addr &&
24591 - (!vma || addr + len <= vma->vm_start))
24592 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24593 return addr;
24594 }
24595 if (mm->get_unmapped_area == arch_get_unmapped_area)
24596 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24597 index d7aea41..f753ad2 100644
24598 --- a/arch/x86/mm/init.c
24599 +++ b/arch/x86/mm/init.c
24600 @@ -16,6 +16,8 @@
24601 #include <asm/tlb.h>
24602 #include <asm/proto.h>
24603 #include <asm/dma.h> /* for MAX_DMA_PFN */
24604 +#include <asm/desc.h>
24605 +#include <asm/bios_ebda.h>
24606
24607 unsigned long __initdata pgt_buf_start;
24608 unsigned long __meminitdata pgt_buf_end;
24609 @@ -44,7 +46,7 @@ static void __init find_early_table_space(struct map_range *mr, int nr_range)
24610 {
24611 int i;
24612 unsigned long puds = 0, pmds = 0, ptes = 0, tables;
24613 - unsigned long start = 0, good_end;
24614 + unsigned long start = 0x100000, good_end;
24615 phys_addr_t base;
24616
24617 for (i = 0; i < nr_range; i++) {
24618 @@ -321,10 +323,37 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24619 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
24620 * mmio resources as well as potential bios/acpi data regions.
24621 */
24622 +
24623 +#ifdef CONFIG_GRKERNSEC_KMEM
24624 +static unsigned int ebda_start __read_only;
24625 +static unsigned int ebda_end __read_only;
24626 +#endif
24627 +
24628 int devmem_is_allowed(unsigned long pagenr)
24629 {
24630 - if (pagenr < 256)
24631 +#ifdef CONFIG_GRKERNSEC_KMEM
24632 + /* allow BDA */
24633 + if (!pagenr)
24634 return 1;
24635 + /* allow EBDA */
24636 + if (pagenr >= ebda_start && pagenr < ebda_end)
24637 + return 1;
24638 +#else
24639 + if (!pagenr)
24640 + return 1;
24641 +#ifdef CONFIG_VM86
24642 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24643 + return 1;
24644 +#endif
24645 +#endif
24646 +
24647 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24648 + return 1;
24649 +#ifdef CONFIG_GRKERNSEC_KMEM
24650 + /* throw out everything else below 1MB */
24651 + if (pagenr <= 256)
24652 + return 0;
24653 +#endif
24654 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24655 return 0;
24656 if (!page_is_ram(pagenr))
24657 @@ -381,8 +410,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24658 #endif
24659 }
24660
24661 +#ifdef CONFIG_GRKERNSEC_KMEM
24662 +static inline void gr_init_ebda(void)
24663 +{
24664 + unsigned int ebda_addr;
24665 + unsigned int ebda_size = 0;
24666 +
24667 + ebda_addr = get_bios_ebda();
24668 + if (ebda_addr) {
24669 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
24670 + ebda_size <<= 10;
24671 + }
24672 + if (ebda_addr && ebda_size) {
24673 + ebda_start = ebda_addr >> PAGE_SHIFT;
24674 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
24675 + } else {
24676 + ebda_start = 0x9f000 >> PAGE_SHIFT;
24677 + ebda_end = 0xa0000 >> PAGE_SHIFT;
24678 + }
24679 +}
24680 +#else
24681 +static inline void gr_init_ebda(void) { }
24682 +#endif
24683 +
24684 void free_initmem(void)
24685 {
24686 +#ifdef CONFIG_PAX_KERNEXEC
24687 +#ifdef CONFIG_X86_32
24688 + /* PaX: limit KERNEL_CS to actual size */
24689 + unsigned long addr, limit;
24690 + struct desc_struct d;
24691 + int cpu;
24692 +#else
24693 + pgd_t *pgd;
24694 + pud_t *pud;
24695 + pmd_t *pmd;
24696 + unsigned long addr, end;
24697 +#endif
24698 +#endif
24699 +
24700 + gr_init_ebda();
24701 +
24702 +#ifdef CONFIG_PAX_KERNEXEC
24703 +#ifdef CONFIG_X86_32
24704 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24705 + limit = (limit - 1UL) >> PAGE_SHIFT;
24706 +
24707 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24708 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24709 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24710 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24711 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
24712 + }
24713 +
24714 + /* PaX: make KERNEL_CS read-only */
24715 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24716 + if (!paravirt_enabled())
24717 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24718 +/*
24719 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24720 + pgd = pgd_offset_k(addr);
24721 + pud = pud_offset(pgd, addr);
24722 + pmd = pmd_offset(pud, addr);
24723 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24724 + }
24725 +*/
24726 +#ifdef CONFIG_X86_PAE
24727 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24728 +/*
24729 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24730 + pgd = pgd_offset_k(addr);
24731 + pud = pud_offset(pgd, addr);
24732 + pmd = pmd_offset(pud, addr);
24733 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24734 + }
24735 +*/
24736 +#endif
24737 +
24738 +#ifdef CONFIG_MODULES
24739 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24740 +#endif
24741 +
24742 +#else
24743 + /* PaX: make kernel code/rodata read-only, rest non-executable */
24744 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24745 + pgd = pgd_offset_k(addr);
24746 + pud = pud_offset(pgd, addr);
24747 + pmd = pmd_offset(pud, addr);
24748 + if (!pmd_present(*pmd))
24749 + continue;
24750 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24751 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24752 + else
24753 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24754 + }
24755 +
24756 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24757 + end = addr + KERNEL_IMAGE_SIZE;
24758 + for (; addr < end; addr += PMD_SIZE) {
24759 + pgd = pgd_offset_k(addr);
24760 + pud = pud_offset(pgd, addr);
24761 + pmd = pmd_offset(pud, addr);
24762 + if (!pmd_present(*pmd))
24763 + continue;
24764 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24765 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24766 + }
24767 +#endif
24768 +
24769 + flush_tlb_all();
24770 +#endif
24771 +
24772 free_init_pages("unused kernel memory",
24773 (unsigned long)(&__init_begin),
24774 (unsigned long)(&__init_end));
24775 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24776 index 575d86f..4987469 100644
24777 --- a/arch/x86/mm/init_32.c
24778 +++ b/arch/x86/mm/init_32.c
24779 @@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
24780 }
24781
24782 /*
24783 - * Creates a middle page table and puts a pointer to it in the
24784 - * given global directory entry. This only returns the gd entry
24785 - * in non-PAE compilation mode, since the middle layer is folded.
24786 - */
24787 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
24788 -{
24789 - pud_t *pud;
24790 - pmd_t *pmd_table;
24791 -
24792 -#ifdef CONFIG_X86_PAE
24793 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24794 - if (after_bootmem)
24795 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24796 - else
24797 - pmd_table = (pmd_t *)alloc_low_page();
24798 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24799 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24800 - pud = pud_offset(pgd, 0);
24801 - BUG_ON(pmd_table != pmd_offset(pud, 0));
24802 -
24803 - return pmd_table;
24804 - }
24805 -#endif
24806 - pud = pud_offset(pgd, 0);
24807 - pmd_table = pmd_offset(pud, 0);
24808 -
24809 - return pmd_table;
24810 -}
24811 -
24812 -/*
24813 * Create a page table and place a pointer to it in a middle page
24814 * directory entry:
24815 */
24816 @@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24817 page_table = (pte_t *)alloc_low_page();
24818
24819 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24820 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24821 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24822 +#else
24823 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24824 +#endif
24825 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24826 }
24827
24828 return pte_offset_kernel(pmd, 0);
24829 }
24830
24831 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
24832 +{
24833 + pud_t *pud;
24834 + pmd_t *pmd_table;
24835 +
24836 + pud = pud_offset(pgd, 0);
24837 + pmd_table = pmd_offset(pud, 0);
24838 +
24839 + return pmd_table;
24840 +}
24841 +
24842 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24843 {
24844 int pgd_idx = pgd_index(vaddr);
24845 @@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24846 int pgd_idx, pmd_idx;
24847 unsigned long vaddr;
24848 pgd_t *pgd;
24849 + pud_t *pud;
24850 pmd_t *pmd;
24851 pte_t *pte = NULL;
24852
24853 @@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24854 pgd = pgd_base + pgd_idx;
24855
24856 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24857 - pmd = one_md_table_init(pgd);
24858 - pmd = pmd + pmd_index(vaddr);
24859 + pud = pud_offset(pgd, vaddr);
24860 + pmd = pmd_offset(pud, vaddr);
24861 +
24862 +#ifdef CONFIG_X86_PAE
24863 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24864 +#endif
24865 +
24866 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24867 pmd++, pmd_idx++) {
24868 pte = page_table_kmap_check(one_page_table_init(pmd),
24869 @@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24870 }
24871 }
24872
24873 -static inline int is_kernel_text(unsigned long addr)
24874 +static inline int is_kernel_text(unsigned long start, unsigned long end)
24875 {
24876 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
24877 - return 1;
24878 - return 0;
24879 + if ((start > ktla_ktva((unsigned long)_etext) ||
24880 + end <= ktla_ktva((unsigned long)_stext)) &&
24881 + (start > ktla_ktva((unsigned long)_einittext) ||
24882 + end <= ktla_ktva((unsigned long)_sinittext)) &&
24883 +
24884 +#ifdef CONFIG_ACPI_SLEEP
24885 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24886 +#endif
24887 +
24888 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24889 + return 0;
24890 + return 1;
24891 }
24892
24893 /*
24894 @@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
24895 unsigned long last_map_addr = end;
24896 unsigned long start_pfn, end_pfn;
24897 pgd_t *pgd_base = swapper_pg_dir;
24898 - int pgd_idx, pmd_idx, pte_ofs;
24899 + unsigned int pgd_idx, pmd_idx, pte_ofs;
24900 unsigned long pfn;
24901 pgd_t *pgd;
24902 + pud_t *pud;
24903 pmd_t *pmd;
24904 pte_t *pte;
24905 unsigned pages_2m, pages_4k;
24906 @@ -280,8 +281,13 @@ repeat:
24907 pfn = start_pfn;
24908 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24909 pgd = pgd_base + pgd_idx;
24910 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
24911 - pmd = one_md_table_init(pgd);
24912 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
24913 + pud = pud_offset(pgd, 0);
24914 + pmd = pmd_offset(pud, 0);
24915 +
24916 +#ifdef CONFIG_X86_PAE
24917 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24918 +#endif
24919
24920 if (pfn >= end_pfn)
24921 continue;
24922 @@ -293,14 +299,13 @@ repeat:
24923 #endif
24924 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
24925 pmd++, pmd_idx++) {
24926 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
24927 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
24928
24929 /*
24930 * Map with big pages if possible, otherwise
24931 * create normal page tables:
24932 */
24933 if (use_pse) {
24934 - unsigned int addr2;
24935 pgprot_t prot = PAGE_KERNEL_LARGE;
24936 /*
24937 * first pass will use the same initial
24938 @@ -310,11 +315,7 @@ repeat:
24939 __pgprot(PTE_IDENT_ATTR |
24940 _PAGE_PSE);
24941
24942 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
24943 - PAGE_OFFSET + PAGE_SIZE-1;
24944 -
24945 - if (is_kernel_text(addr) ||
24946 - is_kernel_text(addr2))
24947 + if (is_kernel_text(address, address + PMD_SIZE))
24948 prot = PAGE_KERNEL_LARGE_EXEC;
24949
24950 pages_2m++;
24951 @@ -331,7 +332,7 @@ repeat:
24952 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24953 pte += pte_ofs;
24954 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
24955 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
24956 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
24957 pgprot_t prot = PAGE_KERNEL;
24958 /*
24959 * first pass will use the same initial
24960 @@ -339,7 +340,7 @@ repeat:
24961 */
24962 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
24963
24964 - if (is_kernel_text(addr))
24965 + if (is_kernel_text(address, address + PAGE_SIZE))
24966 prot = PAGE_KERNEL_EXEC;
24967
24968 pages_4k++;
24969 @@ -465,7 +466,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
24970
24971 pud = pud_offset(pgd, va);
24972 pmd = pmd_offset(pud, va);
24973 - if (!pmd_present(*pmd))
24974 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
24975 break;
24976
24977 pte = pte_offset_kernel(pmd, va);
24978 @@ -517,12 +518,10 @@ void __init early_ioremap_page_table_range_init(void)
24979
24980 static void __init pagetable_init(void)
24981 {
24982 - pgd_t *pgd_base = swapper_pg_dir;
24983 -
24984 - permanent_kmaps_init(pgd_base);
24985 + permanent_kmaps_init(swapper_pg_dir);
24986 }
24987
24988 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24989 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24990 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24991
24992 /* user-defined highmem size */
24993 @@ -734,6 +733,12 @@ void __init mem_init(void)
24994
24995 pci_iommu_alloc();
24996
24997 +#ifdef CONFIG_PAX_PER_CPU_PGD
24998 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24999 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25000 + KERNEL_PGD_PTRS);
25001 +#endif
25002 +
25003 #ifdef CONFIG_FLATMEM
25004 BUG_ON(!mem_map);
25005 #endif
25006 @@ -760,7 +765,7 @@ void __init mem_init(void)
25007 reservedpages++;
25008
25009 codesize = (unsigned long) &_etext - (unsigned long) &_text;
25010 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
25011 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
25012 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
25013
25014 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
25015 @@ -801,10 +806,10 @@ void __init mem_init(void)
25016 ((unsigned long)&__init_end -
25017 (unsigned long)&__init_begin) >> 10,
25018
25019 - (unsigned long)&_etext, (unsigned long)&_edata,
25020 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
25021 + (unsigned long)&_sdata, (unsigned long)&_edata,
25022 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
25023
25024 - (unsigned long)&_text, (unsigned long)&_etext,
25025 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
25026 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
25027
25028 /*
25029 @@ -882,6 +887,7 @@ void set_kernel_text_rw(void)
25030 if (!kernel_set_to_readonly)
25031 return;
25032
25033 + start = ktla_ktva(start);
25034 pr_debug("Set kernel text: %lx - %lx for read write\n",
25035 start, start+size);
25036
25037 @@ -896,6 +902,7 @@ void set_kernel_text_ro(void)
25038 if (!kernel_set_to_readonly)
25039 return;
25040
25041 + start = ktla_ktva(start);
25042 pr_debug("Set kernel text: %lx - %lx for read only\n",
25043 start, start+size);
25044
25045 @@ -924,6 +931,7 @@ void mark_rodata_ro(void)
25046 unsigned long start = PFN_ALIGN(_text);
25047 unsigned long size = PFN_ALIGN(_etext) - start;
25048
25049 + start = ktla_ktva(start);
25050 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
25051 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
25052 size >> 10);
25053 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
25054 index 3baff25..8b37564 100644
25055 --- a/arch/x86/mm/init_64.c
25056 +++ b/arch/x86/mm/init_64.c
25057 @@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
25058 * around without checking the pgd every time.
25059 */
25060
25061 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
25062 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
25063 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25064
25065 int force_personality32;
25066 @@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25067
25068 for (address = start; address <= end; address += PGDIR_SIZE) {
25069 const pgd_t *pgd_ref = pgd_offset_k(address);
25070 +
25071 +#ifdef CONFIG_PAX_PER_CPU_PGD
25072 + unsigned long cpu;
25073 +#else
25074 struct page *page;
25075 +#endif
25076
25077 if (pgd_none(*pgd_ref))
25078 continue;
25079
25080 spin_lock(&pgd_lock);
25081 +
25082 +#ifdef CONFIG_PAX_PER_CPU_PGD
25083 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25084 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
25085 +#else
25086 list_for_each_entry(page, &pgd_list, lru) {
25087 pgd_t *pgd;
25088 spinlock_t *pgt_lock;
25089 @@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25090 /* the pgt_lock only for Xen */
25091 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
25092 spin_lock(pgt_lock);
25093 +#endif
25094
25095 if (pgd_none(*pgd))
25096 set_pgd(pgd, *pgd_ref);
25097 @@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25098 BUG_ON(pgd_page_vaddr(*pgd)
25099 != pgd_page_vaddr(*pgd_ref));
25100
25101 +#ifndef CONFIG_PAX_PER_CPU_PGD
25102 spin_unlock(pgt_lock);
25103 +#endif
25104 +
25105 }
25106 spin_unlock(&pgd_lock);
25107 }
25108 @@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
25109 {
25110 if (pgd_none(*pgd)) {
25111 pud_t *pud = (pud_t *)spp_getpage();
25112 - pgd_populate(&init_mm, pgd, pud);
25113 + pgd_populate_kernel(&init_mm, pgd, pud);
25114 if (pud != pud_offset(pgd, 0))
25115 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
25116 pud, pud_offset(pgd, 0));
25117 @@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
25118 {
25119 if (pud_none(*pud)) {
25120 pmd_t *pmd = (pmd_t *) spp_getpage();
25121 - pud_populate(&init_mm, pud, pmd);
25122 + pud_populate_kernel(&init_mm, pud, pmd);
25123 if (pmd != pmd_offset(pud, 0))
25124 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
25125 pmd, pmd_offset(pud, 0));
25126 @@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
25127 pmd = fill_pmd(pud, vaddr);
25128 pte = fill_pte(pmd, vaddr);
25129
25130 + pax_open_kernel();
25131 set_pte(pte, new_pte);
25132 + pax_close_kernel();
25133
25134 /*
25135 * It's enough to flush this one mapping.
25136 @@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
25137 pgd = pgd_offset_k((unsigned long)__va(phys));
25138 if (pgd_none(*pgd)) {
25139 pud = (pud_t *) spp_getpage();
25140 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
25141 - _PAGE_USER));
25142 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
25143 }
25144 pud = pud_offset(pgd, (unsigned long)__va(phys));
25145 if (pud_none(*pud)) {
25146 pmd = (pmd_t *) spp_getpage();
25147 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
25148 - _PAGE_USER));
25149 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
25150 }
25151 pmd = pmd_offset(pud, phys);
25152 BUG_ON(!pmd_none(*pmd));
25153 @@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
25154 if (pfn >= pgt_buf_top)
25155 panic("alloc_low_page: ran out of memory");
25156
25157 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25158 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25159 clear_page(adr);
25160 *phys = pfn * PAGE_SIZE;
25161 return adr;
25162 @@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
25163
25164 phys = __pa(virt);
25165 left = phys & (PAGE_SIZE - 1);
25166 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25167 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25168 adr = (void *)(((unsigned long)adr) | left);
25169
25170 return adr;
25171 @@ -553,7 +567,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
25172 unmap_low_page(pmd);
25173
25174 spin_lock(&init_mm.page_table_lock);
25175 - pud_populate(&init_mm, pud, __va(pmd_phys));
25176 + pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
25177 spin_unlock(&init_mm.page_table_lock);
25178 }
25179 __flush_tlb_all();
25180 @@ -599,7 +613,7 @@ kernel_physical_mapping_init(unsigned long start,
25181 unmap_low_page(pud);
25182
25183 spin_lock(&init_mm.page_table_lock);
25184 - pgd_populate(&init_mm, pgd, __va(pud_phys));
25185 + pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
25186 spin_unlock(&init_mm.page_table_lock);
25187 pgd_changed = true;
25188 }
25189 @@ -691,6 +705,12 @@ void __init mem_init(void)
25190
25191 pci_iommu_alloc();
25192
25193 +#ifdef CONFIG_PAX_PER_CPU_PGD
25194 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25195 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25196 + KERNEL_PGD_PTRS);
25197 +#endif
25198 +
25199 /* clear_bss() already clear the empty_zero_page */
25200
25201 reservedpages = 0;
25202 @@ -851,8 +871,8 @@ int kern_addr_valid(unsigned long addr)
25203 static struct vm_area_struct gate_vma = {
25204 .vm_start = VSYSCALL_START,
25205 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
25206 - .vm_page_prot = PAGE_READONLY_EXEC,
25207 - .vm_flags = VM_READ | VM_EXEC
25208 + .vm_page_prot = PAGE_READONLY,
25209 + .vm_flags = VM_READ
25210 };
25211
25212 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
25213 @@ -886,7 +906,7 @@ int in_gate_area_no_mm(unsigned long addr)
25214
25215 const char *arch_vma_name(struct vm_area_struct *vma)
25216 {
25217 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
25218 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
25219 return "[vdso]";
25220 if (vma == &gate_vma)
25221 return "[vsyscall]";
25222 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
25223 index 7b179b4..6bd1777 100644
25224 --- a/arch/x86/mm/iomap_32.c
25225 +++ b/arch/x86/mm/iomap_32.c
25226 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
25227 type = kmap_atomic_idx_push();
25228 idx = type + KM_TYPE_NR * smp_processor_id();
25229 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25230 +
25231 + pax_open_kernel();
25232 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
25233 + pax_close_kernel();
25234 +
25235 arch_flush_lazy_mmu_mode();
25236
25237 return (void *)vaddr;
25238 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
25239 index 78fe3f1..8293b6f 100644
25240 --- a/arch/x86/mm/ioremap.c
25241 +++ b/arch/x86/mm/ioremap.c
25242 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
25243 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
25244 int is_ram = page_is_ram(pfn);
25245
25246 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
25247 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
25248 return NULL;
25249 WARN_ON_ONCE(is_ram);
25250 }
25251 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
25252
25253 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
25254 if (page_is_ram(start >> PAGE_SHIFT))
25255 +#ifdef CONFIG_HIGHMEM
25256 + if ((start >> PAGE_SHIFT) < max_low_pfn)
25257 +#endif
25258 return __va(phys);
25259
25260 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
25261 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
25262 early_param("early_ioremap_debug", early_ioremap_debug_setup);
25263
25264 static __initdata int after_paging_init;
25265 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
25266 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
25267
25268 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
25269 {
25270 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
25271 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
25272
25273 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25274 - memset(bm_pte, 0, sizeof(bm_pte));
25275 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
25276 + pmd_populate_user(&init_mm, pmd, bm_pte);
25277
25278 /*
25279 * The boot-ioremap range spans multiple pmds, for which
25280 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25281 index d87dd6d..bf3fa66 100644
25282 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
25283 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25284 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25285 * memory (e.g. tracked pages)? For now, we need this to avoid
25286 * invoking kmemcheck for PnP BIOS calls.
25287 */
25288 - if (regs->flags & X86_VM_MASK)
25289 + if (v8086_mode(regs))
25290 return false;
25291 - if (regs->cs != __KERNEL_CS)
25292 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25293 return false;
25294
25295 pte = kmemcheck_pte_lookup(address);
25296 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25297 index 845df68..1d8d29f 100644
25298 --- a/arch/x86/mm/mmap.c
25299 +++ b/arch/x86/mm/mmap.c
25300 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
25301 * Leave an at least ~128 MB hole with possible stack randomization.
25302 */
25303 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25304 -#define MAX_GAP (TASK_SIZE/6*5)
25305 +#define MAX_GAP (pax_task_size/6*5)
25306
25307 static int mmap_is_legacy(void)
25308 {
25309 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
25310 return rnd << PAGE_SHIFT;
25311 }
25312
25313 -static unsigned long mmap_base(void)
25314 +static unsigned long mmap_base(struct mm_struct *mm)
25315 {
25316 unsigned long gap = rlimit(RLIMIT_STACK);
25317 + unsigned long pax_task_size = TASK_SIZE;
25318 +
25319 +#ifdef CONFIG_PAX_SEGMEXEC
25320 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25321 + pax_task_size = SEGMEXEC_TASK_SIZE;
25322 +#endif
25323
25324 if (gap < MIN_GAP)
25325 gap = MIN_GAP;
25326 else if (gap > MAX_GAP)
25327 gap = MAX_GAP;
25328
25329 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25330 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25331 }
25332
25333 /*
25334 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25335 * does, but not when emulating X86_32
25336 */
25337 -static unsigned long mmap_legacy_base(void)
25338 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
25339 {
25340 - if (mmap_is_ia32())
25341 + if (mmap_is_ia32()) {
25342 +
25343 +#ifdef CONFIG_PAX_SEGMEXEC
25344 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25345 + return SEGMEXEC_TASK_UNMAPPED_BASE;
25346 + else
25347 +#endif
25348 +
25349 return TASK_UNMAPPED_BASE;
25350 - else
25351 + } else
25352 return TASK_UNMAPPED_BASE + mmap_rnd();
25353 }
25354
25355 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25356 void arch_pick_mmap_layout(struct mm_struct *mm)
25357 {
25358 if (mmap_is_legacy()) {
25359 - mm->mmap_base = mmap_legacy_base();
25360 + mm->mmap_base = mmap_legacy_base(mm);
25361 +
25362 +#ifdef CONFIG_PAX_RANDMMAP
25363 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25364 + mm->mmap_base += mm->delta_mmap;
25365 +#endif
25366 +
25367 mm->get_unmapped_area = arch_get_unmapped_area;
25368 mm->unmap_area = arch_unmap_area;
25369 } else {
25370 - mm->mmap_base = mmap_base();
25371 + mm->mmap_base = mmap_base(mm);
25372 +
25373 +#ifdef CONFIG_PAX_RANDMMAP
25374 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25375 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25376 +#endif
25377 +
25378 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25379 mm->unmap_area = arch_unmap_area_topdown;
25380 }
25381 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25382 index dc0b727..dc9d71a 100644
25383 --- a/arch/x86/mm/mmio-mod.c
25384 +++ b/arch/x86/mm/mmio-mod.c
25385 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25386 break;
25387 default:
25388 {
25389 - unsigned char *ip = (unsigned char *)instptr;
25390 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25391 my_trace->opcode = MMIO_UNKNOWN_OP;
25392 my_trace->width = 0;
25393 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25394 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25395 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25396 void __iomem *addr)
25397 {
25398 - static atomic_t next_id;
25399 + static atomic_unchecked_t next_id;
25400 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25401 /* These are page-unaligned. */
25402 struct mmiotrace_map map = {
25403 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25404 .private = trace
25405 },
25406 .phys = offset,
25407 - .id = atomic_inc_return(&next_id)
25408 + .id = atomic_inc_return_unchecked(&next_id)
25409 };
25410 map.map_id = trace->id;
25411
25412 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25413 index b008656..773eac2 100644
25414 --- a/arch/x86/mm/pageattr-test.c
25415 +++ b/arch/x86/mm/pageattr-test.c
25416 @@ -36,7 +36,7 @@ enum {
25417
25418 static int pte_testbit(pte_t pte)
25419 {
25420 - return pte_flags(pte) & _PAGE_UNUSED1;
25421 + return pte_flags(pte) & _PAGE_CPA_TEST;
25422 }
25423
25424 struct split_state {
25425 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25426 index a718e0d..45efc32 100644
25427 --- a/arch/x86/mm/pageattr.c
25428 +++ b/arch/x86/mm/pageattr.c
25429 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25430 */
25431 #ifdef CONFIG_PCI_BIOS
25432 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25433 - pgprot_val(forbidden) |= _PAGE_NX;
25434 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25435 #endif
25436
25437 /*
25438 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25439 * Does not cover __inittext since that is gone later on. On
25440 * 64bit we do not enforce !NX on the low mapping
25441 */
25442 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
25443 - pgprot_val(forbidden) |= _PAGE_NX;
25444 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25445 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25446
25447 +#ifdef CONFIG_DEBUG_RODATA
25448 /*
25449 * The .rodata section needs to be read-only. Using the pfn
25450 * catches all aliases.
25451 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25452 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25453 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25454 pgprot_val(forbidden) |= _PAGE_RW;
25455 +#endif
25456
25457 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25458 /*
25459 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25460 }
25461 #endif
25462
25463 +#ifdef CONFIG_PAX_KERNEXEC
25464 + if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25465 + pgprot_val(forbidden) |= _PAGE_RW;
25466 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25467 + }
25468 +#endif
25469 +
25470 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25471
25472 return prot;
25473 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25474 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25475 {
25476 /* change init_mm */
25477 + pax_open_kernel();
25478 set_pte_atomic(kpte, pte);
25479 +
25480 #ifdef CONFIG_X86_32
25481 if (!SHARED_KERNEL_PMD) {
25482 +
25483 +#ifdef CONFIG_PAX_PER_CPU_PGD
25484 + unsigned long cpu;
25485 +#else
25486 struct page *page;
25487 +#endif
25488
25489 +#ifdef CONFIG_PAX_PER_CPU_PGD
25490 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25491 + pgd_t *pgd = get_cpu_pgd(cpu);
25492 +#else
25493 list_for_each_entry(page, &pgd_list, lru) {
25494 - pgd_t *pgd;
25495 + pgd_t *pgd = (pgd_t *)page_address(page);
25496 +#endif
25497 +
25498 pud_t *pud;
25499 pmd_t *pmd;
25500
25501 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
25502 + pgd += pgd_index(address);
25503 pud = pud_offset(pgd, address);
25504 pmd = pmd_offset(pud, address);
25505 set_pte_atomic((pte_t *)pmd, pte);
25506 }
25507 }
25508 #endif
25509 + pax_close_kernel();
25510 }
25511
25512 static int
25513 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25514 index 3d68ef6..7f69136 100644
25515 --- a/arch/x86/mm/pat.c
25516 +++ b/arch/x86/mm/pat.c
25517 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
25518
25519 if (!entry) {
25520 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
25521 - current->comm, current->pid, start, end - 1);
25522 + current->comm, task_pid_nr(current), start, end - 1);
25523 return -EINVAL;
25524 }
25525
25526 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25527
25528 while (cursor < to) {
25529 if (!devmem_is_allowed(pfn)) {
25530 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
25531 - current->comm, from, to - 1);
25532 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
25533 + current->comm, from, to - 1, cursor);
25534 return 0;
25535 }
25536 cursor += PAGE_SIZE;
25537 @@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25538 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
25539 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
25540 "for [mem %#010Lx-%#010Lx]\n",
25541 - current->comm, current->pid,
25542 + current->comm, task_pid_nr(current),
25543 cattr_name(flags),
25544 base, (unsigned long long)(base + size-1));
25545 return -EINVAL;
25546 @@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25547 flags = lookup_memtype(paddr);
25548 if (want_flags != flags) {
25549 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
25550 - current->comm, current->pid,
25551 + current->comm, task_pid_nr(current),
25552 cattr_name(want_flags),
25553 (unsigned long long)paddr,
25554 (unsigned long long)(paddr + size - 1),
25555 @@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25556 free_memtype(paddr, paddr + size);
25557 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25558 " for [mem %#010Lx-%#010Lx], got %s\n",
25559 - current->comm, current->pid,
25560 + current->comm, task_pid_nr(current),
25561 cattr_name(want_flags),
25562 (unsigned long long)paddr,
25563 (unsigned long long)(paddr + size - 1),
25564 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25565 index 9f0614d..92ae64a 100644
25566 --- a/arch/x86/mm/pf_in.c
25567 +++ b/arch/x86/mm/pf_in.c
25568 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25569 int i;
25570 enum reason_type rv = OTHERS;
25571
25572 - p = (unsigned char *)ins_addr;
25573 + p = (unsigned char *)ktla_ktva(ins_addr);
25574 p += skip_prefix(p, &prf);
25575 p += get_opcode(p, &opcode);
25576
25577 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25578 struct prefix_bits prf;
25579 int i;
25580
25581 - p = (unsigned char *)ins_addr;
25582 + p = (unsigned char *)ktla_ktva(ins_addr);
25583 p += skip_prefix(p, &prf);
25584 p += get_opcode(p, &opcode);
25585
25586 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25587 struct prefix_bits prf;
25588 int i;
25589
25590 - p = (unsigned char *)ins_addr;
25591 + p = (unsigned char *)ktla_ktva(ins_addr);
25592 p += skip_prefix(p, &prf);
25593 p += get_opcode(p, &opcode);
25594
25595 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25596 struct prefix_bits prf;
25597 int i;
25598
25599 - p = (unsigned char *)ins_addr;
25600 + p = (unsigned char *)ktla_ktva(ins_addr);
25601 p += skip_prefix(p, &prf);
25602 p += get_opcode(p, &opcode);
25603 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25604 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25605 struct prefix_bits prf;
25606 int i;
25607
25608 - p = (unsigned char *)ins_addr;
25609 + p = (unsigned char *)ktla_ktva(ins_addr);
25610 p += skip_prefix(p, &prf);
25611 p += get_opcode(p, &opcode);
25612 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25613 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25614 index 8573b83..4f3ed7e 100644
25615 --- a/arch/x86/mm/pgtable.c
25616 +++ b/arch/x86/mm/pgtable.c
25617 @@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
25618 list_del(&page->lru);
25619 }
25620
25621 -#define UNSHARED_PTRS_PER_PGD \
25622 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25623 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25624 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25625
25626 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
25627 +{
25628 + unsigned int count = USER_PGD_PTRS;
25629
25630 + while (count--)
25631 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25632 +}
25633 +#endif
25634 +
25635 +#ifdef CONFIG_PAX_PER_CPU_PGD
25636 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
25637 +{
25638 + unsigned int count = USER_PGD_PTRS;
25639 +
25640 + while (count--) {
25641 + pgd_t pgd;
25642 +
25643 +#ifdef CONFIG_X86_64
25644 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
25645 +#else
25646 + pgd = *src++;
25647 +#endif
25648 +
25649 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25650 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
25651 +#endif
25652 +
25653 + *dst++ = pgd;
25654 + }
25655 +
25656 +}
25657 +#endif
25658 +
25659 +#ifdef CONFIG_X86_64
25660 +#define pxd_t pud_t
25661 +#define pyd_t pgd_t
25662 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25663 +#define pxd_free(mm, pud) pud_free((mm), (pud))
25664 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25665 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
25666 +#define PYD_SIZE PGDIR_SIZE
25667 +#else
25668 +#define pxd_t pmd_t
25669 +#define pyd_t pud_t
25670 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25671 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
25672 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25673 +#define pyd_offset(mm, address) pud_offset((mm), (address))
25674 +#define PYD_SIZE PUD_SIZE
25675 +#endif
25676 +
25677 +#ifdef CONFIG_PAX_PER_CPU_PGD
25678 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25679 +static inline void pgd_dtor(pgd_t *pgd) {}
25680 +#else
25681 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25682 {
25683 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25684 @@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
25685 pgd_list_del(pgd);
25686 spin_unlock(&pgd_lock);
25687 }
25688 +#endif
25689
25690 /*
25691 * List of all pgd's needed for non-PAE so it can invalidate entries
25692 @@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
25693 * -- wli
25694 */
25695
25696 -#ifdef CONFIG_X86_PAE
25697 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25698 /*
25699 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25700 * updating the top-level pagetable entries to guarantee the
25701 @@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
25702 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25703 * and initialize the kernel pmds here.
25704 */
25705 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25706 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25707
25708 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25709 {
25710 @@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25711 */
25712 flush_tlb_mm(mm);
25713 }
25714 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25715 +#define PREALLOCATED_PXDS USER_PGD_PTRS
25716 #else /* !CONFIG_X86_PAE */
25717
25718 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25719 -#define PREALLOCATED_PMDS 0
25720 +#define PREALLOCATED_PXDS 0
25721
25722 #endif /* CONFIG_X86_PAE */
25723
25724 -static void free_pmds(pmd_t *pmds[])
25725 +static void free_pxds(pxd_t *pxds[])
25726 {
25727 int i;
25728
25729 - for(i = 0; i < PREALLOCATED_PMDS; i++)
25730 - if (pmds[i])
25731 - free_page((unsigned long)pmds[i]);
25732 + for(i = 0; i < PREALLOCATED_PXDS; i++)
25733 + if (pxds[i])
25734 + free_page((unsigned long)pxds[i]);
25735 }
25736
25737 -static int preallocate_pmds(pmd_t *pmds[])
25738 +static int preallocate_pxds(pxd_t *pxds[])
25739 {
25740 int i;
25741 bool failed = false;
25742
25743 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25744 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25745 - if (pmd == NULL)
25746 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25747 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25748 + if (pxd == NULL)
25749 failed = true;
25750 - pmds[i] = pmd;
25751 + pxds[i] = pxd;
25752 }
25753
25754 if (failed) {
25755 - free_pmds(pmds);
25756 + free_pxds(pxds);
25757 return -ENOMEM;
25758 }
25759
25760 @@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25761 * preallocate which never got a corresponding vma will need to be
25762 * freed manually.
25763 */
25764 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25765 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25766 {
25767 int i;
25768
25769 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25770 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25771 pgd_t pgd = pgdp[i];
25772
25773 if (pgd_val(pgd) != 0) {
25774 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25775 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25776
25777 - pgdp[i] = native_make_pgd(0);
25778 + set_pgd(pgdp + i, native_make_pgd(0));
25779
25780 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25781 - pmd_free(mm, pmd);
25782 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25783 + pxd_free(mm, pxd);
25784 }
25785 }
25786 }
25787
25788 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25789 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25790 {
25791 - pud_t *pud;
25792 + pyd_t *pyd;
25793 unsigned long addr;
25794 int i;
25795
25796 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25797 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25798 return;
25799
25800 - pud = pud_offset(pgd, 0);
25801 +#ifdef CONFIG_X86_64
25802 + pyd = pyd_offset(mm, 0L);
25803 +#else
25804 + pyd = pyd_offset(pgd, 0L);
25805 +#endif
25806
25807 - for (addr = i = 0; i < PREALLOCATED_PMDS;
25808 - i++, pud++, addr += PUD_SIZE) {
25809 - pmd_t *pmd = pmds[i];
25810 + for (addr = i = 0; i < PREALLOCATED_PXDS;
25811 + i++, pyd++, addr += PYD_SIZE) {
25812 + pxd_t *pxd = pxds[i];
25813
25814 if (i >= KERNEL_PGD_BOUNDARY)
25815 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25816 - sizeof(pmd_t) * PTRS_PER_PMD);
25817 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25818 + sizeof(pxd_t) * PTRS_PER_PMD);
25819
25820 - pud_populate(mm, pud, pmd);
25821 + pyd_populate(mm, pyd, pxd);
25822 }
25823 }
25824
25825 pgd_t *pgd_alloc(struct mm_struct *mm)
25826 {
25827 pgd_t *pgd;
25828 - pmd_t *pmds[PREALLOCATED_PMDS];
25829 + pxd_t *pxds[PREALLOCATED_PXDS];
25830
25831 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25832
25833 @@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25834
25835 mm->pgd = pgd;
25836
25837 - if (preallocate_pmds(pmds) != 0)
25838 + if (preallocate_pxds(pxds) != 0)
25839 goto out_free_pgd;
25840
25841 if (paravirt_pgd_alloc(mm) != 0)
25842 - goto out_free_pmds;
25843 + goto out_free_pxds;
25844
25845 /*
25846 * Make sure that pre-populating the pmds is atomic with
25847 @@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25848 spin_lock(&pgd_lock);
25849
25850 pgd_ctor(mm, pgd);
25851 - pgd_prepopulate_pmd(mm, pgd, pmds);
25852 + pgd_prepopulate_pxd(mm, pgd, pxds);
25853
25854 spin_unlock(&pgd_lock);
25855
25856 return pgd;
25857
25858 -out_free_pmds:
25859 - free_pmds(pmds);
25860 +out_free_pxds:
25861 + free_pxds(pxds);
25862 out_free_pgd:
25863 free_page((unsigned long)pgd);
25864 out:
25865 @@ -295,7 +356,7 @@ out:
25866
25867 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25868 {
25869 - pgd_mop_up_pmds(mm, pgd);
25870 + pgd_mop_up_pxds(mm, pgd);
25871 pgd_dtor(pgd);
25872 paravirt_pgd_free(mm, pgd);
25873 free_page((unsigned long)pgd);
25874 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25875 index a69bcb8..19068ab 100644
25876 --- a/arch/x86/mm/pgtable_32.c
25877 +++ b/arch/x86/mm/pgtable_32.c
25878 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25879 return;
25880 }
25881 pte = pte_offset_kernel(pmd, vaddr);
25882 +
25883 + pax_open_kernel();
25884 if (pte_val(pteval))
25885 set_pte_at(&init_mm, vaddr, pte, pteval);
25886 else
25887 pte_clear(&init_mm, vaddr, pte);
25888 + pax_close_kernel();
25889
25890 /*
25891 * It's enough to flush this one mapping.
25892 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25893 index 410531d..0f16030 100644
25894 --- a/arch/x86/mm/setup_nx.c
25895 +++ b/arch/x86/mm/setup_nx.c
25896 @@ -5,8 +5,10 @@
25897 #include <asm/pgtable.h>
25898 #include <asm/proto.h>
25899
25900 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25901 static int disable_nx __cpuinitdata;
25902
25903 +#ifndef CONFIG_PAX_PAGEEXEC
25904 /*
25905 * noexec = on|off
25906 *
25907 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
25908 return 0;
25909 }
25910 early_param("noexec", noexec_setup);
25911 +#endif
25912 +
25913 +#endif
25914
25915 void __cpuinit x86_configure_nx(void)
25916 {
25917 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25918 if (cpu_has_nx && !disable_nx)
25919 __supported_pte_mask |= _PAGE_NX;
25920 else
25921 +#endif
25922 __supported_pte_mask &= ~_PAGE_NX;
25923 }
25924
25925 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
25926 index 613cd83..3a21f1c 100644
25927 --- a/arch/x86/mm/tlb.c
25928 +++ b/arch/x86/mm/tlb.c
25929 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
25930 BUG();
25931 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
25932 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
25933 +
25934 +#ifndef CONFIG_PAX_PER_CPU_PGD
25935 load_cr3(swapper_pg_dir);
25936 +#endif
25937 +
25938 }
25939 }
25940 EXPORT_SYMBOL_GPL(leave_mm);
25941 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
25942 index 877b9a1..a8ecf42 100644
25943 --- a/arch/x86/net/bpf_jit.S
25944 +++ b/arch/x86/net/bpf_jit.S
25945 @@ -9,6 +9,7 @@
25946 */
25947 #include <linux/linkage.h>
25948 #include <asm/dwarf2.h>
25949 +#include <asm/alternative-asm.h>
25950
25951 /*
25952 * Calling convention :
25953 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
25954 jle bpf_slow_path_word
25955 mov (SKBDATA,%rsi),%eax
25956 bswap %eax /* ntohl() */
25957 + pax_force_retaddr
25958 ret
25959
25960 sk_load_half:
25961 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
25962 jle bpf_slow_path_half
25963 movzwl (SKBDATA,%rsi),%eax
25964 rol $8,%ax # ntohs()
25965 + pax_force_retaddr
25966 ret
25967
25968 sk_load_byte:
25969 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
25970 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
25971 jle bpf_slow_path_byte
25972 movzbl (SKBDATA,%rsi),%eax
25973 + pax_force_retaddr
25974 ret
25975
25976 /**
25977 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
25978 movzbl (SKBDATA,%rsi),%ebx
25979 and $15,%bl
25980 shl $2,%bl
25981 + pax_force_retaddr
25982 ret
25983
25984 /* rsi contains offset and can be scratched */
25985 @@ -109,6 +114,7 @@ bpf_slow_path_word:
25986 js bpf_error
25987 mov -12(%rbp),%eax
25988 bswap %eax
25989 + pax_force_retaddr
25990 ret
25991
25992 bpf_slow_path_half:
25993 @@ -117,12 +123,14 @@ bpf_slow_path_half:
25994 mov -12(%rbp),%ax
25995 rol $8,%ax
25996 movzwl %ax,%eax
25997 + pax_force_retaddr
25998 ret
25999
26000 bpf_slow_path_byte:
26001 bpf_slow_path_common(1)
26002 js bpf_error
26003 movzbl -12(%rbp),%eax
26004 + pax_force_retaddr
26005 ret
26006
26007 bpf_slow_path_byte_msh:
26008 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
26009 and $15,%al
26010 shl $2,%al
26011 xchg %eax,%ebx
26012 + pax_force_retaddr
26013 ret
26014
26015 #define sk_negative_common(SIZE) \
26016 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
26017 sk_negative_common(4)
26018 mov (%rax), %eax
26019 bswap %eax
26020 + pax_force_retaddr
26021 ret
26022
26023 bpf_slow_path_half_neg:
26024 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
26025 mov (%rax),%ax
26026 rol $8,%ax
26027 movzwl %ax,%eax
26028 + pax_force_retaddr
26029 ret
26030
26031 bpf_slow_path_byte_neg:
26032 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
26033 .globl sk_load_byte_negative_offset
26034 sk_negative_common(1)
26035 movzbl (%rax), %eax
26036 + pax_force_retaddr
26037 ret
26038
26039 bpf_slow_path_byte_msh_neg:
26040 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
26041 and $15,%al
26042 shl $2,%al
26043 xchg %eax,%ebx
26044 + pax_force_retaddr
26045 ret
26046
26047 bpf_error:
26048 @@ -197,4 +210,5 @@ bpf_error:
26049 xor %eax,%eax
26050 mov -8(%rbp),%rbx
26051 leaveq
26052 + pax_force_retaddr
26053 ret
26054 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
26055 index 33643a8..8e44870 100644
26056 --- a/arch/x86/net/bpf_jit_comp.c
26057 +++ b/arch/x86/net/bpf_jit_comp.c
26058 @@ -120,6 +120,11 @@ static inline void bpf_flush_icache(void *start, void *end)
26059 set_fs(old_fs);
26060 }
26061
26062 +struct bpf_jit_work {
26063 + struct work_struct work;
26064 + void *image;
26065 +};
26066 +
26067 #define CHOOSE_LOAD_FUNC(K, func) \
26068 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
26069
26070 @@ -146,6 +151,10 @@ void bpf_jit_compile(struct sk_filter *fp)
26071 if (addrs == NULL)
26072 return;
26073
26074 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
26075 + if (!fp->work)
26076 + goto out;
26077 +
26078 /* Before first pass, make a rough estimation of addrs[]
26079 * each bpf instruction is translated to less than 64 bytes
26080 */
26081 @@ -593,17 +602,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26082 break;
26083 default:
26084 /* hmm, too complex filter, give up with jit compiler */
26085 - goto out;
26086 + goto error;
26087 }
26088 ilen = prog - temp;
26089 if (image) {
26090 if (unlikely(proglen + ilen > oldproglen)) {
26091 pr_err("bpb_jit_compile fatal error\n");
26092 - kfree(addrs);
26093 - module_free(NULL, image);
26094 - return;
26095 + module_free_exec(NULL, image);
26096 + goto error;
26097 }
26098 + pax_open_kernel();
26099 memcpy(image + proglen, temp, ilen);
26100 + pax_close_kernel();
26101 }
26102 proglen += ilen;
26103 addrs[i] = proglen;
26104 @@ -624,11 +634,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26105 break;
26106 }
26107 if (proglen == oldproglen) {
26108 - image = module_alloc(max_t(unsigned int,
26109 - proglen,
26110 - sizeof(struct work_struct)));
26111 + image = module_alloc_exec(proglen);
26112 if (!image)
26113 - goto out;
26114 + goto error;
26115 }
26116 oldproglen = proglen;
26117 }
26118 @@ -644,7 +652,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26119 bpf_flush_icache(image, image + proglen);
26120
26121 fp->bpf_func = (void *)image;
26122 - }
26123 + } else
26124 +error:
26125 + kfree(fp->work);
26126 +
26127 out:
26128 kfree(addrs);
26129 return;
26130 @@ -652,18 +663,20 @@ out:
26131
26132 static void jit_free_defer(struct work_struct *arg)
26133 {
26134 - module_free(NULL, arg);
26135 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
26136 + kfree(arg);
26137 }
26138
26139 /* run from softirq, we must use a work_struct to call
26140 - * module_free() from process context
26141 + * module_free_exec() from process context
26142 */
26143 void bpf_jit_free(struct sk_filter *fp)
26144 {
26145 if (fp->bpf_func != sk_run_filter) {
26146 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
26147 + struct work_struct *work = &fp->work->work;
26148
26149 INIT_WORK(work, jit_free_defer);
26150 + fp->work->image = fp->bpf_func;
26151 schedule_work(work);
26152 }
26153 }
26154 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
26155 index d6aa6e8..266395a 100644
26156 --- a/arch/x86/oprofile/backtrace.c
26157 +++ b/arch/x86/oprofile/backtrace.c
26158 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
26159 struct stack_frame_ia32 *fp;
26160 unsigned long bytes;
26161
26162 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26163 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26164 if (bytes != sizeof(bufhead))
26165 return NULL;
26166
26167 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
26168 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
26169
26170 oprofile_add_trace(bufhead[0].return_address);
26171
26172 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
26173 struct stack_frame bufhead[2];
26174 unsigned long bytes;
26175
26176 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26177 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26178 if (bytes != sizeof(bufhead))
26179 return NULL;
26180
26181 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
26182 {
26183 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
26184
26185 - if (!user_mode_vm(regs)) {
26186 + if (!user_mode(regs)) {
26187 unsigned long stack = kernel_stack_pointer(regs);
26188 if (depth)
26189 dump_trace(NULL, regs, (unsigned long *)stack, 0,
26190 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
26191 index e14a2ff..3fd6b58 100644
26192 --- a/arch/x86/pci/mrst.c
26193 +++ b/arch/x86/pci/mrst.c
26194 @@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
26195 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
26196 pci_mmcfg_late_init();
26197 pcibios_enable_irq = mrst_pci_irq_enable;
26198 - pci_root_ops = pci_mrst_ops;
26199 + pax_open_kernel();
26200 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
26201 + pax_close_kernel();
26202 pci_soc_mode = 1;
26203 /* Continue with standard init */
26204 return 1;
26205 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
26206 index da8fe05..7ee6704 100644
26207 --- a/arch/x86/pci/pcbios.c
26208 +++ b/arch/x86/pci/pcbios.c
26209 @@ -79,50 +79,93 @@ union bios32 {
26210 static struct {
26211 unsigned long address;
26212 unsigned short segment;
26213 -} bios32_indirect = { 0, __KERNEL_CS };
26214 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
26215
26216 /*
26217 * Returns the entry point for the given service, NULL on error
26218 */
26219
26220 -static unsigned long bios32_service(unsigned long service)
26221 +static unsigned long __devinit bios32_service(unsigned long service)
26222 {
26223 unsigned char return_code; /* %al */
26224 unsigned long address; /* %ebx */
26225 unsigned long length; /* %ecx */
26226 unsigned long entry; /* %edx */
26227 unsigned long flags;
26228 + struct desc_struct d, *gdt;
26229
26230 local_irq_save(flags);
26231 - __asm__("lcall *(%%edi); cld"
26232 +
26233 + gdt = get_cpu_gdt_table(smp_processor_id());
26234 +
26235 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
26236 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26237 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
26238 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26239 +
26240 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
26241 : "=a" (return_code),
26242 "=b" (address),
26243 "=c" (length),
26244 "=d" (entry)
26245 : "0" (service),
26246 "1" (0),
26247 - "D" (&bios32_indirect));
26248 + "D" (&bios32_indirect),
26249 + "r"(__PCIBIOS_DS)
26250 + : "memory");
26251 +
26252 + pax_open_kernel();
26253 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
26254 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
26255 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
26256 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
26257 + pax_close_kernel();
26258 +
26259 local_irq_restore(flags);
26260
26261 switch (return_code) {
26262 - case 0:
26263 - return address + entry;
26264 - case 0x80: /* Not present */
26265 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26266 - return 0;
26267 - default: /* Shouldn't happen */
26268 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26269 - service, return_code);
26270 + case 0: {
26271 + int cpu;
26272 + unsigned char flags;
26273 +
26274 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26275 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26276 + printk(KERN_WARNING "bios32_service: not valid\n");
26277 return 0;
26278 + }
26279 + address = address + PAGE_OFFSET;
26280 + length += 16UL; /* some BIOSs underreport this... */
26281 + flags = 4;
26282 + if (length >= 64*1024*1024) {
26283 + length >>= PAGE_SHIFT;
26284 + flags |= 8;
26285 + }
26286 +
26287 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26288 + gdt = get_cpu_gdt_table(cpu);
26289 + pack_descriptor(&d, address, length, 0x9b, flags);
26290 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26291 + pack_descriptor(&d, address, length, 0x93, flags);
26292 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26293 + }
26294 + return entry;
26295 + }
26296 + case 0x80: /* Not present */
26297 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26298 + return 0;
26299 + default: /* Shouldn't happen */
26300 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26301 + service, return_code);
26302 + return 0;
26303 }
26304 }
26305
26306 static struct {
26307 unsigned long address;
26308 unsigned short segment;
26309 -} pci_indirect = { 0, __KERNEL_CS };
26310 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26311
26312 -static int pci_bios_present;
26313 +static int pci_bios_present __read_only;
26314
26315 static int __devinit check_pcibios(void)
26316 {
26317 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
26318 unsigned long flags, pcibios_entry;
26319
26320 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26321 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26322 + pci_indirect.address = pcibios_entry;
26323
26324 local_irq_save(flags);
26325 - __asm__(
26326 - "lcall *(%%edi); cld\n\t"
26327 + __asm__("movw %w6, %%ds\n\t"
26328 + "lcall *%%ss:(%%edi); cld\n\t"
26329 + "push %%ss\n\t"
26330 + "pop %%ds\n\t"
26331 "jc 1f\n\t"
26332 "xor %%ah, %%ah\n"
26333 "1:"
26334 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
26335 "=b" (ebx),
26336 "=c" (ecx)
26337 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26338 - "D" (&pci_indirect)
26339 + "D" (&pci_indirect),
26340 + "r" (__PCIBIOS_DS)
26341 : "memory");
26342 local_irq_restore(flags);
26343
26344 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26345
26346 switch (len) {
26347 case 1:
26348 - __asm__("lcall *(%%esi); cld\n\t"
26349 + __asm__("movw %w6, %%ds\n\t"
26350 + "lcall *%%ss:(%%esi); cld\n\t"
26351 + "push %%ss\n\t"
26352 + "pop %%ds\n\t"
26353 "jc 1f\n\t"
26354 "xor %%ah, %%ah\n"
26355 "1:"
26356 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26357 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26358 "b" (bx),
26359 "D" ((long)reg),
26360 - "S" (&pci_indirect));
26361 + "S" (&pci_indirect),
26362 + "r" (__PCIBIOS_DS));
26363 /*
26364 * Zero-extend the result beyond 8 bits, do not trust the
26365 * BIOS having done it:
26366 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26367 *value &= 0xff;
26368 break;
26369 case 2:
26370 - __asm__("lcall *(%%esi); cld\n\t"
26371 + __asm__("movw %w6, %%ds\n\t"
26372 + "lcall *%%ss:(%%esi); cld\n\t"
26373 + "push %%ss\n\t"
26374 + "pop %%ds\n\t"
26375 "jc 1f\n\t"
26376 "xor %%ah, %%ah\n"
26377 "1:"
26378 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26379 : "1" (PCIBIOS_READ_CONFIG_WORD),
26380 "b" (bx),
26381 "D" ((long)reg),
26382 - "S" (&pci_indirect));
26383 + "S" (&pci_indirect),
26384 + "r" (__PCIBIOS_DS));
26385 /*
26386 * Zero-extend the result beyond 16 bits, do not trust the
26387 * BIOS having done it:
26388 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26389 *value &= 0xffff;
26390 break;
26391 case 4:
26392 - __asm__("lcall *(%%esi); cld\n\t"
26393 + __asm__("movw %w6, %%ds\n\t"
26394 + "lcall *%%ss:(%%esi); cld\n\t"
26395 + "push %%ss\n\t"
26396 + "pop %%ds\n\t"
26397 "jc 1f\n\t"
26398 "xor %%ah, %%ah\n"
26399 "1:"
26400 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26401 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26402 "b" (bx),
26403 "D" ((long)reg),
26404 - "S" (&pci_indirect));
26405 + "S" (&pci_indirect),
26406 + "r" (__PCIBIOS_DS));
26407 break;
26408 }
26409
26410 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26411
26412 switch (len) {
26413 case 1:
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 @@ -265,10 +326,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 2:
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 @@ -277,10 +342,14 @@ 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 case 4:
26448 - __asm__("lcall *(%%esi); cld\n\t"
26449 + __asm__("movw %w6, %%ds\n\t"
26450 + "lcall *%%ss:(%%esi); cld\n\t"
26451 + "push %%ss\n\t"
26452 + "pop %%ds\n\t"
26453 "jc 1f\n\t"
26454 "xor %%ah, %%ah\n"
26455 "1:"
26456 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26457 "c" (value),
26458 "b" (bx),
26459 "D" ((long)reg),
26460 - "S" (&pci_indirect));
26461 + "S" (&pci_indirect),
26462 + "r" (__PCIBIOS_DS));
26463 break;
26464 }
26465
26466 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26467
26468 DBG("PCI: Fetching IRQ routing table... ");
26469 __asm__("push %%es\n\t"
26470 + "movw %w8, %%ds\n\t"
26471 "push %%ds\n\t"
26472 "pop %%es\n\t"
26473 - "lcall *(%%esi); cld\n\t"
26474 + "lcall *%%ss:(%%esi); cld\n\t"
26475 "pop %%es\n\t"
26476 + "push %%ss\n\t"
26477 + "pop %%ds\n"
26478 "jc 1f\n\t"
26479 "xor %%ah, %%ah\n"
26480 "1:"
26481 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26482 "1" (0),
26483 "D" ((long) &opt),
26484 "S" (&pci_indirect),
26485 - "m" (opt)
26486 + "m" (opt),
26487 + "r" (__PCIBIOS_DS)
26488 : "memory");
26489 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26490 if (ret & 0xff00)
26491 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26492 {
26493 int ret;
26494
26495 - __asm__("lcall *(%%esi); cld\n\t"
26496 + __asm__("movw %w5, %%ds\n\t"
26497 + "lcall *%%ss:(%%esi); cld\n\t"
26498 + "push %%ss\n\t"
26499 + "pop %%ds\n"
26500 "jc 1f\n\t"
26501 "xor %%ah, %%ah\n"
26502 "1:"
26503 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26504 : "0" (PCIBIOS_SET_PCI_HW_INT),
26505 "b" ((dev->bus->number << 8) | dev->devfn),
26506 "c" ((irq << 8) | (pin + 10)),
26507 - "S" (&pci_indirect));
26508 + "S" (&pci_indirect),
26509 + "r" (__PCIBIOS_DS));
26510 return !(ret & 0xff00);
26511 }
26512 EXPORT_SYMBOL(pcibios_set_irq_routing);
26513 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26514 index 40e4469..1ab536e 100644
26515 --- a/arch/x86/platform/efi/efi_32.c
26516 +++ b/arch/x86/platform/efi/efi_32.c
26517 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26518 {
26519 struct desc_ptr gdt_descr;
26520
26521 +#ifdef CONFIG_PAX_KERNEXEC
26522 + struct desc_struct d;
26523 +#endif
26524 +
26525 local_irq_save(efi_rt_eflags);
26526
26527 load_cr3(initial_page_table);
26528 __flush_tlb_all();
26529
26530 +#ifdef CONFIG_PAX_KERNEXEC
26531 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26532 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26533 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26534 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26535 +#endif
26536 +
26537 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26538 gdt_descr.size = GDT_SIZE - 1;
26539 load_gdt(&gdt_descr);
26540 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26541 {
26542 struct desc_ptr gdt_descr;
26543
26544 +#ifdef CONFIG_PAX_KERNEXEC
26545 + struct desc_struct d;
26546 +
26547 + memset(&d, 0, sizeof d);
26548 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26549 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26550 +#endif
26551 +
26552 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26553 gdt_descr.size = GDT_SIZE - 1;
26554 load_gdt(&gdt_descr);
26555 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26556 index fbe66e6..eae5e38 100644
26557 --- a/arch/x86/platform/efi/efi_stub_32.S
26558 +++ b/arch/x86/platform/efi/efi_stub_32.S
26559 @@ -6,7 +6,9 @@
26560 */
26561
26562 #include <linux/linkage.h>
26563 +#include <linux/init.h>
26564 #include <asm/page_types.h>
26565 +#include <asm/segment.h>
26566
26567 /*
26568 * efi_call_phys(void *, ...) is a function with variable parameters.
26569 @@ -20,7 +22,7 @@
26570 * service functions will comply with gcc calling convention, too.
26571 */
26572
26573 -.text
26574 +__INIT
26575 ENTRY(efi_call_phys)
26576 /*
26577 * 0. The function can only be called in Linux kernel. So CS has been
26578 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
26579 * The mapping of lower virtual memory has been created in prelog and
26580 * epilog.
26581 */
26582 - movl $1f, %edx
26583 - subl $__PAGE_OFFSET, %edx
26584 - jmp *%edx
26585 +#ifdef CONFIG_PAX_KERNEXEC
26586 + movl $(__KERNEXEC_EFI_DS), %edx
26587 + mov %edx, %ds
26588 + mov %edx, %es
26589 + mov %edx, %ss
26590 + addl $2f,(1f)
26591 + ljmp *(1f)
26592 +
26593 +__INITDATA
26594 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
26595 +.previous
26596 +
26597 +2:
26598 + subl $2b,(1b)
26599 +#else
26600 + jmp 1f-__PAGE_OFFSET
26601 1:
26602 +#endif
26603
26604 /*
26605 * 2. Now on the top of stack is the return
26606 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
26607 * parameter 2, ..., param n. To make things easy, we save the return
26608 * address of efi_call_phys in a global variable.
26609 */
26610 - popl %edx
26611 - movl %edx, saved_return_addr
26612 - /* get the function pointer into ECX*/
26613 - popl %ecx
26614 - movl %ecx, efi_rt_function_ptr
26615 - movl $2f, %edx
26616 - subl $__PAGE_OFFSET, %edx
26617 - pushl %edx
26618 + popl (saved_return_addr)
26619 + popl (efi_rt_function_ptr)
26620
26621 /*
26622 * 3. Clear PG bit in %CR0.
26623 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
26624 /*
26625 * 5. Call the physical function.
26626 */
26627 - jmp *%ecx
26628 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
26629
26630 -2:
26631 /*
26632 * 6. After EFI runtime service returns, control will return to
26633 * following instruction. We'd better readjust stack pointer first.
26634 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
26635 movl %cr0, %edx
26636 orl $0x80000000, %edx
26637 movl %edx, %cr0
26638 - jmp 1f
26639 -1:
26640 +
26641 /*
26642 * 8. Now restore the virtual mode from flat mode by
26643 * adding EIP with PAGE_OFFSET.
26644 */
26645 - movl $1f, %edx
26646 - jmp *%edx
26647 +#ifdef CONFIG_PAX_KERNEXEC
26648 + movl $(__KERNEL_DS), %edx
26649 + mov %edx, %ds
26650 + mov %edx, %es
26651 + mov %edx, %ss
26652 + ljmp $(__KERNEL_CS),$1f
26653 +#else
26654 + jmp 1f+__PAGE_OFFSET
26655 +#endif
26656 1:
26657
26658 /*
26659 * 9. Balance the stack. And because EAX contain the return value,
26660 * we'd better not clobber it.
26661 */
26662 - leal efi_rt_function_ptr, %edx
26663 - movl (%edx), %ecx
26664 - pushl %ecx
26665 + pushl (efi_rt_function_ptr)
26666
26667 /*
26668 - * 10. Push the saved return address onto the stack and return.
26669 + * 10. Return to the saved return address.
26670 */
26671 - leal saved_return_addr, %edx
26672 - movl (%edx), %ecx
26673 - pushl %ecx
26674 - ret
26675 + jmpl *(saved_return_addr)
26676 ENDPROC(efi_call_phys)
26677 .previous
26678
26679 -.data
26680 +__INITDATA
26681 saved_return_addr:
26682 .long 0
26683 efi_rt_function_ptr:
26684 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
26685 index 4c07cca..2c8427d 100644
26686 --- a/arch/x86/platform/efi/efi_stub_64.S
26687 +++ b/arch/x86/platform/efi/efi_stub_64.S
26688 @@ -7,6 +7,7 @@
26689 */
26690
26691 #include <linux/linkage.h>
26692 +#include <asm/alternative-asm.h>
26693
26694 #define SAVE_XMM \
26695 mov %rsp, %rax; \
26696 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
26697 call *%rdi
26698 addq $32, %rsp
26699 RESTORE_XMM
26700 + pax_force_retaddr 0, 1
26701 ret
26702 ENDPROC(efi_call0)
26703
26704 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
26705 call *%rdi
26706 addq $32, %rsp
26707 RESTORE_XMM
26708 + pax_force_retaddr 0, 1
26709 ret
26710 ENDPROC(efi_call1)
26711
26712 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
26713 call *%rdi
26714 addq $32, %rsp
26715 RESTORE_XMM
26716 + pax_force_retaddr 0, 1
26717 ret
26718 ENDPROC(efi_call2)
26719
26720 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
26721 call *%rdi
26722 addq $32, %rsp
26723 RESTORE_XMM
26724 + pax_force_retaddr 0, 1
26725 ret
26726 ENDPROC(efi_call3)
26727
26728 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
26729 call *%rdi
26730 addq $32, %rsp
26731 RESTORE_XMM
26732 + pax_force_retaddr 0, 1
26733 ret
26734 ENDPROC(efi_call4)
26735
26736 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
26737 call *%rdi
26738 addq $48, %rsp
26739 RESTORE_XMM
26740 + pax_force_retaddr 0, 1
26741 ret
26742 ENDPROC(efi_call5)
26743
26744 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
26745 call *%rdi
26746 addq $48, %rsp
26747 RESTORE_XMM
26748 + pax_force_retaddr 0, 1
26749 ret
26750 ENDPROC(efi_call6)
26751 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
26752 index fd41a92..9c33628 100644
26753 --- a/arch/x86/platform/mrst/mrst.c
26754 +++ b/arch/x86/platform/mrst/mrst.c
26755 @@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
26756 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
26757 int sfi_mrtc_num;
26758
26759 -static void mrst_power_off(void)
26760 +static __noreturn void mrst_power_off(void)
26761 {
26762 + BUG();
26763 }
26764
26765 -static void mrst_reboot(void)
26766 +static __noreturn void mrst_reboot(void)
26767 {
26768 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
26769 + BUG();
26770 }
26771
26772 /* parse all the mtimer info to a static mtimer array */
26773 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
26774 index 218cdb1..fd55c08 100644
26775 --- a/arch/x86/power/cpu.c
26776 +++ b/arch/x86/power/cpu.c
26777 @@ -132,7 +132,7 @@ static void do_fpu_end(void)
26778 static void fix_processor_context(void)
26779 {
26780 int cpu = smp_processor_id();
26781 - struct tss_struct *t = &per_cpu(init_tss, cpu);
26782 + struct tss_struct *t = init_tss + cpu;
26783
26784 set_tss_desc(cpu, t); /*
26785 * This just modifies memory; should not be
26786 @@ -142,7 +142,9 @@ static void fix_processor_context(void)
26787 */
26788
26789 #ifdef CONFIG_X86_64
26790 + pax_open_kernel();
26791 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
26792 + pax_close_kernel();
26793
26794 syscall_init(); /* This sets MSR_*STAR and related */
26795 #endif
26796 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
26797 index cbca565..bae7133 100644
26798 --- a/arch/x86/realmode/init.c
26799 +++ b/arch/x86/realmode/init.c
26800 @@ -62,7 +62,13 @@ void __init setup_real_mode(void)
26801 __va(real_mode_header->trampoline_header);
26802
26803 #ifdef CONFIG_X86_32
26804 - trampoline_header->start = __pa(startup_32_smp);
26805 + trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
26806 +
26807 +#ifdef CONFIG_PAX_KERNEXEC
26808 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
26809 +#endif
26810 +
26811 + trampoline_header->boot_cs = __BOOT_CS;
26812 trampoline_header->gdt_limit = __BOOT_DS + 7;
26813 trampoline_header->gdt_base = __pa(boot_gdt);
26814 #else
26815 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
26816 index 8869287..d577672 100644
26817 --- a/arch/x86/realmode/rm/Makefile
26818 +++ b/arch/x86/realmode/rm/Makefile
26819 @@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
26820 $(call cc-option, -fno-unit-at-a-time)) \
26821 $(call cc-option, -fno-stack-protector) \
26822 $(call cc-option, -mpreferred-stack-boundary=2)
26823 +ifdef CONSTIFY_PLUGIN
26824 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
26825 +endif
26826 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
26827 GCOV_PROFILE := n
26828 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
26829 index a28221d..93c40f1 100644
26830 --- a/arch/x86/realmode/rm/header.S
26831 +++ b/arch/x86/realmode/rm/header.S
26832 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
26833 #endif
26834 /* APM/BIOS reboot */
26835 .long pa_machine_real_restart_asm
26836 -#ifdef CONFIG_X86_64
26837 +#ifdef CONFIG_X86_32
26838 + .long __KERNEL_CS
26839 +#else
26840 .long __KERNEL32_CS
26841 #endif
26842 END(real_mode_header)
26843 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
26844 index c1b2791..f9e31c7 100644
26845 --- a/arch/x86/realmode/rm/trampoline_32.S
26846 +++ b/arch/x86/realmode/rm/trampoline_32.S
26847 @@ -25,6 +25,12 @@
26848 #include <asm/page_types.h>
26849 #include "realmode.h"
26850
26851 +#ifdef CONFIG_PAX_KERNEXEC
26852 +#define ta(X) (X)
26853 +#else
26854 +#define ta(X) (pa_ ## X)
26855 +#endif
26856 +
26857 .text
26858 .code16
26859
26860 @@ -39,8 +45,6 @@ ENTRY(trampoline_start)
26861
26862 cli # We should be safe anyway
26863
26864 - movl tr_start, %eax # where we need to go
26865 -
26866 movl $0xA5A5A5A5, trampoline_status
26867 # write marker for master knows we're running
26868
26869 @@ -56,7 +60,7 @@ ENTRY(trampoline_start)
26870 movw $1, %dx # protected mode (PE) bit
26871 lmsw %dx # into protected mode
26872
26873 - ljmpl $__BOOT_CS, $pa_startup_32
26874 + ljmpl *(trampoline_header)
26875
26876 .section ".text32","ax"
26877 .code32
26878 @@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
26879 .balign 8
26880 GLOBAL(trampoline_header)
26881 tr_start: .space 4
26882 - tr_gdt_pad: .space 2
26883 + tr_boot_cs: .space 2
26884 tr_gdt: .space 6
26885 END(trampoline_header)
26886
26887 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
26888 index bb360dc..3e5945f 100644
26889 --- a/arch/x86/realmode/rm/trampoline_64.S
26890 +++ b/arch/x86/realmode/rm/trampoline_64.S
26891 @@ -107,7 +107,7 @@ ENTRY(startup_32)
26892 wrmsr
26893
26894 # Enable paging and in turn activate Long Mode
26895 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
26896 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
26897 movl %eax, %cr0
26898
26899 /*
26900 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
26901 index 5a1847d..deccb30 100644
26902 --- a/arch/x86/tools/relocs.c
26903 +++ b/arch/x86/tools/relocs.c
26904 @@ -12,10 +12,13 @@
26905 #include <regex.h>
26906 #include <tools/le_byteshift.h>
26907
26908 +#include "../../../include/generated/autoconf.h"
26909 +
26910 static void die(char *fmt, ...);
26911
26912 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
26913 static Elf32_Ehdr ehdr;
26914 +static Elf32_Phdr *phdr;
26915 static unsigned long reloc_count, reloc_idx;
26916 static unsigned long *relocs;
26917 static unsigned long reloc16_count, reloc16_idx;
26918 @@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
26919 }
26920 }
26921
26922 +static void read_phdrs(FILE *fp)
26923 +{
26924 + unsigned int i;
26925 +
26926 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
26927 + if (!phdr) {
26928 + die("Unable to allocate %d program headers\n",
26929 + ehdr.e_phnum);
26930 + }
26931 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
26932 + die("Seek to %d failed: %s\n",
26933 + ehdr.e_phoff, strerror(errno));
26934 + }
26935 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
26936 + die("Cannot read ELF program headers: %s\n",
26937 + strerror(errno));
26938 + }
26939 + for(i = 0; i < ehdr.e_phnum; i++) {
26940 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
26941 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
26942 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
26943 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
26944 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
26945 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
26946 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
26947 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
26948 + }
26949 +
26950 +}
26951 +
26952 static void read_shdrs(FILE *fp)
26953 {
26954 - int i;
26955 + unsigned int i;
26956 Elf32_Shdr shdr;
26957
26958 secs = calloc(ehdr.e_shnum, sizeof(struct section));
26959 @@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
26960
26961 static void read_strtabs(FILE *fp)
26962 {
26963 - int i;
26964 + unsigned int i;
26965 for (i = 0; i < ehdr.e_shnum; i++) {
26966 struct section *sec = &secs[i];
26967 if (sec->shdr.sh_type != SHT_STRTAB) {
26968 @@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
26969
26970 static void read_symtabs(FILE *fp)
26971 {
26972 - int i,j;
26973 + unsigned int i,j;
26974 for (i = 0; i < ehdr.e_shnum; i++) {
26975 struct section *sec = &secs[i];
26976 if (sec->shdr.sh_type != SHT_SYMTAB) {
26977 @@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
26978 }
26979
26980
26981 -static void read_relocs(FILE *fp)
26982 +static void read_relocs(FILE *fp, int use_real_mode)
26983 {
26984 - int i,j;
26985 + unsigned int i,j;
26986 + uint32_t base;
26987 +
26988 for (i = 0; i < ehdr.e_shnum; i++) {
26989 struct section *sec = &secs[i];
26990 if (sec->shdr.sh_type != SHT_REL) {
26991 @@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
26992 die("Cannot read symbol table: %s\n",
26993 strerror(errno));
26994 }
26995 + base = 0;
26996 +
26997 +#ifdef CONFIG_X86_32
26998 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
26999 + if (phdr[j].p_type != PT_LOAD )
27000 + continue;
27001 + 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)
27002 + continue;
27003 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
27004 + break;
27005 + }
27006 +#endif
27007 +
27008 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
27009 Elf32_Rel *rel = &sec->reltab[j];
27010 - rel->r_offset = elf32_to_cpu(rel->r_offset);
27011 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
27012 rel->r_info = elf32_to_cpu(rel->r_info);
27013 }
27014 }
27015 @@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
27016
27017 static void print_absolute_symbols(void)
27018 {
27019 - int i;
27020 + unsigned int i;
27021 printf("Absolute symbols\n");
27022 printf(" Num: Value Size Type Bind Visibility Name\n");
27023 for (i = 0; i < ehdr.e_shnum; i++) {
27024 struct section *sec = &secs[i];
27025 char *sym_strtab;
27026 - int j;
27027 + unsigned int j;
27028
27029 if (sec->shdr.sh_type != SHT_SYMTAB) {
27030 continue;
27031 @@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
27032
27033 static void print_absolute_relocs(void)
27034 {
27035 - int i, printed = 0;
27036 + unsigned int i, printed = 0;
27037
27038 for (i = 0; i < ehdr.e_shnum; i++) {
27039 struct section *sec = &secs[i];
27040 struct section *sec_applies, *sec_symtab;
27041 char *sym_strtab;
27042 Elf32_Sym *sh_symtab;
27043 - int j;
27044 + unsigned int j;
27045 if (sec->shdr.sh_type != SHT_REL) {
27046 continue;
27047 }
27048 @@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
27049 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
27050 int use_real_mode)
27051 {
27052 - int i;
27053 + unsigned int i;
27054 /* Walk through the relocations */
27055 for (i = 0; i < ehdr.e_shnum; i++) {
27056 char *sym_strtab;
27057 Elf32_Sym *sh_symtab;
27058 struct section *sec_applies, *sec_symtab;
27059 - int j;
27060 + unsigned int j;
27061 struct section *sec = &secs[i];
27062
27063 if (sec->shdr.sh_type != SHT_REL) {
27064 @@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
27065 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
27066 r_type = ELF32_R_TYPE(rel->r_info);
27067
27068 + if (!use_real_mode) {
27069 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
27070 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
27071 + continue;
27072 +
27073 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
27074 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
27075 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
27076 + continue;
27077 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
27078 + continue;
27079 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
27080 + continue;
27081 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
27082 + continue;
27083 +#endif
27084 + }
27085 +
27086 shn_abs = sym->st_shndx == SHN_ABS;
27087
27088 switch (r_type) {
27089 @@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
27090
27091 static void emit_relocs(int as_text, int use_real_mode)
27092 {
27093 - int i;
27094 + unsigned int i;
27095 /* Count how many relocations I have and allocate space for them. */
27096 reloc_count = 0;
27097 walk_relocs(count_reloc, use_real_mode);
27098 @@ -808,10 +874,11 @@ int main(int argc, char **argv)
27099 fname, strerror(errno));
27100 }
27101 read_ehdr(fp);
27102 + read_phdrs(fp);
27103 read_shdrs(fp);
27104 read_strtabs(fp);
27105 read_symtabs(fp);
27106 - read_relocs(fp);
27107 + read_relocs(fp, use_real_mode);
27108 if (show_absolute_syms) {
27109 print_absolute_symbols();
27110 return 0;
27111 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
27112 index fd14be1..e3c79c0 100644
27113 --- a/arch/x86/vdso/Makefile
27114 +++ b/arch/x86/vdso/Makefile
27115 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
27116 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
27117 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
27118
27119 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27120 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27121 GCOV_PROFILE := n
27122
27123 #
27124 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
27125 index 0faad64..39ef157 100644
27126 --- a/arch/x86/vdso/vdso32-setup.c
27127 +++ b/arch/x86/vdso/vdso32-setup.c
27128 @@ -25,6 +25,7 @@
27129 #include <asm/tlbflush.h>
27130 #include <asm/vdso.h>
27131 #include <asm/proto.h>
27132 +#include <asm/mman.h>
27133
27134 enum {
27135 VDSO_DISABLED = 0,
27136 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
27137 void enable_sep_cpu(void)
27138 {
27139 int cpu = get_cpu();
27140 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
27141 + struct tss_struct *tss = init_tss + cpu;
27142
27143 if (!boot_cpu_has(X86_FEATURE_SEP)) {
27144 put_cpu();
27145 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
27146 gate_vma.vm_start = FIXADDR_USER_START;
27147 gate_vma.vm_end = FIXADDR_USER_END;
27148 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
27149 - gate_vma.vm_page_prot = __P101;
27150 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
27151
27152 return 0;
27153 }
27154 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27155 if (compat)
27156 addr = VDSO_HIGH_BASE;
27157 else {
27158 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
27159 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
27160 if (IS_ERR_VALUE(addr)) {
27161 ret = addr;
27162 goto up_fail;
27163 }
27164 }
27165
27166 - current->mm->context.vdso = (void *)addr;
27167 + current->mm->context.vdso = addr;
27168
27169 if (compat_uses_vma || !compat) {
27170 /*
27171 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27172 }
27173
27174 current_thread_info()->sysenter_return =
27175 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27176 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27177
27178 up_fail:
27179 if (ret)
27180 - current->mm->context.vdso = NULL;
27181 + current->mm->context.vdso = 0;
27182
27183 up_write(&mm->mmap_sem);
27184
27185 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
27186
27187 const char *arch_vma_name(struct vm_area_struct *vma)
27188 {
27189 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
27190 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
27191 return "[vdso]";
27192 +
27193 +#ifdef CONFIG_PAX_SEGMEXEC
27194 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
27195 + return "[vdso]";
27196 +#endif
27197 +
27198 return NULL;
27199 }
27200
27201 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
27202 * Check to see if the corresponding task was created in compat vdso
27203 * mode.
27204 */
27205 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
27206 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
27207 return &gate_vma;
27208 return NULL;
27209 }
27210 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
27211 index 00aaf04..4a26505 100644
27212 --- a/arch/x86/vdso/vma.c
27213 +++ b/arch/x86/vdso/vma.c
27214 @@ -16,8 +16,6 @@
27215 #include <asm/vdso.h>
27216 #include <asm/page.h>
27217
27218 -unsigned int __read_mostly vdso_enabled = 1;
27219 -
27220 extern char vdso_start[], vdso_end[];
27221 extern unsigned short vdso_sync_cpuid;
27222
27223 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
27224 * unaligned here as a result of stack start randomization.
27225 */
27226 addr = PAGE_ALIGN(addr);
27227 - addr = align_addr(addr, NULL, ALIGN_VDSO);
27228
27229 return addr;
27230 }
27231 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
27232 unsigned size)
27233 {
27234 struct mm_struct *mm = current->mm;
27235 - unsigned long addr;
27236 + unsigned long addr = 0;
27237 int ret;
27238
27239 - if (!vdso_enabled)
27240 - return 0;
27241 -
27242 down_write(&mm->mmap_sem);
27243 +
27244 +#ifdef CONFIG_PAX_RANDMMAP
27245 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27246 +#endif
27247 +
27248 addr = vdso_addr(mm->start_stack, size);
27249 + addr = align_addr(addr, NULL, ALIGN_VDSO);
27250 addr = get_unmapped_area(NULL, addr, size, 0, 0);
27251 if (IS_ERR_VALUE(addr)) {
27252 ret = addr;
27253 goto up_fail;
27254 }
27255
27256 - current->mm->context.vdso = (void *)addr;
27257 + mm->context.vdso = addr;
27258
27259 ret = install_special_mapping(mm, addr, size,
27260 VM_READ|VM_EXEC|
27261 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
27262 pages);
27263 - if (ret) {
27264 - current->mm->context.vdso = NULL;
27265 - goto up_fail;
27266 - }
27267 + if (ret)
27268 + mm->context.vdso = 0;
27269
27270 up_fail:
27271 up_write(&mm->mmap_sem);
27272 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27273 vdsox32_size);
27274 }
27275 #endif
27276 -
27277 -static __init int vdso_setup(char *s)
27278 -{
27279 - vdso_enabled = simple_strtoul(s, NULL, 0);
27280 - return 0;
27281 -}
27282 -__setup("vdso=", vdso_setup);
27283 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
27284 index c1461de..355f120 100644
27285 --- a/arch/x86/xen/enlighten.c
27286 +++ b/arch/x86/xen/enlighten.c
27287 @@ -98,8 +98,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
27288
27289 struct shared_info xen_dummy_shared_info;
27290
27291 -void *xen_initial_gdt;
27292 -
27293 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
27294 __read_mostly int xen_have_vector_callback;
27295 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
27296 @@ -917,21 +915,21 @@ static u32 xen_safe_apic_wait_icr_idle(void)
27297
27298 static void set_xen_basic_apic_ops(void)
27299 {
27300 - apic->read = xen_apic_read;
27301 - apic->write = xen_apic_write;
27302 - apic->icr_read = xen_apic_icr_read;
27303 - apic->icr_write = xen_apic_icr_write;
27304 - apic->wait_icr_idle = xen_apic_wait_icr_idle;
27305 - apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
27306 - apic->set_apic_id = xen_set_apic_id;
27307 - apic->get_apic_id = xen_get_apic_id;
27308 + *(void **)&apic->read = xen_apic_read;
27309 + *(void **)&apic->write = xen_apic_write;
27310 + *(void **)&apic->icr_read = xen_apic_icr_read;
27311 + *(void **)&apic->icr_write = xen_apic_icr_write;
27312 + *(void **)&apic->wait_icr_idle = xen_apic_wait_icr_idle;
27313 + *(void **)&apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
27314 + *(void **)&apic->set_apic_id = xen_set_apic_id;
27315 + *(void **)&apic->get_apic_id = xen_get_apic_id;
27316
27317 #ifdef CONFIG_SMP
27318 - apic->send_IPI_allbutself = xen_send_IPI_allbutself;
27319 - apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
27320 - apic->send_IPI_mask = xen_send_IPI_mask;
27321 - apic->send_IPI_all = xen_send_IPI_all;
27322 - apic->send_IPI_self = xen_send_IPI_self;
27323 + *(void **)&apic->send_IPI_allbutself = xen_send_IPI_allbutself;
27324 + *(void **)&apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
27325 + *(void **)&apic->send_IPI_mask = xen_send_IPI_mask;
27326 + *(void **)&apic->send_IPI_all = xen_send_IPI_all;
27327 + *(void **)&apic->send_IPI_self = xen_send_IPI_self;
27328 #endif
27329 }
27330
27331 @@ -1221,30 +1219,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
27332 #endif
27333 };
27334
27335 -static void xen_reboot(int reason)
27336 +static __noreturn void xen_reboot(int reason)
27337 {
27338 struct sched_shutdown r = { .reason = reason };
27339
27340 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
27341 - BUG();
27342 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
27343 + BUG();
27344 }
27345
27346 -static void xen_restart(char *msg)
27347 +static __noreturn void xen_restart(char *msg)
27348 {
27349 xen_reboot(SHUTDOWN_reboot);
27350 }
27351
27352 -static void xen_emergency_restart(void)
27353 +static __noreturn void xen_emergency_restart(void)
27354 {
27355 xen_reboot(SHUTDOWN_reboot);
27356 }
27357
27358 -static void xen_machine_halt(void)
27359 +static __noreturn void xen_machine_halt(void)
27360 {
27361 xen_reboot(SHUTDOWN_poweroff);
27362 }
27363
27364 -static void xen_machine_power_off(void)
27365 +static __noreturn void xen_machine_power_off(void)
27366 {
27367 if (pm_power_off)
27368 pm_power_off();
27369 @@ -1347,7 +1345,17 @@ asmlinkage void __init xen_start_kernel(void)
27370 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
27371
27372 /* Work out if we support NX */
27373 - x86_configure_nx();
27374 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27375 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
27376 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
27377 + unsigned l, h;
27378 +
27379 + __supported_pte_mask |= _PAGE_NX;
27380 + rdmsr(MSR_EFER, l, h);
27381 + l |= EFER_NX;
27382 + wrmsr(MSR_EFER, l, h);
27383 + }
27384 +#endif
27385
27386 xen_setup_features();
27387
27388 @@ -1378,13 +1386,6 @@ asmlinkage void __init xen_start_kernel(void)
27389
27390 machine_ops = xen_machine_ops;
27391
27392 - /*
27393 - * The only reliable way to retain the initial address of the
27394 - * percpu gdt_page is to remember it here, so we can go and
27395 - * mark it RW later, when the initial percpu area is freed.
27396 - */
27397 - xen_initial_gdt = &per_cpu(gdt_page, 0);
27398 -
27399 xen_smp_init();
27400
27401 #ifdef CONFIG_ACPI_NUMA
27402 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
27403 index 5141d80..6c9fb41 100644
27404 --- a/arch/x86/xen/mmu.c
27405 +++ b/arch/x86/xen/mmu.c
27406 @@ -1765,6 +1765,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27407 convert_pfn_mfn(init_level4_pgt);
27408 convert_pfn_mfn(level3_ident_pgt);
27409 convert_pfn_mfn(level3_kernel_pgt);
27410 + convert_pfn_mfn(level3_vmalloc_start_pgt);
27411 + convert_pfn_mfn(level3_vmalloc_end_pgt);
27412 + convert_pfn_mfn(level3_vmemmap_pgt);
27413
27414 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
27415 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
27416 @@ -1783,7 +1786,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27417 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
27418 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
27419 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
27420 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
27421 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
27422 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
27423 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
27424 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
27425 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
27426 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
27427
27428 @@ -1967,6 +1974,7 @@ static void __init xen_post_allocator_init(void)
27429 pv_mmu_ops.set_pud = xen_set_pud;
27430 #if PAGETABLE_LEVELS == 4
27431 pv_mmu_ops.set_pgd = xen_set_pgd;
27432 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
27433 #endif
27434
27435 /* This will work as long as patching hasn't happened yet
27436 @@ -2048,6 +2056,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
27437 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
27438 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
27439 .set_pgd = xen_set_pgd_hyper,
27440 + .set_pgd_batched = xen_set_pgd_hyper,
27441
27442 .alloc_pud = xen_alloc_pmd_init,
27443 .release_pud = xen_release_pmd_init,
27444 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
27445 index f58dca7..ad21f52 100644
27446 --- a/arch/x86/xen/smp.c
27447 +++ b/arch/x86/xen/smp.c
27448 @@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
27449 {
27450 BUG_ON(smp_processor_id() != 0);
27451 native_smp_prepare_boot_cpu();
27452 -
27453 - /* We've switched to the "real" per-cpu gdt, so make sure the
27454 - old memory can be recycled */
27455 - make_lowmem_page_readwrite(xen_initial_gdt);
27456 -
27457 xen_filter_cpu_maps();
27458 xen_setup_vcpu_info_placement();
27459 }
27460 @@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
27461 gdt = get_cpu_gdt_table(cpu);
27462
27463 ctxt->flags = VGCF_IN_KERNEL;
27464 - ctxt->user_regs.ds = __USER_DS;
27465 - ctxt->user_regs.es = __USER_DS;
27466 + ctxt->user_regs.ds = __KERNEL_DS;
27467 + ctxt->user_regs.es = __KERNEL_DS;
27468 ctxt->user_regs.ss = __KERNEL_DS;
27469 #ifdef CONFIG_X86_32
27470 ctxt->user_regs.fs = __KERNEL_PERCPU;
27471 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
27472 + savesegment(gs, ctxt->user_regs.gs);
27473 #else
27474 ctxt->gs_base_kernel = per_cpu_offset(cpu);
27475 #endif
27476 @@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
27477 int rc;
27478
27479 per_cpu(current_task, cpu) = idle;
27480 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
27481 #ifdef CONFIG_X86_32
27482 irq_ctx_init(cpu);
27483 #else
27484 clear_tsk_thread_flag(idle, TIF_FORK);
27485 - per_cpu(kernel_stack, cpu) =
27486 - (unsigned long)task_stack_page(idle) -
27487 - KERNEL_STACK_OFFSET + THREAD_SIZE;
27488 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27489 #endif
27490 xen_setup_runstate_info(cpu);
27491 xen_setup_timer(cpu);
27492 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
27493 index f9643fc..602e8af 100644
27494 --- a/arch/x86/xen/xen-asm_32.S
27495 +++ b/arch/x86/xen/xen-asm_32.S
27496 @@ -84,14 +84,14 @@ ENTRY(xen_iret)
27497 ESP_OFFSET=4 # bytes pushed onto stack
27498
27499 /*
27500 - * Store vcpu_info pointer for easy access. Do it this way to
27501 - * avoid having to reload %fs
27502 + * Store vcpu_info pointer for easy access.
27503 */
27504 #ifdef CONFIG_SMP
27505 - GET_THREAD_INFO(%eax)
27506 - movl TI_cpu(%eax), %eax
27507 - movl __per_cpu_offset(,%eax,4), %eax
27508 - mov xen_vcpu(%eax), %eax
27509 + push %fs
27510 + mov $(__KERNEL_PERCPU), %eax
27511 + mov %eax, %fs
27512 + mov PER_CPU_VAR(xen_vcpu), %eax
27513 + pop %fs
27514 #else
27515 movl xen_vcpu, %eax
27516 #endif
27517 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27518 index aaa7291..3f77960 100644
27519 --- a/arch/x86/xen/xen-head.S
27520 +++ b/arch/x86/xen/xen-head.S
27521 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
27522 #ifdef CONFIG_X86_32
27523 mov %esi,xen_start_info
27524 mov $init_thread_union+THREAD_SIZE,%esp
27525 +#ifdef CONFIG_SMP
27526 + movl $cpu_gdt_table,%edi
27527 + movl $__per_cpu_load,%eax
27528 + movw %ax,__KERNEL_PERCPU + 2(%edi)
27529 + rorl $16,%eax
27530 + movb %al,__KERNEL_PERCPU + 4(%edi)
27531 + movb %ah,__KERNEL_PERCPU + 7(%edi)
27532 + movl $__per_cpu_end - 1,%eax
27533 + subl $__per_cpu_start,%eax
27534 + movw %ax,__KERNEL_PERCPU + 0(%edi)
27535 +#endif
27536 #else
27537 mov %rsi,xen_start_info
27538 mov $init_thread_union+THREAD_SIZE,%rsp
27539 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27540 index 202d4c1..99b072a 100644
27541 --- a/arch/x86/xen/xen-ops.h
27542 +++ b/arch/x86/xen/xen-ops.h
27543 @@ -10,8 +10,6 @@
27544 extern const char xen_hypervisor_callback[];
27545 extern const char xen_failsafe_callback[];
27546
27547 -extern void *xen_initial_gdt;
27548 -
27549 struct trap_info;
27550 void xen_copy_trap_info(struct trap_info *traps);
27551
27552 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
27553 index 525bd3d..ef888b1 100644
27554 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
27555 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
27556 @@ -119,9 +119,9 @@
27557 ----------------------------------------------------------------------*/
27558
27559 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
27560 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
27561 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
27562 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
27563 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27564
27565 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
27566 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
27567 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
27568 index 2f33760..835e50a 100644
27569 --- a/arch/xtensa/variants/fsf/include/variant/core.h
27570 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
27571 @@ -11,6 +11,7 @@
27572 #ifndef _XTENSA_CORE_H
27573 #define _XTENSA_CORE_H
27574
27575 +#include <linux/const.h>
27576
27577 /****************************************************************************
27578 Parameters Useful for Any Code, USER or PRIVILEGED
27579 @@ -112,9 +113,9 @@
27580 ----------------------------------------------------------------------*/
27581
27582 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27583 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27584 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27585 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27586 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27587
27588 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
27589 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
27590 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
27591 index af00795..2bb8105 100644
27592 --- a/arch/xtensa/variants/s6000/include/variant/core.h
27593 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
27594 @@ -11,6 +11,7 @@
27595 #ifndef _XTENSA_CORE_CONFIGURATION_H
27596 #define _XTENSA_CORE_CONFIGURATION_H
27597
27598 +#include <linux/const.h>
27599
27600 /****************************************************************************
27601 Parameters Useful for Any Code, USER or PRIVILEGED
27602 @@ -118,9 +119,9 @@
27603 ----------------------------------------------------------------------*/
27604
27605 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27606 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27607 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27608 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27609 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27610
27611 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
27612 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
27613 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27614 index 58916af..9cb880b 100644
27615 --- a/block/blk-iopoll.c
27616 +++ b/block/blk-iopoll.c
27617 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27618 }
27619 EXPORT_SYMBOL(blk_iopoll_complete);
27620
27621 -static void blk_iopoll_softirq(struct softirq_action *h)
27622 +static void blk_iopoll_softirq(void)
27623 {
27624 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27625 int rearm = 0, budget = blk_iopoll_budget;
27626 diff --git a/block/blk-map.c b/block/blk-map.c
27627 index 623e1cd..ca1e109 100644
27628 --- a/block/blk-map.c
27629 +++ b/block/blk-map.c
27630 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27631 if (!len || !kbuf)
27632 return -EINVAL;
27633
27634 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
27635 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
27636 if (do_copy)
27637 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27638 else
27639 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27640 index 467c8de..4bddc6d 100644
27641 --- a/block/blk-softirq.c
27642 +++ b/block/blk-softirq.c
27643 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27644 * Softirq action handler - move entries to local list and loop over them
27645 * while passing them to the queue registered handler.
27646 */
27647 -static void blk_done_softirq(struct softirq_action *h)
27648 +static void blk_done_softirq(void)
27649 {
27650 struct list_head *cpu_list, local_list;
27651
27652 diff --git a/block/bsg.c b/block/bsg.c
27653 index ff64ae3..593560c 100644
27654 --- a/block/bsg.c
27655 +++ b/block/bsg.c
27656 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
27657 struct sg_io_v4 *hdr, struct bsg_device *bd,
27658 fmode_t has_write_perm)
27659 {
27660 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27661 + unsigned char *cmdptr;
27662 +
27663 if (hdr->request_len > BLK_MAX_CDB) {
27664 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27665 if (!rq->cmd)
27666 return -ENOMEM;
27667 - }
27668 + cmdptr = rq->cmd;
27669 + } else
27670 + cmdptr = tmpcmd;
27671
27672 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
27673 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27674 hdr->request_len))
27675 return -EFAULT;
27676
27677 + if (cmdptr != rq->cmd)
27678 + memcpy(rq->cmd, cmdptr, hdr->request_len);
27679 +
27680 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27681 if (blk_verify_command(rq->cmd, has_write_perm))
27682 return -EPERM;
27683 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27684 index 7c668c8..db3521c 100644
27685 --- a/block/compat_ioctl.c
27686 +++ b/block/compat_ioctl.c
27687 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27688 err |= __get_user(f->spec1, &uf->spec1);
27689 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27690 err |= __get_user(name, &uf->name);
27691 - f->name = compat_ptr(name);
27692 + f->name = (void __force_kernel *)compat_ptr(name);
27693 if (err) {
27694 err = -EFAULT;
27695 goto out;
27696 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
27697 index 6296b40..417c00f 100644
27698 --- a/block/partitions/efi.c
27699 +++ b/block/partitions/efi.c
27700 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
27701 if (!gpt)
27702 return NULL;
27703
27704 + if (!le32_to_cpu(gpt->num_partition_entries))
27705 + return NULL;
27706 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
27707 + if (!pte)
27708 + return NULL;
27709 +
27710 count = le32_to_cpu(gpt->num_partition_entries) *
27711 le32_to_cpu(gpt->sizeof_partition_entry);
27712 - if (!count)
27713 - return NULL;
27714 - pte = kzalloc(count, GFP_KERNEL);
27715 - if (!pte)
27716 - return NULL;
27717 -
27718 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
27719 (u8 *) pte,
27720 count) < count) {
27721 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27722 index 9a87daa..fb17486 100644
27723 --- a/block/scsi_ioctl.c
27724 +++ b/block/scsi_ioctl.c
27725 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
27726 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27727 struct sg_io_hdr *hdr, fmode_t mode)
27728 {
27729 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27730 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27731 + unsigned char *cmdptr;
27732 +
27733 + if (rq->cmd != rq->__cmd)
27734 + cmdptr = rq->cmd;
27735 + else
27736 + cmdptr = tmpcmd;
27737 +
27738 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27739 return -EFAULT;
27740 +
27741 + if (cmdptr != rq->cmd)
27742 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27743 +
27744 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27745 return -EPERM;
27746
27747 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27748 int err;
27749 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27750 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27751 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27752 + unsigned char *cmdptr;
27753
27754 if (!sic)
27755 return -EINVAL;
27756 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27757 */
27758 err = -EFAULT;
27759 rq->cmd_len = cmdlen;
27760 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
27761 +
27762 + if (rq->cmd != rq->__cmd)
27763 + cmdptr = rq->cmd;
27764 + else
27765 + cmdptr = tmpcmd;
27766 +
27767 + if (copy_from_user(cmdptr, sic->data, cmdlen))
27768 goto error;
27769
27770 + if (rq->cmd != cmdptr)
27771 + memcpy(rq->cmd, cmdptr, cmdlen);
27772 +
27773 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
27774 goto error;
27775
27776 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
27777 index 671d4d6..5f24030 100644
27778 --- a/crypto/cryptd.c
27779 +++ b/crypto/cryptd.c
27780 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
27781
27782 struct cryptd_blkcipher_request_ctx {
27783 crypto_completion_t complete;
27784 -};
27785 +} __no_const;
27786
27787 struct cryptd_hash_ctx {
27788 struct crypto_shash *child;
27789 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
27790
27791 struct cryptd_aead_request_ctx {
27792 crypto_completion_t complete;
27793 -};
27794 +} __no_const;
27795
27796 static void cryptd_queue_worker(struct work_struct *work);
27797
27798 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
27799 index e6defd8..c26a225 100644
27800 --- a/drivers/acpi/apei/cper.c
27801 +++ b/drivers/acpi/apei/cper.c
27802 @@ -38,12 +38,12 @@
27803 */
27804 u64 cper_next_record_id(void)
27805 {
27806 - static atomic64_t seq;
27807 + static atomic64_unchecked_t seq;
27808
27809 - if (!atomic64_read(&seq))
27810 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
27811 + if (!atomic64_read_unchecked(&seq))
27812 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
27813
27814 - return atomic64_inc_return(&seq);
27815 + return atomic64_inc_return_unchecked(&seq);
27816 }
27817 EXPORT_SYMBOL_GPL(cper_next_record_id);
27818
27819 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
27820 index 7586544..636a2f0 100644
27821 --- a/drivers/acpi/ec_sys.c
27822 +++ b/drivers/acpi/ec_sys.c
27823 @@ -12,6 +12,7 @@
27824 #include <linux/acpi.h>
27825 #include <linux/debugfs.h>
27826 #include <linux/module.h>
27827 +#include <linux/uaccess.h>
27828 #include "internal.h"
27829
27830 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
27831 @@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27832 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
27833 */
27834 unsigned int size = EC_SPACE_SIZE;
27835 - u8 *data = (u8 *) buf;
27836 + u8 data;
27837 loff_t init_off = *off;
27838 int err = 0;
27839
27840 @@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27841 size = count;
27842
27843 while (size) {
27844 - err = ec_read(*off, &data[*off - init_off]);
27845 + err = ec_read(*off, &data);
27846 if (err)
27847 return err;
27848 + if (put_user(data, &buf[*off - init_off]))
27849 + return -EFAULT;
27850 *off += 1;
27851 size--;
27852 }
27853 @@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27854
27855 unsigned int size = count;
27856 loff_t init_off = *off;
27857 - u8 *data = (u8 *) buf;
27858 int err = 0;
27859
27860 if (*off >= EC_SPACE_SIZE)
27861 @@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27862 }
27863
27864 while (size) {
27865 - u8 byte_write = data[*off - init_off];
27866 + u8 byte_write;
27867 + if (get_user(byte_write, &buf[*off - init_off]))
27868 + return -EFAULT;
27869 err = ec_write(*off, byte_write);
27870 if (err)
27871 return err;
27872 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
27873 index 251c7b62..000462d 100644
27874 --- a/drivers/acpi/proc.c
27875 +++ b/drivers/acpi/proc.c
27876 @@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
27877 size_t count, loff_t * ppos)
27878 {
27879 struct list_head *node, *next;
27880 - char strbuf[5];
27881 - char str[5] = "";
27882 - unsigned int len = count;
27883 + char strbuf[5] = {0};
27884
27885 - if (len > 4)
27886 - len = 4;
27887 - if (len < 0)
27888 + if (count > 4)
27889 + count = 4;
27890 + if (copy_from_user(strbuf, buffer, count))
27891 return -EFAULT;
27892 -
27893 - if (copy_from_user(strbuf, buffer, len))
27894 - return -EFAULT;
27895 - strbuf[len] = '\0';
27896 - sscanf(strbuf, "%s", str);
27897 + strbuf[count] = '\0';
27898
27899 mutex_lock(&acpi_device_lock);
27900 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
27901 @@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
27902 if (!dev->wakeup.flags.valid)
27903 continue;
27904
27905 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
27906 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
27907 if (device_can_wakeup(&dev->dev)) {
27908 bool enable = !device_may_wakeup(&dev->dev);
27909 device_set_wakeup_enable(&dev->dev, enable);
27910 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
27911 index bfc31cb..8213ce1 100644
27912 --- a/drivers/acpi/processor_driver.c
27913 +++ b/drivers/acpi/processor_driver.c
27914 @@ -551,7 +551,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
27915 return 0;
27916 #endif
27917
27918 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
27919 + BUG_ON(pr->id >= nr_cpu_ids);
27920
27921 /*
27922 * Buggy BIOS check
27923 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
27924 index 8e1039c..ea9cbd4 100644
27925 --- a/drivers/ata/libata-core.c
27926 +++ b/drivers/ata/libata-core.c
27927 @@ -4750,7 +4750,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
27928 struct ata_port *ap;
27929 unsigned int tag;
27930
27931 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27932 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27933 ap = qc->ap;
27934
27935 qc->flags = 0;
27936 @@ -4766,7 +4766,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
27937 struct ata_port *ap;
27938 struct ata_link *link;
27939
27940 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27941 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27942 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
27943 ap = qc->ap;
27944 link = qc->dev->link;
27945 @@ -5828,6 +5828,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27946 return;
27947
27948 spin_lock(&lock);
27949 + pax_open_kernel();
27950
27951 for (cur = ops->inherits; cur; cur = cur->inherits) {
27952 void **inherit = (void **)cur;
27953 @@ -5841,8 +5842,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27954 if (IS_ERR(*pp))
27955 *pp = NULL;
27956
27957 - ops->inherits = NULL;
27958 + *(struct ata_port_operations **)&ops->inherits = NULL;
27959
27960 + pax_close_kernel();
27961 spin_unlock(&lock);
27962 }
27963
27964 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
27965 index bfaa5cb..3ba1cc3 100644
27966 --- a/drivers/ata/pata_arasan_cf.c
27967 +++ b/drivers/ata/pata_arasan_cf.c
27968 @@ -854,7 +854,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
27969 /* Handle platform specific quirks */
27970 if (pdata->quirk) {
27971 if (pdata->quirk & CF_BROKEN_PIO) {
27972 - ap->ops->set_piomode = NULL;
27973 + pax_open_kernel();
27974 + *(void **)&ap->ops->set_piomode = NULL;
27975 + pax_close_kernel();
27976 ap->pio_mask = 0;
27977 }
27978 if (pdata->quirk & CF_BROKEN_MWDMA)
27979 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
27980 index f9b983a..887b9d8 100644
27981 --- a/drivers/atm/adummy.c
27982 +++ b/drivers/atm/adummy.c
27983 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
27984 vcc->pop(vcc, skb);
27985 else
27986 dev_kfree_skb_any(skb);
27987 - atomic_inc(&vcc->stats->tx);
27988 + atomic_inc_unchecked(&vcc->stats->tx);
27989
27990 return 0;
27991 }
27992 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
27993 index 89b30f3..7964211 100644
27994 --- a/drivers/atm/ambassador.c
27995 +++ b/drivers/atm/ambassador.c
27996 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
27997 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
27998
27999 // VC layer stats
28000 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28001 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28002
28003 // free the descriptor
28004 kfree (tx_descr);
28005 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
28006 dump_skb ("<<<", vc, skb);
28007
28008 // VC layer stats
28009 - atomic_inc(&atm_vcc->stats->rx);
28010 + atomic_inc_unchecked(&atm_vcc->stats->rx);
28011 __net_timestamp(skb);
28012 // end of our responsibility
28013 atm_vcc->push (atm_vcc, skb);
28014 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
28015 } else {
28016 PRINTK (KERN_INFO, "dropped over-size frame");
28017 // should we count this?
28018 - atomic_inc(&atm_vcc->stats->rx_drop);
28019 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28020 }
28021
28022 } else {
28023 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
28024 }
28025
28026 if (check_area (skb->data, skb->len)) {
28027 - atomic_inc(&atm_vcc->stats->tx_err);
28028 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
28029 return -ENOMEM; // ?
28030 }
28031
28032 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
28033 index b22d71c..d6e1049 100644
28034 --- a/drivers/atm/atmtcp.c
28035 +++ b/drivers/atm/atmtcp.c
28036 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28037 if (vcc->pop) vcc->pop(vcc,skb);
28038 else dev_kfree_skb(skb);
28039 if (dev_data) return 0;
28040 - atomic_inc(&vcc->stats->tx_err);
28041 + atomic_inc_unchecked(&vcc->stats->tx_err);
28042 return -ENOLINK;
28043 }
28044 size = skb->len+sizeof(struct atmtcp_hdr);
28045 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28046 if (!new_skb) {
28047 if (vcc->pop) vcc->pop(vcc,skb);
28048 else dev_kfree_skb(skb);
28049 - atomic_inc(&vcc->stats->tx_err);
28050 + atomic_inc_unchecked(&vcc->stats->tx_err);
28051 return -ENOBUFS;
28052 }
28053 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
28054 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28055 if (vcc->pop) vcc->pop(vcc,skb);
28056 else dev_kfree_skb(skb);
28057 out_vcc->push(out_vcc,new_skb);
28058 - atomic_inc(&vcc->stats->tx);
28059 - atomic_inc(&out_vcc->stats->rx);
28060 + atomic_inc_unchecked(&vcc->stats->tx);
28061 + atomic_inc_unchecked(&out_vcc->stats->rx);
28062 return 0;
28063 }
28064
28065 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
28066 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
28067 read_unlock(&vcc_sklist_lock);
28068 if (!out_vcc) {
28069 - atomic_inc(&vcc->stats->tx_err);
28070 + atomic_inc_unchecked(&vcc->stats->tx_err);
28071 goto done;
28072 }
28073 skb_pull(skb,sizeof(struct atmtcp_hdr));
28074 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
28075 __net_timestamp(new_skb);
28076 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
28077 out_vcc->push(out_vcc,new_skb);
28078 - atomic_inc(&vcc->stats->tx);
28079 - atomic_inc(&out_vcc->stats->rx);
28080 + atomic_inc_unchecked(&vcc->stats->tx);
28081 + atomic_inc_unchecked(&out_vcc->stats->rx);
28082 done:
28083 if (vcc->pop) vcc->pop(vcc,skb);
28084 else dev_kfree_skb(skb);
28085 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
28086 index 2059ee4..faf51c7 100644
28087 --- a/drivers/atm/eni.c
28088 +++ b/drivers/atm/eni.c
28089 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
28090 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
28091 vcc->dev->number);
28092 length = 0;
28093 - atomic_inc(&vcc->stats->rx_err);
28094 + atomic_inc_unchecked(&vcc->stats->rx_err);
28095 }
28096 else {
28097 length = ATM_CELL_SIZE-1; /* no HEC */
28098 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
28099 size);
28100 }
28101 eff = length = 0;
28102 - atomic_inc(&vcc->stats->rx_err);
28103 + atomic_inc_unchecked(&vcc->stats->rx_err);
28104 }
28105 else {
28106 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
28107 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
28108 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
28109 vcc->dev->number,vcc->vci,length,size << 2,descr);
28110 length = eff = 0;
28111 - atomic_inc(&vcc->stats->rx_err);
28112 + atomic_inc_unchecked(&vcc->stats->rx_err);
28113 }
28114 }
28115 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
28116 @@ -767,7 +767,7 @@ rx_dequeued++;
28117 vcc->push(vcc,skb);
28118 pushed++;
28119 }
28120 - atomic_inc(&vcc->stats->rx);
28121 + atomic_inc_unchecked(&vcc->stats->rx);
28122 }
28123 wake_up(&eni_dev->rx_wait);
28124 }
28125 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
28126 PCI_DMA_TODEVICE);
28127 if (vcc->pop) vcc->pop(vcc,skb);
28128 else dev_kfree_skb_irq(skb);
28129 - atomic_inc(&vcc->stats->tx);
28130 + atomic_inc_unchecked(&vcc->stats->tx);
28131 wake_up(&eni_dev->tx_wait);
28132 dma_complete++;
28133 }
28134 @@ -1567,7 +1567,7 @@ tx_complete++;
28135 /*--------------------------------- entries ---------------------------------*/
28136
28137
28138 -static const char *media_name[] __devinitdata = {
28139 +static const char *media_name[] __devinitconst = {
28140 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
28141 "UTP", "05?", "06?", "07?", /* 4- 7 */
28142 "TAXI","09?", "10?", "11?", /* 8-11 */
28143 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
28144 index 86fed1b..6dc4721 100644
28145 --- a/drivers/atm/firestream.c
28146 +++ b/drivers/atm/firestream.c
28147 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
28148 }
28149 }
28150
28151 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28152 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28153
28154 fs_dprintk (FS_DEBUG_TXMEM, "i");
28155 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
28156 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28157 #endif
28158 skb_put (skb, qe->p1 & 0xffff);
28159 ATM_SKB(skb)->vcc = atm_vcc;
28160 - atomic_inc(&atm_vcc->stats->rx);
28161 + atomic_inc_unchecked(&atm_vcc->stats->rx);
28162 __net_timestamp(skb);
28163 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
28164 atm_vcc->push (atm_vcc, skb);
28165 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28166 kfree (pe);
28167 }
28168 if (atm_vcc)
28169 - atomic_inc(&atm_vcc->stats->rx_drop);
28170 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28171 break;
28172 case 0x1f: /* Reassembly abort: no buffers. */
28173 /* Silently increment error counter. */
28174 if (atm_vcc)
28175 - atomic_inc(&atm_vcc->stats->rx_drop);
28176 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28177 break;
28178 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
28179 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
28180 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
28181 index 361f5ae..7fc552d 100644
28182 --- a/drivers/atm/fore200e.c
28183 +++ b/drivers/atm/fore200e.c
28184 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
28185 #endif
28186 /* check error condition */
28187 if (*entry->status & STATUS_ERROR)
28188 - atomic_inc(&vcc->stats->tx_err);
28189 + atomic_inc_unchecked(&vcc->stats->tx_err);
28190 else
28191 - atomic_inc(&vcc->stats->tx);
28192 + atomic_inc_unchecked(&vcc->stats->tx);
28193 }
28194 }
28195
28196 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28197 if (skb == NULL) {
28198 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
28199
28200 - atomic_inc(&vcc->stats->rx_drop);
28201 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28202 return -ENOMEM;
28203 }
28204
28205 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28206
28207 dev_kfree_skb_any(skb);
28208
28209 - atomic_inc(&vcc->stats->rx_drop);
28210 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28211 return -ENOMEM;
28212 }
28213
28214 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28215
28216 vcc->push(vcc, skb);
28217 - atomic_inc(&vcc->stats->rx);
28218 + atomic_inc_unchecked(&vcc->stats->rx);
28219
28220 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28221
28222 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
28223 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
28224 fore200e->atm_dev->number,
28225 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
28226 - atomic_inc(&vcc->stats->rx_err);
28227 + atomic_inc_unchecked(&vcc->stats->rx_err);
28228 }
28229 }
28230
28231 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
28232 goto retry_here;
28233 }
28234
28235 - atomic_inc(&vcc->stats->tx_err);
28236 + atomic_inc_unchecked(&vcc->stats->tx_err);
28237
28238 fore200e->tx_sat++;
28239 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
28240 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
28241 index b182c2f..1c6fa8a 100644
28242 --- a/drivers/atm/he.c
28243 +++ b/drivers/atm/he.c
28244 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28245
28246 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
28247 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
28248 - atomic_inc(&vcc->stats->rx_drop);
28249 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28250 goto return_host_buffers;
28251 }
28252
28253 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28254 RBRQ_LEN_ERR(he_dev->rbrq_head)
28255 ? "LEN_ERR" : "",
28256 vcc->vpi, vcc->vci);
28257 - atomic_inc(&vcc->stats->rx_err);
28258 + atomic_inc_unchecked(&vcc->stats->rx_err);
28259 goto return_host_buffers;
28260 }
28261
28262 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28263 vcc->push(vcc, skb);
28264 spin_lock(&he_dev->global_lock);
28265
28266 - atomic_inc(&vcc->stats->rx);
28267 + atomic_inc_unchecked(&vcc->stats->rx);
28268
28269 return_host_buffers:
28270 ++pdus_assembled;
28271 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
28272 tpd->vcc->pop(tpd->vcc, tpd->skb);
28273 else
28274 dev_kfree_skb_any(tpd->skb);
28275 - atomic_inc(&tpd->vcc->stats->tx_err);
28276 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
28277 }
28278 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
28279 return;
28280 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28281 vcc->pop(vcc, skb);
28282 else
28283 dev_kfree_skb_any(skb);
28284 - atomic_inc(&vcc->stats->tx_err);
28285 + atomic_inc_unchecked(&vcc->stats->tx_err);
28286 return -EINVAL;
28287 }
28288
28289 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28290 vcc->pop(vcc, skb);
28291 else
28292 dev_kfree_skb_any(skb);
28293 - atomic_inc(&vcc->stats->tx_err);
28294 + atomic_inc_unchecked(&vcc->stats->tx_err);
28295 return -EINVAL;
28296 }
28297 #endif
28298 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28299 vcc->pop(vcc, skb);
28300 else
28301 dev_kfree_skb_any(skb);
28302 - atomic_inc(&vcc->stats->tx_err);
28303 + atomic_inc_unchecked(&vcc->stats->tx_err);
28304 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28305 return -ENOMEM;
28306 }
28307 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28308 vcc->pop(vcc, skb);
28309 else
28310 dev_kfree_skb_any(skb);
28311 - atomic_inc(&vcc->stats->tx_err);
28312 + atomic_inc_unchecked(&vcc->stats->tx_err);
28313 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28314 return -ENOMEM;
28315 }
28316 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28317 __enqueue_tpd(he_dev, tpd, cid);
28318 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28319
28320 - atomic_inc(&vcc->stats->tx);
28321 + atomic_inc_unchecked(&vcc->stats->tx);
28322
28323 return 0;
28324 }
28325 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
28326 index 7d01c2a..4e3ac01 100644
28327 --- a/drivers/atm/horizon.c
28328 +++ b/drivers/atm/horizon.c
28329 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
28330 {
28331 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
28332 // VC layer stats
28333 - atomic_inc(&vcc->stats->rx);
28334 + atomic_inc_unchecked(&vcc->stats->rx);
28335 __net_timestamp(skb);
28336 // end of our responsibility
28337 vcc->push (vcc, skb);
28338 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
28339 dev->tx_iovec = NULL;
28340
28341 // VC layer stats
28342 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28343 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28344
28345 // free the skb
28346 hrz_kfree_skb (skb);
28347 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
28348 index 8974bd2..b856f85 100644
28349 --- a/drivers/atm/idt77252.c
28350 +++ b/drivers/atm/idt77252.c
28351 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
28352 else
28353 dev_kfree_skb(skb);
28354
28355 - atomic_inc(&vcc->stats->tx);
28356 + atomic_inc_unchecked(&vcc->stats->tx);
28357 }
28358
28359 atomic_dec(&scq->used);
28360 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28361 if ((sb = dev_alloc_skb(64)) == NULL) {
28362 printk("%s: Can't allocate buffers for aal0.\n",
28363 card->name);
28364 - atomic_add(i, &vcc->stats->rx_drop);
28365 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28366 break;
28367 }
28368 if (!atm_charge(vcc, sb->truesize)) {
28369 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
28370 card->name);
28371 - atomic_add(i - 1, &vcc->stats->rx_drop);
28372 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
28373 dev_kfree_skb(sb);
28374 break;
28375 }
28376 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28377 ATM_SKB(sb)->vcc = vcc;
28378 __net_timestamp(sb);
28379 vcc->push(vcc, sb);
28380 - atomic_inc(&vcc->stats->rx);
28381 + atomic_inc_unchecked(&vcc->stats->rx);
28382
28383 cell += ATM_CELL_PAYLOAD;
28384 }
28385 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28386 "(CDC: %08x)\n",
28387 card->name, len, rpp->len, readl(SAR_REG_CDC));
28388 recycle_rx_pool_skb(card, rpp);
28389 - atomic_inc(&vcc->stats->rx_err);
28390 + atomic_inc_unchecked(&vcc->stats->rx_err);
28391 return;
28392 }
28393 if (stat & SAR_RSQE_CRC) {
28394 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
28395 recycle_rx_pool_skb(card, rpp);
28396 - atomic_inc(&vcc->stats->rx_err);
28397 + atomic_inc_unchecked(&vcc->stats->rx_err);
28398 return;
28399 }
28400 if (skb_queue_len(&rpp->queue) > 1) {
28401 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28402 RXPRINTK("%s: Can't alloc RX skb.\n",
28403 card->name);
28404 recycle_rx_pool_skb(card, rpp);
28405 - atomic_inc(&vcc->stats->rx_err);
28406 + atomic_inc_unchecked(&vcc->stats->rx_err);
28407 return;
28408 }
28409 if (!atm_charge(vcc, skb->truesize)) {
28410 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28411 __net_timestamp(skb);
28412
28413 vcc->push(vcc, skb);
28414 - atomic_inc(&vcc->stats->rx);
28415 + atomic_inc_unchecked(&vcc->stats->rx);
28416
28417 return;
28418 }
28419 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28420 __net_timestamp(skb);
28421
28422 vcc->push(vcc, skb);
28423 - atomic_inc(&vcc->stats->rx);
28424 + atomic_inc_unchecked(&vcc->stats->rx);
28425
28426 if (skb->truesize > SAR_FB_SIZE_3)
28427 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
28428 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
28429 if (vcc->qos.aal != ATM_AAL0) {
28430 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
28431 card->name, vpi, vci);
28432 - atomic_inc(&vcc->stats->rx_drop);
28433 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28434 goto drop;
28435 }
28436
28437 if ((sb = dev_alloc_skb(64)) == NULL) {
28438 printk("%s: Can't allocate buffers for AAL0.\n",
28439 card->name);
28440 - atomic_inc(&vcc->stats->rx_err);
28441 + atomic_inc_unchecked(&vcc->stats->rx_err);
28442 goto drop;
28443 }
28444
28445 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
28446 ATM_SKB(sb)->vcc = vcc;
28447 __net_timestamp(sb);
28448 vcc->push(vcc, sb);
28449 - atomic_inc(&vcc->stats->rx);
28450 + atomic_inc_unchecked(&vcc->stats->rx);
28451
28452 drop:
28453 skb_pull(queue, 64);
28454 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28455
28456 if (vc == NULL) {
28457 printk("%s: NULL connection in send().\n", card->name);
28458 - atomic_inc(&vcc->stats->tx_err);
28459 + atomic_inc_unchecked(&vcc->stats->tx_err);
28460 dev_kfree_skb(skb);
28461 return -EINVAL;
28462 }
28463 if (!test_bit(VCF_TX, &vc->flags)) {
28464 printk("%s: Trying to transmit on a non-tx VC.\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 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28471 break;
28472 default:
28473 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
28474 - atomic_inc(&vcc->stats->tx_err);
28475 + atomic_inc_unchecked(&vcc->stats->tx_err);
28476 dev_kfree_skb(skb);
28477 return -EINVAL;
28478 }
28479
28480 if (skb_shinfo(skb)->nr_frags != 0) {
28481 printk("%s: No scatter-gather yet.\n", card->name);
28482 - atomic_inc(&vcc->stats->tx_err);
28483 + atomic_inc_unchecked(&vcc->stats->tx_err);
28484 dev_kfree_skb(skb);
28485 return -EINVAL;
28486 }
28487 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28488
28489 err = queue_skb(card, vc, skb, oam);
28490 if (err) {
28491 - atomic_inc(&vcc->stats->tx_err);
28492 + atomic_inc_unchecked(&vcc->stats->tx_err);
28493 dev_kfree_skb(skb);
28494 return err;
28495 }
28496 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
28497 skb = dev_alloc_skb(64);
28498 if (!skb) {
28499 printk("%s: Out of memory in send_oam().\n", card->name);
28500 - atomic_inc(&vcc->stats->tx_err);
28501 + atomic_inc_unchecked(&vcc->stats->tx_err);
28502 return -ENOMEM;
28503 }
28504 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
28505 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
28506 index 96cce6d..62c3ec5 100644
28507 --- a/drivers/atm/iphase.c
28508 +++ b/drivers/atm/iphase.c
28509 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
28510 status = (u_short) (buf_desc_ptr->desc_mode);
28511 if (status & (RX_CER | RX_PTE | RX_OFL))
28512 {
28513 - atomic_inc(&vcc->stats->rx_err);
28514 + atomic_inc_unchecked(&vcc->stats->rx_err);
28515 IF_ERR(printk("IA: bad packet, dropping it");)
28516 if (status & RX_CER) {
28517 IF_ERR(printk(" cause: packet CRC error\n");)
28518 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
28519 len = dma_addr - buf_addr;
28520 if (len > iadev->rx_buf_sz) {
28521 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
28522 - atomic_inc(&vcc->stats->rx_err);
28523 + atomic_inc_unchecked(&vcc->stats->rx_err);
28524 goto out_free_desc;
28525 }
28526
28527 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28528 ia_vcc = INPH_IA_VCC(vcc);
28529 if (ia_vcc == NULL)
28530 {
28531 - atomic_inc(&vcc->stats->rx_err);
28532 + atomic_inc_unchecked(&vcc->stats->rx_err);
28533 atm_return(vcc, skb->truesize);
28534 dev_kfree_skb_any(skb);
28535 goto INCR_DLE;
28536 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28537 if ((length > iadev->rx_buf_sz) || (length >
28538 (skb->len - sizeof(struct cpcs_trailer))))
28539 {
28540 - atomic_inc(&vcc->stats->rx_err);
28541 + atomic_inc_unchecked(&vcc->stats->rx_err);
28542 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
28543 length, skb->len);)
28544 atm_return(vcc, skb->truesize);
28545 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28546
28547 IF_RX(printk("rx_dle_intr: skb push");)
28548 vcc->push(vcc,skb);
28549 - atomic_inc(&vcc->stats->rx);
28550 + atomic_inc_unchecked(&vcc->stats->rx);
28551 iadev->rx_pkt_cnt++;
28552 }
28553 INCR_DLE:
28554 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
28555 {
28556 struct k_sonet_stats *stats;
28557 stats = &PRIV(_ia_dev[board])->sonet_stats;
28558 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
28559 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
28560 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
28561 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
28562 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
28563 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
28564 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
28565 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
28566 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
28567 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
28568 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
28569 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
28570 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
28571 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
28572 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
28573 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
28574 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
28575 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
28576 }
28577 ia_cmds.status = 0;
28578 break;
28579 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28580 if ((desc == 0) || (desc > iadev->num_tx_desc))
28581 {
28582 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
28583 - atomic_inc(&vcc->stats->tx);
28584 + atomic_inc_unchecked(&vcc->stats->tx);
28585 if (vcc->pop)
28586 vcc->pop(vcc, skb);
28587 else
28588 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28589 ATM_DESC(skb) = vcc->vci;
28590 skb_queue_tail(&iadev->tx_dma_q, skb);
28591
28592 - atomic_inc(&vcc->stats->tx);
28593 + atomic_inc_unchecked(&vcc->stats->tx);
28594 iadev->tx_pkt_cnt++;
28595 /* Increment transaction counter */
28596 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
28597
28598 #if 0
28599 /* add flow control logic */
28600 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
28601 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
28602 if (iavcc->vc_desc_cnt > 10) {
28603 vcc->tx_quota = vcc->tx_quota * 3 / 4;
28604 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
28605 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
28606 index 68c7588..7036683 100644
28607 --- a/drivers/atm/lanai.c
28608 +++ b/drivers/atm/lanai.c
28609 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
28610 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
28611 lanai_endtx(lanai, lvcc);
28612 lanai_free_skb(lvcc->tx.atmvcc, skb);
28613 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28614 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28615 }
28616
28617 /* Try to fill the buffer - don't call unless there is backlog */
28618 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28619 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28620 __net_timestamp(skb);
28621 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28622 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28623 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28624 out:
28625 lvcc->rx.buf.ptr = end;
28626 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28627 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28628 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28629 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28630 lanai->stats.service_rxnotaal5++;
28631 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28632 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28633 return 0;
28634 }
28635 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28636 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28637 int bytes;
28638 read_unlock(&vcc_sklist_lock);
28639 DPRINTK("got trashed rx pdu on vci %d\n", vci);
28640 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28641 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28642 lvcc->stats.x.aal5.service_trash++;
28643 bytes = (SERVICE_GET_END(s) * 16) -
28644 (((unsigned long) lvcc->rx.buf.ptr) -
28645 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28646 }
28647 if (s & SERVICE_STREAM) {
28648 read_unlock(&vcc_sklist_lock);
28649 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28650 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28651 lvcc->stats.x.aal5.service_stream++;
28652 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
28653 "PDU on VCI %d!\n", lanai->number, vci);
28654 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28655 return 0;
28656 }
28657 DPRINTK("got rx crc error on vci %d\n", vci);
28658 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28659 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28660 lvcc->stats.x.aal5.service_rxcrc++;
28661 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
28662 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
28663 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
28664 index 1c70c45..300718d 100644
28665 --- a/drivers/atm/nicstar.c
28666 +++ b/drivers/atm/nicstar.c
28667 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28668 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
28669 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
28670 card->index);
28671 - atomic_inc(&vcc->stats->tx_err);
28672 + atomic_inc_unchecked(&vcc->stats->tx_err);
28673 dev_kfree_skb_any(skb);
28674 return -EINVAL;
28675 }
28676 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28677 if (!vc->tx) {
28678 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
28679 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 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28686 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
28687 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
28688 card->index);
28689 - atomic_inc(&vcc->stats->tx_err);
28690 + atomic_inc_unchecked(&vcc->stats->tx_err);
28691 dev_kfree_skb_any(skb);
28692 return -EINVAL;
28693 }
28694
28695 if (skb_shinfo(skb)->nr_frags != 0) {
28696 printk("nicstar%d: No scatter-gather yet.\n", card->index);
28697 - atomic_inc(&vcc->stats->tx_err);
28698 + atomic_inc_unchecked(&vcc->stats->tx_err);
28699 dev_kfree_skb_any(skb);
28700 return -EINVAL;
28701 }
28702 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28703 }
28704
28705 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
28706 - atomic_inc(&vcc->stats->tx_err);
28707 + atomic_inc_unchecked(&vcc->stats->tx_err);
28708 dev_kfree_skb_any(skb);
28709 return -EIO;
28710 }
28711 - atomic_inc(&vcc->stats->tx);
28712 + atomic_inc_unchecked(&vcc->stats->tx);
28713
28714 return 0;
28715 }
28716 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28717 printk
28718 ("nicstar%d: Can't allocate buffers for aal0.\n",
28719 card->index);
28720 - atomic_add(i, &vcc->stats->rx_drop);
28721 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28722 break;
28723 }
28724 if (!atm_charge(vcc, sb->truesize)) {
28725 RXPRINTK
28726 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
28727 card->index);
28728 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28729 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28730 dev_kfree_skb_any(sb);
28731 break;
28732 }
28733 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28734 ATM_SKB(sb)->vcc = vcc;
28735 __net_timestamp(sb);
28736 vcc->push(vcc, sb);
28737 - atomic_inc(&vcc->stats->rx);
28738 + atomic_inc_unchecked(&vcc->stats->rx);
28739 cell += ATM_CELL_PAYLOAD;
28740 }
28741
28742 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28743 if (iovb == NULL) {
28744 printk("nicstar%d: Out of iovec buffers.\n",
28745 card->index);
28746 - atomic_inc(&vcc->stats->rx_drop);
28747 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28748 recycle_rx_buf(card, skb);
28749 return;
28750 }
28751 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28752 small or large buffer itself. */
28753 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
28754 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
28755 - atomic_inc(&vcc->stats->rx_err);
28756 + atomic_inc_unchecked(&vcc->stats->rx_err);
28757 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28758 NS_MAX_IOVECS);
28759 NS_PRV_IOVCNT(iovb) = 0;
28760 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28761 ("nicstar%d: Expected a small buffer, and this is not one.\n",
28762 card->index);
28763 which_list(card, skb);
28764 - atomic_inc(&vcc->stats->rx_err);
28765 + atomic_inc_unchecked(&vcc->stats->rx_err);
28766 recycle_rx_buf(card, skb);
28767 vc->rx_iov = NULL;
28768 recycle_iov_buf(card, iovb);
28769 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28770 ("nicstar%d: Expected a large buffer, and this is not one.\n",
28771 card->index);
28772 which_list(card, skb);
28773 - atomic_inc(&vcc->stats->rx_err);
28774 + atomic_inc_unchecked(&vcc->stats->rx_err);
28775 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28776 NS_PRV_IOVCNT(iovb));
28777 vc->rx_iov = NULL;
28778 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28779 printk(" - PDU size mismatch.\n");
28780 else
28781 printk(".\n");
28782 - atomic_inc(&vcc->stats->rx_err);
28783 + atomic_inc_unchecked(&vcc->stats->rx_err);
28784 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28785 NS_PRV_IOVCNT(iovb));
28786 vc->rx_iov = NULL;
28787 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28788 /* skb points to a small buffer */
28789 if (!atm_charge(vcc, skb->truesize)) {
28790 push_rxbufs(card, skb);
28791 - atomic_inc(&vcc->stats->rx_drop);
28792 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28793 } else {
28794 skb_put(skb, len);
28795 dequeue_sm_buf(card, skb);
28796 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28797 ATM_SKB(skb)->vcc = vcc;
28798 __net_timestamp(skb);
28799 vcc->push(vcc, skb);
28800 - atomic_inc(&vcc->stats->rx);
28801 + atomic_inc_unchecked(&vcc->stats->rx);
28802 }
28803 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
28804 struct sk_buff *sb;
28805 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28806 if (len <= NS_SMBUFSIZE) {
28807 if (!atm_charge(vcc, sb->truesize)) {
28808 push_rxbufs(card, sb);
28809 - atomic_inc(&vcc->stats->rx_drop);
28810 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28811 } else {
28812 skb_put(sb, len);
28813 dequeue_sm_buf(card, sb);
28814 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28815 ATM_SKB(sb)->vcc = vcc;
28816 __net_timestamp(sb);
28817 vcc->push(vcc, sb);
28818 - atomic_inc(&vcc->stats->rx);
28819 + atomic_inc_unchecked(&vcc->stats->rx);
28820 }
28821
28822 push_rxbufs(card, skb);
28823 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28824
28825 if (!atm_charge(vcc, skb->truesize)) {
28826 push_rxbufs(card, skb);
28827 - atomic_inc(&vcc->stats->rx_drop);
28828 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28829 } else {
28830 dequeue_lg_buf(card, skb);
28831 #ifdef NS_USE_DESTRUCTORS
28832 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28833 ATM_SKB(skb)->vcc = vcc;
28834 __net_timestamp(skb);
28835 vcc->push(vcc, skb);
28836 - atomic_inc(&vcc->stats->rx);
28837 + atomic_inc_unchecked(&vcc->stats->rx);
28838 }
28839
28840 push_rxbufs(card, sb);
28841 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28842 printk
28843 ("nicstar%d: Out of huge buffers.\n",
28844 card->index);
28845 - atomic_inc(&vcc->stats->rx_drop);
28846 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28847 recycle_iovec_rx_bufs(card,
28848 (struct iovec *)
28849 iovb->data,
28850 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28851 card->hbpool.count++;
28852 } else
28853 dev_kfree_skb_any(hb);
28854 - atomic_inc(&vcc->stats->rx_drop);
28855 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28856 } else {
28857 /* Copy the small buffer to the huge buffer */
28858 sb = (struct sk_buff *)iov->iov_base;
28859 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28860 #endif /* NS_USE_DESTRUCTORS */
28861 __net_timestamp(hb);
28862 vcc->push(vcc, hb);
28863 - atomic_inc(&vcc->stats->rx);
28864 + atomic_inc_unchecked(&vcc->stats->rx);
28865 }
28866 }
28867
28868 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
28869 index 9851093..adb2b1e 100644
28870 --- a/drivers/atm/solos-pci.c
28871 +++ b/drivers/atm/solos-pci.c
28872 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
28873 }
28874 atm_charge(vcc, skb->truesize);
28875 vcc->push(vcc, skb);
28876 - atomic_inc(&vcc->stats->rx);
28877 + atomic_inc_unchecked(&vcc->stats->rx);
28878 break;
28879
28880 case PKT_STATUS:
28881 @@ -1009,7 +1009,7 @@ static uint32_t fpga_tx(struct solos_card *card)
28882 vcc = SKB_CB(oldskb)->vcc;
28883
28884 if (vcc) {
28885 - atomic_inc(&vcc->stats->tx);
28886 + atomic_inc_unchecked(&vcc->stats->tx);
28887 solos_pop(vcc, oldskb);
28888 } else
28889 dev_kfree_skb_irq(oldskb);
28890 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
28891 index 0215934..ce9f5b1 100644
28892 --- a/drivers/atm/suni.c
28893 +++ b/drivers/atm/suni.c
28894 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
28895
28896
28897 #define ADD_LIMITED(s,v) \
28898 - atomic_add((v),&stats->s); \
28899 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
28900 + atomic_add_unchecked((v),&stats->s); \
28901 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
28902
28903
28904 static void suni_hz(unsigned long from_timer)
28905 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
28906 index 5120a96..e2572bd 100644
28907 --- a/drivers/atm/uPD98402.c
28908 +++ b/drivers/atm/uPD98402.c
28909 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
28910 struct sonet_stats tmp;
28911 int error = 0;
28912
28913 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28914 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28915 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
28916 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
28917 if (zero && !error) {
28918 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
28919
28920
28921 #define ADD_LIMITED(s,v) \
28922 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
28923 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
28924 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28925 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
28926 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
28927 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28928
28929
28930 static void stat_event(struct atm_dev *dev)
28931 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
28932 if (reason & uPD98402_INT_PFM) stat_event(dev);
28933 if (reason & uPD98402_INT_PCO) {
28934 (void) GET(PCOCR); /* clear interrupt cause */
28935 - atomic_add(GET(HECCT),
28936 + atomic_add_unchecked(GET(HECCT),
28937 &PRIV(dev)->sonet_stats.uncorr_hcs);
28938 }
28939 if ((reason & uPD98402_INT_RFO) &&
28940 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
28941 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
28942 uPD98402_INT_LOS),PIMR); /* enable them */
28943 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
28944 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28945 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
28946 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
28947 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28948 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
28949 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
28950 return 0;
28951 }
28952
28953 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
28954 index abe4e20..83c4727 100644
28955 --- a/drivers/atm/zatm.c
28956 +++ b/drivers/atm/zatm.c
28957 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28958 }
28959 if (!size) {
28960 dev_kfree_skb_irq(skb);
28961 - if (vcc) atomic_inc(&vcc->stats->rx_err);
28962 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
28963 continue;
28964 }
28965 if (!atm_charge(vcc,skb->truesize)) {
28966 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28967 skb->len = size;
28968 ATM_SKB(skb)->vcc = vcc;
28969 vcc->push(vcc,skb);
28970 - atomic_inc(&vcc->stats->rx);
28971 + atomic_inc_unchecked(&vcc->stats->rx);
28972 }
28973 zout(pos & 0xffff,MTA(mbx));
28974 #if 0 /* probably a stupid idea */
28975 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
28976 skb_queue_head(&zatm_vcc->backlog,skb);
28977 break;
28978 }
28979 - atomic_inc(&vcc->stats->tx);
28980 + atomic_inc_unchecked(&vcc->stats->tx);
28981 wake_up(&zatm_vcc->tx_wait);
28982 }
28983
28984 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
28985 index deb4a45..211eff2 100644
28986 --- a/drivers/base/devtmpfs.c
28987 +++ b/drivers/base/devtmpfs.c
28988 @@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
28989 if (!thread)
28990 return 0;
28991
28992 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
28993 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
28994 if (err)
28995 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
28996 else
28997 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
28998 index cbb463b..babe2cf 100644
28999 --- a/drivers/base/power/wakeup.c
29000 +++ b/drivers/base/power/wakeup.c
29001 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
29002 * They need to be modified together atomically, so it's better to use one
29003 * atomic variable to hold them both.
29004 */
29005 -static atomic_t combined_event_count = ATOMIC_INIT(0);
29006 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
29007
29008 #define IN_PROGRESS_BITS (sizeof(int) * 4)
29009 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
29010
29011 static void split_counters(unsigned int *cnt, unsigned int *inpr)
29012 {
29013 - unsigned int comb = atomic_read(&combined_event_count);
29014 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
29015
29016 *cnt = (comb >> IN_PROGRESS_BITS);
29017 *inpr = comb & MAX_IN_PROGRESS;
29018 @@ -385,7 +385,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
29019 ws->start_prevent_time = ws->last_time;
29020
29021 /* Increment the counter of events in progress. */
29022 - cec = atomic_inc_return(&combined_event_count);
29023 + cec = atomic_inc_return_unchecked(&combined_event_count);
29024
29025 trace_wakeup_source_activate(ws->name, cec);
29026 }
29027 @@ -511,7 +511,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
29028 * Increment the counter of registered wakeup events and decrement the
29029 * couter of wakeup events in progress simultaneously.
29030 */
29031 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
29032 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
29033 trace_wakeup_source_deactivate(ws->name, cec);
29034
29035 split_counters(&cnt, &inpr);
29036 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
29037 index b0f553b..77b928b 100644
29038 --- a/drivers/block/cciss.c
29039 +++ b/drivers/block/cciss.c
29040 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
29041 int err;
29042 u32 cp;
29043
29044 + memset(&arg64, 0, sizeof(arg64));
29045 +
29046 err = 0;
29047 err |=
29048 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
29049 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
29050 while (!list_empty(&h->reqQ)) {
29051 c = list_entry(h->reqQ.next, CommandList_struct, list);
29052 /* can't do anything if fifo is full */
29053 - if ((h->access.fifo_full(h))) {
29054 + if ((h->access->fifo_full(h))) {
29055 dev_warn(&h->pdev->dev, "fifo full\n");
29056 break;
29057 }
29058 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
29059 h->Qdepth--;
29060
29061 /* Tell the controller execute command */
29062 - h->access.submit_command(h, c);
29063 + h->access->submit_command(h, c);
29064
29065 /* Put job onto the completed Q */
29066 addQ(&h->cmpQ, c);
29067 @@ -3443,17 +3445,17 @@ startio:
29068
29069 static inline unsigned long get_next_completion(ctlr_info_t *h)
29070 {
29071 - return h->access.command_completed(h);
29072 + return h->access->command_completed(h);
29073 }
29074
29075 static inline int interrupt_pending(ctlr_info_t *h)
29076 {
29077 - return h->access.intr_pending(h);
29078 + return h->access->intr_pending(h);
29079 }
29080
29081 static inline long interrupt_not_for_us(ctlr_info_t *h)
29082 {
29083 - return ((h->access.intr_pending(h) == 0) ||
29084 + return ((h->access->intr_pending(h) == 0) ||
29085 (h->interrupts_enabled == 0));
29086 }
29087
29088 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
29089 u32 a;
29090
29091 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
29092 - return h->access.command_completed(h);
29093 + return h->access->command_completed(h);
29094
29095 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
29096 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
29097 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
29098 trans_support & CFGTBL_Trans_use_short_tags);
29099
29100 /* Change the access methods to the performant access methods */
29101 - h->access = SA5_performant_access;
29102 + h->access = &SA5_performant_access;
29103 h->transMethod = CFGTBL_Trans_Performant;
29104
29105 return;
29106 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
29107 if (prod_index < 0)
29108 return -ENODEV;
29109 h->product_name = products[prod_index].product_name;
29110 - h->access = *(products[prod_index].access);
29111 + h->access = products[prod_index].access;
29112
29113 if (cciss_board_disabled(h)) {
29114 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
29115 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
29116 }
29117
29118 /* make sure the board interrupts are off */
29119 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29120 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29121 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
29122 if (rc)
29123 goto clean2;
29124 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
29125 * fake ones to scoop up any residual completions.
29126 */
29127 spin_lock_irqsave(&h->lock, flags);
29128 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29129 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29130 spin_unlock_irqrestore(&h->lock, flags);
29131 free_irq(h->intr[h->intr_mode], h);
29132 rc = cciss_request_irq(h, cciss_msix_discard_completions,
29133 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
29134 dev_info(&h->pdev->dev, "Board READY.\n");
29135 dev_info(&h->pdev->dev,
29136 "Waiting for stale completions to drain.\n");
29137 - h->access.set_intr_mask(h, CCISS_INTR_ON);
29138 + h->access->set_intr_mask(h, CCISS_INTR_ON);
29139 msleep(10000);
29140 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29141 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29142
29143 rc = controller_reset_failed(h->cfgtable);
29144 if (rc)
29145 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
29146 cciss_scsi_setup(h);
29147
29148 /* Turn the interrupts on so we can service requests */
29149 - h->access.set_intr_mask(h, CCISS_INTR_ON);
29150 + h->access->set_intr_mask(h, CCISS_INTR_ON);
29151
29152 /* Get the firmware version */
29153 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
29154 @@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
29155 kfree(flush_buf);
29156 if (return_code != IO_OK)
29157 dev_warn(&h->pdev->dev, "Error flushing cache\n");
29158 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29159 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29160 free_irq(h->intr[h->intr_mode], h);
29161 }
29162
29163 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
29164 index 7fda30e..eb5dfe0 100644
29165 --- a/drivers/block/cciss.h
29166 +++ b/drivers/block/cciss.h
29167 @@ -101,7 +101,7 @@ struct ctlr_info
29168 /* information about each logical volume */
29169 drive_info_struct *drv[CISS_MAX_LUN];
29170
29171 - struct access_method access;
29172 + struct access_method *access;
29173
29174 /* queue and queue Info */
29175 struct list_head reqQ;
29176 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
29177 index 9125bbe..eede5c8 100644
29178 --- a/drivers/block/cpqarray.c
29179 +++ b/drivers/block/cpqarray.c
29180 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29181 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
29182 goto Enomem4;
29183 }
29184 - hba[i]->access.set_intr_mask(hba[i], 0);
29185 + hba[i]->access->set_intr_mask(hba[i], 0);
29186 if (request_irq(hba[i]->intr, do_ida_intr,
29187 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
29188 {
29189 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29190 add_timer(&hba[i]->timer);
29191
29192 /* Enable IRQ now that spinlock and rate limit timer are set up */
29193 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29194 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29195
29196 for(j=0; j<NWD; j++) {
29197 struct gendisk *disk = ida_gendisk[i][j];
29198 @@ -694,7 +694,7 @@ DBGINFO(
29199 for(i=0; i<NR_PRODUCTS; i++) {
29200 if (board_id == products[i].board_id) {
29201 c->product_name = products[i].product_name;
29202 - c->access = *(products[i].access);
29203 + c->access = products[i].access;
29204 break;
29205 }
29206 }
29207 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
29208 hba[ctlr]->intr = intr;
29209 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
29210 hba[ctlr]->product_name = products[j].product_name;
29211 - hba[ctlr]->access = *(products[j].access);
29212 + hba[ctlr]->access = products[j].access;
29213 hba[ctlr]->ctlr = ctlr;
29214 hba[ctlr]->board_id = board_id;
29215 hba[ctlr]->pci_dev = NULL; /* not PCI */
29216 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
29217
29218 while((c = h->reqQ) != NULL) {
29219 /* Can't do anything if we're busy */
29220 - if (h->access.fifo_full(h) == 0)
29221 + if (h->access->fifo_full(h) == 0)
29222 return;
29223
29224 /* Get the first entry from the request Q */
29225 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
29226 h->Qdepth--;
29227
29228 /* Tell the controller to do our bidding */
29229 - h->access.submit_command(h, c);
29230 + h->access->submit_command(h, c);
29231
29232 /* Get onto the completion Q */
29233 addQ(&h->cmpQ, c);
29234 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29235 unsigned long flags;
29236 __u32 a,a1;
29237
29238 - istat = h->access.intr_pending(h);
29239 + istat = h->access->intr_pending(h);
29240 /* Is this interrupt for us? */
29241 if (istat == 0)
29242 return IRQ_NONE;
29243 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29244 */
29245 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
29246 if (istat & FIFO_NOT_EMPTY) {
29247 - while((a = h->access.command_completed(h))) {
29248 + while((a = h->access->command_completed(h))) {
29249 a1 = a; a &= ~3;
29250 if ((c = h->cmpQ) == NULL)
29251 {
29252 @@ -1449,11 +1449,11 @@ static int sendcmd(
29253 /*
29254 * Disable interrupt
29255 */
29256 - info_p->access.set_intr_mask(info_p, 0);
29257 + info_p->access->set_intr_mask(info_p, 0);
29258 /* Make sure there is room in the command FIFO */
29259 /* Actually it should be completely empty at this time. */
29260 for (i = 200000; i > 0; i--) {
29261 - temp = info_p->access.fifo_full(info_p);
29262 + temp = info_p->access->fifo_full(info_p);
29263 if (temp != 0) {
29264 break;
29265 }
29266 @@ -1466,7 +1466,7 @@ DBG(
29267 /*
29268 * Send the cmd
29269 */
29270 - info_p->access.submit_command(info_p, c);
29271 + info_p->access->submit_command(info_p, c);
29272 complete = pollcomplete(ctlr);
29273
29274 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
29275 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
29276 * we check the new geometry. Then turn interrupts back on when
29277 * we're done.
29278 */
29279 - host->access.set_intr_mask(host, 0);
29280 + host->access->set_intr_mask(host, 0);
29281 getgeometry(ctlr);
29282 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
29283 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
29284
29285 for(i=0; i<NWD; i++) {
29286 struct gendisk *disk = ida_gendisk[ctlr][i];
29287 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
29288 /* Wait (up to 2 seconds) for a command to complete */
29289
29290 for (i = 200000; i > 0; i--) {
29291 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
29292 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
29293 if (done == 0) {
29294 udelay(10); /* a short fixed delay */
29295 } else
29296 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
29297 index be73e9d..7fbf140 100644
29298 --- a/drivers/block/cpqarray.h
29299 +++ b/drivers/block/cpqarray.h
29300 @@ -99,7 +99,7 @@ struct ctlr_info {
29301 drv_info_t drv[NWD];
29302 struct proc_dir_entry *proc;
29303
29304 - struct access_method access;
29305 + struct access_method *access;
29306
29307 cmdlist_t *reqQ;
29308 cmdlist_t *cmpQ;
29309 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
29310 index b953cc7..e3dc580 100644
29311 --- a/drivers/block/drbd/drbd_int.h
29312 +++ b/drivers/block/drbd/drbd_int.h
29313 @@ -735,7 +735,7 @@ struct drbd_request;
29314 struct drbd_epoch {
29315 struct list_head list;
29316 unsigned int barrier_nr;
29317 - atomic_t epoch_size; /* increased on every request added. */
29318 + atomic_unchecked_t epoch_size; /* increased on every request added. */
29319 atomic_t active; /* increased on every req. added, and dec on every finished. */
29320 unsigned long flags;
29321 };
29322 @@ -1116,7 +1116,7 @@ struct drbd_conf {
29323 void *int_dig_in;
29324 void *int_dig_vv;
29325 wait_queue_head_t seq_wait;
29326 - atomic_t packet_seq;
29327 + atomic_unchecked_t packet_seq;
29328 unsigned int peer_seq;
29329 spinlock_t peer_seq_lock;
29330 unsigned int minor;
29331 @@ -1658,30 +1658,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
29332
29333 static inline void drbd_tcp_cork(struct socket *sock)
29334 {
29335 - int __user val = 1;
29336 + int val = 1;
29337 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29338 - (char __user *)&val, sizeof(val));
29339 + (char __force_user *)&val, sizeof(val));
29340 }
29341
29342 static inline void drbd_tcp_uncork(struct socket *sock)
29343 {
29344 - int __user val = 0;
29345 + int val = 0;
29346 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29347 - (char __user *)&val, sizeof(val));
29348 + (char __force_user *)&val, sizeof(val));
29349 }
29350
29351 static inline void drbd_tcp_nodelay(struct socket *sock)
29352 {
29353 - int __user val = 1;
29354 + int val = 1;
29355 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
29356 - (char __user *)&val, sizeof(val));
29357 + (char __force_user *)&val, sizeof(val));
29358 }
29359
29360 static inline void drbd_tcp_quickack(struct socket *sock)
29361 {
29362 - int __user val = 2;
29363 + int val = 2;
29364 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
29365 - (char __user *)&val, sizeof(val));
29366 + (char __force_user *)&val, sizeof(val));
29367 }
29368
29369 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
29370 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
29371 index f93a032..71c87bf 100644
29372 --- a/drivers/block/drbd/drbd_main.c
29373 +++ b/drivers/block/drbd/drbd_main.c
29374 @@ -2567,7 +2567,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
29375 p.sector = sector;
29376 p.block_id = block_id;
29377 p.blksize = blksize;
29378 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29379 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29380
29381 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
29382 return false;
29383 @@ -2865,7 +2865,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
29384
29385 p.sector = cpu_to_be64(req->sector);
29386 p.block_id = (unsigned long)req;
29387 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29388 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29389
29390 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
29391
29392 @@ -3150,7 +3150,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
29393 atomic_set(&mdev->unacked_cnt, 0);
29394 atomic_set(&mdev->local_cnt, 0);
29395 atomic_set(&mdev->net_cnt, 0);
29396 - atomic_set(&mdev->packet_seq, 0);
29397 + atomic_set_unchecked(&mdev->packet_seq, 0);
29398 atomic_set(&mdev->pp_in_use, 0);
29399 atomic_set(&mdev->pp_in_use_by_net, 0);
29400 atomic_set(&mdev->rs_sect_in, 0);
29401 @@ -3232,8 +3232,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
29402 mdev->receiver.t_state);
29403
29404 /* no need to lock it, I'm the only thread alive */
29405 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
29406 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
29407 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
29408 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
29409 mdev->al_writ_cnt =
29410 mdev->bm_writ_cnt =
29411 mdev->read_cnt =
29412 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
29413 index edb490a..ecd69da 100644
29414 --- a/drivers/block/drbd/drbd_nl.c
29415 +++ b/drivers/block/drbd/drbd_nl.c
29416 @@ -2407,7 +2407,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29417 module_put(THIS_MODULE);
29418 }
29419
29420 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29421 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29422
29423 static unsigned short *
29424 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
29425 @@ -2478,7 +2478,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
29426 cn_reply->id.idx = CN_IDX_DRBD;
29427 cn_reply->id.val = CN_VAL_DRBD;
29428
29429 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29430 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29431 cn_reply->ack = 0; /* not used here. */
29432 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29433 (int)((char *)tl - (char *)reply->tag_list);
29434 @@ -2510,7 +2510,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
29435 cn_reply->id.idx = CN_IDX_DRBD;
29436 cn_reply->id.val = CN_VAL_DRBD;
29437
29438 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29439 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29440 cn_reply->ack = 0; /* not used here. */
29441 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29442 (int)((char *)tl - (char *)reply->tag_list);
29443 @@ -2588,7 +2588,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
29444 cn_reply->id.idx = CN_IDX_DRBD;
29445 cn_reply->id.val = CN_VAL_DRBD;
29446
29447 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
29448 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
29449 cn_reply->ack = 0; // not used here.
29450 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29451 (int)((char*)tl - (char*)reply->tag_list);
29452 @@ -2627,7 +2627,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
29453 cn_reply->id.idx = CN_IDX_DRBD;
29454 cn_reply->id.val = CN_VAL_DRBD;
29455
29456 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29457 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29458 cn_reply->ack = 0; /* not used here. */
29459 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29460 (int)((char *)tl - (char *)reply->tag_list);
29461 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
29462 index c74ca2d..860c819 100644
29463 --- a/drivers/block/drbd/drbd_receiver.c
29464 +++ b/drivers/block/drbd/drbd_receiver.c
29465 @@ -898,7 +898,7 @@ retry:
29466 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
29467 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
29468
29469 - atomic_set(&mdev->packet_seq, 0);
29470 + atomic_set_unchecked(&mdev->packet_seq, 0);
29471 mdev->peer_seq = 0;
29472
29473 if (drbd_send_protocol(mdev) == -1)
29474 @@ -999,7 +999,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29475 do {
29476 next_epoch = NULL;
29477
29478 - epoch_size = atomic_read(&epoch->epoch_size);
29479 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
29480
29481 switch (ev & ~EV_CLEANUP) {
29482 case EV_PUT:
29483 @@ -1035,7 +1035,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29484 rv = FE_DESTROYED;
29485 } else {
29486 epoch->flags = 0;
29487 - atomic_set(&epoch->epoch_size, 0);
29488 + atomic_set_unchecked(&epoch->epoch_size, 0);
29489 /* atomic_set(&epoch->active, 0); is already zero */
29490 if (rv == FE_STILL_LIVE)
29491 rv = FE_RECYCLED;
29492 @@ -1210,14 +1210,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29493 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
29494 drbd_flush(mdev);
29495
29496 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29497 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29498 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
29499 if (epoch)
29500 break;
29501 }
29502
29503 epoch = mdev->current_epoch;
29504 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
29505 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
29506
29507 D_ASSERT(atomic_read(&epoch->active) == 0);
29508 D_ASSERT(epoch->flags == 0);
29509 @@ -1229,11 +1229,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29510 }
29511
29512 epoch->flags = 0;
29513 - atomic_set(&epoch->epoch_size, 0);
29514 + atomic_set_unchecked(&epoch->epoch_size, 0);
29515 atomic_set(&epoch->active, 0);
29516
29517 spin_lock(&mdev->epoch_lock);
29518 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29519 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29520 list_add(&epoch->list, &mdev->current_epoch->list);
29521 mdev->current_epoch = epoch;
29522 mdev->epochs++;
29523 @@ -1702,7 +1702,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29524 spin_unlock(&mdev->peer_seq_lock);
29525
29526 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
29527 - atomic_inc(&mdev->current_epoch->epoch_size);
29528 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
29529 return drbd_drain_block(mdev, data_size);
29530 }
29531
29532 @@ -1732,7 +1732,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29533
29534 spin_lock(&mdev->epoch_lock);
29535 e->epoch = mdev->current_epoch;
29536 - atomic_inc(&e->epoch->epoch_size);
29537 + atomic_inc_unchecked(&e->epoch->epoch_size);
29538 atomic_inc(&e->epoch->active);
29539 spin_unlock(&mdev->epoch_lock);
29540
29541 @@ -3954,7 +3954,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
29542 D_ASSERT(list_empty(&mdev->done_ee));
29543
29544 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
29545 - atomic_set(&mdev->current_epoch->epoch_size, 0);
29546 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
29547 D_ASSERT(list_empty(&mdev->current_epoch->list));
29548 }
29549
29550 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
29551 index 3bba655..6151b66 100644
29552 --- a/drivers/block/loop.c
29553 +++ b/drivers/block/loop.c
29554 @@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
29555 mm_segment_t old_fs = get_fs();
29556
29557 set_fs(get_ds());
29558 - bw = file->f_op->write(file, buf, len, &pos);
29559 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
29560 set_fs(old_fs);
29561 if (likely(bw == len))
29562 return 0;
29563 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
29564 index ea6f632..eafb192 100644
29565 --- a/drivers/char/Kconfig
29566 +++ b/drivers/char/Kconfig
29567 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
29568
29569 config DEVKMEM
29570 bool "/dev/kmem virtual device support"
29571 - default y
29572 + default n
29573 + depends on !GRKERNSEC_KMEM
29574 help
29575 Say Y here if you want to support the /dev/kmem device. The
29576 /dev/kmem device is rarely used, but can be used for certain
29577 @@ -581,6 +582,7 @@ config DEVPORT
29578 bool
29579 depends on !M68K
29580 depends on ISA || PCI
29581 + depends on !GRKERNSEC_KMEM
29582 default y
29583
29584 source "drivers/s390/char/Kconfig"
29585 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
29586 index 2e04433..22afc64 100644
29587 --- a/drivers/char/agp/frontend.c
29588 +++ b/drivers/char/agp/frontend.c
29589 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
29590 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
29591 return -EFAULT;
29592
29593 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
29594 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29595 return -EFAULT;
29596
29597 client = agp_find_client_by_pid(reserve.pid);
29598 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29599 index 21cb980..f15107c 100644
29600 --- a/drivers/char/genrtc.c
29601 +++ b/drivers/char/genrtc.c
29602 @@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
29603 switch (cmd) {
29604
29605 case RTC_PLL_GET:
29606 + memset(&pll, 0, sizeof(pll));
29607 if (get_rtc_pll(&pll))
29608 return -EINVAL;
29609 else
29610 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29611 index dfd7876..c0b0885 100644
29612 --- a/drivers/char/hpet.c
29613 +++ b/drivers/char/hpet.c
29614 @@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29615 }
29616
29617 static int
29618 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29619 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29620 struct hpet_info *info)
29621 {
29622 struct hpet_timer __iomem *timer;
29623 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29624 index 2c29942..604c5ba 100644
29625 --- a/drivers/char/ipmi/ipmi_msghandler.c
29626 +++ b/drivers/char/ipmi/ipmi_msghandler.c
29627 @@ -420,7 +420,7 @@ struct ipmi_smi {
29628 struct proc_dir_entry *proc_dir;
29629 char proc_dir_name[10];
29630
29631 - atomic_t stats[IPMI_NUM_STATS];
29632 + atomic_unchecked_t stats[IPMI_NUM_STATS];
29633
29634 /*
29635 * run_to_completion duplicate of smb_info, smi_info
29636 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29637
29638
29639 #define ipmi_inc_stat(intf, stat) \
29640 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29641 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29642 #define ipmi_get_stat(intf, stat) \
29643 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29644 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29645
29646 static int is_lan_addr(struct ipmi_addr *addr)
29647 {
29648 @@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29649 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29650 init_waitqueue_head(&intf->waitq);
29651 for (i = 0; i < IPMI_NUM_STATS; i++)
29652 - atomic_set(&intf->stats[i], 0);
29653 + atomic_set_unchecked(&intf->stats[i], 0);
29654
29655 intf->proc_dir = NULL;
29656
29657 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
29658 index 83f85cf..279e63f 100644
29659 --- a/drivers/char/ipmi/ipmi_si_intf.c
29660 +++ b/drivers/char/ipmi/ipmi_si_intf.c
29661 @@ -275,7 +275,7 @@ struct smi_info {
29662 unsigned char slave_addr;
29663
29664 /* Counters and things for the proc filesystem. */
29665 - atomic_t stats[SI_NUM_STATS];
29666 + atomic_unchecked_t stats[SI_NUM_STATS];
29667
29668 struct task_struct *thread;
29669
29670 @@ -284,9 +284,9 @@ struct smi_info {
29671 };
29672
29673 #define smi_inc_stat(smi, stat) \
29674 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
29675 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
29676 #define smi_get_stat(smi, stat) \
29677 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
29678 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
29679
29680 #define SI_MAX_PARMS 4
29681
29682 @@ -3193,7 +3193,7 @@ static int try_smi_init(struct smi_info *new_smi)
29683 atomic_set(&new_smi->req_events, 0);
29684 new_smi->run_to_completion = 0;
29685 for (i = 0; i < SI_NUM_STATS; i++)
29686 - atomic_set(&new_smi->stats[i], 0);
29687 + atomic_set_unchecked(&new_smi->stats[i], 0);
29688
29689 new_smi->interrupt_disabled = 1;
29690 atomic_set(&new_smi->stop_operation, 0);
29691 diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
29692 index 47ff7e4..0c7d340 100644
29693 --- a/drivers/char/mbcs.c
29694 +++ b/drivers/char/mbcs.c
29695 @@ -799,7 +799,7 @@ static int mbcs_remove(struct cx_dev *dev)
29696 return 0;
29697 }
29698
29699 -static const struct cx_device_id __devinitdata mbcs_id_table[] = {
29700 +static const struct cx_device_id __devinitconst mbcs_id_table[] = {
29701 {
29702 .part_num = MBCS_PART_NUM,
29703 .mfg_num = MBCS_MFG_NUM,
29704 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
29705 index e5eedfa..fcab50ea 100644
29706 --- a/drivers/char/mem.c
29707 +++ b/drivers/char/mem.c
29708 @@ -18,6 +18,7 @@
29709 #include <linux/raw.h>
29710 #include <linux/tty.h>
29711 #include <linux/capability.h>
29712 +#include <linux/security.h>
29713 #include <linux/ptrace.h>
29714 #include <linux/device.h>
29715 #include <linux/highmem.h>
29716 @@ -37,6 +38,10 @@
29717
29718 #define DEVPORT_MINOR 4
29719
29720 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29721 +extern const struct file_operations grsec_fops;
29722 +#endif
29723 +
29724 static inline unsigned long size_inside_page(unsigned long start,
29725 unsigned long size)
29726 {
29727 @@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29728
29729 while (cursor < to) {
29730 if (!devmem_is_allowed(pfn)) {
29731 +#ifdef CONFIG_GRKERNSEC_KMEM
29732 + gr_handle_mem_readwrite(from, to);
29733 +#else
29734 printk(KERN_INFO
29735 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
29736 current->comm, from, to);
29737 +#endif
29738 return 0;
29739 }
29740 cursor += PAGE_SIZE;
29741 @@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29742 }
29743 return 1;
29744 }
29745 +#elif defined(CONFIG_GRKERNSEC_KMEM)
29746 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29747 +{
29748 + return 0;
29749 +}
29750 #else
29751 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29752 {
29753 @@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29754
29755 while (count > 0) {
29756 unsigned long remaining;
29757 + char *temp;
29758
29759 sz = size_inside_page(p, count);
29760
29761 @@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29762 if (!ptr)
29763 return -EFAULT;
29764
29765 - remaining = copy_to_user(buf, ptr, sz);
29766 +#ifdef CONFIG_PAX_USERCOPY
29767 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29768 + if (!temp) {
29769 + unxlate_dev_mem_ptr(p, ptr);
29770 + return -ENOMEM;
29771 + }
29772 + memcpy(temp, ptr, sz);
29773 +#else
29774 + temp = ptr;
29775 +#endif
29776 +
29777 + remaining = copy_to_user(buf, temp, sz);
29778 +
29779 +#ifdef CONFIG_PAX_USERCOPY
29780 + kfree(temp);
29781 +#endif
29782 +
29783 unxlate_dev_mem_ptr(p, ptr);
29784 if (remaining)
29785 return -EFAULT;
29786 @@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29787 size_t count, loff_t *ppos)
29788 {
29789 unsigned long p = *ppos;
29790 - ssize_t low_count, read, sz;
29791 + ssize_t low_count, read, sz, err = 0;
29792 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
29793 - int err = 0;
29794
29795 read = 0;
29796 if (p < (unsigned long) high_memory) {
29797 @@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29798 }
29799 #endif
29800 while (low_count > 0) {
29801 + char *temp;
29802 +
29803 sz = size_inside_page(p, low_count);
29804
29805 /*
29806 @@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29807 */
29808 kbuf = xlate_dev_kmem_ptr((char *)p);
29809
29810 - if (copy_to_user(buf, kbuf, sz))
29811 +#ifdef CONFIG_PAX_USERCOPY
29812 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29813 + if (!temp)
29814 + return -ENOMEM;
29815 + memcpy(temp, kbuf, sz);
29816 +#else
29817 + temp = kbuf;
29818 +#endif
29819 +
29820 + err = copy_to_user(buf, temp, sz);
29821 +
29822 +#ifdef CONFIG_PAX_USERCOPY
29823 + kfree(temp);
29824 +#endif
29825 +
29826 + if (err)
29827 return -EFAULT;
29828 buf += sz;
29829 p += sz;
29830 @@ -833,6 +880,9 @@ static const struct memdev {
29831 #ifdef CONFIG_CRASH_DUMP
29832 [12] = { "oldmem", 0, &oldmem_fops, NULL },
29833 #endif
29834 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29835 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
29836 +#endif
29837 };
29838
29839 static int memory_open(struct inode *inode, struct file *filp)
29840 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
29841 index 9df78e2..01ba9ae 100644
29842 --- a/drivers/char/nvram.c
29843 +++ b/drivers/char/nvram.c
29844 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
29845
29846 spin_unlock_irq(&rtc_lock);
29847
29848 - if (copy_to_user(buf, contents, tmp - contents))
29849 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
29850 return -EFAULT;
29851
29852 *ppos = i;
29853 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
29854 index 0a484b4..f48ccd1 100644
29855 --- a/drivers/char/pcmcia/synclink_cs.c
29856 +++ b/drivers/char/pcmcia/synclink_cs.c
29857 @@ -2340,9 +2340,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29858
29859 if (debug_level >= DEBUG_LEVEL_INFO)
29860 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
29861 - __FILE__,__LINE__, info->device_name, port->count);
29862 + __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
29863
29864 - WARN_ON(!port->count);
29865 + WARN_ON(!atomic_read(&port->count));
29866
29867 if (tty_port_close_start(port, tty, filp) == 0)
29868 goto cleanup;
29869 @@ -2360,7 +2360,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29870 cleanup:
29871 if (debug_level >= DEBUG_LEVEL_INFO)
29872 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
29873 - tty->driver->name, port->count);
29874 + tty->driver->name, atomic_read(&port->count));
29875 }
29876
29877 /* Wait until the transmitter is empty.
29878 @@ -2502,7 +2502,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29879
29880 if (debug_level >= DEBUG_LEVEL_INFO)
29881 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
29882 - __FILE__,__LINE__,tty->driver->name, port->count);
29883 + __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
29884
29885 /* If port is closing, signal caller to try again */
29886 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
29887 @@ -2522,11 +2522,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29888 goto cleanup;
29889 }
29890 spin_lock(&port->lock);
29891 - port->count++;
29892 + atomic_inc(&port->count);
29893 spin_unlock(&port->lock);
29894 spin_unlock_irqrestore(&info->netlock, flags);
29895
29896 - if (port->count == 1) {
29897 + if (atomic_read(&port->count) == 1) {
29898 /* 1st open on this device, init hardware */
29899 retval = startup(info, tty);
29900 if (retval < 0)
29901 @@ -3891,7 +3891,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
29902 unsigned short new_crctype;
29903
29904 /* return error if TTY interface open */
29905 - if (info->port.count)
29906 + if (atomic_read(&info->port.count))
29907 return -EBUSY;
29908
29909 switch (encoding)
29910 @@ -3994,7 +3994,7 @@ static int hdlcdev_open(struct net_device *dev)
29911
29912 /* arbitrate between network and tty opens */
29913 spin_lock_irqsave(&info->netlock, flags);
29914 - if (info->port.count != 0 || info->netcount != 0) {
29915 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
29916 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
29917 spin_unlock_irqrestore(&info->netlock, flags);
29918 return -EBUSY;
29919 @@ -4083,7 +4083,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
29920 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
29921
29922 /* return error if TTY interface open */
29923 - if (info->port.count)
29924 + if (atomic_read(&info->port.count))
29925 return -EBUSY;
29926
29927 if (cmd != SIOCWANDEV)
29928 diff --git a/drivers/char/random.c b/drivers/char/random.c
29929 index b86eae9..4192a7a 100644
29930 --- a/drivers/char/random.c
29931 +++ b/drivers/char/random.c
29932 @@ -272,8 +272,13 @@
29933 /*
29934 * Configuration information
29935 */
29936 +#ifdef CONFIG_GRKERNSEC_RANDNET
29937 +#define INPUT_POOL_WORDS 512
29938 +#define OUTPUT_POOL_WORDS 128
29939 +#else
29940 #define INPUT_POOL_WORDS 128
29941 #define OUTPUT_POOL_WORDS 32
29942 +#endif
29943 #define SEC_XFER_SIZE 512
29944 #define EXTRACT_SIZE 10
29945
29946 @@ -313,10 +318,17 @@ static struct poolinfo {
29947 int poolwords;
29948 int tap1, tap2, tap3, tap4, tap5;
29949 } poolinfo_table[] = {
29950 +#ifdef CONFIG_GRKERNSEC_RANDNET
29951 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
29952 + { 512, 411, 308, 208, 104, 1 },
29953 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
29954 + { 128, 103, 76, 51, 25, 1 },
29955 +#else
29956 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
29957 { 128, 103, 76, 51, 25, 1 },
29958 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
29959 { 32, 26, 20, 14, 7, 1 },
29960 +#endif
29961 #if 0
29962 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
29963 { 2048, 1638, 1231, 819, 411, 1 },
29964 @@ -527,8 +539,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
29965 input_rotate += i ? 7 : 14;
29966 }
29967
29968 - ACCESS_ONCE(r->input_rotate) = input_rotate;
29969 - ACCESS_ONCE(r->add_ptr) = i;
29970 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
29971 + ACCESS_ONCE_RW(r->add_ptr) = i;
29972 smp_wmb();
29973
29974 if (out)
29975 @@ -799,6 +811,17 @@ void add_disk_randomness(struct gendisk *disk)
29976 }
29977 #endif
29978
29979 +#ifdef CONFIG_PAX_LATENT_ENTROPY
29980 +u64 latent_entropy;
29981 +
29982 +__init void transfer_latent_entropy(void)
29983 +{
29984 + mix_pool_bytes(&input_pool, &latent_entropy, sizeof(latent_entropy), NULL);
29985 + mix_pool_bytes(&nonblocking_pool, &latent_entropy, sizeof(latent_entropy), NULL);
29986 +// printk(KERN_INFO "PAX: transferring latent entropy: %16llx\n", latent_entropy);
29987 +}
29988 +#endif
29989 +
29990 /*********************************************************************
29991 *
29992 * Entropy extraction routines
29993 @@ -1008,7 +1031,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
29994
29995 extract_buf(r, tmp);
29996 i = min_t(int, nbytes, EXTRACT_SIZE);
29997 - if (copy_to_user(buf, tmp, i)) {
29998 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
29999 ret = -EFAULT;
30000 break;
30001 }
30002 @@ -1342,7 +1365,7 @@ EXPORT_SYMBOL(generate_random_uuid);
30003 #include <linux/sysctl.h>
30004
30005 static int min_read_thresh = 8, min_write_thresh;
30006 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
30007 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
30008 static int max_write_thresh = INPUT_POOL_WORDS * 32;
30009 static char sysctl_bootid[16];
30010
30011 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
30012 index f877805..403375a 100644
30013 --- a/drivers/char/sonypi.c
30014 +++ b/drivers/char/sonypi.c
30015 @@ -54,6 +54,7 @@
30016
30017 #include <asm/uaccess.h>
30018 #include <asm/io.h>
30019 +#include <asm/local.h>
30020
30021 #include <linux/sonypi.h>
30022
30023 @@ -490,7 +491,7 @@ static struct sonypi_device {
30024 spinlock_t fifo_lock;
30025 wait_queue_head_t fifo_proc_list;
30026 struct fasync_struct *fifo_async;
30027 - int open_count;
30028 + local_t open_count;
30029 int model;
30030 struct input_dev *input_jog_dev;
30031 struct input_dev *input_key_dev;
30032 @@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
30033 static int sonypi_misc_release(struct inode *inode, struct file *file)
30034 {
30035 mutex_lock(&sonypi_device.lock);
30036 - sonypi_device.open_count--;
30037 + local_dec(&sonypi_device.open_count);
30038 mutex_unlock(&sonypi_device.lock);
30039 return 0;
30040 }
30041 @@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
30042 {
30043 mutex_lock(&sonypi_device.lock);
30044 /* Flush input queue on first open */
30045 - if (!sonypi_device.open_count)
30046 + if (!local_read(&sonypi_device.open_count))
30047 kfifo_reset(&sonypi_device.fifo);
30048 - sonypi_device.open_count++;
30049 + local_inc(&sonypi_device.open_count);
30050 mutex_unlock(&sonypi_device.lock);
30051
30052 return 0;
30053 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
30054 index 4dc8024..90108d1 100644
30055 --- a/drivers/char/tpm/tpm.c
30056 +++ b/drivers/char/tpm/tpm.c
30057 @@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
30058 chip->vendor.req_complete_val)
30059 goto out_recv;
30060
30061 - if ((status == chip->vendor.req_canceled)) {
30062 + if (status == chip->vendor.req_canceled) {
30063 dev_err(chip->dev, "Operation Canceled\n");
30064 rc = -ECANCELED;
30065 goto out;
30066 diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
30067 index 0636520..169c1d0 100644
30068 --- a/drivers/char/tpm/tpm_bios.c
30069 +++ b/drivers/char/tpm/tpm_bios.c
30070 @@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
30071 event = addr;
30072
30073 if ((event->event_type == 0 && event->event_size == 0) ||
30074 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
30075 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
30076 return NULL;
30077
30078 return addr;
30079 @@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
30080 return NULL;
30081
30082 if ((event->event_type == 0 && event->event_size == 0) ||
30083 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
30084 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
30085 return NULL;
30086
30087 (*pos)++;
30088 @@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
30089 int i;
30090
30091 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
30092 - seq_putc(m, data[i]);
30093 + if (!seq_putc(m, data[i]))
30094 + return -EFAULT;
30095
30096 return 0;
30097 }
30098 @@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
30099 log->bios_event_log_end = log->bios_event_log + len;
30100
30101 virt = acpi_os_map_memory(start, len);
30102 + if (!virt) {
30103 + kfree(log->bios_event_log);
30104 + log->bios_event_log = NULL;
30105 + return -EFAULT;
30106 + }
30107
30108 - memcpy(log->bios_event_log, virt, len);
30109 + memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
30110
30111 acpi_os_unmap_memory(virt, len);
30112 return 0;
30113 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
30114 index cdf2f54..e55c197 100644
30115 --- a/drivers/char/virtio_console.c
30116 +++ b/drivers/char/virtio_console.c
30117 @@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
30118 if (to_user) {
30119 ssize_t ret;
30120
30121 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
30122 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
30123 if (ret)
30124 return -EFAULT;
30125 } else {
30126 @@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
30127 if (!port_has_data(port) && !port->host_connected)
30128 return 0;
30129
30130 - return fill_readbuf(port, ubuf, count, true);
30131 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
30132 }
30133
30134 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
30135 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
30136 index e164c55..3aabb50 100644
30137 --- a/drivers/edac/edac_pci_sysfs.c
30138 +++ b/drivers/edac/edac_pci_sysfs.c
30139 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
30140 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
30141 static int edac_pci_poll_msec = 1000; /* one second workq period */
30142
30143 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
30144 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
30145 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
30146 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
30147
30148 static struct kobject *edac_pci_top_main_kobj;
30149 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
30150 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30151 edac_printk(KERN_CRIT, EDAC_PCI,
30152 "Signaled System Error on %s\n",
30153 pci_name(dev));
30154 - atomic_inc(&pci_nonparity_count);
30155 + atomic_inc_unchecked(&pci_nonparity_count);
30156 }
30157
30158 if (status & (PCI_STATUS_PARITY)) {
30159 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30160 "Master Data Parity Error on %s\n",
30161 pci_name(dev));
30162
30163 - atomic_inc(&pci_parity_count);
30164 + atomic_inc_unchecked(&pci_parity_count);
30165 }
30166
30167 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30168 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30169 "Detected Parity Error on %s\n",
30170 pci_name(dev));
30171
30172 - atomic_inc(&pci_parity_count);
30173 + atomic_inc_unchecked(&pci_parity_count);
30174 }
30175 }
30176
30177 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30178 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
30179 "Signaled System Error on %s\n",
30180 pci_name(dev));
30181 - atomic_inc(&pci_nonparity_count);
30182 + atomic_inc_unchecked(&pci_nonparity_count);
30183 }
30184
30185 if (status & (PCI_STATUS_PARITY)) {
30186 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30187 "Master Data Parity Error on "
30188 "%s\n", pci_name(dev));
30189
30190 - atomic_inc(&pci_parity_count);
30191 + atomic_inc_unchecked(&pci_parity_count);
30192 }
30193
30194 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30195 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30196 "Detected Parity Error on %s\n",
30197 pci_name(dev));
30198
30199 - atomic_inc(&pci_parity_count);
30200 + atomic_inc_unchecked(&pci_parity_count);
30201 }
30202 }
30203 }
30204 @@ -676,7 +676,7 @@ void edac_pci_do_parity_check(void)
30205 if (!check_pci_errors)
30206 return;
30207
30208 - before_count = atomic_read(&pci_parity_count);
30209 + before_count = atomic_read_unchecked(&pci_parity_count);
30210
30211 /* scan all PCI devices looking for a Parity Error on devices and
30212 * bridges.
30213 @@ -688,7 +688,7 @@ void edac_pci_do_parity_check(void)
30214 /* Only if operator has selected panic on PCI Error */
30215 if (edac_pci_get_panic_on_pe()) {
30216 /* If the count is different 'after' from 'before' */
30217 - if (before_count != atomic_read(&pci_parity_count))
30218 + if (before_count != atomic_read_unchecked(&pci_parity_count))
30219 panic("EDAC: PCI Parity Error");
30220 }
30221 }
30222 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
30223 index 8c87a5e..a19cbd7 100644
30224 --- a/drivers/edac/mce_amd.h
30225 +++ b/drivers/edac/mce_amd.h
30226 @@ -80,7 +80,7 @@ extern const char * const ii_msgs[];
30227 struct amd_decoder_ops {
30228 bool (*dc_mce)(u16, u8);
30229 bool (*ic_mce)(u16, u8);
30230 -};
30231 +} __no_const;
30232
30233 void amd_report_gart_errors(bool);
30234 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
30235 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
30236 index 57ea7f4..789e3c3 100644
30237 --- a/drivers/firewire/core-card.c
30238 +++ b/drivers/firewire/core-card.c
30239 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
30240
30241 void fw_core_remove_card(struct fw_card *card)
30242 {
30243 - struct fw_card_driver dummy_driver = dummy_driver_template;
30244 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
30245
30246 card->driver->update_phy_reg(card, 4,
30247 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
30248 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
30249 index f8d2287..5aaf4db 100644
30250 --- a/drivers/firewire/core-cdev.c
30251 +++ b/drivers/firewire/core-cdev.c
30252 @@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
30253 int ret;
30254
30255 if ((request->channels == 0 && request->bandwidth == 0) ||
30256 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
30257 - request->bandwidth < 0)
30258 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
30259 return -EINVAL;
30260
30261 r = kmalloc(sizeof(*r), GFP_KERNEL);
30262 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
30263 index 87d6f2d..5bf9d90 100644
30264 --- a/drivers/firewire/core-transaction.c
30265 +++ b/drivers/firewire/core-transaction.c
30266 @@ -37,6 +37,7 @@
30267 #include <linux/timer.h>
30268 #include <linux/types.h>
30269 #include <linux/workqueue.h>
30270 +#include <linux/sched.h>
30271
30272 #include <asm/byteorder.h>
30273
30274 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
30275 index 515a42c..5ecf3ba 100644
30276 --- a/drivers/firewire/core.h
30277 +++ b/drivers/firewire/core.h
30278 @@ -111,6 +111,7 @@ struct fw_card_driver {
30279
30280 int (*stop_iso)(struct fw_iso_context *ctx);
30281 };
30282 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
30283
30284 void fw_card_initialize(struct fw_card *card,
30285 const struct fw_card_driver *driver, struct device *device);
30286 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
30287 index b298158..7ed8432 100644
30288 --- a/drivers/firmware/dmi_scan.c
30289 +++ b/drivers/firmware/dmi_scan.c
30290 @@ -452,11 +452,6 @@ void __init dmi_scan_machine(void)
30291 }
30292 }
30293 else {
30294 - /*
30295 - * no iounmap() for that ioremap(); it would be a no-op, but
30296 - * it's so early in setup that sucker gets confused into doing
30297 - * what it shouldn't if we actually call it.
30298 - */
30299 p = dmi_ioremap(0xF0000, 0x10000);
30300 if (p == NULL)
30301 goto error;
30302 @@ -726,7 +721,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
30303 if (buf == NULL)
30304 return -1;
30305
30306 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
30307 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
30308
30309 iounmap(buf);
30310 return 0;
30311 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
30312 index 82d5c20..44a7177 100644
30313 --- a/drivers/gpio/gpio-vr41xx.c
30314 +++ b/drivers/gpio/gpio-vr41xx.c
30315 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
30316 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
30317 maskl, pendl, maskh, pendh);
30318
30319 - atomic_inc(&irq_err_count);
30320 + atomic_inc_unchecked(&irq_err_count);
30321
30322 return -EINVAL;
30323 }
30324 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
30325 index 3252e70..b5314ace 100644
30326 --- a/drivers/gpu/drm/drm_crtc_helper.c
30327 +++ b/drivers/gpu/drm/drm_crtc_helper.c
30328 @@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
30329 struct drm_crtc *tmp;
30330 int crtc_mask = 1;
30331
30332 - WARN(!crtc, "checking null crtc?\n");
30333 + BUG_ON(!crtc);
30334
30335 dev = crtc->dev;
30336
30337 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
30338 index 9238de4..a27c72a 100644
30339 --- a/drivers/gpu/drm/drm_drv.c
30340 +++ b/drivers/gpu/drm/drm_drv.c
30341 @@ -307,7 +307,7 @@ module_exit(drm_core_exit);
30342 /**
30343 * Copy and IOCTL return string to user space
30344 */
30345 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
30346 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
30347 {
30348 int len;
30349
30350 @@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
30351 return -ENODEV;
30352
30353 atomic_inc(&dev->ioctl_count);
30354 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
30355 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
30356 ++file_priv->ioctl_count;
30357
30358 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
30359 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
30360 index 5062eec..4e3e51f 100644
30361 --- a/drivers/gpu/drm/drm_fops.c
30362 +++ b/drivers/gpu/drm/drm_fops.c
30363 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
30364 }
30365
30366 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30367 - atomic_set(&dev->counts[i], 0);
30368 + atomic_set_unchecked(&dev->counts[i], 0);
30369
30370 dev->sigdata.lock = NULL;
30371
30372 @@ -134,8 +134,8 @@ int drm_open(struct inode *inode, struct file *filp)
30373
30374 retcode = drm_open_helper(inode, filp, dev);
30375 if (!retcode) {
30376 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30377 - if (!dev->open_count++)
30378 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30379 + if (local_inc_return(&dev->open_count) == 1)
30380 retcode = drm_setup(dev);
30381 }
30382 if (!retcode) {
30383 @@ -422,7 +422,7 @@ int drm_release(struct inode *inode, struct file *filp)
30384
30385 mutex_lock(&drm_global_mutex);
30386
30387 - DRM_DEBUG("open_count = %d\n", dev->open_count);
30388 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
30389
30390 if (dev->driver->preclose)
30391 dev->driver->preclose(dev, file_priv);
30392 @@ -431,10 +431,10 @@ int drm_release(struct inode *inode, struct file *filp)
30393 * Begin inline drm_release
30394 */
30395
30396 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30397 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
30398 task_pid_nr(current),
30399 (long)old_encode_dev(file_priv->minor->device),
30400 - dev->open_count);
30401 + local_read(&dev->open_count));
30402
30403 /* Release any auth tokens that might point to this file_priv,
30404 (do that under the drm_global_mutex) */
30405 @@ -530,8 +530,8 @@ int drm_release(struct inode *inode, struct file *filp)
30406 * End inline drm_release
30407 */
30408
30409 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30410 - if (!--dev->open_count) {
30411 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30412 + if (local_dec_and_test(&dev->open_count)) {
30413 if (atomic_read(&dev->ioctl_count)) {
30414 DRM_ERROR("Device busy: %d\n",
30415 atomic_read(&dev->ioctl_count));
30416 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30417 index c87dc96..326055d 100644
30418 --- a/drivers/gpu/drm/drm_global.c
30419 +++ b/drivers/gpu/drm/drm_global.c
30420 @@ -36,7 +36,7 @@
30421 struct drm_global_item {
30422 struct mutex mutex;
30423 void *object;
30424 - int refcount;
30425 + atomic_t refcount;
30426 };
30427
30428 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30429 @@ -49,7 +49,7 @@ void drm_global_init(void)
30430 struct drm_global_item *item = &glob[i];
30431 mutex_init(&item->mutex);
30432 item->object = NULL;
30433 - item->refcount = 0;
30434 + atomic_set(&item->refcount, 0);
30435 }
30436 }
30437
30438 @@ -59,7 +59,7 @@ void drm_global_release(void)
30439 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30440 struct drm_global_item *item = &glob[i];
30441 BUG_ON(item->object != NULL);
30442 - BUG_ON(item->refcount != 0);
30443 + BUG_ON(atomic_read(&item->refcount) != 0);
30444 }
30445 }
30446
30447 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30448 void *object;
30449
30450 mutex_lock(&item->mutex);
30451 - if (item->refcount == 0) {
30452 + if (atomic_read(&item->refcount) == 0) {
30453 item->object = kzalloc(ref->size, GFP_KERNEL);
30454 if (unlikely(item->object == NULL)) {
30455 ret = -ENOMEM;
30456 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30457 goto out_err;
30458
30459 }
30460 - ++item->refcount;
30461 + atomic_inc(&item->refcount);
30462 ref->object = item->object;
30463 object = item->object;
30464 mutex_unlock(&item->mutex);
30465 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30466 struct drm_global_item *item = &glob[ref->global_type];
30467
30468 mutex_lock(&item->mutex);
30469 - BUG_ON(item->refcount == 0);
30470 + BUG_ON(atomic_read(&item->refcount) == 0);
30471 BUG_ON(ref->object != item->object);
30472 - if (--item->refcount == 0) {
30473 + if (atomic_dec_and_test(&item->refcount)) {
30474 ref->release(ref);
30475 item->object = NULL;
30476 }
30477 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30478 index 8928edb..0c79258 100644
30479 --- a/drivers/gpu/drm/drm_info.c
30480 +++ b/drivers/gpu/drm/drm_info.c
30481 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30482 struct drm_local_map *map;
30483 struct drm_map_list *r_list;
30484
30485 - /* Hardcoded from _DRM_FRAME_BUFFER,
30486 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30487 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30488 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30489 + static const char * const types[] = {
30490 + [_DRM_FRAME_BUFFER] = "FB",
30491 + [_DRM_REGISTERS] = "REG",
30492 + [_DRM_SHM] = "SHM",
30493 + [_DRM_AGP] = "AGP",
30494 + [_DRM_SCATTER_GATHER] = "SG",
30495 + [_DRM_CONSISTENT] = "PCI",
30496 + [_DRM_GEM] = "GEM" };
30497 const char *type;
30498 int i;
30499
30500 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30501 map = r_list->map;
30502 if (!map)
30503 continue;
30504 - if (map->type < 0 || map->type > 5)
30505 + if (map->type >= ARRAY_SIZE(types))
30506 type = "??";
30507 else
30508 type = types[map->type];
30509 @@ -254,7 +258,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30510 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30511 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30512 vma->vm_flags & VM_IO ? 'i' : '-',
30513 +#ifdef CONFIG_GRKERNSEC_HIDESYM
30514 + 0);
30515 +#else
30516 vma->vm_pgoff);
30517 +#endif
30518
30519 #if defined(__i386__)
30520 pgprot = pgprot_val(vma->vm_page_prot);
30521 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30522 index 637fcc3..e890b33 100644
30523 --- a/drivers/gpu/drm/drm_ioc32.c
30524 +++ b/drivers/gpu/drm/drm_ioc32.c
30525 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30526 request = compat_alloc_user_space(nbytes);
30527 if (!access_ok(VERIFY_WRITE, request, nbytes))
30528 return -EFAULT;
30529 - list = (struct drm_buf_desc *) (request + 1);
30530 + list = (struct drm_buf_desc __user *) (request + 1);
30531
30532 if (__put_user(count, &request->count)
30533 || __put_user(list, &request->list))
30534 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30535 request = compat_alloc_user_space(nbytes);
30536 if (!access_ok(VERIFY_WRITE, request, nbytes))
30537 return -EFAULT;
30538 - list = (struct drm_buf_pub *) (request + 1);
30539 + list = (struct drm_buf_pub __user *) (request + 1);
30540
30541 if (__put_user(count, &request->count)
30542 || __put_user(list, &request->list))
30543 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30544 index 64a62c6..ceab35e 100644
30545 --- a/drivers/gpu/drm/drm_ioctl.c
30546 +++ b/drivers/gpu/drm/drm_ioctl.c
30547 @@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30548 stats->data[i].value =
30549 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30550 else
30551 - stats->data[i].value = atomic_read(&dev->counts[i]);
30552 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30553 stats->data[i].type = dev->types[i];
30554 }
30555
30556 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30557 index 3203955..c8090af 100644
30558 --- a/drivers/gpu/drm/drm_lock.c
30559 +++ b/drivers/gpu/drm/drm_lock.c
30560 @@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30561 if (drm_lock_take(&master->lock, lock->context)) {
30562 master->lock.file_priv = file_priv;
30563 master->lock.lock_time = jiffies;
30564 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30565 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30566 break; /* Got lock */
30567 }
30568
30569 @@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30570 return -EINVAL;
30571 }
30572
30573 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30574 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30575
30576 if (drm_lock_free(&master->lock, lock->context)) {
30577 /* FIXME: Should really bail out here. */
30578 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
30579 index 21bcd4a..8e074e0 100644
30580 --- a/drivers/gpu/drm/drm_stub.c
30581 +++ b/drivers/gpu/drm/drm_stub.c
30582 @@ -511,7 +511,7 @@ void drm_unplug_dev(struct drm_device *dev)
30583
30584 drm_device_set_unplugged(dev);
30585
30586 - if (dev->open_count == 0) {
30587 + if (local_read(&dev->open_count) == 0) {
30588 drm_put_dev(dev);
30589 }
30590 mutex_unlock(&drm_global_mutex);
30591 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30592 index 463ec68..f5bd2b5 100644
30593 --- a/drivers/gpu/drm/i810/i810_dma.c
30594 +++ b/drivers/gpu/drm/i810/i810_dma.c
30595 @@ -946,8 +946,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30596 dma->buflist[vertex->idx],
30597 vertex->discard, vertex->used);
30598
30599 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30600 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30601 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30602 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30603 sarea_priv->last_enqueue = dev_priv->counter - 1;
30604 sarea_priv->last_dispatch = (int)hw_status[5];
30605
30606 @@ -1107,8 +1107,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30607 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30608 mc->last_render);
30609
30610 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30611 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30612 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30613 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30614 sarea_priv->last_enqueue = dev_priv->counter - 1;
30615 sarea_priv->last_dispatch = (int)hw_status[5];
30616
30617 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30618 index 6e0acad..93c8289 100644
30619 --- a/drivers/gpu/drm/i810/i810_drv.h
30620 +++ b/drivers/gpu/drm/i810/i810_drv.h
30621 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30622 int page_flipping;
30623
30624 wait_queue_head_t irq_queue;
30625 - atomic_t irq_received;
30626 - atomic_t irq_emitted;
30627 + atomic_unchecked_t irq_received;
30628 + atomic_unchecked_t irq_emitted;
30629
30630 int front_offset;
30631 } drm_i810_private_t;
30632 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30633 index 359f6e8..ada68fd 100644
30634 --- a/drivers/gpu/drm/i915/i915_debugfs.c
30635 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
30636 @@ -518,7 +518,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30637 I915_READ(GTIMR));
30638 }
30639 seq_printf(m, "Interrupts received: %d\n",
30640 - atomic_read(&dev_priv->irq_received));
30641 + atomic_read_unchecked(&dev_priv->irq_received));
30642 for (i = 0; i < I915_NUM_RINGS; i++) {
30643 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30644 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
30645 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30646 index 914c0df..d47d380 100644
30647 --- a/drivers/gpu/drm/i915/i915_dma.c
30648 +++ b/drivers/gpu/drm/i915/i915_dma.c
30649 @@ -1269,7 +1269,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
30650 bool can_switch;
30651
30652 spin_lock(&dev->count_lock);
30653 - can_switch = (dev->open_count == 0);
30654 + can_switch = (local_read(&dev->open_count) == 0);
30655 spin_unlock(&dev->count_lock);
30656 return can_switch;
30657 }
30658 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
30659 index 627fe35..c9a7346 100644
30660 --- a/drivers/gpu/drm/i915/i915_drv.h
30661 +++ b/drivers/gpu/drm/i915/i915_drv.h
30662 @@ -272,12 +272,12 @@ struct drm_i915_display_funcs {
30663 /* render clock increase/decrease */
30664 /* display clock increase/decrease */
30665 /* pll clock increase/decrease */
30666 -};
30667 +} __no_const;
30668
30669 struct drm_i915_gt_funcs {
30670 void (*force_wake_get)(struct drm_i915_private *dev_priv);
30671 void (*force_wake_put)(struct drm_i915_private *dev_priv);
30672 -};
30673 +} __no_const;
30674
30675 struct intel_device_info {
30676 u8 gen;
30677 @@ -408,7 +408,7 @@ typedef struct drm_i915_private {
30678 int current_page;
30679 int page_flipping;
30680
30681 - atomic_t irq_received;
30682 + atomic_unchecked_t irq_received;
30683
30684 /* protects the irq masks */
30685 spinlock_t irq_lock;
30686 @@ -1014,7 +1014,7 @@ struct drm_i915_gem_object {
30687 * will be page flipped away on the next vblank. When it
30688 * reaches 0, dev_priv->pending_flip_queue will be woken up.
30689 */
30690 - atomic_t pending_flip;
30691 + atomic_unchecked_t pending_flip;
30692 };
30693
30694 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
30695 @@ -1482,7 +1482,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
30696 struct drm_i915_private *dev_priv, unsigned port);
30697 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
30698 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
30699 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30700 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30701 {
30702 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
30703 }
30704 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30705 index cdf46b5..e785624 100644
30706 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30707 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30708 @@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
30709 i915_gem_clflush_object(obj);
30710
30711 if (obj->base.pending_write_domain)
30712 - cd->flips |= atomic_read(&obj->pending_flip);
30713 + cd->flips |= atomic_read_unchecked(&obj->pending_flip);
30714
30715 /* The actual obj->write_domain will be updated with
30716 * pending_write_domain after we emit the accumulated flush for all
30717 @@ -907,9 +907,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
30718
30719 static int
30720 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
30721 - int count)
30722 + unsigned int count)
30723 {
30724 - int i;
30725 + unsigned int i;
30726
30727 for (i = 0; i < count; i++) {
30728 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
30729 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
30730 index 73fa3e1..ab2e9b9 100644
30731 --- a/drivers/gpu/drm/i915/i915_irq.c
30732 +++ b/drivers/gpu/drm/i915/i915_irq.c
30733 @@ -514,7 +514,7 @@ static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS)
30734 u32 pipe_stats[I915_MAX_PIPES];
30735 bool blc_event;
30736
30737 - atomic_inc(&dev_priv->irq_received);
30738 + atomic_inc_unchecked(&dev_priv->irq_received);
30739
30740 while (true) {
30741 iir = I915_READ(VLV_IIR);
30742 @@ -661,7 +661,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
30743 irqreturn_t ret = IRQ_NONE;
30744 int i;
30745
30746 - atomic_inc(&dev_priv->irq_received);
30747 + atomic_inc_unchecked(&dev_priv->irq_received);
30748
30749 /* disable master interrupt before clearing iir */
30750 de_ier = I915_READ(DEIER);
30751 @@ -736,7 +736,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
30752 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
30753 u32 hotplug_mask;
30754
30755 - atomic_inc(&dev_priv->irq_received);
30756 + atomic_inc_unchecked(&dev_priv->irq_received);
30757
30758 /* disable master interrupt before clearing iir */
30759 de_ier = I915_READ(DEIER);
30760 @@ -1717,7 +1717,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
30761 {
30762 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30763
30764 - atomic_set(&dev_priv->irq_received, 0);
30765 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30766
30767 I915_WRITE(HWSTAM, 0xeffe);
30768
30769 @@ -1743,7 +1743,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
30770 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30771 int pipe;
30772
30773 - atomic_set(&dev_priv->irq_received, 0);
30774 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30775
30776 /* VLV magic */
30777 I915_WRITE(VLV_IMR, 0);
30778 @@ -2048,7 +2048,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
30779 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30780 int pipe;
30781
30782 - atomic_set(&dev_priv->irq_received, 0);
30783 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30784
30785 for_each_pipe(pipe)
30786 I915_WRITE(PIPESTAT(pipe), 0);
30787 @@ -2099,7 +2099,7 @@ static irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS)
30788 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
30789 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
30790
30791 - atomic_inc(&dev_priv->irq_received);
30792 + atomic_inc_unchecked(&dev_priv->irq_received);
30793
30794 iir = I915_READ16(IIR);
30795 if (iir == 0)
30796 @@ -2184,7 +2184,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
30797 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30798 int pipe;
30799
30800 - atomic_set(&dev_priv->irq_received, 0);
30801 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30802
30803 if (I915_HAS_HOTPLUG(dev)) {
30804 I915_WRITE(PORT_HOTPLUG_EN, 0);
30805 @@ -2279,7 +2279,7 @@ static irqreturn_t i915_irq_handler(DRM_IRQ_ARGS)
30806 };
30807 int pipe, ret = IRQ_NONE;
30808
30809 - atomic_inc(&dev_priv->irq_received);
30810 + atomic_inc_unchecked(&dev_priv->irq_received);
30811
30812 iir = I915_READ(IIR);
30813 do {
30814 @@ -2405,7 +2405,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
30815 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30816 int pipe;
30817
30818 - atomic_set(&dev_priv->irq_received, 0);
30819 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30820
30821 I915_WRITE(PORT_HOTPLUG_EN, 0);
30822 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
30823 @@ -2512,7 +2512,7 @@ static irqreturn_t i965_irq_handler(DRM_IRQ_ARGS)
30824 int irq_received;
30825 int ret = IRQ_NONE, pipe;
30826
30827 - atomic_inc(&dev_priv->irq_received);
30828 + atomic_inc_unchecked(&dev_priv->irq_received);
30829
30830 iir = I915_READ(IIR);
30831
30832 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
30833 index b634f6f..43c62f5 100644
30834 --- a/drivers/gpu/drm/i915/intel_display.c
30835 +++ b/drivers/gpu/drm/i915/intel_display.c
30836 @@ -2182,7 +2182,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
30837
30838 wait_event(dev_priv->pending_flip_queue,
30839 atomic_read(&dev_priv->mm.wedged) ||
30840 - atomic_read(&obj->pending_flip) == 0);
30841 + atomic_read_unchecked(&obj->pending_flip) == 0);
30842
30843 /* Big Hammer, we also need to ensure that any pending
30844 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
30845 @@ -6168,8 +6168,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
30846
30847 obj = work->old_fb_obj;
30848
30849 - atomic_clear_mask(1 << intel_crtc->plane,
30850 - &obj->pending_flip.counter);
30851 + atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
30852
30853 wake_up(&dev_priv->pending_flip_queue);
30854 schedule_work(&work->work);
30855 @@ -6515,7 +6514,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30856 /* Block clients from rendering to the new back buffer until
30857 * the flip occurs and the object is no longer visible.
30858 */
30859 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30860 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30861
30862 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
30863 if (ret)
30864 @@ -6530,7 +6529,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30865 return 0;
30866
30867 cleanup_pending:
30868 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30869 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30870 drm_gem_object_unreference(&work->old_fb_obj->base);
30871 drm_gem_object_unreference(&obj->base);
30872 mutex_unlock(&dev->struct_mutex);
30873 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
30874 index 54558a0..2d97005 100644
30875 --- a/drivers/gpu/drm/mga/mga_drv.h
30876 +++ b/drivers/gpu/drm/mga/mga_drv.h
30877 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
30878 u32 clear_cmd;
30879 u32 maccess;
30880
30881 - atomic_t vbl_received; /**< Number of vblanks received. */
30882 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
30883 wait_queue_head_t fence_queue;
30884 - atomic_t last_fence_retired;
30885 + atomic_unchecked_t last_fence_retired;
30886 u32 next_fence_to_post;
30887
30888 unsigned int fb_cpp;
30889 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
30890 index 2581202..f230a8d9 100644
30891 --- a/drivers/gpu/drm/mga/mga_irq.c
30892 +++ b/drivers/gpu/drm/mga/mga_irq.c
30893 @@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
30894 if (crtc != 0)
30895 return 0;
30896
30897 - return atomic_read(&dev_priv->vbl_received);
30898 + return atomic_read_unchecked(&dev_priv->vbl_received);
30899 }
30900
30901
30902 @@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30903 /* VBLANK interrupt */
30904 if (status & MGA_VLINEPEN) {
30905 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
30906 - atomic_inc(&dev_priv->vbl_received);
30907 + atomic_inc_unchecked(&dev_priv->vbl_received);
30908 drm_handle_vblank(dev, 0);
30909 handled = 1;
30910 }
30911 @@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30912 if ((prim_start & ~0x03) != (prim_end & ~0x03))
30913 MGA_WRITE(MGA_PRIMEND, prim_end);
30914
30915 - atomic_inc(&dev_priv->last_fence_retired);
30916 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
30917 DRM_WAKEUP(&dev_priv->fence_queue);
30918 handled = 1;
30919 }
30920 @@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
30921 * using fences.
30922 */
30923 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
30924 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
30925 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
30926 - *sequence) <= (1 << 23)));
30927
30928 *sequence = cur_fence;
30929 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
30930 index a0a3fe3..209bf10 100644
30931 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
30932 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
30933 @@ -5340,7 +5340,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
30934 struct bit_table {
30935 const char id;
30936 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
30937 -};
30938 +} __no_const;
30939
30940 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
30941
30942 diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
30943 index 4f2cc95..9c6c510 100644
30944 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h
30945 +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
30946 @@ -302,7 +302,7 @@ struct nouveau_exec_engine {
30947 u32 handle, u16 class);
30948 void (*set_tile_region)(struct drm_device *dev, int i);
30949 void (*tlb_flush)(struct drm_device *, int engine);
30950 -};
30951 +} __no_const;
30952
30953 struct nouveau_instmem_engine {
30954 void *priv;
30955 @@ -324,13 +324,13 @@ struct nouveau_instmem_engine {
30956 struct nouveau_mc_engine {
30957 int (*init)(struct drm_device *dev);
30958 void (*takedown)(struct drm_device *dev);
30959 -};
30960 +} __no_const;
30961
30962 struct nouveau_timer_engine {
30963 int (*init)(struct drm_device *dev);
30964 void (*takedown)(struct drm_device *dev);
30965 uint64_t (*read)(struct drm_device *dev);
30966 -};
30967 +} __no_const;
30968
30969 struct nouveau_fb_engine {
30970 int num_tiles;
30971 @@ -547,7 +547,7 @@ struct nouveau_vram_engine {
30972 void (*put)(struct drm_device *, struct nouveau_mem **);
30973
30974 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
30975 -};
30976 +} __no_const;
30977
30978 struct nouveau_engine {
30979 struct nouveau_instmem_engine instmem;
30980 @@ -693,7 +693,7 @@ struct drm_nouveau_private {
30981 struct drm_global_reference mem_global_ref;
30982 struct ttm_bo_global_ref bo_global_ref;
30983 struct ttm_bo_device bdev;
30984 - atomic_t validate_sequence;
30985 + atomic_unchecked_t validate_sequence;
30986 int (*move)(struct nouveau_channel *,
30987 struct ttm_buffer_object *,
30988 struct ttm_mem_reg *, struct ttm_mem_reg *);
30989 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
30990 index af7cfb8..aadc2a3 100644
30991 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
30992 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
30993 @@ -318,7 +318,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
30994 int trycnt = 0;
30995 int ret, i;
30996
30997 - sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
30998 + sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
30999 retry:
31000 if (++trycnt > 100000) {
31001 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
31002 diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
31003 index f5e9584..05934ba 100644
31004 --- a/drivers/gpu/drm/nouveau/nouveau_state.c
31005 +++ b/drivers/gpu/drm/nouveau/nouveau_state.c
31006 @@ -492,7 +492,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
31007 bool can_switch;
31008
31009 spin_lock(&dev->count_lock);
31010 - can_switch = (dev->open_count == 0);
31011 + can_switch = (local_read(&dev->open_count) == 0);
31012 spin_unlock(&dev->count_lock);
31013 return can_switch;
31014 }
31015 diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
31016 index 93240bd..c490f60 100644
31017 --- a/drivers/gpu/drm/nouveau/nv50_sor.c
31018 +++ b/drivers/gpu/drm/nouveau/nv50_sor.c
31019 @@ -304,7 +304,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
31020 }
31021
31022 if (nv_encoder->dcb->type == OUTPUT_DP) {
31023 - struct dp_train_func func = {
31024 + static struct dp_train_func func = {
31025 .link_set = nv50_sor_dp_link_set,
31026 .train_set = nv50_sor_dp_train_set,
31027 .train_adj = nv50_sor_dp_train_adj
31028 diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
31029 index 8a2fc89..3a5cf40 100644
31030 --- a/drivers/gpu/drm/nouveau/nvd0_display.c
31031 +++ b/drivers/gpu/drm/nouveau/nvd0_display.c
31032 @@ -1367,7 +1367,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
31033 nv_wait(dev, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
31034
31035 if (nv_encoder->dcb->type == OUTPUT_DP) {
31036 - struct dp_train_func func = {
31037 + static struct dp_train_func func = {
31038 .link_set = nvd0_sor_dp_link_set,
31039 .train_set = nvd0_sor_dp_train_set,
31040 .train_adj = nvd0_sor_dp_train_adj
31041 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
31042 index bcac90b..53bfc76 100644
31043 --- a/drivers/gpu/drm/r128/r128_cce.c
31044 +++ b/drivers/gpu/drm/r128/r128_cce.c
31045 @@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
31046
31047 /* GH: Simple idle check.
31048 */
31049 - atomic_set(&dev_priv->idle_count, 0);
31050 + atomic_set_unchecked(&dev_priv->idle_count, 0);
31051
31052 /* We don't support anything other than bus-mastering ring mode,
31053 * but the ring can be in either AGP or PCI space for the ring
31054 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
31055 index 930c71b..499aded 100644
31056 --- a/drivers/gpu/drm/r128/r128_drv.h
31057 +++ b/drivers/gpu/drm/r128/r128_drv.h
31058 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
31059 int is_pci;
31060 unsigned long cce_buffers_offset;
31061
31062 - atomic_t idle_count;
31063 + atomic_unchecked_t idle_count;
31064
31065 int page_flipping;
31066 int current_page;
31067 u32 crtc_offset;
31068 u32 crtc_offset_cntl;
31069
31070 - atomic_t vbl_received;
31071 + atomic_unchecked_t vbl_received;
31072
31073 u32 color_fmt;
31074 unsigned int front_offset;
31075 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
31076 index 429d5a0..7e899ed 100644
31077 --- a/drivers/gpu/drm/r128/r128_irq.c
31078 +++ b/drivers/gpu/drm/r128/r128_irq.c
31079 @@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
31080 if (crtc != 0)
31081 return 0;
31082
31083 - return atomic_read(&dev_priv->vbl_received);
31084 + return atomic_read_unchecked(&dev_priv->vbl_received);
31085 }
31086
31087 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31088 @@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31089 /* VBLANK interrupt */
31090 if (status & R128_CRTC_VBLANK_INT) {
31091 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
31092 - atomic_inc(&dev_priv->vbl_received);
31093 + atomic_inc_unchecked(&dev_priv->vbl_received);
31094 drm_handle_vblank(dev, 0);
31095 return IRQ_HANDLED;
31096 }
31097 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
31098 index a9e33ce..09edd4b 100644
31099 --- a/drivers/gpu/drm/r128/r128_state.c
31100 +++ b/drivers/gpu/drm/r128/r128_state.c
31101 @@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
31102
31103 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
31104 {
31105 - if (atomic_read(&dev_priv->idle_count) == 0)
31106 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
31107 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
31108 else
31109 - atomic_set(&dev_priv->idle_count, 0);
31110 + atomic_set_unchecked(&dev_priv->idle_count, 0);
31111 }
31112
31113 #endif
31114 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
31115 index 5a82b6b..9e69c73 100644
31116 --- a/drivers/gpu/drm/radeon/mkregtable.c
31117 +++ b/drivers/gpu/drm/radeon/mkregtable.c
31118 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
31119 regex_t mask_rex;
31120 regmatch_t match[4];
31121 char buf[1024];
31122 - size_t end;
31123 + long end;
31124 int len;
31125 int done = 0;
31126 int r;
31127 unsigned o;
31128 struct offset *offset;
31129 char last_reg_s[10];
31130 - int last_reg;
31131 + unsigned long last_reg;
31132
31133 if (regcomp
31134 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
31135 diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
31136 index 59a1531..3bab49b 100644
31137 --- a/drivers/gpu/drm/radeon/radeon.h
31138 +++ b/drivers/gpu/drm/radeon/radeon.h
31139 @@ -711,7 +711,7 @@ struct r600_blit_cp_primitives {
31140 int x2, int y2);
31141 void (*draw_auto)(struct radeon_device *rdev);
31142 void (*set_default_state)(struct radeon_device *rdev);
31143 -};
31144 +} __no_const;
31145
31146 struct r600_blit {
31147 struct radeon_bo *shader_obj;
31148 @@ -1216,7 +1216,7 @@ struct radeon_asic {
31149 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
31150 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
31151 } pflip;
31152 -};
31153 +} __no_const;
31154
31155 /*
31156 * Asic structures
31157 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
31158 index 7a3daeb..5016171 100644
31159 --- a/drivers/gpu/drm/radeon/radeon_device.c
31160 +++ b/drivers/gpu/drm/radeon/radeon_device.c
31161 @@ -952,7 +952,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
31162 bool can_switch;
31163
31164 spin_lock(&dev->count_lock);
31165 - can_switch = (dev->open_count == 0);
31166 + can_switch = (local_read(&dev->open_count) == 0);
31167 spin_unlock(&dev->count_lock);
31168 return can_switch;
31169 }
31170 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
31171 index a1b59ca..86f2d44 100644
31172 --- a/drivers/gpu/drm/radeon/radeon_drv.h
31173 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
31174 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
31175
31176 /* SW interrupt */
31177 wait_queue_head_t swi_queue;
31178 - atomic_t swi_emitted;
31179 + atomic_unchecked_t swi_emitted;
31180 int vblank_crtc;
31181 uint32_t irq_enable_reg;
31182 uint32_t r500_disp_irq_reg;
31183 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
31184 index 48b7cea..342236f 100644
31185 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
31186 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
31187 @@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
31188 request = compat_alloc_user_space(sizeof(*request));
31189 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
31190 || __put_user(req32.param, &request->param)
31191 - || __put_user((void __user *)(unsigned long)req32.value,
31192 + || __put_user((unsigned long)req32.value,
31193 &request->value))
31194 return -EFAULT;
31195
31196 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
31197 index 00da384..32f972d 100644
31198 --- a/drivers/gpu/drm/radeon/radeon_irq.c
31199 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
31200 @@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
31201 unsigned int ret;
31202 RING_LOCALS;
31203
31204 - atomic_inc(&dev_priv->swi_emitted);
31205 - ret = atomic_read(&dev_priv->swi_emitted);
31206 + atomic_inc_unchecked(&dev_priv->swi_emitted);
31207 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
31208
31209 BEGIN_RING(4);
31210 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
31211 @@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
31212 drm_radeon_private_t *dev_priv =
31213 (drm_radeon_private_t *) dev->dev_private;
31214
31215 - atomic_set(&dev_priv->swi_emitted, 0);
31216 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
31217 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
31218
31219 dev->max_vblank_count = 0x001fffff;
31220 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
31221 index e8422ae..d22d4a8 100644
31222 --- a/drivers/gpu/drm/radeon/radeon_state.c
31223 +++ b/drivers/gpu/drm/radeon/radeon_state.c
31224 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
31225 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
31226 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
31227
31228 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31229 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31230 sarea_priv->nbox * sizeof(depth_boxes[0])))
31231 return -EFAULT;
31232
31233 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
31234 {
31235 drm_radeon_private_t *dev_priv = dev->dev_private;
31236 drm_radeon_getparam_t *param = data;
31237 - int value;
31238 + int value = 0;
31239
31240 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
31241
31242 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
31243 index 5b71c71..650f9e4 100644
31244 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
31245 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
31246 @@ -822,8 +822,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
31247 }
31248 if (unlikely(ttm_vm_ops == NULL)) {
31249 ttm_vm_ops = vma->vm_ops;
31250 - radeon_ttm_vm_ops = *ttm_vm_ops;
31251 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31252 + pax_open_kernel();
31253 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
31254 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31255 + pax_close_kernel();
31256 }
31257 vma->vm_ops = &radeon_ttm_vm_ops;
31258 return 0;
31259 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
31260 index 3b663fc..57850f4 100644
31261 --- a/drivers/gpu/drm/radeon/rs690.c
31262 +++ b/drivers/gpu/drm/radeon/rs690.c
31263 @@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
31264 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
31265 rdev->pm.sideport_bandwidth.full)
31266 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
31267 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
31268 + read_delay_latency.full = dfixed_const(800 * 1000);
31269 read_delay_latency.full = dfixed_div(read_delay_latency,
31270 rdev->pm.igp_sideport_mclk);
31271 + a.full = dfixed_const(370);
31272 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
31273 } else {
31274 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
31275 rdev->pm.k8_bandwidth.full)
31276 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31277 index ebc6fac..a8313ed 100644
31278 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
31279 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31280 @@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
31281 static int ttm_pool_mm_shrink(struct shrinker *shrink,
31282 struct shrink_control *sc)
31283 {
31284 - static atomic_t start_pool = ATOMIC_INIT(0);
31285 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
31286 unsigned i;
31287 - unsigned pool_offset = atomic_add_return(1, &start_pool);
31288 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
31289 struct ttm_page_pool *pool;
31290 int shrink_pages = sc->nr_to_scan;
31291
31292 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
31293 index 88edacc..1e5412b 100644
31294 --- a/drivers/gpu/drm/via/via_drv.h
31295 +++ b/drivers/gpu/drm/via/via_drv.h
31296 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
31297 typedef uint32_t maskarray_t[5];
31298
31299 typedef struct drm_via_irq {
31300 - atomic_t irq_received;
31301 + atomic_unchecked_t irq_received;
31302 uint32_t pending_mask;
31303 uint32_t enable_mask;
31304 wait_queue_head_t irq_queue;
31305 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
31306 struct timeval last_vblank;
31307 int last_vblank_valid;
31308 unsigned usec_per_vblank;
31309 - atomic_t vbl_received;
31310 + atomic_unchecked_t vbl_received;
31311 drm_via_state_t hc_state;
31312 char pci_buf[VIA_PCI_BUF_SIZE];
31313 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
31314 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
31315 index d391f48..10c8ca3 100644
31316 --- a/drivers/gpu/drm/via/via_irq.c
31317 +++ b/drivers/gpu/drm/via/via_irq.c
31318 @@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
31319 if (crtc != 0)
31320 return 0;
31321
31322 - return atomic_read(&dev_priv->vbl_received);
31323 + return atomic_read_unchecked(&dev_priv->vbl_received);
31324 }
31325
31326 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31327 @@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31328
31329 status = VIA_READ(VIA_REG_INTERRUPT);
31330 if (status & VIA_IRQ_VBLANK_PENDING) {
31331 - atomic_inc(&dev_priv->vbl_received);
31332 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
31333 + atomic_inc_unchecked(&dev_priv->vbl_received);
31334 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
31335 do_gettimeofday(&cur_vblank);
31336 if (dev_priv->last_vblank_valid) {
31337 dev_priv->usec_per_vblank =
31338 @@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31339 dev_priv->last_vblank = cur_vblank;
31340 dev_priv->last_vblank_valid = 1;
31341 }
31342 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
31343 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
31344 DRM_DEBUG("US per vblank is: %u\n",
31345 dev_priv->usec_per_vblank);
31346 }
31347 @@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31348
31349 for (i = 0; i < dev_priv->num_irqs; ++i) {
31350 if (status & cur_irq->pending_mask) {
31351 - atomic_inc(&cur_irq->irq_received);
31352 + atomic_inc_unchecked(&cur_irq->irq_received);
31353 DRM_WAKEUP(&cur_irq->irq_queue);
31354 handled = 1;
31355 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
31356 @@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
31357 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31358 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31359 masks[irq][4]));
31360 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31361 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31362 } else {
31363 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31364 (((cur_irq_sequence =
31365 - atomic_read(&cur_irq->irq_received)) -
31366 + atomic_read_unchecked(&cur_irq->irq_received)) -
31367 *sequence) <= (1 << 23)));
31368 }
31369 *sequence = cur_irq_sequence;
31370 @@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
31371 }
31372
31373 for (i = 0; i < dev_priv->num_irqs; ++i) {
31374 - atomic_set(&cur_irq->irq_received, 0);
31375 + atomic_set_unchecked(&cur_irq->irq_received, 0);
31376 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31377 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31378 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31379 @@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
31380 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31381 case VIA_IRQ_RELATIVE:
31382 irqwait->request.sequence +=
31383 - atomic_read(&cur_irq->irq_received);
31384 + atomic_read_unchecked(&cur_irq->irq_received);
31385 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31386 case VIA_IRQ_ABSOLUTE:
31387 break;
31388 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31389 index 29c984f..4084f1a 100644
31390 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31391 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31392 @@ -263,7 +263,7 @@ struct vmw_private {
31393 * Fencing and IRQs.
31394 */
31395
31396 - atomic_t marker_seq;
31397 + atomic_unchecked_t marker_seq;
31398 wait_queue_head_t fence_queue;
31399 wait_queue_head_t fifo_queue;
31400 int fence_queue_waiters; /* Protected by hw_mutex */
31401 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31402 index a0c2f12..68ae6cb 100644
31403 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31404 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31405 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31406 (unsigned int) min,
31407 (unsigned int) fifo->capabilities);
31408
31409 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31410 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31411 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31412 vmw_marker_queue_init(&fifo->marker_queue);
31413 return vmw_fifo_send_fence(dev_priv, &dummy);
31414 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31415 if (reserveable)
31416 iowrite32(bytes, fifo_mem +
31417 SVGA_FIFO_RESERVED);
31418 - return fifo_mem + (next_cmd >> 2);
31419 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31420 } else {
31421 need_bounce = true;
31422 }
31423 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31424
31425 fm = vmw_fifo_reserve(dev_priv, bytes);
31426 if (unlikely(fm == NULL)) {
31427 - *seqno = atomic_read(&dev_priv->marker_seq);
31428 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31429 ret = -ENOMEM;
31430 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31431 false, 3*HZ);
31432 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31433 }
31434
31435 do {
31436 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31437 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31438 } while (*seqno == 0);
31439
31440 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31441 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31442 index cabc95f..14b3d77 100644
31443 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31444 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31445 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31446 * emitted. Then the fence is stale and signaled.
31447 */
31448
31449 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31450 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31451 > VMW_FENCE_WRAP);
31452
31453 return ret;
31454 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31455
31456 if (fifo_idle)
31457 down_read(&fifo_state->rwsem);
31458 - signal_seq = atomic_read(&dev_priv->marker_seq);
31459 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31460 ret = 0;
31461
31462 for (;;) {
31463 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31464 index 8a8725c..afed796 100644
31465 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31466 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31467 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31468 while (!vmw_lag_lt(queue, us)) {
31469 spin_lock(&queue->lock);
31470 if (list_empty(&queue->head))
31471 - seqno = atomic_read(&dev_priv->marker_seq);
31472 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31473 else {
31474 marker = list_first_entry(&queue->head,
31475 struct vmw_marker, head);
31476 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31477 index 5de3bb3..08e5063 100644
31478 --- a/drivers/hid/hid-core.c
31479 +++ b/drivers/hid/hid-core.c
31480 @@ -2177,7 +2177,7 @@ static bool hid_ignore(struct hid_device *hdev)
31481
31482 int hid_add_device(struct hid_device *hdev)
31483 {
31484 - static atomic_t id = ATOMIC_INIT(0);
31485 + static atomic_unchecked_t id = ATOMIC_INIT(0);
31486 int ret;
31487
31488 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31489 @@ -2212,7 +2212,7 @@ int hid_add_device(struct hid_device *hdev)
31490 /* XXX hack, any other cleaner solution after the driver core
31491 * is converted to allow more than 20 bytes as the device name? */
31492 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31493 - hdev->vendor, hdev->product, atomic_inc_return(&id));
31494 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31495
31496 hid_debug_register(hdev, dev_name(&hdev->dev));
31497 ret = device_add(&hdev->dev);
31498 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
31499 index eec3291..8ed706b 100644
31500 --- a/drivers/hid/hid-wiimote-debug.c
31501 +++ b/drivers/hid/hid-wiimote-debug.c
31502 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
31503 else if (size == 0)
31504 return -EIO;
31505
31506 - if (copy_to_user(u, buf, size))
31507 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
31508 return -EFAULT;
31509
31510 *off += size;
31511 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31512 index 14599e2..711c965 100644
31513 --- a/drivers/hid/usbhid/hiddev.c
31514 +++ b/drivers/hid/usbhid/hiddev.c
31515 @@ -625,7 +625,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31516 break;
31517
31518 case HIDIOCAPPLICATION:
31519 - if (arg < 0 || arg >= hid->maxapplication)
31520 + if (arg >= hid->maxapplication)
31521 break;
31522
31523 for (i = 0; i < hid->maxcollection; i++)
31524 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31525 index f4c3d28..82f45a9 100644
31526 --- a/drivers/hv/channel.c
31527 +++ b/drivers/hv/channel.c
31528 @@ -402,8 +402,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31529 int ret = 0;
31530 int t;
31531
31532 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31533 - atomic_inc(&vmbus_connection.next_gpadl_handle);
31534 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31535 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31536
31537 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31538 if (ret)
31539 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31540 index 86f8885..ab9cb2b 100644
31541 --- a/drivers/hv/hv.c
31542 +++ b/drivers/hv/hv.c
31543 @@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31544 u64 output_address = (output) ? virt_to_phys(output) : 0;
31545 u32 output_address_hi = output_address >> 32;
31546 u32 output_address_lo = output_address & 0xFFFFFFFF;
31547 - void *hypercall_page = hv_context.hypercall_page;
31548 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31549
31550 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31551 "=a"(hv_status_lo) : "d" (control_hi),
31552 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31553 index 0614ff3..f0b2b5c 100644
31554 --- a/drivers/hv/hyperv_vmbus.h
31555 +++ b/drivers/hv/hyperv_vmbus.h
31556 @@ -555,7 +555,7 @@ enum vmbus_connect_state {
31557 struct vmbus_connection {
31558 enum vmbus_connect_state conn_state;
31559
31560 - atomic_t next_gpadl_handle;
31561 + atomic_unchecked_t next_gpadl_handle;
31562
31563 /*
31564 * Represents channel interrupts. Each bit position represents a
31565 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31566 index 4748086..3abf845 100644
31567 --- a/drivers/hv/vmbus_drv.c
31568 +++ b/drivers/hv/vmbus_drv.c
31569 @@ -662,10 +662,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31570 {
31571 int ret = 0;
31572
31573 - static atomic_t device_num = ATOMIC_INIT(0);
31574 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31575
31576 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31577 - atomic_inc_return(&device_num));
31578 + atomic_inc_return_unchecked(&device_num));
31579
31580 child_device_obj->device.bus = &hv_bus;
31581 child_device_obj->device.parent = &hv_acpi_dev->dev;
31582 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31583 index 8b011d0..3de24a1 100644
31584 --- a/drivers/hwmon/sht15.c
31585 +++ b/drivers/hwmon/sht15.c
31586 @@ -166,7 +166,7 @@ struct sht15_data {
31587 int supply_uV;
31588 bool supply_uV_valid;
31589 struct work_struct update_supply_work;
31590 - atomic_t interrupt_handled;
31591 + atomic_unchecked_t interrupt_handled;
31592 };
31593
31594 /**
31595 @@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
31596 return ret;
31597
31598 gpio_direction_input(data->pdata->gpio_data);
31599 - atomic_set(&data->interrupt_handled, 0);
31600 + atomic_set_unchecked(&data->interrupt_handled, 0);
31601
31602 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31603 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31604 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31605 /* Only relevant if the interrupt hasn't occurred. */
31606 - if (!atomic_read(&data->interrupt_handled))
31607 + if (!atomic_read_unchecked(&data->interrupt_handled))
31608 schedule_work(&data->read_work);
31609 }
31610 ret = wait_event_timeout(data->wait_queue,
31611 @@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31612
31613 /* First disable the interrupt */
31614 disable_irq_nosync(irq);
31615 - atomic_inc(&data->interrupt_handled);
31616 + atomic_inc_unchecked(&data->interrupt_handled);
31617 /* Then schedule a reading work struct */
31618 if (data->state != SHT15_READING_NOTHING)
31619 schedule_work(&data->read_work);
31620 @@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31621 * If not, then start the interrupt again - care here as could
31622 * have gone low in meantime so verify it hasn't!
31623 */
31624 - atomic_set(&data->interrupt_handled, 0);
31625 + atomic_set_unchecked(&data->interrupt_handled, 0);
31626 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31627 /* If still not occurred or another handler was scheduled */
31628 if (gpio_get_value(data->pdata->gpio_data)
31629 - || atomic_read(&data->interrupt_handled))
31630 + || atomic_read_unchecked(&data->interrupt_handled))
31631 return;
31632 }
31633
31634 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31635 index 378fcb5..5e91fa8 100644
31636 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
31637 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31638 @@ -43,7 +43,7 @@
31639 extern struct i2c_adapter amd756_smbus;
31640
31641 static struct i2c_adapter *s4882_adapter;
31642 -static struct i2c_algorithm *s4882_algo;
31643 +static i2c_algorithm_no_const *s4882_algo;
31644
31645 /* Wrapper access functions for multiplexed SMBus */
31646 static DEFINE_MUTEX(amd756_lock);
31647 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31648 index 29015eb..af2d8e9 100644
31649 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31650 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
31651 @@ -41,7 +41,7 @@
31652 extern struct i2c_adapter *nforce2_smbus;
31653
31654 static struct i2c_adapter *s4985_adapter;
31655 -static struct i2c_algorithm *s4985_algo;
31656 +static i2c_algorithm_no_const *s4985_algo;
31657
31658 /* Wrapper access functions for multiplexed SMBus */
31659 static DEFINE_MUTEX(nforce2_lock);
31660 diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
31661 index 1038c38..eb92f51 100644
31662 --- a/drivers/i2c/i2c-mux.c
31663 +++ b/drivers/i2c/i2c-mux.c
31664 @@ -30,7 +30,7 @@
31665 /* multiplexer per channel data */
31666 struct i2c_mux_priv {
31667 struct i2c_adapter adap;
31668 - struct i2c_algorithm algo;
31669 + i2c_algorithm_no_const algo;
31670
31671 struct i2c_adapter *parent;
31672 void *mux_priv; /* the mux chip/device */
31673 diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
31674 index 57d00ca..0145194 100644
31675 --- a/drivers/ide/aec62xx.c
31676 +++ b/drivers/ide/aec62xx.c
31677 @@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
31678 .cable_detect = atp86x_cable_detect,
31679 };
31680
31681 -static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
31682 +static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
31683 { /* 0: AEC6210 */
31684 .name = DRV_NAME,
31685 .init_chipset = init_chipset_aec62xx,
31686 diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
31687 index 2c8016a..911a27c 100644
31688 --- a/drivers/ide/alim15x3.c
31689 +++ b/drivers/ide/alim15x3.c
31690 @@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
31691 .dma_sff_read_status = ide_dma_sff_read_status,
31692 };
31693
31694 -static const struct ide_port_info ali15x3_chipset __devinitdata = {
31695 +static const struct ide_port_info ali15x3_chipset __devinitconst = {
31696 .name = DRV_NAME,
31697 .init_chipset = init_chipset_ali15x3,
31698 .init_hwif = init_hwif_ali15x3,
31699 diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
31700 index 3747b25..56fc995 100644
31701 --- a/drivers/ide/amd74xx.c
31702 +++ b/drivers/ide/amd74xx.c
31703 @@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
31704 .udma_mask = udma, \
31705 }
31706
31707 -static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
31708 +static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
31709 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
31710 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
31711 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
31712 diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
31713 index 15f0ead..cb43480 100644
31714 --- a/drivers/ide/atiixp.c
31715 +++ b/drivers/ide/atiixp.c
31716 @@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
31717 .cable_detect = atiixp_cable_detect,
31718 };
31719
31720 -static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
31721 +static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
31722 { /* 0: IXP200/300/400/700 */
31723 .name = DRV_NAME,
31724 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
31725 diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
31726 index 5f80312..d1fc438 100644
31727 --- a/drivers/ide/cmd64x.c
31728 +++ b/drivers/ide/cmd64x.c
31729 @@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
31730 .dma_sff_read_status = ide_dma_sff_read_status,
31731 };
31732
31733 -static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
31734 +static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
31735 { /* 0: CMD643 */
31736 .name = DRV_NAME,
31737 .init_chipset = init_chipset_cmd64x,
31738 diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
31739 index 2c1e5f7..1444762 100644
31740 --- a/drivers/ide/cs5520.c
31741 +++ b/drivers/ide/cs5520.c
31742 @@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
31743 .set_dma_mode = cs5520_set_dma_mode,
31744 };
31745
31746 -static const struct ide_port_info cyrix_chipset __devinitdata = {
31747 +static const struct ide_port_info cyrix_chipset __devinitconst = {
31748 .name = DRV_NAME,
31749 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
31750 .port_ops = &cs5520_port_ops,
31751 diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
31752 index 4dc4eb9..49b40ad 100644
31753 --- a/drivers/ide/cs5530.c
31754 +++ b/drivers/ide/cs5530.c
31755 @@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
31756 .udma_filter = cs5530_udma_filter,
31757 };
31758
31759 -static const struct ide_port_info cs5530_chipset __devinitdata = {
31760 +static const struct ide_port_info cs5530_chipset __devinitconst = {
31761 .name = DRV_NAME,
31762 .init_chipset = init_chipset_cs5530,
31763 .init_hwif = init_hwif_cs5530,
31764 diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
31765 index 5059faf..18d4c85 100644
31766 --- a/drivers/ide/cs5535.c
31767 +++ b/drivers/ide/cs5535.c
31768 @@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
31769 .cable_detect = cs5535_cable_detect,
31770 };
31771
31772 -static const struct ide_port_info cs5535_chipset __devinitdata = {
31773 +static const struct ide_port_info cs5535_chipset __devinitconst = {
31774 .name = DRV_NAME,
31775 .port_ops = &cs5535_port_ops,
31776 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
31777 diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
31778 index 847553f..3ffb49d 100644
31779 --- a/drivers/ide/cy82c693.c
31780 +++ b/drivers/ide/cy82c693.c
31781 @@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
31782 .set_dma_mode = cy82c693_set_dma_mode,
31783 };
31784
31785 -static const struct ide_port_info cy82c693_chipset __devinitdata = {
31786 +static const struct ide_port_info cy82c693_chipset __devinitconst = {
31787 .name = DRV_NAME,
31788 .init_iops = init_iops_cy82c693,
31789 .port_ops = &cy82c693_port_ops,
31790 diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
31791 index 58c51cd..4aec3b8 100644
31792 --- a/drivers/ide/hpt366.c
31793 +++ b/drivers/ide/hpt366.c
31794 @@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
31795 }
31796 };
31797
31798 -static const struct hpt_info hpt36x __devinitdata = {
31799 +static const struct hpt_info hpt36x __devinitconst = {
31800 .chip_name = "HPT36x",
31801 .chip_type = HPT36x,
31802 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
31803 @@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
31804 .timings = &hpt36x_timings
31805 };
31806
31807 -static const struct hpt_info hpt370 __devinitdata = {
31808 +static const struct hpt_info hpt370 __devinitconst = {
31809 .chip_name = "HPT370",
31810 .chip_type = HPT370,
31811 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31812 @@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
31813 .timings = &hpt37x_timings
31814 };
31815
31816 -static const struct hpt_info hpt370a __devinitdata = {
31817 +static const struct hpt_info hpt370a __devinitconst = {
31818 .chip_name = "HPT370A",
31819 .chip_type = HPT370A,
31820 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31821 @@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
31822 .timings = &hpt37x_timings
31823 };
31824
31825 -static const struct hpt_info hpt374 __devinitdata = {
31826 +static const struct hpt_info hpt374 __devinitconst = {
31827 .chip_name = "HPT374",
31828 .chip_type = HPT374,
31829 .udma_mask = ATA_UDMA5,
31830 @@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
31831 .timings = &hpt37x_timings
31832 };
31833
31834 -static const struct hpt_info hpt372 __devinitdata = {
31835 +static const struct hpt_info hpt372 __devinitconst = {
31836 .chip_name = "HPT372",
31837 .chip_type = HPT372,
31838 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31839 @@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
31840 .timings = &hpt37x_timings
31841 };
31842
31843 -static const struct hpt_info hpt372a __devinitdata = {
31844 +static const struct hpt_info hpt372a __devinitconst = {
31845 .chip_name = "HPT372A",
31846 .chip_type = HPT372A,
31847 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31848 @@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
31849 .timings = &hpt37x_timings
31850 };
31851
31852 -static const struct hpt_info hpt302 __devinitdata = {
31853 +static const struct hpt_info hpt302 __devinitconst = {
31854 .chip_name = "HPT302",
31855 .chip_type = HPT302,
31856 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31857 @@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
31858 .timings = &hpt37x_timings
31859 };
31860
31861 -static const struct hpt_info hpt371 __devinitdata = {
31862 +static const struct hpt_info hpt371 __devinitconst = {
31863 .chip_name = "HPT371",
31864 .chip_type = HPT371,
31865 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31866 @@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
31867 .timings = &hpt37x_timings
31868 };
31869
31870 -static const struct hpt_info hpt372n __devinitdata = {
31871 +static const struct hpt_info hpt372n __devinitconst = {
31872 .chip_name = "HPT372N",
31873 .chip_type = HPT372N,
31874 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31875 @@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
31876 .timings = &hpt37x_timings
31877 };
31878
31879 -static const struct hpt_info hpt302n __devinitdata = {
31880 +static const struct hpt_info hpt302n __devinitconst = {
31881 .chip_name = "HPT302N",
31882 .chip_type = HPT302N,
31883 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31884 @@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
31885 .timings = &hpt37x_timings
31886 };
31887
31888 -static const struct hpt_info hpt371n __devinitdata = {
31889 +static const struct hpt_info hpt371n __devinitconst = {
31890 .chip_name = "HPT371N",
31891 .chip_type = HPT371N,
31892 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31893 @@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
31894 .dma_sff_read_status = ide_dma_sff_read_status,
31895 };
31896
31897 -static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
31898 +static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
31899 { /* 0: HPT36x */
31900 .name = DRV_NAME,
31901 .init_chipset = init_chipset_hpt366,
31902 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
31903 index 8126824..55a2798 100644
31904 --- a/drivers/ide/ide-cd.c
31905 +++ b/drivers/ide/ide-cd.c
31906 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
31907 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
31908 if ((unsigned long)buf & alignment
31909 || blk_rq_bytes(rq) & q->dma_pad_mask
31910 - || object_is_on_stack(buf))
31911 + || object_starts_on_stack(buf))
31912 drive->dma = 0;
31913 }
31914 }
31915 diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
31916 index 7f56b73..dab5b67 100644
31917 --- a/drivers/ide/ide-pci-generic.c
31918 +++ b/drivers/ide/ide-pci-generic.c
31919 @@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
31920 .udma_mask = ATA_UDMA6, \
31921 }
31922
31923 -static const struct ide_port_info generic_chipsets[] __devinitdata = {
31924 +static const struct ide_port_info generic_chipsets[] __devinitconst = {
31925 /* 0: Unknown */
31926 DECLARE_GENERIC_PCI_DEV(0),
31927
31928 diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
31929 index 560e66d..d5dd180 100644
31930 --- a/drivers/ide/it8172.c
31931 +++ b/drivers/ide/it8172.c
31932 @@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
31933 .set_dma_mode = it8172_set_dma_mode,
31934 };
31935
31936 -static const struct ide_port_info it8172_port_info __devinitdata = {
31937 +static const struct ide_port_info it8172_port_info __devinitconst = {
31938 .name = DRV_NAME,
31939 .port_ops = &it8172_port_ops,
31940 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
31941 diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
31942 index 46816ba..1847aeb 100644
31943 --- a/drivers/ide/it8213.c
31944 +++ b/drivers/ide/it8213.c
31945 @@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
31946 .cable_detect = it8213_cable_detect,
31947 };
31948
31949 -static const struct ide_port_info it8213_chipset __devinitdata = {
31950 +static const struct ide_port_info it8213_chipset __devinitconst = {
31951 .name = DRV_NAME,
31952 .enablebits = { {0x41, 0x80, 0x80} },
31953 .port_ops = &it8213_port_ops,
31954 diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
31955 index 2e3169f..c5611db 100644
31956 --- a/drivers/ide/it821x.c
31957 +++ b/drivers/ide/it821x.c
31958 @@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
31959 .cable_detect = it821x_cable_detect,
31960 };
31961
31962 -static const struct ide_port_info it821x_chipset __devinitdata = {
31963 +static const struct ide_port_info it821x_chipset __devinitconst = {
31964 .name = DRV_NAME,
31965 .init_chipset = init_chipset_it821x,
31966 .init_hwif = init_hwif_it821x,
31967 diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
31968 index 74c2c4a..efddd7d 100644
31969 --- a/drivers/ide/jmicron.c
31970 +++ b/drivers/ide/jmicron.c
31971 @@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
31972 .cable_detect = jmicron_cable_detect,
31973 };
31974
31975 -static const struct ide_port_info jmicron_chipset __devinitdata = {
31976 +static const struct ide_port_info jmicron_chipset __devinitconst = {
31977 .name = DRV_NAME,
31978 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
31979 .port_ops = &jmicron_port_ops,
31980 diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
31981 index 95327a2..73f78d8 100644
31982 --- a/drivers/ide/ns87415.c
31983 +++ b/drivers/ide/ns87415.c
31984 @@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
31985 .dma_sff_read_status = superio_dma_sff_read_status,
31986 };
31987
31988 -static const struct ide_port_info ns87415_chipset __devinitdata = {
31989 +static const struct ide_port_info ns87415_chipset __devinitconst = {
31990 .name = DRV_NAME,
31991 .init_hwif = init_hwif_ns87415,
31992 .tp_ops = &ns87415_tp_ops,
31993 diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
31994 index 1a53a4c..39edc66 100644
31995 --- a/drivers/ide/opti621.c
31996 +++ b/drivers/ide/opti621.c
31997 @@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
31998 .set_pio_mode = opti621_set_pio_mode,
31999 };
32000
32001 -static const struct ide_port_info opti621_chipset __devinitdata = {
32002 +static const struct ide_port_info opti621_chipset __devinitconst = {
32003 .name = DRV_NAME,
32004 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
32005 .port_ops = &opti621_port_ops,
32006 diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
32007 index 9546fe2..2e5ceb6 100644
32008 --- a/drivers/ide/pdc202xx_new.c
32009 +++ b/drivers/ide/pdc202xx_new.c
32010 @@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
32011 .udma_mask = udma, \
32012 }
32013
32014 -static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
32015 +static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
32016 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
32017 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
32018 };
32019 diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
32020 index 3a35ec6..5634510 100644
32021 --- a/drivers/ide/pdc202xx_old.c
32022 +++ b/drivers/ide/pdc202xx_old.c
32023 @@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
32024 .max_sectors = sectors, \
32025 }
32026
32027 -static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
32028 +static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
32029 { /* 0: PDC20246 */
32030 .name = DRV_NAME,
32031 .init_chipset = init_chipset_pdc202xx,
32032 diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
32033 index 1892e81..fe0fd60 100644
32034 --- a/drivers/ide/piix.c
32035 +++ b/drivers/ide/piix.c
32036 @@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
32037 .udma_mask = udma, \
32038 }
32039
32040 -static const struct ide_port_info piix_pci_info[] __devinitdata = {
32041 +static const struct ide_port_info piix_pci_info[] __devinitconst = {
32042 /* 0: MPIIX */
32043 { /*
32044 * MPIIX actually has only a single IDE channel mapped to
32045 diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
32046 index a6414a8..c04173e 100644
32047 --- a/drivers/ide/rz1000.c
32048 +++ b/drivers/ide/rz1000.c
32049 @@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
32050 }
32051 }
32052
32053 -static const struct ide_port_info rz1000_chipset __devinitdata = {
32054 +static const struct ide_port_info rz1000_chipset __devinitconst = {
32055 .name = DRV_NAME,
32056 .host_flags = IDE_HFLAG_NO_DMA,
32057 };
32058 diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
32059 index 356b9b5..d4758eb 100644
32060 --- a/drivers/ide/sc1200.c
32061 +++ b/drivers/ide/sc1200.c
32062 @@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
32063 .dma_sff_read_status = ide_dma_sff_read_status,
32064 };
32065
32066 -static const struct ide_port_info sc1200_chipset __devinitdata = {
32067 +static const struct ide_port_info sc1200_chipset __devinitconst = {
32068 .name = DRV_NAME,
32069 .port_ops = &sc1200_port_ops,
32070 .dma_ops = &sc1200_dma_ops,
32071 diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
32072 index b7f5b0c..9701038 100644
32073 --- a/drivers/ide/scc_pata.c
32074 +++ b/drivers/ide/scc_pata.c
32075 @@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
32076 .dma_sff_read_status = scc_dma_sff_read_status,
32077 };
32078
32079 -static const struct ide_port_info scc_chipset __devinitdata = {
32080 +static const struct ide_port_info scc_chipset __devinitconst = {
32081 .name = "sccIDE",
32082 .init_iops = init_iops_scc,
32083 .init_dma = scc_init_dma,
32084 diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
32085 index 35fb8da..24d72ef 100644
32086 --- a/drivers/ide/serverworks.c
32087 +++ b/drivers/ide/serverworks.c
32088 @@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
32089 .cable_detect = svwks_cable_detect,
32090 };
32091
32092 -static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
32093 +static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
32094 { /* 0: OSB4 */
32095 .name = DRV_NAME,
32096 .init_chipset = init_chipset_svwks,
32097 diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
32098 index ddeda44..46f7e30 100644
32099 --- a/drivers/ide/siimage.c
32100 +++ b/drivers/ide/siimage.c
32101 @@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
32102 .udma_mask = ATA_UDMA6, \
32103 }
32104
32105 -static const struct ide_port_info siimage_chipsets[] __devinitdata = {
32106 +static const struct ide_port_info siimage_chipsets[] __devinitconst = {
32107 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
32108 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
32109 };
32110 diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
32111 index 4a00225..09e61b4 100644
32112 --- a/drivers/ide/sis5513.c
32113 +++ b/drivers/ide/sis5513.c
32114 @@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
32115 .cable_detect = sis_cable_detect,
32116 };
32117
32118 -static const struct ide_port_info sis5513_chipset __devinitdata = {
32119 +static const struct ide_port_info sis5513_chipset __devinitconst = {
32120 .name = DRV_NAME,
32121 .init_chipset = init_chipset_sis5513,
32122 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
32123 diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
32124 index f21dc2a..d051cd2 100644
32125 --- a/drivers/ide/sl82c105.c
32126 +++ b/drivers/ide/sl82c105.c
32127 @@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
32128 .dma_sff_read_status = ide_dma_sff_read_status,
32129 };
32130
32131 -static const struct ide_port_info sl82c105_chipset __devinitdata = {
32132 +static const struct ide_port_info sl82c105_chipset __devinitconst = {
32133 .name = DRV_NAME,
32134 .init_chipset = init_chipset_sl82c105,
32135 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
32136 diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
32137 index 864ffe0..863a5e9 100644
32138 --- a/drivers/ide/slc90e66.c
32139 +++ b/drivers/ide/slc90e66.c
32140 @@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
32141 .cable_detect = slc90e66_cable_detect,
32142 };
32143
32144 -static const struct ide_port_info slc90e66_chipset __devinitdata = {
32145 +static const struct ide_port_info slc90e66_chipset __devinitconst = {
32146 .name = DRV_NAME,
32147 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
32148 .port_ops = &slc90e66_port_ops,
32149 diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
32150 index 4799d5c..1794678 100644
32151 --- a/drivers/ide/tc86c001.c
32152 +++ b/drivers/ide/tc86c001.c
32153 @@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
32154 .dma_sff_read_status = ide_dma_sff_read_status,
32155 };
32156
32157 -static const struct ide_port_info tc86c001_chipset __devinitdata = {
32158 +static const struct ide_port_info tc86c001_chipset __devinitconst = {
32159 .name = DRV_NAME,
32160 .init_hwif = init_hwif_tc86c001,
32161 .port_ops = &tc86c001_port_ops,
32162 diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
32163 index 281c914..55ce1b8 100644
32164 --- a/drivers/ide/triflex.c
32165 +++ b/drivers/ide/triflex.c
32166 @@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
32167 .set_dma_mode = triflex_set_mode,
32168 };
32169
32170 -static const struct ide_port_info triflex_device __devinitdata = {
32171 +static const struct ide_port_info triflex_device __devinitconst = {
32172 .name = DRV_NAME,
32173 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
32174 .port_ops = &triflex_port_ops,
32175 diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
32176 index 4b42ca0..e494a98 100644
32177 --- a/drivers/ide/trm290.c
32178 +++ b/drivers/ide/trm290.c
32179 @@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
32180 .dma_check = trm290_dma_check,
32181 };
32182
32183 -static const struct ide_port_info trm290_chipset __devinitdata = {
32184 +static const struct ide_port_info trm290_chipset __devinitconst = {
32185 .name = DRV_NAME,
32186 .init_hwif = init_hwif_trm290,
32187 .tp_ops = &trm290_tp_ops,
32188 diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
32189 index f46f49c..eb77678 100644
32190 --- a/drivers/ide/via82cxxx.c
32191 +++ b/drivers/ide/via82cxxx.c
32192 @@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
32193 .cable_detect = via82cxxx_cable_detect,
32194 };
32195
32196 -static const struct ide_port_info via82cxxx_chipset __devinitdata = {
32197 +static const struct ide_port_info via82cxxx_chipset __devinitconst = {
32198 .name = DRV_NAME,
32199 .init_chipset = init_chipset_via82cxxx,
32200 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
32201 diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
32202 index 73d4531..c90cd2d 100644
32203 --- a/drivers/ieee802154/fakehard.c
32204 +++ b/drivers/ieee802154/fakehard.c
32205 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
32206 phy->transmit_power = 0xbf;
32207
32208 dev->netdev_ops = &fake_ops;
32209 - dev->ml_priv = &fake_mlme;
32210 + dev->ml_priv = (void *)&fake_mlme;
32211
32212 priv = netdev_priv(dev);
32213 priv->phy = phy;
32214 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
32215 index d67999f..4c5d083 100644
32216 --- a/drivers/infiniband/core/cm.c
32217 +++ b/drivers/infiniband/core/cm.c
32218 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
32219
32220 struct cm_counter_group {
32221 struct kobject obj;
32222 - atomic_long_t counter[CM_ATTR_COUNT];
32223 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
32224 };
32225
32226 struct cm_counter_attribute {
32227 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
32228 struct ib_mad_send_buf *msg = NULL;
32229 int ret;
32230
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_REQ_COUNTER]);
32234
32235 /* Quick state check to discard duplicate REQs. */
32236 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
32237 if (!cm_id_priv)
32238 return;
32239
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_REP_COUNTER]);
32243 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
32244 if (ret)
32245 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
32246 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
32247 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
32248 spin_unlock_irq(&cm_id_priv->lock);
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_RTU_COUNTER]);
32252 goto out;
32253 }
32254 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
32255 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
32256 dreq_msg->local_comm_id);
32257 if (!cm_id_priv) {
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 cm_issue_drep(work->port, work->mad_recv_wc);
32262 return -EINVAL;
32263 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
32264 case IB_CM_MRA_REP_RCVD:
32265 break;
32266 case IB_CM_TIMEWAIT:
32267 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32268 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32269 counter[CM_DREQ_COUNTER]);
32270 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32271 goto unlock;
32272 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
32273 cm_free_msg(msg);
32274 goto deref;
32275 case IB_CM_DREQ_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_DREQ_COUNTER]);
32279 goto unlock;
32280 default:
32281 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
32282 ib_modify_mad(cm_id_priv->av.port->mad_agent,
32283 cm_id_priv->msg, timeout)) {
32284 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
32285 - atomic_long_inc(&work->port->
32286 + atomic_long_inc_unchecked(&work->port->
32287 counter_group[CM_RECV_DUPLICATES].
32288 counter[CM_MRA_COUNTER]);
32289 goto out;
32290 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
32291 break;
32292 case IB_CM_MRA_REQ_RCVD:
32293 case IB_CM_MRA_REP_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_MRA_COUNTER]);
32297 /* fall through */
32298 default:
32299 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
32300 case IB_CM_LAP_IDLE:
32301 break;
32302 case IB_CM_MRA_LAP_SENT:
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_LAP_COUNTER]);
32306 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32307 goto unlock;
32308 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
32309 cm_free_msg(msg);
32310 goto deref;
32311 case IB_CM_LAP_RCVD:
32312 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32313 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32314 counter[CM_LAP_COUNTER]);
32315 goto unlock;
32316 default:
32317 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
32318 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
32319 if (cur_cm_id_priv) {
32320 spin_unlock_irq(&cm.lock);
32321 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32322 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32323 counter[CM_SIDR_REQ_COUNTER]);
32324 goto out; /* Duplicate message. */
32325 }
32326 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
32327 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
32328 msg->retries = 1;
32329
32330 - atomic_long_add(1 + msg->retries,
32331 + atomic_long_add_unchecked(1 + msg->retries,
32332 &port->counter_group[CM_XMIT].counter[attr_index]);
32333 if (msg->retries)
32334 - atomic_long_add(msg->retries,
32335 + atomic_long_add_unchecked(msg->retries,
32336 &port->counter_group[CM_XMIT_RETRIES].
32337 counter[attr_index]);
32338
32339 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
32340 }
32341
32342 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
32343 - atomic_long_inc(&port->counter_group[CM_RECV].
32344 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
32345 counter[attr_id - CM_ATTR_ID_OFFSET]);
32346
32347 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
32348 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
32349 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
32350
32351 return sprintf(buf, "%ld\n",
32352 - atomic_long_read(&group->counter[cm_attr->index]));
32353 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
32354 }
32355
32356 static const struct sysfs_ops cm_counter_ops = {
32357 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
32358 index 176c8f9..2627b62 100644
32359 --- a/drivers/infiniband/core/fmr_pool.c
32360 +++ b/drivers/infiniband/core/fmr_pool.c
32361 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
32362
32363 struct task_struct *thread;
32364
32365 - atomic_t req_ser;
32366 - atomic_t flush_ser;
32367 + atomic_unchecked_t req_ser;
32368 + atomic_unchecked_t flush_ser;
32369
32370 wait_queue_head_t force_wait;
32371 };
32372 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32373 struct ib_fmr_pool *pool = pool_ptr;
32374
32375 do {
32376 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
32377 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
32378 ib_fmr_batch_release(pool);
32379
32380 - atomic_inc(&pool->flush_ser);
32381 + atomic_inc_unchecked(&pool->flush_ser);
32382 wake_up_interruptible(&pool->force_wait);
32383
32384 if (pool->flush_function)
32385 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32386 }
32387
32388 set_current_state(TASK_INTERRUPTIBLE);
32389 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32390 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32391 !kthread_should_stop())
32392 schedule();
32393 __set_current_state(TASK_RUNNING);
32394 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32395 pool->dirty_watermark = params->dirty_watermark;
32396 pool->dirty_len = 0;
32397 spin_lock_init(&pool->pool_lock);
32398 - atomic_set(&pool->req_ser, 0);
32399 - atomic_set(&pool->flush_ser, 0);
32400 + atomic_set_unchecked(&pool->req_ser, 0);
32401 + atomic_set_unchecked(&pool->flush_ser, 0);
32402 init_waitqueue_head(&pool->force_wait);
32403
32404 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32405 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32406 }
32407 spin_unlock_irq(&pool->pool_lock);
32408
32409 - serial = atomic_inc_return(&pool->req_ser);
32410 + serial = atomic_inc_return_unchecked(&pool->req_ser);
32411 wake_up_process(pool->thread);
32412
32413 if (wait_event_interruptible(pool->force_wait,
32414 - atomic_read(&pool->flush_ser) - serial >= 0))
32415 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32416 return -EINTR;
32417
32418 return 0;
32419 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32420 } else {
32421 list_add_tail(&fmr->list, &pool->dirty_list);
32422 if (++pool->dirty_len >= pool->dirty_watermark) {
32423 - atomic_inc(&pool->req_ser);
32424 + atomic_inc_unchecked(&pool->req_ser);
32425 wake_up_process(pool->thread);
32426 }
32427 }
32428 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32429 index 57e07c6..56d09d4 100644
32430 --- a/drivers/infiniband/hw/cxgb4/mem.c
32431 +++ b/drivers/infiniband/hw/cxgb4/mem.c
32432 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32433 int err;
32434 struct fw_ri_tpte tpt;
32435 u32 stag_idx;
32436 - static atomic_t key;
32437 + static atomic_unchecked_t key;
32438
32439 if (c4iw_fatal_error(rdev))
32440 return -EIO;
32441 @@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32442 if (rdev->stats.stag.cur > rdev->stats.stag.max)
32443 rdev->stats.stag.max = rdev->stats.stag.cur;
32444 mutex_unlock(&rdev->stats.lock);
32445 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32446 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32447 }
32448 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32449 __func__, stag_state, type, pdid, stag_idx);
32450 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32451 index 79b3dbc..96e5fcc 100644
32452 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
32453 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32454 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32455 struct ib_atomic_eth *ateth;
32456 struct ipath_ack_entry *e;
32457 u64 vaddr;
32458 - atomic64_t *maddr;
32459 + atomic64_unchecked_t *maddr;
32460 u64 sdata;
32461 u32 rkey;
32462 u8 next;
32463 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32464 IB_ACCESS_REMOTE_ATOMIC)))
32465 goto nack_acc_unlck;
32466 /* Perform atomic OP and save result. */
32467 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32468 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32469 sdata = be64_to_cpu(ateth->swap_data);
32470 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32471 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32472 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32473 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32474 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32475 be64_to_cpu(ateth->compare_data),
32476 sdata);
32477 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32478 index 1f95bba..9530f87 100644
32479 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32480 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32481 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32482 unsigned long flags;
32483 struct ib_wc wc;
32484 u64 sdata;
32485 - atomic64_t *maddr;
32486 + atomic64_unchecked_t *maddr;
32487 enum ib_wc_status send_status;
32488
32489 /*
32490 @@ -382,11 +382,11 @@ again:
32491 IB_ACCESS_REMOTE_ATOMIC)))
32492 goto acc_err;
32493 /* Perform atomic OP and save result. */
32494 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32495 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32496 sdata = wqe->wr.wr.atomic.compare_add;
32497 *(u64 *) sqp->s_sge.sge.vaddr =
32498 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32499 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32500 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32501 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32502 sdata, wqe->wr.wr.atomic.swap);
32503 goto send_comp;
32504 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32505 index 7140199..da60063 100644
32506 --- a/drivers/infiniband/hw/nes/nes.c
32507 +++ b/drivers/infiniband/hw/nes/nes.c
32508 @@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32509 LIST_HEAD(nes_adapter_list);
32510 static LIST_HEAD(nes_dev_list);
32511
32512 -atomic_t qps_destroyed;
32513 +atomic_unchecked_t qps_destroyed;
32514
32515 static unsigned int ee_flsh_adapter;
32516 static unsigned int sysfs_nonidx_addr;
32517 @@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32518 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32519 struct nes_adapter *nesadapter = nesdev->nesadapter;
32520
32521 - atomic_inc(&qps_destroyed);
32522 + atomic_inc_unchecked(&qps_destroyed);
32523
32524 /* Free the control structures */
32525
32526 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32527 index c438e46..ca30356 100644
32528 --- a/drivers/infiniband/hw/nes/nes.h
32529 +++ b/drivers/infiniband/hw/nes/nes.h
32530 @@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
32531 extern unsigned int wqm_quanta;
32532 extern struct list_head nes_adapter_list;
32533
32534 -extern atomic_t cm_connects;
32535 -extern atomic_t cm_accepts;
32536 -extern atomic_t cm_disconnects;
32537 -extern atomic_t cm_closes;
32538 -extern atomic_t cm_connecteds;
32539 -extern atomic_t cm_connect_reqs;
32540 -extern atomic_t cm_rejects;
32541 -extern atomic_t mod_qp_timouts;
32542 -extern atomic_t qps_created;
32543 -extern atomic_t qps_destroyed;
32544 -extern atomic_t sw_qps_destroyed;
32545 +extern atomic_unchecked_t cm_connects;
32546 +extern atomic_unchecked_t cm_accepts;
32547 +extern atomic_unchecked_t cm_disconnects;
32548 +extern atomic_unchecked_t cm_closes;
32549 +extern atomic_unchecked_t cm_connecteds;
32550 +extern atomic_unchecked_t cm_connect_reqs;
32551 +extern atomic_unchecked_t cm_rejects;
32552 +extern atomic_unchecked_t mod_qp_timouts;
32553 +extern atomic_unchecked_t qps_created;
32554 +extern atomic_unchecked_t qps_destroyed;
32555 +extern atomic_unchecked_t sw_qps_destroyed;
32556 extern u32 mh_detected;
32557 extern u32 mh_pauses_sent;
32558 extern u32 cm_packets_sent;
32559 @@ -197,16 +197,16 @@ extern u32 cm_packets_created;
32560 extern u32 cm_packets_received;
32561 extern u32 cm_packets_dropped;
32562 extern u32 cm_packets_retrans;
32563 -extern atomic_t cm_listens_created;
32564 -extern atomic_t cm_listens_destroyed;
32565 +extern atomic_unchecked_t cm_listens_created;
32566 +extern atomic_unchecked_t cm_listens_destroyed;
32567 extern u32 cm_backlog_drops;
32568 -extern atomic_t cm_loopbacks;
32569 -extern atomic_t cm_nodes_created;
32570 -extern atomic_t cm_nodes_destroyed;
32571 -extern atomic_t cm_accel_dropped_pkts;
32572 -extern atomic_t cm_resets_recvd;
32573 -extern atomic_t pau_qps_created;
32574 -extern atomic_t pau_qps_destroyed;
32575 +extern atomic_unchecked_t cm_loopbacks;
32576 +extern atomic_unchecked_t cm_nodes_created;
32577 +extern atomic_unchecked_t cm_nodes_destroyed;
32578 +extern atomic_unchecked_t cm_accel_dropped_pkts;
32579 +extern atomic_unchecked_t cm_resets_recvd;
32580 +extern atomic_unchecked_t pau_qps_created;
32581 +extern atomic_unchecked_t pau_qps_destroyed;
32582
32583 extern u32 int_mod_timer_init;
32584 extern u32 int_mod_cq_depth_256;
32585 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32586 index 020e95c..fbb3450 100644
32587 --- a/drivers/infiniband/hw/nes/nes_cm.c
32588 +++ b/drivers/infiniband/hw/nes/nes_cm.c
32589 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32590 u32 cm_packets_retrans;
32591 u32 cm_packets_created;
32592 u32 cm_packets_received;
32593 -atomic_t cm_listens_created;
32594 -atomic_t cm_listens_destroyed;
32595 +atomic_unchecked_t cm_listens_created;
32596 +atomic_unchecked_t cm_listens_destroyed;
32597 u32 cm_backlog_drops;
32598 -atomic_t cm_loopbacks;
32599 -atomic_t cm_nodes_created;
32600 -atomic_t cm_nodes_destroyed;
32601 -atomic_t cm_accel_dropped_pkts;
32602 -atomic_t cm_resets_recvd;
32603 +atomic_unchecked_t cm_loopbacks;
32604 +atomic_unchecked_t cm_nodes_created;
32605 +atomic_unchecked_t cm_nodes_destroyed;
32606 +atomic_unchecked_t cm_accel_dropped_pkts;
32607 +atomic_unchecked_t cm_resets_recvd;
32608
32609 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32610 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32611 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32612
32613 static struct nes_cm_core *g_cm_core;
32614
32615 -atomic_t cm_connects;
32616 -atomic_t cm_accepts;
32617 -atomic_t cm_disconnects;
32618 -atomic_t cm_closes;
32619 -atomic_t cm_connecteds;
32620 -atomic_t cm_connect_reqs;
32621 -atomic_t cm_rejects;
32622 +atomic_unchecked_t cm_connects;
32623 +atomic_unchecked_t cm_accepts;
32624 +atomic_unchecked_t cm_disconnects;
32625 +atomic_unchecked_t cm_closes;
32626 +atomic_unchecked_t cm_connecteds;
32627 +atomic_unchecked_t cm_connect_reqs;
32628 +atomic_unchecked_t cm_rejects;
32629
32630 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32631 {
32632 @@ -1279,7 +1279,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32633 kfree(listener);
32634 listener = NULL;
32635 ret = 0;
32636 - atomic_inc(&cm_listens_destroyed);
32637 + atomic_inc_unchecked(&cm_listens_destroyed);
32638 } else {
32639 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32640 }
32641 @@ -1482,7 +1482,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32642 cm_node->rem_mac);
32643
32644 add_hte_node(cm_core, cm_node);
32645 - atomic_inc(&cm_nodes_created);
32646 + atomic_inc_unchecked(&cm_nodes_created);
32647
32648 return cm_node;
32649 }
32650 @@ -1540,7 +1540,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32651 }
32652
32653 atomic_dec(&cm_core->node_cnt);
32654 - atomic_inc(&cm_nodes_destroyed);
32655 + atomic_inc_unchecked(&cm_nodes_destroyed);
32656 nesqp = cm_node->nesqp;
32657 if (nesqp) {
32658 nesqp->cm_node = NULL;
32659 @@ -1604,7 +1604,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32660
32661 static void drop_packet(struct sk_buff *skb)
32662 {
32663 - atomic_inc(&cm_accel_dropped_pkts);
32664 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32665 dev_kfree_skb_any(skb);
32666 }
32667
32668 @@ -1667,7 +1667,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32669 {
32670
32671 int reset = 0; /* whether to send reset in case of err.. */
32672 - atomic_inc(&cm_resets_recvd);
32673 + atomic_inc_unchecked(&cm_resets_recvd);
32674 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32675 " refcnt=%d\n", cm_node, cm_node->state,
32676 atomic_read(&cm_node->ref_count));
32677 @@ -2308,7 +2308,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32678 rem_ref_cm_node(cm_node->cm_core, cm_node);
32679 return NULL;
32680 }
32681 - atomic_inc(&cm_loopbacks);
32682 + atomic_inc_unchecked(&cm_loopbacks);
32683 loopbackremotenode->loopbackpartner = cm_node;
32684 loopbackremotenode->tcp_cntxt.rcv_wscale =
32685 NES_CM_DEFAULT_RCV_WND_SCALE;
32686 @@ -2583,7 +2583,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32687 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32688 else {
32689 rem_ref_cm_node(cm_core, cm_node);
32690 - atomic_inc(&cm_accel_dropped_pkts);
32691 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32692 dev_kfree_skb_any(skb);
32693 }
32694 break;
32695 @@ -2891,7 +2891,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32696
32697 if ((cm_id) && (cm_id->event_handler)) {
32698 if (issue_disconn) {
32699 - atomic_inc(&cm_disconnects);
32700 + atomic_inc_unchecked(&cm_disconnects);
32701 cm_event.event = IW_CM_EVENT_DISCONNECT;
32702 cm_event.status = disconn_status;
32703 cm_event.local_addr = cm_id->local_addr;
32704 @@ -2913,7 +2913,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32705 }
32706
32707 if (issue_close) {
32708 - atomic_inc(&cm_closes);
32709 + atomic_inc_unchecked(&cm_closes);
32710 nes_disconnect(nesqp, 1);
32711
32712 cm_id->provider_data = nesqp;
32713 @@ -3049,7 +3049,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32714
32715 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32716 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32717 - atomic_inc(&cm_accepts);
32718 + atomic_inc_unchecked(&cm_accepts);
32719
32720 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32721 netdev_refcnt_read(nesvnic->netdev));
32722 @@ -3251,7 +3251,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
32723 struct nes_cm_core *cm_core;
32724 u8 *start_buff;
32725
32726 - atomic_inc(&cm_rejects);
32727 + atomic_inc_unchecked(&cm_rejects);
32728 cm_node = (struct nes_cm_node *)cm_id->provider_data;
32729 loopback = cm_node->loopbackpartner;
32730 cm_core = cm_node->cm_core;
32731 @@ -3311,7 +3311,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32732 ntohl(cm_id->local_addr.sin_addr.s_addr),
32733 ntohs(cm_id->local_addr.sin_port));
32734
32735 - atomic_inc(&cm_connects);
32736 + atomic_inc_unchecked(&cm_connects);
32737 nesqp->active_conn = 1;
32738
32739 /* cache the cm_id in the qp */
32740 @@ -3421,7 +3421,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
32741 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
32742 return err;
32743 }
32744 - atomic_inc(&cm_listens_created);
32745 + atomic_inc_unchecked(&cm_listens_created);
32746 }
32747
32748 cm_id->add_ref(cm_id);
32749 @@ -3522,7 +3522,7 @@ static void cm_event_connected(struct nes_cm_event *event)
32750
32751 if (nesqp->destroyed)
32752 return;
32753 - atomic_inc(&cm_connecteds);
32754 + atomic_inc_unchecked(&cm_connecteds);
32755 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
32756 " local port 0x%04X. jiffies = %lu.\n",
32757 nesqp->hwqp.qp_id,
32758 @@ -3709,7 +3709,7 @@ static void cm_event_reset(struct nes_cm_event *event)
32759
32760 cm_id->add_ref(cm_id);
32761 ret = cm_id->event_handler(cm_id, &cm_event);
32762 - atomic_inc(&cm_closes);
32763 + atomic_inc_unchecked(&cm_closes);
32764 cm_event.event = IW_CM_EVENT_CLOSE;
32765 cm_event.status = 0;
32766 cm_event.provider_data = cm_id->provider_data;
32767 @@ -3745,7 +3745,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
32768 return;
32769 cm_id = cm_node->cm_id;
32770
32771 - atomic_inc(&cm_connect_reqs);
32772 + atomic_inc_unchecked(&cm_connect_reqs);
32773 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32774 cm_node, cm_id, jiffies);
32775
32776 @@ -3785,7 +3785,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
32777 return;
32778 cm_id = cm_node->cm_id;
32779
32780 - atomic_inc(&cm_connect_reqs);
32781 + atomic_inc_unchecked(&cm_connect_reqs);
32782 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32783 cm_node, cm_id, jiffies);
32784
32785 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
32786 index 3ba7be3..c81f6ff 100644
32787 --- a/drivers/infiniband/hw/nes/nes_mgt.c
32788 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
32789 @@ -40,8 +40,8 @@
32790 #include "nes.h"
32791 #include "nes_mgt.h"
32792
32793 -atomic_t pau_qps_created;
32794 -atomic_t pau_qps_destroyed;
32795 +atomic_unchecked_t pau_qps_created;
32796 +atomic_unchecked_t pau_qps_destroyed;
32797
32798 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
32799 {
32800 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
32801 {
32802 struct sk_buff *skb;
32803 unsigned long flags;
32804 - atomic_inc(&pau_qps_destroyed);
32805 + atomic_inc_unchecked(&pau_qps_destroyed);
32806
32807 /* Free packets that have not yet been forwarded */
32808 /* Lock is acquired by skb_dequeue when removing the skb */
32809 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
32810 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
32811 skb_queue_head_init(&nesqp->pau_list);
32812 spin_lock_init(&nesqp->pau_lock);
32813 - atomic_inc(&pau_qps_created);
32814 + atomic_inc_unchecked(&pau_qps_created);
32815 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
32816 }
32817
32818 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
32819 index f3a3ecf..57d311d 100644
32820 --- a/drivers/infiniband/hw/nes/nes_nic.c
32821 +++ b/drivers/infiniband/hw/nes/nes_nic.c
32822 @@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
32823 target_stat_values[++index] = mh_detected;
32824 target_stat_values[++index] = mh_pauses_sent;
32825 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
32826 - target_stat_values[++index] = atomic_read(&cm_connects);
32827 - target_stat_values[++index] = atomic_read(&cm_accepts);
32828 - target_stat_values[++index] = atomic_read(&cm_disconnects);
32829 - target_stat_values[++index] = atomic_read(&cm_connecteds);
32830 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
32831 - target_stat_values[++index] = atomic_read(&cm_rejects);
32832 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
32833 - target_stat_values[++index] = atomic_read(&qps_created);
32834 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
32835 - target_stat_values[++index] = atomic_read(&qps_destroyed);
32836 - target_stat_values[++index] = atomic_read(&cm_closes);
32837 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
32838 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
32839 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
32840 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
32841 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
32842 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
32843 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
32844 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
32845 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
32846 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
32847 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
32848 target_stat_values[++index] = cm_packets_sent;
32849 target_stat_values[++index] = cm_packets_bounced;
32850 target_stat_values[++index] = cm_packets_created;
32851 target_stat_values[++index] = cm_packets_received;
32852 target_stat_values[++index] = cm_packets_dropped;
32853 target_stat_values[++index] = cm_packets_retrans;
32854 - target_stat_values[++index] = atomic_read(&cm_listens_created);
32855 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
32856 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
32857 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
32858 target_stat_values[++index] = cm_backlog_drops;
32859 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
32860 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
32861 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
32862 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
32863 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
32864 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
32865 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
32866 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
32867 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
32868 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
32869 target_stat_values[++index] = nesadapter->free_4kpbl;
32870 target_stat_values[++index] = nesadapter->free_256pbl;
32871 target_stat_values[++index] = int_mod_timer_init;
32872 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
32873 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
32874 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
32875 - target_stat_values[++index] = atomic_read(&pau_qps_created);
32876 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
32877 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
32878 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
32879 }
32880
32881 /**
32882 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
32883 index 8b8812d..a5e1133 100644
32884 --- a/drivers/infiniband/hw/nes/nes_verbs.c
32885 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
32886 @@ -46,9 +46,9 @@
32887
32888 #include <rdma/ib_umem.h>
32889
32890 -atomic_t mod_qp_timouts;
32891 -atomic_t qps_created;
32892 -atomic_t sw_qps_destroyed;
32893 +atomic_unchecked_t mod_qp_timouts;
32894 +atomic_unchecked_t qps_created;
32895 +atomic_unchecked_t sw_qps_destroyed;
32896
32897 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
32898
32899 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
32900 if (init_attr->create_flags)
32901 return ERR_PTR(-EINVAL);
32902
32903 - atomic_inc(&qps_created);
32904 + atomic_inc_unchecked(&qps_created);
32905 switch (init_attr->qp_type) {
32906 case IB_QPT_RC:
32907 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
32908 @@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
32909 struct iw_cm_event cm_event;
32910 int ret = 0;
32911
32912 - atomic_inc(&sw_qps_destroyed);
32913 + atomic_inc_unchecked(&sw_qps_destroyed);
32914 nesqp->destroyed = 1;
32915
32916 /* Blow away the connection if it exists. */
32917 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
32918 index 7b1b8669..4b69f85 100644
32919 --- a/drivers/infiniband/hw/qib/qib.h
32920 +++ b/drivers/infiniband/hw/qib/qib.h
32921 @@ -51,6 +51,7 @@
32922 #include <linux/completion.h>
32923 #include <linux/kref.h>
32924 #include <linux/sched.h>
32925 +#include <linux/slab.h>
32926
32927 #include "qib_common.h"
32928 #include "qib_verbs.h"
32929 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
32930 index da739d9..da1c7f4 100644
32931 --- a/drivers/input/gameport/gameport.c
32932 +++ b/drivers/input/gameport/gameport.c
32933 @@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
32934 */
32935 static void gameport_init_port(struct gameport *gameport)
32936 {
32937 - static atomic_t gameport_no = ATOMIC_INIT(0);
32938 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
32939
32940 __module_get(THIS_MODULE);
32941
32942 mutex_init(&gameport->drv_mutex);
32943 device_initialize(&gameport->dev);
32944 dev_set_name(&gameport->dev, "gameport%lu",
32945 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
32946 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
32947 gameport->dev.bus = &gameport_bus;
32948 gameport->dev.release = gameport_release_port;
32949 if (gameport->parent)
32950 diff --git a/drivers/input/input.c b/drivers/input/input.c
32951 index 8921c61..f5cd63d 100644
32952 --- a/drivers/input/input.c
32953 +++ b/drivers/input/input.c
32954 @@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
32955 */
32956 int input_register_device(struct input_dev *dev)
32957 {
32958 - static atomic_t input_no = ATOMIC_INIT(0);
32959 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
32960 struct input_handler *handler;
32961 const char *path;
32962 int error;
32963 @@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
32964 dev->setkeycode = input_default_setkeycode;
32965
32966 dev_set_name(&dev->dev, "input%ld",
32967 - (unsigned long) atomic_inc_return(&input_no) - 1);
32968 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
32969
32970 error = device_add(&dev->dev);
32971 if (error)
32972 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
32973 index 04c69af..5f92d00 100644
32974 --- a/drivers/input/joystick/sidewinder.c
32975 +++ b/drivers/input/joystick/sidewinder.c
32976 @@ -30,6 +30,7 @@
32977 #include <linux/kernel.h>
32978 #include <linux/module.h>
32979 #include <linux/slab.h>
32980 +#include <linux/sched.h>
32981 #include <linux/init.h>
32982 #include <linux/input.h>
32983 #include <linux/gameport.h>
32984 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
32985 index 83811e4..0822b90 100644
32986 --- a/drivers/input/joystick/xpad.c
32987 +++ b/drivers/input/joystick/xpad.c
32988 @@ -726,7 +726,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
32989
32990 static int xpad_led_probe(struct usb_xpad *xpad)
32991 {
32992 - static atomic_t led_seq = ATOMIC_INIT(0);
32993 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
32994 long led_no;
32995 struct xpad_led *led;
32996 struct led_classdev *led_cdev;
32997 @@ -739,7 +739,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
32998 if (!led)
32999 return -ENOMEM;
33000
33001 - led_no = (long)atomic_inc_return(&led_seq) - 1;
33002 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
33003
33004 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
33005 led->xpad = xpad;
33006 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
33007 index 0110b5a..d3ad144 100644
33008 --- a/drivers/input/mousedev.c
33009 +++ b/drivers/input/mousedev.c
33010 @@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
33011
33012 spin_unlock_irq(&client->packet_lock);
33013
33014 - if (copy_to_user(buffer, data, count))
33015 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
33016 return -EFAULT;
33017
33018 return count;
33019 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
33020 index d0f7533..fb8215b 100644
33021 --- a/drivers/input/serio/serio.c
33022 +++ b/drivers/input/serio/serio.c
33023 @@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
33024 */
33025 static void serio_init_port(struct serio *serio)
33026 {
33027 - static atomic_t serio_no = ATOMIC_INIT(0);
33028 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
33029
33030 __module_get(THIS_MODULE);
33031
33032 @@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
33033 mutex_init(&serio->drv_mutex);
33034 device_initialize(&serio->dev);
33035 dev_set_name(&serio->dev, "serio%ld",
33036 - (long)atomic_inc_return(&serio_no) - 1);
33037 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
33038 serio->dev.bus = &serio_bus;
33039 serio->dev.release = serio_release_port;
33040 serio->dev.groups = serio_device_attr_groups;
33041 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
33042 index 38c4bd8..58965d9 100644
33043 --- a/drivers/isdn/capi/capi.c
33044 +++ b/drivers/isdn/capi/capi.c
33045 @@ -83,8 +83,8 @@ struct capiminor {
33046
33047 struct capi20_appl *ap;
33048 u32 ncci;
33049 - atomic_t datahandle;
33050 - atomic_t msgid;
33051 + atomic_unchecked_t datahandle;
33052 + atomic_unchecked_t msgid;
33053
33054 struct tty_port port;
33055 int ttyinstop;
33056 @@ -392,7 +392,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
33057 capimsg_setu16(s, 2, mp->ap->applid);
33058 capimsg_setu8 (s, 4, CAPI_DATA_B3);
33059 capimsg_setu8 (s, 5, CAPI_RESP);
33060 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
33061 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
33062 capimsg_setu32(s, 8, mp->ncci);
33063 capimsg_setu16(s, 12, datahandle);
33064 }
33065 @@ -513,14 +513,14 @@ static void handle_minor_send(struct capiminor *mp)
33066 mp->outbytes -= len;
33067 spin_unlock_bh(&mp->outlock);
33068
33069 - datahandle = atomic_inc_return(&mp->datahandle);
33070 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
33071 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
33072 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
33073 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
33074 capimsg_setu16(skb->data, 2, mp->ap->applid);
33075 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
33076 capimsg_setu8 (skb->data, 5, CAPI_REQ);
33077 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
33078 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
33079 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
33080 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
33081 capimsg_setu16(skb->data, 16, len); /* Data length */
33082 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
33083 index a6d9fd2..afdb8a3 100644
33084 --- a/drivers/isdn/gigaset/interface.c
33085 +++ b/drivers/isdn/gigaset/interface.c
33086 @@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
33087 }
33088 tty->driver_data = cs;
33089
33090 - ++cs->port.count;
33091 + atomic_inc(&cs->port.count);
33092
33093 - if (cs->port.count == 1) {
33094 + if (atomic_read(&cs->port.count) == 1) {
33095 tty_port_tty_set(&cs->port, tty);
33096 tty->low_latency = 1;
33097 }
33098 @@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
33099
33100 if (!cs->connected)
33101 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
33102 - else if (!cs->port.count)
33103 + else if (!atomic_read(&cs->port.count))
33104 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33105 - else if (!--cs->port.count)
33106 + else if (!atomic_dec_return(&cs->port.count))
33107 tty_port_tty_set(&cs->port, NULL);
33108
33109 mutex_unlock(&cs->mutex);
33110 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
33111 index 821f7ac..28d4030 100644
33112 --- a/drivers/isdn/hardware/avm/b1.c
33113 +++ b/drivers/isdn/hardware/avm/b1.c
33114 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
33115 }
33116 if (left) {
33117 if (t4file->user) {
33118 - if (copy_from_user(buf, dp, left))
33119 + if (left > sizeof buf || copy_from_user(buf, dp, left))
33120 return -EFAULT;
33121 } else {
33122 memcpy(buf, dp, left);
33123 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
33124 }
33125 if (left) {
33126 if (config->user) {
33127 - if (copy_from_user(buf, dp, left))
33128 + if (left > sizeof buf || copy_from_user(buf, dp, left))
33129 return -EFAULT;
33130 } else {
33131 memcpy(buf, dp, left);
33132 diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
33133 index dd6b53a..19d9ee6 100644
33134 --- a/drivers/isdn/hardware/eicon/divasync.h
33135 +++ b/drivers/isdn/hardware/eicon/divasync.h
33136 @@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
33137 } diva_didd_add_adapter_t;
33138 typedef struct _diva_didd_remove_adapter {
33139 IDI_CALL p_request;
33140 -} diva_didd_remove_adapter_t;
33141 +} __no_const diva_didd_remove_adapter_t;
33142 typedef struct _diva_didd_read_adapter_array {
33143 void *buffer;
33144 dword length;
33145 diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
33146 index d303e65..28bcb7b 100644
33147 --- a/drivers/isdn/hardware/eicon/xdi_adapter.h
33148 +++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
33149 @@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
33150 typedef struct _diva_os_idi_adapter_interface {
33151 diva_init_card_proc_t cleanup_adapter_proc;
33152 diva_cmd_card_proc_t cmd_proc;
33153 -} diva_os_idi_adapter_interface_t;
33154 +} __no_const diva_os_idi_adapter_interface_t;
33155
33156 typedef struct _diva_os_xdi_adapter {
33157 struct list_head link;
33158 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
33159 index 7bc5067..fd36232 100644
33160 --- a/drivers/isdn/i4l/isdn_tty.c
33161 +++ b/drivers/isdn/i4l/isdn_tty.c
33162 @@ -1505,9 +1505,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
33163 port = &info->port;
33164 #ifdef ISDN_DEBUG_MODEM_OPEN
33165 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
33166 - port->count);
33167 + atomic_read(&port->count))
33168 #endif
33169 - port->count++;
33170 + atomic_inc(&port->count);
33171 tty->driver_data = info;
33172 port->tty = tty;
33173 tty->port = port;
33174 @@ -1553,7 +1553,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
33175 #endif
33176 return;
33177 }
33178 - if ((tty->count == 1) && (port->count != 1)) {
33179 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
33180 /*
33181 * Uh, oh. tty->count is 1, which means that the tty
33182 * structure will be freed. Info->count should always
33183 @@ -1562,15 +1562,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
33184 * serial port won't be shutdown.
33185 */
33186 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
33187 - "info->count is %d\n", port->count);
33188 - port->count = 1;
33189 + "info->count is %d\n", atomic_read(&port->count));
33190 + atomic_set(&port->count, 1);
33191 }
33192 - if (--port->count < 0) {
33193 + if (atomic_dec_return(&port->count) < 0) {
33194 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
33195 - info->line, port->count);
33196 - port->count = 0;
33197 + info->line, atomic_read(&port->count));
33198 + atomic_set(&port->count, 0);
33199 }
33200 - if (port->count) {
33201 + if (atomic_read(&port->count)) {
33202 #ifdef ISDN_DEBUG_MODEM_OPEN
33203 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
33204 #endif
33205 @@ -1624,7 +1624,7 @@ isdn_tty_hangup(struct tty_struct *tty)
33206 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
33207 return;
33208 isdn_tty_shutdown(info);
33209 - port->count = 0;
33210 + atomic_set(&port->count, 0);
33211 port->flags &= ~ASYNC_NORMAL_ACTIVE;
33212 port->tty = NULL;
33213 wake_up_interruptible(&port->open_wait);
33214 @@ -1964,7 +1964,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
33215 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
33216 modem_info *info = &dev->mdm.info[i];
33217
33218 - if (info->port.count == 0)
33219 + if (atomic_read(&info->port.count) == 0)
33220 continue;
33221 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
33222 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
33223 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
33224 index e74df7c..03a03ba 100644
33225 --- a/drivers/isdn/icn/icn.c
33226 +++ b/drivers/isdn/icn/icn.c
33227 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
33228 if (count > len)
33229 count = len;
33230 if (user) {
33231 - if (copy_from_user(msg, buf, count))
33232 + if (count > sizeof msg || copy_from_user(msg, buf, count))
33233 return -EFAULT;
33234 } else
33235 memcpy(msg, buf, count);
33236 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
33237 index b5fdcb7..5b6c59f 100644
33238 --- a/drivers/lguest/core.c
33239 +++ b/drivers/lguest/core.c
33240 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
33241 * it's worked so far. The end address needs +1 because __get_vm_area
33242 * allocates an extra guard page, so we need space for that.
33243 */
33244 +
33245 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
33246 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33247 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
33248 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33249 +#else
33250 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33251 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
33252 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33253 +#endif
33254 +
33255 if (!switcher_vma) {
33256 err = -ENOMEM;
33257 printk("lguest: could not map switcher pages high\n");
33258 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
33259 * Now the Switcher is mapped at the right address, we can't fail!
33260 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
33261 */
33262 - memcpy(switcher_vma->addr, start_switcher_text,
33263 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
33264 end_switcher_text - start_switcher_text);
33265
33266 printk(KERN_INFO "lguest: mapped switcher at %p\n",
33267 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
33268 index 39809035..ce25c5e 100644
33269 --- a/drivers/lguest/x86/core.c
33270 +++ b/drivers/lguest/x86/core.c
33271 @@ -59,7 +59,7 @@ static struct {
33272 /* Offset from where switcher.S was compiled to where we've copied it */
33273 static unsigned long switcher_offset(void)
33274 {
33275 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
33276 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
33277 }
33278
33279 /* This cpu's struct lguest_pages. */
33280 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
33281 * These copies are pretty cheap, so we do them unconditionally: */
33282 /* Save the current Host top-level page directory.
33283 */
33284 +
33285 +#ifdef CONFIG_PAX_PER_CPU_PGD
33286 + pages->state.host_cr3 = read_cr3();
33287 +#else
33288 pages->state.host_cr3 = __pa(current->mm->pgd);
33289 +#endif
33290 +
33291 /*
33292 * Set up the Guest's page tables to see this CPU's pages (and no
33293 * other CPU's pages).
33294 @@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
33295 * compiled-in switcher code and the high-mapped copy we just made.
33296 */
33297 for (i = 0; i < IDT_ENTRIES; i++)
33298 - default_idt_entries[i] += switcher_offset();
33299 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
33300
33301 /*
33302 * Set up the Switcher's per-cpu areas.
33303 @@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
33304 * it will be undisturbed when we switch. To change %cs and jump we
33305 * need this structure to feed to Intel's "lcall" instruction.
33306 */
33307 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
33308 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
33309 lguest_entry.segment = LGUEST_CS;
33310
33311 /*
33312 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
33313 index 40634b0..4f5855e 100644
33314 --- a/drivers/lguest/x86/switcher_32.S
33315 +++ b/drivers/lguest/x86/switcher_32.S
33316 @@ -87,6 +87,7 @@
33317 #include <asm/page.h>
33318 #include <asm/segment.h>
33319 #include <asm/lguest.h>
33320 +#include <asm/processor-flags.h>
33321
33322 // We mark the start of the code to copy
33323 // It's placed in .text tho it's never run here
33324 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
33325 // Changes type when we load it: damn Intel!
33326 // For after we switch over our page tables
33327 // That entry will be read-only: we'd crash.
33328 +
33329 +#ifdef CONFIG_PAX_KERNEXEC
33330 + mov %cr0, %edx
33331 + xor $X86_CR0_WP, %edx
33332 + mov %edx, %cr0
33333 +#endif
33334 +
33335 movl $(GDT_ENTRY_TSS*8), %edx
33336 ltr %dx
33337
33338 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
33339 // Let's clear it again for our return.
33340 // The GDT descriptor of the Host
33341 // Points to the table after two "size" bytes
33342 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33343 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33344 // Clear "used" from type field (byte 5, bit 2)
33345 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33346 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33347 +
33348 +#ifdef CONFIG_PAX_KERNEXEC
33349 + mov %cr0, %eax
33350 + xor $X86_CR0_WP, %eax
33351 + mov %eax, %cr0
33352 +#endif
33353
33354 // Once our page table's switched, the Guest is live!
33355 // The Host fades as we run this final step.
33356 @@ -295,13 +309,12 @@ deliver_to_host:
33357 // I consulted gcc, and it gave
33358 // These instructions, which I gladly credit:
33359 leal (%edx,%ebx,8), %eax
33360 - movzwl (%eax),%edx
33361 - movl 4(%eax), %eax
33362 - xorw %ax, %ax
33363 - orl %eax, %edx
33364 + movl 4(%eax), %edx
33365 + movw (%eax), %dx
33366 // Now the address of the handler's in %edx
33367 // We call it now: its "iret" drops us home.
33368 - jmp *%edx
33369 + ljmp $__KERNEL_CS, $1f
33370 +1: jmp *%edx
33371
33372 // Every interrupt can come to us here
33373 // But we must truly tell each apart.
33374 diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
33375 index 20e5c2c..9e849a9 100644
33376 --- a/drivers/macintosh/macio_asic.c
33377 +++ b/drivers/macintosh/macio_asic.c
33378 @@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
33379 * MacIO is matched against any Apple ID, it's probe() function
33380 * will then decide wether it applies or not
33381 */
33382 -static const struct pci_device_id __devinitdata pci_ids [] = { {
33383 +static const struct pci_device_id __devinitconst pci_ids [] = { {
33384 .vendor = PCI_VENDOR_ID_APPLE,
33385 .device = PCI_ANY_ID,
33386 .subvendor = PCI_ANY_ID,
33387 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
33388 index 94e7f6b..2f4a0d8 100644
33389 --- a/drivers/md/bitmap.c
33390 +++ b/drivers/md/bitmap.c
33391 @@ -1786,7 +1786,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
33392 chunk_kb ? "KB" : "B");
33393 if (bitmap->storage.file) {
33394 seq_printf(seq, ", file: ");
33395 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
33396 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
33397 }
33398
33399 seq_printf(seq, "\n");
33400 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33401 index afd9598..528d8f9 100644
33402 --- a/drivers/md/dm-ioctl.c
33403 +++ b/drivers/md/dm-ioctl.c
33404 @@ -1593,7 +1593,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33405 cmd == DM_LIST_VERSIONS_CMD)
33406 return 0;
33407
33408 - if ((cmd == DM_DEV_CREATE_CMD)) {
33409 + if (cmd == DM_DEV_CREATE_CMD) {
33410 if (!*param->name) {
33411 DMWARN("name not supplied when creating device");
33412 return -EINVAL;
33413 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33414 index bc5ddba8..b961159 100644
33415 --- a/drivers/md/dm-raid1.c
33416 +++ b/drivers/md/dm-raid1.c
33417 @@ -40,7 +40,7 @@ enum dm_raid1_error {
33418
33419 struct mirror {
33420 struct mirror_set *ms;
33421 - atomic_t error_count;
33422 + atomic_unchecked_t error_count;
33423 unsigned long error_type;
33424 struct dm_dev *dev;
33425 sector_t offset;
33426 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33427 struct mirror *m;
33428
33429 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33430 - if (!atomic_read(&m->error_count))
33431 + if (!atomic_read_unchecked(&m->error_count))
33432 return m;
33433
33434 return NULL;
33435 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33436 * simple way to tell if a device has encountered
33437 * errors.
33438 */
33439 - atomic_inc(&m->error_count);
33440 + atomic_inc_unchecked(&m->error_count);
33441
33442 if (test_and_set_bit(error_type, &m->error_type))
33443 return;
33444 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33445 struct mirror *m = get_default_mirror(ms);
33446
33447 do {
33448 - if (likely(!atomic_read(&m->error_count)))
33449 + if (likely(!atomic_read_unchecked(&m->error_count)))
33450 return m;
33451
33452 if (m-- == ms->mirror)
33453 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33454 {
33455 struct mirror *default_mirror = get_default_mirror(m->ms);
33456
33457 - return !atomic_read(&default_mirror->error_count);
33458 + return !atomic_read_unchecked(&default_mirror->error_count);
33459 }
33460
33461 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33462 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33463 */
33464 if (likely(region_in_sync(ms, region, 1)))
33465 m = choose_mirror(ms, bio->bi_sector);
33466 - else if (m && atomic_read(&m->error_count))
33467 + else if (m && atomic_read_unchecked(&m->error_count))
33468 m = NULL;
33469
33470 if (likely(m))
33471 @@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33472 }
33473
33474 ms->mirror[mirror].ms = ms;
33475 - atomic_set(&(ms->mirror[mirror].error_count), 0);
33476 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33477 ms->mirror[mirror].error_type = 0;
33478 ms->mirror[mirror].offset = offset;
33479
33480 @@ -1356,7 +1356,7 @@ static void mirror_resume(struct dm_target *ti)
33481 */
33482 static char device_status_char(struct mirror *m)
33483 {
33484 - if (!atomic_read(&(m->error_count)))
33485 + if (!atomic_read_unchecked(&(m->error_count)))
33486 return 'A';
33487
33488 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33489 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33490 index a087bf2..4c94786 100644
33491 --- a/drivers/md/dm-stripe.c
33492 +++ b/drivers/md/dm-stripe.c
33493 @@ -20,7 +20,7 @@ struct stripe {
33494 struct dm_dev *dev;
33495 sector_t physical_start;
33496
33497 - atomic_t error_count;
33498 + atomic_unchecked_t error_count;
33499 };
33500
33501 struct stripe_c {
33502 @@ -183,7 +183,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33503 kfree(sc);
33504 return r;
33505 }
33506 - atomic_set(&(sc->stripe[i].error_count), 0);
33507 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33508 }
33509
33510 ti->private = sc;
33511 @@ -324,7 +324,7 @@ static int stripe_status(struct dm_target *ti, status_type_t type,
33512 DMEMIT("%d ", sc->stripes);
33513 for (i = 0; i < sc->stripes; i++) {
33514 DMEMIT("%s ", sc->stripe[i].dev->name);
33515 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33516 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33517 'D' : 'A';
33518 }
33519 buffer[i] = '\0';
33520 @@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33521 */
33522 for (i = 0; i < sc->stripes; i++)
33523 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33524 - atomic_inc(&(sc->stripe[i].error_count));
33525 - if (atomic_read(&(sc->stripe[i].error_count)) <
33526 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
33527 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33528 DM_IO_ERROR_THRESHOLD)
33529 schedule_work(&sc->trigger_event);
33530 }
33531 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33532 index 100368e..64262ce 100644
33533 --- a/drivers/md/dm-table.c
33534 +++ b/drivers/md/dm-table.c
33535 @@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33536 if (!dev_size)
33537 return 0;
33538
33539 - if ((start >= dev_size) || (start + len > dev_size)) {
33540 + if ((start >= dev_size) || (len > dev_size - start)) {
33541 DMWARN("%s: %s too small for target: "
33542 "start=%llu, len=%llu, dev_size=%llu",
33543 dm_device_name(ti->table->md), bdevname(bdev, b),
33544 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33545 index 693e149..b7e0fde 100644
33546 --- a/drivers/md/dm-thin-metadata.c
33547 +++ b/drivers/md/dm-thin-metadata.c
33548 @@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
33549 {
33550 pmd->info.tm = pmd->tm;
33551 pmd->info.levels = 2;
33552 - pmd->info.value_type.context = pmd->data_sm;
33553 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33554 pmd->info.value_type.size = sizeof(__le64);
33555 pmd->info.value_type.inc = data_block_inc;
33556 pmd->info.value_type.dec = data_block_dec;
33557 @@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
33558
33559 pmd->bl_info.tm = pmd->tm;
33560 pmd->bl_info.levels = 1;
33561 - pmd->bl_info.value_type.context = pmd->data_sm;
33562 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33563 pmd->bl_info.value_type.size = sizeof(__le64);
33564 pmd->bl_info.value_type.inc = data_block_inc;
33565 pmd->bl_info.value_type.dec = data_block_dec;
33566 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33567 index 67ffa39..cb3b1dd 100644
33568 --- a/drivers/md/dm.c
33569 +++ b/drivers/md/dm.c
33570 @@ -176,9 +176,9 @@ struct mapped_device {
33571 /*
33572 * Event handling.
33573 */
33574 - atomic_t event_nr;
33575 + atomic_unchecked_t event_nr;
33576 wait_queue_head_t eventq;
33577 - atomic_t uevent_seq;
33578 + atomic_unchecked_t uevent_seq;
33579 struct list_head uevent_list;
33580 spinlock_t uevent_lock; /* Protect access to uevent_list */
33581
33582 @@ -1887,8 +1887,8 @@ static struct mapped_device *alloc_dev(int minor)
33583 rwlock_init(&md->map_lock);
33584 atomic_set(&md->holders, 1);
33585 atomic_set(&md->open_count, 0);
33586 - atomic_set(&md->event_nr, 0);
33587 - atomic_set(&md->uevent_seq, 0);
33588 + atomic_set_unchecked(&md->event_nr, 0);
33589 + atomic_set_unchecked(&md->uevent_seq, 0);
33590 INIT_LIST_HEAD(&md->uevent_list);
33591 spin_lock_init(&md->uevent_lock);
33592
33593 @@ -2022,7 +2022,7 @@ static void event_callback(void *context)
33594
33595 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33596
33597 - atomic_inc(&md->event_nr);
33598 + atomic_inc_unchecked(&md->event_nr);
33599 wake_up(&md->eventq);
33600 }
33601
33602 @@ -2677,18 +2677,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33603
33604 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33605 {
33606 - return atomic_add_return(1, &md->uevent_seq);
33607 + return atomic_add_return_unchecked(1, &md->uevent_seq);
33608 }
33609
33610 uint32_t dm_get_event_nr(struct mapped_device *md)
33611 {
33612 - return atomic_read(&md->event_nr);
33613 + return atomic_read_unchecked(&md->event_nr);
33614 }
33615
33616 int dm_wait_event(struct mapped_device *md, int event_nr)
33617 {
33618 return wait_event_interruptible(md->eventq,
33619 - (event_nr != atomic_read(&md->event_nr)));
33620 + (event_nr != atomic_read_unchecked(&md->event_nr)));
33621 }
33622
33623 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33624 diff --git a/drivers/md/md.c b/drivers/md/md.c
33625 index 308e87b..7f365d6 100644
33626 --- a/drivers/md/md.c
33627 +++ b/drivers/md/md.c
33628 @@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33629 * start build, activate spare
33630 */
33631 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33632 -static atomic_t md_event_count;
33633 +static atomic_unchecked_t md_event_count;
33634 void md_new_event(struct mddev *mddev)
33635 {
33636 - atomic_inc(&md_event_count);
33637 + atomic_inc_unchecked(&md_event_count);
33638 wake_up(&md_event_waiters);
33639 }
33640 EXPORT_SYMBOL_GPL(md_new_event);
33641 @@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33642 */
33643 static void md_new_event_inintr(struct mddev *mddev)
33644 {
33645 - atomic_inc(&md_event_count);
33646 + atomic_inc_unchecked(&md_event_count);
33647 wake_up(&md_event_waiters);
33648 }
33649
33650 @@ -1519,7 +1519,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33651 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
33652 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
33653 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
33654 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33655 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33656
33657 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33658 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33659 @@ -1763,7 +1763,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33660 else
33661 sb->resync_offset = cpu_to_le64(0);
33662
33663 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33664 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33665
33666 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33667 sb->size = cpu_to_le64(mddev->dev_sectors);
33668 @@ -2757,7 +2757,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33669 static ssize_t
33670 errors_show(struct md_rdev *rdev, char *page)
33671 {
33672 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33673 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33674 }
33675
33676 static ssize_t
33677 @@ -2766,7 +2766,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33678 char *e;
33679 unsigned long n = simple_strtoul(buf, &e, 10);
33680 if (*buf && (*e == 0 || *e == '\n')) {
33681 - atomic_set(&rdev->corrected_errors, n);
33682 + atomic_set_unchecked(&rdev->corrected_errors, n);
33683 return len;
33684 }
33685 return -EINVAL;
33686 @@ -3213,8 +3213,8 @@ int md_rdev_init(struct md_rdev *rdev)
33687 rdev->sb_loaded = 0;
33688 rdev->bb_page = NULL;
33689 atomic_set(&rdev->nr_pending, 0);
33690 - atomic_set(&rdev->read_errors, 0);
33691 - atomic_set(&rdev->corrected_errors, 0);
33692 + atomic_set_unchecked(&rdev->read_errors, 0);
33693 + atomic_set_unchecked(&rdev->corrected_errors, 0);
33694
33695 INIT_LIST_HEAD(&rdev->same_set);
33696 init_waitqueue_head(&rdev->blocked_wait);
33697 @@ -6947,7 +6947,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33698
33699 spin_unlock(&pers_lock);
33700 seq_printf(seq, "\n");
33701 - seq->poll_event = atomic_read(&md_event_count);
33702 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33703 return 0;
33704 }
33705 if (v == (void*)2) {
33706 @@ -7050,7 +7050,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33707 return error;
33708
33709 seq = file->private_data;
33710 - seq->poll_event = atomic_read(&md_event_count);
33711 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33712 return error;
33713 }
33714
33715 @@ -7064,7 +7064,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33716 /* always allow read */
33717 mask = POLLIN | POLLRDNORM;
33718
33719 - if (seq->poll_event != atomic_read(&md_event_count))
33720 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
33721 mask |= POLLERR | POLLPRI;
33722 return mask;
33723 }
33724 @@ -7108,7 +7108,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
33725 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33726 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33727 (int)part_stat_read(&disk->part0, sectors[1]) -
33728 - atomic_read(&disk->sync_io);
33729 + atomic_read_unchecked(&disk->sync_io);
33730 /* sync IO will cause sync_io to increase before the disk_stats
33731 * as sync_io is counted when a request starts, and
33732 * disk_stats is counted when it completes.
33733 diff --git a/drivers/md/md.h b/drivers/md/md.h
33734 index f385b03..b600be8 100644
33735 --- a/drivers/md/md.h
33736 +++ b/drivers/md/md.h
33737 @@ -94,13 +94,13 @@ struct md_rdev {
33738 * only maintained for arrays that
33739 * support hot removal
33740 */
33741 - atomic_t read_errors; /* number of consecutive read errors that
33742 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
33743 * we have tried to ignore.
33744 */
33745 struct timespec last_read_error; /* monotonic time since our
33746 * last read error
33747 */
33748 - atomic_t corrected_errors; /* number of corrected read errors,
33749 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
33750 * for reporting to userspace and storing
33751 * in superblock.
33752 */
33753 @@ -432,7 +432,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
33754
33755 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
33756 {
33757 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33758 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33759 }
33760
33761 struct md_personality
33762 diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
33763 index f6d29e6..7917f5e 100644
33764 --- a/drivers/md/persistent-data/dm-space-map-disk.c
33765 +++ b/drivers/md/persistent-data/dm-space-map-disk.c
33766 @@ -22,7 +22,7 @@
33767 * Space map interface.
33768 */
33769 struct sm_disk {
33770 - struct dm_space_map sm;
33771 + dm_space_map_no_const sm;
33772
33773 struct ll_disk ll;
33774 struct ll_disk old_ll;
33775 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
33776 index e89ae5e..062e4c2 100644
33777 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
33778 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
33779 @@ -43,7 +43,7 @@ struct block_op {
33780 };
33781
33782 struct sm_metadata {
33783 - struct dm_space_map sm;
33784 + dm_space_map_no_const sm;
33785
33786 struct ll_disk ll;
33787 struct ll_disk old_ll;
33788 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
33789 index 1cbfc6b..56e1dbb 100644
33790 --- a/drivers/md/persistent-data/dm-space-map.h
33791 +++ b/drivers/md/persistent-data/dm-space-map.h
33792 @@ -60,6 +60,7 @@ struct dm_space_map {
33793 int (*root_size)(struct dm_space_map *sm, size_t *result);
33794 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
33795 };
33796 +typedef struct dm_space_map __no_const dm_space_map_no_const;
33797
33798 /*----------------------------------------------------------------*/
33799
33800 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
33801 index 05bb49e..84d7ce6 100644
33802 --- a/drivers/md/raid1.c
33803 +++ b/drivers/md/raid1.c
33804 @@ -1810,7 +1810,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
33805 if (r1_sync_page_io(rdev, sect, s,
33806 bio->bi_io_vec[idx].bv_page,
33807 READ) != 0)
33808 - atomic_add(s, &rdev->corrected_errors);
33809 + atomic_add_unchecked(s, &rdev->corrected_errors);
33810 }
33811 sectors -= s;
33812 sect += s;
33813 @@ -2032,7 +2032,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
33814 test_bit(In_sync, &rdev->flags)) {
33815 if (r1_sync_page_io(rdev, sect, s,
33816 conf->tmppage, READ)) {
33817 - atomic_add(s, &rdev->corrected_errors);
33818 + atomic_add_unchecked(s, &rdev->corrected_errors);
33819 printk(KERN_INFO
33820 "md/raid1:%s: read error corrected "
33821 "(%d sectors at %llu on %s)\n",
33822 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
33823 index a48c215..6bda6f4 100644
33824 --- a/drivers/md/raid10.c
33825 +++ b/drivers/md/raid10.c
33826 @@ -1810,7 +1810,7 @@ static void end_sync_read(struct bio *bio, int error)
33827 /* The write handler will notice the lack of
33828 * R10BIO_Uptodate and record any errors etc
33829 */
33830 - atomic_add(r10_bio->sectors,
33831 + atomic_add_unchecked(r10_bio->sectors,
33832 &conf->mirrors[d].rdev->corrected_errors);
33833
33834 /* for reconstruct, we always reschedule after a read.
33835 @@ -2159,7 +2159,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33836 {
33837 struct timespec cur_time_mon;
33838 unsigned long hours_since_last;
33839 - unsigned int read_errors = atomic_read(&rdev->read_errors);
33840 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
33841
33842 ktime_get_ts(&cur_time_mon);
33843
33844 @@ -2181,9 +2181,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33845 * overflowing the shift of read_errors by hours_since_last.
33846 */
33847 if (hours_since_last >= 8 * sizeof(read_errors))
33848 - atomic_set(&rdev->read_errors, 0);
33849 + atomic_set_unchecked(&rdev->read_errors, 0);
33850 else
33851 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
33852 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
33853 }
33854
33855 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
33856 @@ -2237,8 +2237,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33857 return;
33858
33859 check_decay_read_errors(mddev, rdev);
33860 - atomic_inc(&rdev->read_errors);
33861 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
33862 + atomic_inc_unchecked(&rdev->read_errors);
33863 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
33864 char b[BDEVNAME_SIZE];
33865 bdevname(rdev->bdev, b);
33866
33867 @@ -2246,7 +2246,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33868 "md/raid10:%s: %s: Raid device exceeded "
33869 "read_error threshold [cur %d:max %d]\n",
33870 mdname(mddev), b,
33871 - atomic_read(&rdev->read_errors), max_read_errors);
33872 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
33873 printk(KERN_NOTICE
33874 "md/raid10:%s: %s: Failing raid device\n",
33875 mdname(mddev), b);
33876 @@ -2401,7 +2401,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33877 sect +
33878 choose_data_offset(r10_bio, rdev)),
33879 bdevname(rdev->bdev, b));
33880 - atomic_add(s, &rdev->corrected_errors);
33881 + atomic_add_unchecked(s, &rdev->corrected_errors);
33882 }
33883
33884 rdev_dec_pending(rdev, mddev);
33885 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
33886 index 0689173..35df76c 100644
33887 --- a/drivers/md/raid5.c
33888 +++ b/drivers/md/raid5.c
33889 @@ -1756,21 +1756,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
33890 mdname(conf->mddev), STRIPE_SECTORS,
33891 (unsigned long long)s,
33892 bdevname(rdev->bdev, b));
33893 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
33894 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
33895 clear_bit(R5_ReadError, &sh->dev[i].flags);
33896 clear_bit(R5_ReWrite, &sh->dev[i].flags);
33897 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
33898 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
33899
33900 - if (atomic_read(&rdev->read_errors))
33901 - atomic_set(&rdev->read_errors, 0);
33902 + if (atomic_read_unchecked(&rdev->read_errors))
33903 + atomic_set_unchecked(&rdev->read_errors, 0);
33904 } else {
33905 const char *bdn = bdevname(rdev->bdev, b);
33906 int retry = 0;
33907 int set_bad = 0;
33908
33909 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
33910 - atomic_inc(&rdev->read_errors);
33911 + atomic_inc_unchecked(&rdev->read_errors);
33912 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
33913 printk_ratelimited(
33914 KERN_WARNING
33915 @@ -1798,7 +1798,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
33916 mdname(conf->mddev),
33917 (unsigned long long)s,
33918 bdn);
33919 - } else if (atomic_read(&rdev->read_errors)
33920 + } else if (atomic_read_unchecked(&rdev->read_errors)
33921 > conf->max_nr_stripes)
33922 printk(KERN_WARNING
33923 "md/raid:%s: Too many read errors, failing device %s.\n",
33924 diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
33925 index ebf3f05..b1f3e77 100644
33926 --- a/drivers/media/dvb/ddbridge/ddbridge-core.c
33927 +++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
33928 @@ -1679,7 +1679,7 @@ static struct ddb_info ddb_v6 = {
33929 .subvendor = _subvend, .subdevice = _subdev, \
33930 .driver_data = (unsigned long)&_driverdata }
33931
33932 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
33933 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
33934 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
33935 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
33936 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
33937 diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
33938 index fa7188a..04a045e 100644
33939 --- a/drivers/media/dvb/dvb-core/dvb_demux.h
33940 +++ b/drivers/media/dvb/dvb-core/dvb_demux.h
33941 @@ -73,7 +73,7 @@ struct dvb_demux_feed {
33942 union {
33943 dmx_ts_cb ts;
33944 dmx_section_cb sec;
33945 - } cb;
33946 + } __no_const cb;
33947
33948 struct dvb_demux *demux;
33949 void *priv;
33950 diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
33951 index 39eab73..60033e7 100644
33952 --- a/drivers/media/dvb/dvb-core/dvbdev.c
33953 +++ b/drivers/media/dvb/dvb-core/dvbdev.c
33954 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
33955 const struct dvb_device *template, void *priv, int type)
33956 {
33957 struct dvb_device *dvbdev;
33958 - struct file_operations *dvbdevfops;
33959 + file_operations_no_const *dvbdevfops;
33960 struct device *clsdev;
33961 int minor;
33962 int id;
33963 diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
33964 index 3940bb0..fb3952a 100644
33965 --- a/drivers/media/dvb/dvb-usb/cxusb.c
33966 +++ b/drivers/media/dvb/dvb-usb/cxusb.c
33967 @@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
33968
33969 struct dib0700_adapter_state {
33970 int (*set_param_save) (struct dvb_frontend *);
33971 -};
33972 +} __no_const;
33973
33974 static int dib7070_set_param_override(struct dvb_frontend *fe)
33975 {
33976 diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
33977 index 9382895..ac8093c 100644
33978 --- a/drivers/media/dvb/dvb-usb/dw2102.c
33979 +++ b/drivers/media/dvb/dvb-usb/dw2102.c
33980 @@ -95,7 +95,7 @@ struct su3000_state {
33981
33982 struct s6x0_state {
33983 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
33984 -};
33985 +} __no_const;
33986
33987 /* debug */
33988 static int dvb_usb_dw2102_debug;
33989 diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
33990 index 404f63a..4796533 100644
33991 --- a/drivers/media/dvb/frontends/dib3000.h
33992 +++ b/drivers/media/dvb/frontends/dib3000.h
33993 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
33994 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
33995 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
33996 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
33997 -};
33998 +} __no_const;
33999
34000 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
34001 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
34002 diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
34003 index 72ee8de..eae0c80 100644
34004 --- a/drivers/media/dvb/ngene/ngene-cards.c
34005 +++ b/drivers/media/dvb/ngene/ngene-cards.c
34006 @@ -479,7 +479,7 @@ static struct ngene_info ngene_info_m780 = {
34007
34008 /****************************************************************************/
34009
34010 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
34011 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
34012 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
34013 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
34014 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
34015 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
34016 index 697a421..16c5a5f 100644
34017 --- a/drivers/media/radio/radio-cadet.c
34018 +++ b/drivers/media/radio/radio-cadet.c
34019 @@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
34020 unsigned char readbuf[RDS_BUFFER];
34021 int i = 0;
34022
34023 + if (count > RDS_BUFFER)
34024 + return -EFAULT;
34025 mutex_lock(&dev->lock);
34026 if (dev->rdsstat == 0)
34027 cadet_start_rds(dev);
34028 @@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
34029 while (i < count && dev->rdsin != dev->rdsout)
34030 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
34031
34032 - if (i && copy_to_user(data, readbuf, i))
34033 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
34034 i = -EFAULT;
34035 unlock:
34036 mutex_unlock(&dev->lock);
34037 diff --git a/drivers/media/radio/radio-tea5777.h b/drivers/media/radio/radio-tea5777.h
34038 index 55cbd78..428b0da 100644
34039 --- a/drivers/media/radio/radio-tea5777.h
34040 +++ b/drivers/media/radio/radio-tea5777.h
34041 @@ -63,7 +63,7 @@ struct radio_tea5777_ops {
34042
34043 struct radio_tea5777 {
34044 struct v4l2_device *v4l2_dev;
34045 - struct v4l2_file_operations fops;
34046 + v4l2_file_operations_no_const fops;
34047 struct video_device vd; /* video device */
34048 bool has_am; /* Device can tune to AM freqs */
34049 bool write_before_read; /* must write before read quirk */
34050 diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
34051 index 9cde353..8c6a1c3 100644
34052 --- a/drivers/media/video/au0828/au0828.h
34053 +++ b/drivers/media/video/au0828/au0828.h
34054 @@ -191,7 +191,7 @@ struct au0828_dev {
34055
34056 /* I2C */
34057 struct i2c_adapter i2c_adap;
34058 - struct i2c_algorithm i2c_algo;
34059 + i2c_algorithm_no_const i2c_algo;
34060 struct i2c_client i2c_client;
34061 u32 i2c_rc;
34062
34063 diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
34064 index dfac6e3..c26de31 100644
34065 --- a/drivers/media/video/cx88/cx88-alsa.c
34066 +++ b/drivers/media/video/cx88/cx88-alsa.c
34067 @@ -749,7 +749,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
34068 * Only boards with eeprom and byte 1 at eeprom=1 have it
34069 */
34070
34071 -static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
34072 +static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
34073 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34074 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34075 {0, }
34076 diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
34077 index 88cf9d9..bbc4b2c 100644
34078 --- a/drivers/media/video/omap/omap_vout.c
34079 +++ b/drivers/media/video/omap/omap_vout.c
34080 @@ -64,7 +64,6 @@ enum omap_vout_channels {
34081 OMAP_VIDEO2,
34082 };
34083
34084 -static struct videobuf_queue_ops video_vbq_ops;
34085 /* Variables configurable through module params*/
34086 static u32 video1_numbuffers = 3;
34087 static u32 video2_numbuffers = 3;
34088 @@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
34089 {
34090 struct videobuf_queue *q;
34091 struct omap_vout_device *vout = NULL;
34092 + static struct videobuf_queue_ops video_vbq_ops = {
34093 + .buf_setup = omap_vout_buffer_setup,
34094 + .buf_prepare = omap_vout_buffer_prepare,
34095 + .buf_release = omap_vout_buffer_release,
34096 + .buf_queue = omap_vout_buffer_queue,
34097 + };
34098
34099 vout = video_drvdata(file);
34100 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
34101 @@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
34102 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
34103
34104 q = &vout->vbq;
34105 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
34106 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
34107 - video_vbq_ops.buf_release = omap_vout_buffer_release;
34108 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
34109 spin_lock_init(&vout->vbq_lock);
34110
34111 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
34112 diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34113 index 036952f..80d356d 100644
34114 --- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34115 +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34116 @@ -196,7 +196,7 @@ struct pvr2_hdw {
34117
34118 /* I2C stuff */
34119 struct i2c_adapter i2c_adap;
34120 - struct i2c_algorithm i2c_algo;
34121 + i2c_algorithm_no_const i2c_algo;
34122 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
34123 int i2c_cx25840_hack_state;
34124 int i2c_linked;
34125 diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
34126 index 02194c0..091733b 100644
34127 --- a/drivers/media/video/timblogiw.c
34128 +++ b/drivers/media/video/timblogiw.c
34129 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
34130
34131 /* Platform device functions */
34132
34133 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34134 +static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
34135 .vidioc_querycap = timblogiw_querycap,
34136 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
34137 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
34138 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34139 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
34140 };
34141
34142 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
34143 +static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
34144 .owner = THIS_MODULE,
34145 .open = timblogiw_open,
34146 .release = timblogiw_close,
34147 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
34148 index d99db56..a16b959 100644
34149 --- a/drivers/message/fusion/mptbase.c
34150 +++ b/drivers/message/fusion/mptbase.c
34151 @@ -6751,8 +6751,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
34152 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
34153 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
34154
34155 +#ifdef CONFIG_GRKERNSEC_HIDESYM
34156 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
34157 +#else
34158 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
34159 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
34160 +#endif
34161 +
34162 /*
34163 * Rounding UP to nearest 4-kB boundary here...
34164 */
34165 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
34166 index 551262e..7551198 100644
34167 --- a/drivers/message/fusion/mptsas.c
34168 +++ b/drivers/message/fusion/mptsas.c
34169 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
34170 return 0;
34171 }
34172
34173 +static inline void
34174 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34175 +{
34176 + if (phy_info->port_details) {
34177 + phy_info->port_details->rphy = rphy;
34178 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34179 + ioc->name, rphy));
34180 + }
34181 +
34182 + if (rphy) {
34183 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34184 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34185 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34186 + ioc->name, rphy, rphy->dev.release));
34187 + }
34188 +}
34189 +
34190 /* no mutex */
34191 static void
34192 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
34193 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
34194 return NULL;
34195 }
34196
34197 -static inline void
34198 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34199 -{
34200 - if (phy_info->port_details) {
34201 - phy_info->port_details->rphy = rphy;
34202 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34203 - ioc->name, rphy));
34204 - }
34205 -
34206 - if (rphy) {
34207 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34208 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34209 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34210 - ioc->name, rphy, rphy->dev.release));
34211 - }
34212 -}
34213 -
34214 static inline struct sas_port *
34215 mptsas_get_port(struct mptsas_phyinfo *phy_info)
34216 {
34217 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
34218 index 0c3ced7..1fe34ec 100644
34219 --- a/drivers/message/fusion/mptscsih.c
34220 +++ b/drivers/message/fusion/mptscsih.c
34221 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
34222
34223 h = shost_priv(SChost);
34224
34225 - if (h) {
34226 - if (h->info_kbuf == NULL)
34227 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34228 - return h->info_kbuf;
34229 - h->info_kbuf[0] = '\0';
34230 + if (!h)
34231 + return NULL;
34232
34233 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34234 - h->info_kbuf[size-1] = '\0';
34235 - }
34236 + if (h->info_kbuf == NULL)
34237 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34238 + return h->info_kbuf;
34239 + h->info_kbuf[0] = '\0';
34240 +
34241 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34242 + h->info_kbuf[size-1] = '\0';
34243
34244 return h->info_kbuf;
34245 }
34246 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
34247 index 8001aa6..b137580 100644
34248 --- a/drivers/message/i2o/i2o_proc.c
34249 +++ b/drivers/message/i2o/i2o_proc.c
34250 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
34251 "Array Controller Device"
34252 };
34253
34254 -static char *chtostr(char *tmp, u8 *chars, int n)
34255 -{
34256 - tmp[0] = 0;
34257 - return strncat(tmp, (char *)chars, n);
34258 -}
34259 -
34260 static int i2o_report_query_status(struct seq_file *seq, int block_status,
34261 char *group)
34262 {
34263 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34264 } *result;
34265
34266 i2o_exec_execute_ddm_table ddm_table;
34267 - char tmp[28 + 1];
34268
34269 result = kmalloc(sizeof(*result), GFP_KERNEL);
34270 if (!result)
34271 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34272
34273 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
34274 seq_printf(seq, "%-#8x", ddm_table.module_id);
34275 - seq_printf(seq, "%-29s",
34276 - chtostr(tmp, ddm_table.module_name_version, 28));
34277 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
34278 seq_printf(seq, "%9d ", ddm_table.data_size);
34279 seq_printf(seq, "%8d", ddm_table.code_size);
34280
34281 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34282
34283 i2o_driver_result_table *result;
34284 i2o_driver_store_table *dst;
34285 - char tmp[28 + 1];
34286
34287 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
34288 if (result == NULL)
34289 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34290
34291 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
34292 seq_printf(seq, "%-#8x", dst->module_id);
34293 - seq_printf(seq, "%-29s",
34294 - chtostr(tmp, dst->module_name_version, 28));
34295 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
34296 + seq_printf(seq, "%-.28s", dst->module_name_version);
34297 + seq_printf(seq, "%-.8s", dst->date);
34298 seq_printf(seq, "%8d ", dst->module_size);
34299 seq_printf(seq, "%8d ", dst->mpb_size);
34300 seq_printf(seq, "0x%04x", dst->module_flags);
34301 @@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34302 // == (allow) 512d bytes (max)
34303 static u16 *work16 = (u16 *) work32;
34304 int token;
34305 - char tmp[16 + 1];
34306
34307 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
34308
34309 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34310 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
34311 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
34312 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
34313 - seq_printf(seq, "Vendor info : %s\n",
34314 - chtostr(tmp, (u8 *) (work32 + 2), 16));
34315 - seq_printf(seq, "Product info : %s\n",
34316 - chtostr(tmp, (u8 *) (work32 + 6), 16));
34317 - seq_printf(seq, "Description : %s\n",
34318 - chtostr(tmp, (u8 *) (work32 + 10), 16));
34319 - seq_printf(seq, "Product rev. : %s\n",
34320 - chtostr(tmp, (u8 *) (work32 + 14), 8));
34321 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
34322 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
34323 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
34324 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
34325
34326 seq_printf(seq, "Serial number : ");
34327 print_serial_number(seq, (u8 *) (work32 + 16),
34328 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34329 u8 pad[256]; // allow up to 256 byte (max) serial number
34330 } result;
34331
34332 - char tmp[24 + 1];
34333 -
34334 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
34335
34336 if (token < 0) {
34337 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34338 }
34339
34340 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
34341 - seq_printf(seq, "Module name : %s\n",
34342 - chtostr(tmp, result.module_name, 24));
34343 - seq_printf(seq, "Module revision : %s\n",
34344 - chtostr(tmp, result.module_rev, 8));
34345 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
34346 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
34347
34348 seq_printf(seq, "Serial number : ");
34349 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
34350 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34351 u8 instance_number[4];
34352 } result;
34353
34354 - char tmp[64 + 1];
34355 -
34356 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
34357
34358 if (token < 0) {
34359 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34360 return 0;
34361 }
34362
34363 - seq_printf(seq, "Device name : %s\n",
34364 - chtostr(tmp, result.device_name, 64));
34365 - seq_printf(seq, "Service name : %s\n",
34366 - chtostr(tmp, result.service_name, 64));
34367 - seq_printf(seq, "Physical name : %s\n",
34368 - chtostr(tmp, result.physical_location, 64));
34369 - seq_printf(seq, "Instance number : %s\n",
34370 - chtostr(tmp, result.instance_number, 4));
34371 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
34372 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
34373 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34374 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34375
34376 return 0;
34377 }
34378 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34379 index a8c08f3..155fe3d 100644
34380 --- a/drivers/message/i2o/iop.c
34381 +++ b/drivers/message/i2o/iop.c
34382 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34383
34384 spin_lock_irqsave(&c->context_list_lock, flags);
34385
34386 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34387 - atomic_inc(&c->context_list_counter);
34388 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34389 + atomic_inc_unchecked(&c->context_list_counter);
34390
34391 - entry->context = atomic_read(&c->context_list_counter);
34392 + entry->context = atomic_read_unchecked(&c->context_list_counter);
34393
34394 list_add(&entry->list, &c->context_list);
34395
34396 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34397
34398 #if BITS_PER_LONG == 64
34399 spin_lock_init(&c->context_list_lock);
34400 - atomic_set(&c->context_list_counter, 0);
34401 + atomic_set_unchecked(&c->context_list_counter, 0);
34402 INIT_LIST_HEAD(&c->context_list);
34403 #endif
34404
34405 diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34406 index 7ce65f4..e66e9bc 100644
34407 --- a/drivers/mfd/abx500-core.c
34408 +++ b/drivers/mfd/abx500-core.c
34409 @@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34410
34411 struct abx500_device_entry {
34412 struct list_head list;
34413 - struct abx500_ops ops;
34414 + abx500_ops_no_const ops;
34415 struct device *dev;
34416 };
34417
34418 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34419 index 965c480..71f2db9 100644
34420 --- a/drivers/mfd/janz-cmodio.c
34421 +++ b/drivers/mfd/janz-cmodio.c
34422 @@ -13,6 +13,7 @@
34423
34424 #include <linux/kernel.h>
34425 #include <linux/module.h>
34426 +#include <linux/slab.h>
34427 #include <linux/init.h>
34428 #include <linux/pci.h>
34429 #include <linux/interrupt.h>
34430 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34431 index a981e2a..5ca0c8b 100644
34432 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
34433 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34434 @@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34435 * the lid is closed. This leads to interrupts as soon as a little move
34436 * is done.
34437 */
34438 - atomic_inc(&lis3->count);
34439 + atomic_inc_unchecked(&lis3->count);
34440
34441 wake_up_interruptible(&lis3->misc_wait);
34442 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34443 @@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34444 if (lis3->pm_dev)
34445 pm_runtime_get_sync(lis3->pm_dev);
34446
34447 - atomic_set(&lis3->count, 0);
34448 + atomic_set_unchecked(&lis3->count, 0);
34449 return 0;
34450 }
34451
34452 @@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34453 add_wait_queue(&lis3->misc_wait, &wait);
34454 while (true) {
34455 set_current_state(TASK_INTERRUPTIBLE);
34456 - data = atomic_xchg(&lis3->count, 0);
34457 + data = atomic_xchg_unchecked(&lis3->count, 0);
34458 if (data)
34459 break;
34460
34461 @@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34462 struct lis3lv02d, miscdev);
34463
34464 poll_wait(file, &lis3->misc_wait, wait);
34465 - if (atomic_read(&lis3->count))
34466 + if (atomic_read_unchecked(&lis3->count))
34467 return POLLIN | POLLRDNORM;
34468 return 0;
34469 }
34470 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34471 index 2b1482a..5d33616 100644
34472 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
34473 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34474 @@ -266,7 +266,7 @@ struct lis3lv02d {
34475 struct input_polled_dev *idev; /* input device */
34476 struct platform_device *pdev; /* platform device */
34477 struct regulator_bulk_data regulators[2];
34478 - atomic_t count; /* interrupt count after last read */
34479 + atomic_unchecked_t count; /* interrupt count after last read */
34480 union axis_conversion ac; /* hw -> logical axis */
34481 int mapped_btns[3];
34482
34483 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34484 index 2f30bad..c4c13d0 100644
34485 --- a/drivers/misc/sgi-gru/gruhandles.c
34486 +++ b/drivers/misc/sgi-gru/gruhandles.c
34487 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34488 unsigned long nsec;
34489
34490 nsec = CLKS2NSEC(clks);
34491 - atomic_long_inc(&mcs_op_statistics[op].count);
34492 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
34493 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34494 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34495 if (mcs_op_statistics[op].max < nsec)
34496 mcs_op_statistics[op].max = nsec;
34497 }
34498 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34499 index 950dbe9..eeef0f8 100644
34500 --- a/drivers/misc/sgi-gru/gruprocfs.c
34501 +++ b/drivers/misc/sgi-gru/gruprocfs.c
34502 @@ -32,9 +32,9 @@
34503
34504 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34505
34506 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34507 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34508 {
34509 - unsigned long val = atomic_long_read(v);
34510 + unsigned long val = atomic_long_read_unchecked(v);
34511
34512 seq_printf(s, "%16lu %s\n", val, id);
34513 }
34514 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34515
34516 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34517 for (op = 0; op < mcsop_last; op++) {
34518 - count = atomic_long_read(&mcs_op_statistics[op].count);
34519 - total = atomic_long_read(&mcs_op_statistics[op].total);
34520 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34521 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34522 max = mcs_op_statistics[op].max;
34523 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34524 count ? total / count : 0, max);
34525 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34526 index 5c3ce24..4915ccb 100644
34527 --- a/drivers/misc/sgi-gru/grutables.h
34528 +++ b/drivers/misc/sgi-gru/grutables.h
34529 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34530 * GRU statistics.
34531 */
34532 struct gru_stats_s {
34533 - atomic_long_t vdata_alloc;
34534 - atomic_long_t vdata_free;
34535 - atomic_long_t gts_alloc;
34536 - atomic_long_t gts_free;
34537 - atomic_long_t gms_alloc;
34538 - atomic_long_t gms_free;
34539 - atomic_long_t gts_double_allocate;
34540 - atomic_long_t assign_context;
34541 - atomic_long_t assign_context_failed;
34542 - atomic_long_t free_context;
34543 - atomic_long_t load_user_context;
34544 - atomic_long_t load_kernel_context;
34545 - atomic_long_t lock_kernel_context;
34546 - atomic_long_t unlock_kernel_context;
34547 - atomic_long_t steal_user_context;
34548 - atomic_long_t steal_kernel_context;
34549 - atomic_long_t steal_context_failed;
34550 - atomic_long_t nopfn;
34551 - atomic_long_t asid_new;
34552 - atomic_long_t asid_next;
34553 - atomic_long_t asid_wrap;
34554 - atomic_long_t asid_reuse;
34555 - atomic_long_t intr;
34556 - atomic_long_t intr_cbr;
34557 - atomic_long_t intr_tfh;
34558 - atomic_long_t intr_spurious;
34559 - atomic_long_t intr_mm_lock_failed;
34560 - atomic_long_t call_os;
34561 - atomic_long_t call_os_wait_queue;
34562 - atomic_long_t user_flush_tlb;
34563 - atomic_long_t user_unload_context;
34564 - atomic_long_t user_exception;
34565 - atomic_long_t set_context_option;
34566 - atomic_long_t check_context_retarget_intr;
34567 - atomic_long_t check_context_unload;
34568 - atomic_long_t tlb_dropin;
34569 - atomic_long_t tlb_preload_page;
34570 - atomic_long_t tlb_dropin_fail_no_asid;
34571 - atomic_long_t tlb_dropin_fail_upm;
34572 - atomic_long_t tlb_dropin_fail_invalid;
34573 - atomic_long_t tlb_dropin_fail_range_active;
34574 - atomic_long_t tlb_dropin_fail_idle;
34575 - atomic_long_t tlb_dropin_fail_fmm;
34576 - atomic_long_t tlb_dropin_fail_no_exception;
34577 - atomic_long_t tfh_stale_on_fault;
34578 - atomic_long_t mmu_invalidate_range;
34579 - atomic_long_t mmu_invalidate_page;
34580 - atomic_long_t flush_tlb;
34581 - atomic_long_t flush_tlb_gru;
34582 - atomic_long_t flush_tlb_gru_tgh;
34583 - atomic_long_t flush_tlb_gru_zero_asid;
34584 + atomic_long_unchecked_t vdata_alloc;
34585 + atomic_long_unchecked_t vdata_free;
34586 + atomic_long_unchecked_t gts_alloc;
34587 + atomic_long_unchecked_t gts_free;
34588 + atomic_long_unchecked_t gms_alloc;
34589 + atomic_long_unchecked_t gms_free;
34590 + atomic_long_unchecked_t gts_double_allocate;
34591 + atomic_long_unchecked_t assign_context;
34592 + atomic_long_unchecked_t assign_context_failed;
34593 + atomic_long_unchecked_t free_context;
34594 + atomic_long_unchecked_t load_user_context;
34595 + atomic_long_unchecked_t load_kernel_context;
34596 + atomic_long_unchecked_t lock_kernel_context;
34597 + atomic_long_unchecked_t unlock_kernel_context;
34598 + atomic_long_unchecked_t steal_user_context;
34599 + atomic_long_unchecked_t steal_kernel_context;
34600 + atomic_long_unchecked_t steal_context_failed;
34601 + atomic_long_unchecked_t nopfn;
34602 + atomic_long_unchecked_t asid_new;
34603 + atomic_long_unchecked_t asid_next;
34604 + atomic_long_unchecked_t asid_wrap;
34605 + atomic_long_unchecked_t asid_reuse;
34606 + atomic_long_unchecked_t intr;
34607 + atomic_long_unchecked_t intr_cbr;
34608 + atomic_long_unchecked_t intr_tfh;
34609 + atomic_long_unchecked_t intr_spurious;
34610 + atomic_long_unchecked_t intr_mm_lock_failed;
34611 + atomic_long_unchecked_t call_os;
34612 + atomic_long_unchecked_t call_os_wait_queue;
34613 + atomic_long_unchecked_t user_flush_tlb;
34614 + atomic_long_unchecked_t user_unload_context;
34615 + atomic_long_unchecked_t user_exception;
34616 + atomic_long_unchecked_t set_context_option;
34617 + atomic_long_unchecked_t check_context_retarget_intr;
34618 + atomic_long_unchecked_t check_context_unload;
34619 + atomic_long_unchecked_t tlb_dropin;
34620 + atomic_long_unchecked_t tlb_preload_page;
34621 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34622 + atomic_long_unchecked_t tlb_dropin_fail_upm;
34623 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
34624 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
34625 + atomic_long_unchecked_t tlb_dropin_fail_idle;
34626 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
34627 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34628 + atomic_long_unchecked_t tfh_stale_on_fault;
34629 + atomic_long_unchecked_t mmu_invalidate_range;
34630 + atomic_long_unchecked_t mmu_invalidate_page;
34631 + atomic_long_unchecked_t flush_tlb;
34632 + atomic_long_unchecked_t flush_tlb_gru;
34633 + atomic_long_unchecked_t flush_tlb_gru_tgh;
34634 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34635
34636 - atomic_long_t copy_gpa;
34637 - atomic_long_t read_gpa;
34638 + atomic_long_unchecked_t copy_gpa;
34639 + atomic_long_unchecked_t read_gpa;
34640
34641 - atomic_long_t mesq_receive;
34642 - atomic_long_t mesq_receive_none;
34643 - atomic_long_t mesq_send;
34644 - atomic_long_t mesq_send_failed;
34645 - atomic_long_t mesq_noop;
34646 - atomic_long_t mesq_send_unexpected_error;
34647 - atomic_long_t mesq_send_lb_overflow;
34648 - atomic_long_t mesq_send_qlimit_reached;
34649 - atomic_long_t mesq_send_amo_nacked;
34650 - atomic_long_t mesq_send_put_nacked;
34651 - atomic_long_t mesq_page_overflow;
34652 - atomic_long_t mesq_qf_locked;
34653 - atomic_long_t mesq_qf_noop_not_full;
34654 - atomic_long_t mesq_qf_switch_head_failed;
34655 - atomic_long_t mesq_qf_unexpected_error;
34656 - atomic_long_t mesq_noop_unexpected_error;
34657 - atomic_long_t mesq_noop_lb_overflow;
34658 - atomic_long_t mesq_noop_qlimit_reached;
34659 - atomic_long_t mesq_noop_amo_nacked;
34660 - atomic_long_t mesq_noop_put_nacked;
34661 - atomic_long_t mesq_noop_page_overflow;
34662 + atomic_long_unchecked_t mesq_receive;
34663 + atomic_long_unchecked_t mesq_receive_none;
34664 + atomic_long_unchecked_t mesq_send;
34665 + atomic_long_unchecked_t mesq_send_failed;
34666 + atomic_long_unchecked_t mesq_noop;
34667 + atomic_long_unchecked_t mesq_send_unexpected_error;
34668 + atomic_long_unchecked_t mesq_send_lb_overflow;
34669 + atomic_long_unchecked_t mesq_send_qlimit_reached;
34670 + atomic_long_unchecked_t mesq_send_amo_nacked;
34671 + atomic_long_unchecked_t mesq_send_put_nacked;
34672 + atomic_long_unchecked_t mesq_page_overflow;
34673 + atomic_long_unchecked_t mesq_qf_locked;
34674 + atomic_long_unchecked_t mesq_qf_noop_not_full;
34675 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
34676 + atomic_long_unchecked_t mesq_qf_unexpected_error;
34677 + atomic_long_unchecked_t mesq_noop_unexpected_error;
34678 + atomic_long_unchecked_t mesq_noop_lb_overflow;
34679 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
34680 + atomic_long_unchecked_t mesq_noop_amo_nacked;
34681 + atomic_long_unchecked_t mesq_noop_put_nacked;
34682 + atomic_long_unchecked_t mesq_noop_page_overflow;
34683
34684 };
34685
34686 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34687 tghop_invalidate, mcsop_last};
34688
34689 struct mcs_op_statistic {
34690 - atomic_long_t count;
34691 - atomic_long_t total;
34692 + atomic_long_unchecked_t count;
34693 + atomic_long_unchecked_t total;
34694 unsigned long max;
34695 };
34696
34697 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34698
34699 #define STAT(id) do { \
34700 if (gru_options & OPT_STATS) \
34701 - atomic_long_inc(&gru_stats.id); \
34702 + atomic_long_inc_unchecked(&gru_stats.id); \
34703 } while (0)
34704
34705 #ifdef CONFIG_SGI_GRU_DEBUG
34706 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34707 index c862cd4..0d176fe 100644
34708 --- a/drivers/misc/sgi-xp/xp.h
34709 +++ b/drivers/misc/sgi-xp/xp.h
34710 @@ -288,7 +288,7 @@ struct xpc_interface {
34711 xpc_notify_func, void *);
34712 void (*received) (short, int, void *);
34713 enum xp_retval (*partid_to_nasids) (short, void *);
34714 -};
34715 +} __no_const;
34716
34717 extern struct xpc_interface xpc_interface;
34718
34719 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
34720 index b94d5f7..7f494c5 100644
34721 --- a/drivers/misc/sgi-xp/xpc.h
34722 +++ b/drivers/misc/sgi-xp/xpc.h
34723 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
34724 void (*received_payload) (struct xpc_channel *, void *);
34725 void (*notify_senders_of_disconnect) (struct xpc_channel *);
34726 };
34727 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
34728
34729 /* struct xpc_partition act_state values (for XPC HB) */
34730
34731 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
34732 /* found in xpc_main.c */
34733 extern struct device *xpc_part;
34734 extern struct device *xpc_chan;
34735 -extern struct xpc_arch_operations xpc_arch_ops;
34736 +extern xpc_arch_operations_no_const xpc_arch_ops;
34737 extern int xpc_disengage_timelimit;
34738 extern int xpc_disengage_timedout;
34739 extern int xpc_activate_IRQ_rcvd;
34740 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
34741 index 8d082b4..aa749ae 100644
34742 --- a/drivers/misc/sgi-xp/xpc_main.c
34743 +++ b/drivers/misc/sgi-xp/xpc_main.c
34744 @@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
34745 .notifier_call = xpc_system_die,
34746 };
34747
34748 -struct xpc_arch_operations xpc_arch_ops;
34749 +xpc_arch_operations_no_const xpc_arch_ops;
34750
34751 /*
34752 * Timer function to enforce the timelimit on the partition disengage.
34753 diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
34754 index 504da71..9722d43 100644
34755 --- a/drivers/mmc/host/sdhci-pci.c
34756 +++ b/drivers/mmc/host/sdhci-pci.c
34757 @@ -653,7 +653,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
34758 .probe = via_probe,
34759 };
34760
34761 -static const struct pci_device_id pci_ids[] __devinitdata = {
34762 +static const struct pci_device_id pci_ids[] __devinitconst = {
34763 {
34764 .vendor = PCI_VENDOR_ID_RICOH,
34765 .device = PCI_DEVICE_ID_RICOH_R5C822,
34766 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
34767 index a4eb8b5..8c0628f 100644
34768 --- a/drivers/mtd/devices/doc2000.c
34769 +++ b/drivers/mtd/devices/doc2000.c
34770 @@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
34771
34772 /* The ECC will not be calculated correctly if less than 512 is written */
34773 /* DBB-
34774 - if (len != 0x200 && eccbuf)
34775 + if (len != 0x200)
34776 printk(KERN_WARNING
34777 "ECC needs a full sector write (adr: %lx size %lx)\n",
34778 (long) to, (long) len);
34779 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
34780 index 0650aaf..7718762 100644
34781 --- a/drivers/mtd/nand/denali.c
34782 +++ b/drivers/mtd/nand/denali.c
34783 @@ -26,6 +26,7 @@
34784 #include <linux/pci.h>
34785 #include <linux/mtd/mtd.h>
34786 #include <linux/module.h>
34787 +#include <linux/slab.h>
34788
34789 #include "denali.h"
34790
34791 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
34792 index 51b9d6a..52af9a7 100644
34793 --- a/drivers/mtd/nftlmount.c
34794 +++ b/drivers/mtd/nftlmount.c
34795 @@ -24,6 +24,7 @@
34796 #include <asm/errno.h>
34797 #include <linux/delay.h>
34798 #include <linux/slab.h>
34799 +#include <linux/sched.h>
34800 #include <linux/mtd/mtd.h>
34801 #include <linux/mtd/nand.h>
34802 #include <linux/mtd/nftl.h>
34803 diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c
34804 index dc15d24..ef8d2a0 100644
34805 --- a/drivers/net/bonding/bond_sysfs.c
34806 +++ b/drivers/net/bonding/bond_sysfs.c
34807 @@ -1060,7 +1060,7 @@ static ssize_t bonding_store_primary(struct device *d,
34808 goto out;
34809 }
34810
34811 - sscanf(buf, "%16s", ifname); /* IFNAMSIZ */
34812 + sscanf(buf, "%15s", ifname); /* IFNAMSIZ */
34813
34814 /* check to see if we are clearing primary */
34815 if (!strlen(ifname) || buf[0] == '\n') {
34816 @@ -1237,7 +1237,7 @@ static ssize_t bonding_store_active_slave(struct device *d,
34817 goto out;
34818 }
34819
34820 - sscanf(buf, "%16s", ifname); /* IFNAMSIZ */
34821 + sscanf(buf, "%15s", ifname); /* IFNAMSIZ */
34822
34823 /* check to see if we are clearing active */
34824 if (!strlen(ifname) || buf[0] == '\n') {
34825 diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
34826 index 57d64b8..623dd86 100644
34827 --- a/drivers/net/ethernet/atheros/atlx/atl2.c
34828 +++ b/drivers/net/ethernet/atheros/atlx/atl2.c
34829 @@ -2845,7 +2845,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
34830 */
34831
34832 #define ATL2_PARAM(X, desc) \
34833 - static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34834 + static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34835 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
34836 MODULE_PARM_DESC(X, desc);
34837 #else
34838 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
34839 index 0875ecf..794cdf3 100644
34840 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
34841 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
34842 @@ -3051,9 +3051,8 @@ static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
34843 struct eth_stats_info *ether_stat =
34844 &bp->slowpath->drv_info_to_mcp.ether_stat;
34845
34846 - /* leave last char as NULL */
34847 - memcpy(ether_stat->version, DRV_MODULE_VERSION,
34848 - ETH_STAT_INFO_VERSION_LEN - 1);
34849 + strlcpy(ether_stat->version, DRV_MODULE_VERSION,
34850 + ETH_STAT_INFO_VERSION_LEN);
34851
34852 bp->sp_objs[0].mac_obj.get_n_elements(bp, &bp->sp_objs[0].mac_obj,
34853 DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
34854 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34855 index f83e033..8b4f43a 100644
34856 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34857 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34858 @@ -486,7 +486,7 @@ struct bnx2x_rx_mode_obj {
34859
34860 int (*wait_comp)(struct bnx2x *bp,
34861 struct bnx2x_rx_mode_ramrod_params *p);
34862 -};
34863 +} __no_const;
34864
34865 /********************** Set multicast group ***********************************/
34866
34867 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
34868 index 6d52cb2..bc95640 100644
34869 --- a/drivers/net/ethernet/broadcom/tg3.h
34870 +++ b/drivers/net/ethernet/broadcom/tg3.h
34871 @@ -140,6 +140,7 @@
34872 #define CHIPREV_ID_5750_A0 0x4000
34873 #define CHIPREV_ID_5750_A1 0x4001
34874 #define CHIPREV_ID_5750_A3 0x4003
34875 +#define CHIPREV_ID_5750_C1 0x4201
34876 #define CHIPREV_ID_5750_C2 0x4202
34877 #define CHIPREV_ID_5752_A0_HW 0x5000
34878 #define CHIPREV_ID_5752_A0 0x6000
34879 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34880 index 8cffcdf..aadf043 100644
34881 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34882 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34883 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
34884 */
34885 struct l2t_skb_cb {
34886 arp_failure_handler_func arp_failure_handler;
34887 -};
34888 +} __no_const;
34889
34890 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
34891
34892 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
34893 index f879e92..726f20f 100644
34894 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
34895 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
34896 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34897 for (i=0; i<ETH_ALEN; i++) {
34898 tmp.addr[i] = dev->dev_addr[i];
34899 }
34900 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34901 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34902 break;
34903
34904 case DE4X5_SET_HWADDR: /* Set the hardware address */
34905 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34906 spin_lock_irqsave(&lp->lock, flags);
34907 memcpy(&statbuf, &lp->pktStats, ioc->len);
34908 spin_unlock_irqrestore(&lp->lock, flags);
34909 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
34910 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
34911 return -EFAULT;
34912 break;
34913 }
34914 diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
34915 index ed7d1dc..d426748 100644
34916 --- a/drivers/net/ethernet/dec/tulip/eeprom.c
34917 +++ b/drivers/net/ethernet/dec/tulip/eeprom.c
34918 @@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
34919 {NULL}};
34920
34921
34922 -static const char *block_name[] __devinitdata = {
34923 +static const char *block_name[] __devinitconst = {
34924 "21140 non-MII",
34925 "21140 MII PHY",
34926 "21142 Serial PHY",
34927 diff --git a/drivers/net/ethernet/dec/tulip/uli526x.c b/drivers/net/ethernet/dec/tulip/uli526x.c
34928 index 75d45f8..3d9c55b 100644
34929 --- a/drivers/net/ethernet/dec/tulip/uli526x.c
34930 +++ b/drivers/net/ethernet/dec/tulip/uli526x.c
34931 @@ -129,7 +129,7 @@ struct uli526x_board_info {
34932 struct uli_phy_ops {
34933 void (*write)(struct uli526x_board_info *, u8, u8, u16);
34934 u16 (*read)(struct uli526x_board_info *, u8, u8);
34935 - } phy;
34936 + } __no_const phy;
34937 struct net_device *next_dev; /* next device */
34938 struct pci_dev *pdev; /* PCI device */
34939 spinlock_t lock;
34940 diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
34941 index 4d1ffca..7c1ec4d 100644
34942 --- a/drivers/net/ethernet/dec/tulip/winbond-840.c
34943 +++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
34944 @@ -236,7 +236,7 @@ struct pci_id_info {
34945 int drv_flags; /* Driver use, intended as capability flags. */
34946 };
34947
34948 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34949 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34950 { /* Sometime a Level-One switch card. */
34951 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
34952 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
34953 diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
34954 index d7bb52a..3b83588 100644
34955 --- a/drivers/net/ethernet/dlink/sundance.c
34956 +++ b/drivers/net/ethernet/dlink/sundance.c
34957 @@ -218,7 +218,7 @@ enum {
34958 struct pci_id_info {
34959 const char *name;
34960 };
34961 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34962 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34963 {"D-Link DFE-550TX FAST Ethernet Adapter"},
34964 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
34965 {"D-Link DFE-580TX 4 port Server Adapter"},
34966 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
34967 index 78b8aa8..dd6323a 100644
34968 --- a/drivers/net/ethernet/emulex/benet/be_main.c
34969 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
34970 @@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
34971
34972 if (wrapped)
34973 newacc += 65536;
34974 - ACCESS_ONCE(*acc) = newacc;
34975 + ACCESS_ONCE_RW(*acc) = newacc;
34976 }
34977
34978 void be_parse_stats(struct be_adapter *adapter)
34979 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
34980 index 74d749e..eefb1bd 100644
34981 --- a/drivers/net/ethernet/faraday/ftgmac100.c
34982 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
34983 @@ -31,6 +31,8 @@
34984 #include <linux/netdevice.h>
34985 #include <linux/phy.h>
34986 #include <linux/platform_device.h>
34987 +#include <linux/interrupt.h>
34988 +#include <linux/irqreturn.h>
34989 #include <net/ip.h>
34990
34991 #include "ftgmac100.h"
34992 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
34993 index b901a01..1ff32ee 100644
34994 --- a/drivers/net/ethernet/faraday/ftmac100.c
34995 +++ b/drivers/net/ethernet/faraday/ftmac100.c
34996 @@ -31,6 +31,8 @@
34997 #include <linux/module.h>
34998 #include <linux/netdevice.h>
34999 #include <linux/platform_device.h>
35000 +#include <linux/interrupt.h>
35001 +#include <linux/irqreturn.h>
35002
35003 #include "ftmac100.h"
35004
35005 diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
35006 index 9d71c9c..0e4a0ac 100644
35007 --- a/drivers/net/ethernet/fealnx.c
35008 +++ b/drivers/net/ethernet/fealnx.c
35009 @@ -150,7 +150,7 @@ struct chip_info {
35010 int flags;
35011 };
35012
35013 -static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
35014 +static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
35015 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
35016 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
35017 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
35018 diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
35019 index ed5b409..ec37828 100644
35020 --- a/drivers/net/ethernet/intel/e1000e/hw.h
35021 +++ b/drivers/net/ethernet/intel/e1000e/hw.h
35022 @@ -797,6 +797,7 @@ struct e1000_mac_operations {
35023 void (*rar_set)(struct e1000_hw *, u8 *, u32);
35024 s32 (*read_mac_addr)(struct e1000_hw *);
35025 };
35026 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35027
35028 /*
35029 * When to use various PHY register access functions:
35030 @@ -837,6 +838,7 @@ struct e1000_phy_operations {
35031 void (*power_up)(struct e1000_hw *);
35032 void (*power_down)(struct e1000_hw *);
35033 };
35034 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
35035
35036 /* Function pointers for the NVM. */
35037 struct e1000_nvm_operations {
35038 @@ -849,9 +851,10 @@ struct e1000_nvm_operations {
35039 s32 (*validate)(struct e1000_hw *);
35040 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
35041 };
35042 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
35043
35044 struct e1000_mac_info {
35045 - struct e1000_mac_operations ops;
35046 + e1000_mac_operations_no_const ops;
35047 u8 addr[ETH_ALEN];
35048 u8 perm_addr[ETH_ALEN];
35049
35050 @@ -892,7 +895,7 @@ struct e1000_mac_info {
35051 };
35052
35053 struct e1000_phy_info {
35054 - struct e1000_phy_operations ops;
35055 + e1000_phy_operations_no_const ops;
35056
35057 enum e1000_phy_type type;
35058
35059 @@ -926,7 +929,7 @@ struct e1000_phy_info {
35060 };
35061
35062 struct e1000_nvm_info {
35063 - struct e1000_nvm_operations ops;
35064 + e1000_nvm_operations_no_const ops;
35065
35066 enum e1000_nvm_type type;
35067 enum e1000_nvm_override override;
35068 diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
35069 index c2a51dc..c2bd262 100644
35070 --- a/drivers/net/ethernet/intel/igb/e1000_hw.h
35071 +++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
35072 @@ -327,6 +327,7 @@ struct e1000_mac_operations {
35073 void (*release_swfw_sync)(struct e1000_hw *, u16);
35074
35075 };
35076 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35077
35078 struct e1000_phy_operations {
35079 s32 (*acquire)(struct e1000_hw *);
35080 @@ -343,6 +344,7 @@ struct e1000_phy_operations {
35081 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
35082 s32 (*write_reg)(struct e1000_hw *, u32, u16);
35083 };
35084 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
35085
35086 struct e1000_nvm_operations {
35087 s32 (*acquire)(struct e1000_hw *);
35088 @@ -353,6 +355,7 @@ struct e1000_nvm_operations {
35089 s32 (*validate)(struct e1000_hw *);
35090 s32 (*valid_led_default)(struct e1000_hw *, u16 *);
35091 };
35092 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
35093
35094 struct e1000_info {
35095 s32 (*get_invariants)(struct e1000_hw *);
35096 @@ -364,7 +367,7 @@ struct e1000_info {
35097 extern const struct e1000_info e1000_82575_info;
35098
35099 struct e1000_mac_info {
35100 - struct e1000_mac_operations ops;
35101 + e1000_mac_operations_no_const ops;
35102
35103 u8 addr[6];
35104 u8 perm_addr[6];
35105 @@ -402,7 +405,7 @@ struct e1000_mac_info {
35106 };
35107
35108 struct e1000_phy_info {
35109 - struct e1000_phy_operations ops;
35110 + e1000_phy_operations_no_const ops;
35111
35112 enum e1000_phy_type type;
35113
35114 @@ -437,7 +440,7 @@ struct e1000_phy_info {
35115 };
35116
35117 struct e1000_nvm_info {
35118 - struct e1000_nvm_operations ops;
35119 + e1000_nvm_operations_no_const ops;
35120 enum e1000_nvm_type type;
35121 enum e1000_nvm_override override;
35122
35123 @@ -482,6 +485,7 @@ struct e1000_mbx_operations {
35124 s32 (*check_for_ack)(struct e1000_hw *, u16);
35125 s32 (*check_for_rst)(struct e1000_hw *, u16);
35126 };
35127 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35128
35129 struct e1000_mbx_stats {
35130 u32 msgs_tx;
35131 @@ -493,7 +497,7 @@ struct e1000_mbx_stats {
35132 };
35133
35134 struct e1000_mbx_info {
35135 - struct e1000_mbx_operations ops;
35136 + e1000_mbx_operations_no_const ops;
35137 struct e1000_mbx_stats stats;
35138 u32 timeout;
35139 u32 usec_delay;
35140 diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
35141 index 57db3c6..aa825fc 100644
35142 --- a/drivers/net/ethernet/intel/igbvf/vf.h
35143 +++ b/drivers/net/ethernet/intel/igbvf/vf.h
35144 @@ -189,9 +189,10 @@ struct e1000_mac_operations {
35145 s32 (*read_mac_addr)(struct e1000_hw *);
35146 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
35147 };
35148 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35149
35150 struct e1000_mac_info {
35151 - struct e1000_mac_operations ops;
35152 + e1000_mac_operations_no_const ops;
35153 u8 addr[6];
35154 u8 perm_addr[6];
35155
35156 @@ -213,6 +214,7 @@ struct e1000_mbx_operations {
35157 s32 (*check_for_ack)(struct e1000_hw *);
35158 s32 (*check_for_rst)(struct e1000_hw *);
35159 };
35160 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35161
35162 struct e1000_mbx_stats {
35163 u32 msgs_tx;
35164 @@ -224,7 +226,7 @@ struct e1000_mbx_stats {
35165 };
35166
35167 struct e1000_mbx_info {
35168 - struct e1000_mbx_operations ops;
35169 + e1000_mbx_operations_no_const ops;
35170 struct e1000_mbx_stats stats;
35171 u32 timeout;
35172 u32 usec_delay;
35173 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35174 index 3456d56..b688d81 100644
35175 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35176 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35177 @@ -884,7 +884,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
35178 /* store the new cycle speed */
35179 adapter->cycle_speed = cycle_speed;
35180
35181 - ACCESS_ONCE(adapter->base_incval) = incval;
35182 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
35183 smp_mb();
35184
35185 /* grab the ptp lock */
35186 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35187 index 400f86a..7f2e062 100644
35188 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35189 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35190 @@ -2799,6 +2799,7 @@ struct ixgbe_eeprom_operations {
35191 s32 (*update_checksum)(struct ixgbe_hw *);
35192 u16 (*calc_checksum)(struct ixgbe_hw *);
35193 };
35194 +typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
35195
35196 struct ixgbe_mac_operations {
35197 s32 (*init_hw)(struct ixgbe_hw *);
35198 @@ -2865,6 +2866,7 @@ struct ixgbe_mac_operations {
35199 s32 (*get_thermal_sensor_data)(struct ixgbe_hw *);
35200 s32 (*init_thermal_sensor_thresh)(struct ixgbe_hw *hw);
35201 };
35202 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35203
35204 struct ixgbe_phy_operations {
35205 s32 (*identify)(struct ixgbe_hw *);
35206 @@ -2884,9 +2886,10 @@ struct ixgbe_phy_operations {
35207 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
35208 s32 (*check_overtemp)(struct ixgbe_hw *);
35209 };
35210 +typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
35211
35212 struct ixgbe_eeprom_info {
35213 - struct ixgbe_eeprom_operations ops;
35214 + ixgbe_eeprom_operations_no_const ops;
35215 enum ixgbe_eeprom_type type;
35216 u32 semaphore_delay;
35217 u16 word_size;
35218 @@ -2896,7 +2899,7 @@ struct ixgbe_eeprom_info {
35219
35220 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
35221 struct ixgbe_mac_info {
35222 - struct ixgbe_mac_operations ops;
35223 + ixgbe_mac_operations_no_const ops;
35224 enum ixgbe_mac_type type;
35225 u8 addr[ETH_ALEN];
35226 u8 perm_addr[ETH_ALEN];
35227 @@ -2926,7 +2929,7 @@ struct ixgbe_mac_info {
35228 };
35229
35230 struct ixgbe_phy_info {
35231 - struct ixgbe_phy_operations ops;
35232 + ixgbe_phy_operations_no_const ops;
35233 struct mdio_if_info mdio;
35234 enum ixgbe_phy_type type;
35235 u32 id;
35236 @@ -2954,6 +2957,7 @@ struct ixgbe_mbx_operations {
35237 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
35238 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
35239 };
35240 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35241
35242 struct ixgbe_mbx_stats {
35243 u32 msgs_tx;
35244 @@ -2965,7 +2969,7 @@ struct ixgbe_mbx_stats {
35245 };
35246
35247 struct ixgbe_mbx_info {
35248 - struct ixgbe_mbx_operations ops;
35249 + ixgbe_mbx_operations_no_const ops;
35250 struct ixgbe_mbx_stats stats;
35251 u32 timeout;
35252 u32 usec_delay;
35253 diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
35254 index 25c951d..cc7cf33 100644
35255 --- a/drivers/net/ethernet/intel/ixgbevf/vf.h
35256 +++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
35257 @@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
35258 s32 (*clear_vfta)(struct ixgbe_hw *);
35259 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
35260 };
35261 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35262
35263 enum ixgbe_mac_type {
35264 ixgbe_mac_unknown = 0,
35265 @@ -79,7 +80,7 @@ enum ixgbe_mac_type {
35266 };
35267
35268 struct ixgbe_mac_info {
35269 - struct ixgbe_mac_operations ops;
35270 + ixgbe_mac_operations_no_const ops;
35271 u8 addr[6];
35272 u8 perm_addr[6];
35273
35274 @@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
35275 s32 (*check_for_ack)(struct ixgbe_hw *);
35276 s32 (*check_for_rst)(struct ixgbe_hw *);
35277 };
35278 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35279
35280 struct ixgbe_mbx_stats {
35281 u32 msgs_tx;
35282 @@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
35283 };
35284
35285 struct ixgbe_mbx_info {
35286 - struct ixgbe_mbx_operations ops;
35287 + ixgbe_mbx_operations_no_const ops;
35288 struct ixgbe_mbx_stats stats;
35289 u32 timeout;
35290 u32 udelay;
35291 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35292 index 9e0c1ee..8471f77 100644
35293 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
35294 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35295 @@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
35296 void (*link_down)(struct __vxge_hw_device *devh);
35297 void (*crit_err)(struct __vxge_hw_device *devh,
35298 enum vxge_hw_event type, u64 ext_data);
35299 -};
35300 +} __no_const;
35301
35302 /*
35303 * struct __vxge_hw_blockpool_entry - Block private data structure
35304 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35305 index 4a518a3..936b334 100644
35306 --- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35307 +++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35308 @@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
35309 struct vxge_hw_mempool_dma *dma_object,
35310 u32 index,
35311 u32 is_last);
35312 -};
35313 +} __no_const;
35314
35315 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
35316 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
35317 diff --git a/drivers/net/ethernet/nxp/lpc_eth.c b/drivers/net/ethernet/nxp/lpc_eth.c
35318 index 53743f7..af8b414 100644
35319 --- a/drivers/net/ethernet/nxp/lpc_eth.c
35320 +++ b/drivers/net/ethernet/nxp/lpc_eth.c
35321 @@ -1524,6 +1524,7 @@ static int lpc_eth_drv_remove(struct platform_device *pdev)
35322 pldat->dma_buff_base_p);
35323 free_irq(ndev->irq, ndev);
35324 iounmap(pldat->net_base);
35325 + mdiobus_unregister(pldat->mii_bus);
35326 mdiobus_free(pldat->mii_bus);
35327 clk_disable(pldat->clk);
35328 clk_put(pldat->clk);
35329 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
35330 index b47d5b3..273a516 100644
35331 --- a/drivers/net/ethernet/realtek/r8169.c
35332 +++ b/drivers/net/ethernet/realtek/r8169.c
35333 @@ -745,22 +745,22 @@ struct rtl8169_private {
35334 struct mdio_ops {
35335 void (*write)(struct rtl8169_private *, int, int);
35336 int (*read)(struct rtl8169_private *, int);
35337 - } mdio_ops;
35338 + } __no_const mdio_ops;
35339
35340 struct pll_power_ops {
35341 void (*down)(struct rtl8169_private *);
35342 void (*up)(struct rtl8169_private *);
35343 - } pll_power_ops;
35344 + } __no_const pll_power_ops;
35345
35346 struct jumbo_ops {
35347 void (*enable)(struct rtl8169_private *);
35348 void (*disable)(struct rtl8169_private *);
35349 - } jumbo_ops;
35350 + } __no_const jumbo_ops;
35351
35352 struct csi_ops {
35353 void (*write)(struct rtl8169_private *, int, int);
35354 u32 (*read)(struct rtl8169_private *, int);
35355 - } csi_ops;
35356 + } __no_const csi_ops;
35357
35358 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
35359 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
35360 diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
35361 index 4613591..d816601 100644
35362 --- a/drivers/net/ethernet/sis/sis190.c
35363 +++ b/drivers/net/ethernet/sis/sis190.c
35364 @@ -1618,7 +1618,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
35365 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
35366 struct net_device *dev)
35367 {
35368 - static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
35369 + static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
35370 struct sis190_private *tp = netdev_priv(dev);
35371 struct pci_dev *isa_bridge;
35372 u8 reg, tmp8;
35373 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35374 index 0c74a70..3bc6f68 100644
35375 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35376 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35377 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
35378
35379 writel(value, ioaddr + MMC_CNTRL);
35380
35381 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35382 - MMC_CNTRL, value);
35383 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35384 +// MMC_CNTRL, value);
35385 }
35386
35387 /* To mask all all interrupts.*/
35388 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
35389 index 95ceb35..318fc12 100644
35390 --- a/drivers/net/hyperv/hyperv_net.h
35391 +++ b/drivers/net/hyperv/hyperv_net.h
35392 @@ -99,7 +99,7 @@ struct rndis_device {
35393
35394 enum rndis_device_state state;
35395 bool link_state;
35396 - atomic_t new_req_id;
35397 + atomic_unchecked_t new_req_id;
35398
35399 spinlock_t request_lock;
35400 struct list_head req_list;
35401 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
35402 index 1e88a10..1b01736 100644
35403 --- a/drivers/net/hyperv/rndis_filter.c
35404 +++ b/drivers/net/hyperv/rndis_filter.c
35405 @@ -99,7 +99,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35406 * template
35407 */
35408 set = &rndis_msg->msg.set_req;
35409 - set->req_id = atomic_inc_return(&dev->new_req_id);
35410 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35411
35412 /* Add to the request list */
35413 spin_lock_irqsave(&dev->request_lock, flags);
35414 @@ -730,7 +730,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35415
35416 /* Setup the rndis set */
35417 halt = &request->request_msg.msg.halt_req;
35418 - halt->req_id = atomic_inc_return(&dev->new_req_id);
35419 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35420
35421 /* Ignore return since this msg is optional. */
35422 rndis_filter_send_request(dev, request);
35423 diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
35424 index daec9b0..6428fcb 100644
35425 --- a/drivers/net/phy/mdio-bitbang.c
35426 +++ b/drivers/net/phy/mdio-bitbang.c
35427 @@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
35428 struct mdiobb_ctrl *ctrl = bus->priv;
35429
35430 module_put(ctrl->ops->owner);
35431 + mdiobus_unregister(bus);
35432 mdiobus_free(bus);
35433 }
35434 EXPORT_SYMBOL(free_mdio_bitbang);
35435 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35436 index 5c05572..389610b 100644
35437 --- a/drivers/net/ppp/ppp_generic.c
35438 +++ b/drivers/net/ppp/ppp_generic.c
35439 @@ -986,7 +986,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35440 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35441 struct ppp_stats stats;
35442 struct ppp_comp_stats cstats;
35443 - char *vers;
35444
35445 switch (cmd) {
35446 case SIOCGPPPSTATS:
35447 @@ -1008,8 +1007,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35448 break;
35449
35450 case SIOCGPPPVER:
35451 - vers = PPP_VERSION;
35452 - if (copy_to_user(addr, vers, strlen(vers) + 1))
35453 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35454 break;
35455 err = 0;
35456 break;
35457 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
35458 index 3a16d4f..a311cec 100644
35459 --- a/drivers/net/tun.c
35460 +++ b/drivers/net/tun.c
35461 @@ -1367,7 +1367,7 @@ static int set_offload(struct tun_struct *tun, unsigned long arg)
35462 }
35463
35464 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
35465 - unsigned long arg, int ifreq_len)
35466 + unsigned long arg, size_t ifreq_len)
35467 {
35468 struct tun_file *tfile = file->private_data;
35469 struct tun_struct *tun;
35470 @@ -1378,6 +1378,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
35471 int vnet_hdr_sz;
35472 int ret;
35473
35474 + if (ifreq_len > sizeof ifr)
35475 + return -EFAULT;
35476 +
35477 if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89) {
35478 if (copy_from_user(&ifr, argp, ifreq_len))
35479 return -EFAULT;
35480 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35481 index 62f30b4..ff99dfd 100644
35482 --- a/drivers/net/usb/hso.c
35483 +++ b/drivers/net/usb/hso.c
35484 @@ -71,7 +71,7 @@
35485 #include <asm/byteorder.h>
35486 #include <linux/serial_core.h>
35487 #include <linux/serial.h>
35488 -
35489 +#include <asm/local.h>
35490
35491 #define MOD_AUTHOR "Option Wireless"
35492 #define MOD_DESCRIPTION "USB High Speed Option driver"
35493 @@ -1182,7 +1182,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35494 struct urb *urb;
35495
35496 urb = serial->rx_urb[0];
35497 - if (serial->port.count > 0) {
35498 + if (atomic_read(&serial->port.count) > 0) {
35499 count = put_rxbuf_data(urb, serial);
35500 if (count == -1)
35501 return;
35502 @@ -1218,7 +1218,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35503 DUMP1(urb->transfer_buffer, urb->actual_length);
35504
35505 /* Anyone listening? */
35506 - if (serial->port.count == 0)
35507 + if (atomic_read(&serial->port.count) == 0)
35508 return;
35509
35510 if (status == 0) {
35511 @@ -1300,8 +1300,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35512 tty_port_tty_set(&serial->port, tty);
35513
35514 /* check for port already opened, if not set the termios */
35515 - serial->port.count++;
35516 - if (serial->port.count == 1) {
35517 + if (atomic_inc_return(&serial->port.count) == 1) {
35518 serial->rx_state = RX_IDLE;
35519 /* Force default termio settings */
35520 _hso_serial_set_termios(tty, NULL);
35521 @@ -1313,7 +1312,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35522 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35523 if (result) {
35524 hso_stop_serial_device(serial->parent);
35525 - serial->port.count--;
35526 + atomic_dec(&serial->port.count);
35527 kref_put(&serial->parent->ref, hso_serial_ref_free);
35528 }
35529 } else {
35530 @@ -1350,10 +1349,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35531
35532 /* reset the rts and dtr */
35533 /* do the actual close */
35534 - serial->port.count--;
35535 + atomic_dec(&serial->port.count);
35536
35537 - if (serial->port.count <= 0) {
35538 - serial->port.count = 0;
35539 + if (atomic_read(&serial->port.count) <= 0) {
35540 + atomic_set(&serial->port.count, 0);
35541 tty_port_tty_set(&serial->port, NULL);
35542 if (!usb_gone)
35543 hso_stop_serial_device(serial->parent);
35544 @@ -1429,7 +1428,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35545
35546 /* the actual setup */
35547 spin_lock_irqsave(&serial->serial_lock, flags);
35548 - if (serial->port.count)
35549 + if (atomic_read(&serial->port.count))
35550 _hso_serial_set_termios(tty, old);
35551 else
35552 tty->termios = old;
35553 @@ -1888,7 +1887,7 @@ static void intr_callback(struct urb *urb)
35554 D1("Pending read interrupt on port %d\n", i);
35555 spin_lock(&serial->serial_lock);
35556 if (serial->rx_state == RX_IDLE &&
35557 - serial->port.count > 0) {
35558 + atomic_read(&serial->port.count) > 0) {
35559 /* Setup and send a ctrl req read on
35560 * port i */
35561 if (!serial->rx_urb_filled[0]) {
35562 @@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
35563 /* Start all serial ports */
35564 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35565 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35566 - if (dev2ser(serial_table[i])->port.count) {
35567 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
35568 result =
35569 hso_start_serial_device(serial_table[i], GFP_NOIO);
35570 hso_kick_transmit(dev2ser(serial_table[i]));
35571 diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35572 index 6169fbd..40e8422 100644
35573 --- a/drivers/net/wireless/ath/ath.h
35574 +++ b/drivers/net/wireless/ath/ath.h
35575 @@ -119,6 +119,7 @@ struct ath_ops {
35576 void (*write_flush) (void *);
35577 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35578 };
35579 +typedef struct ath_ops __no_const ath_ops_no_const;
35580
35581 struct ath_common;
35582 struct ath_bus_ops;
35583 diff --git a/drivers/net/wireless/ath/ath5k/base.c b/drivers/net/wireless/ath/ath5k/base.c
35584 index 2aab20e..b761ef8 100644
35585 --- a/drivers/net/wireless/ath/ath5k/base.c
35586 +++ b/drivers/net/wireless/ath/ath5k/base.c
35587 @@ -1803,7 +1803,7 @@ ath5k_beacon_update(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
35588 {
35589 int ret;
35590 struct ath5k_hw *ah = hw->priv;
35591 - struct ath5k_vif *avf = (void *)vif->drv_priv;
35592 + struct ath5k_vif *avf;
35593 struct sk_buff *skb;
35594
35595 if (WARN_ON(!vif)) {
35596 @@ -1818,6 +1818,7 @@ ath5k_beacon_update(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
35597 goto out;
35598 }
35599
35600 + avf = (void *)vif->drv_priv;
35601 ath5k_txbuf_free_skb(ah, avf->bbuf);
35602 avf->bbuf->skb = skb;
35603 ret = ath5k_beacon_setup(ah, avf->bbuf);
35604 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35605 index 8d78253..bebbb68 100644
35606 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35607 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35608 @@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35609 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35610 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35611
35612 - ACCESS_ONCE(ads->ds_link) = i->link;
35613 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35614 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
35615 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35616
35617 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35618 ctl6 = SM(i->keytype, AR_EncrType);
35619 @@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35620
35621 if ((i->is_first || i->is_last) &&
35622 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35623 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35624 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35625 | set11nTries(i->rates, 1)
35626 | set11nTries(i->rates, 2)
35627 | set11nTries(i->rates, 3)
35628 | (i->dur_update ? AR_DurUpdateEna : 0)
35629 | SM(0, AR_BurstDur);
35630
35631 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35632 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35633 | set11nRate(i->rates, 1)
35634 | set11nRate(i->rates, 2)
35635 | set11nRate(i->rates, 3);
35636 } else {
35637 - ACCESS_ONCE(ads->ds_ctl2) = 0;
35638 - ACCESS_ONCE(ads->ds_ctl3) = 0;
35639 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35640 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35641 }
35642
35643 if (!i->is_first) {
35644 - ACCESS_ONCE(ads->ds_ctl0) = 0;
35645 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35646 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35647 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35648 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35649 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35650 return;
35651 }
35652
35653 @@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35654 break;
35655 }
35656
35657 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35658 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35659 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35660 | SM(i->txpower, AR_XmitPower)
35661 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35662 @@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35663 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35664 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35665
35666 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35667 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35668 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35669 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35670
35671 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35672 return;
35673
35674 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35675 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35676 | set11nPktDurRTSCTS(i->rates, 1);
35677
35678 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35679 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35680 | set11nPktDurRTSCTS(i->rates, 3);
35681
35682 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35683 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35684 | set11nRateFlags(i->rates, 1)
35685 | set11nRateFlags(i->rates, 2)
35686 | set11nRateFlags(i->rates, 3)
35687 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35688 index 78816b8..1fcdfae 100644
35689 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35690 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35691 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35692 (i->qcu << AR_TxQcuNum_S) | desc_len;
35693
35694 checksum += val;
35695 - ACCESS_ONCE(ads->info) = val;
35696 + ACCESS_ONCE_RW(ads->info) = val;
35697
35698 checksum += i->link;
35699 - ACCESS_ONCE(ads->link) = i->link;
35700 + ACCESS_ONCE_RW(ads->link) = i->link;
35701
35702 checksum += i->buf_addr[0];
35703 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35704 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35705 checksum += i->buf_addr[1];
35706 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35707 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35708 checksum += i->buf_addr[2];
35709 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35710 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35711 checksum += i->buf_addr[3];
35712 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35713 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35714
35715 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35716 - ACCESS_ONCE(ads->ctl3) = val;
35717 + ACCESS_ONCE_RW(ads->ctl3) = val;
35718 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35719 - ACCESS_ONCE(ads->ctl5) = val;
35720 + ACCESS_ONCE_RW(ads->ctl5) = val;
35721 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35722 - ACCESS_ONCE(ads->ctl7) = val;
35723 + ACCESS_ONCE_RW(ads->ctl7) = val;
35724 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35725 - ACCESS_ONCE(ads->ctl9) = val;
35726 + ACCESS_ONCE_RW(ads->ctl9) = val;
35727
35728 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35729 - ACCESS_ONCE(ads->ctl10) = checksum;
35730 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
35731
35732 if (i->is_first || i->is_last) {
35733 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35734 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
35735 | set11nTries(i->rates, 1)
35736 | set11nTries(i->rates, 2)
35737 | set11nTries(i->rates, 3)
35738 | (i->dur_update ? AR_DurUpdateEna : 0)
35739 | SM(0, AR_BurstDur);
35740
35741 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
35742 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
35743 | set11nRate(i->rates, 1)
35744 | set11nRate(i->rates, 2)
35745 | set11nRate(i->rates, 3);
35746 } else {
35747 - ACCESS_ONCE(ads->ctl13) = 0;
35748 - ACCESS_ONCE(ads->ctl14) = 0;
35749 + ACCESS_ONCE_RW(ads->ctl13) = 0;
35750 + ACCESS_ONCE_RW(ads->ctl14) = 0;
35751 }
35752
35753 ads->ctl20 = 0;
35754 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35755
35756 ctl17 = SM(i->keytype, AR_EncrType);
35757 if (!i->is_first) {
35758 - ACCESS_ONCE(ads->ctl11) = 0;
35759 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35760 - ACCESS_ONCE(ads->ctl15) = 0;
35761 - ACCESS_ONCE(ads->ctl16) = 0;
35762 - ACCESS_ONCE(ads->ctl17) = ctl17;
35763 - ACCESS_ONCE(ads->ctl18) = 0;
35764 - ACCESS_ONCE(ads->ctl19) = 0;
35765 + ACCESS_ONCE_RW(ads->ctl11) = 0;
35766 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35767 + ACCESS_ONCE_RW(ads->ctl15) = 0;
35768 + ACCESS_ONCE_RW(ads->ctl16) = 0;
35769 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35770 + ACCESS_ONCE_RW(ads->ctl18) = 0;
35771 + ACCESS_ONCE_RW(ads->ctl19) = 0;
35772 return;
35773 }
35774
35775 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35776 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35777 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35778 | SM(i->txpower, AR_XmitPower)
35779 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35780 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35781 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
35782 ctl12 |= SM(val, AR_PAPRDChainMask);
35783
35784 - ACCESS_ONCE(ads->ctl12) = ctl12;
35785 - ACCESS_ONCE(ads->ctl17) = ctl17;
35786 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
35787 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35788
35789 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35790 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35791 | set11nPktDurRTSCTS(i->rates, 1);
35792
35793 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35794 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35795 | set11nPktDurRTSCTS(i->rates, 3);
35796
35797 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
35798 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
35799 | set11nRateFlags(i->rates, 1)
35800 | set11nRateFlags(i->rates, 2)
35801 | set11nRateFlags(i->rates, 3)
35802 | SM(i->rtscts_rate, AR_RTSCTSRate);
35803
35804 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
35805 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
35806 }
35807
35808 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
35809 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
35810 index de6968f..29ac4c1 100644
35811 --- a/drivers/net/wireless/ath/ath9k/hw.h
35812 +++ b/drivers/net/wireless/ath/ath9k/hw.h
35813 @@ -656,7 +656,7 @@ struct ath_hw_private_ops {
35814
35815 /* ANI */
35816 void (*ani_cache_ini_regs)(struct ath_hw *ah);
35817 -};
35818 +} __no_const;
35819
35820 /**
35821 * struct ath_hw_ops - callbacks used by hardware code and driver code
35822 @@ -686,7 +686,7 @@ struct ath_hw_ops {
35823 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
35824 struct ath_hw_antcomb_conf *antconf);
35825
35826 -};
35827 +} __no_const;
35828
35829 struct ath_nf_limits {
35830 s16 max;
35831 @@ -706,7 +706,7 @@ enum ath_cal_list {
35832 #define AH_FASTCC 0x4
35833
35834 struct ath_hw {
35835 - struct ath_ops reg_ops;
35836 + ath_ops_no_const reg_ops;
35837
35838 struct ieee80211_hw *hw;
35839 struct ath_common common;
35840 diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35841 index af00e2c..ab04d34 100644
35842 --- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35843 +++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35844 @@ -545,7 +545,7 @@ struct phy_func_ptr {
35845 void (*carrsuppr)(struct brcms_phy *);
35846 s32 (*rxsigpwr)(struct brcms_phy *, s32);
35847 void (*detach)(struct brcms_phy *);
35848 -};
35849 +} __no_const;
35850
35851 struct brcms_phy {
35852 struct brcms_phy_pub pubpi_ro;
35853 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
35854 index faec404..a5277f1 100644
35855 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
35856 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
35857 @@ -3611,7 +3611,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
35858 */
35859 if (il3945_mod_params.disable_hw_scan) {
35860 D_INFO("Disabling hw_scan\n");
35861 - il3945_mac_ops.hw_scan = NULL;
35862 + pax_open_kernel();
35863 + *(void **)&il3945_mac_ops.hw_scan = NULL;
35864 + pax_close_kernel();
35865 }
35866
35867 D_INFO("*** LOAD DRIVER ***\n");
35868 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35869 index a47b306..297daf2 100644
35870 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35871 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35872 @@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
35873 {
35874 struct iwl_priv *priv = file->private_data;
35875 char buf[64];
35876 - int buf_size;
35877 + size_t buf_size;
35878 u32 offset, len;
35879
35880 memset(buf, 0, sizeof(buf));
35881 @@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
35882 struct iwl_priv *priv = file->private_data;
35883
35884 char buf[8];
35885 - int buf_size;
35886 + size_t buf_size;
35887 u32 reset_flag;
35888
35889 memset(buf, 0, sizeof(buf));
35890 @@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
35891 {
35892 struct iwl_priv *priv = file->private_data;
35893 char buf[8];
35894 - int buf_size;
35895 + size_t buf_size;
35896 int ht40;
35897
35898 memset(buf, 0, sizeof(buf));
35899 @@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
35900 {
35901 struct iwl_priv *priv = file->private_data;
35902 char buf[8];
35903 - int buf_size;
35904 + size_t buf_size;
35905 int value;
35906
35907 memset(buf, 0, sizeof(buf));
35908 @@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
35909 {
35910 struct iwl_priv *priv = file->private_data;
35911 char buf[8];
35912 - int buf_size;
35913 + size_t buf_size;
35914 int clear;
35915
35916 memset(buf, 0, sizeof(buf));
35917 @@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
35918 {
35919 struct iwl_priv *priv = file->private_data;
35920 char buf[8];
35921 - int buf_size;
35922 + size_t buf_size;
35923 int trace;
35924
35925 memset(buf, 0, sizeof(buf));
35926 @@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
35927 {
35928 struct iwl_priv *priv = file->private_data;
35929 char buf[8];
35930 - int buf_size;
35931 + size_t buf_size;
35932 int missed;
35933
35934 memset(buf, 0, sizeof(buf));
35935 @@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
35936
35937 struct iwl_priv *priv = file->private_data;
35938 char buf[8];
35939 - int buf_size;
35940 + size_t buf_size;
35941 int plcp;
35942
35943 memset(buf, 0, sizeof(buf));
35944 @@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
35945
35946 struct iwl_priv *priv = file->private_data;
35947 char buf[8];
35948 - int buf_size;
35949 + size_t buf_size;
35950 int flush;
35951
35952 memset(buf, 0, sizeof(buf));
35953 @@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
35954
35955 struct iwl_priv *priv = file->private_data;
35956 char buf[8];
35957 - int buf_size;
35958 + size_t buf_size;
35959 int rts;
35960
35961 if (!priv->cfg->ht_params)
35962 @@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
35963 {
35964 struct iwl_priv *priv = file->private_data;
35965 char buf[8];
35966 - int buf_size;
35967 + size_t buf_size;
35968
35969 memset(buf, 0, sizeof(buf));
35970 buf_size = min(count, sizeof(buf) - 1);
35971 @@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
35972 struct iwl_priv *priv = file->private_data;
35973 u32 event_log_flag;
35974 char buf[8];
35975 - int buf_size;
35976 + size_t buf_size;
35977
35978 /* check that the interface is up */
35979 if (!iwl_is_ready(priv))
35980 @@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
35981 struct iwl_priv *priv = file->private_data;
35982 char buf[8];
35983 u32 calib_disabled;
35984 - int buf_size;
35985 + size_t buf_size;
35986
35987 memset(buf, 0, sizeof(buf));
35988 buf_size = min(count, sizeof(buf) - 1);
35989 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
35990 index dbeebef..b45a152 100644
35991 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
35992 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
35993 @@ -1944,7 +1944,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
35994 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
35995
35996 char buf[8];
35997 - int buf_size;
35998 + size_t buf_size;
35999 u32 reset_flag;
36000
36001 memset(buf, 0, sizeof(buf));
36002 @@ -1965,7 +1965,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
36003 {
36004 struct iwl_trans *trans = file->private_data;
36005 char buf[8];
36006 - int buf_size;
36007 + size_t buf_size;
36008 int csr;
36009
36010 memset(buf, 0, sizeof(buf));
36011 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
36012 index 0083839..fcb7225 100644
36013 --- a/drivers/net/wireless/mac80211_hwsim.c
36014 +++ b/drivers/net/wireless/mac80211_hwsim.c
36015 @@ -1748,9 +1748,11 @@ static int __init init_mac80211_hwsim(void)
36016 return -EINVAL;
36017
36018 if (fake_hw_scan) {
36019 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
36020 - mac80211_hwsim_ops.sw_scan_start = NULL;
36021 - mac80211_hwsim_ops.sw_scan_complete = NULL;
36022 + pax_open_kernel();
36023 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
36024 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
36025 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
36026 + pax_close_kernel();
36027 }
36028
36029 spin_lock_init(&hwsim_radio_lock);
36030 diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
36031 index e7c2a82..582e228 100644
36032 --- a/drivers/net/wireless/mwifiex/main.h
36033 +++ b/drivers/net/wireless/mwifiex/main.h
36034 @@ -571,7 +571,7 @@ struct mwifiex_if_ops {
36035 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
36036 int (*data_complete) (struct mwifiex_adapter *, struct sk_buff *);
36037 int (*dnld_fw) (struct mwifiex_adapter *, struct mwifiex_fw_image *);
36038 -};
36039 +} __no_const;
36040
36041 struct mwifiex_adapter {
36042 u8 iface_type;
36043 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
36044 index 7a4ae9e..56e00bd 100644
36045 --- a/drivers/net/wireless/rndis_wlan.c
36046 +++ b/drivers/net/wireless/rndis_wlan.c
36047 @@ -1235,7 +1235,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
36048
36049 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
36050
36051 - if (rts_threshold < 0 || rts_threshold > 2347)
36052 + if (rts_threshold > 2347)
36053 rts_threshold = 2347;
36054
36055 tmp = cpu_to_le32(rts_threshold);
36056 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
36057 index 8afb546..0c0dc5c 100644
36058 --- a/drivers/net/wireless/rt2x00/rt2x00.h
36059 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
36060 @@ -397,7 +397,7 @@ struct rt2x00_intf {
36061 * for hardware which doesn't support hardware
36062 * sequence counting.
36063 */
36064 - atomic_t seqno;
36065 + atomic_unchecked_t seqno;
36066 };
36067
36068 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
36069 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
36070 index f7e74a0..da71431 100644
36071 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
36072 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
36073 @@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
36074 * sequence counter given by mac80211.
36075 */
36076 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
36077 - seqno = atomic_add_return(0x10, &intf->seqno);
36078 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
36079 else
36080 - seqno = atomic_read(&intf->seqno);
36081 + seqno = atomic_read_unchecked(&intf->seqno);
36082
36083 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
36084 hdr->seq_ctrl |= cpu_to_le16(seqno);
36085 diff --git a/drivers/net/wireless/ti/wl1251/wl1251.h b/drivers/net/wireless/ti/wl1251/wl1251.h
36086 index fd02060..74ee481 100644
36087 --- a/drivers/net/wireless/ti/wl1251/wl1251.h
36088 +++ b/drivers/net/wireless/ti/wl1251/wl1251.h
36089 @@ -266,7 +266,7 @@ struct wl1251_if_operations {
36090 void (*reset)(struct wl1251 *wl);
36091 void (*enable_irq)(struct wl1251 *wl);
36092 void (*disable_irq)(struct wl1251 *wl);
36093 -};
36094 +} __no_const;
36095
36096 struct wl1251 {
36097 struct ieee80211_hw *hw;
36098 diff --git a/drivers/net/wireless/ti/wlcore/wlcore.h b/drivers/net/wireless/ti/wlcore/wlcore.h
36099 index 0ce7a8e..56a0ccf 100644
36100 --- a/drivers/net/wireless/ti/wlcore/wlcore.h
36101 +++ b/drivers/net/wireless/ti/wlcore/wlcore.h
36102 @@ -81,7 +81,7 @@ struct wlcore_ops {
36103 struct ieee80211_sta *sta,
36104 struct ieee80211_key_conf *key_conf);
36105 u32 (*pre_pkt_send)(struct wl1271 *wl, u32 buf_offset, u32 last_len);
36106 -};
36107 +} __no_const;
36108
36109 enum wlcore_partitions {
36110 PART_DOWN,
36111 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
36112 index f34b5b2..b5abb9f 100644
36113 --- a/drivers/oprofile/buffer_sync.c
36114 +++ b/drivers/oprofile/buffer_sync.c
36115 @@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
36116 if (cookie == NO_COOKIE)
36117 offset = pc;
36118 if (cookie == INVALID_COOKIE) {
36119 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36120 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36121 offset = pc;
36122 }
36123 if (cookie != last_cookie) {
36124 @@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
36125 /* add userspace sample */
36126
36127 if (!mm) {
36128 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
36129 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
36130 return 0;
36131 }
36132
36133 cookie = lookup_dcookie(mm, s->eip, &offset);
36134
36135 if (cookie == INVALID_COOKIE) {
36136 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36137 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36138 return 0;
36139 }
36140
36141 @@ -563,7 +563,7 @@ void sync_buffer(int cpu)
36142 /* ignore backtraces if failed to add a sample */
36143 if (state == sb_bt_start) {
36144 state = sb_bt_ignore;
36145 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
36146 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
36147 }
36148 }
36149 release_mm(mm);
36150 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
36151 index c0cc4e7..44d4e54 100644
36152 --- a/drivers/oprofile/event_buffer.c
36153 +++ b/drivers/oprofile/event_buffer.c
36154 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
36155 }
36156
36157 if (buffer_pos == buffer_size) {
36158 - atomic_inc(&oprofile_stats.event_lost_overflow);
36159 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
36160 return;
36161 }
36162
36163 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
36164 index ed2c3ec..deda85a 100644
36165 --- a/drivers/oprofile/oprof.c
36166 +++ b/drivers/oprofile/oprof.c
36167 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
36168 if (oprofile_ops.switch_events())
36169 return;
36170
36171 - atomic_inc(&oprofile_stats.multiplex_counter);
36172 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
36173 start_switch_worker();
36174 }
36175
36176 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
36177 index 917d28e..d62d981 100644
36178 --- a/drivers/oprofile/oprofile_stats.c
36179 +++ b/drivers/oprofile/oprofile_stats.c
36180 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
36181 cpu_buf->sample_invalid_eip = 0;
36182 }
36183
36184 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
36185 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
36186 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
36187 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
36188 - atomic_set(&oprofile_stats.multiplex_counter, 0);
36189 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
36190 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
36191 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
36192 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
36193 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
36194 }
36195
36196
36197 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
36198 index 38b6fc0..b5cbfce 100644
36199 --- a/drivers/oprofile/oprofile_stats.h
36200 +++ b/drivers/oprofile/oprofile_stats.h
36201 @@ -13,11 +13,11 @@
36202 #include <linux/atomic.h>
36203
36204 struct oprofile_stat_struct {
36205 - atomic_t sample_lost_no_mm;
36206 - atomic_t sample_lost_no_mapping;
36207 - atomic_t bt_lost_no_mapping;
36208 - atomic_t event_lost_overflow;
36209 - atomic_t multiplex_counter;
36210 + atomic_unchecked_t sample_lost_no_mm;
36211 + atomic_unchecked_t sample_lost_no_mapping;
36212 + atomic_unchecked_t bt_lost_no_mapping;
36213 + atomic_unchecked_t event_lost_overflow;
36214 + atomic_unchecked_t multiplex_counter;
36215 };
36216
36217 extern struct oprofile_stat_struct oprofile_stats;
36218 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
36219 index 849357c..b83c1e0 100644
36220 --- a/drivers/oprofile/oprofilefs.c
36221 +++ b/drivers/oprofile/oprofilefs.c
36222 @@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
36223
36224
36225 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
36226 - char const *name, atomic_t *val)
36227 + char const *name, atomic_unchecked_t *val)
36228 {
36229 return __oprofilefs_create_file(sb, root, name,
36230 &atomic_ro_fops, 0444, val);
36231 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
36232 index 3f56bc0..707d642 100644
36233 --- a/drivers/parport/procfs.c
36234 +++ b/drivers/parport/procfs.c
36235 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
36236
36237 *ppos += len;
36238
36239 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
36240 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
36241 }
36242
36243 #ifdef CONFIG_PARPORT_1284
36244 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
36245
36246 *ppos += len;
36247
36248 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
36249 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
36250 }
36251 #endif /* IEEE1284.3 support. */
36252
36253 diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
36254 index 9fff878..ad0ad53 100644
36255 --- a/drivers/pci/hotplug/cpci_hotplug.h
36256 +++ b/drivers/pci/hotplug/cpci_hotplug.h
36257 @@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
36258 int (*hardware_test) (struct slot* slot, u32 value);
36259 u8 (*get_power) (struct slot* slot);
36260 int (*set_power) (struct slot* slot, int value);
36261 -};
36262 +} __no_const;
36263
36264 struct cpci_hp_controller {
36265 unsigned int irq;
36266 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
36267 index 76ba8a1..20ca857 100644
36268 --- a/drivers/pci/hotplug/cpqphp_nvram.c
36269 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
36270 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
36271
36272 void compaq_nvram_init (void __iomem *rom_start)
36273 {
36274 +
36275 +#ifndef CONFIG_PAX_KERNEXEC
36276 if (rom_start) {
36277 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
36278 }
36279 +#endif
36280 +
36281 dbg("int15 entry = %p\n", compaq_int15_entry_point);
36282
36283 /* initialize our int15 lock */
36284 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
36285 index b500840..d7159d3 100644
36286 --- a/drivers/pci/pcie/aspm.c
36287 +++ b/drivers/pci/pcie/aspm.c
36288 @@ -27,9 +27,9 @@
36289 #define MODULE_PARAM_PREFIX "pcie_aspm."
36290
36291 /* Note: those are not register definitions */
36292 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
36293 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
36294 -#define ASPM_STATE_L1 (4) /* L1 state */
36295 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
36296 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
36297 +#define ASPM_STATE_L1 (4U) /* L1 state */
36298 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
36299 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
36300
36301 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
36302 index 61859d0..124539e 100644
36303 --- a/drivers/pci/probe.c
36304 +++ b/drivers/pci/probe.c
36305 @@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
36306 struct pci_bus_region region;
36307 bool bar_too_big = false, bar_disabled = false;
36308
36309 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
36310 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
36311
36312 /* No printks while decoding is disabled! */
36313 if (!dev->mmio_always_on) {
36314 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
36315 index 27911b5..5b6db88 100644
36316 --- a/drivers/pci/proc.c
36317 +++ b/drivers/pci/proc.c
36318 @@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
36319 static int __init pci_proc_init(void)
36320 {
36321 struct pci_dev *dev = NULL;
36322 +
36323 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
36324 +#ifdef CONFIG_GRKERNSEC_PROC_USER
36325 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
36326 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
36327 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
36328 +#endif
36329 +#else
36330 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
36331 +#endif
36332 proc_create("devices", 0, proc_bus_pci_dir,
36333 &proc_bus_pci_dev_operations);
36334 proc_initialized = 1;
36335 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
36336 index 52daaa8..d6b81eb 100644
36337 --- a/drivers/platform/x86/thinkpad_acpi.c
36338 +++ b/drivers/platform/x86/thinkpad_acpi.c
36339 @@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
36340 return 0;
36341 }
36342
36343 -void static hotkey_mask_warn_incomplete_mask(void)
36344 +static void hotkey_mask_warn_incomplete_mask(void)
36345 {
36346 /* log only what the user can fix... */
36347 const u32 wantedmask = hotkey_driver_mask &
36348 @@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
36349 }
36350 }
36351
36352 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36353 - struct tp_nvram_state *newn,
36354 - const u32 event_mask)
36355 -{
36356 -
36357 #define TPACPI_COMPARE_KEY(__scancode, __member) \
36358 do { \
36359 if ((event_mask & (1 << __scancode)) && \
36360 @@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36361 tpacpi_hotkey_send_key(__scancode); \
36362 } while (0)
36363
36364 - void issue_volchange(const unsigned int oldvol,
36365 - const unsigned int newvol)
36366 - {
36367 - unsigned int i = oldvol;
36368 +static void issue_volchange(const unsigned int oldvol,
36369 + const unsigned int newvol,
36370 + const u32 event_mask)
36371 +{
36372 + unsigned int i = oldvol;
36373
36374 - while (i > newvol) {
36375 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36376 - i--;
36377 - }
36378 - while (i < newvol) {
36379 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36380 - i++;
36381 - }
36382 + while (i > newvol) {
36383 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36384 + i--;
36385 }
36386 + while (i < newvol) {
36387 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36388 + i++;
36389 + }
36390 +}
36391
36392 - void issue_brightnesschange(const unsigned int oldbrt,
36393 - const unsigned int newbrt)
36394 - {
36395 - unsigned int i = oldbrt;
36396 +static void issue_brightnesschange(const unsigned int oldbrt,
36397 + const unsigned int newbrt,
36398 + const u32 event_mask)
36399 +{
36400 + unsigned int i = oldbrt;
36401
36402 - while (i > newbrt) {
36403 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36404 - i--;
36405 - }
36406 - while (i < newbrt) {
36407 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36408 - i++;
36409 - }
36410 + while (i > newbrt) {
36411 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36412 + i--;
36413 + }
36414 + while (i < newbrt) {
36415 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36416 + i++;
36417 }
36418 +}
36419
36420 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36421 + struct tp_nvram_state *newn,
36422 + const u32 event_mask)
36423 +{
36424 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
36425 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
36426 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
36427 @@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36428 oldn->volume_level != newn->volume_level) {
36429 /* recently muted, or repeated mute keypress, or
36430 * multiple presses ending in mute */
36431 - issue_volchange(oldn->volume_level, newn->volume_level);
36432 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36433 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
36434 }
36435 } else {
36436 @@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36437 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36438 }
36439 if (oldn->volume_level != newn->volume_level) {
36440 - issue_volchange(oldn->volume_level, newn->volume_level);
36441 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36442 } else if (oldn->volume_toggle != newn->volume_toggle) {
36443 /* repeated vol up/down keypress at end of scale ? */
36444 if (newn->volume_level == 0)
36445 @@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36446 /* handle brightness */
36447 if (oldn->brightness_level != newn->brightness_level) {
36448 issue_brightnesschange(oldn->brightness_level,
36449 - newn->brightness_level);
36450 + newn->brightness_level,
36451 + event_mask);
36452 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
36453 /* repeated key presses that didn't change state */
36454 if (newn->brightness_level == 0)
36455 @@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36456 && !tp_features.bright_unkfw)
36457 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36458 }
36459 +}
36460
36461 #undef TPACPI_COMPARE_KEY
36462 #undef TPACPI_MAY_SEND_KEY
36463 -}
36464
36465 /*
36466 * Polling driver
36467 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
36468 index 769d265..a3a05ca 100644
36469 --- a/drivers/pnp/pnpbios/bioscalls.c
36470 +++ b/drivers/pnp/pnpbios/bioscalls.c
36471 @@ -58,7 +58,7 @@ do { \
36472 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
36473 } while(0)
36474
36475 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
36476 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
36477 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
36478
36479 /*
36480 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36481
36482 cpu = get_cpu();
36483 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
36484 +
36485 + pax_open_kernel();
36486 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
36487 + pax_close_kernel();
36488
36489 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
36490 spin_lock_irqsave(&pnp_bios_lock, flags);
36491 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36492 :"memory");
36493 spin_unlock_irqrestore(&pnp_bios_lock, flags);
36494
36495 + pax_open_kernel();
36496 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
36497 + pax_close_kernel();
36498 +
36499 put_cpu();
36500
36501 /* If we get here and this is set then the PnP BIOS faulted on us. */
36502 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
36503 return status;
36504 }
36505
36506 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
36507 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
36508 {
36509 int i;
36510
36511 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36512 pnp_bios_callpoint.offset = header->fields.pm16offset;
36513 pnp_bios_callpoint.segment = PNP_CS16;
36514
36515 + pax_open_kernel();
36516 +
36517 for_each_possible_cpu(i) {
36518 struct desc_struct *gdt = get_cpu_gdt_table(i);
36519 if (!gdt)
36520 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36521 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
36522 (unsigned long)__va(header->fields.pm16dseg));
36523 }
36524 +
36525 + pax_close_kernel();
36526 }
36527 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
36528 index b0ecacb..7c9da2e 100644
36529 --- a/drivers/pnp/resource.c
36530 +++ b/drivers/pnp/resource.c
36531 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
36532 return 1;
36533
36534 /* check if the resource is valid */
36535 - if (*irq < 0 || *irq > 15)
36536 + if (*irq > 15)
36537 return 0;
36538
36539 /* check if the resource is reserved */
36540 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
36541 return 1;
36542
36543 /* check if the resource is valid */
36544 - if (*dma < 0 || *dma == 4 || *dma > 7)
36545 + if (*dma == 4 || *dma > 7)
36546 return 0;
36547
36548 /* check if the resource is reserved */
36549 diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
36550 index 181ddec..774b6da 100644
36551 --- a/drivers/power/bq27x00_battery.c
36552 +++ b/drivers/power/bq27x00_battery.c
36553 @@ -80,7 +80,7 @@
36554 struct bq27x00_device_info;
36555 struct bq27x00_access_methods {
36556 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36557 -};
36558 +} __no_const;
36559
36560 enum bq27x00_chip { BQ27000, BQ27500, BQ27425};
36561
36562 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36563 index 8d53174..04c65de 100644
36564 --- a/drivers/regulator/max8660.c
36565 +++ b/drivers/regulator/max8660.c
36566 @@ -333,8 +333,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36567 max8660->shadow_regs[MAX8660_OVER1] = 5;
36568 } else {
36569 /* Otherwise devices can be toggled via software */
36570 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
36571 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
36572 + pax_open_kernel();
36573 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36574 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36575 + pax_close_kernel();
36576 }
36577
36578 /*
36579 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36580 index b388b74..ed82573 100644
36581 --- a/drivers/regulator/mc13892-regulator.c
36582 +++ b/drivers/regulator/mc13892-regulator.c
36583 @@ -565,10 +565,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36584 }
36585 mc13xxx_unlock(mc13892);
36586
36587 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36588 + pax_open_kernel();
36589 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36590 = mc13892_vcam_set_mode;
36591 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36592 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36593 = mc13892_vcam_get_mode;
36594 + pax_close_kernel();
36595
36596 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36597 ARRAY_SIZE(mc13892_regulators));
36598 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36599 index cace6d3..f623fda 100644
36600 --- a/drivers/rtc/rtc-dev.c
36601 +++ b/drivers/rtc/rtc-dev.c
36602 @@ -14,6 +14,7 @@
36603 #include <linux/module.h>
36604 #include <linux/rtc.h>
36605 #include <linux/sched.h>
36606 +#include <linux/grsecurity.h>
36607 #include "rtc-core.h"
36608
36609 static dev_t rtc_devt;
36610 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36611 if (copy_from_user(&tm, uarg, sizeof(tm)))
36612 return -EFAULT;
36613
36614 + gr_log_timechange();
36615 +
36616 return rtc_set_time(rtc, &tm);
36617
36618 case RTC_PIE_ON:
36619 diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36620 index 9e933a8..4f969f7 100644
36621 --- a/drivers/scsi/aacraid/aacraid.h
36622 +++ b/drivers/scsi/aacraid/aacraid.h
36623 @@ -503,7 +503,7 @@ struct adapter_ops
36624 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36625 /* Administrative operations */
36626 int (*adapter_comm)(struct aac_dev * dev, int comm);
36627 -};
36628 +} __no_const;
36629
36630 /*
36631 * Define which interrupt handler needs to be installed
36632 diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
36633 index 7199534..cb7f158 100644
36634 --- a/drivers/scsi/aacraid/linit.c
36635 +++ b/drivers/scsi/aacraid/linit.c
36636 @@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
36637 #elif defined(__devinitconst)
36638 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36639 #else
36640 -static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
36641 +static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36642 #endif
36643 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
36644 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
36645 diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
36646 index ff80552..1c4120c 100644
36647 --- a/drivers/scsi/aic94xx/aic94xx_init.c
36648 +++ b/drivers/scsi/aic94xx/aic94xx_init.c
36649 @@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
36650 .lldd_ata_set_dmamode = asd_set_dmamode,
36651 };
36652
36653 -static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
36654 +static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
36655 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
36656 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
36657 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
36658 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36659 index 4ad7e36..d004679 100644
36660 --- a/drivers/scsi/bfa/bfa.h
36661 +++ b/drivers/scsi/bfa/bfa.h
36662 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
36663 u32 *end);
36664 int cpe_vec_q0;
36665 int rme_vec_q0;
36666 -};
36667 +} __no_const;
36668 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36669
36670 struct bfa_faa_cbfn_s {
36671 diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36672 index f0f80e2..8ec946b 100644
36673 --- a/drivers/scsi/bfa/bfa_fcpim.c
36674 +++ b/drivers/scsi/bfa/bfa_fcpim.c
36675 @@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36676
36677 bfa_iotag_attach(fcp);
36678
36679 - fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36680 + fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36681 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36682 (fcp->num_itns * sizeof(struct bfa_itn_s));
36683 memset(fcp->itn_arr, 0,
36684 @@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36685 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36686 {
36687 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36688 - struct bfa_itn_s *itn;
36689 + bfa_itn_s_no_const *itn;
36690
36691 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36692 itn->isr = isr;
36693 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36694 index 36f26da..38a34a8 100644
36695 --- a/drivers/scsi/bfa/bfa_fcpim.h
36696 +++ b/drivers/scsi/bfa/bfa_fcpim.h
36697 @@ -37,6 +37,7 @@ struct bfa_iotag_s {
36698 struct bfa_itn_s {
36699 bfa_isr_func_t isr;
36700 };
36701 +typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36702
36703 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36704 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36705 @@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
36706 struct list_head iotag_tio_free_q; /* free IO resources */
36707 struct list_head iotag_unused_q; /* unused IO resources*/
36708 struct bfa_iotag_s *iotag_arr;
36709 - struct bfa_itn_s *itn_arr;
36710 + bfa_itn_s_no_const *itn_arr;
36711 int num_ioim_reqs;
36712 int num_fwtio_reqs;
36713 int num_itns;
36714 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36715 index 1a99d4b..e85d64b 100644
36716 --- a/drivers/scsi/bfa/bfa_ioc.h
36717 +++ b/drivers/scsi/bfa/bfa_ioc.h
36718 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36719 bfa_ioc_disable_cbfn_t disable_cbfn;
36720 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36721 bfa_ioc_reset_cbfn_t reset_cbfn;
36722 -};
36723 +} __no_const;
36724
36725 /*
36726 * IOC event notification mechanism.
36727 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36728 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36729 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36730 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36731 -};
36732 +} __no_const;
36733
36734 /*
36735 * Queue element to wait for room in request queue. FIFO order is
36736 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36737 index 593085a..47aa999 100644
36738 --- a/drivers/scsi/hosts.c
36739 +++ b/drivers/scsi/hosts.c
36740 @@ -42,7 +42,7 @@
36741 #include "scsi_logging.h"
36742
36743
36744 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
36745 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
36746
36747
36748 static void scsi_host_cls_release(struct device *dev)
36749 @@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36750 * subtract one because we increment first then return, but we need to
36751 * know what the next host number was before increment
36752 */
36753 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36754 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36755 shost->dma_channel = 0xff;
36756
36757 /* These three are default values which can be overridden */
36758 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
36759 index f9823f2..7bc3e81 100644
36760 --- a/drivers/scsi/hpsa.c
36761 +++ b/drivers/scsi/hpsa.c
36762 @@ -536,7 +536,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
36763 unsigned long flags;
36764
36765 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36766 - return h->access.command_completed(h, q);
36767 + return h->access->command_completed(h, q);
36768
36769 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
36770 a = rq->head[rq->current_entry];
36771 @@ -3355,7 +3355,7 @@ static void start_io(struct ctlr_info *h)
36772 while (!list_empty(&h->reqQ)) {
36773 c = list_entry(h->reqQ.next, struct CommandList, list);
36774 /* can't do anything if fifo is full */
36775 - if ((h->access.fifo_full(h))) {
36776 + if ((h->access->fifo_full(h))) {
36777 dev_warn(&h->pdev->dev, "fifo full\n");
36778 break;
36779 }
36780 @@ -3377,7 +3377,7 @@ static void start_io(struct ctlr_info *h)
36781
36782 /* Tell the controller execute command */
36783 spin_unlock_irqrestore(&h->lock, flags);
36784 - h->access.submit_command(h, c);
36785 + h->access->submit_command(h, c);
36786 spin_lock_irqsave(&h->lock, flags);
36787 }
36788 spin_unlock_irqrestore(&h->lock, flags);
36789 @@ -3385,17 +3385,17 @@ static void start_io(struct ctlr_info *h)
36790
36791 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
36792 {
36793 - return h->access.command_completed(h, q);
36794 + return h->access->command_completed(h, q);
36795 }
36796
36797 static inline bool interrupt_pending(struct ctlr_info *h)
36798 {
36799 - return h->access.intr_pending(h);
36800 + return h->access->intr_pending(h);
36801 }
36802
36803 static inline long interrupt_not_for_us(struct ctlr_info *h)
36804 {
36805 - return (h->access.intr_pending(h) == 0) ||
36806 + return (h->access->intr_pending(h) == 0) ||
36807 (h->interrupts_enabled == 0);
36808 }
36809
36810 @@ -4299,7 +4299,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
36811 if (prod_index < 0)
36812 return -ENODEV;
36813 h->product_name = products[prod_index].product_name;
36814 - h->access = *(products[prod_index].access);
36815 + h->access = products[prod_index].access;
36816
36817 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
36818 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
36819 @@ -4581,7 +4581,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
36820
36821 assert_spin_locked(&lockup_detector_lock);
36822 remove_ctlr_from_lockup_detector_list(h);
36823 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36824 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36825 spin_lock_irqsave(&h->lock, flags);
36826 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
36827 spin_unlock_irqrestore(&h->lock, flags);
36828 @@ -4759,7 +4759,7 @@ reinit_after_soft_reset:
36829 }
36830
36831 /* make sure the board interrupts are off */
36832 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36833 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36834
36835 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
36836 goto clean2;
36837 @@ -4793,7 +4793,7 @@ reinit_after_soft_reset:
36838 * fake ones to scoop up any residual completions.
36839 */
36840 spin_lock_irqsave(&h->lock, flags);
36841 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36842 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36843 spin_unlock_irqrestore(&h->lock, flags);
36844 free_irqs(h);
36845 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
36846 @@ -4812,9 +4812,9 @@ reinit_after_soft_reset:
36847 dev_info(&h->pdev->dev, "Board READY.\n");
36848 dev_info(&h->pdev->dev,
36849 "Waiting for stale completions to drain.\n");
36850 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36851 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36852 msleep(10000);
36853 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36854 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36855
36856 rc = controller_reset_failed(h->cfgtable);
36857 if (rc)
36858 @@ -4835,7 +4835,7 @@ reinit_after_soft_reset:
36859 }
36860
36861 /* Turn the interrupts on so we can service requests */
36862 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36863 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36864
36865 hpsa_hba_inquiry(h);
36866 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
36867 @@ -4887,7 +4887,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
36868 * To write all data in the battery backed cache to disks
36869 */
36870 hpsa_flush_cache(h);
36871 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36872 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36873 hpsa_free_irqs_and_disable_msix(h);
36874 }
36875
36876 @@ -5056,7 +5056,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
36877 return;
36878 }
36879 /* Change the access methods to the performant access methods */
36880 - h->access = SA5_performant_access;
36881 + h->access = &SA5_performant_access;
36882 h->transMethod = CFGTBL_Trans_Performant;
36883 }
36884
36885 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
36886 index 9816479..c5d4e97 100644
36887 --- a/drivers/scsi/hpsa.h
36888 +++ b/drivers/scsi/hpsa.h
36889 @@ -79,7 +79,7 @@ struct ctlr_info {
36890 unsigned int msix_vector;
36891 unsigned int msi_vector;
36892 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
36893 - struct access_method access;
36894 + struct access_method *access;
36895
36896 /* queue and queue Info */
36897 struct list_head reqQ;
36898 diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
36899 index f2df059..a3a9930 100644
36900 --- a/drivers/scsi/ips.h
36901 +++ b/drivers/scsi/ips.h
36902 @@ -1027,7 +1027,7 @@ typedef struct {
36903 int (*intr)(struct ips_ha *);
36904 void (*enableint)(struct ips_ha *);
36905 uint32_t (*statupd)(struct ips_ha *);
36906 -} ips_hw_func_t;
36907 +} __no_const ips_hw_func_t;
36908
36909 typedef struct ips_ha {
36910 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36911 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
36912 index c772d8d..35c362c 100644
36913 --- a/drivers/scsi/libfc/fc_exch.c
36914 +++ b/drivers/scsi/libfc/fc_exch.c
36915 @@ -100,12 +100,12 @@ struct fc_exch_mgr {
36916 u16 pool_max_index;
36917
36918 struct {
36919 - atomic_t no_free_exch;
36920 - atomic_t no_free_exch_xid;
36921 - atomic_t xid_not_found;
36922 - atomic_t xid_busy;
36923 - atomic_t seq_not_found;
36924 - atomic_t non_bls_resp;
36925 + atomic_unchecked_t no_free_exch;
36926 + atomic_unchecked_t no_free_exch_xid;
36927 + atomic_unchecked_t xid_not_found;
36928 + atomic_unchecked_t xid_busy;
36929 + atomic_unchecked_t seq_not_found;
36930 + atomic_unchecked_t non_bls_resp;
36931 } stats;
36932 };
36933
36934 @@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
36935 /* allocate memory for exchange */
36936 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
36937 if (!ep) {
36938 - atomic_inc(&mp->stats.no_free_exch);
36939 + atomic_inc_unchecked(&mp->stats.no_free_exch);
36940 goto out;
36941 }
36942 memset(ep, 0, sizeof(*ep));
36943 @@ -786,7 +786,7 @@ out:
36944 return ep;
36945 err:
36946 spin_unlock_bh(&pool->lock);
36947 - atomic_inc(&mp->stats.no_free_exch_xid);
36948 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
36949 mempool_free(ep, mp->ep_pool);
36950 return NULL;
36951 }
36952 @@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36953 xid = ntohs(fh->fh_ox_id); /* we originated exch */
36954 ep = fc_exch_find(mp, xid);
36955 if (!ep) {
36956 - atomic_inc(&mp->stats.xid_not_found);
36957 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36958 reject = FC_RJT_OX_ID;
36959 goto out;
36960 }
36961 @@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36962 ep = fc_exch_find(mp, xid);
36963 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
36964 if (ep) {
36965 - atomic_inc(&mp->stats.xid_busy);
36966 + atomic_inc_unchecked(&mp->stats.xid_busy);
36967 reject = FC_RJT_RX_ID;
36968 goto rel;
36969 }
36970 @@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36971 }
36972 xid = ep->xid; /* get our XID */
36973 } else if (!ep) {
36974 - atomic_inc(&mp->stats.xid_not_found);
36975 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36976 reject = FC_RJT_RX_ID; /* XID not found */
36977 goto out;
36978 }
36979 @@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36980 } else {
36981 sp = &ep->seq;
36982 if (sp->id != fh->fh_seq_id) {
36983 - atomic_inc(&mp->stats.seq_not_found);
36984 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36985 if (f_ctl & FC_FC_END_SEQ) {
36986 /*
36987 * Update sequence_id based on incoming last
36988 @@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36989
36990 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
36991 if (!ep) {
36992 - atomic_inc(&mp->stats.xid_not_found);
36993 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36994 goto out;
36995 }
36996 if (ep->esb_stat & ESB_ST_COMPLETE) {
36997 - atomic_inc(&mp->stats.xid_not_found);
36998 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36999 goto rel;
37000 }
37001 if (ep->rxid == FC_XID_UNKNOWN)
37002 ep->rxid = ntohs(fh->fh_rx_id);
37003 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
37004 - atomic_inc(&mp->stats.xid_not_found);
37005 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37006 goto rel;
37007 }
37008 if (ep->did != ntoh24(fh->fh_s_id) &&
37009 ep->did != FC_FID_FLOGI) {
37010 - atomic_inc(&mp->stats.xid_not_found);
37011 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37012 goto rel;
37013 }
37014 sof = fr_sof(fp);
37015 @@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
37016 sp->ssb_stat |= SSB_ST_RESP;
37017 sp->id = fh->fh_seq_id;
37018 } else if (sp->id != fh->fh_seq_id) {
37019 - atomic_inc(&mp->stats.seq_not_found);
37020 + atomic_inc_unchecked(&mp->stats.seq_not_found);
37021 goto rel;
37022 }
37023
37024 @@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
37025 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
37026
37027 if (!sp)
37028 - atomic_inc(&mp->stats.xid_not_found);
37029 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37030 else
37031 - atomic_inc(&mp->stats.non_bls_resp);
37032 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
37033
37034 fc_frame_free(fp);
37035 }
37036 @@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
37037
37038 list_for_each_entry(ema, &lport->ema_list, ema_list) {
37039 mp = ema->mp;
37040 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
37041 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
37042 st->fc_no_free_exch_xid +=
37043 - atomic_read(&mp->stats.no_free_exch_xid);
37044 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
37045 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
37046 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
37047 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
37048 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
37049 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
37050 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
37051 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
37052 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
37053 }
37054 }
37055 EXPORT_SYMBOL(fc_exch_update_stats);
37056 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
37057 index a59fcdc..abe55f3 100644
37058 --- a/drivers/scsi/libsas/sas_ata.c
37059 +++ b/drivers/scsi/libsas/sas_ata.c
37060 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
37061 .postreset = ata_std_postreset,
37062 .error_handler = ata_std_error_handler,
37063 .post_internal_cmd = sas_ata_post_internal,
37064 - .qc_defer = ata_std_qc_defer,
37065 + .qc_defer = ata_std_qc_defer,
37066 .qc_prep = ata_noop_qc_prep,
37067 .qc_issue = sas_ata_qc_issue,
37068 .qc_fill_rtf = sas_ata_qc_fill_rtf,
37069 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
37070 index a65c05a..a39e402 100644
37071 --- a/drivers/scsi/lpfc/lpfc.h
37072 +++ b/drivers/scsi/lpfc/lpfc.h
37073 @@ -420,7 +420,7 @@ struct lpfc_vport {
37074 struct dentry *debug_nodelist;
37075 struct dentry *vport_debugfs_root;
37076 struct lpfc_debugfs_trc *disc_trc;
37077 - atomic_t disc_trc_cnt;
37078 + atomic_unchecked_t disc_trc_cnt;
37079 #endif
37080 uint8_t stat_data_enabled;
37081 uint8_t stat_data_blocked;
37082 @@ -834,8 +834,8 @@ struct lpfc_hba {
37083 struct timer_list fabric_block_timer;
37084 unsigned long bit_flags;
37085 #define FABRIC_COMANDS_BLOCKED 0
37086 - atomic_t num_rsrc_err;
37087 - atomic_t num_cmd_success;
37088 + atomic_unchecked_t num_rsrc_err;
37089 + atomic_unchecked_t num_cmd_success;
37090 unsigned long last_rsrc_error_time;
37091 unsigned long last_ramp_down_time;
37092 unsigned long last_ramp_up_time;
37093 @@ -871,7 +871,7 @@ struct lpfc_hba {
37094
37095 struct dentry *debug_slow_ring_trc;
37096 struct lpfc_debugfs_trc *slow_ring_trc;
37097 - atomic_t slow_ring_trc_cnt;
37098 + atomic_unchecked_t slow_ring_trc_cnt;
37099 /* iDiag debugfs sub-directory */
37100 struct dentry *idiag_root;
37101 struct dentry *idiag_pci_cfg;
37102 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
37103 index 3217d63..c417981 100644
37104 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
37105 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
37106 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
37107
37108 #include <linux/debugfs.h>
37109
37110 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37111 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37112 static unsigned long lpfc_debugfs_start_time = 0L;
37113
37114 /* iDiag */
37115 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
37116 lpfc_debugfs_enable = 0;
37117
37118 len = 0;
37119 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
37120 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
37121 (lpfc_debugfs_max_disc_trc - 1);
37122 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
37123 dtp = vport->disc_trc + i;
37124 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
37125 lpfc_debugfs_enable = 0;
37126
37127 len = 0;
37128 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
37129 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
37130 (lpfc_debugfs_max_slow_ring_trc - 1);
37131 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
37132 dtp = phba->slow_ring_trc + i;
37133 @@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
37134 !vport || !vport->disc_trc)
37135 return;
37136
37137 - index = atomic_inc_return(&vport->disc_trc_cnt) &
37138 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
37139 (lpfc_debugfs_max_disc_trc - 1);
37140 dtp = vport->disc_trc + index;
37141 dtp->fmt = fmt;
37142 dtp->data1 = data1;
37143 dtp->data2 = data2;
37144 dtp->data3 = data3;
37145 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37146 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37147 dtp->jif = jiffies;
37148 #endif
37149 return;
37150 @@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
37151 !phba || !phba->slow_ring_trc)
37152 return;
37153
37154 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
37155 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
37156 (lpfc_debugfs_max_slow_ring_trc - 1);
37157 dtp = phba->slow_ring_trc + index;
37158 dtp->fmt = fmt;
37159 dtp->data1 = data1;
37160 dtp->data2 = data2;
37161 dtp->data3 = data3;
37162 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37163 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37164 dtp->jif = jiffies;
37165 #endif
37166 return;
37167 @@ -4090,7 +4090,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37168 "slow_ring buffer\n");
37169 goto debug_failed;
37170 }
37171 - atomic_set(&phba->slow_ring_trc_cnt, 0);
37172 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
37173 memset(phba->slow_ring_trc, 0,
37174 (sizeof(struct lpfc_debugfs_trc) *
37175 lpfc_debugfs_max_slow_ring_trc));
37176 @@ -4136,7 +4136,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37177 "buffer\n");
37178 goto debug_failed;
37179 }
37180 - atomic_set(&vport->disc_trc_cnt, 0);
37181 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
37182
37183 snprintf(name, sizeof(name), "discovery_trace");
37184 vport->debug_disc_trc =
37185 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
37186 index 45c1520..35ba744 100644
37187 --- a/drivers/scsi/lpfc/lpfc_init.c
37188 +++ b/drivers/scsi/lpfc/lpfc_init.c
37189 @@ -10478,8 +10478,10 @@ lpfc_init(void)
37190 "misc_register returned with status %d", error);
37191
37192 if (lpfc_enable_npiv) {
37193 - lpfc_transport_functions.vport_create = lpfc_vport_create;
37194 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37195 + pax_open_kernel();
37196 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
37197 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37198 + pax_close_kernel();
37199 }
37200 lpfc_transport_template =
37201 fc_attach_transport(&lpfc_transport_functions);
37202 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
37203 index 925975d..0f1fc07 100644
37204 --- a/drivers/scsi/lpfc/lpfc_scsi.c
37205 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
37206 @@ -311,7 +311,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
37207 uint32_t evt_posted;
37208
37209 spin_lock_irqsave(&phba->hbalock, flags);
37210 - atomic_inc(&phba->num_rsrc_err);
37211 + atomic_inc_unchecked(&phba->num_rsrc_err);
37212 phba->last_rsrc_error_time = jiffies;
37213
37214 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
37215 @@ -352,7 +352,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
37216 unsigned long flags;
37217 struct lpfc_hba *phba = vport->phba;
37218 uint32_t evt_posted;
37219 - atomic_inc(&phba->num_cmd_success);
37220 + atomic_inc_unchecked(&phba->num_cmd_success);
37221
37222 if (vport->cfg_lun_queue_depth <= queue_depth)
37223 return;
37224 @@ -396,8 +396,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37225 unsigned long num_rsrc_err, num_cmd_success;
37226 int i;
37227
37228 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
37229 - num_cmd_success = atomic_read(&phba->num_cmd_success);
37230 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
37231 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
37232
37233 /*
37234 * The error and success command counters are global per
37235 @@ -425,8 +425,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37236 }
37237 }
37238 lpfc_destroy_vport_work_array(phba, vports);
37239 - atomic_set(&phba->num_rsrc_err, 0);
37240 - atomic_set(&phba->num_cmd_success, 0);
37241 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37242 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37243 }
37244
37245 /**
37246 @@ -460,8 +460,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
37247 }
37248 }
37249 lpfc_destroy_vport_work_array(phba, vports);
37250 - atomic_set(&phba->num_rsrc_err, 0);
37251 - atomic_set(&phba->num_cmd_success, 0);
37252 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37253 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37254 }
37255
37256 /**
37257 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
37258 index ea8a0b4..812a124 100644
37259 --- a/drivers/scsi/pmcraid.c
37260 +++ b/drivers/scsi/pmcraid.c
37261 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
37262 res->scsi_dev = scsi_dev;
37263 scsi_dev->hostdata = res;
37264 res->change_detected = 0;
37265 - atomic_set(&res->read_failures, 0);
37266 - atomic_set(&res->write_failures, 0);
37267 + atomic_set_unchecked(&res->read_failures, 0);
37268 + atomic_set_unchecked(&res->write_failures, 0);
37269 rc = 0;
37270 }
37271 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
37272 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
37273
37274 /* If this was a SCSI read/write command keep count of errors */
37275 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
37276 - atomic_inc(&res->read_failures);
37277 + atomic_inc_unchecked(&res->read_failures);
37278 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
37279 - atomic_inc(&res->write_failures);
37280 + atomic_inc_unchecked(&res->write_failures);
37281
37282 if (!RES_IS_GSCSI(res->cfg_entry) &&
37283 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
37284 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
37285 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37286 * hrrq_id assigned here in queuecommand
37287 */
37288 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37289 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37290 pinstance->num_hrrq;
37291 cmd->cmd_done = pmcraid_io_done;
37292
37293 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
37294 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37295 * hrrq_id assigned here in queuecommand
37296 */
37297 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37298 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37299 pinstance->num_hrrq;
37300
37301 if (request_size) {
37302 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
37303
37304 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
37305 /* add resources only after host is added into system */
37306 - if (!atomic_read(&pinstance->expose_resources))
37307 + if (!atomic_read_unchecked(&pinstance->expose_resources))
37308 return;
37309
37310 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
37311 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
37312 init_waitqueue_head(&pinstance->reset_wait_q);
37313
37314 atomic_set(&pinstance->outstanding_cmds, 0);
37315 - atomic_set(&pinstance->last_message_id, 0);
37316 - atomic_set(&pinstance->expose_resources, 0);
37317 + atomic_set_unchecked(&pinstance->last_message_id, 0);
37318 + atomic_set_unchecked(&pinstance->expose_resources, 0);
37319
37320 INIT_LIST_HEAD(&pinstance->free_res_q);
37321 INIT_LIST_HEAD(&pinstance->used_res_q);
37322 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
37323 /* Schedule worker thread to handle CCN and take care of adding and
37324 * removing devices to OS
37325 */
37326 - atomic_set(&pinstance->expose_resources, 1);
37327 + atomic_set_unchecked(&pinstance->expose_resources, 1);
37328 schedule_work(&pinstance->worker_q);
37329 return rc;
37330
37331 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
37332 index e1d150f..6c6df44 100644
37333 --- a/drivers/scsi/pmcraid.h
37334 +++ b/drivers/scsi/pmcraid.h
37335 @@ -748,7 +748,7 @@ struct pmcraid_instance {
37336 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
37337
37338 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
37339 - atomic_t last_message_id;
37340 + atomic_unchecked_t last_message_id;
37341
37342 /* configuration table */
37343 struct pmcraid_config_table *cfg_table;
37344 @@ -777,7 +777,7 @@ struct pmcraid_instance {
37345 atomic_t outstanding_cmds;
37346
37347 /* should add/delete resources to mid-layer now ?*/
37348 - atomic_t expose_resources;
37349 + atomic_unchecked_t expose_resources;
37350
37351
37352
37353 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
37354 struct pmcraid_config_table_entry_ext cfg_entry_ext;
37355 };
37356 struct scsi_device *scsi_dev; /* Link scsi_device structure */
37357 - atomic_t read_failures; /* count of failed READ commands */
37358 - atomic_t write_failures; /* count of failed WRITE commands */
37359 + atomic_unchecked_t read_failures; /* count of failed READ commands */
37360 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
37361
37362 /* To indicate add/delete/modify during CCN */
37363 u8 change_detected;
37364 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
37365 index 5ab9530..2dd80f7 100644
37366 --- a/drivers/scsi/qla2xxx/qla_attr.c
37367 +++ b/drivers/scsi/qla2xxx/qla_attr.c
37368 @@ -1855,7 +1855,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
37369 return 0;
37370 }
37371
37372 -struct fc_function_template qla2xxx_transport_functions = {
37373 +fc_function_template_no_const qla2xxx_transport_functions = {
37374
37375 .show_host_node_name = 1,
37376 .show_host_port_name = 1,
37377 @@ -1902,7 +1902,7 @@ struct fc_function_template qla2xxx_transport_functions = {
37378 .bsg_timeout = qla24xx_bsg_timeout,
37379 };
37380
37381 -struct fc_function_template qla2xxx_transport_vport_functions = {
37382 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
37383
37384 .show_host_node_name = 1,
37385 .show_host_port_name = 1,
37386 diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
37387 index 39007f5..7fafc64 100644
37388 --- a/drivers/scsi/qla2xxx/qla_def.h
37389 +++ b/drivers/scsi/qla2xxx/qla_def.h
37390 @@ -2284,7 +2284,7 @@ struct isp_operations {
37391 int (*start_scsi) (srb_t *);
37392 int (*abort_isp) (struct scsi_qla_host *);
37393 int (*iospace_config)(struct qla_hw_data*);
37394 -};
37395 +} __no_const;
37396
37397 /* MSI-X Support *************************************************************/
37398
37399 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
37400 index 9eacd2d..d79629c 100644
37401 --- a/drivers/scsi/qla2xxx/qla_gbl.h
37402 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
37403 @@ -484,8 +484,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
37404 struct device_attribute;
37405 extern struct device_attribute *qla2x00_host_attrs[];
37406 struct fc_function_template;
37407 -extern struct fc_function_template qla2xxx_transport_functions;
37408 -extern struct fc_function_template qla2xxx_transport_vport_functions;
37409 +extern fc_function_template_no_const qla2xxx_transport_functions;
37410 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
37411 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
37412 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
37413 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
37414 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
37415 index 7fdba7f..1b4b2c2 100644
37416 --- a/drivers/scsi/qla4xxx/ql4_def.h
37417 +++ b/drivers/scsi/qla4xxx/ql4_def.h
37418 @@ -268,7 +268,7 @@ struct ddb_entry {
37419 * (4000 only) */
37420 atomic_t relogin_timer; /* Max Time to wait for
37421 * relogin to complete */
37422 - atomic_t relogin_retry_count; /* Num of times relogin has been
37423 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
37424 * retried */
37425 uint32_t default_time2wait; /* Default Min time between
37426 * relogins (+aens) */
37427 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
37428 index 9da4266..377b3b6 100644
37429 --- a/drivers/scsi/qla4xxx/ql4_os.c
37430 +++ b/drivers/scsi/qla4xxx/ql4_os.c
37431 @@ -2615,12 +2615,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
37432 */
37433 if (!iscsi_is_session_online(cls_sess)) {
37434 /* Reset retry relogin timer */
37435 - atomic_inc(&ddb_entry->relogin_retry_count);
37436 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
37437 DEBUG2(ql4_printk(KERN_INFO, ha,
37438 "%s: index[%d] relogin timed out-retrying"
37439 " relogin (%d), retry (%d)\n", __func__,
37440 ddb_entry->fw_ddb_index,
37441 - atomic_read(&ddb_entry->relogin_retry_count),
37442 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
37443 ddb_entry->default_time2wait + 4));
37444 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
37445 atomic_set(&ddb_entry->retry_relogin_timer,
37446 @@ -4635,7 +4635,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
37447
37448 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
37449 atomic_set(&ddb_entry->relogin_timer, 0);
37450 - atomic_set(&ddb_entry->relogin_retry_count, 0);
37451 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
37452 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
37453 ddb_entry->default_relogin_timeout =
37454 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
37455 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
37456 index 2936b44..546ecdb 100644
37457 --- a/drivers/scsi/scsi.c
37458 +++ b/drivers/scsi/scsi.c
37459 @@ -660,7 +660,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
37460 unsigned long timeout;
37461 int rtn = 0;
37462
37463 - atomic_inc(&cmd->device->iorequest_cnt);
37464 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37465
37466 /* check if the device is still usable */
37467 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
37468 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
37469 index faa790f..7e351ddd 100644
37470 --- a/drivers/scsi/scsi_lib.c
37471 +++ b/drivers/scsi/scsi_lib.c
37472 @@ -1442,7 +1442,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
37473 shost = sdev->host;
37474 scsi_init_cmd_errh(cmd);
37475 cmd->result = DID_NO_CONNECT << 16;
37476 - atomic_inc(&cmd->device->iorequest_cnt);
37477 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37478
37479 /*
37480 * SCSI request completion path will do scsi_device_unbusy(),
37481 @@ -1468,9 +1468,9 @@ static void scsi_softirq_done(struct request *rq)
37482
37483 INIT_LIST_HEAD(&cmd->eh_entry);
37484
37485 - atomic_inc(&cmd->device->iodone_cnt);
37486 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
37487 if (cmd->result)
37488 - atomic_inc(&cmd->device->ioerr_cnt);
37489 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
37490
37491 disposition = scsi_decide_disposition(cmd);
37492 if (disposition != SUCCESS &&
37493 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
37494 index ce5224c..8c6d071 100644
37495 --- a/drivers/scsi/scsi_sysfs.c
37496 +++ b/drivers/scsi/scsi_sysfs.c
37497 @@ -661,7 +661,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
37498 char *buf) \
37499 { \
37500 struct scsi_device *sdev = to_scsi_device(dev); \
37501 - unsigned long long count = atomic_read(&sdev->field); \
37502 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
37503 return snprintf(buf, 20, "0x%llx\n", count); \
37504 } \
37505 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
37506 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
37507 index 84a1fdf..693b0d6 100644
37508 --- a/drivers/scsi/scsi_tgt_lib.c
37509 +++ b/drivers/scsi/scsi_tgt_lib.c
37510 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
37511 int err;
37512
37513 dprintk("%lx %u\n", uaddr, len);
37514 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
37515 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
37516 if (err) {
37517 /*
37518 * TODO: need to fixup sg_tablesize, max_segment_size,
37519 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
37520 index e894ca7..de9d7660 100644
37521 --- a/drivers/scsi/scsi_transport_fc.c
37522 +++ b/drivers/scsi/scsi_transport_fc.c
37523 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
37524 * Netlink Infrastructure
37525 */
37526
37527 -static atomic_t fc_event_seq;
37528 +static atomic_unchecked_t fc_event_seq;
37529
37530 /**
37531 * fc_get_event_number - Obtain the next sequential FC event number
37532 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
37533 u32
37534 fc_get_event_number(void)
37535 {
37536 - return atomic_add_return(1, &fc_event_seq);
37537 + return atomic_add_return_unchecked(1, &fc_event_seq);
37538 }
37539 EXPORT_SYMBOL(fc_get_event_number);
37540
37541 @@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
37542 {
37543 int error;
37544
37545 - atomic_set(&fc_event_seq, 0);
37546 + atomic_set_unchecked(&fc_event_seq, 0);
37547
37548 error = transport_class_register(&fc_host_class);
37549 if (error)
37550 @@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
37551 char *cp;
37552
37553 *val = simple_strtoul(buf, &cp, 0);
37554 - if ((*cp && (*cp != '\n')) || (*val < 0))
37555 + if (*cp && (*cp != '\n'))
37556 return -EINVAL;
37557 /*
37558 * Check for overflow; dev_loss_tmo is u32
37559 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
37560 index fa1dfaa..4bb620c 100644
37561 --- a/drivers/scsi/scsi_transport_iscsi.c
37562 +++ b/drivers/scsi/scsi_transport_iscsi.c
37563 @@ -79,7 +79,7 @@ struct iscsi_internal {
37564 struct transport_container session_cont;
37565 };
37566
37567 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37568 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37569 static struct workqueue_struct *iscsi_eh_timer_workq;
37570
37571 static DEFINE_IDA(iscsi_sess_ida);
37572 @@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
37573 int err;
37574
37575 ihost = shost->shost_data;
37576 - session->sid = atomic_add_return(1, &iscsi_session_nr);
37577 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37578
37579 if (target_id == ISCSI_MAX_TARGET) {
37580 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37581 @@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
37582 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37583 ISCSI_TRANSPORT_VERSION);
37584
37585 - atomic_set(&iscsi_session_nr, 0);
37586 + atomic_set_unchecked(&iscsi_session_nr, 0);
37587
37588 err = class_register(&iscsi_transport_class);
37589 if (err)
37590 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37591 index 21a045e..ec89e03 100644
37592 --- a/drivers/scsi/scsi_transport_srp.c
37593 +++ b/drivers/scsi/scsi_transport_srp.c
37594 @@ -33,7 +33,7 @@
37595 #include "scsi_transport_srp_internal.h"
37596
37597 struct srp_host_attrs {
37598 - atomic_t next_port_id;
37599 + atomic_unchecked_t next_port_id;
37600 };
37601 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37602
37603 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37604 struct Scsi_Host *shost = dev_to_shost(dev);
37605 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37606
37607 - atomic_set(&srp_host->next_port_id, 0);
37608 + atomic_set_unchecked(&srp_host->next_port_id, 0);
37609 return 0;
37610 }
37611
37612 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37613 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37614 rport->roles = ids->roles;
37615
37616 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37617 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37618 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37619
37620 transport_setup_device(&rport->dev);
37621 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
37622 index 4df73e5..b691c58 100644
37623 --- a/drivers/scsi/sd.c
37624 +++ b/drivers/scsi/sd.c
37625 @@ -2709,7 +2709,7 @@ static int sd_probe(struct device *dev)
37626 sdkp->disk = gd;
37627 sdkp->index = index;
37628 atomic_set(&sdkp->openers, 0);
37629 - atomic_set(&sdkp->device->ioerr_cnt, 0);
37630 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
37631
37632 if (!sdp->request_queue->rq_timeout) {
37633 if (sdp->type != TYPE_MOD)
37634 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37635 index 9c5c5f2..8414557 100644
37636 --- a/drivers/scsi/sg.c
37637 +++ b/drivers/scsi/sg.c
37638 @@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37639 sdp->disk->disk_name,
37640 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37641 NULL,
37642 - (char *)arg);
37643 + (char __user *)arg);
37644 case BLKTRACESTART:
37645 return blk_trace_startstop(sdp->device->request_queue, 1);
37646 case BLKTRACESTOP:
37647 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37648 index 84c2861..ece0a31 100644
37649 --- a/drivers/spi/spi.c
37650 +++ b/drivers/spi/spi.c
37651 @@ -1453,7 +1453,7 @@ int spi_bus_unlock(struct spi_master *master)
37652 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37653
37654 /* portable code must never pass more than 32 bytes */
37655 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37656 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37657
37658 static u8 *buf;
37659
37660 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37661 index 34afc16..ffe44dd 100644
37662 --- a/drivers/staging/octeon/ethernet-rx.c
37663 +++ b/drivers/staging/octeon/ethernet-rx.c
37664 @@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37665 /* Increment RX stats for virtual ports */
37666 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37667 #ifdef CONFIG_64BIT
37668 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37669 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37670 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37671 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37672 #else
37673 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37674 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37675 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37676 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37677 #endif
37678 }
37679 netif_receive_skb(skb);
37680 @@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37681 dev->name);
37682 */
37683 #ifdef CONFIG_64BIT
37684 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37685 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37686 #else
37687 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37688 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37689 #endif
37690 dev_kfree_skb_irq(skb);
37691 }
37692 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37693 index 683bedc..86dba9a 100644
37694 --- a/drivers/staging/octeon/ethernet.c
37695 +++ b/drivers/staging/octeon/ethernet.c
37696 @@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37697 * since the RX tasklet also increments it.
37698 */
37699 #ifdef CONFIG_64BIT
37700 - atomic64_add(rx_status.dropped_packets,
37701 - (atomic64_t *)&priv->stats.rx_dropped);
37702 + atomic64_add_unchecked(rx_status.dropped_packets,
37703 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37704 #else
37705 - atomic_add(rx_status.dropped_packets,
37706 - (atomic_t *)&priv->stats.rx_dropped);
37707 + atomic_add_unchecked(rx_status.dropped_packets,
37708 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
37709 #endif
37710 }
37711
37712 diff --git a/drivers/staging/omapdrm/omap_drv.c b/drivers/staging/omapdrm/omap_drv.c
37713 index 4beab94..44149ee 100644
37714 --- a/drivers/staging/omapdrm/omap_drv.c
37715 +++ b/drivers/staging/omapdrm/omap_drv.c
37716 @@ -761,7 +761,6 @@ static struct drm_driver omap_drm_driver = {
37717 .irq_postinstall = dev_irq_postinstall,
37718 .irq_uninstall = dev_irq_uninstall,
37719 .irq_handler = dev_irq_handler,
37720 - .reclaim_buffers = drm_core_reclaim_buffers,
37721 #ifdef CONFIG_DEBUG_FS
37722 .debugfs_init = omap_debugfs_init,
37723 .debugfs_cleanup = omap_debugfs_cleanup,
37724 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37725 index dc23395..cf7e9b1 100644
37726 --- a/drivers/staging/rtl8712/rtl871x_io.h
37727 +++ b/drivers/staging/rtl8712/rtl871x_io.h
37728 @@ -108,7 +108,7 @@ struct _io_ops {
37729 u8 *pmem);
37730 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37731 u8 *pmem);
37732 -};
37733 +} __no_const;
37734
37735 struct io_req {
37736 struct list_head list;
37737 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37738 index c7b5e8b..783d6cb 100644
37739 --- a/drivers/staging/sbe-2t3e3/netdev.c
37740 +++ b/drivers/staging/sbe-2t3e3/netdev.c
37741 @@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37742 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37743
37744 if (rlen)
37745 - if (copy_to_user(data, &resp, rlen))
37746 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37747 return -EFAULT;
37748
37749 return 0;
37750 diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37751 index 5d89c0f..9261317 100644
37752 --- a/drivers/staging/usbip/usbip_common.h
37753 +++ b/drivers/staging/usbip/usbip_common.h
37754 @@ -289,7 +289,7 @@ struct usbip_device {
37755 void (*shutdown)(struct usbip_device *);
37756 void (*reset)(struct usbip_device *);
37757 void (*unusable)(struct usbip_device *);
37758 - } eh_ops;
37759 + } __no_const eh_ops;
37760 };
37761
37762 #define kthread_get_run(threadfn, data, namefmt, ...) \
37763 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
37764 index c66b8b3..a4a035b 100644
37765 --- a/drivers/staging/usbip/vhci.h
37766 +++ b/drivers/staging/usbip/vhci.h
37767 @@ -83,7 +83,7 @@ struct vhci_hcd {
37768 unsigned resuming:1;
37769 unsigned long re_timeout;
37770
37771 - atomic_t seqnum;
37772 + atomic_unchecked_t seqnum;
37773
37774 /*
37775 * NOTE:
37776 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
37777 index 12a9a5f..afd8295 100644
37778 --- a/drivers/staging/usbip/vhci_hcd.c
37779 +++ b/drivers/staging/usbip/vhci_hcd.c
37780 @@ -471,7 +471,7 @@ static void vhci_tx_urb(struct urb *urb)
37781 return;
37782 }
37783
37784 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37785 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37786 if (priv->seqnum == 0xffff)
37787 dev_info(&urb->dev->dev, "seqnum max\n");
37788
37789 @@ -723,7 +723,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
37790 return -ENOMEM;
37791 }
37792
37793 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37794 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37795 if (unlink->seqnum == 0xffff)
37796 pr_info("seqnum max\n");
37797
37798 @@ -911,7 +911,7 @@ static int vhci_start(struct usb_hcd *hcd)
37799 vdev->rhport = rhport;
37800 }
37801
37802 - atomic_set(&vhci->seqnum, 0);
37803 + atomic_set_unchecked(&vhci->seqnum, 0);
37804 spin_lock_init(&vhci->lock);
37805
37806 hcd->power_budget = 0; /* no limit */
37807 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
37808 index f0eaf04..5a82e06 100644
37809 --- a/drivers/staging/usbip/vhci_rx.c
37810 +++ b/drivers/staging/usbip/vhci_rx.c
37811 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
37812 if (!urb) {
37813 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
37814 pr_info("max seqnum %d\n",
37815 - atomic_read(&the_controller->seqnum));
37816 + atomic_read_unchecked(&the_controller->seqnum));
37817 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
37818 return;
37819 }
37820 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
37821 index 6ac6f45..1b208ba 100644
37822 --- a/drivers/staging/vt6655/hostap.c
37823 +++ b/drivers/staging/vt6655/hostap.c
37824 @@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
37825 *
37826 */
37827
37828 +static net_device_ops_no_const apdev_netdev_ops;
37829 +
37830 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37831 {
37832 PSDevice apdev_priv;
37833 struct net_device *dev = pDevice->dev;
37834 int ret;
37835 - const struct net_device_ops apdev_netdev_ops = {
37836 - .ndo_start_xmit = pDevice->tx_80211,
37837 - };
37838
37839 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37840
37841 @@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37842 *apdev_priv = *pDevice;
37843 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37844
37845 + /* only half broken now */
37846 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37847 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37848
37849 pDevice->apdev->type = ARPHRD_IEEE80211;
37850 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
37851 index 682002a..35ed5cf 100644
37852 --- a/drivers/staging/vt6656/hostap.c
37853 +++ b/drivers/staging/vt6656/hostap.c
37854 @@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
37855 *
37856 */
37857
37858 +static net_device_ops_no_const apdev_netdev_ops;
37859 +
37860 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37861 {
37862 PSDevice apdev_priv;
37863 struct net_device *dev = pDevice->dev;
37864 int ret;
37865 - const struct net_device_ops apdev_netdev_ops = {
37866 - .ndo_start_xmit = pDevice->tx_80211,
37867 - };
37868
37869 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37870
37871 @@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37872 *apdev_priv = *pDevice;
37873 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37874
37875 + /* only half broken now */
37876 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37877 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37878
37879 pDevice->apdev->type = ARPHRD_IEEE80211;
37880 diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
37881 index 7843dfd..3db105f 100644
37882 --- a/drivers/staging/wlan-ng/hfa384x_usb.c
37883 +++ b/drivers/staging/wlan-ng/hfa384x_usb.c
37884 @@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
37885
37886 struct usbctlx_completor {
37887 int (*complete) (struct usbctlx_completor *);
37888 -};
37889 +} __no_const;
37890
37891 static int
37892 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
37893 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
37894 index eaa9021..43f023b 100644
37895 --- a/drivers/staging/zcache/tmem.c
37896 +++ b/drivers/staging/zcache/tmem.c
37897 @@ -39,7 +39,7 @@
37898 * A tmem host implementation must use this function to register callbacks
37899 * for memory allocation.
37900 */
37901 -static struct tmem_hostops tmem_hostops;
37902 +static tmem_hostops_no_const tmem_hostops;
37903
37904 static void tmem_objnode_tree_init(void);
37905
37906 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
37907 * A tmem host implementation must use this function to register
37908 * callbacks for a page-accessible memory (PAM) implementation
37909 */
37910 -static struct tmem_pamops tmem_pamops;
37911 +static tmem_pamops_no_const tmem_pamops;
37912
37913 void tmem_register_pamops(struct tmem_pamops *m)
37914 {
37915 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
37916 index 0d4aa82..f7832d4 100644
37917 --- a/drivers/staging/zcache/tmem.h
37918 +++ b/drivers/staging/zcache/tmem.h
37919 @@ -180,6 +180,7 @@ struct tmem_pamops {
37920 void (*new_obj)(struct tmem_obj *);
37921 int (*replace_in_obj)(void *, struct tmem_obj *);
37922 };
37923 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
37924 extern void tmem_register_pamops(struct tmem_pamops *m);
37925
37926 /* memory allocation methods provided by the host implementation */
37927 @@ -189,6 +190,7 @@ struct tmem_hostops {
37928 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
37929 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
37930 };
37931 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
37932 extern void tmem_register_hostops(struct tmem_hostops *m);
37933
37934 /* core tmem accessor functions */
37935 diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
37936 index 9fc9a60..68d4c10 100644
37937 --- a/drivers/target/target_core_device.c
37938 +++ b/drivers/target/target_core_device.c
37939 @@ -850,20 +850,20 @@ int se_dev_check_shutdown(struct se_device *dev)
37940
37941 static u32 se_dev_align_max_sectors(u32 max_sectors, u32 block_size)
37942 {
37943 - u32 tmp, aligned_max_sectors;
37944 + u32 aligned_max_sectors;
37945 + u32 alignment;
37946 /*
37947 * Limit max_sectors to a PAGE_SIZE aligned value for modern
37948 * transport_allocate_data_tasks() operation.
37949 */
37950 - tmp = rounddown((max_sectors * block_size), PAGE_SIZE);
37951 - aligned_max_sectors = (tmp / block_size);
37952 - if (max_sectors != aligned_max_sectors) {
37953 - printk(KERN_INFO "Rounding down aligned max_sectors from %u"
37954 - " to %u\n", max_sectors, aligned_max_sectors);
37955 - return aligned_max_sectors;
37956 - }
37957 + alignment = max(1ul, PAGE_SIZE / block_size);
37958 + aligned_max_sectors = rounddown(max_sectors, alignment);
37959
37960 - return max_sectors;
37961 + if (max_sectors != aligned_max_sectors)
37962 + pr_info("Rounding down aligned max_sectors from %u to %u\n",
37963 + max_sectors, aligned_max_sectors);
37964 +
37965 + return aligned_max_sectors;
37966 }
37967
37968 void se_dev_set_default_attribs(
37969 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
37970 index 7502660..f214d9f 100644
37971 --- a/drivers/target/target_core_transport.c
37972 +++ b/drivers/target/target_core_transport.c
37973 @@ -1098,7 +1098,7 @@ struct se_device *transport_add_device_to_core_hba(
37974 spin_lock_init(&dev->se_port_lock);
37975 spin_lock_init(&dev->se_tmr_lock);
37976 spin_lock_init(&dev->qf_cmd_lock);
37977 - atomic_set(&dev->dev_ordered_id, 0);
37978 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
37979
37980 se_dev_set_default_attribs(dev, dev_limits);
37981
37982 @@ -1288,7 +1288,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
37983 * Used to determine when ORDERED commands should go from
37984 * Dormant to Active status.
37985 */
37986 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
37987 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
37988 smp_mb__after_atomic_inc();
37989 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
37990 cmd->se_ordered_id, cmd->sam_task_attr,
37991 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
37992 index e61cabd..7617d26 100644
37993 --- a/drivers/tty/cyclades.c
37994 +++ b/drivers/tty/cyclades.c
37995 @@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
37996 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
37997 info->port.count);
37998 #endif
37999 - info->port.count++;
38000 + atomic_inc(&info->port.count);
38001 #ifdef CY_DEBUG_COUNT
38002 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
38003 - current->pid, info->port.count);
38004 + current->pid, atomic_read(&info->port.count));
38005 #endif
38006
38007 /*
38008 @@ -3987,7 +3987,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
38009 for (j = 0; j < cy_card[i].nports; j++) {
38010 info = &cy_card[i].ports[j];
38011
38012 - if (info->port.count) {
38013 + if (atomic_read(&info->port.count)) {
38014 /* XXX is the ldisc num worth this? */
38015 struct tty_struct *tty;
38016 struct tty_ldisc *ld;
38017 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
38018 index 2d691eb..be02ebd 100644
38019 --- a/drivers/tty/hvc/hvc_console.c
38020 +++ b/drivers/tty/hvc/hvc_console.c
38021 @@ -315,7 +315,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
38022
38023 spin_lock_irqsave(&hp->port.lock, flags);
38024 /* Check and then increment for fast path open. */
38025 - if (hp->port.count++ > 0) {
38026 + if (atomic_inc_return(&hp->port.count) > 1) {
38027 spin_unlock_irqrestore(&hp->port.lock, flags);
38028 hvc_kick();
38029 return 0;
38030 @@ -366,7 +366,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
38031
38032 spin_lock_irqsave(&hp->port.lock, flags);
38033
38034 - if (--hp->port.count == 0) {
38035 + if (atomic_dec_return(&hp->port.count) == 0) {
38036 spin_unlock_irqrestore(&hp->port.lock, flags);
38037 /* We are done with the tty pointer now. */
38038 tty_port_tty_set(&hp->port, NULL);
38039 @@ -384,9 +384,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
38040 */
38041 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
38042 } else {
38043 - if (hp->port.count < 0)
38044 + if (atomic_read(&hp->port.count) < 0)
38045 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
38046 - hp->vtermno, hp->port.count);
38047 + hp->vtermno, atomic_read(&hp->port.count));
38048 spin_unlock_irqrestore(&hp->port.lock, flags);
38049 }
38050
38051 @@ -412,13 +412,13 @@ static void hvc_hangup(struct tty_struct *tty)
38052 * open->hangup case this can be called after the final close so prevent
38053 * that from happening for now.
38054 */
38055 - if (hp->port.count <= 0) {
38056 + if (atomic_read(&hp->port.count) <= 0) {
38057 spin_unlock_irqrestore(&hp->port.lock, flags);
38058 return;
38059 }
38060
38061 - temp_open_count = hp->port.count;
38062 - hp->port.count = 0;
38063 + temp_open_count = atomic_read(&hp->port.count);
38064 + atomic_set(&hp->port.count, 0);
38065 spin_unlock_irqrestore(&hp->port.lock, flags);
38066 tty_port_tty_set(&hp->port, NULL);
38067
38068 @@ -471,7 +471,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
38069 return -EPIPE;
38070
38071 /* FIXME what's this (unprotected) check for? */
38072 - if (hp->port.count <= 0)
38073 + if (atomic_read(&hp->port.count) <= 0)
38074 return -EIO;
38075
38076 spin_lock_irqsave(&hp->lock, flags);
38077 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
38078 index d56788c..12d8f85 100644
38079 --- a/drivers/tty/hvc/hvcs.c
38080 +++ b/drivers/tty/hvc/hvcs.c
38081 @@ -83,6 +83,7 @@
38082 #include <asm/hvcserver.h>
38083 #include <asm/uaccess.h>
38084 #include <asm/vio.h>
38085 +#include <asm/local.h>
38086
38087 /*
38088 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
38089 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
38090
38091 spin_lock_irqsave(&hvcsd->lock, flags);
38092
38093 - if (hvcsd->port.count > 0) {
38094 + if (atomic_read(&hvcsd->port.count) > 0) {
38095 spin_unlock_irqrestore(&hvcsd->lock, flags);
38096 printk(KERN_INFO "HVCS: vterm state unchanged. "
38097 "The hvcs device node is still in use.\n");
38098 @@ -1134,7 +1135,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
38099 if ((retval = hvcs_partner_connect(hvcsd)))
38100 goto error_release;
38101
38102 - hvcsd->port.count = 1;
38103 + atomic_set(&hvcsd->port.count, 1);
38104 hvcsd->port.tty = tty;
38105 tty->driver_data = hvcsd;
38106
38107 @@ -1168,7 +1169,7 @@ fast_open:
38108
38109 spin_lock_irqsave(&hvcsd->lock, flags);
38110 tty_port_get(&hvcsd->port);
38111 - hvcsd->port.count++;
38112 + atomic_inc(&hvcsd->port.count);
38113 hvcsd->todo_mask |= HVCS_SCHED_READ;
38114 spin_unlock_irqrestore(&hvcsd->lock, flags);
38115
38116 @@ -1212,7 +1213,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
38117 hvcsd = tty->driver_data;
38118
38119 spin_lock_irqsave(&hvcsd->lock, flags);
38120 - if (--hvcsd->port.count == 0) {
38121 + if (atomic_dec_and_test(&hvcsd->port.count)) {
38122
38123 vio_disable_interrupts(hvcsd->vdev);
38124
38125 @@ -1238,10 +1239,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
38126 free_irq(irq, hvcsd);
38127 tty_port_put(&hvcsd->port);
38128 return;
38129 - } else if (hvcsd->port.count < 0) {
38130 + } else if (atomic_read(&hvcsd->port.count) < 0) {
38131 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
38132 " is missmanaged.\n",
38133 - hvcsd->vdev->unit_address, hvcsd->port.count);
38134 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
38135 }
38136
38137 spin_unlock_irqrestore(&hvcsd->lock, flags);
38138 @@ -1257,7 +1258,7 @@ static void hvcs_hangup(struct tty_struct * tty)
38139
38140 spin_lock_irqsave(&hvcsd->lock, flags);
38141 /* Preserve this so that we know how many kref refs to put */
38142 - temp_open_count = hvcsd->port.count;
38143 + temp_open_count = atomic_read(&hvcsd->port.count);
38144
38145 /*
38146 * Don't kref put inside the spinlock because the destruction
38147 @@ -1272,7 +1273,7 @@ static void hvcs_hangup(struct tty_struct * tty)
38148 tty->driver_data = NULL;
38149 hvcsd->port.tty = NULL;
38150
38151 - hvcsd->port.count = 0;
38152 + atomic_set(&hvcsd->port.count, 0);
38153
38154 /* This will drop any buffered data on the floor which is OK in a hangup
38155 * scenario. */
38156 @@ -1343,7 +1344,7 @@ static int hvcs_write(struct tty_struct *tty,
38157 * the middle of a write operation? This is a crummy place to do this
38158 * but we want to keep it all in the spinlock.
38159 */
38160 - if (hvcsd->port.count <= 0) {
38161 + if (atomic_read(&hvcsd->port.count) <= 0) {
38162 spin_unlock_irqrestore(&hvcsd->lock, flags);
38163 return -ENODEV;
38164 }
38165 @@ -1417,7 +1418,7 @@ static int hvcs_write_room(struct tty_struct *tty)
38166 {
38167 struct hvcs_struct *hvcsd = tty->driver_data;
38168
38169 - if (!hvcsd || hvcsd->port.count <= 0)
38170 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
38171 return 0;
38172
38173 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
38174 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
38175 index f8b5fa0..4ba9f89 100644
38176 --- a/drivers/tty/ipwireless/tty.c
38177 +++ b/drivers/tty/ipwireless/tty.c
38178 @@ -29,6 +29,7 @@
38179 #include <linux/tty_driver.h>
38180 #include <linux/tty_flip.h>
38181 #include <linux/uaccess.h>
38182 +#include <asm/local.h>
38183
38184 #include "tty.h"
38185 #include "network.h"
38186 @@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38187 mutex_unlock(&tty->ipw_tty_mutex);
38188 return -ENODEV;
38189 }
38190 - if (tty->port.count == 0)
38191 + if (atomic_read(&tty->port.count) == 0)
38192 tty->tx_bytes_queued = 0;
38193
38194 - tty->port.count++;
38195 + atomic_inc(&tty->port.count);
38196
38197 tty->port.tty = linux_tty;
38198 linux_tty->driver_data = tty;
38199 @@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38200
38201 static void do_ipw_close(struct ipw_tty *tty)
38202 {
38203 - tty->port.count--;
38204 -
38205 - if (tty->port.count == 0) {
38206 + if (atomic_dec_return(&tty->port.count) == 0) {
38207 struct tty_struct *linux_tty = tty->port.tty;
38208
38209 if (linux_tty != NULL) {
38210 @@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
38211 return;
38212
38213 mutex_lock(&tty->ipw_tty_mutex);
38214 - if (tty->port.count == 0) {
38215 + if (atomic_read(&tty->port.count) == 0) {
38216 mutex_unlock(&tty->ipw_tty_mutex);
38217 return;
38218 }
38219 @@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
38220 return;
38221 }
38222
38223 - if (!tty->port.count) {
38224 + if (!atomic_read(&tty->port.count)) {
38225 mutex_unlock(&tty->ipw_tty_mutex);
38226 return;
38227 }
38228 @@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
38229 return -ENODEV;
38230
38231 mutex_lock(&tty->ipw_tty_mutex);
38232 - if (!tty->port.count) {
38233 + if (!atomic_read(&tty->port.count)) {
38234 mutex_unlock(&tty->ipw_tty_mutex);
38235 return -EINVAL;
38236 }
38237 @@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
38238 if (!tty)
38239 return -ENODEV;
38240
38241 - if (!tty->port.count)
38242 + if (!atomic_read(&tty->port.count))
38243 return -EINVAL;
38244
38245 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
38246 @@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
38247 if (!tty)
38248 return 0;
38249
38250 - if (!tty->port.count)
38251 + if (!atomic_read(&tty->port.count))
38252 return 0;
38253
38254 return tty->tx_bytes_queued;
38255 @@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
38256 if (!tty)
38257 return -ENODEV;
38258
38259 - if (!tty->port.count)
38260 + if (!atomic_read(&tty->port.count))
38261 return -EINVAL;
38262
38263 return get_control_lines(tty);
38264 @@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
38265 if (!tty)
38266 return -ENODEV;
38267
38268 - if (!tty->port.count)
38269 + if (!atomic_read(&tty->port.count))
38270 return -EINVAL;
38271
38272 return set_control_lines(tty, set, clear);
38273 @@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
38274 if (!tty)
38275 return -ENODEV;
38276
38277 - if (!tty->port.count)
38278 + if (!atomic_read(&tty->port.count))
38279 return -EINVAL;
38280
38281 /* FIXME: Exactly how is the tty object locked here .. */
38282 @@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
38283 * are gone */
38284 mutex_lock(&ttyj->ipw_tty_mutex);
38285 }
38286 - while (ttyj->port.count)
38287 + while (atomic_read(&ttyj->port.count))
38288 do_ipw_close(ttyj);
38289 ipwireless_disassociate_network_ttys(network,
38290 ttyj->channel_idx);
38291 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
38292 index 324467d..504cc25 100644
38293 --- a/drivers/tty/moxa.c
38294 +++ b/drivers/tty/moxa.c
38295 @@ -1172,7 +1172,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
38296 }
38297
38298 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
38299 - ch->port.count++;
38300 + atomic_inc(&ch->port.count);
38301 tty->driver_data = ch;
38302 tty_port_tty_set(&ch->port, tty);
38303 mutex_lock(&ch->port.mutex);
38304 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
38305 index 90dff82..08119c3 100644
38306 --- a/drivers/tty/n_gsm.c
38307 +++ b/drivers/tty/n_gsm.c
38308 @@ -1639,7 +1639,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
38309 kref_init(&dlci->ref);
38310 mutex_init(&dlci->mutex);
38311 dlci->fifo = &dlci->_fifo;
38312 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
38313 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
38314 kfree(dlci);
38315 return NULL;
38316 }
38317 @@ -2909,7 +2909,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
38318 if (dlci == NULL)
38319 return -ENOMEM;
38320 port = &dlci->port;
38321 - port->count++;
38322 + atomic_inc(&port->count);
38323 tty->driver_data = dlci;
38324 dlci_get(dlci);
38325 dlci_get(dlci->gsm->dlci[0]);
38326 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
38327 index 26f0d0e..b7c4273 100644
38328 --- a/drivers/tty/n_tty.c
38329 +++ b/drivers/tty/n_tty.c
38330 @@ -2124,6 +2124,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
38331 {
38332 *ops = tty_ldisc_N_TTY;
38333 ops->owner = NULL;
38334 - ops->refcount = ops->flags = 0;
38335 + atomic_set(&ops->refcount, 0);
38336 + ops->flags = 0;
38337 }
38338 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
38339 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
38340 index 5505ffc..7affff9 100644
38341 --- a/drivers/tty/pty.c
38342 +++ b/drivers/tty/pty.c
38343 @@ -718,8 +718,10 @@ static void __init unix98_pty_init(void)
38344 panic("Couldn't register Unix98 pts driver");
38345
38346 /* Now create the /dev/ptmx special device */
38347 + pax_open_kernel();
38348 tty_default_fops(&ptmx_fops);
38349 - ptmx_fops.open = ptmx_open;
38350 + *(void **)&ptmx_fops.open = ptmx_open;
38351 + pax_close_kernel();
38352
38353 cdev_init(&ptmx_cdev, &ptmx_fops);
38354 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
38355 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
38356 index 777d5f9..56d67ca 100644
38357 --- a/drivers/tty/rocket.c
38358 +++ b/drivers/tty/rocket.c
38359 @@ -924,7 +924,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
38360 tty->driver_data = info;
38361 tty_port_tty_set(port, tty);
38362
38363 - if (port->count++ == 0) {
38364 + if (atomic_inc_return(&port->count) == 1) {
38365 atomic_inc(&rp_num_ports_open);
38366
38367 #ifdef ROCKET_DEBUG_OPEN
38368 @@ -933,7 +933,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
38369 #endif
38370 }
38371 #ifdef ROCKET_DEBUG_OPEN
38372 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
38373 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
38374 #endif
38375
38376 /*
38377 @@ -1528,7 +1528,7 @@ static void rp_hangup(struct tty_struct *tty)
38378 spin_unlock_irqrestore(&info->port.lock, flags);
38379 return;
38380 }
38381 - if (info->port.count)
38382 + if (atomic_read(&info->port.count))
38383 atomic_dec(&rp_num_ports_open);
38384 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
38385 spin_unlock_irqrestore(&info->port.lock, flags);
38386 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
38387 index 2b42a01..32a2ed3 100644
38388 --- a/drivers/tty/serial/kgdboc.c
38389 +++ b/drivers/tty/serial/kgdboc.c
38390 @@ -24,8 +24,9 @@
38391 #define MAX_CONFIG_LEN 40
38392
38393 static struct kgdb_io kgdboc_io_ops;
38394 +static struct kgdb_io kgdboc_io_ops_console;
38395
38396 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
38397 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
38398 static int configured = -1;
38399
38400 static char config[MAX_CONFIG_LEN];
38401 @@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
38402 kgdboc_unregister_kbd();
38403 if (configured == 1)
38404 kgdb_unregister_io_module(&kgdboc_io_ops);
38405 + else if (configured == 2)
38406 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
38407 }
38408
38409 static int configure_kgdboc(void)
38410 @@ -157,13 +160,13 @@ static int configure_kgdboc(void)
38411 int err;
38412 char *cptr = config;
38413 struct console *cons;
38414 + int is_console = 0;
38415
38416 err = kgdboc_option_setup(config);
38417 if (err || !strlen(config) || isspace(config[0]))
38418 goto noconfig;
38419
38420 err = -ENODEV;
38421 - kgdboc_io_ops.is_console = 0;
38422 kgdb_tty_driver = NULL;
38423
38424 kgdboc_use_kms = 0;
38425 @@ -184,7 +187,7 @@ static int configure_kgdboc(void)
38426 int idx;
38427 if (cons->device && cons->device(cons, &idx) == p &&
38428 idx == tty_line) {
38429 - kgdboc_io_ops.is_console = 1;
38430 + is_console = 1;
38431 break;
38432 }
38433 cons = cons->next;
38434 @@ -194,12 +197,16 @@ static int configure_kgdboc(void)
38435 kgdb_tty_line = tty_line;
38436
38437 do_register:
38438 - err = kgdb_register_io_module(&kgdboc_io_ops);
38439 + if (is_console) {
38440 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
38441 + configured = 2;
38442 + } else {
38443 + err = kgdb_register_io_module(&kgdboc_io_ops);
38444 + configured = 1;
38445 + }
38446 if (err)
38447 goto noconfig;
38448
38449 - configured = 1;
38450 -
38451 return 0;
38452
38453 noconfig:
38454 @@ -213,7 +220,7 @@ noconfig:
38455 static int __init init_kgdboc(void)
38456 {
38457 /* Already configured? */
38458 - if (configured == 1)
38459 + if (configured >= 1)
38460 return 0;
38461
38462 return configure_kgdboc();
38463 @@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
38464 if (config[len - 1] == '\n')
38465 config[len - 1] = '\0';
38466
38467 - if (configured == 1)
38468 + if (configured >= 1)
38469 cleanup_kgdboc();
38470
38471 /* Go and configure with the new params. */
38472 @@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
38473 .post_exception = kgdboc_post_exp_handler,
38474 };
38475
38476 +static struct kgdb_io kgdboc_io_ops_console = {
38477 + .name = "kgdboc",
38478 + .read_char = kgdboc_get_char,
38479 + .write_char = kgdboc_put_char,
38480 + .pre_exception = kgdboc_pre_exp_handler,
38481 + .post_exception = kgdboc_post_exp_handler,
38482 + .is_console = 1
38483 +};
38484 +
38485 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
38486 /* This is only available if kgdboc is a built in for early debugging */
38487 static int __init kgdboc_early_init(char *opt)
38488 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
38489 index a21dc8e..fe43e9e 100644
38490 --- a/drivers/tty/serial/serial_core.c
38491 +++ b/drivers/tty/serial/serial_core.c
38492 @@ -1392,7 +1392,7 @@ static void uart_hangup(struct tty_struct *tty)
38493 uart_flush_buffer(tty);
38494 uart_shutdown(tty, state);
38495 spin_lock_irqsave(&port->lock, flags);
38496 - port->count = 0;
38497 + atomic_set(&port->count, 0);
38498 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
38499 spin_unlock_irqrestore(&port->lock, flags);
38500 tty_port_tty_set(port, NULL);
38501 @@ -1488,7 +1488,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38502 goto end;
38503 }
38504
38505 - port->count++;
38506 + atomic_inc(&port->count);
38507 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
38508 retval = -ENXIO;
38509 goto err_dec_count;
38510 @@ -1515,7 +1515,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38511 /*
38512 * Make sure the device is in D0 state.
38513 */
38514 - if (port->count == 1)
38515 + if (atomic_read(&port->count) == 1)
38516 uart_change_pm(state, 0);
38517
38518 /*
38519 @@ -1533,7 +1533,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38520 end:
38521 return retval;
38522 err_dec_count:
38523 - port->count--;
38524 + atomic_inc(&port->count);
38525 mutex_unlock(&port->mutex);
38526 goto end;
38527 }
38528 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
38529 index 593d40a..bdc61f3 100644
38530 --- a/drivers/tty/synclink.c
38531 +++ b/drivers/tty/synclink.c
38532 @@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38533
38534 if (debug_level >= DEBUG_LEVEL_INFO)
38535 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
38536 - __FILE__,__LINE__, info->device_name, info->port.count);
38537 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38538
38539 if (tty_port_close_start(&info->port, tty, filp) == 0)
38540 goto cleanup;
38541 @@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38542 cleanup:
38543 if (debug_level >= DEBUG_LEVEL_INFO)
38544 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
38545 - tty->driver->name, info->port.count);
38546 + tty->driver->name, atomic_read(&info->port.count));
38547
38548 } /* end of mgsl_close() */
38549
38550 @@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
38551
38552 mgsl_flush_buffer(tty);
38553 shutdown(info);
38554 -
38555 - info->port.count = 0;
38556 +
38557 + atomic_set(&info->port.count, 0);
38558 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38559 info->port.tty = NULL;
38560
38561 @@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38562
38563 if (debug_level >= DEBUG_LEVEL_INFO)
38564 printk("%s(%d):block_til_ready before block on %s count=%d\n",
38565 - __FILE__,__LINE__, tty->driver->name, port->count );
38566 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38567
38568 spin_lock_irqsave(&info->irq_spinlock, flags);
38569 if (!tty_hung_up_p(filp)) {
38570 extra_count = true;
38571 - port->count--;
38572 + atomic_dec(&port->count);
38573 }
38574 spin_unlock_irqrestore(&info->irq_spinlock, flags);
38575 port->blocked_open++;
38576 @@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38577
38578 if (debug_level >= DEBUG_LEVEL_INFO)
38579 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
38580 - __FILE__,__LINE__, tty->driver->name, port->count );
38581 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38582
38583 tty_unlock();
38584 schedule();
38585 @@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38586
38587 /* FIXME: Racy on hangup during close wait */
38588 if (extra_count)
38589 - port->count++;
38590 + atomic_inc(&port->count);
38591 port->blocked_open--;
38592
38593 if (debug_level >= DEBUG_LEVEL_INFO)
38594 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
38595 - __FILE__,__LINE__, tty->driver->name, port->count );
38596 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38597
38598 if (!retval)
38599 port->flags |= ASYNC_NORMAL_ACTIVE;
38600 @@ -3398,7 +3398,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38601
38602 if (debug_level >= DEBUG_LEVEL_INFO)
38603 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
38604 - __FILE__,__LINE__,tty->driver->name, info->port.count);
38605 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38606
38607 /* If port is closing, signal caller to try again */
38608 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38609 @@ -3417,10 +3417,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38610 spin_unlock_irqrestore(&info->netlock, flags);
38611 goto cleanup;
38612 }
38613 - info->port.count++;
38614 + atomic_inc(&info->port.count);
38615 spin_unlock_irqrestore(&info->netlock, flags);
38616
38617 - if (info->port.count == 1) {
38618 + if (atomic_read(&info->port.count) == 1) {
38619 /* 1st open on this device, init hardware */
38620 retval = startup(info);
38621 if (retval < 0)
38622 @@ -3444,8 +3444,8 @@ cleanup:
38623 if (retval) {
38624 if (tty->count == 1)
38625 info->port.tty = NULL; /* tty layer will release tty struct */
38626 - if(info->port.count)
38627 - info->port.count--;
38628 + if (atomic_read(&info->port.count))
38629 + atomic_dec(&info->port.count);
38630 }
38631
38632 return retval;
38633 @@ -7653,7 +7653,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38634 unsigned short new_crctype;
38635
38636 /* return error if TTY interface open */
38637 - if (info->port.count)
38638 + if (atomic_read(&info->port.count))
38639 return -EBUSY;
38640
38641 switch (encoding)
38642 @@ -7748,7 +7748,7 @@ static int hdlcdev_open(struct net_device *dev)
38643
38644 /* arbitrate between network and tty opens */
38645 spin_lock_irqsave(&info->netlock, flags);
38646 - if (info->port.count != 0 || info->netcount != 0) {
38647 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38648 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38649 spin_unlock_irqrestore(&info->netlock, flags);
38650 return -EBUSY;
38651 @@ -7834,7 +7834,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38652 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38653
38654 /* return error if TTY interface open */
38655 - if (info->port.count)
38656 + if (atomic_read(&info->port.count))
38657 return -EBUSY;
38658
38659 if (cmd != SIOCWANDEV)
38660 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
38661 index aa1debf..9297a16 100644
38662 --- a/drivers/tty/synclink_gt.c
38663 +++ b/drivers/tty/synclink_gt.c
38664 @@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38665 tty->driver_data = info;
38666 info->port.tty = tty;
38667
38668 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
38669 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
38670
38671 /* If port is closing, signal caller to try again */
38672 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38673 @@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38674 mutex_unlock(&info->port.mutex);
38675 goto cleanup;
38676 }
38677 - info->port.count++;
38678 + atomic_inc(&info->port.count);
38679 spin_unlock_irqrestore(&info->netlock, flags);
38680
38681 - if (info->port.count == 1) {
38682 + if (atomic_read(&info->port.count) == 1) {
38683 /* 1st open on this device, init hardware */
38684 retval = startup(info);
38685 if (retval < 0) {
38686 @@ -716,8 +716,8 @@ cleanup:
38687 if (retval) {
38688 if (tty->count == 1)
38689 info->port.tty = NULL; /* tty layer will release tty struct */
38690 - if(info->port.count)
38691 - info->port.count--;
38692 + if(atomic_read(&info->port.count))
38693 + atomic_dec(&info->port.count);
38694 }
38695
38696 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
38697 @@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38698
38699 if (sanity_check(info, tty->name, "close"))
38700 return;
38701 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
38702 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
38703
38704 if (tty_port_close_start(&info->port, tty, filp) == 0)
38705 goto cleanup;
38706 @@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38707 tty_port_close_end(&info->port, tty);
38708 info->port.tty = NULL;
38709 cleanup:
38710 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
38711 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
38712 }
38713
38714 static void hangup(struct tty_struct *tty)
38715 @@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
38716 shutdown(info);
38717
38718 spin_lock_irqsave(&info->port.lock, flags);
38719 - info->port.count = 0;
38720 + atomic_set(&info->port.count, 0);
38721 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38722 info->port.tty = NULL;
38723 spin_unlock_irqrestore(&info->port.lock, flags);
38724 @@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38725 unsigned short new_crctype;
38726
38727 /* return error if TTY interface open */
38728 - if (info->port.count)
38729 + if (atomic_read(&info->port.count))
38730 return -EBUSY;
38731
38732 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
38733 @@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
38734
38735 /* arbitrate between network and tty opens */
38736 spin_lock_irqsave(&info->netlock, flags);
38737 - if (info->port.count != 0 || info->netcount != 0) {
38738 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38739 DBGINFO(("%s hdlc_open busy\n", dev->name));
38740 spin_unlock_irqrestore(&info->netlock, flags);
38741 return -EBUSY;
38742 @@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38743 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
38744
38745 /* return error if TTY interface open */
38746 - if (info->port.count)
38747 + if (atomic_read(&info->port.count))
38748 return -EBUSY;
38749
38750 if (cmd != SIOCWANDEV)
38751 @@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
38752 if (port == NULL)
38753 continue;
38754 spin_lock(&port->lock);
38755 - if ((port->port.count || port->netcount) &&
38756 + if ((atomic_read(&port->port.count) || port->netcount) &&
38757 port->pending_bh && !port->bh_running &&
38758 !port->bh_requested) {
38759 DBGISR(("%s bh queued\n", port->device_name));
38760 @@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38761 spin_lock_irqsave(&info->lock, flags);
38762 if (!tty_hung_up_p(filp)) {
38763 extra_count = true;
38764 - port->count--;
38765 + atomic_dec(&port->count);
38766 }
38767 spin_unlock_irqrestore(&info->lock, flags);
38768 port->blocked_open++;
38769 @@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38770 remove_wait_queue(&port->open_wait, &wait);
38771
38772 if (extra_count)
38773 - port->count++;
38774 + atomic_inc(&port->count);
38775 port->blocked_open--;
38776
38777 if (!retval)
38778 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
38779 index a3dddc1..8905ab2 100644
38780 --- a/drivers/tty/synclinkmp.c
38781 +++ b/drivers/tty/synclinkmp.c
38782 @@ -742,7 +742,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38783
38784 if (debug_level >= DEBUG_LEVEL_INFO)
38785 printk("%s(%d):%s open(), old ref count = %d\n",
38786 - __FILE__,__LINE__,tty->driver->name, info->port.count);
38787 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38788
38789 /* If port is closing, signal caller to try again */
38790 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38791 @@ -761,10 +761,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38792 spin_unlock_irqrestore(&info->netlock, flags);
38793 goto cleanup;
38794 }
38795 - info->port.count++;
38796 + atomic_inc(&info->port.count);
38797 spin_unlock_irqrestore(&info->netlock, flags);
38798
38799 - if (info->port.count == 1) {
38800 + if (atomic_read(&info->port.count) == 1) {
38801 /* 1st open on this device, init hardware */
38802 retval = startup(info);
38803 if (retval < 0)
38804 @@ -788,8 +788,8 @@ cleanup:
38805 if (retval) {
38806 if (tty->count == 1)
38807 info->port.tty = NULL; /* tty layer will release tty struct */
38808 - if(info->port.count)
38809 - info->port.count--;
38810 + if(atomic_read(&info->port.count))
38811 + atomic_dec(&info->port.count);
38812 }
38813
38814 return retval;
38815 @@ -807,7 +807,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38816
38817 if (debug_level >= DEBUG_LEVEL_INFO)
38818 printk("%s(%d):%s close() entry, count=%d\n",
38819 - __FILE__,__LINE__, info->device_name, info->port.count);
38820 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38821
38822 if (tty_port_close_start(&info->port, tty, filp) == 0)
38823 goto cleanup;
38824 @@ -826,7 +826,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38825 cleanup:
38826 if (debug_level >= DEBUG_LEVEL_INFO)
38827 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
38828 - tty->driver->name, info->port.count);
38829 + tty->driver->name, atomic_read(&info->port.count));
38830 }
38831
38832 /* Called by tty_hangup() when a hangup is signaled.
38833 @@ -849,7 +849,7 @@ static void hangup(struct tty_struct *tty)
38834 shutdown(info);
38835
38836 spin_lock_irqsave(&info->port.lock, flags);
38837 - info->port.count = 0;
38838 + atomic_set(&info->port.count, 0);
38839 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38840 info->port.tty = NULL;
38841 spin_unlock_irqrestore(&info->port.lock, flags);
38842 @@ -1557,7 +1557,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38843 unsigned short new_crctype;
38844
38845 /* return error if TTY interface open */
38846 - if (info->port.count)
38847 + if (atomic_read(&info->port.count))
38848 return -EBUSY;
38849
38850 switch (encoding)
38851 @@ -1652,7 +1652,7 @@ static int hdlcdev_open(struct net_device *dev)
38852
38853 /* arbitrate between network and tty opens */
38854 spin_lock_irqsave(&info->netlock, flags);
38855 - if (info->port.count != 0 || info->netcount != 0) {
38856 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38857 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38858 spin_unlock_irqrestore(&info->netlock, flags);
38859 return -EBUSY;
38860 @@ -1738,7 +1738,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38861 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38862
38863 /* return error if TTY interface open */
38864 - if (info->port.count)
38865 + if (atomic_read(&info->port.count))
38866 return -EBUSY;
38867
38868 if (cmd != SIOCWANDEV)
38869 @@ -2623,7 +2623,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
38870 * do not request bottom half processing if the
38871 * device is not open in a normal mode.
38872 */
38873 - if ( port && (port->port.count || port->netcount) &&
38874 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
38875 port->pending_bh && !port->bh_running &&
38876 !port->bh_requested ) {
38877 if ( debug_level >= DEBUG_LEVEL_ISR )
38878 @@ -3321,12 +3321,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38879
38880 if (debug_level >= DEBUG_LEVEL_INFO)
38881 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
38882 - __FILE__,__LINE__, tty->driver->name, port->count );
38883 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38884
38885 spin_lock_irqsave(&info->lock, flags);
38886 if (!tty_hung_up_p(filp)) {
38887 extra_count = true;
38888 - port->count--;
38889 + atomic_dec(&port->count);
38890 }
38891 spin_unlock_irqrestore(&info->lock, flags);
38892 port->blocked_open++;
38893 @@ -3355,7 +3355,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38894
38895 if (debug_level >= DEBUG_LEVEL_INFO)
38896 printk("%s(%d):%s block_til_ready() count=%d\n",
38897 - __FILE__,__LINE__, tty->driver->name, port->count );
38898 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38899
38900 tty_unlock();
38901 schedule();
38902 @@ -3366,12 +3366,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38903 remove_wait_queue(&port->open_wait, &wait);
38904
38905 if (extra_count)
38906 - port->count++;
38907 + atomic_inc(&port->count);
38908 port->blocked_open--;
38909
38910 if (debug_level >= DEBUG_LEVEL_INFO)
38911 printk("%s(%d):%s block_til_ready() after, count=%d\n",
38912 - __FILE__,__LINE__, tty->driver->name, port->count );
38913 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38914
38915 if (!retval)
38916 port->flags |= ASYNC_NORMAL_ACTIVE;
38917 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
38918 index 05728894..b9d44c6 100644
38919 --- a/drivers/tty/sysrq.c
38920 +++ b/drivers/tty/sysrq.c
38921 @@ -865,7 +865,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
38922 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
38923 size_t count, loff_t *ppos)
38924 {
38925 - if (count) {
38926 + if (count && capable(CAP_SYS_ADMIN)) {
38927 char c;
38928
38929 if (get_user(c, buf))
38930 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
38931 index b425c79..08a3f06 100644
38932 --- a/drivers/tty/tty_io.c
38933 +++ b/drivers/tty/tty_io.c
38934 @@ -3283,7 +3283,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
38935
38936 void tty_default_fops(struct file_operations *fops)
38937 {
38938 - *fops = tty_fops;
38939 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
38940 }
38941
38942 /*
38943 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
38944 index 6f99c99..8947bc4 100644
38945 --- a/drivers/tty/tty_ldisc.c
38946 +++ b/drivers/tty/tty_ldisc.c
38947 @@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
38948 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
38949 struct tty_ldisc_ops *ldo = ld->ops;
38950
38951 - ldo->refcount--;
38952 + atomic_dec(&ldo->refcount);
38953 module_put(ldo->owner);
38954 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38955
38956 @@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
38957 spin_lock_irqsave(&tty_ldisc_lock, flags);
38958 tty_ldiscs[disc] = new_ldisc;
38959 new_ldisc->num = disc;
38960 - new_ldisc->refcount = 0;
38961 + atomic_set(&new_ldisc->refcount, 0);
38962 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38963
38964 return ret;
38965 @@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
38966 return -EINVAL;
38967
38968 spin_lock_irqsave(&tty_ldisc_lock, flags);
38969 - if (tty_ldiscs[disc]->refcount)
38970 + if (atomic_read(&tty_ldiscs[disc]->refcount))
38971 ret = -EBUSY;
38972 else
38973 tty_ldiscs[disc] = NULL;
38974 @@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
38975 if (ldops) {
38976 ret = ERR_PTR(-EAGAIN);
38977 if (try_module_get(ldops->owner)) {
38978 - ldops->refcount++;
38979 + atomic_inc(&ldops->refcount);
38980 ret = ldops;
38981 }
38982 }
38983 @@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
38984 unsigned long flags;
38985
38986 spin_lock_irqsave(&tty_ldisc_lock, flags);
38987 - ldops->refcount--;
38988 + atomic_dec(&ldops->refcount);
38989 module_put(ldops->owner);
38990 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38991 }
38992 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
38993 index bf6e238..d401c04 100644
38994 --- a/drivers/tty/tty_port.c
38995 +++ b/drivers/tty/tty_port.c
38996 @@ -138,7 +138,7 @@ void tty_port_hangup(struct tty_port *port)
38997 unsigned long flags;
38998
38999 spin_lock_irqsave(&port->lock, flags);
39000 - port->count = 0;
39001 + atomic_set(&port->count, 0);
39002 port->flags &= ~ASYNC_NORMAL_ACTIVE;
39003 if (port->tty) {
39004 set_bit(TTY_IO_ERROR, &port->tty->flags);
39005 @@ -264,7 +264,7 @@ int tty_port_block_til_ready(struct tty_port *port,
39006 /* The port lock protects the port counts */
39007 spin_lock_irqsave(&port->lock, flags);
39008 if (!tty_hung_up_p(filp))
39009 - port->count--;
39010 + atomic_dec(&port->count);
39011 port->blocked_open++;
39012 spin_unlock_irqrestore(&port->lock, flags);
39013
39014 @@ -306,7 +306,7 @@ int tty_port_block_til_ready(struct tty_port *port,
39015 we must not mess that up further */
39016 spin_lock_irqsave(&port->lock, flags);
39017 if (!tty_hung_up_p(filp))
39018 - port->count++;
39019 + atomic_inc(&port->count);
39020 port->blocked_open--;
39021 if (retval == 0)
39022 port->flags |= ASYNC_NORMAL_ACTIVE;
39023 @@ -326,19 +326,19 @@ int tty_port_close_start(struct tty_port *port,
39024 return 0;
39025 }
39026
39027 - if (tty->count == 1 && port->count != 1) {
39028 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
39029 printk(KERN_WARNING
39030 "tty_port_close_start: tty->count = 1 port count = %d.\n",
39031 - port->count);
39032 - port->count = 1;
39033 + atomic_read(&port->count));
39034 + atomic_set(&port->count, 1);
39035 }
39036 - if (--port->count < 0) {
39037 + if (atomic_dec_return(&port->count) < 0) {
39038 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
39039 - port->count);
39040 - port->count = 0;
39041 + atomic_read(&port->count));
39042 + atomic_set(&port->count, 0);
39043 }
39044
39045 - if (port->count) {
39046 + if (atomic_read(&port->count)) {
39047 spin_unlock_irqrestore(&port->lock, flags);
39048 if (port->ops->drop)
39049 port->ops->drop(port);
39050 @@ -418,7 +418,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
39051 {
39052 spin_lock_irq(&port->lock);
39053 if (!tty_hung_up_p(filp))
39054 - ++port->count;
39055 + atomic_inc(&port->count);
39056 spin_unlock_irq(&port->lock);
39057 tty_port_tty_set(port, tty);
39058
39059 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
39060 index 770a854..e5d3db3 100644
39061 --- a/drivers/tty/vt/keyboard.c
39062 +++ b/drivers/tty/vt/keyboard.c
39063 @@ -659,6 +659,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
39064 kbd->kbdmode == VC_OFF) &&
39065 value != KVAL(K_SAK))
39066 return; /* SAK is allowed even in raw mode */
39067 +
39068 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
39069 + {
39070 + void *func = fn_handler[value];
39071 + if (func == fn_show_state || func == fn_show_ptregs ||
39072 + func == fn_show_mem)
39073 + return;
39074 + }
39075 +#endif
39076 +
39077 fn_handler[value](vc);
39078 }
39079
39080 @@ -1805,9 +1815,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
39081 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
39082 return -EFAULT;
39083
39084 - if (!capable(CAP_SYS_TTY_CONFIG))
39085 - perm = 0;
39086 -
39087 switch (cmd) {
39088 case KDGKBENT:
39089 /* Ensure another thread doesn't free it under us */
39090 @@ -1822,6 +1829,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
39091 spin_unlock_irqrestore(&kbd_event_lock, flags);
39092 return put_user(val, &user_kbe->kb_value);
39093 case KDSKBENT:
39094 + if (!capable(CAP_SYS_TTY_CONFIG))
39095 + perm = 0;
39096 +
39097 if (!perm)
39098 return -EPERM;
39099 if (!i && v == K_NOSUCHMAP) {
39100 @@ -1912,9 +1922,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
39101 int i, j, k;
39102 int ret;
39103
39104 - if (!capable(CAP_SYS_TTY_CONFIG))
39105 - perm = 0;
39106 -
39107 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
39108 if (!kbs) {
39109 ret = -ENOMEM;
39110 @@ -1948,6 +1955,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
39111 kfree(kbs);
39112 return ((p && *p) ? -EOVERFLOW : 0);
39113 case KDSKBSENT:
39114 + if (!capable(CAP_SYS_TTY_CONFIG))
39115 + perm = 0;
39116 +
39117 if (!perm) {
39118 ret = -EPERM;
39119 goto reterr;
39120 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
39121 index a783d53..cb30d94 100644
39122 --- a/drivers/uio/uio.c
39123 +++ b/drivers/uio/uio.c
39124 @@ -25,6 +25,7 @@
39125 #include <linux/kobject.h>
39126 #include <linux/cdev.h>
39127 #include <linux/uio_driver.h>
39128 +#include <asm/local.h>
39129
39130 #define UIO_MAX_DEVICES (1U << MINORBITS)
39131
39132 @@ -32,10 +33,10 @@ struct uio_device {
39133 struct module *owner;
39134 struct device *dev;
39135 int minor;
39136 - atomic_t event;
39137 + atomic_unchecked_t event;
39138 struct fasync_struct *async_queue;
39139 wait_queue_head_t wait;
39140 - int vma_count;
39141 + local_t vma_count;
39142 struct uio_info *info;
39143 struct kobject *map_dir;
39144 struct kobject *portio_dir;
39145 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
39146 struct device_attribute *attr, char *buf)
39147 {
39148 struct uio_device *idev = dev_get_drvdata(dev);
39149 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
39150 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
39151 }
39152
39153 static struct device_attribute uio_class_attributes[] = {
39154 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
39155 {
39156 struct uio_device *idev = info->uio_dev;
39157
39158 - atomic_inc(&idev->event);
39159 + atomic_inc_unchecked(&idev->event);
39160 wake_up_interruptible(&idev->wait);
39161 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
39162 }
39163 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
39164 }
39165
39166 listener->dev = idev;
39167 - listener->event_count = atomic_read(&idev->event);
39168 + listener->event_count = atomic_read_unchecked(&idev->event);
39169 filep->private_data = listener;
39170
39171 if (idev->info->open) {
39172 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
39173 return -EIO;
39174
39175 poll_wait(filep, &idev->wait, wait);
39176 - if (listener->event_count != atomic_read(&idev->event))
39177 + if (listener->event_count != atomic_read_unchecked(&idev->event))
39178 return POLLIN | POLLRDNORM;
39179 return 0;
39180 }
39181 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
39182 do {
39183 set_current_state(TASK_INTERRUPTIBLE);
39184
39185 - event_count = atomic_read(&idev->event);
39186 + event_count = atomic_read_unchecked(&idev->event);
39187 if (event_count != listener->event_count) {
39188 if (copy_to_user(buf, &event_count, count))
39189 retval = -EFAULT;
39190 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
39191 static void uio_vma_open(struct vm_area_struct *vma)
39192 {
39193 struct uio_device *idev = vma->vm_private_data;
39194 - idev->vma_count++;
39195 + local_inc(&idev->vma_count);
39196 }
39197
39198 static void uio_vma_close(struct vm_area_struct *vma)
39199 {
39200 struct uio_device *idev = vma->vm_private_data;
39201 - idev->vma_count--;
39202 + local_dec(&idev->vma_count);
39203 }
39204
39205 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
39206 @@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
39207 idev->owner = owner;
39208 idev->info = info;
39209 init_waitqueue_head(&idev->wait);
39210 - atomic_set(&idev->event, 0);
39211 + atomic_set_unchecked(&idev->event, 0);
39212
39213 ret = uio_get_minor(idev);
39214 if (ret)
39215 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
39216 index b7eb86a..36d28af 100644
39217 --- a/drivers/usb/atm/cxacru.c
39218 +++ b/drivers/usb/atm/cxacru.c
39219 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
39220 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
39221 if (ret < 2)
39222 return -EINVAL;
39223 - if (index < 0 || index > 0x7f)
39224 + if (index > 0x7f)
39225 return -EINVAL;
39226 pos += tmp;
39227
39228 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
39229 index ee62b35..b663594 100644
39230 --- a/drivers/usb/atm/usbatm.c
39231 +++ b/drivers/usb/atm/usbatm.c
39232 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39233 if (printk_ratelimit())
39234 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
39235 __func__, vpi, vci);
39236 - atomic_inc(&vcc->stats->rx_err);
39237 + atomic_inc_unchecked(&vcc->stats->rx_err);
39238 return;
39239 }
39240
39241 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39242 if (length > ATM_MAX_AAL5_PDU) {
39243 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
39244 __func__, length, vcc);
39245 - atomic_inc(&vcc->stats->rx_err);
39246 + atomic_inc_unchecked(&vcc->stats->rx_err);
39247 goto out;
39248 }
39249
39250 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39251 if (sarb->len < pdu_length) {
39252 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
39253 __func__, pdu_length, sarb->len, vcc);
39254 - atomic_inc(&vcc->stats->rx_err);
39255 + atomic_inc_unchecked(&vcc->stats->rx_err);
39256 goto out;
39257 }
39258
39259 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
39260 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
39261 __func__, vcc);
39262 - atomic_inc(&vcc->stats->rx_err);
39263 + atomic_inc_unchecked(&vcc->stats->rx_err);
39264 goto out;
39265 }
39266
39267 @@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39268 if (printk_ratelimit())
39269 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
39270 __func__, length);
39271 - atomic_inc(&vcc->stats->rx_drop);
39272 + atomic_inc_unchecked(&vcc->stats->rx_drop);
39273 goto out;
39274 }
39275
39276 @@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39277
39278 vcc->push(vcc, skb);
39279
39280 - atomic_inc(&vcc->stats->rx);
39281 + atomic_inc_unchecked(&vcc->stats->rx);
39282 out:
39283 skb_trim(sarb, 0);
39284 }
39285 @@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
39286 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
39287
39288 usbatm_pop(vcc, skb);
39289 - atomic_inc(&vcc->stats->tx);
39290 + atomic_inc_unchecked(&vcc->stats->tx);
39291
39292 skb = skb_dequeue(&instance->sndqueue);
39293 }
39294 @@ -770,11 +770,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
39295 if (!left--)
39296 return sprintf(page,
39297 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
39298 - atomic_read(&atm_dev->stats.aal5.tx),
39299 - atomic_read(&atm_dev->stats.aal5.tx_err),
39300 - atomic_read(&atm_dev->stats.aal5.rx),
39301 - atomic_read(&atm_dev->stats.aal5.rx_err),
39302 - atomic_read(&atm_dev->stats.aal5.rx_drop));
39303 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
39304 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
39305 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
39306 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
39307 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
39308
39309 if (!left--) {
39310 if (instance->disconnected)
39311 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
39312 index 3440812..2a4ef1f 100644
39313 --- a/drivers/usb/core/devices.c
39314 +++ b/drivers/usb/core/devices.c
39315 @@ -126,7 +126,7 @@ static const char format_endpt[] =
39316 * time it gets called.
39317 */
39318 static struct device_connect_event {
39319 - atomic_t count;
39320 + atomic_unchecked_t count;
39321 wait_queue_head_t wait;
39322 } device_event = {
39323 .count = ATOMIC_INIT(1),
39324 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
39325
39326 void usbfs_conn_disc_event(void)
39327 {
39328 - atomic_add(2, &device_event.count);
39329 + atomic_add_unchecked(2, &device_event.count);
39330 wake_up(&device_event.wait);
39331 }
39332
39333 @@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
39334
39335 poll_wait(file, &device_event.wait, wait);
39336
39337 - event_count = atomic_read(&device_event.count);
39338 + event_count = atomic_read_unchecked(&device_event.count);
39339 if (file->f_version != event_count) {
39340 file->f_version = event_count;
39341 return POLLIN | POLLRDNORM;
39342 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
39343 index 89dcf15..481800b 100644
39344 --- a/drivers/usb/early/ehci-dbgp.c
39345 +++ b/drivers/usb/early/ehci-dbgp.c
39346 @@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
39347
39348 #ifdef CONFIG_KGDB
39349 static struct kgdb_io kgdbdbgp_io_ops;
39350 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
39351 +static struct kgdb_io kgdbdbgp_io_ops_console;
39352 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
39353 #else
39354 #define dbgp_kgdb_mode (0)
39355 #endif
39356 @@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
39357 .write_char = kgdbdbgp_write_char,
39358 };
39359
39360 +static struct kgdb_io kgdbdbgp_io_ops_console = {
39361 + .name = "kgdbdbgp",
39362 + .read_char = kgdbdbgp_read_char,
39363 + .write_char = kgdbdbgp_write_char,
39364 + .is_console = 1
39365 +};
39366 +
39367 static int kgdbdbgp_wait_time;
39368
39369 static int __init kgdbdbgp_parse_config(char *str)
39370 @@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
39371 ptr++;
39372 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
39373 }
39374 - kgdb_register_io_module(&kgdbdbgp_io_ops);
39375 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
39376 + if (early_dbgp_console.index != -1)
39377 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
39378 + else
39379 + kgdb_register_io_module(&kgdbdbgp_io_ops);
39380
39381 return 0;
39382 }
39383 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
39384 index da6d479..80ed10b 100644
39385 --- a/drivers/usb/gadget/u_serial.c
39386 +++ b/drivers/usb/gadget/u_serial.c
39387 @@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
39388 spin_lock_irq(&port->port_lock);
39389
39390 /* already open? Great. */
39391 - if (port->port.count) {
39392 + if (atomic_read(&port->port.count)) {
39393 status = 0;
39394 - port->port.count++;
39395 + atomic_inc(&port->port.count);
39396
39397 /* currently opening/closing? wait ... */
39398 } else if (port->openclose) {
39399 @@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
39400 tty->driver_data = port;
39401 port->port.tty = tty;
39402
39403 - port->port.count = 1;
39404 + atomic_set(&port->port.count, 1);
39405 port->openclose = false;
39406
39407 /* if connected, start the I/O stream */
39408 @@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
39409
39410 spin_lock_irq(&port->port_lock);
39411
39412 - if (port->port.count != 1) {
39413 - if (port->port.count == 0)
39414 + if (atomic_read(&port->port.count) != 1) {
39415 + if (atomic_read(&port->port.count) == 0)
39416 WARN_ON(1);
39417 else
39418 - --port->port.count;
39419 + atomic_dec(&port->port.count);
39420 goto exit;
39421 }
39422
39423 @@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
39424 * and sleep if necessary
39425 */
39426 port->openclose = true;
39427 - port->port.count = 0;
39428 + atomic_set(&port->port.count, 0);
39429
39430 gser = port->port_usb;
39431 if (gser && gser->disconnect)
39432 @@ -1156,7 +1156,7 @@ static int gs_closed(struct gs_port *port)
39433 int cond;
39434
39435 spin_lock_irq(&port->port_lock);
39436 - cond = (port->port.count == 0) && !port->openclose;
39437 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
39438 spin_unlock_irq(&port->port_lock);
39439 return cond;
39440 }
39441 @@ -1269,7 +1269,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
39442 /* if it's already open, start I/O ... and notify the serial
39443 * protocol about open/close status (connect/disconnect).
39444 */
39445 - if (port->port.count) {
39446 + if (atomic_read(&port->port.count)) {
39447 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
39448 gs_start_io(port);
39449 if (gser->connect)
39450 @@ -1316,7 +1316,7 @@ void gserial_disconnect(struct gserial *gser)
39451
39452 port->port_usb = NULL;
39453 gser->ioport = NULL;
39454 - if (port->port.count > 0 || port->openclose) {
39455 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
39456 wake_up_interruptible(&port->drain_wait);
39457 if (port->port.tty)
39458 tty_hangup(port->port.tty);
39459 @@ -1332,7 +1332,7 @@ void gserial_disconnect(struct gserial *gser)
39460
39461 /* finally, free any unused/unusable I/O buffers */
39462 spin_lock_irqsave(&port->port_lock, flags);
39463 - if (port->port.count == 0 && !port->openclose)
39464 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
39465 gs_buf_free(&port->port_write_buf);
39466 gs_free_requests(gser->out, &port->read_pool, NULL);
39467 gs_free_requests(gser->out, &port->read_queue, NULL);
39468 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
39469 index b9cca6d..75c75df 100644
39470 --- a/drivers/usb/serial/console.c
39471 +++ b/drivers/usb/serial/console.c
39472 @@ -127,7 +127,7 @@ static int usb_console_setup(struct console *co, char *options)
39473
39474 info->port = port;
39475
39476 - ++port->port.count;
39477 + atomic_inc(&port->port.count);
39478 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
39479 if (serial->type->set_termios) {
39480 /*
39481 @@ -177,7 +177,7 @@ static int usb_console_setup(struct console *co, char *options)
39482 }
39483 /* Now that any required fake tty operations are completed restore
39484 * the tty port count */
39485 - --port->port.count;
39486 + atomic_dec(&port->port.count);
39487 /* The console is special in terms of closing the device so
39488 * indicate this port is now acting as a system console. */
39489 port->port.console = 1;
39490 @@ -190,7 +190,7 @@ static int usb_console_setup(struct console *co, char *options)
39491 free_tty:
39492 kfree(tty);
39493 reset_open_count:
39494 - port->port.count = 0;
39495 + atomic_set(&port->port.count, 0);
39496 usb_autopm_put_interface(serial->interface);
39497 error_get_interface:
39498 usb_serial_put(serial);
39499 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
39500 index d6bea3e..60b250e 100644
39501 --- a/drivers/usb/wusbcore/wa-hc.h
39502 +++ b/drivers/usb/wusbcore/wa-hc.h
39503 @@ -192,7 +192,7 @@ struct wahc {
39504 struct list_head xfer_delayed_list;
39505 spinlock_t xfer_list_lock;
39506 struct work_struct xfer_work;
39507 - atomic_t xfer_id_count;
39508 + atomic_unchecked_t xfer_id_count;
39509 };
39510
39511
39512 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
39513 INIT_LIST_HEAD(&wa->xfer_delayed_list);
39514 spin_lock_init(&wa->xfer_list_lock);
39515 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
39516 - atomic_set(&wa->xfer_id_count, 1);
39517 + atomic_set_unchecked(&wa->xfer_id_count, 1);
39518 }
39519
39520 /**
39521 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
39522 index 57c01ab..8a05959 100644
39523 --- a/drivers/usb/wusbcore/wa-xfer.c
39524 +++ b/drivers/usb/wusbcore/wa-xfer.c
39525 @@ -296,7 +296,7 @@ out:
39526 */
39527 static void wa_xfer_id_init(struct wa_xfer *xfer)
39528 {
39529 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
39530 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
39531 }
39532
39533 /*
39534 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
39535 index ef82a0d..da8a0b3 100644
39536 --- a/drivers/vhost/vhost.c
39537 +++ b/drivers/vhost/vhost.c
39538 @@ -634,7 +634,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
39539 return 0;
39540 }
39541
39542 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
39543 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
39544 {
39545 struct file *eventfp, *filep = NULL,
39546 *pollstart = NULL, *pollstop = NULL;
39547 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
39548 index 747442d..7c0c434 100644
39549 --- a/drivers/video/aty/aty128fb.c
39550 +++ b/drivers/video/aty/aty128fb.c
39551 @@ -149,7 +149,7 @@ enum {
39552 };
39553
39554 /* Must match above enum */
39555 -static const char *r128_family[] __devinitdata = {
39556 +static const char *r128_family[] __devinitconst = {
39557 "AGP",
39558 "PCI",
39559 "PRO AGP",
39560 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
39561 index 5c3960d..15cf8fc 100644
39562 --- a/drivers/video/fbcmap.c
39563 +++ b/drivers/video/fbcmap.c
39564 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
39565 rc = -ENODEV;
39566 goto out;
39567 }
39568 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
39569 - !info->fbops->fb_setcmap)) {
39570 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
39571 rc = -EINVAL;
39572 goto out1;
39573 }
39574 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
39575 index 0dff12a..2ef47b3 100644
39576 --- a/drivers/video/fbmem.c
39577 +++ b/drivers/video/fbmem.c
39578 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39579 image->dx += image->width + 8;
39580 }
39581 } else if (rotate == FB_ROTATE_UD) {
39582 - for (x = 0; x < num && image->dx >= 0; x++) {
39583 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
39584 info->fbops->fb_imageblit(info, image);
39585 image->dx -= image->width + 8;
39586 }
39587 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39588 image->dy += image->height + 8;
39589 }
39590 } else if (rotate == FB_ROTATE_CCW) {
39591 - for (x = 0; x < num && image->dy >= 0; x++) {
39592 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
39593 info->fbops->fb_imageblit(info, image);
39594 image->dy -= image->height + 8;
39595 }
39596 @@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
39597 return -EFAULT;
39598 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
39599 return -EINVAL;
39600 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
39601 + if (con2fb.framebuffer >= FB_MAX)
39602 return -EINVAL;
39603 if (!registered_fb[con2fb.framebuffer])
39604 request_module("fb%d", con2fb.framebuffer);
39605 diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
39606 index 5a5d092..265c5ed 100644
39607 --- a/drivers/video/geode/gx1fb_core.c
39608 +++ b/drivers/video/geode/gx1fb_core.c
39609 @@ -29,7 +29,7 @@ static int crt_option = 1;
39610 static char panel_option[32] = "";
39611
39612 /* Modes relevant to the GX1 (taken from modedb.c) */
39613 -static const struct fb_videomode __devinitdata gx1_modedb[] = {
39614 +static const struct fb_videomode __devinitconst gx1_modedb[] = {
39615 /* 640x480-60 VESA */
39616 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
39617 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
39618 diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
39619 index 0fad23f..0e9afa4 100644
39620 --- a/drivers/video/gxt4500.c
39621 +++ b/drivers/video/gxt4500.c
39622 @@ -156,7 +156,7 @@ struct gxt4500_par {
39623 static char *mode_option;
39624
39625 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
39626 -static const struct fb_videomode defaultmode __devinitdata = {
39627 +static const struct fb_videomode defaultmode __devinitconst = {
39628 .refresh = 60,
39629 .xres = 1280,
39630 .yres = 1024,
39631 @@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
39632 return 0;
39633 }
39634
39635 -static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
39636 +static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
39637 .id = "IBM GXT4500P",
39638 .type = FB_TYPE_PACKED_PIXELS,
39639 .visual = FB_VISUAL_PSEUDOCOLOR,
39640 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
39641 index 7672d2e..b56437f 100644
39642 --- a/drivers/video/i810/i810_accel.c
39643 +++ b/drivers/video/i810/i810_accel.c
39644 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
39645 }
39646 }
39647 printk("ringbuffer lockup!!!\n");
39648 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
39649 i810_report_error(mmio);
39650 par->dev_flags |= LOCKUP;
39651 info->pixmap.scan_align = 1;
39652 diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
39653 index b83f361..2b05a91 100644
39654 --- a/drivers/video/i810/i810_main.c
39655 +++ b/drivers/video/i810/i810_main.c
39656 @@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
39657 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
39658
39659 /* PCI */
39660 -static const char *i810_pci_list[] __devinitdata = {
39661 +static const char *i810_pci_list[] __devinitconst = {
39662 "Intel(R) 810 Framebuffer Device" ,
39663 "Intel(R) 810-DC100 Framebuffer Device" ,
39664 "Intel(R) 810E Framebuffer Device" ,
39665 diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
39666 index de36693..3c63fc2 100644
39667 --- a/drivers/video/jz4740_fb.c
39668 +++ b/drivers/video/jz4740_fb.c
39669 @@ -136,7 +136,7 @@ struct jzfb {
39670 uint32_t pseudo_palette[16];
39671 };
39672
39673 -static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
39674 +static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
39675 .id = "JZ4740 FB",
39676 .type = FB_TYPE_PACKED_PIXELS,
39677 .visual = FB_VISUAL_TRUECOLOR,
39678 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
39679 index 3c14e43..eafa544 100644
39680 --- a/drivers/video/logo/logo_linux_clut224.ppm
39681 +++ b/drivers/video/logo/logo_linux_clut224.ppm
39682 @@ -1,1604 +1,1123 @@
39683 P3
39684 -# Standard 224-color Linux logo
39685 80 80
39686 255
39687 - 0 0 0 0 0 0 0 0 0 0 0 0
39688 - 0 0 0 0 0 0 0 0 0 0 0 0
39689 - 0 0 0 0 0 0 0 0 0 0 0 0
39690 - 0 0 0 0 0 0 0 0 0 0 0 0
39691 - 0 0 0 0 0 0 0 0 0 0 0 0
39692 - 0 0 0 0 0 0 0 0 0 0 0 0
39693 - 0 0 0 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 - 6 6 6 6 6 6 10 10 10 10 10 10
39697 - 10 10 10 6 6 6 6 6 6 6 6 6
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 0 0 0 0 0 0 0 0 0 0
39702 - 0 0 0 0 0 0 0 0 0 0 0 0
39703 - 0 0 0 0 0 0 0 0 0 0 0 0
39704 - 0 0 0 0 0 0 0 0 0 0 0 0
39705 - 0 0 0 0 0 0 0 0 0 0 0 0
39706 - 0 0 0 0 0 0 0 0 0 0 0 0
39707 - 0 0 0 0 0 0 0 0 0 0 0 0
39708 - 0 0 0 0 0 0 0 0 0 0 0 0
39709 - 0 0 0 0 0 0 0 0 0 0 0 0
39710 - 0 0 0 0 0 0 0 0 0 0 0 0
39711 - 0 0 0 0 0 0 0 0 0 0 0 0
39712 - 0 0 0 0 0 0 0 0 0 0 0 0
39713 - 0 0 0 0 0 0 0 0 0 0 0 0
39714 - 0 0 0 0 0 0 0 0 0 0 0 0
39715 - 0 0 0 6 6 6 10 10 10 14 14 14
39716 - 22 22 22 26 26 26 30 30 30 34 34 34
39717 - 30 30 30 30 30 30 26 26 26 18 18 18
39718 - 14 14 14 10 10 10 6 6 6 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 0 0 0
39727 - 0 0 0 0 0 0 0 0 0 0 0 0
39728 - 0 0 0 0 0 1 0 0 1 0 0 0
39729 - 0 0 0 0 0 0 0 0 0 0 0 0
39730 - 0 0 0 0 0 0 0 0 0 0 0 0
39731 - 0 0 0 0 0 0 0 0 0 0 0 0
39732 - 0 0 0 0 0 0 0 0 0 0 0 0
39733 - 0 0 0 0 0 0 0 0 0 0 0 0
39734 - 0 0 0 0 0 0 0 0 0 0 0 0
39735 - 6 6 6 14 14 14 26 26 26 42 42 42
39736 - 54 54 54 66 66 66 78 78 78 78 78 78
39737 - 78 78 78 74 74 74 66 66 66 54 54 54
39738 - 42 42 42 26 26 26 18 18 18 10 10 10
39739 - 6 6 6 0 0 0 0 0 0 0 0 0
39740 - 0 0 0 0 0 0 0 0 0 0 0 0
39741 - 0 0 0 0 0 0 0 0 0 0 0 0
39742 - 0 0 0 0 0 0 0 0 0 0 0 0
39743 - 0 0 0 0 0 0 0 0 0 0 0 0
39744 - 0 0 0 0 0 0 0 0 0 0 0 0
39745 - 0 0 0 0 0 0 0 0 0 0 0 0
39746 - 0 0 0 0 0 0 0 0 0 0 0 0
39747 - 0 0 0 0 0 0 0 0 0 0 0 0
39748 - 0 0 1 0 0 0 0 0 0 0 0 0
39749 - 0 0 0 0 0 0 0 0 0 0 0 0
39750 - 0 0 0 0 0 0 0 0 0 0 0 0
39751 - 0 0 0 0 0 0 0 0 0 0 0 0
39752 - 0 0 0 0 0 0 0 0 0 0 0 0
39753 - 0 0 0 0 0 0 0 0 0 0 0 0
39754 - 0 0 0 0 0 0 0 0 0 10 10 10
39755 - 22 22 22 42 42 42 66 66 66 86 86 86
39756 - 66 66 66 38 38 38 38 38 38 22 22 22
39757 - 26 26 26 34 34 34 54 54 54 66 66 66
39758 - 86 86 86 70 70 70 46 46 46 26 26 26
39759 - 14 14 14 6 6 6 0 0 0 0 0 0
39760 - 0 0 0 0 0 0 0 0 0 0 0 0
39761 - 0 0 0 0 0 0 0 0 0 0 0 0
39762 - 0 0 0 0 0 0 0 0 0 0 0 0
39763 - 0 0 0 0 0 0 0 0 0 0 0 0
39764 - 0 0 0 0 0 0 0 0 0 0 0 0
39765 - 0 0 0 0 0 0 0 0 0 0 0 0
39766 - 0 0 0 0 0 0 0 0 0 0 0 0
39767 - 0 0 0 0 0 0 0 0 0 0 0 0
39768 - 0 0 1 0 0 1 0 0 1 0 0 0
39769 - 0 0 0 0 0 0 0 0 0 0 0 0
39770 - 0 0 0 0 0 0 0 0 0 0 0 0
39771 - 0 0 0 0 0 0 0 0 0 0 0 0
39772 - 0 0 0 0 0 0 0 0 0 0 0 0
39773 - 0 0 0 0 0 0 0 0 0 0 0 0
39774 - 0 0 0 0 0 0 10 10 10 26 26 26
39775 - 50 50 50 82 82 82 58 58 58 6 6 6
39776 - 2 2 6 2 2 6 2 2 6 2 2 6
39777 - 2 2 6 2 2 6 2 2 6 2 2 6
39778 - 6 6 6 54 54 54 86 86 86 66 66 66
39779 - 38 38 38 18 18 18 6 6 6 0 0 0
39780 - 0 0 0 0 0 0 0 0 0 0 0 0
39781 - 0 0 0 0 0 0 0 0 0 0 0 0
39782 - 0 0 0 0 0 0 0 0 0 0 0 0
39783 - 0 0 0 0 0 0 0 0 0 0 0 0
39784 - 0 0 0 0 0 0 0 0 0 0 0 0
39785 - 0 0 0 0 0 0 0 0 0 0 0 0
39786 - 0 0 0 0 0 0 0 0 0 0 0 0
39787 - 0 0 0 0 0 0 0 0 0 0 0 0
39788 - 0 0 0 0 0 0 0 0 0 0 0 0
39789 - 0 0 0 0 0 0 0 0 0 0 0 0
39790 - 0 0 0 0 0 0 0 0 0 0 0 0
39791 - 0 0 0 0 0 0 0 0 0 0 0 0
39792 - 0 0 0 0 0 0 0 0 0 0 0 0
39793 - 0 0 0 0 0 0 0 0 0 0 0 0
39794 - 0 0 0 6 6 6 22 22 22 50 50 50
39795 - 78 78 78 34 34 34 2 2 6 2 2 6
39796 - 2 2 6 2 2 6 2 2 6 2 2 6
39797 - 2 2 6 2 2 6 2 2 6 2 2 6
39798 - 2 2 6 2 2 6 6 6 6 70 70 70
39799 - 78 78 78 46 46 46 22 22 22 6 6 6
39800 - 0 0 0 0 0 0 0 0 0 0 0 0
39801 - 0 0 0 0 0 0 0 0 0 0 0 0
39802 - 0 0 0 0 0 0 0 0 0 0 0 0
39803 - 0 0 0 0 0 0 0 0 0 0 0 0
39804 - 0 0 0 0 0 0 0 0 0 0 0 0
39805 - 0 0 0 0 0 0 0 0 0 0 0 0
39806 - 0 0 0 0 0 0 0 0 0 0 0 0
39807 - 0 0 0 0 0 0 0 0 0 0 0 0
39808 - 0 0 1 0 0 1 0 0 1 0 0 0
39809 - 0 0 0 0 0 0 0 0 0 0 0 0
39810 - 0 0 0 0 0 0 0 0 0 0 0 0
39811 - 0 0 0 0 0 0 0 0 0 0 0 0
39812 - 0 0 0 0 0 0 0 0 0 0 0 0
39813 - 0 0 0 0 0 0 0 0 0 0 0 0
39814 - 6 6 6 18 18 18 42 42 42 82 82 82
39815 - 26 26 26 2 2 6 2 2 6 2 2 6
39816 - 2 2 6 2 2 6 2 2 6 2 2 6
39817 - 2 2 6 2 2 6 2 2 6 14 14 14
39818 - 46 46 46 34 34 34 6 6 6 2 2 6
39819 - 42 42 42 78 78 78 42 42 42 18 18 18
39820 - 6 6 6 0 0 0 0 0 0 0 0 0
39821 - 0 0 0 0 0 0 0 0 0 0 0 0
39822 - 0 0 0 0 0 0 0 0 0 0 0 0
39823 - 0 0 0 0 0 0 0 0 0 0 0 0
39824 - 0 0 0 0 0 0 0 0 0 0 0 0
39825 - 0 0 0 0 0 0 0 0 0 0 0 0
39826 - 0 0 0 0 0 0 0 0 0 0 0 0
39827 - 0 0 0 0 0 0 0 0 0 0 0 0
39828 - 0 0 1 0 0 0 0 0 1 0 0 0
39829 - 0 0 0 0 0 0 0 0 0 0 0 0
39830 - 0 0 0 0 0 0 0 0 0 0 0 0
39831 - 0 0 0 0 0 0 0 0 0 0 0 0
39832 - 0 0 0 0 0 0 0 0 0 0 0 0
39833 - 0 0 0 0 0 0 0 0 0 0 0 0
39834 - 10 10 10 30 30 30 66 66 66 58 58 58
39835 - 2 2 6 2 2 6 2 2 6 2 2 6
39836 - 2 2 6 2 2 6 2 2 6 2 2 6
39837 - 2 2 6 2 2 6 2 2 6 26 26 26
39838 - 86 86 86 101 101 101 46 46 46 10 10 10
39839 - 2 2 6 58 58 58 70 70 70 34 34 34
39840 - 10 10 10 0 0 0 0 0 0 0 0 0
39841 - 0 0 0 0 0 0 0 0 0 0 0 0
39842 - 0 0 0 0 0 0 0 0 0 0 0 0
39843 - 0 0 0 0 0 0 0 0 0 0 0 0
39844 - 0 0 0 0 0 0 0 0 0 0 0 0
39845 - 0 0 0 0 0 0 0 0 0 0 0 0
39846 - 0 0 0 0 0 0 0 0 0 0 0 0
39847 - 0 0 0 0 0 0 0 0 0 0 0 0
39848 - 0 0 1 0 0 1 0 0 1 0 0 0
39849 - 0 0 0 0 0 0 0 0 0 0 0 0
39850 - 0 0 0 0 0 0 0 0 0 0 0 0
39851 - 0 0 0 0 0 0 0 0 0 0 0 0
39852 - 0 0 0 0 0 0 0 0 0 0 0 0
39853 - 0 0 0 0 0 0 0 0 0 0 0 0
39854 - 14 14 14 42 42 42 86 86 86 10 10 10
39855 - 2 2 6 2 2 6 2 2 6 2 2 6
39856 - 2 2 6 2 2 6 2 2 6 2 2 6
39857 - 2 2 6 2 2 6 2 2 6 30 30 30
39858 - 94 94 94 94 94 94 58 58 58 26 26 26
39859 - 2 2 6 6 6 6 78 78 78 54 54 54
39860 - 22 22 22 6 6 6 0 0 0 0 0 0
39861 - 0 0 0 0 0 0 0 0 0 0 0 0
39862 - 0 0 0 0 0 0 0 0 0 0 0 0
39863 - 0 0 0 0 0 0 0 0 0 0 0 0
39864 - 0 0 0 0 0 0 0 0 0 0 0 0
39865 - 0 0 0 0 0 0 0 0 0 0 0 0
39866 - 0 0 0 0 0 0 0 0 0 0 0 0
39867 - 0 0 0 0 0 0 0 0 0 0 0 0
39868 - 0 0 0 0 0 0 0 0 0 0 0 0
39869 - 0 0 0 0 0 0 0 0 0 0 0 0
39870 - 0 0 0 0 0 0 0 0 0 0 0 0
39871 - 0 0 0 0 0 0 0 0 0 0 0 0
39872 - 0 0 0 0 0 0 0 0 0 0 0 0
39873 - 0 0 0 0 0 0 0 0 0 6 6 6
39874 - 22 22 22 62 62 62 62 62 62 2 2 6
39875 - 2 2 6 2 2 6 2 2 6 2 2 6
39876 - 2 2 6 2 2 6 2 2 6 2 2 6
39877 - 2 2 6 2 2 6 2 2 6 26 26 26
39878 - 54 54 54 38 38 38 18 18 18 10 10 10
39879 - 2 2 6 2 2 6 34 34 34 82 82 82
39880 - 38 38 38 14 14 14 0 0 0 0 0 0
39881 - 0 0 0 0 0 0 0 0 0 0 0 0
39882 - 0 0 0 0 0 0 0 0 0 0 0 0
39883 - 0 0 0 0 0 0 0 0 0 0 0 0
39884 - 0 0 0 0 0 0 0 0 0 0 0 0
39885 - 0 0 0 0 0 0 0 0 0 0 0 0
39886 - 0 0 0 0 0 0 0 0 0 0 0 0
39887 - 0 0 0 0 0 0 0 0 0 0 0 0
39888 - 0 0 0 0 0 1 0 0 1 0 0 0
39889 - 0 0 0 0 0 0 0 0 0 0 0 0
39890 - 0 0 0 0 0 0 0 0 0 0 0 0
39891 - 0 0 0 0 0 0 0 0 0 0 0 0
39892 - 0 0 0 0 0 0 0 0 0 0 0 0
39893 - 0 0 0 0 0 0 0 0 0 6 6 6
39894 - 30 30 30 78 78 78 30 30 30 2 2 6
39895 - 2 2 6 2 2 6 2 2 6 2 2 6
39896 - 2 2 6 2 2 6 2 2 6 2 2 6
39897 - 2 2 6 2 2 6 2 2 6 10 10 10
39898 - 10 10 10 2 2 6 2 2 6 2 2 6
39899 - 2 2 6 2 2 6 2 2 6 78 78 78
39900 - 50 50 50 18 18 18 6 6 6 0 0 0
39901 - 0 0 0 0 0 0 0 0 0 0 0 0
39902 - 0 0 0 0 0 0 0 0 0 0 0 0
39903 - 0 0 0 0 0 0 0 0 0 0 0 0
39904 - 0 0 0 0 0 0 0 0 0 0 0 0
39905 - 0 0 0 0 0 0 0 0 0 0 0 0
39906 - 0 0 0 0 0 0 0 0 0 0 0 0
39907 - 0 0 0 0 0 0 0 0 0 0 0 0
39908 - 0 0 1 0 0 0 0 0 0 0 0 0
39909 - 0 0 0 0 0 0 0 0 0 0 0 0
39910 - 0 0 0 0 0 0 0 0 0 0 0 0
39911 - 0 0 0 0 0 0 0 0 0 0 0 0
39912 - 0 0 0 0 0 0 0 0 0 0 0 0
39913 - 0 0 0 0 0 0 0 0 0 10 10 10
39914 - 38 38 38 86 86 86 14 14 14 2 2 6
39915 - 2 2 6 2 2 6 2 2 6 2 2 6
39916 - 2 2 6 2 2 6 2 2 6 2 2 6
39917 - 2 2 6 2 2 6 2 2 6 2 2 6
39918 - 2 2 6 2 2 6 2 2 6 2 2 6
39919 - 2 2 6 2 2 6 2 2 6 54 54 54
39920 - 66 66 66 26 26 26 6 6 6 0 0 0
39921 - 0 0 0 0 0 0 0 0 0 0 0 0
39922 - 0 0 0 0 0 0 0 0 0 0 0 0
39923 - 0 0 0 0 0 0 0 0 0 0 0 0
39924 - 0 0 0 0 0 0 0 0 0 0 0 0
39925 - 0 0 0 0 0 0 0 0 0 0 0 0
39926 - 0 0 0 0 0 0 0 0 0 0 0 0
39927 - 0 0 0 0 0 0 0 0 0 0 0 0
39928 - 0 0 0 0 0 1 0 0 1 0 0 0
39929 - 0 0 0 0 0 0 0 0 0 0 0 0
39930 - 0 0 0 0 0 0 0 0 0 0 0 0
39931 - 0 0 0 0 0 0 0 0 0 0 0 0
39932 - 0 0 0 0 0 0 0 0 0 0 0 0
39933 - 0 0 0 0 0 0 0 0 0 14 14 14
39934 - 42 42 42 82 82 82 2 2 6 2 2 6
39935 - 2 2 6 6 6 6 10 10 10 2 2 6
39936 - 2 2 6 2 2 6 2 2 6 2 2 6
39937 - 2 2 6 2 2 6 2 2 6 6 6 6
39938 - 14 14 14 10 10 10 2 2 6 2 2 6
39939 - 2 2 6 2 2 6 2 2 6 18 18 18
39940 - 82 82 82 34 34 34 10 10 10 0 0 0
39941 - 0 0 0 0 0 0 0 0 0 0 0 0
39942 - 0 0 0 0 0 0 0 0 0 0 0 0
39943 - 0 0 0 0 0 0 0 0 0 0 0 0
39944 - 0 0 0 0 0 0 0 0 0 0 0 0
39945 - 0 0 0 0 0 0 0 0 0 0 0 0
39946 - 0 0 0 0 0 0 0 0 0 0 0 0
39947 - 0 0 0 0 0 0 0 0 0 0 0 0
39948 - 0 0 1 0 0 0 0 0 0 0 0 0
39949 - 0 0 0 0 0 0 0 0 0 0 0 0
39950 - 0 0 0 0 0 0 0 0 0 0 0 0
39951 - 0 0 0 0 0 0 0 0 0 0 0 0
39952 - 0 0 0 0 0 0 0 0 0 0 0 0
39953 - 0 0 0 0 0 0 0 0 0 14 14 14
39954 - 46 46 46 86 86 86 2 2 6 2 2 6
39955 - 6 6 6 6 6 6 22 22 22 34 34 34
39956 - 6 6 6 2 2 6 2 2 6 2 2 6
39957 - 2 2 6 2 2 6 18 18 18 34 34 34
39958 - 10 10 10 50 50 50 22 22 22 2 2 6
39959 - 2 2 6 2 2 6 2 2 6 10 10 10
39960 - 86 86 86 42 42 42 14 14 14 0 0 0
39961 - 0 0 0 0 0 0 0 0 0 0 0 0
39962 - 0 0 0 0 0 0 0 0 0 0 0 0
39963 - 0 0 0 0 0 0 0 0 0 0 0 0
39964 - 0 0 0 0 0 0 0 0 0 0 0 0
39965 - 0 0 0 0 0 0 0 0 0 0 0 0
39966 - 0 0 0 0 0 0 0 0 0 0 0 0
39967 - 0 0 0 0 0 0 0 0 0 0 0 0
39968 - 0 0 1 0 0 1 0 0 1 0 0 0
39969 - 0 0 0 0 0 0 0 0 0 0 0 0
39970 - 0 0 0 0 0 0 0 0 0 0 0 0
39971 - 0 0 0 0 0 0 0 0 0 0 0 0
39972 - 0 0 0 0 0 0 0 0 0 0 0 0
39973 - 0 0 0 0 0 0 0 0 0 14 14 14
39974 - 46 46 46 86 86 86 2 2 6 2 2 6
39975 - 38 38 38 116 116 116 94 94 94 22 22 22
39976 - 22 22 22 2 2 6 2 2 6 2 2 6
39977 - 14 14 14 86 86 86 138 138 138 162 162 162
39978 -154 154 154 38 38 38 26 26 26 6 6 6
39979 - 2 2 6 2 2 6 2 2 6 2 2 6
39980 - 86 86 86 46 46 46 14 14 14 0 0 0
39981 - 0 0 0 0 0 0 0 0 0 0 0 0
39982 - 0 0 0 0 0 0 0 0 0 0 0 0
39983 - 0 0 0 0 0 0 0 0 0 0 0 0
39984 - 0 0 0 0 0 0 0 0 0 0 0 0
39985 - 0 0 0 0 0 0 0 0 0 0 0 0
39986 - 0 0 0 0 0 0 0 0 0 0 0 0
39987 - 0 0 0 0 0 0 0 0 0 0 0 0
39988 - 0 0 0 0 0 0 0 0 0 0 0 0
39989 - 0 0 0 0 0 0 0 0 0 0 0 0
39990 - 0 0 0 0 0 0 0 0 0 0 0 0
39991 - 0 0 0 0 0 0 0 0 0 0 0 0
39992 - 0 0 0 0 0 0 0 0 0 0 0 0
39993 - 0 0 0 0 0 0 0 0 0 14 14 14
39994 - 46 46 46 86 86 86 2 2 6 14 14 14
39995 -134 134 134 198 198 198 195 195 195 116 116 116
39996 - 10 10 10 2 2 6 2 2 6 6 6 6
39997 -101 98 89 187 187 187 210 210 210 218 218 218
39998 -214 214 214 134 134 134 14 14 14 6 6 6
39999 - 2 2 6 2 2 6 2 2 6 2 2 6
40000 - 86 86 86 50 50 50 18 18 18 6 6 6
40001 - 0 0 0 0 0 0 0 0 0 0 0 0
40002 - 0 0 0 0 0 0 0 0 0 0 0 0
40003 - 0 0 0 0 0 0 0 0 0 0 0 0
40004 - 0 0 0 0 0 0 0 0 0 0 0 0
40005 - 0 0 0 0 0 0 0 0 0 0 0 0
40006 - 0 0 0 0 0 0 0 0 0 0 0 0
40007 - 0 0 0 0 0 0 0 0 1 0 0 0
40008 - 0 0 1 0 0 1 0 0 1 0 0 0
40009 - 0 0 0 0 0 0 0 0 0 0 0 0
40010 - 0 0 0 0 0 0 0 0 0 0 0 0
40011 - 0 0 0 0 0 0 0 0 0 0 0 0
40012 - 0 0 0 0 0 0 0 0 0 0 0 0
40013 - 0 0 0 0 0 0 0 0 0 14 14 14
40014 - 46 46 46 86 86 86 2 2 6 54 54 54
40015 -218 218 218 195 195 195 226 226 226 246 246 246
40016 - 58 58 58 2 2 6 2 2 6 30 30 30
40017 -210 210 210 253 253 253 174 174 174 123 123 123
40018 -221 221 221 234 234 234 74 74 74 2 2 6
40019 - 2 2 6 2 2 6 2 2 6 2 2 6
40020 - 70 70 70 58 58 58 22 22 22 6 6 6
40021 - 0 0 0 0 0 0 0 0 0 0 0 0
40022 - 0 0 0 0 0 0 0 0 0 0 0 0
40023 - 0 0 0 0 0 0 0 0 0 0 0 0
40024 - 0 0 0 0 0 0 0 0 0 0 0 0
40025 - 0 0 0 0 0 0 0 0 0 0 0 0
40026 - 0 0 0 0 0 0 0 0 0 0 0 0
40027 - 0 0 0 0 0 0 0 0 0 0 0 0
40028 - 0 0 0 0 0 0 0 0 0 0 0 0
40029 - 0 0 0 0 0 0 0 0 0 0 0 0
40030 - 0 0 0 0 0 0 0 0 0 0 0 0
40031 - 0 0 0 0 0 0 0 0 0 0 0 0
40032 - 0 0 0 0 0 0 0 0 0 0 0 0
40033 - 0 0 0 0 0 0 0 0 0 14 14 14
40034 - 46 46 46 82 82 82 2 2 6 106 106 106
40035 -170 170 170 26 26 26 86 86 86 226 226 226
40036 -123 123 123 10 10 10 14 14 14 46 46 46
40037 -231 231 231 190 190 190 6 6 6 70 70 70
40038 - 90 90 90 238 238 238 158 158 158 2 2 6
40039 - 2 2 6 2 2 6 2 2 6 2 2 6
40040 - 70 70 70 58 58 58 22 22 22 6 6 6
40041 - 0 0 0 0 0 0 0 0 0 0 0 0
40042 - 0 0 0 0 0 0 0 0 0 0 0 0
40043 - 0 0 0 0 0 0 0 0 0 0 0 0
40044 - 0 0 0 0 0 0 0 0 0 0 0 0
40045 - 0 0 0 0 0 0 0 0 0 0 0 0
40046 - 0 0 0 0 0 0 0 0 0 0 0 0
40047 - 0 0 0 0 0 0 0 0 1 0 0 0
40048 - 0 0 1 0 0 1 0 0 1 0 0 0
40049 - 0 0 0 0 0 0 0 0 0 0 0 0
40050 - 0 0 0 0 0 0 0 0 0 0 0 0
40051 - 0 0 0 0 0 0 0 0 0 0 0 0
40052 - 0 0 0 0 0 0 0 0 0 0 0 0
40053 - 0 0 0 0 0 0 0 0 0 14 14 14
40054 - 42 42 42 86 86 86 6 6 6 116 116 116
40055 -106 106 106 6 6 6 70 70 70 149 149 149
40056 -128 128 128 18 18 18 38 38 38 54 54 54
40057 -221 221 221 106 106 106 2 2 6 14 14 14
40058 - 46 46 46 190 190 190 198 198 198 2 2 6
40059 - 2 2 6 2 2 6 2 2 6 2 2 6
40060 - 74 74 74 62 62 62 22 22 22 6 6 6
40061 - 0 0 0 0 0 0 0 0 0 0 0 0
40062 - 0 0 0 0 0 0 0 0 0 0 0 0
40063 - 0 0 0 0 0 0 0 0 0 0 0 0
40064 - 0 0 0 0 0 0 0 0 0 0 0 0
40065 - 0 0 0 0 0 0 0 0 0 0 0 0
40066 - 0 0 0 0 0 0 0 0 0 0 0 0
40067 - 0 0 0 0 0 0 0 0 1 0 0 0
40068 - 0 0 1 0 0 0 0 0 1 0 0 0
40069 - 0 0 0 0 0 0 0 0 0 0 0 0
40070 - 0 0 0 0 0 0 0 0 0 0 0 0
40071 - 0 0 0 0 0 0 0 0 0 0 0 0
40072 - 0 0 0 0 0 0 0 0 0 0 0 0
40073 - 0 0 0 0 0 0 0 0 0 14 14 14
40074 - 42 42 42 94 94 94 14 14 14 101 101 101
40075 -128 128 128 2 2 6 18 18 18 116 116 116
40076 -118 98 46 121 92 8 121 92 8 98 78 10
40077 -162 162 162 106 106 106 2 2 6 2 2 6
40078 - 2 2 6 195 195 195 195 195 195 6 6 6
40079 - 2 2 6 2 2 6 2 2 6 2 2 6
40080 - 74 74 74 62 62 62 22 22 22 6 6 6
40081 - 0 0 0 0 0 0 0 0 0 0 0 0
40082 - 0 0 0 0 0 0 0 0 0 0 0 0
40083 - 0 0 0 0 0 0 0 0 0 0 0 0
40084 - 0 0 0 0 0 0 0 0 0 0 0 0
40085 - 0 0 0 0 0 0 0 0 0 0 0 0
40086 - 0 0 0 0 0 0 0 0 0 0 0 0
40087 - 0 0 0 0 0 0 0 0 1 0 0 1
40088 - 0 0 1 0 0 0 0 0 1 0 0 0
40089 - 0 0 0 0 0 0 0 0 0 0 0 0
40090 - 0 0 0 0 0 0 0 0 0 0 0 0
40091 - 0 0 0 0 0 0 0 0 0 0 0 0
40092 - 0 0 0 0 0 0 0 0 0 0 0 0
40093 - 0 0 0 0 0 0 0 0 0 10 10 10
40094 - 38 38 38 90 90 90 14 14 14 58 58 58
40095 -210 210 210 26 26 26 54 38 6 154 114 10
40096 -226 170 11 236 186 11 225 175 15 184 144 12
40097 -215 174 15 175 146 61 37 26 9 2 2 6
40098 - 70 70 70 246 246 246 138 138 138 2 2 6
40099 - 2 2 6 2 2 6 2 2 6 2 2 6
40100 - 70 70 70 66 66 66 26 26 26 6 6 6
40101 - 0 0 0 0 0 0 0 0 0 0 0 0
40102 - 0 0 0 0 0 0 0 0 0 0 0 0
40103 - 0 0 0 0 0 0 0 0 0 0 0 0
40104 - 0 0 0 0 0 0 0 0 0 0 0 0
40105 - 0 0 0 0 0 0 0 0 0 0 0 0
40106 - 0 0 0 0 0 0 0 0 0 0 0 0
40107 - 0 0 0 0 0 0 0 0 0 0 0 0
40108 - 0 0 0 0 0 0 0 0 0 0 0 0
40109 - 0 0 0 0 0 0 0 0 0 0 0 0
40110 - 0 0 0 0 0 0 0 0 0 0 0 0
40111 - 0 0 0 0 0 0 0 0 0 0 0 0
40112 - 0 0 0 0 0 0 0 0 0 0 0 0
40113 - 0 0 0 0 0 0 0 0 0 10 10 10
40114 - 38 38 38 86 86 86 14 14 14 10 10 10
40115 -195 195 195 188 164 115 192 133 9 225 175 15
40116 -239 182 13 234 190 10 232 195 16 232 200 30
40117 -245 207 45 241 208 19 232 195 16 184 144 12
40118 -218 194 134 211 206 186 42 42 42 2 2 6
40119 - 2 2 6 2 2 6 2 2 6 2 2 6
40120 - 50 50 50 74 74 74 30 30 30 6 6 6
40121 - 0 0 0 0 0 0 0 0 0 0 0 0
40122 - 0 0 0 0 0 0 0 0 0 0 0 0
40123 - 0 0 0 0 0 0 0 0 0 0 0 0
40124 - 0 0 0 0 0 0 0 0 0 0 0 0
40125 - 0 0 0 0 0 0 0 0 0 0 0 0
40126 - 0 0 0 0 0 0 0 0 0 0 0 0
40127 - 0 0 0 0 0 0 0 0 0 0 0 0
40128 - 0 0 0 0 0 0 0 0 0 0 0 0
40129 - 0 0 0 0 0 0 0 0 0 0 0 0
40130 - 0 0 0 0 0 0 0 0 0 0 0 0
40131 - 0 0 0 0 0 0 0 0 0 0 0 0
40132 - 0 0 0 0 0 0 0 0 0 0 0 0
40133 - 0 0 0 0 0 0 0 0 0 10 10 10
40134 - 34 34 34 86 86 86 14 14 14 2 2 6
40135 -121 87 25 192 133 9 219 162 10 239 182 13
40136 -236 186 11 232 195 16 241 208 19 244 214 54
40137 -246 218 60 246 218 38 246 215 20 241 208 19
40138 -241 208 19 226 184 13 121 87 25 2 2 6
40139 - 2 2 6 2 2 6 2 2 6 2 2 6
40140 - 50 50 50 82 82 82 34 34 34 10 10 10
40141 - 0 0 0 0 0 0 0 0 0 0 0 0
40142 - 0 0 0 0 0 0 0 0 0 0 0 0
40143 - 0 0 0 0 0 0 0 0 0 0 0 0
40144 - 0 0 0 0 0 0 0 0 0 0 0 0
40145 - 0 0 0 0 0 0 0 0 0 0 0 0
40146 - 0 0 0 0 0 0 0 0 0 0 0 0
40147 - 0 0 0 0 0 0 0 0 0 0 0 0
40148 - 0 0 0 0 0 0 0 0 0 0 0 0
40149 - 0 0 0 0 0 0 0 0 0 0 0 0
40150 - 0 0 0 0 0 0 0 0 0 0 0 0
40151 - 0 0 0 0 0 0 0 0 0 0 0 0
40152 - 0 0 0 0 0 0 0 0 0 0 0 0
40153 - 0 0 0 0 0 0 0 0 0 10 10 10
40154 - 34 34 34 82 82 82 30 30 30 61 42 6
40155 -180 123 7 206 145 10 230 174 11 239 182 13
40156 -234 190 10 238 202 15 241 208 19 246 218 74
40157 -246 218 38 246 215 20 246 215 20 246 215 20
40158 -226 184 13 215 174 15 184 144 12 6 6 6
40159 - 2 2 6 2 2 6 2 2 6 2 2 6
40160 - 26 26 26 94 94 94 42 42 42 14 14 14
40161 - 0 0 0 0 0 0 0 0 0 0 0 0
40162 - 0 0 0 0 0 0 0 0 0 0 0 0
40163 - 0 0 0 0 0 0 0 0 0 0 0 0
40164 - 0 0 0 0 0 0 0 0 0 0 0 0
40165 - 0 0 0 0 0 0 0 0 0 0 0 0
40166 - 0 0 0 0 0 0 0 0 0 0 0 0
40167 - 0 0 0 0 0 0 0 0 0 0 0 0
40168 - 0 0 0 0 0 0 0 0 0 0 0 0
40169 - 0 0 0 0 0 0 0 0 0 0 0 0
40170 - 0 0 0 0 0 0 0 0 0 0 0 0
40171 - 0 0 0 0 0 0 0 0 0 0 0 0
40172 - 0 0 0 0 0 0 0 0 0 0 0 0
40173 - 0 0 0 0 0 0 0 0 0 10 10 10
40174 - 30 30 30 78 78 78 50 50 50 104 69 6
40175 -192 133 9 216 158 10 236 178 12 236 186 11
40176 -232 195 16 241 208 19 244 214 54 245 215 43
40177 -246 215 20 246 215 20 241 208 19 198 155 10
40178 -200 144 11 216 158 10 156 118 10 2 2 6
40179 - 2 2 6 2 2 6 2 2 6 2 2 6
40180 - 6 6 6 90 90 90 54 54 54 18 18 18
40181 - 6 6 6 0 0 0 0 0 0 0 0 0
40182 - 0 0 0 0 0 0 0 0 0 0 0 0
40183 - 0 0 0 0 0 0 0 0 0 0 0 0
40184 - 0 0 0 0 0 0 0 0 0 0 0 0
40185 - 0 0 0 0 0 0 0 0 0 0 0 0
40186 - 0 0 0 0 0 0 0 0 0 0 0 0
40187 - 0 0 0 0 0 0 0 0 0 0 0 0
40188 - 0 0 0 0 0 0 0 0 0 0 0 0
40189 - 0 0 0 0 0 0 0 0 0 0 0 0
40190 - 0 0 0 0 0 0 0 0 0 0 0 0
40191 - 0 0 0 0 0 0 0 0 0 0 0 0
40192 - 0 0 0 0 0 0 0 0 0 0 0 0
40193 - 0 0 0 0 0 0 0 0 0 10 10 10
40194 - 30 30 30 78 78 78 46 46 46 22 22 22
40195 -137 92 6 210 162 10 239 182 13 238 190 10
40196 -238 202 15 241 208 19 246 215 20 246 215 20
40197 -241 208 19 203 166 17 185 133 11 210 150 10
40198 -216 158 10 210 150 10 102 78 10 2 2 6
40199 - 6 6 6 54 54 54 14 14 14 2 2 6
40200 - 2 2 6 62 62 62 74 74 74 30 30 30
40201 - 10 10 10 0 0 0 0 0 0 0 0 0
40202 - 0 0 0 0 0 0 0 0 0 0 0 0
40203 - 0 0 0 0 0 0 0 0 0 0 0 0
40204 - 0 0 0 0 0 0 0 0 0 0 0 0
40205 - 0 0 0 0 0 0 0 0 0 0 0 0
40206 - 0 0 0 0 0 0 0 0 0 0 0 0
40207 - 0 0 0 0 0 0 0 0 0 0 0 0
40208 - 0 0 0 0 0 0 0 0 0 0 0 0
40209 - 0 0 0 0 0 0 0 0 0 0 0 0
40210 - 0 0 0 0 0 0 0 0 0 0 0 0
40211 - 0 0 0 0 0 0 0 0 0 0 0 0
40212 - 0 0 0 0 0 0 0 0 0 0 0 0
40213 - 0 0 0 0 0 0 0 0 0 10 10 10
40214 - 34 34 34 78 78 78 50 50 50 6 6 6
40215 - 94 70 30 139 102 15 190 146 13 226 184 13
40216 -232 200 30 232 195 16 215 174 15 190 146 13
40217 -168 122 10 192 133 9 210 150 10 213 154 11
40218 -202 150 34 182 157 106 101 98 89 2 2 6
40219 - 2 2 6 78 78 78 116 116 116 58 58 58
40220 - 2 2 6 22 22 22 90 90 90 46 46 46
40221 - 18 18 18 6 6 6 0 0 0 0 0 0
40222 - 0 0 0 0 0 0 0 0 0 0 0 0
40223 - 0 0 0 0 0 0 0 0 0 0 0 0
40224 - 0 0 0 0 0 0 0 0 0 0 0 0
40225 - 0 0 0 0 0 0 0 0 0 0 0 0
40226 - 0 0 0 0 0 0 0 0 0 0 0 0
40227 - 0 0 0 0 0 0 0 0 0 0 0 0
40228 - 0 0 0 0 0 0 0 0 0 0 0 0
40229 - 0 0 0 0 0 0 0 0 0 0 0 0
40230 - 0 0 0 0 0 0 0 0 0 0 0 0
40231 - 0 0 0 0 0 0 0 0 0 0 0 0
40232 - 0 0 0 0 0 0 0 0 0 0 0 0
40233 - 0 0 0 0 0 0 0 0 0 10 10 10
40234 - 38 38 38 86 86 86 50 50 50 6 6 6
40235 -128 128 128 174 154 114 156 107 11 168 122 10
40236 -198 155 10 184 144 12 197 138 11 200 144 11
40237 -206 145 10 206 145 10 197 138 11 188 164 115
40238 -195 195 195 198 198 198 174 174 174 14 14 14
40239 - 2 2 6 22 22 22 116 116 116 116 116 116
40240 - 22 22 22 2 2 6 74 74 74 70 70 70
40241 - 30 30 30 10 10 10 0 0 0 0 0 0
40242 - 0 0 0 0 0 0 0 0 0 0 0 0
40243 - 0 0 0 0 0 0 0 0 0 0 0 0
40244 - 0 0 0 0 0 0 0 0 0 0 0 0
40245 - 0 0 0 0 0 0 0 0 0 0 0 0
40246 - 0 0 0 0 0 0 0 0 0 0 0 0
40247 - 0 0 0 0 0 0 0 0 0 0 0 0
40248 - 0 0 0 0 0 0 0 0 0 0 0 0
40249 - 0 0 0 0 0 0 0 0 0 0 0 0
40250 - 0 0 0 0 0 0 0 0 0 0 0 0
40251 - 0 0 0 0 0 0 0 0 0 0 0 0
40252 - 0 0 0 0 0 0 0 0 0 0 0 0
40253 - 0 0 0 0 0 0 6 6 6 18 18 18
40254 - 50 50 50 101 101 101 26 26 26 10 10 10
40255 -138 138 138 190 190 190 174 154 114 156 107 11
40256 -197 138 11 200 144 11 197 138 11 192 133 9
40257 -180 123 7 190 142 34 190 178 144 187 187 187
40258 -202 202 202 221 221 221 214 214 214 66 66 66
40259 - 2 2 6 2 2 6 50 50 50 62 62 62
40260 - 6 6 6 2 2 6 10 10 10 90 90 90
40261 - 50 50 50 18 18 18 6 6 6 0 0 0
40262 - 0 0 0 0 0 0 0 0 0 0 0 0
40263 - 0 0 0 0 0 0 0 0 0 0 0 0
40264 - 0 0 0 0 0 0 0 0 0 0 0 0
40265 - 0 0 0 0 0 0 0 0 0 0 0 0
40266 - 0 0 0 0 0 0 0 0 0 0 0 0
40267 - 0 0 0 0 0 0 0 0 0 0 0 0
40268 - 0 0 0 0 0 0 0 0 0 0 0 0
40269 - 0 0 0 0 0 0 0 0 0 0 0 0
40270 - 0 0 0 0 0 0 0 0 0 0 0 0
40271 - 0 0 0 0 0 0 0 0 0 0 0 0
40272 - 0 0 0 0 0 0 0 0 0 0 0 0
40273 - 0 0 0 0 0 0 10 10 10 34 34 34
40274 - 74 74 74 74 74 74 2 2 6 6 6 6
40275 -144 144 144 198 198 198 190 190 190 178 166 146
40276 -154 121 60 156 107 11 156 107 11 168 124 44
40277 -174 154 114 187 187 187 190 190 190 210 210 210
40278 -246 246 246 253 253 253 253 253 253 182 182 182
40279 - 6 6 6 2 2 6 2 2 6 2 2 6
40280 - 2 2 6 2 2 6 2 2 6 62 62 62
40281 - 74 74 74 34 34 34 14 14 14 0 0 0
40282 - 0 0 0 0 0 0 0 0 0 0 0 0
40283 - 0 0 0 0 0 0 0 0 0 0 0 0
40284 - 0 0 0 0 0 0 0 0 0 0 0 0
40285 - 0 0 0 0 0 0 0 0 0 0 0 0
40286 - 0 0 0 0 0 0 0 0 0 0 0 0
40287 - 0 0 0 0 0 0 0 0 0 0 0 0
40288 - 0 0 0 0 0 0 0 0 0 0 0 0
40289 - 0 0 0 0 0 0 0 0 0 0 0 0
40290 - 0 0 0 0 0 0 0 0 0 0 0 0
40291 - 0 0 0 0 0 0 0 0 0 0 0 0
40292 - 0 0 0 0 0 0 0 0 0 0 0 0
40293 - 0 0 0 10 10 10 22 22 22 54 54 54
40294 - 94 94 94 18 18 18 2 2 6 46 46 46
40295 -234 234 234 221 221 221 190 190 190 190 190 190
40296 -190 190 190 187 187 187 187 187 187 190 190 190
40297 -190 190 190 195 195 195 214 214 214 242 242 242
40298 -253 253 253 253 253 253 253 253 253 253 253 253
40299 - 82 82 82 2 2 6 2 2 6 2 2 6
40300 - 2 2 6 2 2 6 2 2 6 14 14 14
40301 - 86 86 86 54 54 54 22 22 22 6 6 6
40302 - 0 0 0 0 0 0 0 0 0 0 0 0
40303 - 0 0 0 0 0 0 0 0 0 0 0 0
40304 - 0 0 0 0 0 0 0 0 0 0 0 0
40305 - 0 0 0 0 0 0 0 0 0 0 0 0
40306 - 0 0 0 0 0 0 0 0 0 0 0 0
40307 - 0 0 0 0 0 0 0 0 0 0 0 0
40308 - 0 0 0 0 0 0 0 0 0 0 0 0
40309 - 0 0 0 0 0 0 0 0 0 0 0 0
40310 - 0 0 0 0 0 0 0 0 0 0 0 0
40311 - 0 0 0 0 0 0 0 0 0 0 0 0
40312 - 0 0 0 0 0 0 0 0 0 0 0 0
40313 - 6 6 6 18 18 18 46 46 46 90 90 90
40314 - 46 46 46 18 18 18 6 6 6 182 182 182
40315 -253 253 253 246 246 246 206 206 206 190 190 190
40316 -190 190 190 190 190 190 190 190 190 190 190 190
40317 -206 206 206 231 231 231 250 250 250 253 253 253
40318 -253 253 253 253 253 253 253 253 253 253 253 253
40319 -202 202 202 14 14 14 2 2 6 2 2 6
40320 - 2 2 6 2 2 6 2 2 6 2 2 6
40321 - 42 42 42 86 86 86 42 42 42 18 18 18
40322 - 6 6 6 0 0 0 0 0 0 0 0 0
40323 - 0 0 0 0 0 0 0 0 0 0 0 0
40324 - 0 0 0 0 0 0 0 0 0 0 0 0
40325 - 0 0 0 0 0 0 0 0 0 0 0 0
40326 - 0 0 0 0 0 0 0 0 0 0 0 0
40327 - 0 0 0 0 0 0 0 0 0 0 0 0
40328 - 0 0 0 0 0 0 0 0 0 0 0 0
40329 - 0 0 0 0 0 0 0 0 0 0 0 0
40330 - 0 0 0 0 0 0 0 0 0 0 0 0
40331 - 0 0 0 0 0 0 0 0 0 0 0 0
40332 - 0 0 0 0 0 0 0 0 0 6 6 6
40333 - 14 14 14 38 38 38 74 74 74 66 66 66
40334 - 2 2 6 6 6 6 90 90 90 250 250 250
40335 -253 253 253 253 253 253 238 238 238 198 198 198
40336 -190 190 190 190 190 190 195 195 195 221 221 221
40337 -246 246 246 253 253 253 253 253 253 253 253 253
40338 -253 253 253 253 253 253 253 253 253 253 253 253
40339 -253 253 253 82 82 82 2 2 6 2 2 6
40340 - 2 2 6 2 2 6 2 2 6 2 2 6
40341 - 2 2 6 78 78 78 70 70 70 34 34 34
40342 - 14 14 14 6 6 6 0 0 0 0 0 0
40343 - 0 0 0 0 0 0 0 0 0 0 0 0
40344 - 0 0 0 0 0 0 0 0 0 0 0 0
40345 - 0 0 0 0 0 0 0 0 0 0 0 0
40346 - 0 0 0 0 0 0 0 0 0 0 0 0
40347 - 0 0 0 0 0 0 0 0 0 0 0 0
40348 - 0 0 0 0 0 0 0 0 0 0 0 0
40349 - 0 0 0 0 0 0 0 0 0 0 0 0
40350 - 0 0 0 0 0 0 0 0 0 0 0 0
40351 - 0 0 0 0 0 0 0 0 0 0 0 0
40352 - 0 0 0 0 0 0 0 0 0 14 14 14
40353 - 34 34 34 66 66 66 78 78 78 6 6 6
40354 - 2 2 6 18 18 18 218 218 218 253 253 253
40355 -253 253 253 253 253 253 253 253 253 246 246 246
40356 -226 226 226 231 231 231 246 246 246 253 253 253
40357 -253 253 253 253 253 253 253 253 253 253 253 253
40358 -253 253 253 253 253 253 253 253 253 253 253 253
40359 -253 253 253 178 178 178 2 2 6 2 2 6
40360 - 2 2 6 2 2 6 2 2 6 2 2 6
40361 - 2 2 6 18 18 18 90 90 90 62 62 62
40362 - 30 30 30 10 10 10 0 0 0 0 0 0
40363 - 0 0 0 0 0 0 0 0 0 0 0 0
40364 - 0 0 0 0 0 0 0 0 0 0 0 0
40365 - 0 0 0 0 0 0 0 0 0 0 0 0
40366 - 0 0 0 0 0 0 0 0 0 0 0 0
40367 - 0 0 0 0 0 0 0 0 0 0 0 0
40368 - 0 0 0 0 0 0 0 0 0 0 0 0
40369 - 0 0 0 0 0 0 0 0 0 0 0 0
40370 - 0 0 0 0 0 0 0 0 0 0 0 0
40371 - 0 0 0 0 0 0 0 0 0 0 0 0
40372 - 0 0 0 0 0 0 10 10 10 26 26 26
40373 - 58 58 58 90 90 90 18 18 18 2 2 6
40374 - 2 2 6 110 110 110 253 253 253 253 253 253
40375 -253 253 253 253 253 253 253 253 253 253 253 253
40376 -250 250 250 253 253 253 253 253 253 253 253 253
40377 -253 253 253 253 253 253 253 253 253 253 253 253
40378 -253 253 253 253 253 253 253 253 253 253 253 253
40379 -253 253 253 231 231 231 18 18 18 2 2 6
40380 - 2 2 6 2 2 6 2 2 6 2 2 6
40381 - 2 2 6 2 2 6 18 18 18 94 94 94
40382 - 54 54 54 26 26 26 10 10 10 0 0 0
40383 - 0 0 0 0 0 0 0 0 0 0 0 0
40384 - 0 0 0 0 0 0 0 0 0 0 0 0
40385 - 0 0 0 0 0 0 0 0 0 0 0 0
40386 - 0 0 0 0 0 0 0 0 0 0 0 0
40387 - 0 0 0 0 0 0 0 0 0 0 0 0
40388 - 0 0 0 0 0 0 0 0 0 0 0 0
40389 - 0 0 0 0 0 0 0 0 0 0 0 0
40390 - 0 0 0 0 0 0 0 0 0 0 0 0
40391 - 0 0 0 0 0 0 0 0 0 0 0 0
40392 - 0 0 0 6 6 6 22 22 22 50 50 50
40393 - 90 90 90 26 26 26 2 2 6 2 2 6
40394 - 14 14 14 195 195 195 250 250 250 253 253 253
40395 -253 253 253 253 253 253 253 253 253 253 253 253
40396 -253 253 253 253 253 253 253 253 253 253 253 253
40397 -253 253 253 253 253 253 253 253 253 253 253 253
40398 -253 253 253 253 253 253 253 253 253 253 253 253
40399 -250 250 250 242 242 242 54 54 54 2 2 6
40400 - 2 2 6 2 2 6 2 2 6 2 2 6
40401 - 2 2 6 2 2 6 2 2 6 38 38 38
40402 - 86 86 86 50 50 50 22 22 22 6 6 6
40403 - 0 0 0 0 0 0 0 0 0 0 0 0
40404 - 0 0 0 0 0 0 0 0 0 0 0 0
40405 - 0 0 0 0 0 0 0 0 0 0 0 0
40406 - 0 0 0 0 0 0 0 0 0 0 0 0
40407 - 0 0 0 0 0 0 0 0 0 0 0 0
40408 - 0 0 0 0 0 0 0 0 0 0 0 0
40409 - 0 0 0 0 0 0 0 0 0 0 0 0
40410 - 0 0 0 0 0 0 0 0 0 0 0 0
40411 - 0 0 0 0 0 0 0 0 0 0 0 0
40412 - 6 6 6 14 14 14 38 38 38 82 82 82
40413 - 34 34 34 2 2 6 2 2 6 2 2 6
40414 - 42 42 42 195 195 195 246 246 246 253 253 253
40415 -253 253 253 253 253 253 253 253 253 250 250 250
40416 -242 242 242 242 242 242 250 250 250 253 253 253
40417 -253 253 253 253 253 253 253 253 253 253 253 253
40418 -253 253 253 250 250 250 246 246 246 238 238 238
40419 -226 226 226 231 231 231 101 101 101 6 6 6
40420 - 2 2 6 2 2 6 2 2 6 2 2 6
40421 - 2 2 6 2 2 6 2 2 6 2 2 6
40422 - 38 38 38 82 82 82 42 42 42 14 14 14
40423 - 6 6 6 0 0 0 0 0 0 0 0 0
40424 - 0 0 0 0 0 0 0 0 0 0 0 0
40425 - 0 0 0 0 0 0 0 0 0 0 0 0
40426 - 0 0 0 0 0 0 0 0 0 0 0 0
40427 - 0 0 0 0 0 0 0 0 0 0 0 0
40428 - 0 0 0 0 0 0 0 0 0 0 0 0
40429 - 0 0 0 0 0 0 0 0 0 0 0 0
40430 - 0 0 0 0 0 0 0 0 0 0 0 0
40431 - 0 0 0 0 0 0 0 0 0 0 0 0
40432 - 10 10 10 26 26 26 62 62 62 66 66 66
40433 - 2 2 6 2 2 6 2 2 6 6 6 6
40434 - 70 70 70 170 170 170 206 206 206 234 234 234
40435 -246 246 246 250 250 250 250 250 250 238 238 238
40436 -226 226 226 231 231 231 238 238 238 250 250 250
40437 -250 250 250 250 250 250 246 246 246 231 231 231
40438 -214 214 214 206 206 206 202 202 202 202 202 202
40439 -198 198 198 202 202 202 182 182 182 18 18 18
40440 - 2 2 6 2 2 6 2 2 6 2 2 6
40441 - 2 2 6 2 2 6 2 2 6 2 2 6
40442 - 2 2 6 62 62 62 66 66 66 30 30 30
40443 - 10 10 10 0 0 0 0 0 0 0 0 0
40444 - 0 0 0 0 0 0 0 0 0 0 0 0
40445 - 0 0 0 0 0 0 0 0 0 0 0 0
40446 - 0 0 0 0 0 0 0 0 0 0 0 0
40447 - 0 0 0 0 0 0 0 0 0 0 0 0
40448 - 0 0 0 0 0 0 0 0 0 0 0 0
40449 - 0 0 0 0 0 0 0 0 0 0 0 0
40450 - 0 0 0 0 0 0 0 0 0 0 0 0
40451 - 0 0 0 0 0 0 0 0 0 0 0 0
40452 - 14 14 14 42 42 42 82 82 82 18 18 18
40453 - 2 2 6 2 2 6 2 2 6 10 10 10
40454 - 94 94 94 182 182 182 218 218 218 242 242 242
40455 -250 250 250 253 253 253 253 253 253 250 250 250
40456 -234 234 234 253 253 253 253 253 253 253 253 253
40457 -253 253 253 253 253 253 253 253 253 246 246 246
40458 -238 238 238 226 226 226 210 210 210 202 202 202
40459 -195 195 195 195 195 195 210 210 210 158 158 158
40460 - 6 6 6 14 14 14 50 50 50 14 14 14
40461 - 2 2 6 2 2 6 2 2 6 2 2 6
40462 - 2 2 6 6 6 6 86 86 86 46 46 46
40463 - 18 18 18 6 6 6 0 0 0 0 0 0
40464 - 0 0 0 0 0 0 0 0 0 0 0 0
40465 - 0 0 0 0 0 0 0 0 0 0 0 0
40466 - 0 0 0 0 0 0 0 0 0 0 0 0
40467 - 0 0 0 0 0 0 0 0 0 0 0 0
40468 - 0 0 0 0 0 0 0 0 0 0 0 0
40469 - 0 0 0 0 0 0 0 0 0 0 0 0
40470 - 0 0 0 0 0 0 0 0 0 0 0 0
40471 - 0 0 0 0 0 0 0 0 0 6 6 6
40472 - 22 22 22 54 54 54 70 70 70 2 2 6
40473 - 2 2 6 10 10 10 2 2 6 22 22 22
40474 -166 166 166 231 231 231 250 250 250 253 253 253
40475 -253 253 253 253 253 253 253 253 253 250 250 250
40476 -242 242 242 253 253 253 253 253 253 253 253 253
40477 -253 253 253 253 253 253 253 253 253 253 253 253
40478 -253 253 253 253 253 253 253 253 253 246 246 246
40479 -231 231 231 206 206 206 198 198 198 226 226 226
40480 - 94 94 94 2 2 6 6 6 6 38 38 38
40481 - 30 30 30 2 2 6 2 2 6 2 2 6
40482 - 2 2 6 2 2 6 62 62 62 66 66 66
40483 - 26 26 26 10 10 10 0 0 0 0 0 0
40484 - 0 0 0 0 0 0 0 0 0 0 0 0
40485 - 0 0 0 0 0 0 0 0 0 0 0 0
40486 - 0 0 0 0 0 0 0 0 0 0 0 0
40487 - 0 0 0 0 0 0 0 0 0 0 0 0
40488 - 0 0 0 0 0 0 0 0 0 0 0 0
40489 - 0 0 0 0 0 0 0 0 0 0 0 0
40490 - 0 0 0 0 0 0 0 0 0 0 0 0
40491 - 0 0 0 0 0 0 0 0 0 10 10 10
40492 - 30 30 30 74 74 74 50 50 50 2 2 6
40493 - 26 26 26 26 26 26 2 2 6 106 106 106
40494 -238 238 238 253 253 253 253 253 253 253 253 253
40495 -253 253 253 253 253 253 253 253 253 253 253 253
40496 -253 253 253 253 253 253 253 253 253 253 253 253
40497 -253 253 253 253 253 253 253 253 253 253 253 253
40498 -253 253 253 253 253 253 253 253 253 253 253 253
40499 -253 253 253 246 246 246 218 218 218 202 202 202
40500 -210 210 210 14 14 14 2 2 6 2 2 6
40501 - 30 30 30 22 22 22 2 2 6 2 2 6
40502 - 2 2 6 2 2 6 18 18 18 86 86 86
40503 - 42 42 42 14 14 14 0 0 0 0 0 0
40504 - 0 0 0 0 0 0 0 0 0 0 0 0
40505 - 0 0 0 0 0 0 0 0 0 0 0 0
40506 - 0 0 0 0 0 0 0 0 0 0 0 0
40507 - 0 0 0 0 0 0 0 0 0 0 0 0
40508 - 0 0 0 0 0 0 0 0 0 0 0 0
40509 - 0 0 0 0 0 0 0 0 0 0 0 0
40510 - 0 0 0 0 0 0 0 0 0 0 0 0
40511 - 0 0 0 0 0 0 0 0 0 14 14 14
40512 - 42 42 42 90 90 90 22 22 22 2 2 6
40513 - 42 42 42 2 2 6 18 18 18 218 218 218
40514 -253 253 253 253 253 253 253 253 253 253 253 253
40515 -253 253 253 253 253 253 253 253 253 253 253 253
40516 -253 253 253 253 253 253 253 253 253 253 253 253
40517 -253 253 253 253 253 253 253 253 253 253 253 253
40518 -253 253 253 253 253 253 253 253 253 253 253 253
40519 -253 253 253 253 253 253 250 250 250 221 221 221
40520 -218 218 218 101 101 101 2 2 6 14 14 14
40521 - 18 18 18 38 38 38 10 10 10 2 2 6
40522 - 2 2 6 2 2 6 2 2 6 78 78 78
40523 - 58 58 58 22 22 22 6 6 6 0 0 0
40524 - 0 0 0 0 0 0 0 0 0 0 0 0
40525 - 0 0 0 0 0 0 0 0 0 0 0 0
40526 - 0 0 0 0 0 0 0 0 0 0 0 0
40527 - 0 0 0 0 0 0 0 0 0 0 0 0
40528 - 0 0 0 0 0 0 0 0 0 0 0 0
40529 - 0 0 0 0 0 0 0 0 0 0 0 0
40530 - 0 0 0 0 0 0 0 0 0 0 0 0
40531 - 0 0 0 0 0 0 6 6 6 18 18 18
40532 - 54 54 54 82 82 82 2 2 6 26 26 26
40533 - 22 22 22 2 2 6 123 123 123 253 253 253
40534 -253 253 253 253 253 253 253 253 253 253 253 253
40535 -253 253 253 253 253 253 253 253 253 253 253 253
40536 -253 253 253 253 253 253 253 253 253 253 253 253
40537 -253 253 253 253 253 253 253 253 253 253 253 253
40538 -253 253 253 253 253 253 253 253 253 253 253 253
40539 -253 253 253 253 253 253 253 253 253 250 250 250
40540 -238 238 238 198 198 198 6 6 6 38 38 38
40541 - 58 58 58 26 26 26 38 38 38 2 2 6
40542 - 2 2 6 2 2 6 2 2 6 46 46 46
40543 - 78 78 78 30 30 30 10 10 10 0 0 0
40544 - 0 0 0 0 0 0 0 0 0 0 0 0
40545 - 0 0 0 0 0 0 0 0 0 0 0 0
40546 - 0 0 0 0 0 0 0 0 0 0 0 0
40547 - 0 0 0 0 0 0 0 0 0 0 0 0
40548 - 0 0 0 0 0 0 0 0 0 0 0 0
40549 - 0 0 0 0 0 0 0 0 0 0 0 0
40550 - 0 0 0 0 0 0 0 0 0 0 0 0
40551 - 0 0 0 0 0 0 10 10 10 30 30 30
40552 - 74 74 74 58 58 58 2 2 6 42 42 42
40553 - 2 2 6 22 22 22 231 231 231 253 253 253
40554 -253 253 253 253 253 253 253 253 253 253 253 253
40555 -253 253 253 253 253 253 253 253 253 250 250 250
40556 -253 253 253 253 253 253 253 253 253 253 253 253
40557 -253 253 253 253 253 253 253 253 253 253 253 253
40558 -253 253 253 253 253 253 253 253 253 253 253 253
40559 -253 253 253 253 253 253 253 253 253 253 253 253
40560 -253 253 253 246 246 246 46 46 46 38 38 38
40561 - 42 42 42 14 14 14 38 38 38 14 14 14
40562 - 2 2 6 2 2 6 2 2 6 6 6 6
40563 - 86 86 86 46 46 46 14 14 14 0 0 0
40564 - 0 0 0 0 0 0 0 0 0 0 0 0
40565 - 0 0 0 0 0 0 0 0 0 0 0 0
40566 - 0 0 0 0 0 0 0 0 0 0 0 0
40567 - 0 0 0 0 0 0 0 0 0 0 0 0
40568 - 0 0 0 0 0 0 0 0 0 0 0 0
40569 - 0 0 0 0 0 0 0 0 0 0 0 0
40570 - 0 0 0 0 0 0 0 0 0 0 0 0
40571 - 0 0 0 6 6 6 14 14 14 42 42 42
40572 - 90 90 90 18 18 18 18 18 18 26 26 26
40573 - 2 2 6 116 116 116 253 253 253 253 253 253
40574 -253 253 253 253 253 253 253 253 253 253 253 253
40575 -253 253 253 253 253 253 250 250 250 238 238 238
40576 -253 253 253 253 253 253 253 253 253 253 253 253
40577 -253 253 253 253 253 253 253 253 253 253 253 253
40578 -253 253 253 253 253 253 253 253 253 253 253 253
40579 -253 253 253 253 253 253 253 253 253 253 253 253
40580 -253 253 253 253 253 253 94 94 94 6 6 6
40581 - 2 2 6 2 2 6 10 10 10 34 34 34
40582 - 2 2 6 2 2 6 2 2 6 2 2 6
40583 - 74 74 74 58 58 58 22 22 22 6 6 6
40584 - 0 0 0 0 0 0 0 0 0 0 0 0
40585 - 0 0 0 0 0 0 0 0 0 0 0 0
40586 - 0 0 0 0 0 0 0 0 0 0 0 0
40587 - 0 0 0 0 0 0 0 0 0 0 0 0
40588 - 0 0 0 0 0 0 0 0 0 0 0 0
40589 - 0 0 0 0 0 0 0 0 0 0 0 0
40590 - 0 0 0 0 0 0 0 0 0 0 0 0
40591 - 0 0 0 10 10 10 26 26 26 66 66 66
40592 - 82 82 82 2 2 6 38 38 38 6 6 6
40593 - 14 14 14 210 210 210 253 253 253 253 253 253
40594 -253 253 253 253 253 253 253 253 253 253 253 253
40595 -253 253 253 253 253 253 246 246 246 242 242 242
40596 -253 253 253 253 253 253 253 253 253 253 253 253
40597 -253 253 253 253 253 253 253 253 253 253 253 253
40598 -253 253 253 253 253 253 253 253 253 253 253 253
40599 -253 253 253 253 253 253 253 253 253 253 253 253
40600 -253 253 253 253 253 253 144 144 144 2 2 6
40601 - 2 2 6 2 2 6 2 2 6 46 46 46
40602 - 2 2 6 2 2 6 2 2 6 2 2 6
40603 - 42 42 42 74 74 74 30 30 30 10 10 10
40604 - 0 0 0 0 0 0 0 0 0 0 0 0
40605 - 0 0 0 0 0 0 0 0 0 0 0 0
40606 - 0 0 0 0 0 0 0 0 0 0 0 0
40607 - 0 0 0 0 0 0 0 0 0 0 0 0
40608 - 0 0 0 0 0 0 0 0 0 0 0 0
40609 - 0 0 0 0 0 0 0 0 0 0 0 0
40610 - 0 0 0 0 0 0 0 0 0 0 0 0
40611 - 6 6 6 14 14 14 42 42 42 90 90 90
40612 - 26 26 26 6 6 6 42 42 42 2 2 6
40613 - 74 74 74 250 250 250 253 253 253 253 253 253
40614 -253 253 253 253 253 253 253 253 253 253 253 253
40615 -253 253 253 253 253 253 242 242 242 242 242 242
40616 -253 253 253 253 253 253 253 253 253 253 253 253
40617 -253 253 253 253 253 253 253 253 253 253 253 253
40618 -253 253 253 253 253 253 253 253 253 253 253 253
40619 -253 253 253 253 253 253 253 253 253 253 253 253
40620 -253 253 253 253 253 253 182 182 182 2 2 6
40621 - 2 2 6 2 2 6 2 2 6 46 46 46
40622 - 2 2 6 2 2 6 2 2 6 2 2 6
40623 - 10 10 10 86 86 86 38 38 38 10 10 10
40624 - 0 0 0 0 0 0 0 0 0 0 0 0
40625 - 0 0 0 0 0 0 0 0 0 0 0 0
40626 - 0 0 0 0 0 0 0 0 0 0 0 0
40627 - 0 0 0 0 0 0 0 0 0 0 0 0
40628 - 0 0 0 0 0 0 0 0 0 0 0 0
40629 - 0 0 0 0 0 0 0 0 0 0 0 0
40630 - 0 0 0 0 0 0 0 0 0 0 0 0
40631 - 10 10 10 26 26 26 66 66 66 82 82 82
40632 - 2 2 6 22 22 22 18 18 18 2 2 6
40633 -149 149 149 253 253 253 253 253 253 253 253 253
40634 -253 253 253 253 253 253 253 253 253 253 253 253
40635 -253 253 253 253 253 253 234 234 234 242 242 242
40636 -253 253 253 253 253 253 253 253 253 253 253 253
40637 -253 253 253 253 253 253 253 253 253 253 253 253
40638 -253 253 253 253 253 253 253 253 253 253 253 253
40639 -253 253 253 253 253 253 253 253 253 253 253 253
40640 -253 253 253 253 253 253 206 206 206 2 2 6
40641 - 2 2 6 2 2 6 2 2 6 38 38 38
40642 - 2 2 6 2 2 6 2 2 6 2 2 6
40643 - 6 6 6 86 86 86 46 46 46 14 14 14
40644 - 0 0 0 0 0 0 0 0 0 0 0 0
40645 - 0 0 0 0 0 0 0 0 0 0 0 0
40646 - 0 0 0 0 0 0 0 0 0 0 0 0
40647 - 0 0 0 0 0 0 0 0 0 0 0 0
40648 - 0 0 0 0 0 0 0 0 0 0 0 0
40649 - 0 0 0 0 0 0 0 0 0 0 0 0
40650 - 0 0 0 0 0 0 0 0 0 6 6 6
40651 - 18 18 18 46 46 46 86 86 86 18 18 18
40652 - 2 2 6 34 34 34 10 10 10 6 6 6
40653 -210 210 210 253 253 253 253 253 253 253 253 253
40654 -253 253 253 253 253 253 253 253 253 253 253 253
40655 -253 253 253 253 253 253 234 234 234 242 242 242
40656 -253 253 253 253 253 253 253 253 253 253 253 253
40657 -253 253 253 253 253 253 253 253 253 253 253 253
40658 -253 253 253 253 253 253 253 253 253 253 253 253
40659 -253 253 253 253 253 253 253 253 253 253 253 253
40660 -253 253 253 253 253 253 221 221 221 6 6 6
40661 - 2 2 6 2 2 6 6 6 6 30 30 30
40662 - 2 2 6 2 2 6 2 2 6 2 2 6
40663 - 2 2 6 82 82 82 54 54 54 18 18 18
40664 - 6 6 6 0 0 0 0 0 0 0 0 0
40665 - 0 0 0 0 0 0 0 0 0 0 0 0
40666 - 0 0 0 0 0 0 0 0 0 0 0 0
40667 - 0 0 0 0 0 0 0 0 0 0 0 0
40668 - 0 0 0 0 0 0 0 0 0 0 0 0
40669 - 0 0 0 0 0 0 0 0 0 0 0 0
40670 - 0 0 0 0 0 0 0 0 0 10 10 10
40671 - 26 26 26 66 66 66 62 62 62 2 2 6
40672 - 2 2 6 38 38 38 10 10 10 26 26 26
40673 -238 238 238 253 253 253 253 253 253 253 253 253
40674 -253 253 253 253 253 253 253 253 253 253 253 253
40675 -253 253 253 253 253 253 231 231 231 238 238 238
40676 -253 253 253 253 253 253 253 253 253 253 253 253
40677 -253 253 253 253 253 253 253 253 253 253 253 253
40678 -253 253 253 253 253 253 253 253 253 253 253 253
40679 -253 253 253 253 253 253 253 253 253 253 253 253
40680 -253 253 253 253 253 253 231 231 231 6 6 6
40681 - 2 2 6 2 2 6 10 10 10 30 30 30
40682 - 2 2 6 2 2 6 2 2 6 2 2 6
40683 - 2 2 6 66 66 66 58 58 58 22 22 22
40684 - 6 6 6 0 0 0 0 0 0 0 0 0
40685 - 0 0 0 0 0 0 0 0 0 0 0 0
40686 - 0 0 0 0 0 0 0 0 0 0 0 0
40687 - 0 0 0 0 0 0 0 0 0 0 0 0
40688 - 0 0 0 0 0 0 0 0 0 0 0 0
40689 - 0 0 0 0 0 0 0 0 0 0 0 0
40690 - 0 0 0 0 0 0 0 0 0 10 10 10
40691 - 38 38 38 78 78 78 6 6 6 2 2 6
40692 - 2 2 6 46 46 46 14 14 14 42 42 42
40693 -246 246 246 253 253 253 253 253 253 253 253 253
40694 -253 253 253 253 253 253 253 253 253 253 253 253
40695 -253 253 253 253 253 253 231 231 231 242 242 242
40696 -253 253 253 253 253 253 253 253 253 253 253 253
40697 -253 253 253 253 253 253 253 253 253 253 253 253
40698 -253 253 253 253 253 253 253 253 253 253 253 253
40699 -253 253 253 253 253 253 253 253 253 253 253 253
40700 -253 253 253 253 253 253 234 234 234 10 10 10
40701 - 2 2 6 2 2 6 22 22 22 14 14 14
40702 - 2 2 6 2 2 6 2 2 6 2 2 6
40703 - 2 2 6 66 66 66 62 62 62 22 22 22
40704 - 6 6 6 0 0 0 0 0 0 0 0 0
40705 - 0 0 0 0 0 0 0 0 0 0 0 0
40706 - 0 0 0 0 0 0 0 0 0 0 0 0
40707 - 0 0 0 0 0 0 0 0 0 0 0 0
40708 - 0 0 0 0 0 0 0 0 0 0 0 0
40709 - 0 0 0 0 0 0 0 0 0 0 0 0
40710 - 0 0 0 0 0 0 6 6 6 18 18 18
40711 - 50 50 50 74 74 74 2 2 6 2 2 6
40712 - 14 14 14 70 70 70 34 34 34 62 62 62
40713 -250 250 250 253 253 253 253 253 253 253 253 253
40714 -253 253 253 253 253 253 253 253 253 253 253 253
40715 -253 253 253 253 253 253 231 231 231 246 246 246
40716 -253 253 253 253 253 253 253 253 253 253 253 253
40717 -253 253 253 253 253 253 253 253 253 253 253 253
40718 -253 253 253 253 253 253 253 253 253 253 253 253
40719 -253 253 253 253 253 253 253 253 253 253 253 253
40720 -253 253 253 253 253 253 234 234 234 14 14 14
40721 - 2 2 6 2 2 6 30 30 30 2 2 6
40722 - 2 2 6 2 2 6 2 2 6 2 2 6
40723 - 2 2 6 66 66 66 62 62 62 22 22 22
40724 - 6 6 6 0 0 0 0 0 0 0 0 0
40725 - 0 0 0 0 0 0 0 0 0 0 0 0
40726 - 0 0 0 0 0 0 0 0 0 0 0 0
40727 - 0 0 0 0 0 0 0 0 0 0 0 0
40728 - 0 0 0 0 0 0 0 0 0 0 0 0
40729 - 0 0 0 0 0 0 0 0 0 0 0 0
40730 - 0 0 0 0 0 0 6 6 6 18 18 18
40731 - 54 54 54 62 62 62 2 2 6 2 2 6
40732 - 2 2 6 30 30 30 46 46 46 70 70 70
40733 -250 250 250 253 253 253 253 253 253 253 253 253
40734 -253 253 253 253 253 253 253 253 253 253 253 253
40735 -253 253 253 253 253 253 231 231 231 246 246 246
40736 -253 253 253 253 253 253 253 253 253 253 253 253
40737 -253 253 253 253 253 253 253 253 253 253 253 253
40738 -253 253 253 253 253 253 253 253 253 253 253 253
40739 -253 253 253 253 253 253 253 253 253 253 253 253
40740 -253 253 253 253 253 253 226 226 226 10 10 10
40741 - 2 2 6 6 6 6 30 30 30 2 2 6
40742 - 2 2 6 2 2 6 2 2 6 2 2 6
40743 - 2 2 6 66 66 66 58 58 58 22 22 22
40744 - 6 6 6 0 0 0 0 0 0 0 0 0
40745 - 0 0 0 0 0 0 0 0 0 0 0 0
40746 - 0 0 0 0 0 0 0 0 0 0 0 0
40747 - 0 0 0 0 0 0 0 0 0 0 0 0
40748 - 0 0 0 0 0 0 0 0 0 0 0 0
40749 - 0 0 0 0 0 0 0 0 0 0 0 0
40750 - 0 0 0 0 0 0 6 6 6 22 22 22
40751 - 58 58 58 62 62 62 2 2 6 2 2 6
40752 - 2 2 6 2 2 6 30 30 30 78 78 78
40753 -250 250 250 253 253 253 253 253 253 253 253 253
40754 -253 253 253 253 253 253 253 253 253 253 253 253
40755 -253 253 253 253 253 253 231 231 231 246 246 246
40756 -253 253 253 253 253 253 253 253 253 253 253 253
40757 -253 253 253 253 253 253 253 253 253 253 253 253
40758 -253 253 253 253 253 253 253 253 253 253 253 253
40759 -253 253 253 253 253 253 253 253 253 253 253 253
40760 -253 253 253 253 253 253 206 206 206 2 2 6
40761 - 22 22 22 34 34 34 18 14 6 22 22 22
40762 - 26 26 26 18 18 18 6 6 6 2 2 6
40763 - 2 2 6 82 82 82 54 54 54 18 18 18
40764 - 6 6 6 0 0 0 0 0 0 0 0 0
40765 - 0 0 0 0 0 0 0 0 0 0 0 0
40766 - 0 0 0 0 0 0 0 0 0 0 0 0
40767 - 0 0 0 0 0 0 0 0 0 0 0 0
40768 - 0 0 0 0 0 0 0 0 0 0 0 0
40769 - 0 0 0 0 0 0 0 0 0 0 0 0
40770 - 0 0 0 0 0 0 6 6 6 26 26 26
40771 - 62 62 62 106 106 106 74 54 14 185 133 11
40772 -210 162 10 121 92 8 6 6 6 62 62 62
40773 -238 238 238 253 253 253 253 253 253 253 253 253
40774 -253 253 253 253 253 253 253 253 253 253 253 253
40775 -253 253 253 253 253 253 231 231 231 246 246 246
40776 -253 253 253 253 253 253 253 253 253 253 253 253
40777 -253 253 253 253 253 253 253 253 253 253 253 253
40778 -253 253 253 253 253 253 253 253 253 253 253 253
40779 -253 253 253 253 253 253 253 253 253 253 253 253
40780 -253 253 253 253 253 253 158 158 158 18 18 18
40781 - 14 14 14 2 2 6 2 2 6 2 2 6
40782 - 6 6 6 18 18 18 66 66 66 38 38 38
40783 - 6 6 6 94 94 94 50 50 50 18 18 18
40784 - 6 6 6 0 0 0 0 0 0 0 0 0
40785 - 0 0 0 0 0 0 0 0 0 0 0 0
40786 - 0 0 0 0 0 0 0 0 0 0 0 0
40787 - 0 0 0 0 0 0 0 0 0 0 0 0
40788 - 0 0 0 0 0 0 0 0 0 0 0 0
40789 - 0 0 0 0 0 0 0 0 0 6 6 6
40790 - 10 10 10 10 10 10 18 18 18 38 38 38
40791 - 78 78 78 142 134 106 216 158 10 242 186 14
40792 -246 190 14 246 190 14 156 118 10 10 10 10
40793 - 90 90 90 238 238 238 253 253 253 253 253 253
40794 -253 253 253 253 253 253 253 253 253 253 253 253
40795 -253 253 253 253 253 253 231 231 231 250 250 250
40796 -253 253 253 253 253 253 253 253 253 253 253 253
40797 -253 253 253 253 253 253 253 253 253 253 253 253
40798 -253 253 253 253 253 253 253 253 253 253 253 253
40799 -253 253 253 253 253 253 253 253 253 246 230 190
40800 -238 204 91 238 204 91 181 142 44 37 26 9
40801 - 2 2 6 2 2 6 2 2 6 2 2 6
40802 - 2 2 6 2 2 6 38 38 38 46 46 46
40803 - 26 26 26 106 106 106 54 54 54 18 18 18
40804 - 6 6 6 0 0 0 0 0 0 0 0 0
40805 - 0 0 0 0 0 0 0 0 0 0 0 0
40806 - 0 0 0 0 0 0 0 0 0 0 0 0
40807 - 0 0 0 0 0 0 0 0 0 0 0 0
40808 - 0 0 0 0 0 0 0 0 0 0 0 0
40809 - 0 0 0 6 6 6 14 14 14 22 22 22
40810 - 30 30 30 38 38 38 50 50 50 70 70 70
40811 -106 106 106 190 142 34 226 170 11 242 186 14
40812 -246 190 14 246 190 14 246 190 14 154 114 10
40813 - 6 6 6 74 74 74 226 226 226 253 253 253
40814 -253 253 253 253 253 253 253 253 253 253 253 253
40815 -253 253 253 253 253 253 231 231 231 250 250 250
40816 -253 253 253 253 253 253 253 253 253 253 253 253
40817 -253 253 253 253 253 253 253 253 253 253 253 253
40818 -253 253 253 253 253 253 253 253 253 253 253 253
40819 -253 253 253 253 253 253 253 253 253 228 184 62
40820 -241 196 14 241 208 19 232 195 16 38 30 10
40821 - 2 2 6 2 2 6 2 2 6 2 2 6
40822 - 2 2 6 6 6 6 30 30 30 26 26 26
40823 -203 166 17 154 142 90 66 66 66 26 26 26
40824 - 6 6 6 0 0 0 0 0 0 0 0 0
40825 - 0 0 0 0 0 0 0 0 0 0 0 0
40826 - 0 0 0 0 0 0 0 0 0 0 0 0
40827 - 0 0 0 0 0 0 0 0 0 0 0 0
40828 - 0 0 0 0 0 0 0 0 0 0 0 0
40829 - 6 6 6 18 18 18 38 38 38 58 58 58
40830 - 78 78 78 86 86 86 101 101 101 123 123 123
40831 -175 146 61 210 150 10 234 174 13 246 186 14
40832 -246 190 14 246 190 14 246 190 14 238 190 10
40833 -102 78 10 2 2 6 46 46 46 198 198 198
40834 -253 253 253 253 253 253 253 253 253 253 253 253
40835 -253 253 253 253 253 253 234 234 234 242 242 242
40836 -253 253 253 253 253 253 253 253 253 253 253 253
40837 -253 253 253 253 253 253 253 253 253 253 253 253
40838 -253 253 253 253 253 253 253 253 253 253 253 253
40839 -253 253 253 253 253 253 253 253 253 224 178 62
40840 -242 186 14 241 196 14 210 166 10 22 18 6
40841 - 2 2 6 2 2 6 2 2 6 2 2 6
40842 - 2 2 6 2 2 6 6 6 6 121 92 8
40843 -238 202 15 232 195 16 82 82 82 34 34 34
40844 - 10 10 10 0 0 0 0 0 0 0 0 0
40845 - 0 0 0 0 0 0 0 0 0 0 0 0
40846 - 0 0 0 0 0 0 0 0 0 0 0 0
40847 - 0 0 0 0 0 0 0 0 0 0 0 0
40848 - 0 0 0 0 0 0 0 0 0 0 0 0
40849 - 14 14 14 38 38 38 70 70 70 154 122 46
40850 -190 142 34 200 144 11 197 138 11 197 138 11
40851 -213 154 11 226 170 11 242 186 14 246 190 14
40852 -246 190 14 246 190 14 246 190 14 246 190 14
40853 -225 175 15 46 32 6 2 2 6 22 22 22
40854 -158 158 158 250 250 250 253 253 253 253 253 253
40855 -253 253 253 253 253 253 253 253 253 253 253 253
40856 -253 253 253 253 253 253 253 253 253 253 253 253
40857 -253 253 253 253 253 253 253 253 253 253 253 253
40858 -253 253 253 253 253 253 253 253 253 253 253 253
40859 -253 253 253 250 250 250 242 242 242 224 178 62
40860 -239 182 13 236 186 11 213 154 11 46 32 6
40861 - 2 2 6 2 2 6 2 2 6 2 2 6
40862 - 2 2 6 2 2 6 61 42 6 225 175 15
40863 -238 190 10 236 186 11 112 100 78 42 42 42
40864 - 14 14 14 0 0 0 0 0 0 0 0 0
40865 - 0 0 0 0 0 0 0 0 0 0 0 0
40866 - 0 0 0 0 0 0 0 0 0 0 0 0
40867 - 0 0 0 0 0 0 0 0 0 0 0 0
40868 - 0 0 0 0 0 0 0 0 0 6 6 6
40869 - 22 22 22 54 54 54 154 122 46 213 154 11
40870 -226 170 11 230 174 11 226 170 11 226 170 11
40871 -236 178 12 242 186 14 246 190 14 246 190 14
40872 -246 190 14 246 190 14 246 190 14 246 190 14
40873 -241 196 14 184 144 12 10 10 10 2 2 6
40874 - 6 6 6 116 116 116 242 242 242 253 253 253
40875 -253 253 253 253 253 253 253 253 253 253 253 253
40876 -253 253 253 253 253 253 253 253 253 253 253 253
40877 -253 253 253 253 253 253 253 253 253 253 253 253
40878 -253 253 253 253 253 253 253 253 253 253 253 253
40879 -253 253 253 231 231 231 198 198 198 214 170 54
40880 -236 178 12 236 178 12 210 150 10 137 92 6
40881 - 18 14 6 2 2 6 2 2 6 2 2 6
40882 - 6 6 6 70 47 6 200 144 11 236 178 12
40883 -239 182 13 239 182 13 124 112 88 58 58 58
40884 - 22 22 22 6 6 6 0 0 0 0 0 0
40885 - 0 0 0 0 0 0 0 0 0 0 0 0
40886 - 0 0 0 0 0 0 0 0 0 0 0 0
40887 - 0 0 0 0 0 0 0 0 0 0 0 0
40888 - 0 0 0 0 0 0 0 0 0 10 10 10
40889 - 30 30 30 70 70 70 180 133 36 226 170 11
40890 -239 182 13 242 186 14 242 186 14 246 186 14
40891 -246 190 14 246 190 14 246 190 14 246 190 14
40892 -246 190 14 246 190 14 246 190 14 246 190 14
40893 -246 190 14 232 195 16 98 70 6 2 2 6
40894 - 2 2 6 2 2 6 66 66 66 221 221 221
40895 -253 253 253 253 253 253 253 253 253 253 253 253
40896 -253 253 253 253 253 253 253 253 253 253 253 253
40897 -253 253 253 253 253 253 253 253 253 253 253 253
40898 -253 253 253 253 253 253 253 253 253 253 253 253
40899 -253 253 253 206 206 206 198 198 198 214 166 58
40900 -230 174 11 230 174 11 216 158 10 192 133 9
40901 -163 110 8 116 81 8 102 78 10 116 81 8
40902 -167 114 7 197 138 11 226 170 11 239 182 13
40903 -242 186 14 242 186 14 162 146 94 78 78 78
40904 - 34 34 34 14 14 14 6 6 6 0 0 0
40905 - 0 0 0 0 0 0 0 0 0 0 0 0
40906 - 0 0 0 0 0 0 0 0 0 0 0 0
40907 - 0 0 0 0 0 0 0 0 0 0 0 0
40908 - 0 0 0 0 0 0 0 0 0 6 6 6
40909 - 30 30 30 78 78 78 190 142 34 226 170 11
40910 -239 182 13 246 190 14 246 190 14 246 190 14
40911 -246 190 14 246 190 14 246 190 14 246 190 14
40912 -246 190 14 246 190 14 246 190 14 246 190 14
40913 -246 190 14 241 196 14 203 166 17 22 18 6
40914 - 2 2 6 2 2 6 2 2 6 38 38 38
40915 -218 218 218 253 253 253 253 253 253 253 253 253
40916 -253 253 253 253 253 253 253 253 253 253 253 253
40917 -253 253 253 253 253 253 253 253 253 253 253 253
40918 -253 253 253 253 253 253 253 253 253 253 253 253
40919 -250 250 250 206 206 206 198 198 198 202 162 69
40920 -226 170 11 236 178 12 224 166 10 210 150 10
40921 -200 144 11 197 138 11 192 133 9 197 138 11
40922 -210 150 10 226 170 11 242 186 14 246 190 14
40923 -246 190 14 246 186 14 225 175 15 124 112 88
40924 - 62 62 62 30 30 30 14 14 14 6 6 6
40925 - 0 0 0 0 0 0 0 0 0 0 0 0
40926 - 0 0 0 0 0 0 0 0 0 0 0 0
40927 - 0 0 0 0 0 0 0 0 0 0 0 0
40928 - 0 0 0 0 0 0 0 0 0 10 10 10
40929 - 30 30 30 78 78 78 174 135 50 224 166 10
40930 -239 182 13 246 190 14 246 190 14 246 190 14
40931 -246 190 14 246 190 14 246 190 14 246 190 14
40932 -246 190 14 246 190 14 246 190 14 246 190 14
40933 -246 190 14 246 190 14 241 196 14 139 102 15
40934 - 2 2 6 2 2 6 2 2 6 2 2 6
40935 - 78 78 78 250 250 250 253 253 253 253 253 253
40936 -253 253 253 253 253 253 253 253 253 253 253 253
40937 -253 253 253 253 253 253 253 253 253 253 253 253
40938 -253 253 253 253 253 253 253 253 253 253 253 253
40939 -250 250 250 214 214 214 198 198 198 190 150 46
40940 -219 162 10 236 178 12 234 174 13 224 166 10
40941 -216 158 10 213 154 11 213 154 11 216 158 10
40942 -226 170 11 239 182 13 246 190 14 246 190 14
40943 -246 190 14 246 190 14 242 186 14 206 162 42
40944 -101 101 101 58 58 58 30 30 30 14 14 14
40945 - 6 6 6 0 0 0 0 0 0 0 0 0
40946 - 0 0 0 0 0 0 0 0 0 0 0 0
40947 - 0 0 0 0 0 0 0 0 0 0 0 0
40948 - 0 0 0 0 0 0 0 0 0 10 10 10
40949 - 30 30 30 74 74 74 174 135 50 216 158 10
40950 -236 178 12 246 190 14 246 190 14 246 190 14
40951 -246 190 14 246 190 14 246 190 14 246 190 14
40952 -246 190 14 246 190 14 246 190 14 246 190 14
40953 -246 190 14 246 190 14 241 196 14 226 184 13
40954 - 61 42 6 2 2 6 2 2 6 2 2 6
40955 - 22 22 22 238 238 238 253 253 253 253 253 253
40956 -253 253 253 253 253 253 253 253 253 253 253 253
40957 -253 253 253 253 253 253 253 253 253 253 253 253
40958 -253 253 253 253 253 253 253 253 253 253 253 253
40959 -253 253 253 226 226 226 187 187 187 180 133 36
40960 -216 158 10 236 178 12 239 182 13 236 178 12
40961 -230 174 11 226 170 11 226 170 11 230 174 11
40962 -236 178 12 242 186 14 246 190 14 246 190 14
40963 -246 190 14 246 190 14 246 186 14 239 182 13
40964 -206 162 42 106 106 106 66 66 66 34 34 34
40965 - 14 14 14 6 6 6 0 0 0 0 0 0
40966 - 0 0 0 0 0 0 0 0 0 0 0 0
40967 - 0 0 0 0 0 0 0 0 0 0 0 0
40968 - 0 0 0 0 0 0 0 0 0 6 6 6
40969 - 26 26 26 70 70 70 163 133 67 213 154 11
40970 -236 178 12 246 190 14 246 190 14 246 190 14
40971 -246 190 14 246 190 14 246 190 14 246 190 14
40972 -246 190 14 246 190 14 246 190 14 246 190 14
40973 -246 190 14 246 190 14 246 190 14 241 196 14
40974 -190 146 13 18 14 6 2 2 6 2 2 6
40975 - 46 46 46 246 246 246 253 253 253 253 253 253
40976 -253 253 253 253 253 253 253 253 253 253 253 253
40977 -253 253 253 253 253 253 253 253 253 253 253 253
40978 -253 253 253 253 253 253 253 253 253 253 253 253
40979 -253 253 253 221 221 221 86 86 86 156 107 11
40980 -216 158 10 236 178 12 242 186 14 246 186 14
40981 -242 186 14 239 182 13 239 182 13 242 186 14
40982 -242 186 14 246 186 14 246 190 14 246 190 14
40983 -246 190 14 246 190 14 246 190 14 246 190 14
40984 -242 186 14 225 175 15 142 122 72 66 66 66
40985 - 30 30 30 10 10 10 0 0 0 0 0 0
40986 - 0 0 0 0 0 0 0 0 0 0 0 0
40987 - 0 0 0 0 0 0 0 0 0 0 0 0
40988 - 0 0 0 0 0 0 0 0 0 6 6 6
40989 - 26 26 26 70 70 70 163 133 67 210 150 10
40990 -236 178 12 246 190 14 246 190 14 246 190 14
40991 -246 190 14 246 190 14 246 190 14 246 190 14
40992 -246 190 14 246 190 14 246 190 14 246 190 14
40993 -246 190 14 246 190 14 246 190 14 246 190 14
40994 -232 195 16 121 92 8 34 34 34 106 106 106
40995 -221 221 221 253 253 253 253 253 253 253 253 253
40996 -253 253 253 253 253 253 253 253 253 253 253 253
40997 -253 253 253 253 253 253 253 253 253 253 253 253
40998 -253 253 253 253 253 253 253 253 253 253 253 253
40999 -242 242 242 82 82 82 18 14 6 163 110 8
41000 -216 158 10 236 178 12 242 186 14 246 190 14
41001 -246 190 14 246 190 14 246 190 14 246 190 14
41002 -246 190 14 246 190 14 246 190 14 246 190 14
41003 -246 190 14 246 190 14 246 190 14 246 190 14
41004 -246 190 14 246 190 14 242 186 14 163 133 67
41005 - 46 46 46 18 18 18 6 6 6 0 0 0
41006 - 0 0 0 0 0 0 0 0 0 0 0 0
41007 - 0 0 0 0 0 0 0 0 0 0 0 0
41008 - 0 0 0 0 0 0 0 0 0 10 10 10
41009 - 30 30 30 78 78 78 163 133 67 210 150 10
41010 -236 178 12 246 186 14 246 190 14 246 190 14
41011 -246 190 14 246 190 14 246 190 14 246 190 14
41012 -246 190 14 246 190 14 246 190 14 246 190 14
41013 -246 190 14 246 190 14 246 190 14 246 190 14
41014 -241 196 14 215 174 15 190 178 144 253 253 253
41015 -253 253 253 253 253 253 253 253 253 253 253 253
41016 -253 253 253 253 253 253 253 253 253 253 253 253
41017 -253 253 253 253 253 253 253 253 253 253 253 253
41018 -253 253 253 253 253 253 253 253 253 218 218 218
41019 - 58 58 58 2 2 6 22 18 6 167 114 7
41020 -216 158 10 236 178 12 246 186 14 246 190 14
41021 -246 190 14 246 190 14 246 190 14 246 190 14
41022 -246 190 14 246 190 14 246 190 14 246 190 14
41023 -246 190 14 246 190 14 246 190 14 246 190 14
41024 -246 190 14 246 186 14 242 186 14 190 150 46
41025 - 54 54 54 22 22 22 6 6 6 0 0 0
41026 - 0 0 0 0 0 0 0 0 0 0 0 0
41027 - 0 0 0 0 0 0 0 0 0 0 0 0
41028 - 0 0 0 0 0 0 0 0 0 14 14 14
41029 - 38 38 38 86 86 86 180 133 36 213 154 11
41030 -236 178 12 246 186 14 246 190 14 246 190 14
41031 -246 190 14 246 190 14 246 190 14 246 190 14
41032 -246 190 14 246 190 14 246 190 14 246 190 14
41033 -246 190 14 246 190 14 246 190 14 246 190 14
41034 -246 190 14 232 195 16 190 146 13 214 214 214
41035 -253 253 253 253 253 253 253 253 253 253 253 253
41036 -253 253 253 253 253 253 253 253 253 253 253 253
41037 -253 253 253 253 253 253 253 253 253 253 253 253
41038 -253 253 253 250 250 250 170 170 170 26 26 26
41039 - 2 2 6 2 2 6 37 26 9 163 110 8
41040 -219 162 10 239 182 13 246 186 14 246 190 14
41041 -246 190 14 246 190 14 246 190 14 246 190 14
41042 -246 190 14 246 190 14 246 190 14 246 190 14
41043 -246 190 14 246 190 14 246 190 14 246 190 14
41044 -246 186 14 236 178 12 224 166 10 142 122 72
41045 - 46 46 46 18 18 18 6 6 6 0 0 0
41046 - 0 0 0 0 0 0 0 0 0 0 0 0
41047 - 0 0 0 0 0 0 0 0 0 0 0 0
41048 - 0 0 0 0 0 0 6 6 6 18 18 18
41049 - 50 50 50 109 106 95 192 133 9 224 166 10
41050 -242 186 14 246 190 14 246 190 14 246 190 14
41051 -246 190 14 246 190 14 246 190 14 246 190 14
41052 -246 190 14 246 190 14 246 190 14 246 190 14
41053 -246 190 14 246 190 14 246 190 14 246 190 14
41054 -242 186 14 226 184 13 210 162 10 142 110 46
41055 -226 226 226 253 253 253 253 253 253 253 253 253
41056 -253 253 253 253 253 253 253 253 253 253 253 253
41057 -253 253 253 253 253 253 253 253 253 253 253 253
41058 -198 198 198 66 66 66 2 2 6 2 2 6
41059 - 2 2 6 2 2 6 50 34 6 156 107 11
41060 -219 162 10 239 182 13 246 186 14 246 190 14
41061 -246 190 14 246 190 14 246 190 14 246 190 14
41062 -246 190 14 246 190 14 246 190 14 246 190 14
41063 -246 190 14 246 190 14 246 190 14 242 186 14
41064 -234 174 13 213 154 11 154 122 46 66 66 66
41065 - 30 30 30 10 10 10 0 0 0 0 0 0
41066 - 0 0 0 0 0 0 0 0 0 0 0 0
41067 - 0 0 0 0 0 0 0 0 0 0 0 0
41068 - 0 0 0 0 0 0 6 6 6 22 22 22
41069 - 58 58 58 154 121 60 206 145 10 234 174 13
41070 -242 186 14 246 186 14 246 190 14 246 190 14
41071 -246 190 14 246 190 14 246 190 14 246 190 14
41072 -246 190 14 246 190 14 246 190 14 246 190 14
41073 -246 190 14 246 190 14 246 190 14 246 190 14
41074 -246 186 14 236 178 12 210 162 10 163 110 8
41075 - 61 42 6 138 138 138 218 218 218 250 250 250
41076 -253 253 253 253 253 253 253 253 253 250 250 250
41077 -242 242 242 210 210 210 144 144 144 66 66 66
41078 - 6 6 6 2 2 6 2 2 6 2 2 6
41079 - 2 2 6 2 2 6 61 42 6 163 110 8
41080 -216 158 10 236 178 12 246 190 14 246 190 14
41081 -246 190 14 246 190 14 246 190 14 246 190 14
41082 -246 190 14 246 190 14 246 190 14 246 190 14
41083 -246 190 14 239 182 13 230 174 11 216 158 10
41084 -190 142 34 124 112 88 70 70 70 38 38 38
41085 - 18 18 18 6 6 6 0 0 0 0 0 0
41086 - 0 0 0 0 0 0 0 0 0 0 0 0
41087 - 0 0 0 0 0 0 0 0 0 0 0 0
41088 - 0 0 0 0 0 0 6 6 6 22 22 22
41089 - 62 62 62 168 124 44 206 145 10 224 166 10
41090 -236 178 12 239 182 13 242 186 14 242 186 14
41091 -246 186 14 246 190 14 246 190 14 246 190 14
41092 -246 190 14 246 190 14 246 190 14 246 190 14
41093 -246 190 14 246 190 14 246 190 14 246 190 14
41094 -246 190 14 236 178 12 216 158 10 175 118 6
41095 - 80 54 7 2 2 6 6 6 6 30 30 30
41096 - 54 54 54 62 62 62 50 50 50 38 38 38
41097 - 14 14 14 2 2 6 2 2 6 2 2 6
41098 - 2 2 6 2 2 6 2 2 6 2 2 6
41099 - 2 2 6 6 6 6 80 54 7 167 114 7
41100 -213 154 11 236 178 12 246 190 14 246 190 14
41101 -246 190 14 246 190 14 246 190 14 246 190 14
41102 -246 190 14 242 186 14 239 182 13 239 182 13
41103 -230 174 11 210 150 10 174 135 50 124 112 88
41104 - 82 82 82 54 54 54 34 34 34 18 18 18
41105 - 6 6 6 0 0 0 0 0 0 0 0 0
41106 - 0 0 0 0 0 0 0 0 0 0 0 0
41107 - 0 0 0 0 0 0 0 0 0 0 0 0
41108 - 0 0 0 0 0 0 6 6 6 18 18 18
41109 - 50 50 50 158 118 36 192 133 9 200 144 11
41110 -216 158 10 219 162 10 224 166 10 226 170 11
41111 -230 174 11 236 178 12 239 182 13 239 182 13
41112 -242 186 14 246 186 14 246 190 14 246 190 14
41113 -246 190 14 246 190 14 246 190 14 246 190 14
41114 -246 186 14 230 174 11 210 150 10 163 110 8
41115 -104 69 6 10 10 10 2 2 6 2 2 6
41116 - 2 2 6 2 2 6 2 2 6 2 2 6
41117 - 2 2 6 2 2 6 2 2 6 2 2 6
41118 - 2 2 6 2 2 6 2 2 6 2 2 6
41119 - 2 2 6 6 6 6 91 60 6 167 114 7
41120 -206 145 10 230 174 11 242 186 14 246 190 14
41121 -246 190 14 246 190 14 246 186 14 242 186 14
41122 -239 182 13 230 174 11 224 166 10 213 154 11
41123 -180 133 36 124 112 88 86 86 86 58 58 58
41124 - 38 38 38 22 22 22 10 10 10 6 6 6
41125 - 0 0 0 0 0 0 0 0 0 0 0 0
41126 - 0 0 0 0 0 0 0 0 0 0 0 0
41127 - 0 0 0 0 0 0 0 0 0 0 0 0
41128 - 0 0 0 0 0 0 0 0 0 14 14 14
41129 - 34 34 34 70 70 70 138 110 50 158 118 36
41130 -167 114 7 180 123 7 192 133 9 197 138 11
41131 -200 144 11 206 145 10 213 154 11 219 162 10
41132 -224 166 10 230 174 11 239 182 13 242 186 14
41133 -246 186 14 246 186 14 246 186 14 246 186 14
41134 -239 182 13 216 158 10 185 133 11 152 99 6
41135 -104 69 6 18 14 6 2 2 6 2 2 6
41136 - 2 2 6 2 2 6 2 2 6 2 2 6
41137 - 2 2 6 2 2 6 2 2 6 2 2 6
41138 - 2 2 6 2 2 6 2 2 6 2 2 6
41139 - 2 2 6 6 6 6 80 54 7 152 99 6
41140 -192 133 9 219 162 10 236 178 12 239 182 13
41141 -246 186 14 242 186 14 239 182 13 236 178 12
41142 -224 166 10 206 145 10 192 133 9 154 121 60
41143 - 94 94 94 62 62 62 42 42 42 22 22 22
41144 - 14 14 14 6 6 6 0 0 0 0 0 0
41145 - 0 0 0 0 0 0 0 0 0 0 0 0
41146 - 0 0 0 0 0 0 0 0 0 0 0 0
41147 - 0 0 0 0 0 0 0 0 0 0 0 0
41148 - 0 0 0 0 0 0 0 0 0 6 6 6
41149 - 18 18 18 34 34 34 58 58 58 78 78 78
41150 -101 98 89 124 112 88 142 110 46 156 107 11
41151 -163 110 8 167 114 7 175 118 6 180 123 7
41152 -185 133 11 197 138 11 210 150 10 219 162 10
41153 -226 170 11 236 178 12 236 178 12 234 174 13
41154 -219 162 10 197 138 11 163 110 8 130 83 6
41155 - 91 60 6 10 10 10 2 2 6 2 2 6
41156 - 18 18 18 38 38 38 38 38 38 38 38 38
41157 - 38 38 38 38 38 38 38 38 38 38 38 38
41158 - 38 38 38 38 38 38 26 26 26 2 2 6
41159 - 2 2 6 6 6 6 70 47 6 137 92 6
41160 -175 118 6 200 144 11 219 162 10 230 174 11
41161 -234 174 13 230 174 11 219 162 10 210 150 10
41162 -192 133 9 163 110 8 124 112 88 82 82 82
41163 - 50 50 50 30 30 30 14 14 14 6 6 6
41164 - 0 0 0 0 0 0 0 0 0 0 0 0
41165 - 0 0 0 0 0 0 0 0 0 0 0 0
41166 - 0 0 0 0 0 0 0 0 0 0 0 0
41167 - 0 0 0 0 0 0 0 0 0 0 0 0
41168 - 0 0 0 0 0 0 0 0 0 0 0 0
41169 - 6 6 6 14 14 14 22 22 22 34 34 34
41170 - 42 42 42 58 58 58 74 74 74 86 86 86
41171 -101 98 89 122 102 70 130 98 46 121 87 25
41172 -137 92 6 152 99 6 163 110 8 180 123 7
41173 -185 133 11 197 138 11 206 145 10 200 144 11
41174 -180 123 7 156 107 11 130 83 6 104 69 6
41175 - 50 34 6 54 54 54 110 110 110 101 98 89
41176 - 86 86 86 82 82 82 78 78 78 78 78 78
41177 - 78 78 78 78 78 78 78 78 78 78 78 78
41178 - 78 78 78 82 82 82 86 86 86 94 94 94
41179 -106 106 106 101 101 101 86 66 34 124 80 6
41180 -156 107 11 180 123 7 192 133 9 200 144 11
41181 -206 145 10 200 144 11 192 133 9 175 118 6
41182 -139 102 15 109 106 95 70 70 70 42 42 42
41183 - 22 22 22 10 10 10 0 0 0 0 0 0
41184 - 0 0 0 0 0 0 0 0 0 0 0 0
41185 - 0 0 0 0 0 0 0 0 0 0 0 0
41186 - 0 0 0 0 0 0 0 0 0 0 0 0
41187 - 0 0 0 0 0 0 0 0 0 0 0 0
41188 - 0 0 0 0 0 0 0 0 0 0 0 0
41189 - 0 0 0 0 0 0 6 6 6 10 10 10
41190 - 14 14 14 22 22 22 30 30 30 38 38 38
41191 - 50 50 50 62 62 62 74 74 74 90 90 90
41192 -101 98 89 112 100 78 121 87 25 124 80 6
41193 -137 92 6 152 99 6 152 99 6 152 99 6
41194 -138 86 6 124 80 6 98 70 6 86 66 30
41195 -101 98 89 82 82 82 58 58 58 46 46 46
41196 - 38 38 38 34 34 34 34 34 34 34 34 34
41197 - 34 34 34 34 34 34 34 34 34 34 34 34
41198 - 34 34 34 34 34 34 38 38 38 42 42 42
41199 - 54 54 54 82 82 82 94 86 76 91 60 6
41200 -134 86 6 156 107 11 167 114 7 175 118 6
41201 -175 118 6 167 114 7 152 99 6 121 87 25
41202 -101 98 89 62 62 62 34 34 34 18 18 18
41203 - 6 6 6 0 0 0 0 0 0 0 0 0
41204 - 0 0 0 0 0 0 0 0 0 0 0 0
41205 - 0 0 0 0 0 0 0 0 0 0 0 0
41206 - 0 0 0 0 0 0 0 0 0 0 0 0
41207 - 0 0 0 0 0 0 0 0 0 0 0 0
41208 - 0 0 0 0 0 0 0 0 0 0 0 0
41209 - 0 0 0 0 0 0 0 0 0 0 0 0
41210 - 0 0 0 6 6 6 6 6 6 10 10 10
41211 - 18 18 18 22 22 22 30 30 30 42 42 42
41212 - 50 50 50 66 66 66 86 86 86 101 98 89
41213 -106 86 58 98 70 6 104 69 6 104 69 6
41214 -104 69 6 91 60 6 82 62 34 90 90 90
41215 - 62 62 62 38 38 38 22 22 22 14 14 14
41216 - 10 10 10 10 10 10 10 10 10 10 10 10
41217 - 10 10 10 10 10 10 6 6 6 10 10 10
41218 - 10 10 10 10 10 10 10 10 10 14 14 14
41219 - 22 22 22 42 42 42 70 70 70 89 81 66
41220 - 80 54 7 104 69 6 124 80 6 137 92 6
41221 -134 86 6 116 81 8 100 82 52 86 86 86
41222 - 58 58 58 30 30 30 14 14 14 6 6 6
41223 - 0 0 0 0 0 0 0 0 0 0 0 0
41224 - 0 0 0 0 0 0 0 0 0 0 0 0
41225 - 0 0 0 0 0 0 0 0 0 0 0 0
41226 - 0 0 0 0 0 0 0 0 0 0 0 0
41227 - 0 0 0 0 0 0 0 0 0 0 0 0
41228 - 0 0 0 0 0 0 0 0 0 0 0 0
41229 - 0 0 0 0 0 0 0 0 0 0 0 0
41230 - 0 0 0 0 0 0 0 0 0 0 0 0
41231 - 0 0 0 6 6 6 10 10 10 14 14 14
41232 - 18 18 18 26 26 26 38 38 38 54 54 54
41233 - 70 70 70 86 86 86 94 86 76 89 81 66
41234 - 89 81 66 86 86 86 74 74 74 50 50 50
41235 - 30 30 30 14 14 14 6 6 6 0 0 0
41236 - 0 0 0 0 0 0 0 0 0 0 0 0
41237 - 0 0 0 0 0 0 0 0 0 0 0 0
41238 - 0 0 0 0 0 0 0 0 0 0 0 0
41239 - 6 6 6 18 18 18 34 34 34 58 58 58
41240 - 82 82 82 89 81 66 89 81 66 89 81 66
41241 - 94 86 66 94 86 76 74 74 74 50 50 50
41242 - 26 26 26 14 14 14 6 6 6 0 0 0
41243 - 0 0 0 0 0 0 0 0 0 0 0 0
41244 - 0 0 0 0 0 0 0 0 0 0 0 0
41245 - 0 0 0 0 0 0 0 0 0 0 0 0
41246 - 0 0 0 0 0 0 0 0 0 0 0 0
41247 - 0 0 0 0 0 0 0 0 0 0 0 0
41248 - 0 0 0 0 0 0 0 0 0 0 0 0
41249 - 0 0 0 0 0 0 0 0 0 0 0 0
41250 - 0 0 0 0 0 0 0 0 0 0 0 0
41251 - 0 0 0 0 0 0 0 0 0 0 0 0
41252 - 6 6 6 6 6 6 14 14 14 18 18 18
41253 - 30 30 30 38 38 38 46 46 46 54 54 54
41254 - 50 50 50 42 42 42 30 30 30 18 18 18
41255 - 10 10 10 0 0 0 0 0 0 0 0 0
41256 - 0 0 0 0 0 0 0 0 0 0 0 0
41257 - 0 0 0 0 0 0 0 0 0 0 0 0
41258 - 0 0 0 0 0 0 0 0 0 0 0 0
41259 - 0 0 0 6 6 6 14 14 14 26 26 26
41260 - 38 38 38 50 50 50 58 58 58 58 58 58
41261 - 54 54 54 42 42 42 30 30 30 18 18 18
41262 - 10 10 10 0 0 0 0 0 0 0 0 0
41263 - 0 0 0 0 0 0 0 0 0 0 0 0
41264 - 0 0 0 0 0 0 0 0 0 0 0 0
41265 - 0 0 0 0 0 0 0 0 0 0 0 0
41266 - 0 0 0 0 0 0 0 0 0 0 0 0
41267 - 0 0 0 0 0 0 0 0 0 0 0 0
41268 - 0 0 0 0 0 0 0 0 0 0 0 0
41269 - 0 0 0 0 0 0 0 0 0 0 0 0
41270 - 0 0 0 0 0 0 0 0 0 0 0 0
41271 - 0 0 0 0 0 0 0 0 0 0 0 0
41272 - 0 0 0 0 0 0 0 0 0 6 6 6
41273 - 6 6 6 10 10 10 14 14 14 18 18 18
41274 - 18 18 18 14 14 14 10 10 10 6 6 6
41275 - 0 0 0 0 0 0 0 0 0 0 0 0
41276 - 0 0 0 0 0 0 0 0 0 0 0 0
41277 - 0 0 0 0 0 0 0 0 0 0 0 0
41278 - 0 0 0 0 0 0 0 0 0 0 0 0
41279 - 0 0 0 0 0 0 0 0 0 6 6 6
41280 - 14 14 14 18 18 18 22 22 22 22 22 22
41281 - 18 18 18 14 14 14 10 10 10 6 6 6
41282 - 0 0 0 0 0 0 0 0 0 0 0 0
41283 - 0 0 0 0 0 0 0 0 0 0 0 0
41284 - 0 0 0 0 0 0 0 0 0 0 0 0
41285 - 0 0 0 0 0 0 0 0 0 0 0 0
41286 - 0 0 0 0 0 0 0 0 0 0 0 0
41287 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41288 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41289 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41290 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41291 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41292 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41293 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4
41297 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41298 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41299 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41300 +4 4 4 4 4 4
41301 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41302 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41303 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41304 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41305 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41306 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41307 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4
41311 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41312 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41313 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41314 +4 4 4 4 4 4
41315 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41316 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41317 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41318 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41319 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41320 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41321 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
41325 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41326 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41327 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41328 +4 4 4 4 4 4
41329 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41330 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41331 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41332 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41333 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41334 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41335 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41336 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41337 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41338 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41339 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41340 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41341 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41342 +4 4 4 4 4 4
41343 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41344 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41345 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41346 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41347 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41348 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41349 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41350 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41351 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41352 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41353 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41354 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41355 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41356 +4 4 4 4 4 4
41357 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41358 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41359 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41360 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41361 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41362 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41363 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41364 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41365 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41366 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41367 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41368 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41369 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41370 +4 4 4 4 4 4
41371 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41372 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41373 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41374 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41375 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
41376 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
41377 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41378 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41379 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41380 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
41381 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41382 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
41383 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41384 +4 4 4 4 4 4
41385 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41386 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41387 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41388 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41389 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
41390 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
41391 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41392 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41393 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41394 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
41395 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
41396 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
41397 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41398 +4 4 4 4 4 4
41399 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41400 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41401 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41402 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41403 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
41404 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
41405 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41406 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41407 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41408 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
41409 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
41410 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
41411 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
41412 +4 4 4 4 4 4
41413 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41414 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41415 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41416 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
41417 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
41418 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
41419 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
41420 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41421 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41422 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
41423 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
41424 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
41425 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
41426 +4 4 4 4 4 4
41427 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41428 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41429 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41430 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
41431 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
41432 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
41433 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
41434 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41435 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
41436 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
41437 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
41438 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
41439 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
41440 +4 4 4 4 4 4
41441 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41442 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41443 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41444 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
41445 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
41446 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
41447 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
41448 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
41449 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
41450 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
41451 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
41452 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
41453 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
41454 +4 4 4 4 4 4
41455 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41456 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41457 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
41458 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
41459 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
41460 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
41461 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
41462 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
41463 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
41464 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
41465 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
41466 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
41467 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
41468 +4 4 4 4 4 4
41469 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41470 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41471 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
41472 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
41473 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
41474 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
41475 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
41476 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
41477 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
41478 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
41479 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
41480 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
41481 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
41482 +4 4 4 4 4 4
41483 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41484 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41485 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
41486 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
41487 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
41488 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
41489 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
41490 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
41491 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
41492 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
41493 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
41494 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
41495 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41496 +4 4 4 4 4 4
41497 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41498 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41499 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
41500 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
41501 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
41502 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
41503 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
41504 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
41505 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
41506 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
41507 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
41508 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
41509 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
41510 +4 4 4 4 4 4
41511 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41512 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
41513 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
41514 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
41515 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
41516 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
41517 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
41518 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
41519 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
41520 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
41521 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
41522 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
41523 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
41524 +4 4 4 4 4 4
41525 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41526 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
41527 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
41528 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
41529 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41530 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
41531 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
41532 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
41533 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
41534 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
41535 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
41536 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
41537 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
41538 +0 0 0 4 4 4
41539 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41540 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
41541 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
41542 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
41543 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
41544 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
41545 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
41546 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
41547 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
41548 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
41549 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
41550 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
41551 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
41552 +2 0 0 0 0 0
41553 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
41554 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
41555 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
41556 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
41557 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
41558 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
41559 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
41560 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
41561 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
41562 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
41563 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
41564 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
41565 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
41566 +37 38 37 0 0 0
41567 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41568 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
41569 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
41570 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
41571 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
41572 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
41573 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
41574 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
41575 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
41576 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
41577 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
41578 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
41579 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
41580 +85 115 134 4 0 0
41581 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
41582 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
41583 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
41584 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
41585 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
41586 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
41587 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
41588 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
41589 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
41590 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
41591 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
41592 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
41593 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
41594 +60 73 81 4 0 0
41595 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
41596 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
41597 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
41598 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
41599 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
41600 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
41601 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
41602 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
41603 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
41604 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
41605 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
41606 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
41607 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
41608 +16 19 21 4 0 0
41609 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
41610 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
41611 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
41612 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
41613 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
41614 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
41615 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
41616 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
41617 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
41618 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
41619 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
41620 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
41621 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
41622 +4 0 0 4 3 3
41623 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
41624 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
41625 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
41626 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
41627 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
41628 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
41629 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
41630 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
41631 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
41632 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
41633 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
41634 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
41635 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
41636 +3 2 2 4 4 4
41637 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
41638 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
41639 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
41640 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41641 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
41642 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
41643 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
41644 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
41645 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
41646 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
41647 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
41648 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
41649 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
41650 +4 4 4 4 4 4
41651 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
41652 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
41653 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
41654 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
41655 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
41656 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
41657 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
41658 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
41659 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
41660 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
41661 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
41662 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
41663 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
41664 +4 4 4 4 4 4
41665 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
41666 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
41667 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
41668 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
41669 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
41670 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41671 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
41672 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
41673 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
41674 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
41675 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
41676 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
41677 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
41678 +5 5 5 5 5 5
41679 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
41680 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
41681 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
41682 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
41683 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
41684 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41685 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
41686 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
41687 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
41688 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
41689 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
41690 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
41691 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41692 +5 5 5 4 4 4
41693 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
41694 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
41695 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
41696 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
41697 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41698 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
41699 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
41700 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
41701 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
41702 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
41703 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
41704 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41705 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41706 +4 4 4 4 4 4
41707 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
41708 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
41709 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
41710 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
41711 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
41712 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41713 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41714 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
41715 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
41716 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
41717 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
41718 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
41719 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41720 +4 4 4 4 4 4
41721 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
41722 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
41723 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
41724 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
41725 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41726 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
41727 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
41728 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
41729 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
41730 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
41731 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
41732 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41733 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41734 +4 4 4 4 4 4
41735 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
41736 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
41737 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
41738 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
41739 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41740 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41741 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41742 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
41743 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
41744 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
41745 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
41746 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41747 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41748 +4 4 4 4 4 4
41749 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
41750 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
41751 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
41752 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
41753 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41754 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
41755 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41756 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
41757 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
41758 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
41759 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41760 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41761 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41762 +4 4 4 4 4 4
41763 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
41764 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
41765 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
41766 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
41767 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41768 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
41769 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
41770 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
41771 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
41772 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
41773 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
41774 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41775 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41776 +4 4 4 4 4 4
41777 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
41778 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
41779 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
41780 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
41781 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41782 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
41783 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
41784 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
41785 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
41786 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
41787 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
41788 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41789 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41790 +4 4 4 4 4 4
41791 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
41792 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
41793 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
41794 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41795 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
41796 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
41797 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
41798 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
41799 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
41800 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
41801 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41802 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41803 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41804 +4 4 4 4 4 4
41805 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
41806 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
41807 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
41808 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41809 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41810 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
41811 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
41812 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
41813 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
41814 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
41815 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41816 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41817 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41818 +4 4 4 4 4 4
41819 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
41820 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
41821 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41822 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41823 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41824 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
41825 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
41826 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
41827 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
41828 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
41829 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41830 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41831 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41832 +4 4 4 4 4 4
41833 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
41834 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
41835 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41836 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41837 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41838 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
41839 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
41840 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
41841 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41842 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41843 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41844 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41845 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41846 +4 4 4 4 4 4
41847 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41848 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
41849 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41850 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
41851 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
41852 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
41853 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
41854 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
41855 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41856 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41857 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41858 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41859 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41860 +4 4 4 4 4 4
41861 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41862 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
41863 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41864 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
41865 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41866 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
41867 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
41868 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
41869 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41870 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41871 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41872 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41873 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41874 +4 4 4 4 4 4
41875 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
41876 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
41877 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41878 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
41879 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
41880 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
41881 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
41882 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
41883 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41884 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41885 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41886 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41887 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41888 +4 4 4 4 4 4
41889 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
41890 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
41891 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41892 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
41893 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
41894 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
41895 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
41896 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
41897 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41898 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41899 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41900 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41901 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41902 +4 4 4 4 4 4
41903 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41904 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
41905 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41906 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
41907 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
41908 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
41909 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
41910 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
41911 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41912 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41913 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41914 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41915 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41916 +4 4 4 4 4 4
41917 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
41918 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
41919 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41920 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
41921 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
41922 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
41923 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
41924 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
41925 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
41926 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41927 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41928 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41929 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41930 +4 4 4 4 4 4
41931 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41932 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
41933 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
41934 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
41935 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
41936 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
41937 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
41938 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
41939 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41940 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41941 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41942 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41943 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41944 +4 4 4 4 4 4
41945 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41946 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
41947 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41948 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
41949 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
41950 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
41951 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
41952 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
41953 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41954 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41955 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41956 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41957 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41958 +4 4 4 4 4 4
41959 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41960 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
41961 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
41962 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
41963 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
41964 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
41965 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41966 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
41967 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41968 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41969 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41970 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41971 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41972 +4 4 4 4 4 4
41973 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41974 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
41975 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
41976 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41977 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
41978 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
41979 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41980 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
41981 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41982 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41983 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41984 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41985 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41986 +4 4 4 4 4 4
41987 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41988 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
41989 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
41990 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
41991 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
41992 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
41993 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
41994 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
41995 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
41996 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41997 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41998 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41999 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42000 +4 4 4 4 4 4
42001 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
42002 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
42003 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
42004 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
42005 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
42006 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
42007 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
42008 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
42009 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
42010 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42011 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42012 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42013 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42014 +4 4 4 4 4 4
42015 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
42016 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
42017 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
42018 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
42019 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
42020 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
42021 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
42022 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
42023 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
42024 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42025 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42026 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42027 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42028 +4 4 4 4 4 4
42029 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
42030 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
42031 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
42032 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
42033 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
42034 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
42035 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
42036 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
42037 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
42038 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42039 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42040 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42041 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42042 +4 4 4 4 4 4
42043 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
42044 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
42045 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
42046 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
42047 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
42048 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
42049 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
42050 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
42051 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
42052 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
42053 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42054 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42055 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42056 +4 4 4 4 4 4
42057 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
42058 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
42059 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
42060 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
42061 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
42062 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
42063 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
42064 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
42065 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
42066 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
42067 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42068 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42069 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42070 +4 4 4 4 4 4
42071 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
42072 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
42073 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
42074 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
42075 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
42076 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
42077 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42078 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
42079 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
42080 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
42081 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42082 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42083 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42084 +4 4 4 4 4 4
42085 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
42086 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
42087 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
42088 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
42089 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
42090 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
42091 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
42092 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
42093 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
42094 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
42095 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42096 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42097 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42098 +4 4 4 4 4 4
42099 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
42100 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
42101 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
42102 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
42103 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
42104 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
42105 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
42106 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
42107 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
42108 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
42109 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42110 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42111 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42112 +4 4 4 4 4 4
42113 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42114 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
42115 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
42116 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
42117 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
42118 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
42119 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
42120 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
42121 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
42122 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
42123 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42124 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42125 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42126 +4 4 4 4 4 4
42127 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
42128 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
42129 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
42130 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
42131 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
42132 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
42133 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
42134 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
42135 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
42136 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
42137 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42138 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42139 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42140 +4 4 4 4 4 4
42141 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
42142 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
42143 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
42144 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
42145 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
42146 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
42147 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
42148 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
42149 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
42150 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42151 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42152 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42153 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42154 +4 4 4 4 4 4
42155 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
42156 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42157 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
42158 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
42159 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
42160 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
42161 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
42162 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
42163 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
42164 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42165 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42166 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42167 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42168 +4 4 4 4 4 4
42169 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
42170 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
42171 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
42172 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
42173 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
42174 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
42175 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
42176 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
42177 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
42178 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42179 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42180 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42181 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42182 +4 4 4 4 4 4
42183 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
42184 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
42185 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
42186 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
42187 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
42188 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
42189 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
42190 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
42191 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42192 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42193 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42194 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42195 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42196 +4 4 4 4 4 4
42197 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
42198 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
42199 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42200 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
42201 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
42202 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
42203 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
42204 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
42205 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42206 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42207 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42208 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42209 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42210 +4 4 4 4 4 4
42211 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
42212 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
42213 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
42214 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
42215 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
42216 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
42217 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
42218 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
42219 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42220 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42221 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42222 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42223 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42224 +4 4 4 4 4 4
42225 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42226 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
42227 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42228 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
42229 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
42230 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
42231 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
42232 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
42233 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42234 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42235 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42236 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42237 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42238 +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 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
42241 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
42242 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
42243 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
42244 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
42245 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
42246 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
42247 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42248 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42249 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42250 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42251 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42252 +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 5 5 5 5 5 5 5 5 5
42255 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
42256 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42257 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
42258 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
42259 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
42260 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42261 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42262 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42263 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42264 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42265 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42266 +4 4 4 4 4 4
42267 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42268 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42269 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42270 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
42271 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
42272 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
42273 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
42274 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42275 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42276 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42277 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42278 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42279 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42280 +4 4 4 4 4 4
42281 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42282 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42283 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42284 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42285 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
42286 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
42287 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
42288 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42289 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42290 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42291 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42292 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42293 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42294 +4 4 4 4 4 4
42295 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42296 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42297 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42298 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42299 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42300 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
42301 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
42302 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42303 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42304 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42305 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42306 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42307 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42308 +4 4 4 4 4 4
42309 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42310 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42311 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42312 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
42313 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42314 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42315 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
42316 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42317 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42318 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42319 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42320 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42321 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42322 +4 4 4 4 4 4
42323 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42324 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42325 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42326 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
42327 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
42328 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
42329 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
42330 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42331 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42332 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42333 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42334 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42335 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42336 +4 4 4 4 4 4
42337 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42338 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42339 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42340 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42341 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
42342 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42343 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42344 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42345 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42346 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42347 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42348 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42349 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42350 +4 4 4 4 4 4
42351 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42352 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42353 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42354 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42355 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
42356 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
42357 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
42358 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42359 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42360 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42361 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42362 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42363 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42364 +4 4 4 4 4 4
42365 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42366 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42367 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42368 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42369 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
42370 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
42371 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42372 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42373 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42374 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42375 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42376 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42377 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42378 +4 4 4 4 4 4
42379 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42380 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42381 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42382 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42383 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
42384 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
42385 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42386 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42387 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42388 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42389 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42390 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42391 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42392 +4 4 4 4 4 4
42393 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42394 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42395 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42396 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42397 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
42398 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
42399 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42400 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42401 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42402 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42403 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42404 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42405 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42406 +4 4 4 4 4 4
42407 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
42408 index 38fcfff..0072dcd 100644
42409 --- a/drivers/video/udlfb.c
42410 +++ b/drivers/video/udlfb.c
42411 @@ -620,11 +620,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
42412 dlfb_urb_completion(urb);
42413
42414 error:
42415 - atomic_add(bytes_sent, &dev->bytes_sent);
42416 - atomic_add(bytes_identical, &dev->bytes_identical);
42417 - atomic_add(width*height*2, &dev->bytes_rendered);
42418 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42419 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42420 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
42421 end_cycles = get_cycles();
42422 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
42423 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42424 >> 10)), /* Kcycles */
42425 &dev->cpu_kcycles_used);
42426
42427 @@ -745,11 +745,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
42428 dlfb_urb_completion(urb);
42429
42430 error:
42431 - atomic_add(bytes_sent, &dev->bytes_sent);
42432 - atomic_add(bytes_identical, &dev->bytes_identical);
42433 - atomic_add(bytes_rendered, &dev->bytes_rendered);
42434 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42435 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42436 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
42437 end_cycles = get_cycles();
42438 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
42439 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42440 >> 10)), /* Kcycles */
42441 &dev->cpu_kcycles_used);
42442 }
42443 @@ -1373,7 +1373,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
42444 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42445 struct dlfb_data *dev = fb_info->par;
42446 return snprintf(buf, PAGE_SIZE, "%u\n",
42447 - atomic_read(&dev->bytes_rendered));
42448 + atomic_read_unchecked(&dev->bytes_rendered));
42449 }
42450
42451 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42452 @@ -1381,7 +1381,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42453 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42454 struct dlfb_data *dev = fb_info->par;
42455 return snprintf(buf, PAGE_SIZE, "%u\n",
42456 - atomic_read(&dev->bytes_identical));
42457 + atomic_read_unchecked(&dev->bytes_identical));
42458 }
42459
42460 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42461 @@ -1389,7 +1389,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42462 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42463 struct dlfb_data *dev = fb_info->par;
42464 return snprintf(buf, PAGE_SIZE, "%u\n",
42465 - atomic_read(&dev->bytes_sent));
42466 + atomic_read_unchecked(&dev->bytes_sent));
42467 }
42468
42469 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42470 @@ -1397,7 +1397,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42471 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42472 struct dlfb_data *dev = fb_info->par;
42473 return snprintf(buf, PAGE_SIZE, "%u\n",
42474 - atomic_read(&dev->cpu_kcycles_used));
42475 + atomic_read_unchecked(&dev->cpu_kcycles_used));
42476 }
42477
42478 static ssize_t edid_show(
42479 @@ -1457,10 +1457,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
42480 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42481 struct dlfb_data *dev = fb_info->par;
42482
42483 - atomic_set(&dev->bytes_rendered, 0);
42484 - atomic_set(&dev->bytes_identical, 0);
42485 - atomic_set(&dev->bytes_sent, 0);
42486 - atomic_set(&dev->cpu_kcycles_used, 0);
42487 + atomic_set_unchecked(&dev->bytes_rendered, 0);
42488 + atomic_set_unchecked(&dev->bytes_identical, 0);
42489 + atomic_set_unchecked(&dev->bytes_sent, 0);
42490 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
42491
42492 return count;
42493 }
42494 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
42495 index b0e2a42..e2df3ad 100644
42496 --- a/drivers/video/uvesafb.c
42497 +++ b/drivers/video/uvesafb.c
42498 @@ -19,6 +19,7 @@
42499 #include <linux/io.h>
42500 #include <linux/mutex.h>
42501 #include <linux/slab.h>
42502 +#include <linux/moduleloader.h>
42503 #include <video/edid.h>
42504 #include <video/uvesafb.h>
42505 #ifdef CONFIG_X86
42506 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
42507 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
42508 par->pmi_setpal = par->ypan = 0;
42509 } else {
42510 +
42511 +#ifdef CONFIG_PAX_KERNEXEC
42512 +#ifdef CONFIG_MODULES
42513 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
42514 +#endif
42515 + if (!par->pmi_code) {
42516 + par->pmi_setpal = par->ypan = 0;
42517 + return 0;
42518 + }
42519 +#endif
42520 +
42521 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
42522 + task->t.regs.edi);
42523 +
42524 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42525 + pax_open_kernel();
42526 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
42527 + pax_close_kernel();
42528 +
42529 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
42530 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
42531 +#else
42532 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
42533 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
42534 +#endif
42535 +
42536 printk(KERN_INFO "uvesafb: protected mode interface info at "
42537 "%04x:%04x\n",
42538 (u16)task->t.regs.es, (u16)task->t.regs.edi);
42539 @@ -816,13 +839,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
42540 par->ypan = ypan;
42541
42542 if (par->pmi_setpal || par->ypan) {
42543 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
42544 if (__supported_pte_mask & _PAGE_NX) {
42545 par->pmi_setpal = par->ypan = 0;
42546 printk(KERN_WARNING "uvesafb: NX protection is actively."
42547 "We have better not to use the PMI.\n");
42548 - } else {
42549 + } else
42550 +#endif
42551 uvesafb_vbe_getpmi(task, par);
42552 - }
42553 }
42554 #else
42555 /* The protected mode interface is not available on non-x86. */
42556 @@ -1836,6 +1860,11 @@ out:
42557 if (par->vbe_modes)
42558 kfree(par->vbe_modes);
42559
42560 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42561 + if (par->pmi_code)
42562 + module_free_exec(NULL, par->pmi_code);
42563 +#endif
42564 +
42565 framebuffer_release(info);
42566 return err;
42567 }
42568 @@ -1862,6 +1891,12 @@ static int uvesafb_remove(struct platform_device *dev)
42569 kfree(par->vbe_state_orig);
42570 if (par->vbe_state_saved)
42571 kfree(par->vbe_state_saved);
42572 +
42573 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42574 + if (par->pmi_code)
42575 + module_free_exec(NULL, par->pmi_code);
42576 +#endif
42577 +
42578 }
42579
42580 framebuffer_release(info);
42581 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
42582 index 501b340..86bd4cf 100644
42583 --- a/drivers/video/vesafb.c
42584 +++ b/drivers/video/vesafb.c
42585 @@ -9,6 +9,7 @@
42586 */
42587
42588 #include <linux/module.h>
42589 +#include <linux/moduleloader.h>
42590 #include <linux/kernel.h>
42591 #include <linux/errno.h>
42592 #include <linux/string.h>
42593 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
42594 static int vram_total __initdata; /* Set total amount of memory */
42595 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
42596 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
42597 -static void (*pmi_start)(void) __read_mostly;
42598 -static void (*pmi_pal) (void) __read_mostly;
42599 +static void (*pmi_start)(void) __read_only;
42600 +static void (*pmi_pal) (void) __read_only;
42601 static int depth __read_mostly;
42602 static int vga_compat __read_mostly;
42603 /* --------------------------------------------------------------------- */
42604 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
42605 unsigned int size_vmode;
42606 unsigned int size_remap;
42607 unsigned int size_total;
42608 + void *pmi_code = NULL;
42609
42610 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
42611 return -ENODEV;
42612 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
42613 size_remap = size_total;
42614 vesafb_fix.smem_len = size_remap;
42615
42616 -#ifndef __i386__
42617 - screen_info.vesapm_seg = 0;
42618 -#endif
42619 -
42620 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
42621 printk(KERN_WARNING
42622 "vesafb: cannot reserve video memory at 0x%lx\n",
42623 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
42624 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
42625 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
42626
42627 +#ifdef __i386__
42628 +
42629 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42630 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
42631 + if (!pmi_code)
42632 +#elif !defined(CONFIG_PAX_KERNEXEC)
42633 + if (0)
42634 +#endif
42635 +
42636 +#endif
42637 + screen_info.vesapm_seg = 0;
42638 +
42639 if (screen_info.vesapm_seg) {
42640 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
42641 - screen_info.vesapm_seg,screen_info.vesapm_off);
42642 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
42643 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
42644 }
42645
42646 if (screen_info.vesapm_seg < 0xc000)
42647 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
42648
42649 if (ypan || pmi_setpal) {
42650 unsigned short *pmi_base;
42651 +
42652 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
42653 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
42654 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
42655 +
42656 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42657 + pax_open_kernel();
42658 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
42659 +#else
42660 + pmi_code = pmi_base;
42661 +#endif
42662 +
42663 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
42664 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
42665 +
42666 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42667 + pmi_start = ktva_ktla(pmi_start);
42668 + pmi_pal = ktva_ktla(pmi_pal);
42669 + pax_close_kernel();
42670 +#endif
42671 +
42672 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
42673 if (pmi_base[3]) {
42674 printk(KERN_INFO "vesafb: pmi: ports = ");
42675 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
42676 info->node, info->fix.id);
42677 return 0;
42678 err:
42679 +
42680 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42681 + module_free_exec(NULL, pmi_code);
42682 +#endif
42683 +
42684 if (info->screen_base)
42685 iounmap(info->screen_base);
42686 framebuffer_release(info);
42687 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
42688 index 88714ae..16c2e11 100644
42689 --- a/drivers/video/via/via_clock.h
42690 +++ b/drivers/video/via/via_clock.h
42691 @@ -56,7 +56,7 @@ struct via_clock {
42692
42693 void (*set_engine_pll_state)(u8 state);
42694 void (*set_engine_pll)(struct via_pll_config config);
42695 -};
42696 +} __no_const;
42697
42698
42699 static inline u32 get_pll_internal_frequency(u32 ref_freq,
42700 diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
42701 index 453db0c..604973e 100644
42702 --- a/drivers/virtio/virtio_mmio.c
42703 +++ b/drivers/virtio/virtio_mmio.c
42704 @@ -521,7 +521,7 @@ static int vm_cmdline_set(const char *device,
42705
42706 resources[0].end = memparse(device, &str) - 1;
42707
42708 - processed = sscanf(str, "@%lli:%u%n:%d%n",
42709 + processed = sscanf(str, "@%lli:%llu%n:%d%n",
42710 &base, &resources[1].start, &consumed,
42711 &vm_cmdline_id, &consumed);
42712
42713 diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
42714 index e56c934..fc22f4b 100644
42715 --- a/drivers/xen/xen-pciback/conf_space.h
42716 +++ b/drivers/xen/xen-pciback/conf_space.h
42717 @@ -44,15 +44,15 @@ struct config_field {
42718 struct {
42719 conf_dword_write write;
42720 conf_dword_read read;
42721 - } dw;
42722 + } __no_const dw;
42723 struct {
42724 conf_word_write write;
42725 conf_word_read read;
42726 - } w;
42727 + } __no_const w;
42728 struct {
42729 conf_byte_write write;
42730 conf_byte_read read;
42731 - } b;
42732 + } __no_const b;
42733 } u;
42734 struct list_head list;
42735 };
42736 diff --git a/drivers/xen/xenbus/xenbus_dev_frontend.c b/drivers/xen/xenbus/xenbus_dev_frontend.c
42737 index 89f7625..ac72702 100644
42738 --- a/drivers/xen/xenbus/xenbus_dev_frontend.c
42739 +++ b/drivers/xen/xenbus/xenbus_dev_frontend.c
42740 @@ -458,7 +458,7 @@ static ssize_t xenbus_file_write(struct file *filp,
42741 goto out;
42742
42743 /* Can't write a xenbus message larger we can buffer */
42744 - if ((len + u->len) > sizeof(u->u.buffer)) {
42745 + if (len > sizeof(u->u.buffer) - u->len) {
42746 /* On error, dump existing buffer */
42747 u->len = 0;
42748 rc = -EINVAL;
42749 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
42750 index cbf9dbb..35c3af7 100644
42751 --- a/fs/9p/vfs_inode.c
42752 +++ b/fs/9p/vfs_inode.c
42753 @@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
42754 void
42755 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42756 {
42757 - char *s = nd_get_link(nd);
42758 + const char *s = nd_get_link(nd);
42759
42760 p9_debug(P9_DEBUG_VFS, " %s %s\n",
42761 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
42762 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
42763 index 0225742..1cd4732 100644
42764 --- a/fs/Kconfig.binfmt
42765 +++ b/fs/Kconfig.binfmt
42766 @@ -89,7 +89,7 @@ config HAVE_AOUT
42767
42768 config BINFMT_AOUT
42769 tristate "Kernel support for a.out and ECOFF binaries"
42770 - depends on HAVE_AOUT
42771 + depends on HAVE_AOUT && BROKEN
42772 ---help---
42773 A.out (Assembler.OUTput) is a set of formats for libraries and
42774 executables used in the earliest versions of UNIX. Linux used
42775 diff --git a/fs/aio.c b/fs/aio.c
42776 index 71f613c..9d01f1f 100644
42777 --- a/fs/aio.c
42778 +++ b/fs/aio.c
42779 @@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
42780 size += sizeof(struct io_event) * nr_events;
42781 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
42782
42783 - if (nr_pages < 0)
42784 + if (nr_pages <= 0)
42785 return -EINVAL;
42786
42787 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
42788 @@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
42789 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42790 {
42791 ssize_t ret;
42792 + struct iovec iovstack;
42793
42794 #ifdef CONFIG_COMPAT
42795 if (compat)
42796 ret = compat_rw_copy_check_uvector(type,
42797 (struct compat_iovec __user *)kiocb->ki_buf,
42798 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42799 + kiocb->ki_nbytes, 1, &iovstack,
42800 &kiocb->ki_iovec);
42801 else
42802 #endif
42803 ret = rw_copy_check_uvector(type,
42804 (struct iovec __user *)kiocb->ki_buf,
42805 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42806 + kiocb->ki_nbytes, 1, &iovstack,
42807 &kiocb->ki_iovec);
42808 if (ret < 0)
42809 goto out;
42810 @@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42811 if (ret < 0)
42812 goto out;
42813
42814 + if (kiocb->ki_iovec == &iovstack) {
42815 + kiocb->ki_inline_vec = iovstack;
42816 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
42817 + }
42818 kiocb->ki_nr_segs = kiocb->ki_nbytes;
42819 kiocb->ki_cur_seg = 0;
42820 /* ki_nbytes/left now reflect bytes instead of segs */
42821 diff --git a/fs/attr.c b/fs/attr.c
42822 index 29e38a1..2bc037b 100644
42823 --- a/fs/attr.c
42824 +++ b/fs/attr.c
42825 @@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
42826 unsigned long limit;
42827
42828 limit = rlimit(RLIMIT_FSIZE);
42829 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
42830 if (limit != RLIM_INFINITY && offset > limit)
42831 goto out_sig;
42832 if (offset > inode->i_sb->s_maxbytes)
42833 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
42834 index da8876d..4456166 100644
42835 --- a/fs/autofs4/waitq.c
42836 +++ b/fs/autofs4/waitq.c
42837 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
42838 {
42839 unsigned long sigpipe, flags;
42840 mm_segment_t fs;
42841 - const char *data = (const char *)addr;
42842 + const char __user *data = (const char __force_user *)addr;
42843 ssize_t wr = 0;
42844
42845 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
42846 @@ -348,6 +348,10 @@ static int validate_request(struct autofs_wait_queue **wait,
42847 return 1;
42848 }
42849
42850 +#ifdef CONFIG_GRKERNSEC_HIDESYM
42851 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
42852 +#endif
42853 +
42854 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
42855 enum autofs_notify notify)
42856 {
42857 @@ -381,7 +385,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
42858
42859 /* If this is a direct mount request create a dummy name */
42860 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
42861 +#ifdef CONFIG_GRKERNSEC_HIDESYM
42862 + /* this name does get written to userland via autofs4_write() */
42863 + qstr.len = sprintf(name, "%08lx", atomic_inc_return_unchecked(&autofs_dummy_name_id));
42864 +#else
42865 qstr.len = sprintf(name, "%p", dentry);
42866 +#endif
42867 else {
42868 qstr.len = autofs4_getpath(sbi, dentry, &name);
42869 if (!qstr.len) {
42870 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
42871 index cf7f3c6..f61080d 100644
42872 --- a/fs/befs/linuxvfs.c
42873 +++ b/fs/befs/linuxvfs.c
42874 @@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42875 {
42876 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
42877 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
42878 - char *link = nd_get_link(nd);
42879 + const char *link = nd_get_link(nd);
42880 if (!IS_ERR(link))
42881 kfree(link);
42882 }
42883 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
42884 index d146e18..12d1bd1 100644
42885 --- a/fs/binfmt_aout.c
42886 +++ b/fs/binfmt_aout.c
42887 @@ -16,6 +16,7 @@
42888 #include <linux/string.h>
42889 #include <linux/fs.h>
42890 #include <linux/file.h>
42891 +#include <linux/security.h>
42892 #include <linux/stat.h>
42893 #include <linux/fcntl.h>
42894 #include <linux/ptrace.h>
42895 @@ -83,6 +84,8 @@ static int aout_core_dump(struct coredump_params *cprm)
42896 #endif
42897 # define START_STACK(u) ((void __user *)u.start_stack)
42898
42899 + memset(&dump, 0, sizeof(dump));
42900 +
42901 fs = get_fs();
42902 set_fs(KERNEL_DS);
42903 has_dumped = 1;
42904 @@ -94,10 +97,12 @@ static int aout_core_dump(struct coredump_params *cprm)
42905
42906 /* If the size of the dump file exceeds the rlimit, then see what would happen
42907 if we wrote the stack, but not the data area. */
42908 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
42909 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
42910 dump.u_dsize = 0;
42911
42912 /* Make sure we have enough room to write the stack and data areas. */
42913 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
42914 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
42915 dump.u_ssize = 0;
42916
42917 @@ -231,6 +236,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42918 rlim = rlimit(RLIMIT_DATA);
42919 if (rlim >= RLIM_INFINITY)
42920 rlim = ~0;
42921 +
42922 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
42923 if (ex.a_data + ex.a_bss > rlim)
42924 return -ENOMEM;
42925
42926 @@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42927
42928 install_exec_creds(bprm);
42929
42930 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42931 + current->mm->pax_flags = 0UL;
42932 +#endif
42933 +
42934 +#ifdef CONFIG_PAX_PAGEEXEC
42935 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
42936 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
42937 +
42938 +#ifdef CONFIG_PAX_EMUTRAMP
42939 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
42940 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
42941 +#endif
42942 +
42943 +#ifdef CONFIG_PAX_MPROTECT
42944 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
42945 + current->mm->pax_flags |= MF_PAX_MPROTECT;
42946 +#endif
42947 +
42948 + }
42949 +#endif
42950 +
42951 if (N_MAGIC(ex) == OMAGIC) {
42952 unsigned long text_addr, map_size;
42953 loff_t pos;
42954 @@ -330,7 +358,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42955 }
42956
42957 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
42958 - PROT_READ | PROT_WRITE | PROT_EXEC,
42959 + PROT_READ | PROT_WRITE,
42960 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
42961 fd_offset + ex.a_text);
42962 if (error != N_DATADDR(ex)) {
42963 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
42964 index 0225fdd..08bda99 100644
42965 --- a/fs/binfmt_elf.c
42966 +++ b/fs/binfmt_elf.c
42967 @@ -32,6 +32,7 @@
42968 #include <linux/elf.h>
42969 #include <linux/utsname.h>
42970 #include <linux/coredump.h>
42971 +#include <linux/xattr.h>
42972 #include <asm/uaccess.h>
42973 #include <asm/param.h>
42974 #include <asm/page.h>
42975 @@ -52,6 +53,10 @@ static int elf_core_dump(struct coredump_params *cprm);
42976 #define elf_core_dump NULL
42977 #endif
42978
42979 +#ifdef CONFIG_PAX_MPROTECT
42980 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
42981 +#endif
42982 +
42983 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
42984 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
42985 #else
42986 @@ -71,6 +76,11 @@ static struct linux_binfmt elf_format = {
42987 .load_binary = load_elf_binary,
42988 .load_shlib = load_elf_library,
42989 .core_dump = elf_core_dump,
42990 +
42991 +#ifdef CONFIG_PAX_MPROTECT
42992 + .handle_mprotect= elf_handle_mprotect,
42993 +#endif
42994 +
42995 .min_coredump = ELF_EXEC_PAGESIZE,
42996 };
42997
42998 @@ -78,6 +88,8 @@ static struct linux_binfmt elf_format = {
42999
43000 static int set_brk(unsigned long start, unsigned long end)
43001 {
43002 + unsigned long e = end;
43003 +
43004 start = ELF_PAGEALIGN(start);
43005 end = ELF_PAGEALIGN(end);
43006 if (end > start) {
43007 @@ -86,7 +98,7 @@ static int set_brk(unsigned long start, unsigned long end)
43008 if (BAD_ADDR(addr))
43009 return addr;
43010 }
43011 - current->mm->start_brk = current->mm->brk = end;
43012 + current->mm->start_brk = current->mm->brk = e;
43013 return 0;
43014 }
43015
43016 @@ -147,12 +159,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
43017 elf_addr_t __user *u_rand_bytes;
43018 const char *k_platform = ELF_PLATFORM;
43019 const char *k_base_platform = ELF_BASE_PLATFORM;
43020 - unsigned char k_rand_bytes[16];
43021 + u32 k_rand_bytes[4];
43022 int items;
43023 elf_addr_t *elf_info;
43024 int ei_index = 0;
43025 const struct cred *cred = current_cred();
43026 struct vm_area_struct *vma;
43027 + unsigned long saved_auxv[AT_VECTOR_SIZE];
43028
43029 /*
43030 * In some cases (e.g. Hyper-Threading), we want to avoid L1
43031 @@ -194,8 +207,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
43032 * Generate 16 random bytes for userspace PRNG seeding.
43033 */
43034 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
43035 - u_rand_bytes = (elf_addr_t __user *)
43036 - STACK_ALLOC(p, sizeof(k_rand_bytes));
43037 + srandom32(k_rand_bytes[0] ^ random32());
43038 + srandom32(k_rand_bytes[1] ^ random32());
43039 + srandom32(k_rand_bytes[2] ^ random32());
43040 + srandom32(k_rand_bytes[3] ^ random32());
43041 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
43042 + u_rand_bytes = (elf_addr_t __user *) p;
43043 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
43044 return -EFAULT;
43045
43046 @@ -307,9 +324,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
43047 return -EFAULT;
43048 current->mm->env_end = p;
43049
43050 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
43051 +
43052 /* Put the elf_info on the stack in the right place. */
43053 sp = (elf_addr_t __user *)envp + 1;
43054 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
43055 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
43056 return -EFAULT;
43057 return 0;
43058 }
43059 @@ -373,15 +392,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
43060 an ELF header */
43061
43062 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43063 - struct file *interpreter, unsigned long *interp_map_addr,
43064 - unsigned long no_base)
43065 + struct file *interpreter, unsigned long no_base)
43066 {
43067 struct elf_phdr *elf_phdata;
43068 struct elf_phdr *eppnt;
43069 - unsigned long load_addr = 0;
43070 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
43071 int load_addr_set = 0;
43072 unsigned long last_bss = 0, elf_bss = 0;
43073 - unsigned long error = ~0UL;
43074 + unsigned long error = -EINVAL;
43075 unsigned long total_size;
43076 int retval, i, size;
43077
43078 @@ -427,6 +445,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43079 goto out_close;
43080 }
43081
43082 +#ifdef CONFIG_PAX_SEGMEXEC
43083 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
43084 + pax_task_size = SEGMEXEC_TASK_SIZE;
43085 +#endif
43086 +
43087 eppnt = elf_phdata;
43088 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
43089 if (eppnt->p_type == PT_LOAD) {
43090 @@ -450,8 +473,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43091 map_addr = elf_map(interpreter, load_addr + vaddr,
43092 eppnt, elf_prot, elf_type, total_size);
43093 total_size = 0;
43094 - if (!*interp_map_addr)
43095 - *interp_map_addr = map_addr;
43096 error = map_addr;
43097 if (BAD_ADDR(map_addr))
43098 goto out_close;
43099 @@ -470,8 +491,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43100 k = load_addr + eppnt->p_vaddr;
43101 if (BAD_ADDR(k) ||
43102 eppnt->p_filesz > eppnt->p_memsz ||
43103 - eppnt->p_memsz > TASK_SIZE ||
43104 - TASK_SIZE - eppnt->p_memsz < k) {
43105 + eppnt->p_memsz > pax_task_size ||
43106 + pax_task_size - eppnt->p_memsz < k) {
43107 error = -ENOMEM;
43108 goto out_close;
43109 }
43110 @@ -523,6 +544,311 @@ out:
43111 return error;
43112 }
43113
43114 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
43115 +#ifdef CONFIG_PAX_SOFTMODE
43116 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
43117 +{
43118 + unsigned long pax_flags = 0UL;
43119 +
43120 +#ifdef CONFIG_PAX_PAGEEXEC
43121 + if (elf_phdata->p_flags & PF_PAGEEXEC)
43122 + pax_flags |= MF_PAX_PAGEEXEC;
43123 +#endif
43124 +
43125 +#ifdef CONFIG_PAX_SEGMEXEC
43126 + if (elf_phdata->p_flags & PF_SEGMEXEC)
43127 + pax_flags |= MF_PAX_SEGMEXEC;
43128 +#endif
43129 +
43130 +#ifdef CONFIG_PAX_EMUTRAMP
43131 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
43132 + pax_flags |= MF_PAX_EMUTRAMP;
43133 +#endif
43134 +
43135 +#ifdef CONFIG_PAX_MPROTECT
43136 + if (elf_phdata->p_flags & PF_MPROTECT)
43137 + pax_flags |= MF_PAX_MPROTECT;
43138 +#endif
43139 +
43140 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43141 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
43142 + pax_flags |= MF_PAX_RANDMMAP;
43143 +#endif
43144 +
43145 + return pax_flags;
43146 +}
43147 +#endif
43148 +
43149 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
43150 +{
43151 + unsigned long pax_flags = 0UL;
43152 +
43153 +#ifdef CONFIG_PAX_PAGEEXEC
43154 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
43155 + pax_flags |= MF_PAX_PAGEEXEC;
43156 +#endif
43157 +
43158 +#ifdef CONFIG_PAX_SEGMEXEC
43159 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
43160 + pax_flags |= MF_PAX_SEGMEXEC;
43161 +#endif
43162 +
43163 +#ifdef CONFIG_PAX_EMUTRAMP
43164 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
43165 + pax_flags |= MF_PAX_EMUTRAMP;
43166 +#endif
43167 +
43168 +#ifdef CONFIG_PAX_MPROTECT
43169 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
43170 + pax_flags |= MF_PAX_MPROTECT;
43171 +#endif
43172 +
43173 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43174 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
43175 + pax_flags |= MF_PAX_RANDMMAP;
43176 +#endif
43177 +
43178 + return pax_flags;
43179 +}
43180 +#endif
43181 +
43182 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43183 +#ifdef CONFIG_PAX_SOFTMODE
43184 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
43185 +{
43186 + unsigned long pax_flags = 0UL;
43187 +
43188 +#ifdef CONFIG_PAX_PAGEEXEC
43189 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
43190 + pax_flags |= MF_PAX_PAGEEXEC;
43191 +#endif
43192 +
43193 +#ifdef CONFIG_PAX_SEGMEXEC
43194 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
43195 + pax_flags |= MF_PAX_SEGMEXEC;
43196 +#endif
43197 +
43198 +#ifdef CONFIG_PAX_EMUTRAMP
43199 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
43200 + pax_flags |= MF_PAX_EMUTRAMP;
43201 +#endif
43202 +
43203 +#ifdef CONFIG_PAX_MPROTECT
43204 + if (pax_flags_softmode & MF_PAX_MPROTECT)
43205 + pax_flags |= MF_PAX_MPROTECT;
43206 +#endif
43207 +
43208 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43209 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
43210 + pax_flags |= MF_PAX_RANDMMAP;
43211 +#endif
43212 +
43213 + return pax_flags;
43214 +}
43215 +#endif
43216 +
43217 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
43218 +{
43219 + unsigned long pax_flags = 0UL;
43220 +
43221 +#ifdef CONFIG_PAX_PAGEEXEC
43222 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
43223 + pax_flags |= MF_PAX_PAGEEXEC;
43224 +#endif
43225 +
43226 +#ifdef CONFIG_PAX_SEGMEXEC
43227 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
43228 + pax_flags |= MF_PAX_SEGMEXEC;
43229 +#endif
43230 +
43231 +#ifdef CONFIG_PAX_EMUTRAMP
43232 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
43233 + pax_flags |= MF_PAX_EMUTRAMP;
43234 +#endif
43235 +
43236 +#ifdef CONFIG_PAX_MPROTECT
43237 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
43238 + pax_flags |= MF_PAX_MPROTECT;
43239 +#endif
43240 +
43241 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43242 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
43243 + pax_flags |= MF_PAX_RANDMMAP;
43244 +#endif
43245 +
43246 + return pax_flags;
43247 +}
43248 +#endif
43249 +
43250 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43251 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
43252 +{
43253 + unsigned long pax_flags = 0UL;
43254 +
43255 +#ifdef CONFIG_PAX_EI_PAX
43256 +
43257 +#ifdef CONFIG_PAX_PAGEEXEC
43258 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
43259 + pax_flags |= MF_PAX_PAGEEXEC;
43260 +#endif
43261 +
43262 +#ifdef CONFIG_PAX_SEGMEXEC
43263 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
43264 + pax_flags |= MF_PAX_SEGMEXEC;
43265 +#endif
43266 +
43267 +#ifdef CONFIG_PAX_EMUTRAMP
43268 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
43269 + pax_flags |= MF_PAX_EMUTRAMP;
43270 +#endif
43271 +
43272 +#ifdef CONFIG_PAX_MPROTECT
43273 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
43274 + pax_flags |= MF_PAX_MPROTECT;
43275 +#endif
43276 +
43277 +#ifdef CONFIG_PAX_ASLR
43278 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
43279 + pax_flags |= MF_PAX_RANDMMAP;
43280 +#endif
43281 +
43282 +#else
43283 +
43284 +#ifdef CONFIG_PAX_PAGEEXEC
43285 + pax_flags |= MF_PAX_PAGEEXEC;
43286 +#endif
43287 +
43288 +#ifdef CONFIG_PAX_SEGMEXEC
43289 + pax_flags |= MF_PAX_SEGMEXEC;
43290 +#endif
43291 +
43292 +#ifdef CONFIG_PAX_MPROTECT
43293 + pax_flags |= MF_PAX_MPROTECT;
43294 +#endif
43295 +
43296 +#ifdef CONFIG_PAX_RANDMMAP
43297 + if (randomize_va_space)
43298 + pax_flags |= MF_PAX_RANDMMAP;
43299 +#endif
43300 +
43301 +#endif
43302 +
43303 + return pax_flags;
43304 +}
43305 +
43306 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
43307 +{
43308 +
43309 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
43310 + unsigned long i;
43311 +
43312 + for (i = 0UL; i < elf_ex->e_phnum; i++)
43313 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
43314 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
43315 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
43316 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
43317 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
43318 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
43319 + return ~0UL;
43320 +
43321 +#ifdef CONFIG_PAX_SOFTMODE
43322 + if (pax_softmode)
43323 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
43324 + else
43325 +#endif
43326 +
43327 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
43328 + break;
43329 + }
43330 +#endif
43331 +
43332 + return ~0UL;
43333 +}
43334 +
43335 +static unsigned long pax_parse_xattr_pax(struct file * const file)
43336 +{
43337 +
43338 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43339 + ssize_t xattr_size, i;
43340 + unsigned char xattr_value[5];
43341 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
43342 +
43343 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
43344 + if (xattr_size <= 0)
43345 + return ~0UL;
43346 +
43347 + for (i = 0; i < xattr_size; i++)
43348 + switch (xattr_value[i]) {
43349 + default:
43350 + return ~0UL;
43351 +
43352 +#define parse_flag(option1, option2, flag) \
43353 + case option1: \
43354 + pax_flags_hardmode |= MF_PAX_##flag; \
43355 + break; \
43356 + case option2: \
43357 + pax_flags_softmode |= MF_PAX_##flag; \
43358 + break;
43359 +
43360 + parse_flag('p', 'P', PAGEEXEC);
43361 + parse_flag('e', 'E', EMUTRAMP);
43362 + parse_flag('m', 'M', MPROTECT);
43363 + parse_flag('r', 'R', RANDMMAP);
43364 + parse_flag('s', 'S', SEGMEXEC);
43365 +
43366 +#undef parse_flag
43367 + }
43368 +
43369 + if (pax_flags_hardmode & pax_flags_softmode)
43370 + return ~0UL;
43371 +
43372 +#ifdef CONFIG_PAX_SOFTMODE
43373 + if (pax_softmode)
43374 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
43375 + else
43376 +#endif
43377 +
43378 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
43379 +#else
43380 + return ~0UL;
43381 +#endif
43382 +
43383 +}
43384 +
43385 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
43386 +{
43387 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
43388 +
43389 + pax_flags = pax_parse_ei_pax(elf_ex);
43390 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
43391 + xattr_pax_flags = pax_parse_xattr_pax(file);
43392 +
43393 + if (pt_pax_flags == ~0UL)
43394 + pt_pax_flags = xattr_pax_flags;
43395 + else if (xattr_pax_flags == ~0UL)
43396 + xattr_pax_flags = pt_pax_flags;
43397 + if (pt_pax_flags != xattr_pax_flags)
43398 + return -EINVAL;
43399 + if (pt_pax_flags != ~0UL)
43400 + pax_flags = pt_pax_flags;
43401 +
43402 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
43403 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43404 + if ((__supported_pte_mask & _PAGE_NX))
43405 + pax_flags &= ~MF_PAX_SEGMEXEC;
43406 + else
43407 + pax_flags &= ~MF_PAX_PAGEEXEC;
43408 + }
43409 +#endif
43410 +
43411 + if (0 > pax_check_flags(&pax_flags))
43412 + return -EINVAL;
43413 +
43414 + current->mm->pax_flags = pax_flags;
43415 + return 0;
43416 +}
43417 +#endif
43418 +
43419 /*
43420 * These are the functions used to load ELF style executables and shared
43421 * libraries. There is no binary dependent code anywhere else.
43422 @@ -539,6 +865,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
43423 {
43424 unsigned int random_variable = 0;
43425
43426 +#ifdef CONFIG_PAX_RANDUSTACK
43427 + if (randomize_va_space)
43428 + return stack_top - current->mm->delta_stack;
43429 +#endif
43430 +
43431 if ((current->flags & PF_RANDOMIZE) &&
43432 !(current->personality & ADDR_NO_RANDOMIZE)) {
43433 random_variable = get_random_int() & STACK_RND_MASK;
43434 @@ -557,7 +888,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43435 unsigned long load_addr = 0, load_bias = 0;
43436 int load_addr_set = 0;
43437 char * elf_interpreter = NULL;
43438 - unsigned long error;
43439 + unsigned long error = 0;
43440 struct elf_phdr *elf_ppnt, *elf_phdata;
43441 unsigned long elf_bss, elf_brk;
43442 int retval, i;
43443 @@ -567,11 +898,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43444 unsigned long start_code, end_code, start_data, end_data;
43445 unsigned long reloc_func_desc __maybe_unused = 0;
43446 int executable_stack = EXSTACK_DEFAULT;
43447 - unsigned long def_flags = 0;
43448 struct {
43449 struct elfhdr elf_ex;
43450 struct elfhdr interp_elf_ex;
43451 } *loc;
43452 + unsigned long pax_task_size = TASK_SIZE;
43453
43454 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
43455 if (!loc) {
43456 @@ -707,11 +1038,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43457 goto out_free_dentry;
43458
43459 /* OK, This is the point of no return */
43460 - current->mm->def_flags = def_flags;
43461 +
43462 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43463 + current->mm->pax_flags = 0UL;
43464 +#endif
43465 +
43466 +#ifdef CONFIG_PAX_DLRESOLVE
43467 + current->mm->call_dl_resolve = 0UL;
43468 +#endif
43469 +
43470 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
43471 + current->mm->call_syscall = 0UL;
43472 +#endif
43473 +
43474 +#ifdef CONFIG_PAX_ASLR
43475 + current->mm->delta_mmap = 0UL;
43476 + current->mm->delta_stack = 0UL;
43477 +#endif
43478 +
43479 + current->mm->def_flags = 0;
43480 +
43481 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43482 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
43483 + send_sig(SIGKILL, current, 0);
43484 + goto out_free_dentry;
43485 + }
43486 +#endif
43487 +
43488 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
43489 + pax_set_initial_flags(bprm);
43490 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
43491 + if (pax_set_initial_flags_func)
43492 + (pax_set_initial_flags_func)(bprm);
43493 +#endif
43494 +
43495 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
43496 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
43497 + current->mm->context.user_cs_limit = PAGE_SIZE;
43498 + current->mm->def_flags |= VM_PAGEEXEC;
43499 + }
43500 +#endif
43501 +
43502 +#ifdef CONFIG_PAX_SEGMEXEC
43503 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
43504 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
43505 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
43506 + pax_task_size = SEGMEXEC_TASK_SIZE;
43507 + current->mm->def_flags |= VM_NOHUGEPAGE;
43508 + }
43509 +#endif
43510 +
43511 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
43512 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43513 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
43514 + put_cpu();
43515 + }
43516 +#endif
43517
43518 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
43519 may depend on the personality. */
43520 SET_PERSONALITY(loc->elf_ex);
43521 +
43522 +#ifdef CONFIG_PAX_ASLR
43523 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43524 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
43525 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
43526 + }
43527 +#endif
43528 +
43529 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43530 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43531 + executable_stack = EXSTACK_DISABLE_X;
43532 + current->personality &= ~READ_IMPLIES_EXEC;
43533 + } else
43534 +#endif
43535 +
43536 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
43537 current->personality |= READ_IMPLIES_EXEC;
43538
43539 @@ -802,6 +1203,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43540 #else
43541 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
43542 #endif
43543 +
43544 +#ifdef CONFIG_PAX_RANDMMAP
43545 + /* PaX: randomize base address at the default exe base if requested */
43546 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
43547 +#ifdef CONFIG_SPARC64
43548 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
43549 +#else
43550 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
43551 +#endif
43552 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
43553 + elf_flags |= MAP_FIXED;
43554 + }
43555 +#endif
43556 +
43557 }
43558
43559 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
43560 @@ -834,9 +1249,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43561 * allowed task size. Note that p_filesz must always be
43562 * <= p_memsz so it is only necessary to check p_memsz.
43563 */
43564 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43565 - elf_ppnt->p_memsz > TASK_SIZE ||
43566 - TASK_SIZE - elf_ppnt->p_memsz < k) {
43567 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43568 + elf_ppnt->p_memsz > pax_task_size ||
43569 + pax_task_size - elf_ppnt->p_memsz < k) {
43570 /* set_brk can never work. Avoid overflows. */
43571 send_sig(SIGKILL, current, 0);
43572 retval = -EINVAL;
43573 @@ -875,17 +1290,44 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43574 goto out_free_dentry;
43575 }
43576 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
43577 - send_sig(SIGSEGV, current, 0);
43578 - retval = -EFAULT; /* Nobody gets to see this, but.. */
43579 - goto out_free_dentry;
43580 + /*
43581 + * This bss-zeroing can fail if the ELF
43582 + * file specifies odd protections. So
43583 + * we don't check the return value
43584 + */
43585 }
43586
43587 +#ifdef CONFIG_PAX_RANDMMAP
43588 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43589 + unsigned long start, size;
43590 +
43591 + start = ELF_PAGEALIGN(elf_brk);
43592 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
43593 + down_read(&current->mm->mmap_sem);
43594 + retval = -ENOMEM;
43595 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
43596 + unsigned long prot = PROT_NONE;
43597 +
43598 + up_read(&current->mm->mmap_sem);
43599 + current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
43600 +// if (current->personality & ADDR_NO_RANDOMIZE)
43601 +// prot = PROT_READ;
43602 + start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
43603 + retval = IS_ERR_VALUE(start) ? start : 0;
43604 + } else
43605 + up_read(&current->mm->mmap_sem);
43606 + if (retval == 0)
43607 + retval = set_brk(start + size, start + size + PAGE_SIZE);
43608 + if (retval < 0) {
43609 + send_sig(SIGKILL, current, 0);
43610 + goto out_free_dentry;
43611 + }
43612 + }
43613 +#endif
43614 +
43615 if (elf_interpreter) {
43616 - unsigned long uninitialized_var(interp_map_addr);
43617 -
43618 elf_entry = load_elf_interp(&loc->interp_elf_ex,
43619 interpreter,
43620 - &interp_map_addr,
43621 load_bias);
43622 if (!IS_ERR((void *)elf_entry)) {
43623 /*
43624 @@ -1107,7 +1549,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
43625 * Decide what to dump of a segment, part, all or none.
43626 */
43627 static unsigned long vma_dump_size(struct vm_area_struct *vma,
43628 - unsigned long mm_flags)
43629 + unsigned long mm_flags, long signr)
43630 {
43631 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
43632
43633 @@ -1144,7 +1586,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
43634 if (vma->vm_file == NULL)
43635 return 0;
43636
43637 - if (FILTER(MAPPED_PRIVATE))
43638 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
43639 goto whole;
43640
43641 /*
43642 @@ -1366,9 +1808,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
43643 {
43644 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
43645 int i = 0;
43646 - do
43647 + do {
43648 i += 2;
43649 - while (auxv[i - 2] != AT_NULL);
43650 + } while (auxv[i - 2] != AT_NULL);
43651 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
43652 }
43653
43654 @@ -1879,14 +2321,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
43655 }
43656
43657 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
43658 - unsigned long mm_flags)
43659 + struct coredump_params *cprm)
43660 {
43661 struct vm_area_struct *vma;
43662 size_t size = 0;
43663
43664 for (vma = first_vma(current, gate_vma); vma != NULL;
43665 vma = next_vma(vma, gate_vma))
43666 - size += vma_dump_size(vma, mm_flags);
43667 + size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43668 return size;
43669 }
43670
43671 @@ -1980,7 +2422,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43672
43673 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
43674
43675 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
43676 + offset += elf_core_vma_data_size(gate_vma, cprm);
43677 offset += elf_core_extra_data_size();
43678 e_shoff = offset;
43679
43680 @@ -1994,10 +2436,12 @@ static int elf_core_dump(struct coredump_params *cprm)
43681 offset = dataoff;
43682
43683 size += sizeof(*elf);
43684 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43685 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
43686 goto end_coredump;
43687
43688 size += sizeof(*phdr4note);
43689 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43690 if (size > cprm->limit
43691 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
43692 goto end_coredump;
43693 @@ -2011,7 +2455,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43694 phdr.p_offset = offset;
43695 phdr.p_vaddr = vma->vm_start;
43696 phdr.p_paddr = 0;
43697 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
43698 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43699 phdr.p_memsz = vma->vm_end - vma->vm_start;
43700 offset += phdr.p_filesz;
43701 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
43702 @@ -2022,6 +2466,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43703 phdr.p_align = ELF_EXEC_PAGESIZE;
43704
43705 size += sizeof(phdr);
43706 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43707 if (size > cprm->limit
43708 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
43709 goto end_coredump;
43710 @@ -2046,7 +2491,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43711 unsigned long addr;
43712 unsigned long end;
43713
43714 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
43715 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43716
43717 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
43718 struct page *page;
43719 @@ -2055,6 +2500,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43720 page = get_dump_page(addr);
43721 if (page) {
43722 void *kaddr = kmap(page);
43723 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
43724 stop = ((size += PAGE_SIZE) > cprm->limit) ||
43725 !dump_write(cprm->file, kaddr,
43726 PAGE_SIZE);
43727 @@ -2072,6 +2518,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43728
43729 if (e_phnum == PN_XNUM) {
43730 size += sizeof(*shdr4extnum);
43731 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43732 if (size > cprm->limit
43733 || !dump_write(cprm->file, shdr4extnum,
43734 sizeof(*shdr4extnum)))
43735 @@ -2092,6 +2539,97 @@ out:
43736
43737 #endif /* CONFIG_ELF_CORE */
43738
43739 +#ifdef CONFIG_PAX_MPROTECT
43740 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
43741 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
43742 + * we'll remove VM_MAYWRITE for good on RELRO segments.
43743 + *
43744 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
43745 + * basis because we want to allow the common case and not the special ones.
43746 + */
43747 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
43748 +{
43749 + struct elfhdr elf_h;
43750 + struct elf_phdr elf_p;
43751 + unsigned long i;
43752 + unsigned long oldflags;
43753 + bool is_textrel_rw, is_textrel_rx, is_relro;
43754 +
43755 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
43756 + return;
43757 +
43758 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
43759 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
43760 +
43761 +#ifdef CONFIG_PAX_ELFRELOCS
43762 + /* possible TEXTREL */
43763 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
43764 + 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);
43765 +#else
43766 + is_textrel_rw = false;
43767 + is_textrel_rx = false;
43768 +#endif
43769 +
43770 + /* possible RELRO */
43771 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
43772 +
43773 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
43774 + return;
43775 +
43776 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
43777 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
43778 +
43779 +#ifdef CONFIG_PAX_ETEXECRELOCS
43780 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43781 +#else
43782 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
43783 +#endif
43784 +
43785 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43786 + !elf_check_arch(&elf_h) ||
43787 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
43788 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
43789 + return;
43790 +
43791 + for (i = 0UL; i < elf_h.e_phnum; i++) {
43792 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
43793 + return;
43794 + switch (elf_p.p_type) {
43795 + case PT_DYNAMIC:
43796 + if (!is_textrel_rw && !is_textrel_rx)
43797 + continue;
43798 + i = 0UL;
43799 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
43800 + elf_dyn dyn;
43801 +
43802 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
43803 + return;
43804 + if (dyn.d_tag == DT_NULL)
43805 + return;
43806 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
43807 + gr_log_textrel(vma);
43808 + if (is_textrel_rw)
43809 + vma->vm_flags |= VM_MAYWRITE;
43810 + else
43811 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
43812 + vma->vm_flags &= ~VM_MAYWRITE;
43813 + return;
43814 + }
43815 + i++;
43816 + }
43817 + return;
43818 +
43819 + case PT_GNU_RELRO:
43820 + if (!is_relro)
43821 + continue;
43822 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
43823 + vma->vm_flags &= ~VM_MAYWRITE;
43824 + return;
43825 + }
43826 + }
43827 +}
43828 +#endif
43829 +
43830 static int __init init_elf_binfmt(void)
43831 {
43832 register_binfmt(&elf_format);
43833 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
43834 index 178cb70..8972997 100644
43835 --- a/fs/binfmt_flat.c
43836 +++ b/fs/binfmt_flat.c
43837 @@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
43838 realdatastart = (unsigned long) -ENOMEM;
43839 printk("Unable to allocate RAM for process data, errno %d\n",
43840 (int)-realdatastart);
43841 + down_write(&current->mm->mmap_sem);
43842 vm_munmap(textpos, text_len);
43843 + up_write(&current->mm->mmap_sem);
43844 ret = realdatastart;
43845 goto err;
43846 }
43847 @@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43848 }
43849 if (IS_ERR_VALUE(result)) {
43850 printk("Unable to read data+bss, errno %d\n", (int)-result);
43851 + down_write(&current->mm->mmap_sem);
43852 vm_munmap(textpos, text_len);
43853 vm_munmap(realdatastart, len);
43854 + up_write(&current->mm->mmap_sem);
43855 ret = result;
43856 goto err;
43857 }
43858 @@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43859 }
43860 if (IS_ERR_VALUE(result)) {
43861 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
43862 + down_write(&current->mm->mmap_sem);
43863 vm_munmap(textpos, text_len + data_len + extra +
43864 MAX_SHARED_LIBS * sizeof(unsigned long));
43865 + up_write(&current->mm->mmap_sem);
43866 ret = result;
43867 goto err;
43868 }
43869 diff --git a/fs/bio.c b/fs/bio.c
43870 index 71072ab..439851b 100644
43871 --- a/fs/bio.c
43872 +++ b/fs/bio.c
43873 @@ -842,7 +842,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
43874 /*
43875 * Overflow, abort
43876 */
43877 - if (end < start)
43878 + if (end < start || end - start > INT_MAX - nr_pages)
43879 return ERR_PTR(-EINVAL);
43880
43881 nr_pages += end - start;
43882 @@ -976,7 +976,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
43883 /*
43884 * Overflow, abort
43885 */
43886 - if (end < start)
43887 + if (end < start || end - start > INT_MAX - nr_pages)
43888 return ERR_PTR(-EINVAL);
43889
43890 nr_pages += end - start;
43891 @@ -1238,7 +1238,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
43892 const int read = bio_data_dir(bio) == READ;
43893 struct bio_map_data *bmd = bio->bi_private;
43894 int i;
43895 - char *p = bmd->sgvecs[0].iov_base;
43896 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
43897
43898 __bio_for_each_segment(bvec, bio, i, 0) {
43899 char *addr = page_address(bvec->bv_page);
43900 diff --git a/fs/block_dev.c b/fs/block_dev.c
43901 index 38e721b..7a9c5bc 100644
43902 --- a/fs/block_dev.c
43903 +++ b/fs/block_dev.c
43904 @@ -704,7 +704,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
43905 else if (bdev->bd_contains == bdev)
43906 return true; /* is a whole device which isn't held */
43907
43908 - else if (whole->bd_holder == bd_may_claim)
43909 + else if (whole->bd_holder == (void *)bd_may_claim)
43910 return true; /* is a partition of a device that is being partitioned */
43911 else if (whole->bd_holder != NULL)
43912 return false; /* is a partition of a held device */
43913 diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
43914 index 9197e2e..7f731f8 100644
43915 --- a/fs/btrfs/check-integrity.c
43916 +++ b/fs/btrfs/check-integrity.c
43917 @@ -155,7 +155,7 @@ struct btrfsic_block {
43918 union {
43919 bio_end_io_t *bio;
43920 bh_end_io_t *bh;
43921 - } orig_bio_bh_end_io;
43922 + } __no_const orig_bio_bh_end_io;
43923 int submit_bio_bh_rw;
43924 u64 flush_gen; /* only valid if !never_written */
43925 };
43926 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
43927 index 6d183f6..f47cc7a 100644
43928 --- a/fs/btrfs/ctree.c
43929 +++ b/fs/btrfs/ctree.c
43930 @@ -1037,9 +1037,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
43931 free_extent_buffer(buf);
43932 add_root_to_dirty_list(root);
43933 } else {
43934 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
43935 - parent_start = parent->start;
43936 - else
43937 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
43938 + if (parent)
43939 + parent_start = parent->start;
43940 + else
43941 + parent_start = 0;
43942 + } else
43943 parent_start = 0;
43944
43945 WARN_ON(trans->transid != btrfs_header_generation(parent));
43946 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
43947 index ec154f9..bf617a7 100644
43948 --- a/fs/btrfs/inode.c
43949 +++ b/fs/btrfs/inode.c
43950 @@ -7126,7 +7126,7 @@ fail:
43951 return -ENOMEM;
43952 }
43953
43954 -static int btrfs_getattr(struct vfsmount *mnt,
43955 +int btrfs_getattr(struct vfsmount *mnt,
43956 struct dentry *dentry, struct kstat *stat)
43957 {
43958 struct inode *inode = dentry->d_inode;
43959 @@ -7140,6 +7140,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
43960 return 0;
43961 }
43962
43963 +EXPORT_SYMBOL(btrfs_getattr);
43964 +
43965 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
43966 +{
43967 + return BTRFS_I(inode)->root->anon_dev;
43968 +}
43969 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
43970 +
43971 /*
43972 * If a file is moved, it will inherit the cow and compression flags of the new
43973 * directory.
43974 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
43975 index 9df50fa..6cd20d0 100644
43976 --- a/fs/btrfs/ioctl.c
43977 +++ b/fs/btrfs/ioctl.c
43978 @@ -2942,9 +2942,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43979 for (i = 0; i < num_types; i++) {
43980 struct btrfs_space_info *tmp;
43981
43982 + /* Don't copy in more than we allocated */
43983 if (!slot_count)
43984 break;
43985
43986 + slot_count--;
43987 +
43988 info = NULL;
43989 rcu_read_lock();
43990 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
43991 @@ -2966,10 +2969,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43992 memcpy(dest, &space, sizeof(space));
43993 dest++;
43994 space_args.total_spaces++;
43995 - slot_count--;
43996 }
43997 - if (!slot_count)
43998 - break;
43999 }
44000 up_read(&info->groups_sem);
44001 }
44002 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
44003 index 4da0865..01c4778 100644
44004 --- a/fs/btrfs/relocation.c
44005 +++ b/fs/btrfs/relocation.c
44006 @@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
44007 }
44008 spin_unlock(&rc->reloc_root_tree.lock);
44009
44010 - BUG_ON((struct btrfs_root *)node->data != root);
44011 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
44012
44013 if (!del) {
44014 spin_lock(&rc->reloc_root_tree.lock);
44015 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
44016 index 622f469..e8d2d55 100644
44017 --- a/fs/cachefiles/bind.c
44018 +++ b/fs/cachefiles/bind.c
44019 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
44020 args);
44021
44022 /* start by checking things over */
44023 - ASSERT(cache->fstop_percent >= 0 &&
44024 - cache->fstop_percent < cache->fcull_percent &&
44025 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
44026 cache->fcull_percent < cache->frun_percent &&
44027 cache->frun_percent < 100);
44028
44029 - ASSERT(cache->bstop_percent >= 0 &&
44030 - cache->bstop_percent < cache->bcull_percent &&
44031 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
44032 cache->bcull_percent < cache->brun_percent &&
44033 cache->brun_percent < 100);
44034
44035 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
44036 index 0a1467b..6a53245 100644
44037 --- a/fs/cachefiles/daemon.c
44038 +++ b/fs/cachefiles/daemon.c
44039 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
44040 if (n > buflen)
44041 return -EMSGSIZE;
44042
44043 - if (copy_to_user(_buffer, buffer, n) != 0)
44044 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
44045 return -EFAULT;
44046
44047 return n;
44048 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
44049 if (test_bit(CACHEFILES_DEAD, &cache->flags))
44050 return -EIO;
44051
44052 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
44053 + if (datalen > PAGE_SIZE - 1)
44054 return -EOPNOTSUPP;
44055
44056 /* drag the command string into the kernel so we can parse it */
44057 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
44058 if (args[0] != '%' || args[1] != '\0')
44059 return -EINVAL;
44060
44061 - if (fstop < 0 || fstop >= cache->fcull_percent)
44062 + if (fstop >= cache->fcull_percent)
44063 return cachefiles_daemon_range_error(cache, args);
44064
44065 cache->fstop_percent = fstop;
44066 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
44067 if (args[0] != '%' || args[1] != '\0')
44068 return -EINVAL;
44069
44070 - if (bstop < 0 || bstop >= cache->bcull_percent)
44071 + if (bstop >= cache->bcull_percent)
44072 return cachefiles_daemon_range_error(cache, args);
44073
44074 cache->bstop_percent = bstop;
44075 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
44076 index bd6bc1b..b627b53 100644
44077 --- a/fs/cachefiles/internal.h
44078 +++ b/fs/cachefiles/internal.h
44079 @@ -57,7 +57,7 @@ struct cachefiles_cache {
44080 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
44081 struct rb_root active_nodes; /* active nodes (can't be culled) */
44082 rwlock_t active_lock; /* lock for active_nodes */
44083 - atomic_t gravecounter; /* graveyard uniquifier */
44084 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
44085 unsigned frun_percent; /* when to stop culling (% files) */
44086 unsigned fcull_percent; /* when to start culling (% files) */
44087 unsigned fstop_percent; /* when to stop allocating (% files) */
44088 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
44089 * proc.c
44090 */
44091 #ifdef CONFIG_CACHEFILES_HISTOGRAM
44092 -extern atomic_t cachefiles_lookup_histogram[HZ];
44093 -extern atomic_t cachefiles_mkdir_histogram[HZ];
44094 -extern atomic_t cachefiles_create_histogram[HZ];
44095 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
44096 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
44097 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
44098
44099 extern int __init cachefiles_proc_init(void);
44100 extern void cachefiles_proc_cleanup(void);
44101 static inline
44102 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
44103 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
44104 {
44105 unsigned long jif = jiffies - start_jif;
44106 if (jif >= HZ)
44107 jif = HZ - 1;
44108 - atomic_inc(&histogram[jif]);
44109 + atomic_inc_unchecked(&histogram[jif]);
44110 }
44111
44112 #else
44113 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
44114 index b0b5f7c..039bb26 100644
44115 --- a/fs/cachefiles/namei.c
44116 +++ b/fs/cachefiles/namei.c
44117 @@ -318,7 +318,7 @@ try_again:
44118 /* first step is to make up a grave dentry in the graveyard */
44119 sprintf(nbuffer, "%08x%08x",
44120 (uint32_t) get_seconds(),
44121 - (uint32_t) atomic_inc_return(&cache->gravecounter));
44122 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
44123
44124 /* do the multiway lock magic */
44125 trap = lock_rename(cache->graveyard, dir);
44126 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
44127 index eccd339..4c1d995 100644
44128 --- a/fs/cachefiles/proc.c
44129 +++ b/fs/cachefiles/proc.c
44130 @@ -14,9 +14,9 @@
44131 #include <linux/seq_file.h>
44132 #include "internal.h"
44133
44134 -atomic_t cachefiles_lookup_histogram[HZ];
44135 -atomic_t cachefiles_mkdir_histogram[HZ];
44136 -atomic_t cachefiles_create_histogram[HZ];
44137 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
44138 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
44139 +atomic_unchecked_t cachefiles_create_histogram[HZ];
44140
44141 /*
44142 * display the latency histogram
44143 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
44144 return 0;
44145 default:
44146 index = (unsigned long) v - 3;
44147 - x = atomic_read(&cachefiles_lookup_histogram[index]);
44148 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
44149 - z = atomic_read(&cachefiles_create_histogram[index]);
44150 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
44151 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
44152 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
44153 if (x == 0 && y == 0 && z == 0)
44154 return 0;
44155
44156 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
44157 index c994691..2a1537f 100644
44158 --- a/fs/cachefiles/rdwr.c
44159 +++ b/fs/cachefiles/rdwr.c
44160 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
44161 old_fs = get_fs();
44162 set_fs(KERNEL_DS);
44163 ret = file->f_op->write(
44164 - file, (const void __user *) data, len, &pos);
44165 + file, (const void __force_user *) data, len, &pos);
44166 set_fs(old_fs);
44167 kunmap(page);
44168 if (ret != len)
44169 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
44170 index e5b7731..b9c59fb 100644
44171 --- a/fs/ceph/dir.c
44172 +++ b/fs/ceph/dir.c
44173 @@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
44174 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
44175 struct ceph_mds_client *mdsc = fsc->mdsc;
44176 unsigned frag = fpos_frag(filp->f_pos);
44177 - int off = fpos_off(filp->f_pos);
44178 + unsigned int off = fpos_off(filp->f_pos);
44179 int err;
44180 u32 ftype;
44181 struct ceph_mds_reply_info_parsed *rinfo;
44182 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
44183 index d9ea6ed..1e6c8ac 100644
44184 --- a/fs/cifs/cifs_debug.c
44185 +++ b/fs/cifs/cifs_debug.c
44186 @@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44187
44188 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
44189 #ifdef CONFIG_CIFS_STATS2
44190 - atomic_set(&totBufAllocCount, 0);
44191 - atomic_set(&totSmBufAllocCount, 0);
44192 + atomic_set_unchecked(&totBufAllocCount, 0);
44193 + atomic_set_unchecked(&totSmBufAllocCount, 0);
44194 #endif /* CONFIG_CIFS_STATS2 */
44195 spin_lock(&cifs_tcp_ses_lock);
44196 list_for_each(tmp1, &cifs_tcp_ses_list) {
44197 @@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44198 tcon = list_entry(tmp3,
44199 struct cifs_tcon,
44200 tcon_list);
44201 - atomic_set(&tcon->num_smbs_sent, 0);
44202 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
44203 if (server->ops->clear_stats)
44204 server->ops->clear_stats(tcon);
44205 }
44206 @@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44207 smBufAllocCount.counter, cifs_min_small);
44208 #ifdef CONFIG_CIFS_STATS2
44209 seq_printf(m, "Total Large %d Small %d Allocations\n",
44210 - atomic_read(&totBufAllocCount),
44211 - atomic_read(&totSmBufAllocCount));
44212 + atomic_read_unchecked(&totBufAllocCount),
44213 + atomic_read_unchecked(&totSmBufAllocCount));
44214 #endif /* CONFIG_CIFS_STATS2 */
44215
44216 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
44217 @@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44218 if (tcon->need_reconnect)
44219 seq_puts(m, "\tDISCONNECTED ");
44220 seq_printf(m, "\nSMBs: %d",
44221 - atomic_read(&tcon->num_smbs_sent));
44222 + atomic_read_unchecked(&tcon->num_smbs_sent));
44223 if (server->ops->print_stats)
44224 server->ops->print_stats(m, tcon);
44225 }
44226 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
44227 index db8a404..c712e2e 100644
44228 --- a/fs/cifs/cifsfs.c
44229 +++ b/fs/cifs/cifsfs.c
44230 @@ -1003,7 +1003,7 @@ cifs_init_request_bufs(void)
44231 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
44232 cifs_req_cachep = kmem_cache_create("cifs_request",
44233 CIFSMaxBufSize + max_hdr_size, 0,
44234 - SLAB_HWCACHE_ALIGN, NULL);
44235 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
44236 if (cifs_req_cachep == NULL)
44237 return -ENOMEM;
44238
44239 @@ -1030,7 +1030,7 @@ cifs_init_request_bufs(void)
44240 efficient to alloc 1 per page off the slab compared to 17K (5page)
44241 alloc of large cifs buffers even when page debugging is on */
44242 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
44243 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
44244 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
44245 NULL);
44246 if (cifs_sm_req_cachep == NULL) {
44247 mempool_destroy(cifs_req_poolp);
44248 @@ -1115,8 +1115,8 @@ init_cifs(void)
44249 atomic_set(&bufAllocCount, 0);
44250 atomic_set(&smBufAllocCount, 0);
44251 #ifdef CONFIG_CIFS_STATS2
44252 - atomic_set(&totBufAllocCount, 0);
44253 - atomic_set(&totSmBufAllocCount, 0);
44254 + atomic_set_unchecked(&totBufAllocCount, 0);
44255 + atomic_set_unchecked(&totSmBufAllocCount, 0);
44256 #endif /* CONFIG_CIFS_STATS2 */
44257
44258 atomic_set(&midCount, 0);
44259 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
44260 index 977dc0e..ba48ab9 100644
44261 --- a/fs/cifs/cifsglob.h
44262 +++ b/fs/cifs/cifsglob.h
44263 @@ -590,35 +590,35 @@ struct cifs_tcon {
44264 __u16 Flags; /* optional support bits */
44265 enum statusEnum tidStatus;
44266 #ifdef CONFIG_CIFS_STATS
44267 - atomic_t num_smbs_sent;
44268 + atomic_unchecked_t num_smbs_sent;
44269 union {
44270 struct {
44271 - atomic_t num_writes;
44272 - atomic_t num_reads;
44273 - atomic_t num_flushes;
44274 - atomic_t num_oplock_brks;
44275 - atomic_t num_opens;
44276 - atomic_t num_closes;
44277 - atomic_t num_deletes;
44278 - atomic_t num_mkdirs;
44279 - atomic_t num_posixopens;
44280 - atomic_t num_posixmkdirs;
44281 - atomic_t num_rmdirs;
44282 - atomic_t num_renames;
44283 - atomic_t num_t2renames;
44284 - atomic_t num_ffirst;
44285 - atomic_t num_fnext;
44286 - atomic_t num_fclose;
44287 - atomic_t num_hardlinks;
44288 - atomic_t num_symlinks;
44289 - atomic_t num_locks;
44290 - atomic_t num_acl_get;
44291 - atomic_t num_acl_set;
44292 + atomic_unchecked_t num_writes;
44293 + atomic_unchecked_t num_reads;
44294 + atomic_unchecked_t num_flushes;
44295 + atomic_unchecked_t num_oplock_brks;
44296 + atomic_unchecked_t num_opens;
44297 + atomic_unchecked_t num_closes;
44298 + atomic_unchecked_t num_deletes;
44299 + atomic_unchecked_t num_mkdirs;
44300 + atomic_unchecked_t num_posixopens;
44301 + atomic_unchecked_t num_posixmkdirs;
44302 + atomic_unchecked_t num_rmdirs;
44303 + atomic_unchecked_t num_renames;
44304 + atomic_unchecked_t num_t2renames;
44305 + atomic_unchecked_t num_ffirst;
44306 + atomic_unchecked_t num_fnext;
44307 + atomic_unchecked_t num_fclose;
44308 + atomic_unchecked_t num_hardlinks;
44309 + atomic_unchecked_t num_symlinks;
44310 + atomic_unchecked_t num_locks;
44311 + atomic_unchecked_t num_acl_get;
44312 + atomic_unchecked_t num_acl_set;
44313 } cifs_stats;
44314 #ifdef CONFIG_CIFS_SMB2
44315 struct {
44316 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
44317 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
44318 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
44319 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
44320 } smb2_stats;
44321 #endif /* CONFIG_CIFS_SMB2 */
44322 } stats;
44323 @@ -862,7 +862,7 @@ build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
44324 }
44325
44326 #ifdef CONFIG_CIFS_STATS
44327 -#define cifs_stats_inc atomic_inc
44328 +#define cifs_stats_inc atomic_inc_unchecked
44329
44330 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
44331 unsigned int bytes)
44332 @@ -1227,8 +1227,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
44333 /* Various Debug counters */
44334 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
44335 #ifdef CONFIG_CIFS_STATS2
44336 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
44337 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
44338 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
44339 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
44340 #endif
44341 GLOBAL_EXTERN atomic_t smBufAllocCount;
44342 GLOBAL_EXTERN atomic_t midCount;
44343 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
44344 index e6ce3b1..adc21fd 100644
44345 --- a/fs/cifs/link.c
44346 +++ b/fs/cifs/link.c
44347 @@ -602,7 +602,7 @@ symlink_exit:
44348
44349 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
44350 {
44351 - char *p = nd_get_link(nd);
44352 + const char *p = nd_get_link(nd);
44353 if (!IS_ERR(p))
44354 kfree(p);
44355 }
44356 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
44357 index ce41fee..ac0d27a 100644
44358 --- a/fs/cifs/misc.c
44359 +++ b/fs/cifs/misc.c
44360 @@ -169,7 +169,7 @@ cifs_buf_get(void)
44361 memset(ret_buf, 0, buf_size + 3);
44362 atomic_inc(&bufAllocCount);
44363 #ifdef CONFIG_CIFS_STATS2
44364 - atomic_inc(&totBufAllocCount);
44365 + atomic_inc_unchecked(&totBufAllocCount);
44366 #endif /* CONFIG_CIFS_STATS2 */
44367 }
44368
44369 @@ -204,7 +204,7 @@ cifs_small_buf_get(void)
44370 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
44371 atomic_inc(&smBufAllocCount);
44372 #ifdef CONFIG_CIFS_STATS2
44373 - atomic_inc(&totSmBufAllocCount);
44374 + atomic_inc_unchecked(&totSmBufAllocCount);
44375 #endif /* CONFIG_CIFS_STATS2 */
44376
44377 }
44378 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
44379 index 3129ac7..cc4a948 100644
44380 --- a/fs/cifs/smb1ops.c
44381 +++ b/fs/cifs/smb1ops.c
44382 @@ -524,27 +524,27 @@ static void
44383 cifs_clear_stats(struct cifs_tcon *tcon)
44384 {
44385 #ifdef CONFIG_CIFS_STATS
44386 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
44387 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
44388 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
44389 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
44390 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
44391 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
44392 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
44393 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
44394 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
44395 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
44396 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
44397 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
44398 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
44399 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
44400 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
44401 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
44402 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
44403 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
44404 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
44405 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
44406 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
44407 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
44408 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
44409 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
44410 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
44411 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
44412 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
44413 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
44414 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
44415 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
44416 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
44417 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
44418 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
44419 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
44420 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
44421 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
44422 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
44423 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
44424 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
44425 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
44426 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
44427 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
44428 #endif
44429 }
44430
44431 @@ -553,36 +553,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
44432 {
44433 #ifdef CONFIG_CIFS_STATS
44434 seq_printf(m, " Oplocks breaks: %d",
44435 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
44436 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
44437 seq_printf(m, "\nReads: %d Bytes: %llu",
44438 - atomic_read(&tcon->stats.cifs_stats.num_reads),
44439 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
44440 (long long)(tcon->bytes_read));
44441 seq_printf(m, "\nWrites: %d Bytes: %llu",
44442 - atomic_read(&tcon->stats.cifs_stats.num_writes),
44443 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
44444 (long long)(tcon->bytes_written));
44445 seq_printf(m, "\nFlushes: %d",
44446 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
44447 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
44448 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
44449 - atomic_read(&tcon->stats.cifs_stats.num_locks),
44450 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
44451 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
44452 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
44453 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
44454 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
44455 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
44456 - atomic_read(&tcon->stats.cifs_stats.num_opens),
44457 - atomic_read(&tcon->stats.cifs_stats.num_closes),
44458 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
44459 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
44460 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
44461 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
44462 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
44463 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
44464 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
44465 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
44466 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
44467 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
44468 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
44469 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
44470 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
44471 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
44472 seq_printf(m, "\nRenames: %d T2 Renames %d",
44473 - atomic_read(&tcon->stats.cifs_stats.num_renames),
44474 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
44475 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
44476 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
44477 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
44478 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
44479 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
44480 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
44481 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
44482 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
44483 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
44484 #endif
44485 }
44486
44487 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
44488 index 826209b..fa460f4 100644
44489 --- a/fs/cifs/smb2ops.c
44490 +++ b/fs/cifs/smb2ops.c
44491 @@ -219,8 +219,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
44492 #ifdef CONFIG_CIFS_STATS
44493 int i;
44494 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
44495 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
44496 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
44497 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
44498 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
44499 }
44500 #endif
44501 }
44502 @@ -229,66 +229,66 @@ static void
44503 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
44504 {
44505 #ifdef CONFIG_CIFS_STATS
44506 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
44507 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
44508 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
44509 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
44510 seq_printf(m, "\nNegotiates: %d sent %d failed",
44511 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
44512 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
44513 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
44514 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
44515 seq_printf(m, "\nSessionSetups: %d sent %d failed",
44516 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
44517 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
44518 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
44519 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
44520 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
44521 seq_printf(m, "\nLogoffs: %d sent %d failed",
44522 - atomic_read(&sent[SMB2_LOGOFF_HE]),
44523 - atomic_read(&failed[SMB2_LOGOFF_HE]));
44524 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
44525 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
44526 seq_printf(m, "\nTreeConnects: %d sent %d failed",
44527 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
44528 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
44529 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
44530 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
44531 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
44532 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
44533 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
44534 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
44535 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
44536 seq_printf(m, "\nCreates: %d sent %d failed",
44537 - atomic_read(&sent[SMB2_CREATE_HE]),
44538 - atomic_read(&failed[SMB2_CREATE_HE]));
44539 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
44540 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
44541 seq_printf(m, "\nCloses: %d sent %d failed",
44542 - atomic_read(&sent[SMB2_CLOSE_HE]),
44543 - atomic_read(&failed[SMB2_CLOSE_HE]));
44544 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
44545 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
44546 seq_printf(m, "\nFlushes: %d sent %d failed",
44547 - atomic_read(&sent[SMB2_FLUSH_HE]),
44548 - atomic_read(&failed[SMB2_FLUSH_HE]));
44549 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
44550 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
44551 seq_printf(m, "\nReads: %d sent %d failed",
44552 - atomic_read(&sent[SMB2_READ_HE]),
44553 - atomic_read(&failed[SMB2_READ_HE]));
44554 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
44555 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
44556 seq_printf(m, "\nWrites: %d sent %d failed",
44557 - atomic_read(&sent[SMB2_WRITE_HE]),
44558 - atomic_read(&failed[SMB2_WRITE_HE]));
44559 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
44560 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
44561 seq_printf(m, "\nLocks: %d sent %d failed",
44562 - atomic_read(&sent[SMB2_LOCK_HE]),
44563 - atomic_read(&failed[SMB2_LOCK_HE]));
44564 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
44565 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
44566 seq_printf(m, "\nIOCTLs: %d sent %d failed",
44567 - atomic_read(&sent[SMB2_IOCTL_HE]),
44568 - atomic_read(&failed[SMB2_IOCTL_HE]));
44569 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
44570 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
44571 seq_printf(m, "\nCancels: %d sent %d failed",
44572 - atomic_read(&sent[SMB2_CANCEL_HE]),
44573 - atomic_read(&failed[SMB2_CANCEL_HE]));
44574 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
44575 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
44576 seq_printf(m, "\nEchos: %d sent %d failed",
44577 - atomic_read(&sent[SMB2_ECHO_HE]),
44578 - atomic_read(&failed[SMB2_ECHO_HE]));
44579 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
44580 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
44581 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
44582 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
44583 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
44584 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
44585 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
44586 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
44587 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
44588 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
44589 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
44590 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
44591 seq_printf(m, "\nQueryInfos: %d sent %d failed",
44592 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
44593 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
44594 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
44595 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
44596 seq_printf(m, "\nSetInfos: %d sent %d failed",
44597 - atomic_read(&sent[SMB2_SET_INFO_HE]),
44598 - atomic_read(&failed[SMB2_SET_INFO_HE]));
44599 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
44600 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
44601 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
44602 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
44603 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
44604 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
44605 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
44606 #endif
44607 }
44608
44609 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
44610 index 958ae0e..505c9d0 100644
44611 --- a/fs/coda/cache.c
44612 +++ b/fs/coda/cache.c
44613 @@ -24,7 +24,7 @@
44614 #include "coda_linux.h"
44615 #include "coda_cache.h"
44616
44617 -static atomic_t permission_epoch = ATOMIC_INIT(0);
44618 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
44619
44620 /* replace or extend an acl cache hit */
44621 void coda_cache_enter(struct inode *inode, int mask)
44622 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
44623 struct coda_inode_info *cii = ITOC(inode);
44624
44625 spin_lock(&cii->c_lock);
44626 - cii->c_cached_epoch = atomic_read(&permission_epoch);
44627 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
44628 if (cii->c_uid != current_fsuid()) {
44629 cii->c_uid = current_fsuid();
44630 cii->c_cached_perm = mask;
44631 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
44632 {
44633 struct coda_inode_info *cii = ITOC(inode);
44634 spin_lock(&cii->c_lock);
44635 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
44636 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
44637 spin_unlock(&cii->c_lock);
44638 }
44639
44640 /* remove all acl caches */
44641 void coda_cache_clear_all(struct super_block *sb)
44642 {
44643 - atomic_inc(&permission_epoch);
44644 + atomic_inc_unchecked(&permission_epoch);
44645 }
44646
44647
44648 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
44649 spin_lock(&cii->c_lock);
44650 hit = (mask & cii->c_cached_perm) == mask &&
44651 cii->c_uid == current_fsuid() &&
44652 - cii->c_cached_epoch == atomic_read(&permission_epoch);
44653 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
44654 spin_unlock(&cii->c_lock);
44655
44656 return hit;
44657 diff --git a/fs/compat.c b/fs/compat.c
44658 index 1bdb350..9f28287 100644
44659 --- a/fs/compat.c
44660 +++ b/fs/compat.c
44661 @@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
44662
44663 set_fs(KERNEL_DS);
44664 /* The __user pointer cast is valid because of the set_fs() */
44665 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
44666 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
44667 set_fs(oldfs);
44668 /* truncating is ok because it's a user address */
44669 if (!ret)
44670 @@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
44671 goto out;
44672
44673 ret = -EINVAL;
44674 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
44675 + if (nr_segs > UIO_MAXIOV)
44676 goto out;
44677 if (nr_segs > fast_segs) {
44678 ret = -ENOMEM;
44679 @@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
44680
44681 struct compat_readdir_callback {
44682 struct compat_old_linux_dirent __user *dirent;
44683 + struct file * file;
44684 int result;
44685 };
44686
44687 @@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
44688 buf->result = -EOVERFLOW;
44689 return -EOVERFLOW;
44690 }
44691 +
44692 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44693 + return 0;
44694 +
44695 buf->result++;
44696 dirent = buf->dirent;
44697 if (!access_ok(VERIFY_WRITE, dirent,
44698 @@ -880,6 +885,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
44699
44700 buf.result = 0;
44701 buf.dirent = dirent;
44702 + buf.file = file;
44703
44704 error = vfs_readdir(file, compat_fillonedir, &buf);
44705 if (buf.result)
44706 @@ -899,6 +905,7 @@ struct compat_linux_dirent {
44707 struct compat_getdents_callback {
44708 struct compat_linux_dirent __user *current_dir;
44709 struct compat_linux_dirent __user *previous;
44710 + struct file * file;
44711 int count;
44712 int error;
44713 };
44714 @@ -920,6 +927,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
44715 buf->error = -EOVERFLOW;
44716 return -EOVERFLOW;
44717 }
44718 +
44719 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44720 + return 0;
44721 +
44722 dirent = buf->previous;
44723 if (dirent) {
44724 if (__put_user(offset, &dirent->d_off))
44725 @@ -966,6 +977,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44726 buf.previous = NULL;
44727 buf.count = count;
44728 buf.error = 0;
44729 + buf.file = file;
44730
44731 error = vfs_readdir(file, compat_filldir, &buf);
44732 if (error >= 0)
44733 @@ -986,6 +998,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44734 struct compat_getdents_callback64 {
44735 struct linux_dirent64 __user *current_dir;
44736 struct linux_dirent64 __user *previous;
44737 + struct file * file;
44738 int count;
44739 int error;
44740 };
44741 @@ -1002,6 +1015,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
44742 buf->error = -EINVAL; /* only used if we fail.. */
44743 if (reclen > buf->count)
44744 return -EINVAL;
44745 +
44746 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44747 + return 0;
44748 +
44749 dirent = buf->previous;
44750
44751 if (dirent) {
44752 @@ -1052,13 +1069,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
44753 buf.previous = NULL;
44754 buf.count = count;
44755 buf.error = 0;
44756 + buf.file = file;
44757
44758 error = vfs_readdir(file, compat_filldir64, &buf);
44759 if (error >= 0)
44760 error = buf.error;
44761 lastdirent = buf.previous;
44762 if (lastdirent) {
44763 - typeof(lastdirent->d_off) d_off = file->f_pos;
44764 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
44765 if (__put_user_unaligned(d_off, &lastdirent->d_off))
44766 error = -EFAULT;
44767 else
44768 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
44769 index 112e45a..b59845b 100644
44770 --- a/fs/compat_binfmt_elf.c
44771 +++ b/fs/compat_binfmt_elf.c
44772 @@ -30,11 +30,13 @@
44773 #undef elf_phdr
44774 #undef elf_shdr
44775 #undef elf_note
44776 +#undef elf_dyn
44777 #undef elf_addr_t
44778 #define elfhdr elf32_hdr
44779 #define elf_phdr elf32_phdr
44780 #define elf_shdr elf32_shdr
44781 #define elf_note elf32_note
44782 +#define elf_dyn Elf32_Dyn
44783 #define elf_addr_t Elf32_Addr
44784
44785 /*
44786 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
44787 index 5d2069f..75d31d4 100644
44788 --- a/fs/compat_ioctl.c
44789 +++ b/fs/compat_ioctl.c
44790 @@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
44791 return -EFAULT;
44792 if (__get_user(udata, &ss32->iomem_base))
44793 return -EFAULT;
44794 - ss.iomem_base = compat_ptr(udata);
44795 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
44796 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
44797 __get_user(ss.port_high, &ss32->port_high))
44798 return -EFAULT;
44799 @@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
44800 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
44801 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
44802 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
44803 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44804 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44805 return -EFAULT;
44806
44807 return ioctl_preallocate(file, p);
44808 @@ -1612,8 +1612,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
44809 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
44810 {
44811 unsigned int a, b;
44812 - a = *(unsigned int *)p;
44813 - b = *(unsigned int *)q;
44814 + a = *(const unsigned int *)p;
44815 + b = *(const unsigned int *)q;
44816 if (a > b)
44817 return 1;
44818 if (a < b)
44819 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
44820 index 7414ae2..d98ad6d 100644
44821 --- a/fs/configfs/dir.c
44822 +++ b/fs/configfs/dir.c
44823 @@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44824 }
44825 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
44826 struct configfs_dirent *next;
44827 - const char * name;
44828 + const unsigned char * name;
44829 + char d_name[sizeof(next->s_dentry->d_iname)];
44830 int len;
44831 struct inode *inode = NULL;
44832
44833 @@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44834 continue;
44835
44836 name = configfs_get_name(next);
44837 - len = strlen(name);
44838 + if (next->s_dentry && name == next->s_dentry->d_iname) {
44839 + len = next->s_dentry->d_name.len;
44840 + memcpy(d_name, name, len);
44841 + name = d_name;
44842 + } else
44843 + len = strlen(name);
44844
44845 /*
44846 * We'll have a dentry and an inode for
44847 diff --git a/fs/dcache.c b/fs/dcache.c
44848 index 693f95b..95f1223 100644
44849 --- a/fs/dcache.c
44850 +++ b/fs/dcache.c
44851 @@ -3164,7 +3164,7 @@ void __init vfs_caches_init(unsigned long mempages)
44852 mempages -= reserve;
44853
44854 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
44855 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
44856 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
44857
44858 dcache_init();
44859 inode_init();
44860 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
44861 index 4733eab..71ef6fa 100644
44862 --- a/fs/debugfs/inode.c
44863 +++ b/fs/debugfs/inode.c
44864 @@ -406,7 +406,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
44865 */
44866 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
44867 {
44868 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
44869 + return __create_file(name, S_IFDIR | S_IRWXU,
44870 +#else
44871 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
44872 +#endif
44873 parent, NULL, NULL);
44874 }
44875 EXPORT_SYMBOL_GPL(debugfs_create_dir);
44876 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
44877 index cc7709e..7e7211f 100644
44878 --- a/fs/ecryptfs/inode.c
44879 +++ b/fs/ecryptfs/inode.c
44880 @@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
44881 old_fs = get_fs();
44882 set_fs(get_ds());
44883 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
44884 - (char __user *)lower_buf,
44885 + (char __force_user *)lower_buf,
44886 PATH_MAX);
44887 set_fs(old_fs);
44888 if (rc < 0)
44889 @@ -706,7 +706,7 @@ out:
44890 static void
44891 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
44892 {
44893 - char *buf = nd_get_link(nd);
44894 + const char *buf = nd_get_link(nd);
44895 if (!IS_ERR(buf)) {
44896 /* Free the char* */
44897 kfree(buf);
44898 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
44899 index 412e6ed..4292d22 100644
44900 --- a/fs/ecryptfs/miscdev.c
44901 +++ b/fs/ecryptfs/miscdev.c
44902 @@ -315,7 +315,7 @@ check_list:
44903 goto out_unlock_msg_ctx;
44904 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
44905 if (msg_ctx->msg) {
44906 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
44907 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
44908 goto out_unlock_msg_ctx;
44909 i += packet_length_size;
44910 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
44911 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
44912 index b2a34a1..162fa69 100644
44913 --- a/fs/ecryptfs/read_write.c
44914 +++ b/fs/ecryptfs/read_write.c
44915 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
44916 return -EIO;
44917 fs_save = get_fs();
44918 set_fs(get_ds());
44919 - rc = vfs_write(lower_file, data, size, &offset);
44920 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
44921 set_fs(fs_save);
44922 mark_inode_dirty_sync(ecryptfs_inode);
44923 return rc;
44924 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
44925 return -EIO;
44926 fs_save = get_fs();
44927 set_fs(get_ds());
44928 - rc = vfs_read(lower_file, data, size, &offset);
44929 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
44930 set_fs(fs_save);
44931 return rc;
44932 }
44933 diff --git a/fs/exec.c b/fs/exec.c
44934 index fab2c6d..4fa20c0 100644
44935 --- a/fs/exec.c
44936 +++ b/fs/exec.c
44937 @@ -55,6 +55,15 @@
44938 #include <linux/pipe_fs_i.h>
44939 #include <linux/oom.h>
44940 #include <linux/compat.h>
44941 +#include <linux/random.h>
44942 +#include <linux/seq_file.h>
44943 +
44944 +#ifdef CONFIG_PAX_REFCOUNT
44945 +#include <linux/kallsyms.h>
44946 +#include <linux/kdebug.h>
44947 +#endif
44948 +
44949 +#include <trace/events/fs.h>
44950
44951 #include <asm/uaccess.h>
44952 #include <asm/mmu_context.h>
44953 @@ -66,6 +75,18 @@
44954
44955 #include <trace/events/sched.h>
44956
44957 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
44958 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
44959 +{
44960 + 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");
44961 +}
44962 +#endif
44963 +
44964 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
44965 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
44966 +EXPORT_SYMBOL(pax_set_initial_flags_func);
44967 +#endif
44968 +
44969 int core_uses_pid;
44970 char core_pattern[CORENAME_MAX_SIZE] = "core";
44971 unsigned int core_pipe_limit;
44972 @@ -75,7 +96,7 @@ struct core_name {
44973 char *corename;
44974 int used, size;
44975 };
44976 -static atomic_t call_count = ATOMIC_INIT(1);
44977 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
44978
44979 /* The maximal length of core_pattern is also specified in sysctl.c */
44980
44981 @@ -191,18 +212,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44982 int write)
44983 {
44984 struct page *page;
44985 - int ret;
44986
44987 -#ifdef CONFIG_STACK_GROWSUP
44988 - if (write) {
44989 - ret = expand_downwards(bprm->vma, pos);
44990 - if (ret < 0)
44991 - return NULL;
44992 - }
44993 -#endif
44994 - ret = get_user_pages(current, bprm->mm, pos,
44995 - 1, write, 1, &page, NULL);
44996 - if (ret <= 0)
44997 + if (0 > expand_downwards(bprm->vma, pos))
44998 + return NULL;
44999 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
45000 return NULL;
45001
45002 if (write) {
45003 @@ -218,6 +231,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
45004 if (size <= ARG_MAX)
45005 return page;
45006
45007 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45008 + // only allow 512KB for argv+env on suid/sgid binaries
45009 + // to prevent easy ASLR exhaustion
45010 + if (((bprm->cred->euid != current_euid()) ||
45011 + (bprm->cred->egid != current_egid())) &&
45012 + (size > (512 * 1024))) {
45013 + put_page(page);
45014 + return NULL;
45015 + }
45016 +#endif
45017 +
45018 /*
45019 * Limit to 1/4-th the stack size for the argv+env strings.
45020 * This ensures that:
45021 @@ -277,6 +301,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
45022 vma->vm_end = STACK_TOP_MAX;
45023 vma->vm_start = vma->vm_end - PAGE_SIZE;
45024 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
45025 +
45026 +#ifdef CONFIG_PAX_SEGMEXEC
45027 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
45028 +#endif
45029 +
45030 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
45031 INIT_LIST_HEAD(&vma->anon_vma_chain);
45032
45033 @@ -287,6 +316,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
45034 mm->stack_vm = mm->total_vm = 1;
45035 up_write(&mm->mmap_sem);
45036 bprm->p = vma->vm_end - sizeof(void *);
45037 +
45038 +#ifdef CONFIG_PAX_RANDUSTACK
45039 + if (randomize_va_space)
45040 + bprm->p ^= random32() & ~PAGE_MASK;
45041 +#endif
45042 +
45043 return 0;
45044 err:
45045 up_write(&mm->mmap_sem);
45046 @@ -395,19 +430,7 @@ err:
45047 return err;
45048 }
45049
45050 -struct user_arg_ptr {
45051 -#ifdef CONFIG_COMPAT
45052 - bool is_compat;
45053 -#endif
45054 - union {
45055 - const char __user *const __user *native;
45056 -#ifdef CONFIG_COMPAT
45057 - compat_uptr_t __user *compat;
45058 -#endif
45059 - } ptr;
45060 -};
45061 -
45062 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
45063 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
45064 {
45065 const char __user *native;
45066
45067 @@ -416,14 +439,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
45068 compat_uptr_t compat;
45069
45070 if (get_user(compat, argv.ptr.compat + nr))
45071 - return ERR_PTR(-EFAULT);
45072 + return (const char __force_user *)ERR_PTR(-EFAULT);
45073
45074 return compat_ptr(compat);
45075 }
45076 #endif
45077
45078 if (get_user(native, argv.ptr.native + nr))
45079 - return ERR_PTR(-EFAULT);
45080 + return (const char __force_user *)ERR_PTR(-EFAULT);
45081
45082 return native;
45083 }
45084 @@ -442,7 +465,7 @@ static int count(struct user_arg_ptr argv, int max)
45085 if (!p)
45086 break;
45087
45088 - if (IS_ERR(p))
45089 + if (IS_ERR((const char __force_kernel *)p))
45090 return -EFAULT;
45091
45092 if (i++ >= max)
45093 @@ -476,7 +499,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
45094
45095 ret = -EFAULT;
45096 str = get_user_arg_ptr(argv, argc);
45097 - if (IS_ERR(str))
45098 + if (IS_ERR((const char __force_kernel *)str))
45099 goto out;
45100
45101 len = strnlen_user(str, MAX_ARG_STRLEN);
45102 @@ -558,7 +581,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
45103 int r;
45104 mm_segment_t oldfs = get_fs();
45105 struct user_arg_ptr argv = {
45106 - .ptr.native = (const char __user *const __user *)__argv,
45107 + .ptr.native = (const char __force_user *const __force_user *)__argv,
45108 };
45109
45110 set_fs(KERNEL_DS);
45111 @@ -593,7 +616,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
45112 unsigned long new_end = old_end - shift;
45113 struct mmu_gather tlb;
45114
45115 - BUG_ON(new_start > new_end);
45116 + if (new_start >= new_end || new_start < mmap_min_addr)
45117 + return -ENOMEM;
45118
45119 /*
45120 * ensure there are no vmas between where we want to go
45121 @@ -602,6 +626,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
45122 if (vma != find_vma(mm, new_start))
45123 return -EFAULT;
45124
45125 +#ifdef CONFIG_PAX_SEGMEXEC
45126 + BUG_ON(pax_find_mirror_vma(vma));
45127 +#endif
45128 +
45129 /*
45130 * cover the whole range: [new_start, old_end)
45131 */
45132 @@ -682,10 +710,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
45133 stack_top = arch_align_stack(stack_top);
45134 stack_top = PAGE_ALIGN(stack_top);
45135
45136 - if (unlikely(stack_top < mmap_min_addr) ||
45137 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
45138 - return -ENOMEM;
45139 -
45140 stack_shift = vma->vm_end - stack_top;
45141
45142 bprm->p -= stack_shift;
45143 @@ -697,8 +721,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
45144 bprm->exec -= stack_shift;
45145
45146 down_write(&mm->mmap_sem);
45147 +
45148 + /* Move stack pages down in memory. */
45149 + if (stack_shift) {
45150 + ret = shift_arg_pages(vma, stack_shift);
45151 + if (ret)
45152 + goto out_unlock;
45153 + }
45154 +
45155 vm_flags = VM_STACK_FLAGS;
45156
45157 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45158 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45159 + vm_flags &= ~VM_EXEC;
45160 +
45161 +#ifdef CONFIG_PAX_MPROTECT
45162 + if (mm->pax_flags & MF_PAX_MPROTECT)
45163 + vm_flags &= ~VM_MAYEXEC;
45164 +#endif
45165 +
45166 + }
45167 +#endif
45168 +
45169 /*
45170 * Adjust stack execute permissions; explicitly enable for
45171 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
45172 @@ -717,13 +761,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
45173 goto out_unlock;
45174 BUG_ON(prev != vma);
45175
45176 - /* Move stack pages down in memory. */
45177 - if (stack_shift) {
45178 - ret = shift_arg_pages(vma, stack_shift);
45179 - if (ret)
45180 - goto out_unlock;
45181 - }
45182 -
45183 /* mprotect_fixup is overkill to remove the temporary stack flags */
45184 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
45185
45186 @@ -781,6 +818,8 @@ struct file *open_exec(const char *name)
45187
45188 fsnotify_open(file);
45189
45190 + trace_open_exec(name);
45191 +
45192 err = deny_write_access(file);
45193 if (err)
45194 goto exit;
45195 @@ -804,7 +843,7 @@ int kernel_read(struct file *file, loff_t offset,
45196 old_fs = get_fs();
45197 set_fs(get_ds());
45198 /* The cast to a user pointer is valid due to the set_fs() */
45199 - result = vfs_read(file, (void __user *)addr, count, &pos);
45200 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
45201 set_fs(old_fs);
45202 return result;
45203 }
45204 @@ -1258,7 +1297,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
45205 }
45206 rcu_read_unlock();
45207
45208 - if (p->fs->users > n_fs) {
45209 + if (atomic_read(&p->fs->users) > n_fs) {
45210 bprm->unsafe |= LSM_UNSAFE_SHARE;
45211 } else {
45212 res = -EAGAIN;
45213 @@ -1461,6 +1500,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
45214
45215 EXPORT_SYMBOL(search_binary_handler);
45216
45217 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45218 +static DEFINE_PER_CPU(u64, exec_counter);
45219 +static int __init init_exec_counters(void)
45220 +{
45221 + unsigned int cpu;
45222 +
45223 + for_each_possible_cpu(cpu) {
45224 + per_cpu(exec_counter, cpu) = (u64)cpu;
45225 + }
45226 +
45227 + return 0;
45228 +}
45229 +early_initcall(init_exec_counters);
45230 +static inline void increment_exec_counter(void)
45231 +{
45232 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
45233 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
45234 +}
45235 +#else
45236 +static inline void increment_exec_counter(void) {}
45237 +#endif
45238 +
45239 /*
45240 * sys_execve() executes a new program.
45241 */
45242 @@ -1469,6 +1530,11 @@ static int do_execve_common(const char *filename,
45243 struct user_arg_ptr envp,
45244 struct pt_regs *regs)
45245 {
45246 +#ifdef CONFIG_GRKERNSEC
45247 + struct file *old_exec_file;
45248 + struct acl_subject_label *old_acl;
45249 + struct rlimit old_rlim[RLIM_NLIMITS];
45250 +#endif
45251 struct linux_binprm *bprm;
45252 struct file *file;
45253 struct files_struct *displaced;
45254 @@ -1476,6 +1542,8 @@ static int do_execve_common(const char *filename,
45255 int retval;
45256 const struct cred *cred = current_cred();
45257
45258 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
45259 +
45260 /*
45261 * We move the actual failure in case of RLIMIT_NPROC excess from
45262 * set*uid() to execve() because too many poorly written programs
45263 @@ -1516,12 +1584,27 @@ static int do_execve_common(const char *filename,
45264 if (IS_ERR(file))
45265 goto out_unmark;
45266
45267 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
45268 + retval = -EPERM;
45269 + goto out_file;
45270 + }
45271 +
45272 sched_exec();
45273
45274 bprm->file = file;
45275 bprm->filename = filename;
45276 bprm->interp = filename;
45277
45278 + if (gr_process_user_ban()) {
45279 + retval = -EPERM;
45280 + goto out_file;
45281 + }
45282 +
45283 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
45284 + retval = -EACCES;
45285 + goto out_file;
45286 + }
45287 +
45288 retval = bprm_mm_init(bprm);
45289 if (retval)
45290 goto out_file;
45291 @@ -1538,24 +1621,65 @@ static int do_execve_common(const char *filename,
45292 if (retval < 0)
45293 goto out;
45294
45295 +#ifdef CONFIG_GRKERNSEC
45296 + old_acl = current->acl;
45297 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
45298 + old_exec_file = current->exec_file;
45299 + get_file(file);
45300 + current->exec_file = file;
45301 +#endif
45302 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45303 + /* limit suid stack to 8MB
45304 + we saved the old limits above and will restore them if this exec fails
45305 + */
45306 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
45307 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
45308 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
45309 +#endif
45310 +
45311 + if (!gr_tpe_allow(file)) {
45312 + retval = -EACCES;
45313 + goto out_fail;
45314 + }
45315 +
45316 + if (gr_check_crash_exec(file)) {
45317 + retval = -EACCES;
45318 + goto out_fail;
45319 + }
45320 +
45321 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
45322 + bprm->unsafe);
45323 + if (retval < 0)
45324 + goto out_fail;
45325 +
45326 retval = copy_strings_kernel(1, &bprm->filename, bprm);
45327 if (retval < 0)
45328 - goto out;
45329 + goto out_fail;
45330
45331 bprm->exec = bprm->p;
45332 retval = copy_strings(bprm->envc, envp, bprm);
45333 if (retval < 0)
45334 - goto out;
45335 + goto out_fail;
45336
45337 retval = copy_strings(bprm->argc, argv, bprm);
45338 if (retval < 0)
45339 - goto out;
45340 + goto out_fail;
45341 +
45342 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
45343 +
45344 + gr_handle_exec_args(bprm, argv);
45345
45346 retval = search_binary_handler(bprm,regs);
45347 if (retval < 0)
45348 - goto out;
45349 + goto out_fail;
45350 +#ifdef CONFIG_GRKERNSEC
45351 + if (old_exec_file)
45352 + fput(old_exec_file);
45353 +#endif
45354
45355 /* execve succeeded */
45356 +
45357 + increment_exec_counter();
45358 current->fs->in_exec = 0;
45359 current->in_execve = 0;
45360 acct_update_integrals(current);
45361 @@ -1564,6 +1688,14 @@ static int do_execve_common(const char *filename,
45362 put_files_struct(displaced);
45363 return retval;
45364
45365 +out_fail:
45366 +#ifdef CONFIG_GRKERNSEC
45367 + current->acl = old_acl;
45368 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
45369 + fput(current->exec_file);
45370 + current->exec_file = old_exec_file;
45371 +#endif
45372 +
45373 out:
45374 if (bprm->mm) {
45375 acct_arg_size(bprm, 0);
45376 @@ -1637,7 +1769,7 @@ static int expand_corename(struct core_name *cn)
45377 {
45378 char *old_corename = cn->corename;
45379
45380 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
45381 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
45382 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
45383
45384 if (!cn->corename) {
45385 @@ -1734,7 +1866,7 @@ static int format_corename(struct core_name *cn, long signr)
45386 int pid_in_pattern = 0;
45387 int err = 0;
45388
45389 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
45390 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
45391 cn->corename = kmalloc(cn->size, GFP_KERNEL);
45392 cn->used = 0;
45393
45394 @@ -1831,6 +1963,250 @@ out:
45395 return ispipe;
45396 }
45397
45398 +int pax_check_flags(unsigned long *flags)
45399 +{
45400 + int retval = 0;
45401 +
45402 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
45403 + if (*flags & MF_PAX_SEGMEXEC)
45404 + {
45405 + *flags &= ~MF_PAX_SEGMEXEC;
45406 + retval = -EINVAL;
45407 + }
45408 +#endif
45409 +
45410 + if ((*flags & MF_PAX_PAGEEXEC)
45411 +
45412 +#ifdef CONFIG_PAX_PAGEEXEC
45413 + && (*flags & MF_PAX_SEGMEXEC)
45414 +#endif
45415 +
45416 + )
45417 + {
45418 + *flags &= ~MF_PAX_PAGEEXEC;
45419 + retval = -EINVAL;
45420 + }
45421 +
45422 + if ((*flags & MF_PAX_MPROTECT)
45423 +
45424 +#ifdef CONFIG_PAX_MPROTECT
45425 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45426 +#endif
45427 +
45428 + )
45429 + {
45430 + *flags &= ~MF_PAX_MPROTECT;
45431 + retval = -EINVAL;
45432 + }
45433 +
45434 + if ((*flags & MF_PAX_EMUTRAMP)
45435 +
45436 +#ifdef CONFIG_PAX_EMUTRAMP
45437 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45438 +#endif
45439 +
45440 + )
45441 + {
45442 + *flags &= ~MF_PAX_EMUTRAMP;
45443 + retval = -EINVAL;
45444 + }
45445 +
45446 + return retval;
45447 +}
45448 +
45449 +EXPORT_SYMBOL(pax_check_flags);
45450 +
45451 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45452 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
45453 +{
45454 + struct task_struct *tsk = current;
45455 + struct mm_struct *mm = current->mm;
45456 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
45457 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
45458 + char *path_exec = NULL;
45459 + char *path_fault = NULL;
45460 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
45461 +
45462 + if (buffer_exec && buffer_fault) {
45463 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
45464 +
45465 + down_read(&mm->mmap_sem);
45466 + vma = mm->mmap;
45467 + while (vma && (!vma_exec || !vma_fault)) {
45468 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
45469 + vma_exec = vma;
45470 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
45471 + vma_fault = vma;
45472 + vma = vma->vm_next;
45473 + }
45474 + if (vma_exec) {
45475 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
45476 + if (IS_ERR(path_exec))
45477 + path_exec = "<path too long>";
45478 + else {
45479 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
45480 + if (path_exec) {
45481 + *path_exec = 0;
45482 + path_exec = buffer_exec;
45483 + } else
45484 + path_exec = "<path too long>";
45485 + }
45486 + }
45487 + if (vma_fault) {
45488 + start = vma_fault->vm_start;
45489 + end = vma_fault->vm_end;
45490 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
45491 + if (vma_fault->vm_file) {
45492 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
45493 + if (IS_ERR(path_fault))
45494 + path_fault = "<path too long>";
45495 + else {
45496 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
45497 + if (path_fault) {
45498 + *path_fault = 0;
45499 + path_fault = buffer_fault;
45500 + } else
45501 + path_fault = "<path too long>";
45502 + }
45503 + } else
45504 + path_fault = "<anonymous mapping>";
45505 + }
45506 + up_read(&mm->mmap_sem);
45507 + }
45508 + if (tsk->signal->curr_ip)
45509 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
45510 + else
45511 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
45512 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
45513 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
45514 + task_uid(tsk), task_euid(tsk), pc, sp);
45515 + free_page((unsigned long)buffer_exec);
45516 + free_page((unsigned long)buffer_fault);
45517 + pax_report_insns(regs, pc, sp);
45518 + do_coredump(SIGKILL, SIGKILL, regs);
45519 +}
45520 +#endif
45521 +
45522 +#ifdef CONFIG_PAX_REFCOUNT
45523 +void pax_report_refcount_overflow(struct pt_regs *regs)
45524 +{
45525 + if (current->signal->curr_ip)
45526 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45527 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
45528 + else
45529 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45530 + current->comm, task_pid_nr(current), current_uid(), current_euid());
45531 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
45532 + show_regs(regs);
45533 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
45534 +}
45535 +#endif
45536 +
45537 +#ifdef CONFIG_PAX_USERCOPY
45538 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
45539 +static noinline int check_stack_object(const void *obj, unsigned long len)
45540 +{
45541 + const void * const stack = task_stack_page(current);
45542 + const void * const stackend = stack + THREAD_SIZE;
45543 +
45544 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45545 + const void *frame = NULL;
45546 + const void *oldframe;
45547 +#endif
45548 +
45549 + if (obj + len < obj)
45550 + return -1;
45551 +
45552 + if (obj + len <= stack || stackend <= obj)
45553 + return 0;
45554 +
45555 + if (obj < stack || stackend < obj + len)
45556 + return -1;
45557 +
45558 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45559 + oldframe = __builtin_frame_address(1);
45560 + if (oldframe)
45561 + frame = __builtin_frame_address(2);
45562 + /*
45563 + low ----------------------------------------------> high
45564 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
45565 + ^----------------^
45566 + allow copies only within here
45567 + */
45568 + while (stack <= frame && frame < stackend) {
45569 + /* if obj + len extends past the last frame, this
45570 + check won't pass and the next frame will be 0,
45571 + causing us to bail out and correctly report
45572 + the copy as invalid
45573 + */
45574 + if (obj + len <= frame)
45575 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
45576 + oldframe = frame;
45577 + frame = *(const void * const *)frame;
45578 + }
45579 + return -1;
45580 +#else
45581 + return 1;
45582 +#endif
45583 +}
45584 +
45585 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
45586 +{
45587 + if (current->signal->curr_ip)
45588 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45589 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45590 + else
45591 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45592 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45593 + dump_stack();
45594 + gr_handle_kernel_exploit();
45595 + do_group_exit(SIGKILL);
45596 +}
45597 +#endif
45598 +
45599 +void check_object_size(const void *ptr, unsigned long n, bool to)
45600 +{
45601 +
45602 +#ifdef CONFIG_PAX_USERCOPY
45603 + const char *type;
45604 +
45605 + if (!n)
45606 + return;
45607 +
45608 + type = check_heap_object(ptr, n, to);
45609 + if (!type) {
45610 + if (check_stack_object(ptr, n) != -1)
45611 + return;
45612 + type = "<process stack>";
45613 + }
45614 +
45615 + pax_report_usercopy(ptr, n, to, type);
45616 +#endif
45617 +
45618 +}
45619 +EXPORT_SYMBOL(check_object_size);
45620 +
45621 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
45622 +void pax_track_stack(void)
45623 +{
45624 + unsigned long sp = (unsigned long)&sp;
45625 + if (sp < current_thread_info()->lowest_stack &&
45626 + sp > (unsigned long)task_stack_page(current))
45627 + current_thread_info()->lowest_stack = sp;
45628 +}
45629 +EXPORT_SYMBOL(pax_track_stack);
45630 +#endif
45631 +
45632 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
45633 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
45634 +{
45635 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
45636 + dump_stack();
45637 + do_group_exit(SIGKILL);
45638 +}
45639 +EXPORT_SYMBOL(report_size_overflow);
45640 +#endif
45641 +
45642 static int zap_process(struct task_struct *start, int exit_code)
45643 {
45644 struct task_struct *t;
45645 @@ -2041,17 +2417,17 @@ static void wait_for_dump_helpers(struct file *file)
45646 pipe = file->f_path.dentry->d_inode->i_pipe;
45647
45648 pipe_lock(pipe);
45649 - pipe->readers++;
45650 - pipe->writers--;
45651 + atomic_inc(&pipe->readers);
45652 + atomic_dec(&pipe->writers);
45653
45654 - while ((pipe->readers > 1) && (!signal_pending(current))) {
45655 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
45656 wake_up_interruptible_sync(&pipe->wait);
45657 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
45658 pipe_wait(pipe);
45659 }
45660
45661 - pipe->readers--;
45662 - pipe->writers++;
45663 + atomic_dec(&pipe->readers);
45664 + atomic_inc(&pipe->writers);
45665 pipe_unlock(pipe);
45666
45667 }
45668 @@ -2106,7 +2482,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45669 int flag = 0;
45670 int ispipe;
45671 bool need_nonrelative = false;
45672 - static atomic_t core_dump_count = ATOMIC_INIT(0);
45673 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
45674 struct coredump_params cprm = {
45675 .signr = signr,
45676 .regs = regs,
45677 @@ -2121,6 +2497,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45678
45679 audit_core_dumps(signr);
45680
45681 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
45682 + gr_handle_brute_attach(current, cprm.mm_flags);
45683 +
45684 binfmt = mm->binfmt;
45685 if (!binfmt || !binfmt->core_dump)
45686 goto fail;
45687 @@ -2191,7 +2570,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45688 }
45689 cprm.limit = RLIM_INFINITY;
45690
45691 - dump_count = atomic_inc_return(&core_dump_count);
45692 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
45693 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
45694 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
45695 task_tgid_vnr(current), current->comm);
45696 @@ -2218,6 +2597,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45697 } else {
45698 struct inode *inode;
45699
45700 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
45701 +
45702 if (cprm.limit < binfmt->min_coredump)
45703 goto fail_unlock;
45704
45705 @@ -2269,7 +2650,7 @@ close_fail:
45706 filp_close(cprm.file, NULL);
45707 fail_dropcount:
45708 if (ispipe)
45709 - atomic_dec(&core_dump_count);
45710 + atomic_dec_unchecked(&core_dump_count);
45711 fail_unlock:
45712 kfree(cn.corename);
45713 fail_corename:
45714 @@ -2288,7 +2669,7 @@ fail:
45715 */
45716 int dump_write(struct file *file, const void *addr, int nr)
45717 {
45718 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
45719 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
45720 }
45721 EXPORT_SYMBOL(dump_write);
45722
45723 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
45724 index 376aa77..59a129c 100644
45725 --- a/fs/ext2/balloc.c
45726 +++ b/fs/ext2/balloc.c
45727 @@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
45728
45729 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45730 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45731 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45732 + if (free_blocks < root_blocks + 1 &&
45733 !uid_eq(sbi->s_resuid, current_fsuid()) &&
45734 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45735 - !in_group_p (sbi->s_resgid))) {
45736 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45737 return 0;
45738 }
45739 return 1;
45740 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
45741 index 90d901f..159975f 100644
45742 --- a/fs/ext3/balloc.c
45743 +++ b/fs/ext3/balloc.c
45744 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
45745
45746 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45747 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45748 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45749 + if (free_blocks < root_blocks + 1 &&
45750 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
45751 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45752 - !in_group_p (sbi->s_resgid))) {
45753 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45754 return 0;
45755 }
45756 return 1;
45757 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
45758 index cf18217..8f6b9c3 100644
45759 --- a/fs/ext4/balloc.c
45760 +++ b/fs/ext4/balloc.c
45761 @@ -498,8 +498,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
45762 /* Hm, nope. Are (enough) root reserved clusters available? */
45763 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
45764 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
45765 - capable(CAP_SYS_RESOURCE) ||
45766 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
45767 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
45768 + capable_nolog(CAP_SYS_RESOURCE)) {
45769
45770 if (free_clusters >= (nclusters + dirty_clusters))
45771 return 1;
45772 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
45773 index 5c69f2b..05dec7f 100644
45774 --- a/fs/ext4/ext4.h
45775 +++ b/fs/ext4/ext4.h
45776 @@ -1248,19 +1248,19 @@ struct ext4_sb_info {
45777 unsigned long s_mb_last_start;
45778
45779 /* stats for buddy allocator */
45780 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
45781 - atomic_t s_bal_success; /* we found long enough chunks */
45782 - atomic_t s_bal_allocated; /* in blocks */
45783 - atomic_t s_bal_ex_scanned; /* total extents scanned */
45784 - atomic_t s_bal_goals; /* goal hits */
45785 - atomic_t s_bal_breaks; /* too long searches */
45786 - atomic_t s_bal_2orders; /* 2^order hits */
45787 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
45788 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
45789 + atomic_unchecked_t s_bal_allocated; /* in blocks */
45790 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
45791 + atomic_unchecked_t s_bal_goals; /* goal hits */
45792 + atomic_unchecked_t s_bal_breaks; /* too long searches */
45793 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
45794 spinlock_t s_bal_lock;
45795 unsigned long s_mb_buddies_generated;
45796 unsigned long long s_mb_generation_time;
45797 - atomic_t s_mb_lost_chunks;
45798 - atomic_t s_mb_preallocated;
45799 - atomic_t s_mb_discarded;
45800 + atomic_unchecked_t s_mb_lost_chunks;
45801 + atomic_unchecked_t s_mb_preallocated;
45802 + atomic_unchecked_t s_mb_discarded;
45803 atomic_t s_lock_busy;
45804
45805 /* locality groups */
45806 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
45807 index b26410c..7383d90 100644
45808 --- a/fs/ext4/mballoc.c
45809 +++ b/fs/ext4/mballoc.c
45810 @@ -1746,7 +1746,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
45811 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
45812
45813 if (EXT4_SB(sb)->s_mb_stats)
45814 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
45815 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
45816
45817 break;
45818 }
45819 @@ -2040,7 +2040,7 @@ repeat:
45820 ac->ac_status = AC_STATUS_CONTINUE;
45821 ac->ac_flags |= EXT4_MB_HINT_FIRST;
45822 cr = 3;
45823 - atomic_inc(&sbi->s_mb_lost_chunks);
45824 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
45825 goto repeat;
45826 }
45827 }
45828 @@ -2551,25 +2551,25 @@ int ext4_mb_release(struct super_block *sb)
45829 if (sbi->s_mb_stats) {
45830 ext4_msg(sb, KERN_INFO,
45831 "mballoc: %u blocks %u reqs (%u success)",
45832 - atomic_read(&sbi->s_bal_allocated),
45833 - atomic_read(&sbi->s_bal_reqs),
45834 - atomic_read(&sbi->s_bal_success));
45835 + atomic_read_unchecked(&sbi->s_bal_allocated),
45836 + atomic_read_unchecked(&sbi->s_bal_reqs),
45837 + atomic_read_unchecked(&sbi->s_bal_success));
45838 ext4_msg(sb, KERN_INFO,
45839 "mballoc: %u extents scanned, %u goal hits, "
45840 "%u 2^N hits, %u breaks, %u lost",
45841 - atomic_read(&sbi->s_bal_ex_scanned),
45842 - atomic_read(&sbi->s_bal_goals),
45843 - atomic_read(&sbi->s_bal_2orders),
45844 - atomic_read(&sbi->s_bal_breaks),
45845 - atomic_read(&sbi->s_mb_lost_chunks));
45846 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
45847 + atomic_read_unchecked(&sbi->s_bal_goals),
45848 + atomic_read_unchecked(&sbi->s_bal_2orders),
45849 + atomic_read_unchecked(&sbi->s_bal_breaks),
45850 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
45851 ext4_msg(sb, KERN_INFO,
45852 "mballoc: %lu generated and it took %Lu",
45853 sbi->s_mb_buddies_generated,
45854 sbi->s_mb_generation_time);
45855 ext4_msg(sb, KERN_INFO,
45856 "mballoc: %u preallocated, %u discarded",
45857 - atomic_read(&sbi->s_mb_preallocated),
45858 - atomic_read(&sbi->s_mb_discarded));
45859 + atomic_read_unchecked(&sbi->s_mb_preallocated),
45860 + atomic_read_unchecked(&sbi->s_mb_discarded));
45861 }
45862
45863 free_percpu(sbi->s_locality_groups);
45864 @@ -3051,16 +3051,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
45865 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
45866
45867 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
45868 - atomic_inc(&sbi->s_bal_reqs);
45869 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45870 + atomic_inc_unchecked(&sbi->s_bal_reqs);
45871 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45872 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
45873 - atomic_inc(&sbi->s_bal_success);
45874 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
45875 + atomic_inc_unchecked(&sbi->s_bal_success);
45876 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
45877 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
45878 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
45879 - atomic_inc(&sbi->s_bal_goals);
45880 + atomic_inc_unchecked(&sbi->s_bal_goals);
45881 if (ac->ac_found > sbi->s_mb_max_to_scan)
45882 - atomic_inc(&sbi->s_bal_breaks);
45883 + atomic_inc_unchecked(&sbi->s_bal_breaks);
45884 }
45885
45886 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
45887 @@ -3460,7 +3460,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
45888 trace_ext4_mb_new_inode_pa(ac, pa);
45889
45890 ext4_mb_use_inode_pa(ac, pa);
45891 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
45892 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
45893
45894 ei = EXT4_I(ac->ac_inode);
45895 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45896 @@ -3520,7 +3520,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
45897 trace_ext4_mb_new_group_pa(ac, pa);
45898
45899 ext4_mb_use_group_pa(ac, pa);
45900 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45901 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45902
45903 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45904 lg = ac->ac_lg;
45905 @@ -3609,7 +3609,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
45906 * from the bitmap and continue.
45907 */
45908 }
45909 - atomic_add(free, &sbi->s_mb_discarded);
45910 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
45911
45912 return err;
45913 }
45914 @@ -3627,7 +3627,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
45915 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
45916 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
45917 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
45918 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45919 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45920 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
45921
45922 return 0;
45923 diff --git a/fs/fcntl.c b/fs/fcntl.c
45924 index 887b5ba..0e3f2c3 100644
45925 --- a/fs/fcntl.c
45926 +++ b/fs/fcntl.c
45927 @@ -225,6 +225,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
45928 if (err)
45929 return err;
45930
45931 + if (gr_handle_chroot_fowner(pid, type))
45932 + return -ENOENT;
45933 + if (gr_check_protected_task_fowner(pid, type))
45934 + return -EACCES;
45935 +
45936 f_modown(filp, pid, type, force);
45937 return 0;
45938 }
45939 @@ -267,7 +272,7 @@ pid_t f_getown(struct file *filp)
45940
45941 static int f_setown_ex(struct file *filp, unsigned long arg)
45942 {
45943 - struct f_owner_ex * __user owner_p = (void * __user)arg;
45944 + struct f_owner_ex __user *owner_p = (void __user *)arg;
45945 struct f_owner_ex owner;
45946 struct pid *pid;
45947 int type;
45948 @@ -307,7 +312,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
45949
45950 static int f_getown_ex(struct file *filp, unsigned long arg)
45951 {
45952 - struct f_owner_ex * __user owner_p = (void * __user)arg;
45953 + struct f_owner_ex __user *owner_p = (void __user *)arg;
45954 struct f_owner_ex owner;
45955 int ret = 0;
45956
45957 @@ -374,6 +379,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
45958 switch (cmd) {
45959 case F_DUPFD:
45960 case F_DUPFD_CLOEXEC:
45961 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
45962 if (arg >= rlimit(RLIMIT_NOFILE))
45963 break;
45964 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
45965 diff --git a/fs/fifo.c b/fs/fifo.c
45966 index cf6f434..3d7942c 100644
45967 --- a/fs/fifo.c
45968 +++ b/fs/fifo.c
45969 @@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
45970 */
45971 filp->f_op = &read_pipefifo_fops;
45972 pipe->r_counter++;
45973 - if (pipe->readers++ == 0)
45974 + if (atomic_inc_return(&pipe->readers) == 1)
45975 wake_up_partner(inode);
45976
45977 - if (!pipe->writers) {
45978 + if (!atomic_read(&pipe->writers)) {
45979 if ((filp->f_flags & O_NONBLOCK)) {
45980 /* suppress POLLHUP until we have
45981 * seen a writer */
45982 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
45983 * errno=ENXIO when there is no process reading the FIFO.
45984 */
45985 ret = -ENXIO;
45986 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
45987 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
45988 goto err;
45989
45990 filp->f_op = &write_pipefifo_fops;
45991 pipe->w_counter++;
45992 - if (!pipe->writers++)
45993 + if (atomic_inc_return(&pipe->writers) == 1)
45994 wake_up_partner(inode);
45995
45996 - if (!pipe->readers) {
45997 + if (!atomic_read(&pipe->readers)) {
45998 if (wait_for_partner(inode, &pipe->r_counter))
45999 goto err_wr;
46000 }
46001 @@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
46002 */
46003 filp->f_op = &rdwr_pipefifo_fops;
46004
46005 - pipe->readers++;
46006 - pipe->writers++;
46007 + atomic_inc(&pipe->readers);
46008 + atomic_inc(&pipe->writers);
46009 pipe->r_counter++;
46010 pipe->w_counter++;
46011 - if (pipe->readers == 1 || pipe->writers == 1)
46012 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
46013 wake_up_partner(inode);
46014 break;
46015
46016 @@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
46017 return 0;
46018
46019 err_rd:
46020 - if (!--pipe->readers)
46021 + if (atomic_dec_and_test(&pipe->readers))
46022 wake_up_interruptible(&pipe->wait);
46023 ret = -ERESTARTSYS;
46024 goto err;
46025
46026 err_wr:
46027 - if (!--pipe->writers)
46028 + if (atomic_dec_and_test(&pipe->writers))
46029 wake_up_interruptible(&pipe->wait);
46030 ret = -ERESTARTSYS;
46031 goto err;
46032
46033 err:
46034 - if (!pipe->readers && !pipe->writers)
46035 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
46036 free_pipe_info(inode);
46037
46038 err_nocleanup:
46039 diff --git a/fs/file.c b/fs/file.c
46040 index ba3f605..fade102 100644
46041 --- a/fs/file.c
46042 +++ b/fs/file.c
46043 @@ -15,6 +15,7 @@
46044 #include <linux/slab.h>
46045 #include <linux/vmalloc.h>
46046 #include <linux/file.h>
46047 +#include <linux/security.h>
46048 #include <linux/fdtable.h>
46049 #include <linux/bitops.h>
46050 #include <linux/interrupt.h>
46051 @@ -255,6 +256,7 @@ int expand_files(struct files_struct *files, int nr)
46052 * N.B. For clone tasks sharing a files structure, this test
46053 * will limit the total number of files that can be opened.
46054 */
46055 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
46056 if (nr >= rlimit(RLIMIT_NOFILE))
46057 return -EMFILE;
46058
46059 diff --git a/fs/filesystems.c b/fs/filesystems.c
46060 index 96f2428..f5eeb8e 100644
46061 --- a/fs/filesystems.c
46062 +++ b/fs/filesystems.c
46063 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
46064 int len = dot ? dot - name : strlen(name);
46065
46066 fs = __get_fs_type(name, len);
46067 +
46068 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
46069 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
46070 +#else
46071 if (!fs && (request_module("%.*s", len, name) == 0))
46072 +#endif
46073 fs = __get_fs_type(name, len);
46074
46075 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
46076 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
46077 index 5df4775..9d9336f 100644
46078 --- a/fs/fs_struct.c
46079 +++ b/fs/fs_struct.c
46080 @@ -4,6 +4,7 @@
46081 #include <linux/path.h>
46082 #include <linux/slab.h>
46083 #include <linux/fs_struct.h>
46084 +#include <linux/grsecurity.h>
46085 #include "internal.h"
46086
46087 /*
46088 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
46089 write_seqcount_begin(&fs->seq);
46090 old_root = fs->root;
46091 fs->root = *path;
46092 + gr_set_chroot_entries(current, path);
46093 write_seqcount_end(&fs->seq);
46094 spin_unlock(&fs->lock);
46095 if (old_root.dentry)
46096 @@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
46097 return 1;
46098 }
46099
46100 +static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
46101 +{
46102 + if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
46103 + return 0;
46104 + *p = *new;
46105 +
46106 + /* This function is only called from pivot_root(). Leave our
46107 + gr_chroot_dentry and is_chrooted flags as-is, so that a
46108 + pivoted root isn't treated as a chroot
46109 + */
46110 + //gr_set_chroot_entries(task, new);
46111 +
46112 + return 1;
46113 +}
46114 +
46115 void chroot_fs_refs(struct path *old_root, struct path *new_root)
46116 {
46117 struct task_struct *g, *p;
46118 @@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
46119 int hits = 0;
46120 spin_lock(&fs->lock);
46121 write_seqcount_begin(&fs->seq);
46122 - hits += replace_path(&fs->root, old_root, new_root);
46123 + hits += replace_root_path(p, &fs->root, old_root, new_root);
46124 hits += replace_path(&fs->pwd, old_root, new_root);
46125 write_seqcount_end(&fs->seq);
46126 while (hits--) {
46127 @@ -99,7 +116,8 @@ void exit_fs(struct task_struct *tsk)
46128 task_lock(tsk);
46129 spin_lock(&fs->lock);
46130 tsk->fs = NULL;
46131 - kill = !--fs->users;
46132 + gr_clear_chroot_entries(tsk);
46133 + kill = !atomic_dec_return(&fs->users);
46134 spin_unlock(&fs->lock);
46135 task_unlock(tsk);
46136 if (kill)
46137 @@ -112,7 +130,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
46138 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
46139 /* We don't need to lock fs - think why ;-) */
46140 if (fs) {
46141 - fs->users = 1;
46142 + atomic_set(&fs->users, 1);
46143 fs->in_exec = 0;
46144 spin_lock_init(&fs->lock);
46145 seqcount_init(&fs->seq);
46146 @@ -121,6 +139,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
46147 spin_lock(&old->lock);
46148 fs->root = old->root;
46149 path_get(&fs->root);
46150 + /* instead of calling gr_set_chroot_entries here,
46151 + we call it from every caller of this function
46152 + */
46153 fs->pwd = old->pwd;
46154 path_get(&fs->pwd);
46155 spin_unlock(&old->lock);
46156 @@ -139,8 +160,9 @@ int unshare_fs_struct(void)
46157
46158 task_lock(current);
46159 spin_lock(&fs->lock);
46160 - kill = !--fs->users;
46161 + kill = !atomic_dec_return(&fs->users);
46162 current->fs = new_fs;
46163 + gr_set_chroot_entries(current, &new_fs->root);
46164 spin_unlock(&fs->lock);
46165 task_unlock(current);
46166
46167 @@ -153,13 +175,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
46168
46169 int current_umask(void)
46170 {
46171 - return current->fs->umask;
46172 + return current->fs->umask | gr_acl_umask();
46173 }
46174 EXPORT_SYMBOL(current_umask);
46175
46176 /* to be mentioned only in INIT_TASK */
46177 struct fs_struct init_fs = {
46178 - .users = 1,
46179 + .users = ATOMIC_INIT(1),
46180 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
46181 .seq = SEQCNT_ZERO,
46182 .umask = 0022,
46183 @@ -175,12 +197,13 @@ void daemonize_fs_struct(void)
46184 task_lock(current);
46185
46186 spin_lock(&init_fs.lock);
46187 - init_fs.users++;
46188 + atomic_inc(&init_fs.users);
46189 spin_unlock(&init_fs.lock);
46190
46191 spin_lock(&fs->lock);
46192 current->fs = &init_fs;
46193 - kill = !--fs->users;
46194 + gr_set_chroot_entries(current, &current->fs->root);
46195 + kill = !atomic_dec_return(&fs->users);
46196 spin_unlock(&fs->lock);
46197
46198 task_unlock(current);
46199 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
46200 index 9905350..02eaec4 100644
46201 --- a/fs/fscache/cookie.c
46202 +++ b/fs/fscache/cookie.c
46203 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
46204 parent ? (char *) parent->def->name : "<no-parent>",
46205 def->name, netfs_data);
46206
46207 - fscache_stat(&fscache_n_acquires);
46208 + fscache_stat_unchecked(&fscache_n_acquires);
46209
46210 /* if there's no parent cookie, then we don't create one here either */
46211 if (!parent) {
46212 - fscache_stat(&fscache_n_acquires_null);
46213 + fscache_stat_unchecked(&fscache_n_acquires_null);
46214 _leave(" [no parent]");
46215 return NULL;
46216 }
46217 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
46218 /* allocate and initialise a cookie */
46219 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
46220 if (!cookie) {
46221 - fscache_stat(&fscache_n_acquires_oom);
46222 + fscache_stat_unchecked(&fscache_n_acquires_oom);
46223 _leave(" [ENOMEM]");
46224 return NULL;
46225 }
46226 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46227
46228 switch (cookie->def->type) {
46229 case FSCACHE_COOKIE_TYPE_INDEX:
46230 - fscache_stat(&fscache_n_cookie_index);
46231 + fscache_stat_unchecked(&fscache_n_cookie_index);
46232 break;
46233 case FSCACHE_COOKIE_TYPE_DATAFILE:
46234 - fscache_stat(&fscache_n_cookie_data);
46235 + fscache_stat_unchecked(&fscache_n_cookie_data);
46236 break;
46237 default:
46238 - fscache_stat(&fscache_n_cookie_special);
46239 + fscache_stat_unchecked(&fscache_n_cookie_special);
46240 break;
46241 }
46242
46243 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46244 if (fscache_acquire_non_index_cookie(cookie) < 0) {
46245 atomic_dec(&parent->n_children);
46246 __fscache_cookie_put(cookie);
46247 - fscache_stat(&fscache_n_acquires_nobufs);
46248 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
46249 _leave(" = NULL");
46250 return NULL;
46251 }
46252 }
46253
46254 - fscache_stat(&fscache_n_acquires_ok);
46255 + fscache_stat_unchecked(&fscache_n_acquires_ok);
46256 _leave(" = %p", cookie);
46257 return cookie;
46258 }
46259 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
46260 cache = fscache_select_cache_for_object(cookie->parent);
46261 if (!cache) {
46262 up_read(&fscache_addremove_sem);
46263 - fscache_stat(&fscache_n_acquires_no_cache);
46264 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
46265 _leave(" = -ENOMEDIUM [no cache]");
46266 return -ENOMEDIUM;
46267 }
46268 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
46269 object = cache->ops->alloc_object(cache, cookie);
46270 fscache_stat_d(&fscache_n_cop_alloc_object);
46271 if (IS_ERR(object)) {
46272 - fscache_stat(&fscache_n_object_no_alloc);
46273 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
46274 ret = PTR_ERR(object);
46275 goto error;
46276 }
46277
46278 - fscache_stat(&fscache_n_object_alloc);
46279 + fscache_stat_unchecked(&fscache_n_object_alloc);
46280
46281 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
46282
46283 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
46284 struct fscache_object *object;
46285 struct hlist_node *_p;
46286
46287 - fscache_stat(&fscache_n_updates);
46288 + fscache_stat_unchecked(&fscache_n_updates);
46289
46290 if (!cookie) {
46291 - fscache_stat(&fscache_n_updates_null);
46292 + fscache_stat_unchecked(&fscache_n_updates_null);
46293 _leave(" [no cookie]");
46294 return;
46295 }
46296 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46297 struct fscache_object *object;
46298 unsigned long event;
46299
46300 - fscache_stat(&fscache_n_relinquishes);
46301 + fscache_stat_unchecked(&fscache_n_relinquishes);
46302 if (retire)
46303 - fscache_stat(&fscache_n_relinquishes_retire);
46304 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
46305
46306 if (!cookie) {
46307 - fscache_stat(&fscache_n_relinquishes_null);
46308 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
46309 _leave(" [no cookie]");
46310 return;
46311 }
46312 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46313
46314 /* wait for the cookie to finish being instantiated (or to fail) */
46315 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
46316 - fscache_stat(&fscache_n_relinquishes_waitcrt);
46317 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
46318 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
46319 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
46320 }
46321 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
46322 index f6aad48..88dcf26 100644
46323 --- a/fs/fscache/internal.h
46324 +++ b/fs/fscache/internal.h
46325 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
46326 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
46327 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
46328
46329 -extern atomic_t fscache_n_op_pend;
46330 -extern atomic_t fscache_n_op_run;
46331 -extern atomic_t fscache_n_op_enqueue;
46332 -extern atomic_t fscache_n_op_deferred_release;
46333 -extern atomic_t fscache_n_op_release;
46334 -extern atomic_t fscache_n_op_gc;
46335 -extern atomic_t fscache_n_op_cancelled;
46336 -extern atomic_t fscache_n_op_rejected;
46337 +extern atomic_unchecked_t fscache_n_op_pend;
46338 +extern atomic_unchecked_t fscache_n_op_run;
46339 +extern atomic_unchecked_t fscache_n_op_enqueue;
46340 +extern atomic_unchecked_t fscache_n_op_deferred_release;
46341 +extern atomic_unchecked_t fscache_n_op_release;
46342 +extern atomic_unchecked_t fscache_n_op_gc;
46343 +extern atomic_unchecked_t fscache_n_op_cancelled;
46344 +extern atomic_unchecked_t fscache_n_op_rejected;
46345
46346 -extern atomic_t fscache_n_attr_changed;
46347 -extern atomic_t fscache_n_attr_changed_ok;
46348 -extern atomic_t fscache_n_attr_changed_nobufs;
46349 -extern atomic_t fscache_n_attr_changed_nomem;
46350 -extern atomic_t fscache_n_attr_changed_calls;
46351 +extern atomic_unchecked_t fscache_n_attr_changed;
46352 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
46353 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
46354 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
46355 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
46356
46357 -extern atomic_t fscache_n_allocs;
46358 -extern atomic_t fscache_n_allocs_ok;
46359 -extern atomic_t fscache_n_allocs_wait;
46360 -extern atomic_t fscache_n_allocs_nobufs;
46361 -extern atomic_t fscache_n_allocs_intr;
46362 -extern atomic_t fscache_n_allocs_object_dead;
46363 -extern atomic_t fscache_n_alloc_ops;
46364 -extern atomic_t fscache_n_alloc_op_waits;
46365 +extern atomic_unchecked_t fscache_n_allocs;
46366 +extern atomic_unchecked_t fscache_n_allocs_ok;
46367 +extern atomic_unchecked_t fscache_n_allocs_wait;
46368 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
46369 +extern atomic_unchecked_t fscache_n_allocs_intr;
46370 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
46371 +extern atomic_unchecked_t fscache_n_alloc_ops;
46372 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
46373
46374 -extern atomic_t fscache_n_retrievals;
46375 -extern atomic_t fscache_n_retrievals_ok;
46376 -extern atomic_t fscache_n_retrievals_wait;
46377 -extern atomic_t fscache_n_retrievals_nodata;
46378 -extern atomic_t fscache_n_retrievals_nobufs;
46379 -extern atomic_t fscache_n_retrievals_intr;
46380 -extern atomic_t fscache_n_retrievals_nomem;
46381 -extern atomic_t fscache_n_retrievals_object_dead;
46382 -extern atomic_t fscache_n_retrieval_ops;
46383 -extern atomic_t fscache_n_retrieval_op_waits;
46384 +extern atomic_unchecked_t fscache_n_retrievals;
46385 +extern atomic_unchecked_t fscache_n_retrievals_ok;
46386 +extern atomic_unchecked_t fscache_n_retrievals_wait;
46387 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
46388 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
46389 +extern atomic_unchecked_t fscache_n_retrievals_intr;
46390 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
46391 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
46392 +extern atomic_unchecked_t fscache_n_retrieval_ops;
46393 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
46394
46395 -extern atomic_t fscache_n_stores;
46396 -extern atomic_t fscache_n_stores_ok;
46397 -extern atomic_t fscache_n_stores_again;
46398 -extern atomic_t fscache_n_stores_nobufs;
46399 -extern atomic_t fscache_n_stores_oom;
46400 -extern atomic_t fscache_n_store_ops;
46401 -extern atomic_t fscache_n_store_calls;
46402 -extern atomic_t fscache_n_store_pages;
46403 -extern atomic_t fscache_n_store_radix_deletes;
46404 -extern atomic_t fscache_n_store_pages_over_limit;
46405 +extern atomic_unchecked_t fscache_n_stores;
46406 +extern atomic_unchecked_t fscache_n_stores_ok;
46407 +extern atomic_unchecked_t fscache_n_stores_again;
46408 +extern atomic_unchecked_t fscache_n_stores_nobufs;
46409 +extern atomic_unchecked_t fscache_n_stores_oom;
46410 +extern atomic_unchecked_t fscache_n_store_ops;
46411 +extern atomic_unchecked_t fscache_n_store_calls;
46412 +extern atomic_unchecked_t fscache_n_store_pages;
46413 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
46414 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
46415
46416 -extern atomic_t fscache_n_store_vmscan_not_storing;
46417 -extern atomic_t fscache_n_store_vmscan_gone;
46418 -extern atomic_t fscache_n_store_vmscan_busy;
46419 -extern atomic_t fscache_n_store_vmscan_cancelled;
46420 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46421 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
46422 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
46423 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46424
46425 -extern atomic_t fscache_n_marks;
46426 -extern atomic_t fscache_n_uncaches;
46427 +extern atomic_unchecked_t fscache_n_marks;
46428 +extern atomic_unchecked_t fscache_n_uncaches;
46429
46430 -extern atomic_t fscache_n_acquires;
46431 -extern atomic_t fscache_n_acquires_null;
46432 -extern atomic_t fscache_n_acquires_no_cache;
46433 -extern atomic_t fscache_n_acquires_ok;
46434 -extern atomic_t fscache_n_acquires_nobufs;
46435 -extern atomic_t fscache_n_acquires_oom;
46436 +extern atomic_unchecked_t fscache_n_acquires;
46437 +extern atomic_unchecked_t fscache_n_acquires_null;
46438 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
46439 +extern atomic_unchecked_t fscache_n_acquires_ok;
46440 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
46441 +extern atomic_unchecked_t fscache_n_acquires_oom;
46442
46443 -extern atomic_t fscache_n_updates;
46444 -extern atomic_t fscache_n_updates_null;
46445 -extern atomic_t fscache_n_updates_run;
46446 +extern atomic_unchecked_t fscache_n_updates;
46447 +extern atomic_unchecked_t fscache_n_updates_null;
46448 +extern atomic_unchecked_t fscache_n_updates_run;
46449
46450 -extern atomic_t fscache_n_relinquishes;
46451 -extern atomic_t fscache_n_relinquishes_null;
46452 -extern atomic_t fscache_n_relinquishes_waitcrt;
46453 -extern atomic_t fscache_n_relinquishes_retire;
46454 +extern atomic_unchecked_t fscache_n_relinquishes;
46455 +extern atomic_unchecked_t fscache_n_relinquishes_null;
46456 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46457 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
46458
46459 -extern atomic_t fscache_n_cookie_index;
46460 -extern atomic_t fscache_n_cookie_data;
46461 -extern atomic_t fscache_n_cookie_special;
46462 +extern atomic_unchecked_t fscache_n_cookie_index;
46463 +extern atomic_unchecked_t fscache_n_cookie_data;
46464 +extern atomic_unchecked_t fscache_n_cookie_special;
46465
46466 -extern atomic_t fscache_n_object_alloc;
46467 -extern atomic_t fscache_n_object_no_alloc;
46468 -extern atomic_t fscache_n_object_lookups;
46469 -extern atomic_t fscache_n_object_lookups_negative;
46470 -extern atomic_t fscache_n_object_lookups_positive;
46471 -extern atomic_t fscache_n_object_lookups_timed_out;
46472 -extern atomic_t fscache_n_object_created;
46473 -extern atomic_t fscache_n_object_avail;
46474 -extern atomic_t fscache_n_object_dead;
46475 +extern atomic_unchecked_t fscache_n_object_alloc;
46476 +extern atomic_unchecked_t fscache_n_object_no_alloc;
46477 +extern atomic_unchecked_t fscache_n_object_lookups;
46478 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
46479 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
46480 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
46481 +extern atomic_unchecked_t fscache_n_object_created;
46482 +extern atomic_unchecked_t fscache_n_object_avail;
46483 +extern atomic_unchecked_t fscache_n_object_dead;
46484
46485 -extern atomic_t fscache_n_checkaux_none;
46486 -extern atomic_t fscache_n_checkaux_okay;
46487 -extern atomic_t fscache_n_checkaux_update;
46488 -extern atomic_t fscache_n_checkaux_obsolete;
46489 +extern atomic_unchecked_t fscache_n_checkaux_none;
46490 +extern atomic_unchecked_t fscache_n_checkaux_okay;
46491 +extern atomic_unchecked_t fscache_n_checkaux_update;
46492 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
46493
46494 extern atomic_t fscache_n_cop_alloc_object;
46495 extern atomic_t fscache_n_cop_lookup_object;
46496 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
46497 atomic_inc(stat);
46498 }
46499
46500 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
46501 +{
46502 + atomic_inc_unchecked(stat);
46503 +}
46504 +
46505 static inline void fscache_stat_d(atomic_t *stat)
46506 {
46507 atomic_dec(stat);
46508 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
46509
46510 #define __fscache_stat(stat) (NULL)
46511 #define fscache_stat(stat) do {} while (0)
46512 +#define fscache_stat_unchecked(stat) do {} while (0)
46513 #define fscache_stat_d(stat) do {} while (0)
46514 #endif
46515
46516 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
46517 index b6b897c..0ffff9c 100644
46518 --- a/fs/fscache/object.c
46519 +++ b/fs/fscache/object.c
46520 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46521 /* update the object metadata on disk */
46522 case FSCACHE_OBJECT_UPDATING:
46523 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
46524 - fscache_stat(&fscache_n_updates_run);
46525 + fscache_stat_unchecked(&fscache_n_updates_run);
46526 fscache_stat(&fscache_n_cop_update_object);
46527 object->cache->ops->update_object(object);
46528 fscache_stat_d(&fscache_n_cop_update_object);
46529 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46530 spin_lock(&object->lock);
46531 object->state = FSCACHE_OBJECT_DEAD;
46532 spin_unlock(&object->lock);
46533 - fscache_stat(&fscache_n_object_dead);
46534 + fscache_stat_unchecked(&fscache_n_object_dead);
46535 goto terminal_transit;
46536
46537 /* handle the parent cache of this object being withdrawn from
46538 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46539 spin_lock(&object->lock);
46540 object->state = FSCACHE_OBJECT_DEAD;
46541 spin_unlock(&object->lock);
46542 - fscache_stat(&fscache_n_object_dead);
46543 + fscache_stat_unchecked(&fscache_n_object_dead);
46544 goto terminal_transit;
46545
46546 /* complain about the object being woken up once it is
46547 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46548 parent->cookie->def->name, cookie->def->name,
46549 object->cache->tag->name);
46550
46551 - fscache_stat(&fscache_n_object_lookups);
46552 + fscache_stat_unchecked(&fscache_n_object_lookups);
46553 fscache_stat(&fscache_n_cop_lookup_object);
46554 ret = object->cache->ops->lookup_object(object);
46555 fscache_stat_d(&fscache_n_cop_lookup_object);
46556 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46557 if (ret == -ETIMEDOUT) {
46558 /* probably stuck behind another object, so move this one to
46559 * the back of the queue */
46560 - fscache_stat(&fscache_n_object_lookups_timed_out);
46561 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
46562 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46563 }
46564
46565 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
46566
46567 spin_lock(&object->lock);
46568 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46569 - fscache_stat(&fscache_n_object_lookups_negative);
46570 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
46571
46572 /* transit here to allow write requests to begin stacking up
46573 * and read requests to begin returning ENODATA */
46574 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
46575 * result, in which case there may be data available */
46576 spin_lock(&object->lock);
46577 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46578 - fscache_stat(&fscache_n_object_lookups_positive);
46579 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
46580
46581 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
46582
46583 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
46584 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46585 } else {
46586 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
46587 - fscache_stat(&fscache_n_object_created);
46588 + fscache_stat_unchecked(&fscache_n_object_created);
46589
46590 object->state = FSCACHE_OBJECT_AVAILABLE;
46591 spin_unlock(&object->lock);
46592 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
46593 fscache_enqueue_dependents(object);
46594
46595 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
46596 - fscache_stat(&fscache_n_object_avail);
46597 + fscache_stat_unchecked(&fscache_n_object_avail);
46598
46599 _leave("");
46600 }
46601 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46602 enum fscache_checkaux result;
46603
46604 if (!object->cookie->def->check_aux) {
46605 - fscache_stat(&fscache_n_checkaux_none);
46606 + fscache_stat_unchecked(&fscache_n_checkaux_none);
46607 return FSCACHE_CHECKAUX_OKAY;
46608 }
46609
46610 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46611 switch (result) {
46612 /* entry okay as is */
46613 case FSCACHE_CHECKAUX_OKAY:
46614 - fscache_stat(&fscache_n_checkaux_okay);
46615 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
46616 break;
46617
46618 /* entry requires update */
46619 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
46620 - fscache_stat(&fscache_n_checkaux_update);
46621 + fscache_stat_unchecked(&fscache_n_checkaux_update);
46622 break;
46623
46624 /* entry requires deletion */
46625 case FSCACHE_CHECKAUX_OBSOLETE:
46626 - fscache_stat(&fscache_n_checkaux_obsolete);
46627 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
46628 break;
46629
46630 default:
46631 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
46632 index 30afdfa..2256596 100644
46633 --- a/fs/fscache/operation.c
46634 +++ b/fs/fscache/operation.c
46635 @@ -17,7 +17,7 @@
46636 #include <linux/slab.h>
46637 #include "internal.h"
46638
46639 -atomic_t fscache_op_debug_id;
46640 +atomic_unchecked_t fscache_op_debug_id;
46641 EXPORT_SYMBOL(fscache_op_debug_id);
46642
46643 /**
46644 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
46645 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
46646 ASSERTCMP(atomic_read(&op->usage), >, 0);
46647
46648 - fscache_stat(&fscache_n_op_enqueue);
46649 + fscache_stat_unchecked(&fscache_n_op_enqueue);
46650 switch (op->flags & FSCACHE_OP_TYPE) {
46651 case FSCACHE_OP_ASYNC:
46652 _debug("queue async");
46653 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
46654 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
46655 if (op->processor)
46656 fscache_enqueue_operation(op);
46657 - fscache_stat(&fscache_n_op_run);
46658 + fscache_stat_unchecked(&fscache_n_op_run);
46659 }
46660
46661 /*
46662 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46663 if (object->n_ops > 1) {
46664 atomic_inc(&op->usage);
46665 list_add_tail(&op->pend_link, &object->pending_ops);
46666 - fscache_stat(&fscache_n_op_pend);
46667 + fscache_stat_unchecked(&fscache_n_op_pend);
46668 } else if (!list_empty(&object->pending_ops)) {
46669 atomic_inc(&op->usage);
46670 list_add_tail(&op->pend_link, &object->pending_ops);
46671 - fscache_stat(&fscache_n_op_pend);
46672 + fscache_stat_unchecked(&fscache_n_op_pend);
46673 fscache_start_operations(object);
46674 } else {
46675 ASSERTCMP(object->n_in_progress, ==, 0);
46676 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46677 object->n_exclusive++; /* reads and writes must wait */
46678 atomic_inc(&op->usage);
46679 list_add_tail(&op->pend_link, &object->pending_ops);
46680 - fscache_stat(&fscache_n_op_pend);
46681 + fscache_stat_unchecked(&fscache_n_op_pend);
46682 ret = 0;
46683 } else {
46684 /* not allowed to submit ops in any other state */
46685 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
46686 if (object->n_exclusive > 0) {
46687 atomic_inc(&op->usage);
46688 list_add_tail(&op->pend_link, &object->pending_ops);
46689 - fscache_stat(&fscache_n_op_pend);
46690 + fscache_stat_unchecked(&fscache_n_op_pend);
46691 } else if (!list_empty(&object->pending_ops)) {
46692 atomic_inc(&op->usage);
46693 list_add_tail(&op->pend_link, &object->pending_ops);
46694 - fscache_stat(&fscache_n_op_pend);
46695 + fscache_stat_unchecked(&fscache_n_op_pend);
46696 fscache_start_operations(object);
46697 } else {
46698 ASSERTCMP(object->n_exclusive, ==, 0);
46699 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
46700 object->n_ops++;
46701 atomic_inc(&op->usage);
46702 list_add_tail(&op->pend_link, &object->pending_ops);
46703 - fscache_stat(&fscache_n_op_pend);
46704 + fscache_stat_unchecked(&fscache_n_op_pend);
46705 ret = 0;
46706 } else if (object->state == FSCACHE_OBJECT_DYING ||
46707 object->state == FSCACHE_OBJECT_LC_DYING ||
46708 object->state == FSCACHE_OBJECT_WITHDRAWING) {
46709 - fscache_stat(&fscache_n_op_rejected);
46710 + fscache_stat_unchecked(&fscache_n_op_rejected);
46711 ret = -ENOBUFS;
46712 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
46713 fscache_report_unexpected_submission(object, op, ostate);
46714 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
46715
46716 ret = -EBUSY;
46717 if (!list_empty(&op->pend_link)) {
46718 - fscache_stat(&fscache_n_op_cancelled);
46719 + fscache_stat_unchecked(&fscache_n_op_cancelled);
46720 list_del_init(&op->pend_link);
46721 object->n_ops--;
46722 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
46723 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
46724 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
46725 BUG();
46726
46727 - fscache_stat(&fscache_n_op_release);
46728 + fscache_stat_unchecked(&fscache_n_op_release);
46729
46730 if (op->release) {
46731 op->release(op);
46732 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
46733 * lock, and defer it otherwise */
46734 if (!spin_trylock(&object->lock)) {
46735 _debug("defer put");
46736 - fscache_stat(&fscache_n_op_deferred_release);
46737 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
46738
46739 cache = object->cache;
46740 spin_lock(&cache->op_gc_list_lock);
46741 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
46742
46743 _debug("GC DEFERRED REL OBJ%x OP%x",
46744 object->debug_id, op->debug_id);
46745 - fscache_stat(&fscache_n_op_gc);
46746 + fscache_stat_unchecked(&fscache_n_op_gc);
46747
46748 ASSERTCMP(atomic_read(&op->usage), ==, 0);
46749
46750 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
46751 index 3f7a59b..cf196cc 100644
46752 --- a/fs/fscache/page.c
46753 +++ b/fs/fscache/page.c
46754 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46755 val = radix_tree_lookup(&cookie->stores, page->index);
46756 if (!val) {
46757 rcu_read_unlock();
46758 - fscache_stat(&fscache_n_store_vmscan_not_storing);
46759 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
46760 __fscache_uncache_page(cookie, page);
46761 return true;
46762 }
46763 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46764 spin_unlock(&cookie->stores_lock);
46765
46766 if (xpage) {
46767 - fscache_stat(&fscache_n_store_vmscan_cancelled);
46768 - fscache_stat(&fscache_n_store_radix_deletes);
46769 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
46770 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46771 ASSERTCMP(xpage, ==, page);
46772 } else {
46773 - fscache_stat(&fscache_n_store_vmscan_gone);
46774 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
46775 }
46776
46777 wake_up_bit(&cookie->flags, 0);
46778 @@ -107,7 +107,7 @@ page_busy:
46779 /* we might want to wait here, but that could deadlock the allocator as
46780 * the work threads writing to the cache may all end up sleeping
46781 * on memory allocation */
46782 - fscache_stat(&fscache_n_store_vmscan_busy);
46783 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
46784 return false;
46785 }
46786 EXPORT_SYMBOL(__fscache_maybe_release_page);
46787 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
46788 FSCACHE_COOKIE_STORING_TAG);
46789 if (!radix_tree_tag_get(&cookie->stores, page->index,
46790 FSCACHE_COOKIE_PENDING_TAG)) {
46791 - fscache_stat(&fscache_n_store_radix_deletes);
46792 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46793 xpage = radix_tree_delete(&cookie->stores, page->index);
46794 }
46795 spin_unlock(&cookie->stores_lock);
46796 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
46797
46798 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
46799
46800 - fscache_stat(&fscache_n_attr_changed_calls);
46801 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
46802
46803 if (fscache_object_is_active(object)) {
46804 fscache_stat(&fscache_n_cop_attr_changed);
46805 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46806
46807 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46808
46809 - fscache_stat(&fscache_n_attr_changed);
46810 + fscache_stat_unchecked(&fscache_n_attr_changed);
46811
46812 op = kzalloc(sizeof(*op), GFP_KERNEL);
46813 if (!op) {
46814 - fscache_stat(&fscache_n_attr_changed_nomem);
46815 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
46816 _leave(" = -ENOMEM");
46817 return -ENOMEM;
46818 }
46819 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46820 if (fscache_submit_exclusive_op(object, op) < 0)
46821 goto nobufs;
46822 spin_unlock(&cookie->lock);
46823 - fscache_stat(&fscache_n_attr_changed_ok);
46824 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
46825 fscache_put_operation(op);
46826 _leave(" = 0");
46827 return 0;
46828 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46829 nobufs:
46830 spin_unlock(&cookie->lock);
46831 kfree(op);
46832 - fscache_stat(&fscache_n_attr_changed_nobufs);
46833 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
46834 _leave(" = %d", -ENOBUFS);
46835 return -ENOBUFS;
46836 }
46837 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
46838 /* allocate a retrieval operation and attempt to submit it */
46839 op = kzalloc(sizeof(*op), GFP_NOIO);
46840 if (!op) {
46841 - fscache_stat(&fscache_n_retrievals_nomem);
46842 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46843 return NULL;
46844 }
46845
46846 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46847 return 0;
46848 }
46849
46850 - fscache_stat(&fscache_n_retrievals_wait);
46851 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
46852
46853 jif = jiffies;
46854 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
46855 fscache_wait_bit_interruptible,
46856 TASK_INTERRUPTIBLE) != 0) {
46857 - fscache_stat(&fscache_n_retrievals_intr);
46858 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46859 _leave(" = -ERESTARTSYS");
46860 return -ERESTARTSYS;
46861 }
46862 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46863 */
46864 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46865 struct fscache_retrieval *op,
46866 - atomic_t *stat_op_waits,
46867 - atomic_t *stat_object_dead)
46868 + atomic_unchecked_t *stat_op_waits,
46869 + atomic_unchecked_t *stat_object_dead)
46870 {
46871 int ret;
46872
46873 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46874 goto check_if_dead;
46875
46876 _debug(">>> WT");
46877 - fscache_stat(stat_op_waits);
46878 + fscache_stat_unchecked(stat_op_waits);
46879 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
46880 fscache_wait_bit_interruptible,
46881 TASK_INTERRUPTIBLE) < 0) {
46882 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46883
46884 check_if_dead:
46885 if (unlikely(fscache_object_is_dead(object))) {
46886 - fscache_stat(stat_object_dead);
46887 + fscache_stat_unchecked(stat_object_dead);
46888 return -ENOBUFS;
46889 }
46890 return 0;
46891 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46892
46893 _enter("%p,%p,,,", cookie, page);
46894
46895 - fscache_stat(&fscache_n_retrievals);
46896 + fscache_stat_unchecked(&fscache_n_retrievals);
46897
46898 if (hlist_empty(&cookie->backing_objects))
46899 goto nobufs;
46900 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46901 goto nobufs_unlock;
46902 spin_unlock(&cookie->lock);
46903
46904 - fscache_stat(&fscache_n_retrieval_ops);
46905 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46906
46907 /* pin the netfs read context in case we need to do the actual netfs
46908 * read because we've encountered a cache read failure */
46909 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46910
46911 error:
46912 if (ret == -ENOMEM)
46913 - fscache_stat(&fscache_n_retrievals_nomem);
46914 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46915 else if (ret == -ERESTARTSYS)
46916 - fscache_stat(&fscache_n_retrievals_intr);
46917 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46918 else if (ret == -ENODATA)
46919 - fscache_stat(&fscache_n_retrievals_nodata);
46920 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46921 else if (ret < 0)
46922 - fscache_stat(&fscache_n_retrievals_nobufs);
46923 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46924 else
46925 - fscache_stat(&fscache_n_retrievals_ok);
46926 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46927
46928 fscache_put_retrieval(op);
46929 _leave(" = %d", ret);
46930 @@ -429,7 +429,7 @@ nobufs_unlock:
46931 spin_unlock(&cookie->lock);
46932 kfree(op);
46933 nobufs:
46934 - fscache_stat(&fscache_n_retrievals_nobufs);
46935 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46936 _leave(" = -ENOBUFS");
46937 return -ENOBUFS;
46938 }
46939 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46940
46941 _enter("%p,,%d,,,", cookie, *nr_pages);
46942
46943 - fscache_stat(&fscache_n_retrievals);
46944 + fscache_stat_unchecked(&fscache_n_retrievals);
46945
46946 if (hlist_empty(&cookie->backing_objects))
46947 goto nobufs;
46948 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46949 goto nobufs_unlock;
46950 spin_unlock(&cookie->lock);
46951
46952 - fscache_stat(&fscache_n_retrieval_ops);
46953 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46954
46955 /* pin the netfs read context in case we need to do the actual netfs
46956 * read because we've encountered a cache read failure */
46957 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46958
46959 error:
46960 if (ret == -ENOMEM)
46961 - fscache_stat(&fscache_n_retrievals_nomem);
46962 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46963 else if (ret == -ERESTARTSYS)
46964 - fscache_stat(&fscache_n_retrievals_intr);
46965 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46966 else if (ret == -ENODATA)
46967 - fscache_stat(&fscache_n_retrievals_nodata);
46968 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46969 else if (ret < 0)
46970 - fscache_stat(&fscache_n_retrievals_nobufs);
46971 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46972 else
46973 - fscache_stat(&fscache_n_retrievals_ok);
46974 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46975
46976 fscache_put_retrieval(op);
46977 _leave(" = %d", ret);
46978 @@ -545,7 +545,7 @@ nobufs_unlock:
46979 spin_unlock(&cookie->lock);
46980 kfree(op);
46981 nobufs:
46982 - fscache_stat(&fscache_n_retrievals_nobufs);
46983 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46984 _leave(" = -ENOBUFS");
46985 return -ENOBUFS;
46986 }
46987 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46988
46989 _enter("%p,%p,,,", cookie, page);
46990
46991 - fscache_stat(&fscache_n_allocs);
46992 + fscache_stat_unchecked(&fscache_n_allocs);
46993
46994 if (hlist_empty(&cookie->backing_objects))
46995 goto nobufs;
46996 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46997 goto nobufs_unlock;
46998 spin_unlock(&cookie->lock);
46999
47000 - fscache_stat(&fscache_n_alloc_ops);
47001 + fscache_stat_unchecked(&fscache_n_alloc_ops);
47002
47003 ret = fscache_wait_for_retrieval_activation(
47004 object, op,
47005 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
47006
47007 error:
47008 if (ret == -ERESTARTSYS)
47009 - fscache_stat(&fscache_n_allocs_intr);
47010 + fscache_stat_unchecked(&fscache_n_allocs_intr);
47011 else if (ret < 0)
47012 - fscache_stat(&fscache_n_allocs_nobufs);
47013 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
47014 else
47015 - fscache_stat(&fscache_n_allocs_ok);
47016 + fscache_stat_unchecked(&fscache_n_allocs_ok);
47017
47018 fscache_put_retrieval(op);
47019 _leave(" = %d", ret);
47020 @@ -625,7 +625,7 @@ nobufs_unlock:
47021 spin_unlock(&cookie->lock);
47022 kfree(op);
47023 nobufs:
47024 - fscache_stat(&fscache_n_allocs_nobufs);
47025 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
47026 _leave(" = -ENOBUFS");
47027 return -ENOBUFS;
47028 }
47029 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
47030
47031 spin_lock(&cookie->stores_lock);
47032
47033 - fscache_stat(&fscache_n_store_calls);
47034 + fscache_stat_unchecked(&fscache_n_store_calls);
47035
47036 /* find a page to store */
47037 page = NULL;
47038 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
47039 page = results[0];
47040 _debug("gang %d [%lx]", n, page->index);
47041 if (page->index > op->store_limit) {
47042 - fscache_stat(&fscache_n_store_pages_over_limit);
47043 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
47044 goto superseded;
47045 }
47046
47047 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
47048 spin_unlock(&cookie->stores_lock);
47049 spin_unlock(&object->lock);
47050
47051 - fscache_stat(&fscache_n_store_pages);
47052 + fscache_stat_unchecked(&fscache_n_store_pages);
47053 fscache_stat(&fscache_n_cop_write_page);
47054 ret = object->cache->ops->write_page(op, page);
47055 fscache_stat_d(&fscache_n_cop_write_page);
47056 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
47057 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
47058 ASSERT(PageFsCache(page));
47059
47060 - fscache_stat(&fscache_n_stores);
47061 + fscache_stat_unchecked(&fscache_n_stores);
47062
47063 op = kzalloc(sizeof(*op), GFP_NOIO);
47064 if (!op)
47065 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
47066 spin_unlock(&cookie->stores_lock);
47067 spin_unlock(&object->lock);
47068
47069 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
47070 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
47071 op->store_limit = object->store_limit;
47072
47073 if (fscache_submit_op(object, &op->op) < 0)
47074 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
47075
47076 spin_unlock(&cookie->lock);
47077 radix_tree_preload_end();
47078 - fscache_stat(&fscache_n_store_ops);
47079 - fscache_stat(&fscache_n_stores_ok);
47080 + fscache_stat_unchecked(&fscache_n_store_ops);
47081 + fscache_stat_unchecked(&fscache_n_stores_ok);
47082
47083 /* the work queue now carries its own ref on the object */
47084 fscache_put_operation(&op->op);
47085 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
47086 return 0;
47087
47088 already_queued:
47089 - fscache_stat(&fscache_n_stores_again);
47090 + fscache_stat_unchecked(&fscache_n_stores_again);
47091 already_pending:
47092 spin_unlock(&cookie->stores_lock);
47093 spin_unlock(&object->lock);
47094 spin_unlock(&cookie->lock);
47095 radix_tree_preload_end();
47096 kfree(op);
47097 - fscache_stat(&fscache_n_stores_ok);
47098 + fscache_stat_unchecked(&fscache_n_stores_ok);
47099 _leave(" = 0");
47100 return 0;
47101
47102 @@ -851,14 +851,14 @@ nobufs:
47103 spin_unlock(&cookie->lock);
47104 radix_tree_preload_end();
47105 kfree(op);
47106 - fscache_stat(&fscache_n_stores_nobufs);
47107 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
47108 _leave(" = -ENOBUFS");
47109 return -ENOBUFS;
47110
47111 nomem_free:
47112 kfree(op);
47113 nomem:
47114 - fscache_stat(&fscache_n_stores_oom);
47115 + fscache_stat_unchecked(&fscache_n_stores_oom);
47116 _leave(" = -ENOMEM");
47117 return -ENOMEM;
47118 }
47119 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
47120 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
47121 ASSERTCMP(page, !=, NULL);
47122
47123 - fscache_stat(&fscache_n_uncaches);
47124 + fscache_stat_unchecked(&fscache_n_uncaches);
47125
47126 /* cache withdrawal may beat us to it */
47127 if (!PageFsCache(page))
47128 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
47129 unsigned long loop;
47130
47131 #ifdef CONFIG_FSCACHE_STATS
47132 - atomic_add(pagevec->nr, &fscache_n_marks);
47133 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
47134 #endif
47135
47136 for (loop = 0; loop < pagevec->nr; loop++) {
47137 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
47138 index 4765190..2a067f2 100644
47139 --- a/fs/fscache/stats.c
47140 +++ b/fs/fscache/stats.c
47141 @@ -18,95 +18,95 @@
47142 /*
47143 * operation counters
47144 */
47145 -atomic_t fscache_n_op_pend;
47146 -atomic_t fscache_n_op_run;
47147 -atomic_t fscache_n_op_enqueue;
47148 -atomic_t fscache_n_op_requeue;
47149 -atomic_t fscache_n_op_deferred_release;
47150 -atomic_t fscache_n_op_release;
47151 -atomic_t fscache_n_op_gc;
47152 -atomic_t fscache_n_op_cancelled;
47153 -atomic_t fscache_n_op_rejected;
47154 +atomic_unchecked_t fscache_n_op_pend;
47155 +atomic_unchecked_t fscache_n_op_run;
47156 +atomic_unchecked_t fscache_n_op_enqueue;
47157 +atomic_unchecked_t fscache_n_op_requeue;
47158 +atomic_unchecked_t fscache_n_op_deferred_release;
47159 +atomic_unchecked_t fscache_n_op_release;
47160 +atomic_unchecked_t fscache_n_op_gc;
47161 +atomic_unchecked_t fscache_n_op_cancelled;
47162 +atomic_unchecked_t fscache_n_op_rejected;
47163
47164 -atomic_t fscache_n_attr_changed;
47165 -atomic_t fscache_n_attr_changed_ok;
47166 -atomic_t fscache_n_attr_changed_nobufs;
47167 -atomic_t fscache_n_attr_changed_nomem;
47168 -atomic_t fscache_n_attr_changed_calls;
47169 +atomic_unchecked_t fscache_n_attr_changed;
47170 +atomic_unchecked_t fscache_n_attr_changed_ok;
47171 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
47172 +atomic_unchecked_t fscache_n_attr_changed_nomem;
47173 +atomic_unchecked_t fscache_n_attr_changed_calls;
47174
47175 -atomic_t fscache_n_allocs;
47176 -atomic_t fscache_n_allocs_ok;
47177 -atomic_t fscache_n_allocs_wait;
47178 -atomic_t fscache_n_allocs_nobufs;
47179 -atomic_t fscache_n_allocs_intr;
47180 -atomic_t fscache_n_allocs_object_dead;
47181 -atomic_t fscache_n_alloc_ops;
47182 -atomic_t fscache_n_alloc_op_waits;
47183 +atomic_unchecked_t fscache_n_allocs;
47184 +atomic_unchecked_t fscache_n_allocs_ok;
47185 +atomic_unchecked_t fscache_n_allocs_wait;
47186 +atomic_unchecked_t fscache_n_allocs_nobufs;
47187 +atomic_unchecked_t fscache_n_allocs_intr;
47188 +atomic_unchecked_t fscache_n_allocs_object_dead;
47189 +atomic_unchecked_t fscache_n_alloc_ops;
47190 +atomic_unchecked_t fscache_n_alloc_op_waits;
47191
47192 -atomic_t fscache_n_retrievals;
47193 -atomic_t fscache_n_retrievals_ok;
47194 -atomic_t fscache_n_retrievals_wait;
47195 -atomic_t fscache_n_retrievals_nodata;
47196 -atomic_t fscache_n_retrievals_nobufs;
47197 -atomic_t fscache_n_retrievals_intr;
47198 -atomic_t fscache_n_retrievals_nomem;
47199 -atomic_t fscache_n_retrievals_object_dead;
47200 -atomic_t fscache_n_retrieval_ops;
47201 -atomic_t fscache_n_retrieval_op_waits;
47202 +atomic_unchecked_t fscache_n_retrievals;
47203 +atomic_unchecked_t fscache_n_retrievals_ok;
47204 +atomic_unchecked_t fscache_n_retrievals_wait;
47205 +atomic_unchecked_t fscache_n_retrievals_nodata;
47206 +atomic_unchecked_t fscache_n_retrievals_nobufs;
47207 +atomic_unchecked_t fscache_n_retrievals_intr;
47208 +atomic_unchecked_t fscache_n_retrievals_nomem;
47209 +atomic_unchecked_t fscache_n_retrievals_object_dead;
47210 +atomic_unchecked_t fscache_n_retrieval_ops;
47211 +atomic_unchecked_t fscache_n_retrieval_op_waits;
47212
47213 -atomic_t fscache_n_stores;
47214 -atomic_t fscache_n_stores_ok;
47215 -atomic_t fscache_n_stores_again;
47216 -atomic_t fscache_n_stores_nobufs;
47217 -atomic_t fscache_n_stores_oom;
47218 -atomic_t fscache_n_store_ops;
47219 -atomic_t fscache_n_store_calls;
47220 -atomic_t fscache_n_store_pages;
47221 -atomic_t fscache_n_store_radix_deletes;
47222 -atomic_t fscache_n_store_pages_over_limit;
47223 +atomic_unchecked_t fscache_n_stores;
47224 +atomic_unchecked_t fscache_n_stores_ok;
47225 +atomic_unchecked_t fscache_n_stores_again;
47226 +atomic_unchecked_t fscache_n_stores_nobufs;
47227 +atomic_unchecked_t fscache_n_stores_oom;
47228 +atomic_unchecked_t fscache_n_store_ops;
47229 +atomic_unchecked_t fscache_n_store_calls;
47230 +atomic_unchecked_t fscache_n_store_pages;
47231 +atomic_unchecked_t fscache_n_store_radix_deletes;
47232 +atomic_unchecked_t fscache_n_store_pages_over_limit;
47233
47234 -atomic_t fscache_n_store_vmscan_not_storing;
47235 -atomic_t fscache_n_store_vmscan_gone;
47236 -atomic_t fscache_n_store_vmscan_busy;
47237 -atomic_t fscache_n_store_vmscan_cancelled;
47238 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
47239 +atomic_unchecked_t fscache_n_store_vmscan_gone;
47240 +atomic_unchecked_t fscache_n_store_vmscan_busy;
47241 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
47242
47243 -atomic_t fscache_n_marks;
47244 -atomic_t fscache_n_uncaches;
47245 +atomic_unchecked_t fscache_n_marks;
47246 +atomic_unchecked_t fscache_n_uncaches;
47247
47248 -atomic_t fscache_n_acquires;
47249 -atomic_t fscache_n_acquires_null;
47250 -atomic_t fscache_n_acquires_no_cache;
47251 -atomic_t fscache_n_acquires_ok;
47252 -atomic_t fscache_n_acquires_nobufs;
47253 -atomic_t fscache_n_acquires_oom;
47254 +atomic_unchecked_t fscache_n_acquires;
47255 +atomic_unchecked_t fscache_n_acquires_null;
47256 +atomic_unchecked_t fscache_n_acquires_no_cache;
47257 +atomic_unchecked_t fscache_n_acquires_ok;
47258 +atomic_unchecked_t fscache_n_acquires_nobufs;
47259 +atomic_unchecked_t fscache_n_acquires_oom;
47260
47261 -atomic_t fscache_n_updates;
47262 -atomic_t fscache_n_updates_null;
47263 -atomic_t fscache_n_updates_run;
47264 +atomic_unchecked_t fscache_n_updates;
47265 +atomic_unchecked_t fscache_n_updates_null;
47266 +atomic_unchecked_t fscache_n_updates_run;
47267
47268 -atomic_t fscache_n_relinquishes;
47269 -atomic_t fscache_n_relinquishes_null;
47270 -atomic_t fscache_n_relinquishes_waitcrt;
47271 -atomic_t fscache_n_relinquishes_retire;
47272 +atomic_unchecked_t fscache_n_relinquishes;
47273 +atomic_unchecked_t fscache_n_relinquishes_null;
47274 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
47275 +atomic_unchecked_t fscache_n_relinquishes_retire;
47276
47277 -atomic_t fscache_n_cookie_index;
47278 -atomic_t fscache_n_cookie_data;
47279 -atomic_t fscache_n_cookie_special;
47280 +atomic_unchecked_t fscache_n_cookie_index;
47281 +atomic_unchecked_t fscache_n_cookie_data;
47282 +atomic_unchecked_t fscache_n_cookie_special;
47283
47284 -atomic_t fscache_n_object_alloc;
47285 -atomic_t fscache_n_object_no_alloc;
47286 -atomic_t fscache_n_object_lookups;
47287 -atomic_t fscache_n_object_lookups_negative;
47288 -atomic_t fscache_n_object_lookups_positive;
47289 -atomic_t fscache_n_object_lookups_timed_out;
47290 -atomic_t fscache_n_object_created;
47291 -atomic_t fscache_n_object_avail;
47292 -atomic_t fscache_n_object_dead;
47293 +atomic_unchecked_t fscache_n_object_alloc;
47294 +atomic_unchecked_t fscache_n_object_no_alloc;
47295 +atomic_unchecked_t fscache_n_object_lookups;
47296 +atomic_unchecked_t fscache_n_object_lookups_negative;
47297 +atomic_unchecked_t fscache_n_object_lookups_positive;
47298 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
47299 +atomic_unchecked_t fscache_n_object_created;
47300 +atomic_unchecked_t fscache_n_object_avail;
47301 +atomic_unchecked_t fscache_n_object_dead;
47302
47303 -atomic_t fscache_n_checkaux_none;
47304 -atomic_t fscache_n_checkaux_okay;
47305 -atomic_t fscache_n_checkaux_update;
47306 -atomic_t fscache_n_checkaux_obsolete;
47307 +atomic_unchecked_t fscache_n_checkaux_none;
47308 +atomic_unchecked_t fscache_n_checkaux_okay;
47309 +atomic_unchecked_t fscache_n_checkaux_update;
47310 +atomic_unchecked_t fscache_n_checkaux_obsolete;
47311
47312 atomic_t fscache_n_cop_alloc_object;
47313 atomic_t fscache_n_cop_lookup_object;
47314 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
47315 seq_puts(m, "FS-Cache statistics\n");
47316
47317 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
47318 - atomic_read(&fscache_n_cookie_index),
47319 - atomic_read(&fscache_n_cookie_data),
47320 - atomic_read(&fscache_n_cookie_special));
47321 + atomic_read_unchecked(&fscache_n_cookie_index),
47322 + atomic_read_unchecked(&fscache_n_cookie_data),
47323 + atomic_read_unchecked(&fscache_n_cookie_special));
47324
47325 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
47326 - atomic_read(&fscache_n_object_alloc),
47327 - atomic_read(&fscache_n_object_no_alloc),
47328 - atomic_read(&fscache_n_object_avail),
47329 - atomic_read(&fscache_n_object_dead));
47330 + atomic_read_unchecked(&fscache_n_object_alloc),
47331 + atomic_read_unchecked(&fscache_n_object_no_alloc),
47332 + atomic_read_unchecked(&fscache_n_object_avail),
47333 + atomic_read_unchecked(&fscache_n_object_dead));
47334 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
47335 - atomic_read(&fscache_n_checkaux_none),
47336 - atomic_read(&fscache_n_checkaux_okay),
47337 - atomic_read(&fscache_n_checkaux_update),
47338 - atomic_read(&fscache_n_checkaux_obsolete));
47339 + atomic_read_unchecked(&fscache_n_checkaux_none),
47340 + atomic_read_unchecked(&fscache_n_checkaux_okay),
47341 + atomic_read_unchecked(&fscache_n_checkaux_update),
47342 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
47343
47344 seq_printf(m, "Pages : mrk=%u unc=%u\n",
47345 - atomic_read(&fscache_n_marks),
47346 - atomic_read(&fscache_n_uncaches));
47347 + atomic_read_unchecked(&fscache_n_marks),
47348 + atomic_read_unchecked(&fscache_n_uncaches));
47349
47350 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
47351 " oom=%u\n",
47352 - atomic_read(&fscache_n_acquires),
47353 - atomic_read(&fscache_n_acquires_null),
47354 - atomic_read(&fscache_n_acquires_no_cache),
47355 - atomic_read(&fscache_n_acquires_ok),
47356 - atomic_read(&fscache_n_acquires_nobufs),
47357 - atomic_read(&fscache_n_acquires_oom));
47358 + atomic_read_unchecked(&fscache_n_acquires),
47359 + atomic_read_unchecked(&fscache_n_acquires_null),
47360 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
47361 + atomic_read_unchecked(&fscache_n_acquires_ok),
47362 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
47363 + atomic_read_unchecked(&fscache_n_acquires_oom));
47364
47365 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
47366 - atomic_read(&fscache_n_object_lookups),
47367 - atomic_read(&fscache_n_object_lookups_negative),
47368 - atomic_read(&fscache_n_object_lookups_positive),
47369 - atomic_read(&fscache_n_object_created),
47370 - atomic_read(&fscache_n_object_lookups_timed_out));
47371 + atomic_read_unchecked(&fscache_n_object_lookups),
47372 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
47373 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
47374 + atomic_read_unchecked(&fscache_n_object_created),
47375 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
47376
47377 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
47378 - atomic_read(&fscache_n_updates),
47379 - atomic_read(&fscache_n_updates_null),
47380 - atomic_read(&fscache_n_updates_run));
47381 + atomic_read_unchecked(&fscache_n_updates),
47382 + atomic_read_unchecked(&fscache_n_updates_null),
47383 + atomic_read_unchecked(&fscache_n_updates_run));
47384
47385 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
47386 - atomic_read(&fscache_n_relinquishes),
47387 - atomic_read(&fscache_n_relinquishes_null),
47388 - atomic_read(&fscache_n_relinquishes_waitcrt),
47389 - atomic_read(&fscache_n_relinquishes_retire));
47390 + atomic_read_unchecked(&fscache_n_relinquishes),
47391 + atomic_read_unchecked(&fscache_n_relinquishes_null),
47392 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
47393 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
47394
47395 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
47396 - atomic_read(&fscache_n_attr_changed),
47397 - atomic_read(&fscache_n_attr_changed_ok),
47398 - atomic_read(&fscache_n_attr_changed_nobufs),
47399 - atomic_read(&fscache_n_attr_changed_nomem),
47400 - atomic_read(&fscache_n_attr_changed_calls));
47401 + atomic_read_unchecked(&fscache_n_attr_changed),
47402 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
47403 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
47404 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
47405 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
47406
47407 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
47408 - atomic_read(&fscache_n_allocs),
47409 - atomic_read(&fscache_n_allocs_ok),
47410 - atomic_read(&fscache_n_allocs_wait),
47411 - atomic_read(&fscache_n_allocs_nobufs),
47412 - atomic_read(&fscache_n_allocs_intr));
47413 + atomic_read_unchecked(&fscache_n_allocs),
47414 + atomic_read_unchecked(&fscache_n_allocs_ok),
47415 + atomic_read_unchecked(&fscache_n_allocs_wait),
47416 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
47417 + atomic_read_unchecked(&fscache_n_allocs_intr));
47418 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
47419 - atomic_read(&fscache_n_alloc_ops),
47420 - atomic_read(&fscache_n_alloc_op_waits),
47421 - atomic_read(&fscache_n_allocs_object_dead));
47422 + atomic_read_unchecked(&fscache_n_alloc_ops),
47423 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
47424 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
47425
47426 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
47427 " int=%u oom=%u\n",
47428 - atomic_read(&fscache_n_retrievals),
47429 - atomic_read(&fscache_n_retrievals_ok),
47430 - atomic_read(&fscache_n_retrievals_wait),
47431 - atomic_read(&fscache_n_retrievals_nodata),
47432 - atomic_read(&fscache_n_retrievals_nobufs),
47433 - atomic_read(&fscache_n_retrievals_intr),
47434 - atomic_read(&fscache_n_retrievals_nomem));
47435 + atomic_read_unchecked(&fscache_n_retrievals),
47436 + atomic_read_unchecked(&fscache_n_retrievals_ok),
47437 + atomic_read_unchecked(&fscache_n_retrievals_wait),
47438 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
47439 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
47440 + atomic_read_unchecked(&fscache_n_retrievals_intr),
47441 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
47442 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
47443 - atomic_read(&fscache_n_retrieval_ops),
47444 - atomic_read(&fscache_n_retrieval_op_waits),
47445 - atomic_read(&fscache_n_retrievals_object_dead));
47446 + atomic_read_unchecked(&fscache_n_retrieval_ops),
47447 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
47448 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
47449
47450 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
47451 - atomic_read(&fscache_n_stores),
47452 - atomic_read(&fscache_n_stores_ok),
47453 - atomic_read(&fscache_n_stores_again),
47454 - atomic_read(&fscache_n_stores_nobufs),
47455 - atomic_read(&fscache_n_stores_oom));
47456 + atomic_read_unchecked(&fscache_n_stores),
47457 + atomic_read_unchecked(&fscache_n_stores_ok),
47458 + atomic_read_unchecked(&fscache_n_stores_again),
47459 + atomic_read_unchecked(&fscache_n_stores_nobufs),
47460 + atomic_read_unchecked(&fscache_n_stores_oom));
47461 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
47462 - atomic_read(&fscache_n_store_ops),
47463 - atomic_read(&fscache_n_store_calls),
47464 - atomic_read(&fscache_n_store_pages),
47465 - atomic_read(&fscache_n_store_radix_deletes),
47466 - atomic_read(&fscache_n_store_pages_over_limit));
47467 + atomic_read_unchecked(&fscache_n_store_ops),
47468 + atomic_read_unchecked(&fscache_n_store_calls),
47469 + atomic_read_unchecked(&fscache_n_store_pages),
47470 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
47471 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
47472
47473 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
47474 - atomic_read(&fscache_n_store_vmscan_not_storing),
47475 - atomic_read(&fscache_n_store_vmscan_gone),
47476 - atomic_read(&fscache_n_store_vmscan_busy),
47477 - atomic_read(&fscache_n_store_vmscan_cancelled));
47478 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
47479 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
47480 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
47481 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
47482
47483 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
47484 - atomic_read(&fscache_n_op_pend),
47485 - atomic_read(&fscache_n_op_run),
47486 - atomic_read(&fscache_n_op_enqueue),
47487 - atomic_read(&fscache_n_op_cancelled),
47488 - atomic_read(&fscache_n_op_rejected));
47489 + atomic_read_unchecked(&fscache_n_op_pend),
47490 + atomic_read_unchecked(&fscache_n_op_run),
47491 + atomic_read_unchecked(&fscache_n_op_enqueue),
47492 + atomic_read_unchecked(&fscache_n_op_cancelled),
47493 + atomic_read_unchecked(&fscache_n_op_rejected));
47494 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
47495 - atomic_read(&fscache_n_op_deferred_release),
47496 - atomic_read(&fscache_n_op_release),
47497 - atomic_read(&fscache_n_op_gc));
47498 + atomic_read_unchecked(&fscache_n_op_deferred_release),
47499 + atomic_read_unchecked(&fscache_n_op_release),
47500 + atomic_read_unchecked(&fscache_n_op_gc));
47501
47502 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
47503 atomic_read(&fscache_n_cop_alloc_object),
47504 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
47505 index ee8d550..7189d8c 100644
47506 --- a/fs/fuse/cuse.c
47507 +++ b/fs/fuse/cuse.c
47508 @@ -585,10 +585,12 @@ static int __init cuse_init(void)
47509 INIT_LIST_HEAD(&cuse_conntbl[i]);
47510
47511 /* inherit and extend fuse_dev_operations */
47512 - cuse_channel_fops = fuse_dev_operations;
47513 - cuse_channel_fops.owner = THIS_MODULE;
47514 - cuse_channel_fops.open = cuse_channel_open;
47515 - cuse_channel_fops.release = cuse_channel_release;
47516 + pax_open_kernel();
47517 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
47518 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
47519 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
47520 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
47521 + pax_close_kernel();
47522
47523 cuse_class = class_create(THIS_MODULE, "cuse");
47524 if (IS_ERR(cuse_class))
47525 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
47526 index f4246cf..b4aed1d 100644
47527 --- a/fs/fuse/dev.c
47528 +++ b/fs/fuse/dev.c
47529 @@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
47530 ret = 0;
47531 pipe_lock(pipe);
47532
47533 - if (!pipe->readers) {
47534 + if (!atomic_read(&pipe->readers)) {
47535 send_sig(SIGPIPE, current, 0);
47536 if (!ret)
47537 ret = -EPIPE;
47538 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
47539 index 324bc08..4fdd56e 100644
47540 --- a/fs/fuse/dir.c
47541 +++ b/fs/fuse/dir.c
47542 @@ -1226,7 +1226,7 @@ static char *read_link(struct dentry *dentry)
47543 return link;
47544 }
47545
47546 -static void free_link(char *link)
47547 +static void free_link(const char *link)
47548 {
47549 if (!IS_ERR(link))
47550 free_page((unsigned long) link);
47551 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
47552 index 753af3d..f7b021a 100644
47553 --- a/fs/gfs2/inode.c
47554 +++ b/fs/gfs2/inode.c
47555 @@ -1498,7 +1498,7 @@ out:
47556
47557 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47558 {
47559 - char *s = nd_get_link(nd);
47560 + const char *s = nd_get_link(nd);
47561 if (!IS_ERR(s))
47562 kfree(s);
47563 }
47564 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
47565 index 8349a89..51a0254 100644
47566 --- a/fs/hugetlbfs/inode.c
47567 +++ b/fs/hugetlbfs/inode.c
47568 @@ -920,7 +920,7 @@ static struct file_system_type hugetlbfs_fs_type = {
47569 .kill_sb = kill_litter_super,
47570 };
47571
47572 -static struct vfsmount *hugetlbfs_vfsmount;
47573 +struct vfsmount *hugetlbfs_vfsmount;
47574
47575 static int can_do_hugetlb_shm(void)
47576 {
47577 diff --git a/fs/inode.c b/fs/inode.c
47578 index ac8d904..9f45d40 100644
47579 --- a/fs/inode.c
47580 +++ b/fs/inode.c
47581 @@ -867,8 +867,8 @@ unsigned int get_next_ino(void)
47582
47583 #ifdef CONFIG_SMP
47584 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
47585 - static atomic_t shared_last_ino;
47586 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
47587 + static atomic_unchecked_t shared_last_ino;
47588 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
47589
47590 res = next - LAST_INO_BATCH;
47591 }
47592 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
47593 index 4a6cf28..d3a29d3 100644
47594 --- a/fs/jffs2/erase.c
47595 +++ b/fs/jffs2/erase.c
47596 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
47597 struct jffs2_unknown_node marker = {
47598 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
47599 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47600 - .totlen = cpu_to_je32(c->cleanmarker_size)
47601 + .totlen = cpu_to_je32(c->cleanmarker_size),
47602 + .hdr_crc = cpu_to_je32(0)
47603 };
47604
47605 jffs2_prealloc_raw_node_refs(c, jeb, 1);
47606 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
47607 index a6597d6..41b30ec 100644
47608 --- a/fs/jffs2/wbuf.c
47609 +++ b/fs/jffs2/wbuf.c
47610 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
47611 {
47612 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
47613 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47614 - .totlen = constant_cpu_to_je32(8)
47615 + .totlen = constant_cpu_to_je32(8),
47616 + .hdr_crc = constant_cpu_to_je32(0)
47617 };
47618
47619 /*
47620 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
47621 index c55c745..f67ee56 100644
47622 --- a/fs/jfs/super.c
47623 +++ b/fs/jfs/super.c
47624 @@ -806,7 +806,7 @@ static int __init init_jfs_fs(void)
47625
47626 jfs_inode_cachep =
47627 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
47628 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
47629 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
47630 init_once);
47631 if (jfs_inode_cachep == NULL)
47632 return -ENOMEM;
47633 diff --git a/fs/libfs.c b/fs/libfs.c
47634 index a74cb17..37fcbe4 100644
47635 --- a/fs/libfs.c
47636 +++ b/fs/libfs.c
47637 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47638
47639 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
47640 struct dentry *next;
47641 + char d_name[sizeof(next->d_iname)];
47642 + const unsigned char *name;
47643 +
47644 next = list_entry(p, struct dentry, d_u.d_child);
47645 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
47646 if (!simple_positive(next)) {
47647 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47648
47649 spin_unlock(&next->d_lock);
47650 spin_unlock(&dentry->d_lock);
47651 - if (filldir(dirent, next->d_name.name,
47652 + name = next->d_name.name;
47653 + if (name == next->d_iname) {
47654 + memcpy(d_name, name, next->d_name.len);
47655 + name = d_name;
47656 + }
47657 + if (filldir(dirent, name,
47658 next->d_name.len, filp->f_pos,
47659 next->d_inode->i_ino,
47660 dt_type(next->d_inode)) < 0)
47661 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
47662 index 05d2912..760abfa 100644
47663 --- a/fs/lockd/clntproc.c
47664 +++ b/fs/lockd/clntproc.c
47665 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
47666 /*
47667 * Cookie counter for NLM requests
47668 */
47669 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
47670 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
47671
47672 void nlmclnt_next_cookie(struct nlm_cookie *c)
47673 {
47674 - u32 cookie = atomic_inc_return(&nlm_cookie);
47675 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
47676
47677 memcpy(c->data, &cookie, 4);
47678 c->len=4;
47679 diff --git a/fs/locks.c b/fs/locks.c
47680 index 7e81bfc..c3649aa 100644
47681 --- a/fs/locks.c
47682 +++ b/fs/locks.c
47683 @@ -2066,16 +2066,16 @@ void locks_remove_flock(struct file *filp)
47684 return;
47685
47686 if (filp->f_op && filp->f_op->flock) {
47687 - struct file_lock fl = {
47688 + struct file_lock flock = {
47689 .fl_pid = current->tgid,
47690 .fl_file = filp,
47691 .fl_flags = FL_FLOCK,
47692 .fl_type = F_UNLCK,
47693 .fl_end = OFFSET_MAX,
47694 };
47695 - filp->f_op->flock(filp, F_SETLKW, &fl);
47696 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
47697 - fl.fl_ops->fl_release_private(&fl);
47698 + filp->f_op->flock(filp, F_SETLKW, &flock);
47699 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
47700 + flock.fl_ops->fl_release_private(&flock);
47701 }
47702
47703 lock_flocks();
47704 diff --git a/fs/namei.c b/fs/namei.c
47705 index 091c4b7..fbcb268 100644
47706 --- a/fs/namei.c
47707 +++ b/fs/namei.c
47708 @@ -265,16 +265,32 @@ int generic_permission(struct inode *inode, int mask)
47709 if (ret != -EACCES)
47710 return ret;
47711
47712 +#ifdef CONFIG_GRKERNSEC
47713 + /* we'll block if we have to log due to a denied capability use */
47714 + if (mask & MAY_NOT_BLOCK)
47715 + return -ECHILD;
47716 +#endif
47717 +
47718 if (S_ISDIR(inode->i_mode)) {
47719 /* DACs are overridable for directories */
47720 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
47721 - return 0;
47722 if (!(mask & MAY_WRITE))
47723 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47724 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47725 + inode_capable(inode, CAP_DAC_READ_SEARCH))
47726 return 0;
47727 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
47728 + return 0;
47729 return -EACCES;
47730 }
47731 /*
47732 + * Searching includes executable on directories, else just read.
47733 + */
47734 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47735 + if (mask == MAY_READ)
47736 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47737 + inode_capable(inode, CAP_DAC_READ_SEARCH))
47738 + return 0;
47739 +
47740 + /*
47741 * Read/write DACs are always overridable.
47742 * Executable DACs are overridable when there is
47743 * at least one exec bit set.
47744 @@ -283,14 +299,6 @@ int generic_permission(struct inode *inode, int mask)
47745 if (inode_capable(inode, CAP_DAC_OVERRIDE))
47746 return 0;
47747
47748 - /*
47749 - * Searching includes executable on directories, else just read.
47750 - */
47751 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47752 - if (mask == MAY_READ)
47753 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47754 - return 0;
47755 -
47756 return -EACCES;
47757 }
47758
47759 @@ -772,7 +780,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47760 {
47761 struct dentry *dentry = link->dentry;
47762 int error;
47763 - char *s;
47764 + const char *s;
47765
47766 BUG_ON(nd->flags & LOOKUP_RCU);
47767
47768 @@ -793,6 +801,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47769 if (error)
47770 goto out_put_nd_path;
47771
47772 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
47773 + dentry->d_inode, dentry, nd->path.mnt)) {
47774 + error = -EACCES;
47775 + goto out_put_nd_path;
47776 + }
47777 +
47778 nd->last_type = LAST_BIND;
47779 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
47780 error = PTR_ERR(*p);
47781 @@ -1550,6 +1564,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
47782 break;
47783 res = walk_component(nd, path, &nd->last,
47784 nd->last_type, LOOKUP_FOLLOW);
47785 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
47786 + res = -EACCES;
47787 put_link(nd, &link, cookie);
47788 } while (res > 0);
47789
47790 @@ -1648,7 +1664,7 @@ EXPORT_SYMBOL(full_name_hash);
47791 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
47792 {
47793 unsigned long a, b, adata, bdata, mask, hash, len;
47794 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
47795 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
47796
47797 hash = a = 0;
47798 len = -sizeof(unsigned long);
47799 @@ -1943,6 +1959,8 @@ static int path_lookupat(int dfd, const char *name,
47800 if (err)
47801 break;
47802 err = lookup_last(nd, &path);
47803 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
47804 + err = -EACCES;
47805 put_link(nd, &link, cookie);
47806 }
47807 }
47808 @@ -1950,6 +1968,21 @@ static int path_lookupat(int dfd, const char *name,
47809 if (!err)
47810 err = complete_walk(nd);
47811
47812 + if (!(nd->flags & LOOKUP_PARENT)) {
47813 +#ifdef CONFIG_GRKERNSEC
47814 + if (flags & LOOKUP_RCU) {
47815 + if (!err)
47816 + path_put(&nd->path);
47817 + err = -ECHILD;
47818 + } else
47819 +#endif
47820 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47821 + if (!err)
47822 + path_put(&nd->path);
47823 + err = -ENOENT;
47824 + }
47825 + }
47826 +
47827 if (!err && nd->flags & LOOKUP_DIRECTORY) {
47828 if (!nd->inode->i_op->lookup) {
47829 path_put(&nd->path);
47830 @@ -1977,6 +2010,15 @@ static int do_path_lookup(int dfd, const char *name,
47831 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
47832
47833 if (likely(!retval)) {
47834 + if (*name != '/' && nd->path.dentry && nd->inode) {
47835 +#ifdef CONFIG_GRKERNSEC
47836 + if (flags & LOOKUP_RCU)
47837 + return -ECHILD;
47838 +#endif
47839 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
47840 + return -ENOENT;
47841 + }
47842 +
47843 if (unlikely(!audit_dummy_context())) {
47844 if (nd->path.dentry && nd->inode)
47845 audit_inode(name, nd->path.dentry);
47846 @@ -2336,6 +2378,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
47847 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
47848 return -EPERM;
47849
47850 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
47851 + return -EPERM;
47852 + if (gr_handle_rawio(inode))
47853 + return -EPERM;
47854 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
47855 + return -EACCES;
47856 +
47857 return 0;
47858 }
47859
47860 @@ -2557,7 +2606,7 @@ looked_up:
47861 * cleared otherwise prior to returning.
47862 */
47863 static int lookup_open(struct nameidata *nd, struct path *path,
47864 - struct file *file,
47865 + struct path *link, struct file *file,
47866 const struct open_flags *op,
47867 bool got_write, int *opened)
47868 {
47869 @@ -2592,6 +2641,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
47870 /* Negative dentry, just create the file */
47871 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
47872 umode_t mode = op->mode;
47873 +
47874 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
47875 + error = -EACCES;
47876 + goto out_dput;
47877 + }
47878 +
47879 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
47880 + error = -EACCES;
47881 + goto out_dput;
47882 + }
47883 +
47884 if (!IS_POSIXACL(dir->d_inode))
47885 mode &= ~current_umask();
47886 /*
47887 @@ -2613,6 +2673,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
47888 nd->flags & LOOKUP_EXCL);
47889 if (error)
47890 goto out_dput;
47891 + else
47892 + gr_handle_create(dentry, nd->path.mnt);
47893 }
47894 out_no_open:
47895 path->dentry = dentry;
47896 @@ -2627,7 +2689,7 @@ out_dput:
47897 /*
47898 * Handle the last step of open()
47899 */
47900 -static int do_last(struct nameidata *nd, struct path *path,
47901 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
47902 struct file *file, const struct open_flags *op,
47903 int *opened, const char *pathname)
47904 {
47905 @@ -2656,16 +2718,44 @@ static int do_last(struct nameidata *nd, struct path *path,
47906 error = complete_walk(nd);
47907 if (error)
47908 return error;
47909 +#ifdef CONFIG_GRKERNSEC
47910 + if (nd->flags & LOOKUP_RCU) {
47911 + error = -ECHILD;
47912 + goto out;
47913 + }
47914 +#endif
47915 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47916 + error = -ENOENT;
47917 + goto out;
47918 + }
47919 audit_inode(pathname, nd->path.dentry);
47920 if (open_flag & O_CREAT) {
47921 error = -EISDIR;
47922 goto out;
47923 }
47924 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
47925 + error = -EACCES;
47926 + goto out;
47927 + }
47928 goto finish_open;
47929 case LAST_BIND:
47930 error = complete_walk(nd);
47931 if (error)
47932 return error;
47933 +#ifdef CONFIG_GRKERNSEC
47934 + if (nd->flags & LOOKUP_RCU) {
47935 + error = -ECHILD;
47936 + goto out;
47937 + }
47938 +#endif
47939 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
47940 + error = -ENOENT;
47941 + goto out;
47942 + }
47943 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
47944 + error = -EACCES;
47945 + goto out;
47946 + }
47947 audit_inode(pathname, dir);
47948 goto finish_open;
47949 }
47950 @@ -2714,7 +2804,7 @@ retry_lookup:
47951 */
47952 }
47953 mutex_lock(&dir->d_inode->i_mutex);
47954 - error = lookup_open(nd, path, file, op, got_write, opened);
47955 + error = lookup_open(nd, path, link, file, op, got_write, opened);
47956 mutex_unlock(&dir->d_inode->i_mutex);
47957
47958 if (error <= 0) {
47959 @@ -2738,11 +2828,28 @@ retry_lookup:
47960 goto finish_open_created;
47961 }
47962
47963 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
47964 + error = -ENOENT;
47965 + goto exit_dput;
47966 + }
47967 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
47968 + error = -EACCES;
47969 + goto exit_dput;
47970 + }
47971 +
47972 /*
47973 * create/update audit record if it already exists.
47974 */
47975 - if (path->dentry->d_inode)
47976 + if (path->dentry->d_inode) {
47977 + /* only check if O_CREAT is specified, all other checks need to go
47978 + into may_open */
47979 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
47980 + error = -EACCES;
47981 + goto exit_dput;
47982 + }
47983 +
47984 audit_inode(pathname, path->dentry);
47985 + }
47986
47987 /*
47988 * If atomic_open() acquired write access it is dropped now due to
47989 @@ -2783,6 +2890,11 @@ finish_lookup:
47990 }
47991 }
47992 BUG_ON(inode != path->dentry->d_inode);
47993 + /* if we're resolving a symlink to another symlink */
47994 + if (link && gr_handle_symlink_owner(link, inode)) {
47995 + error = -EACCES;
47996 + goto out;
47997 + }
47998 return 1;
47999 }
48000
48001 @@ -2792,7 +2904,6 @@ finish_lookup:
48002 save_parent.dentry = nd->path.dentry;
48003 save_parent.mnt = mntget(path->mnt);
48004 nd->path.dentry = path->dentry;
48005 -
48006 }
48007 nd->inode = inode;
48008 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
48009 @@ -2801,6 +2912,22 @@ finish_lookup:
48010 path_put(&save_parent);
48011 return error;
48012 }
48013 +
48014 +#ifdef CONFIG_GRKERNSEC
48015 + if (nd->flags & LOOKUP_RCU) {
48016 + error = -ECHILD;
48017 + goto out;
48018 + }
48019 +#endif
48020 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
48021 + error = -ENOENT;
48022 + goto out;
48023 + }
48024 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
48025 + error = -EACCES;
48026 + goto out;
48027 + }
48028 +
48029 error = -EISDIR;
48030 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
48031 goto out;
48032 @@ -2899,7 +3026,7 @@ static struct file *path_openat(int dfd, const char *pathname,
48033 if (unlikely(error))
48034 goto out;
48035
48036 - error = do_last(nd, &path, file, op, &opened, pathname);
48037 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
48038 while (unlikely(error > 0)) { /* trailing symlink */
48039 struct path link = path;
48040 void *cookie;
48041 @@ -2917,7 +3044,7 @@ static struct file *path_openat(int dfd, const char *pathname,
48042 error = follow_link(&link, nd, &cookie);
48043 if (unlikely(error))
48044 break;
48045 - error = do_last(nd, &path, file, op, &opened, pathname);
48046 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
48047 put_link(nd, &link, cookie);
48048 }
48049 out:
48050 @@ -3006,8 +3133,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
48051 goto unlock;
48052
48053 error = -EEXIST;
48054 - if (dentry->d_inode)
48055 + if (dentry->d_inode) {
48056 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
48057 + error = -ENOENT;
48058 + }
48059 goto fail;
48060 + }
48061 /*
48062 * Special case - lookup gave negative, but... we had foo/bar/
48063 * From the vfs_mknod() POV we just have a negative dentry -
48064 @@ -3058,6 +3189,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
48065 }
48066 EXPORT_SYMBOL(user_path_create);
48067
48068 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
48069 +{
48070 + char *tmp = getname(pathname);
48071 + struct dentry *res;
48072 + if (IS_ERR(tmp))
48073 + return ERR_CAST(tmp);
48074 + res = kern_path_create(dfd, tmp, path, is_dir);
48075 + if (IS_ERR(res))
48076 + putname(tmp);
48077 + else
48078 + *to = tmp;
48079 + return res;
48080 +}
48081 +
48082 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
48083 {
48084 int error = may_create(dir, dentry);
48085 @@ -3119,6 +3264,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
48086
48087 if (!IS_POSIXACL(path.dentry->d_inode))
48088 mode &= ~current_umask();
48089 +
48090 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
48091 + error = -EPERM;
48092 + goto out;
48093 + }
48094 +
48095 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
48096 + error = -EACCES;
48097 + goto out;
48098 + }
48099 +
48100 error = security_path_mknod(&path, dentry, mode, dev);
48101 if (error)
48102 goto out;
48103 @@ -3135,6 +3291,8 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
48104 break;
48105 }
48106 out:
48107 + if (!error)
48108 + gr_handle_create(dentry, path.mnt);
48109 done_path_create(&path, dentry);
48110 return error;
48111 }
48112 @@ -3181,9 +3339,18 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
48113
48114 if (!IS_POSIXACL(path.dentry->d_inode))
48115 mode &= ~current_umask();
48116 +
48117 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
48118 + error = -EACCES;
48119 + goto out;
48120 + }
48121 +
48122 error = security_path_mkdir(&path, dentry, mode);
48123 if (!error)
48124 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
48125 + if (!error)
48126 + gr_handle_create(dentry, path.mnt);
48127 +out:
48128 done_path_create(&path, dentry);
48129 return error;
48130 }
48131 @@ -3260,6 +3427,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
48132 char * name;
48133 struct dentry *dentry;
48134 struct nameidata nd;
48135 + ino_t saved_ino = 0;
48136 + dev_t saved_dev = 0;
48137
48138 error = user_path_parent(dfd, pathname, &nd, &name);
48139 if (error)
48140 @@ -3291,10 +3460,21 @@ static long do_rmdir(int dfd, const char __user *pathname)
48141 error = -ENOENT;
48142 goto exit3;
48143 }
48144 +
48145 + saved_ino = dentry->d_inode->i_ino;
48146 + saved_dev = gr_get_dev_from_dentry(dentry);
48147 +
48148 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
48149 + error = -EACCES;
48150 + goto exit3;
48151 + }
48152 +
48153 error = security_path_rmdir(&nd.path, dentry);
48154 if (error)
48155 goto exit3;
48156 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
48157 + if (!error && (saved_dev || saved_ino))
48158 + gr_handle_delete(saved_ino, saved_dev);
48159 exit3:
48160 dput(dentry);
48161 exit2:
48162 @@ -3356,6 +3536,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
48163 struct dentry *dentry;
48164 struct nameidata nd;
48165 struct inode *inode = NULL;
48166 + ino_t saved_ino = 0;
48167 + dev_t saved_dev = 0;
48168
48169 error = user_path_parent(dfd, pathname, &nd, &name);
48170 if (error)
48171 @@ -3381,10 +3563,22 @@ static long do_unlinkat(int dfd, const char __user *pathname)
48172 if (!inode)
48173 goto slashes;
48174 ihold(inode);
48175 +
48176 + if (inode->i_nlink <= 1) {
48177 + saved_ino = inode->i_ino;
48178 + saved_dev = gr_get_dev_from_dentry(dentry);
48179 + }
48180 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
48181 + error = -EACCES;
48182 + goto exit2;
48183 + }
48184 +
48185 error = security_path_unlink(&nd.path, dentry);
48186 if (error)
48187 goto exit2;
48188 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
48189 + if (!error && (saved_ino || saved_dev))
48190 + gr_handle_delete(saved_ino, saved_dev);
48191 exit2:
48192 dput(dentry);
48193 }
48194 @@ -3456,9 +3650,17 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
48195 if (IS_ERR(dentry))
48196 goto out_putname;
48197
48198 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
48199 + error = -EACCES;
48200 + goto out;
48201 + }
48202 +
48203 error = security_path_symlink(&path, dentry, from);
48204 if (!error)
48205 error = vfs_symlink(path.dentry->d_inode, dentry, from);
48206 + if (!error)
48207 + gr_handle_create(dentry, path.mnt);
48208 +out:
48209 done_path_create(&path, dentry);
48210 out_putname:
48211 putname(from);
48212 @@ -3528,6 +3730,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48213 {
48214 struct dentry *new_dentry;
48215 struct path old_path, new_path;
48216 + char *to = NULL;
48217 int how = 0;
48218 int error;
48219
48220 @@ -3551,7 +3754,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48221 if (error)
48222 return error;
48223
48224 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
48225 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
48226 error = PTR_ERR(new_dentry);
48227 if (IS_ERR(new_dentry))
48228 goto out;
48229 @@ -3562,11 +3765,28 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48230 error = may_linkat(&old_path);
48231 if (unlikely(error))
48232 goto out_dput;
48233 +
48234 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
48235 + old_path.dentry->d_inode,
48236 + old_path.dentry->d_inode->i_mode, to)) {
48237 + error = -EACCES;
48238 + goto out_dput;
48239 + }
48240 +
48241 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
48242 + old_path.dentry, old_path.mnt, to)) {
48243 + error = -EACCES;
48244 + goto out_dput;
48245 + }
48246 +
48247 error = security_path_link(old_path.dentry, &new_path, new_dentry);
48248 if (error)
48249 goto out_dput;
48250 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
48251 + if (!error)
48252 + gr_handle_create(new_dentry, new_path.mnt);
48253 out_dput:
48254 + putname(to);
48255 done_path_create(&new_path, new_dentry);
48256 out:
48257 path_put(&old_path);
48258 @@ -3802,12 +4022,21 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
48259 if (new_dentry == trap)
48260 goto exit5;
48261
48262 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
48263 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
48264 + to);
48265 + if (error)
48266 + goto exit5;
48267 +
48268 error = security_path_rename(&oldnd.path, old_dentry,
48269 &newnd.path, new_dentry);
48270 if (error)
48271 goto exit5;
48272 error = vfs_rename(old_dir->d_inode, old_dentry,
48273 new_dir->d_inode, new_dentry);
48274 + if (!error)
48275 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
48276 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
48277 exit5:
48278 dput(new_dentry);
48279 exit4:
48280 @@ -3832,6 +4061,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
48281
48282 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
48283 {
48284 + char tmpbuf[64];
48285 + const char *newlink;
48286 int len;
48287
48288 len = PTR_ERR(link);
48289 @@ -3841,7 +4072,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
48290 len = strlen(link);
48291 if (len > (unsigned) buflen)
48292 len = buflen;
48293 - if (copy_to_user(buffer, link, len))
48294 +
48295 + if (len < sizeof(tmpbuf)) {
48296 + memcpy(tmpbuf, link, len);
48297 + newlink = tmpbuf;
48298 + } else
48299 + newlink = link;
48300 +
48301 + if (copy_to_user(buffer, newlink, len))
48302 len = -EFAULT;
48303 out:
48304 return len;
48305 diff --git a/fs/namespace.c b/fs/namespace.c
48306 index 7bdf790..eb79c4b 100644
48307 --- a/fs/namespace.c
48308 +++ b/fs/namespace.c
48309 @@ -1212,6 +1212,9 @@ static int do_umount(struct mount *mnt, int flags)
48310 if (!(sb->s_flags & MS_RDONLY))
48311 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
48312 up_write(&sb->s_umount);
48313 +
48314 + gr_log_remount(mnt->mnt_devname, retval);
48315 +
48316 return retval;
48317 }
48318
48319 @@ -1231,6 +1234,9 @@ static int do_umount(struct mount *mnt, int flags)
48320 br_write_unlock(&vfsmount_lock);
48321 up_write(&namespace_sem);
48322 release_mounts(&umount_list);
48323 +
48324 + gr_log_unmount(mnt->mnt_devname, retval);
48325 +
48326 return retval;
48327 }
48328
48329 @@ -2244,6 +2250,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
48330 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
48331 MS_STRICTATIME);
48332
48333 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
48334 + retval = -EPERM;
48335 + goto dput_out;
48336 + }
48337 +
48338 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
48339 + retval = -EPERM;
48340 + goto dput_out;
48341 + }
48342 +
48343 if (flags & MS_REMOUNT)
48344 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
48345 data_page);
48346 @@ -2258,6 +2274,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
48347 dev_name, data_page);
48348 dput_out:
48349 path_put(&path);
48350 +
48351 + gr_log_mount(dev_name, dir_name, retval);
48352 +
48353 return retval;
48354 }
48355
48356 @@ -2516,6 +2535,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
48357 if (error)
48358 goto out2;
48359
48360 + if (gr_handle_chroot_pivot()) {
48361 + error = -EPERM;
48362 + goto out2;
48363 + }
48364 +
48365 get_fs_root(current->fs, &root);
48366 error = lock_mount(&old);
48367 if (error)
48368 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
48369 index 9b47610..066975e 100644
48370 --- a/fs/nfs/inode.c
48371 +++ b/fs/nfs/inode.c
48372 @@ -1026,16 +1026,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
48373 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
48374 }
48375
48376 -static atomic_long_t nfs_attr_generation_counter;
48377 +static atomic_long_unchecked_t nfs_attr_generation_counter;
48378
48379 static unsigned long nfs_read_attr_generation_counter(void)
48380 {
48381 - return atomic_long_read(&nfs_attr_generation_counter);
48382 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
48383 }
48384
48385 unsigned long nfs_inc_attr_generation_counter(void)
48386 {
48387 - return atomic_long_inc_return(&nfs_attr_generation_counter);
48388 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
48389 }
48390
48391 void nfs_fattr_init(struct nfs_fattr *fattr)
48392 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
48393 index a9269f1..5490437 100644
48394 --- a/fs/nfsd/vfs.c
48395 +++ b/fs/nfsd/vfs.c
48396 @@ -941,7 +941,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
48397 } else {
48398 oldfs = get_fs();
48399 set_fs(KERNEL_DS);
48400 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
48401 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
48402 set_fs(oldfs);
48403 }
48404
48405 @@ -1045,7 +1045,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
48406
48407 /* Write the data. */
48408 oldfs = get_fs(); set_fs(KERNEL_DS);
48409 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
48410 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
48411 set_fs(oldfs);
48412 if (host_err < 0)
48413 goto out_nfserr;
48414 @@ -1581,7 +1581,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
48415 */
48416
48417 oldfs = get_fs(); set_fs(KERNEL_DS);
48418 - host_err = inode->i_op->readlink(path.dentry, buf, *lenp);
48419 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
48420 set_fs(oldfs);
48421
48422 if (host_err < 0)
48423 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
48424 index d438036..0ecadde 100644
48425 --- a/fs/notify/fanotify/fanotify_user.c
48426 +++ b/fs/notify/fanotify/fanotify_user.c
48427 @@ -274,7 +274,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
48428 goto out_close_fd;
48429
48430 ret = -EFAULT;
48431 - if (copy_to_user(buf, &fanotify_event_metadata,
48432 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
48433 + copy_to_user(buf, &fanotify_event_metadata,
48434 fanotify_event_metadata.event_len))
48435 goto out_kill_access_response;
48436
48437 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
48438 index c887b13..0fdf472 100644
48439 --- a/fs/notify/notification.c
48440 +++ b/fs/notify/notification.c
48441 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
48442 * get set to 0 so it will never get 'freed'
48443 */
48444 static struct fsnotify_event *q_overflow_event;
48445 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48446 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48447
48448 /**
48449 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
48450 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48451 */
48452 u32 fsnotify_get_cookie(void)
48453 {
48454 - return atomic_inc_return(&fsnotify_sync_cookie);
48455 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
48456 }
48457 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
48458
48459 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
48460 index 99e3610..02c1068 100644
48461 --- a/fs/ntfs/dir.c
48462 +++ b/fs/ntfs/dir.c
48463 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
48464 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
48465 ~(s64)(ndir->itype.index.block_size - 1)));
48466 /* Bounds checks. */
48467 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48468 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48469 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
48470 "inode 0x%lx or driver bug.", vdir->i_ino);
48471 goto err_out;
48472 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
48473 index 1ecf464..e1ff8bf 100644
48474 --- a/fs/ntfs/file.c
48475 +++ b/fs/ntfs/file.c
48476 @@ -2232,6 +2232,6 @@ const struct inode_operations ntfs_file_inode_ops = {
48477 #endif /* NTFS_RW */
48478 };
48479
48480 -const struct file_operations ntfs_empty_file_ops = {};
48481 +const struct file_operations ntfs_empty_file_ops __read_only;
48482
48483 -const struct inode_operations ntfs_empty_inode_ops = {};
48484 +const struct inode_operations ntfs_empty_inode_ops __read_only;
48485 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
48486 index a9f78c7..ed8a381 100644
48487 --- a/fs/ocfs2/localalloc.c
48488 +++ b/fs/ocfs2/localalloc.c
48489 @@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
48490 goto bail;
48491 }
48492
48493 - atomic_inc(&osb->alloc_stats.moves);
48494 + atomic_inc_unchecked(&osb->alloc_stats.moves);
48495
48496 bail:
48497 if (handle)
48498 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
48499 index d355e6e..578d905 100644
48500 --- a/fs/ocfs2/ocfs2.h
48501 +++ b/fs/ocfs2/ocfs2.h
48502 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
48503
48504 struct ocfs2_alloc_stats
48505 {
48506 - atomic_t moves;
48507 - atomic_t local_data;
48508 - atomic_t bitmap_data;
48509 - atomic_t bg_allocs;
48510 - atomic_t bg_extends;
48511 + atomic_unchecked_t moves;
48512 + atomic_unchecked_t local_data;
48513 + atomic_unchecked_t bitmap_data;
48514 + atomic_unchecked_t bg_allocs;
48515 + atomic_unchecked_t bg_extends;
48516 };
48517
48518 enum ocfs2_local_alloc_state
48519 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
48520 index f169da4..9112253 100644
48521 --- a/fs/ocfs2/suballoc.c
48522 +++ b/fs/ocfs2/suballoc.c
48523 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
48524 mlog_errno(status);
48525 goto bail;
48526 }
48527 - atomic_inc(&osb->alloc_stats.bg_extends);
48528 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
48529
48530 /* You should never ask for this much metadata */
48531 BUG_ON(bits_wanted >
48532 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
48533 mlog_errno(status);
48534 goto bail;
48535 }
48536 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48537 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48538
48539 *suballoc_loc = res.sr_bg_blkno;
48540 *suballoc_bit_start = res.sr_bit_offset;
48541 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
48542 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
48543 res->sr_bits);
48544
48545 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48546 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48547
48548 BUG_ON(res->sr_bits != 1);
48549
48550 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
48551 mlog_errno(status);
48552 goto bail;
48553 }
48554 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48555 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48556
48557 BUG_ON(res.sr_bits != 1);
48558
48559 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48560 cluster_start,
48561 num_clusters);
48562 if (!status)
48563 - atomic_inc(&osb->alloc_stats.local_data);
48564 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
48565 } else {
48566 if (min_clusters > (osb->bitmap_cpg - 1)) {
48567 /* The only paths asking for contiguousness
48568 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48569 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
48570 res.sr_bg_blkno,
48571 res.sr_bit_offset);
48572 - atomic_inc(&osb->alloc_stats.bitmap_data);
48573 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
48574 *num_clusters = res.sr_bits;
48575 }
48576 }
48577 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
48578 index 68f4541..89cfe6a 100644
48579 --- a/fs/ocfs2/super.c
48580 +++ b/fs/ocfs2/super.c
48581 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
48582 "%10s => GlobalAllocs: %d LocalAllocs: %d "
48583 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
48584 "Stats",
48585 - atomic_read(&osb->alloc_stats.bitmap_data),
48586 - atomic_read(&osb->alloc_stats.local_data),
48587 - atomic_read(&osb->alloc_stats.bg_allocs),
48588 - atomic_read(&osb->alloc_stats.moves),
48589 - atomic_read(&osb->alloc_stats.bg_extends));
48590 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
48591 + atomic_read_unchecked(&osb->alloc_stats.local_data),
48592 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
48593 + atomic_read_unchecked(&osb->alloc_stats.moves),
48594 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
48595
48596 out += snprintf(buf + out, len - out,
48597 "%10s => State: %u Descriptor: %llu Size: %u bits "
48598 @@ -2116,11 +2116,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
48599 spin_lock_init(&osb->osb_xattr_lock);
48600 ocfs2_init_steal_slots(osb);
48601
48602 - atomic_set(&osb->alloc_stats.moves, 0);
48603 - atomic_set(&osb->alloc_stats.local_data, 0);
48604 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
48605 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
48606 - atomic_set(&osb->alloc_stats.bg_extends, 0);
48607 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
48608 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
48609 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
48610 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
48611 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
48612
48613 /* Copy the blockcheck stats from the superblock probe */
48614 osb->osb_ecc_stats = *stats;
48615 diff --git a/fs/open.c b/fs/open.c
48616 index e1f2cdb..3bd5f39 100644
48617 --- a/fs/open.c
48618 +++ b/fs/open.c
48619 @@ -31,6 +31,8 @@
48620 #include <linux/ima.h>
48621 #include <linux/dnotify.h>
48622
48623 +#define CREATE_TRACE_POINTS
48624 +#include <trace/events/fs.h>
48625 #include "internal.h"
48626
48627 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
48628 @@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
48629 error = locks_verify_truncate(inode, NULL, length);
48630 if (!error)
48631 error = security_path_truncate(&path);
48632 +
48633 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
48634 + error = -EACCES;
48635 +
48636 if (!error)
48637 error = do_truncate(path.dentry, length, 0, NULL);
48638
48639 @@ -364,6 +370,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
48640 if (__mnt_is_readonly(path.mnt))
48641 res = -EROFS;
48642
48643 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
48644 + res = -EACCES;
48645 +
48646 out_path_release:
48647 path_put(&path);
48648 out:
48649 @@ -390,6 +399,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
48650 if (error)
48651 goto dput_and_out;
48652
48653 + gr_log_chdir(path.dentry, path.mnt);
48654 +
48655 set_fs_pwd(current->fs, &path);
48656
48657 dput_and_out:
48658 @@ -416,6 +427,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
48659 goto out_putf;
48660
48661 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
48662 +
48663 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
48664 + error = -EPERM;
48665 +
48666 + if (!error)
48667 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
48668 +
48669 if (!error)
48670 set_fs_pwd(current->fs, &file->f_path);
48671 out_putf:
48672 @@ -444,7 +462,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
48673 if (error)
48674 goto dput_and_out;
48675
48676 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
48677 + goto dput_and_out;
48678 +
48679 set_fs_root(current->fs, &path);
48680 +
48681 + gr_handle_chroot_chdir(&path);
48682 +
48683 error = 0;
48684 dput_and_out:
48685 path_put(&path);
48686 @@ -462,6 +486,16 @@ static int chmod_common(struct path *path, umode_t mode)
48687 if (error)
48688 return error;
48689 mutex_lock(&inode->i_mutex);
48690 +
48691 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
48692 + error = -EACCES;
48693 + goto out_unlock;
48694 + }
48695 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
48696 + error = -EACCES;
48697 + goto out_unlock;
48698 + }
48699 +
48700 error = security_path_chmod(path, mode);
48701 if (error)
48702 goto out_unlock;
48703 @@ -517,6 +551,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
48704 uid = make_kuid(current_user_ns(), user);
48705 gid = make_kgid(current_user_ns(), group);
48706
48707 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
48708 + return -EACCES;
48709 +
48710 newattrs.ia_valid = ATTR_CTIME;
48711 if (user != (uid_t) -1) {
48712 if (!uid_valid(uid))
48713 @@ -958,6 +995,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
48714 } else {
48715 fsnotify_open(f);
48716 fd_install(fd, f);
48717 + trace_do_sys_open(tmp, flags, mode);
48718 }
48719 }
48720 putname(tmp);
48721 diff --git a/fs/pipe.c b/fs/pipe.c
48722 index 8d85d70..581036b 100644
48723 --- a/fs/pipe.c
48724 +++ b/fs/pipe.c
48725 @@ -438,9 +438,9 @@ redo:
48726 }
48727 if (bufs) /* More to do? */
48728 continue;
48729 - if (!pipe->writers)
48730 + if (!atomic_read(&pipe->writers))
48731 break;
48732 - if (!pipe->waiting_writers) {
48733 + if (!atomic_read(&pipe->waiting_writers)) {
48734 /* syscall merging: Usually we must not sleep
48735 * if O_NONBLOCK is set, or if we got some data.
48736 * But if a writer sleeps in kernel space, then
48737 @@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
48738 mutex_lock(&inode->i_mutex);
48739 pipe = inode->i_pipe;
48740
48741 - if (!pipe->readers) {
48742 + if (!atomic_read(&pipe->readers)) {
48743 send_sig(SIGPIPE, current, 0);
48744 ret = -EPIPE;
48745 goto out;
48746 @@ -553,7 +553,7 @@ redo1:
48747 for (;;) {
48748 int bufs;
48749
48750 - if (!pipe->readers) {
48751 + if (!atomic_read(&pipe->readers)) {
48752 send_sig(SIGPIPE, current, 0);
48753 if (!ret)
48754 ret = -EPIPE;
48755 @@ -644,9 +644,9 @@ redo2:
48756 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
48757 do_wakeup = 0;
48758 }
48759 - pipe->waiting_writers++;
48760 + atomic_inc(&pipe->waiting_writers);
48761 pipe_wait(pipe);
48762 - pipe->waiting_writers--;
48763 + atomic_dec(&pipe->waiting_writers);
48764 }
48765 out:
48766 mutex_unlock(&inode->i_mutex);
48767 @@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48768 mask = 0;
48769 if (filp->f_mode & FMODE_READ) {
48770 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
48771 - if (!pipe->writers && filp->f_version != pipe->w_counter)
48772 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
48773 mask |= POLLHUP;
48774 }
48775
48776 @@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48777 * Most Unices do not set POLLERR for FIFOs but on Linux they
48778 * behave exactly like pipes for poll().
48779 */
48780 - if (!pipe->readers)
48781 + if (!atomic_read(&pipe->readers))
48782 mask |= POLLERR;
48783 }
48784
48785 @@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
48786
48787 mutex_lock(&inode->i_mutex);
48788 pipe = inode->i_pipe;
48789 - pipe->readers -= decr;
48790 - pipe->writers -= decw;
48791 + atomic_sub(decr, &pipe->readers);
48792 + atomic_sub(decw, &pipe->writers);
48793
48794 - if (!pipe->readers && !pipe->writers) {
48795 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
48796 free_pipe_info(inode);
48797 } else {
48798 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
48799 @@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
48800
48801 if (inode->i_pipe) {
48802 ret = 0;
48803 - inode->i_pipe->readers++;
48804 + atomic_inc(&inode->i_pipe->readers);
48805 }
48806
48807 mutex_unlock(&inode->i_mutex);
48808 @@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
48809
48810 if (inode->i_pipe) {
48811 ret = 0;
48812 - inode->i_pipe->writers++;
48813 + atomic_inc(&inode->i_pipe->writers);
48814 }
48815
48816 mutex_unlock(&inode->i_mutex);
48817 @@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
48818 if (inode->i_pipe) {
48819 ret = 0;
48820 if (filp->f_mode & FMODE_READ)
48821 - inode->i_pipe->readers++;
48822 + atomic_inc(&inode->i_pipe->readers);
48823 if (filp->f_mode & FMODE_WRITE)
48824 - inode->i_pipe->writers++;
48825 + atomic_inc(&inode->i_pipe->writers);
48826 }
48827
48828 mutex_unlock(&inode->i_mutex);
48829 @@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
48830 inode->i_pipe = NULL;
48831 }
48832
48833 -static struct vfsmount *pipe_mnt __read_mostly;
48834 +struct vfsmount *pipe_mnt __read_mostly;
48835
48836 /*
48837 * pipefs_dname() is called from d_path().
48838 @@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
48839 goto fail_iput;
48840 inode->i_pipe = pipe;
48841
48842 - pipe->readers = pipe->writers = 1;
48843 + atomic_set(&pipe->readers, 1);
48844 + atomic_set(&pipe->writers, 1);
48845 inode->i_fop = &rdwr_pipefifo_fops;
48846
48847 /*
48848 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
48849 index 15af622..0e9f4467 100644
48850 --- a/fs/proc/Kconfig
48851 +++ b/fs/proc/Kconfig
48852 @@ -30,12 +30,12 @@ config PROC_FS
48853
48854 config PROC_KCORE
48855 bool "/proc/kcore support" if !ARM
48856 - depends on PROC_FS && MMU
48857 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
48858
48859 config PROC_VMCORE
48860 bool "/proc/vmcore support"
48861 - depends on PROC_FS && CRASH_DUMP
48862 - default y
48863 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
48864 + default n
48865 help
48866 Exports the dump image of crashed kernel in ELF format.
48867
48868 @@ -59,8 +59,8 @@ config PROC_SYSCTL
48869 limited in memory.
48870
48871 config PROC_PAGE_MONITOR
48872 - default y
48873 - depends on PROC_FS && MMU
48874 + default n
48875 + depends on PROC_FS && MMU && !GRKERNSEC
48876 bool "Enable /proc page monitoring" if EXPERT
48877 help
48878 Various /proc files exist to monitor process memory utilization:
48879 diff --git a/fs/proc/array.c b/fs/proc/array.c
48880 index c1c207c..01ce725 100644
48881 --- a/fs/proc/array.c
48882 +++ b/fs/proc/array.c
48883 @@ -60,6 +60,7 @@
48884 #include <linux/tty.h>
48885 #include <linux/string.h>
48886 #include <linux/mman.h>
48887 +#include <linux/grsecurity.h>
48888 #include <linux/proc_fs.h>
48889 #include <linux/ioport.h>
48890 #include <linux/uaccess.h>
48891 @@ -346,6 +347,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
48892 seq_putc(m, '\n');
48893 }
48894
48895 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48896 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
48897 +{
48898 + if (p->mm)
48899 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
48900 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
48901 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
48902 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
48903 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
48904 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
48905 + else
48906 + seq_printf(m, "PaX:\t-----\n");
48907 +}
48908 +#endif
48909 +
48910 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48911 struct pid *pid, struct task_struct *task)
48912 {
48913 @@ -363,9 +379,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48914 task_cpus_allowed(m, task);
48915 cpuset_task_status_allowed(m, task);
48916 task_context_switch_counts(m, task);
48917 +
48918 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48919 + task_pax(m, task);
48920 +#endif
48921 +
48922 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
48923 + task_grsec_rbac(m, task);
48924 +#endif
48925 +
48926 return 0;
48927 }
48928
48929 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48930 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48931 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48932 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48933 +#endif
48934 +
48935 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48936 struct pid *pid, struct task_struct *task, int whole)
48937 {
48938 @@ -387,6 +418,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48939 char tcomm[sizeof(task->comm)];
48940 unsigned long flags;
48941
48942 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48943 + if (current->exec_id != m->exec_id) {
48944 + gr_log_badprocpid("stat");
48945 + return 0;
48946 + }
48947 +#endif
48948 +
48949 state = *get_task_state(task);
48950 vsize = eip = esp = 0;
48951 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48952 @@ -458,6 +496,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48953 gtime = task->gtime;
48954 }
48955
48956 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48957 + if (PAX_RAND_FLAGS(mm)) {
48958 + eip = 0;
48959 + esp = 0;
48960 + wchan = 0;
48961 + }
48962 +#endif
48963 +#ifdef CONFIG_GRKERNSEC_HIDESYM
48964 + wchan = 0;
48965 + eip =0;
48966 + esp =0;
48967 +#endif
48968 +
48969 /* scale priority and nice values from timeslices to -20..20 */
48970 /* to make it look like a "normal" Unix priority/nice value */
48971 priority = task_prio(task);
48972 @@ -494,9 +545,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48973 seq_put_decimal_ull(m, ' ', vsize);
48974 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
48975 seq_put_decimal_ull(m, ' ', rsslim);
48976 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48977 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
48978 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
48979 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
48980 +#else
48981 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
48982 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
48983 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
48984 +#endif
48985 seq_put_decimal_ull(m, ' ', esp);
48986 seq_put_decimal_ull(m, ' ', eip);
48987 /* The signal information here is obsolete.
48988 @@ -518,7 +575,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48989 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
48990 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
48991
48992 - if (mm && permitted) {
48993 + if (mm && permitted
48994 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48995 + && !PAX_RAND_FLAGS(mm)
48996 +#endif
48997 + ) {
48998 seq_put_decimal_ull(m, ' ', mm->start_data);
48999 seq_put_decimal_ull(m, ' ', mm->end_data);
49000 seq_put_decimal_ull(m, ' ', mm->start_brk);
49001 @@ -556,8 +617,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49002 struct pid *pid, struct task_struct *task)
49003 {
49004 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
49005 - struct mm_struct *mm = get_task_mm(task);
49006 + struct mm_struct *mm;
49007
49008 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49009 + if (current->exec_id != m->exec_id) {
49010 + gr_log_badprocpid("statm");
49011 + return 0;
49012 + }
49013 +#endif
49014 + mm = get_task_mm(task);
49015 if (mm) {
49016 size = task_statm(mm, &shared, &text, &data, &resident);
49017 mmput(mm);
49018 @@ -580,6 +648,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49019 return 0;
49020 }
49021
49022 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49023 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
49024 +{
49025 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
49026 +}
49027 +#endif
49028 +
49029 #ifdef CONFIG_CHECKPOINT_RESTORE
49030 static struct pid *
49031 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
49032 diff --git a/fs/proc/base.c b/fs/proc/base.c
49033 index 1b6c84c..66b738b 100644
49034 --- a/fs/proc/base.c
49035 +++ b/fs/proc/base.c
49036 @@ -110,6 +110,14 @@ struct pid_entry {
49037 union proc_op op;
49038 };
49039
49040 +struct getdents_callback {
49041 + struct linux_dirent __user * current_dir;
49042 + struct linux_dirent __user * previous;
49043 + struct file * file;
49044 + int count;
49045 + int error;
49046 +};
49047 +
49048 #define NOD(NAME, MODE, IOP, FOP, OP) { \
49049 .name = (NAME), \
49050 .len = sizeof(NAME) - 1, \
49051 @@ -209,6 +217,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
49052 if (!mm->arg_end)
49053 goto out_mm; /* Shh! No looking before we're done */
49054
49055 + if (gr_acl_handle_procpidmem(task))
49056 + goto out_mm;
49057 +
49058 len = mm->arg_end - mm->arg_start;
49059
49060 if (len > PAGE_SIZE)
49061 @@ -236,12 +247,28 @@ out:
49062 return res;
49063 }
49064
49065 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49066 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49067 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
49068 + _mm->pax_flags & MF_PAX_SEGMEXEC))
49069 +#endif
49070 +
49071 static int proc_pid_auxv(struct task_struct *task, char *buffer)
49072 {
49073 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
49074 int res = PTR_ERR(mm);
49075 if (mm && !IS_ERR(mm)) {
49076 unsigned int nwords = 0;
49077 +
49078 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49079 + /* allow if we're currently ptracing this task */
49080 + if (PAX_RAND_FLAGS(mm) &&
49081 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
49082 + mmput(mm);
49083 + return 0;
49084 + }
49085 +#endif
49086 +
49087 do {
49088 nwords += 2;
49089 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
49090 @@ -255,7 +282,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
49091 }
49092
49093
49094 -#ifdef CONFIG_KALLSYMS
49095 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49096 /*
49097 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
49098 * Returns the resolved symbol. If that fails, simply return the address.
49099 @@ -294,7 +321,7 @@ static void unlock_trace(struct task_struct *task)
49100 mutex_unlock(&task->signal->cred_guard_mutex);
49101 }
49102
49103 -#ifdef CONFIG_STACKTRACE
49104 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49105
49106 #define MAX_STACK_TRACE_DEPTH 64
49107
49108 @@ -486,7 +513,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
49109 return count;
49110 }
49111
49112 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49113 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49114 static int proc_pid_syscall(struct task_struct *task, char *buffer)
49115 {
49116 long nr;
49117 @@ -515,7 +542,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
49118 /************************************************************************/
49119
49120 /* permission checks */
49121 -static int proc_fd_access_allowed(struct inode *inode)
49122 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
49123 {
49124 struct task_struct *task;
49125 int allowed = 0;
49126 @@ -525,7 +552,10 @@ static int proc_fd_access_allowed(struct inode *inode)
49127 */
49128 task = get_proc_task(inode);
49129 if (task) {
49130 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
49131 + if (log)
49132 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
49133 + else
49134 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
49135 put_task_struct(task);
49136 }
49137 return allowed;
49138 @@ -563,10 +593,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
49139 struct task_struct *task,
49140 int hide_pid_min)
49141 {
49142 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49143 + return false;
49144 +
49145 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49146 + rcu_read_lock();
49147 + {
49148 + const struct cred *tmpcred = current_cred();
49149 + const struct cred *cred = __task_cred(task);
49150 +
49151 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
49152 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49153 + || in_group_p(grsec_proc_gid)
49154 +#endif
49155 + ) {
49156 + rcu_read_unlock();
49157 + return true;
49158 + }
49159 + }
49160 + rcu_read_unlock();
49161 +
49162 + if (!pid->hide_pid)
49163 + return false;
49164 +#endif
49165 +
49166 if (pid->hide_pid < hide_pid_min)
49167 return true;
49168 if (in_group_p(pid->pid_gid))
49169 return true;
49170 +
49171 return ptrace_may_access(task, PTRACE_MODE_READ);
49172 }
49173
49174 @@ -584,7 +639,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
49175 put_task_struct(task);
49176
49177 if (!has_perms) {
49178 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49179 + {
49180 +#else
49181 if (pid->hide_pid == 2) {
49182 +#endif
49183 /*
49184 * Let's make getdents(), stat(), and open()
49185 * consistent with each other. If a process
49186 @@ -682,6 +741,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
49187 if (!task)
49188 return -ESRCH;
49189
49190 + if (gr_acl_handle_procpidmem(task)) {
49191 + put_task_struct(task);
49192 + return -EPERM;
49193 + }
49194 +
49195 mm = mm_access(task, mode);
49196 put_task_struct(task);
49197
49198 @@ -697,6 +761,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
49199
49200 file->private_data = mm;
49201
49202 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49203 + file->f_version = current->exec_id;
49204 +#endif
49205 +
49206 return 0;
49207 }
49208
49209 @@ -718,6 +786,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
49210 ssize_t copied;
49211 char *page;
49212
49213 +#ifdef CONFIG_GRKERNSEC
49214 + if (write)
49215 + return -EPERM;
49216 +#endif
49217 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49218 + if (file->f_version != current->exec_id) {
49219 + gr_log_badprocpid("mem");
49220 + return 0;
49221 + }
49222 +#endif
49223 +
49224 if (!mm)
49225 return 0;
49226
49227 @@ -822,6 +901,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
49228 if (!mm)
49229 return 0;
49230
49231 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49232 + if (file->f_version != current->exec_id) {
49233 + gr_log_badprocpid("environ");
49234 + return 0;
49235 + }
49236 +#endif
49237 +
49238 page = (char *)__get_free_page(GFP_TEMPORARY);
49239 if (!page)
49240 return -ENOMEM;
49241 @@ -1435,7 +1521,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
49242 int error = -EACCES;
49243
49244 /* Are we allowed to snoop on the tasks file descriptors? */
49245 - if (!proc_fd_access_allowed(inode))
49246 + if (!proc_fd_access_allowed(inode, 0))
49247 goto out;
49248
49249 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
49250 @@ -1479,8 +1565,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
49251 struct path path;
49252
49253 /* Are we allowed to snoop on the tasks file descriptors? */
49254 - if (!proc_fd_access_allowed(inode))
49255 - goto out;
49256 + /* logging this is needed for learning on chromium to work properly,
49257 + but we don't want to flood the logs from 'ps' which does a readlink
49258 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
49259 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
49260 + */
49261 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
49262 + if (!proc_fd_access_allowed(inode,0))
49263 + goto out;
49264 + } else {
49265 + if (!proc_fd_access_allowed(inode,1))
49266 + goto out;
49267 + }
49268
49269 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
49270 if (error)
49271 @@ -1545,7 +1641,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
49272 rcu_read_lock();
49273 cred = __task_cred(task);
49274 inode->i_uid = cred->euid;
49275 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49276 + inode->i_gid = grsec_proc_gid;
49277 +#else
49278 inode->i_gid = cred->egid;
49279 +#endif
49280 rcu_read_unlock();
49281 }
49282 security_task_to_inode(task, inode);
49283 @@ -1581,10 +1681,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
49284 return -ENOENT;
49285 }
49286 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49287 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49288 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49289 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49290 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49291 +#endif
49292 task_dumpable(task)) {
49293 cred = __task_cred(task);
49294 stat->uid = cred->euid;
49295 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49296 + stat->gid = grsec_proc_gid;
49297 +#else
49298 stat->gid = cred->egid;
49299 +#endif
49300 }
49301 }
49302 rcu_read_unlock();
49303 @@ -1622,11 +1731,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
49304
49305 if (task) {
49306 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49307 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49308 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49309 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49310 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49311 +#endif
49312 task_dumpable(task)) {
49313 rcu_read_lock();
49314 cred = __task_cred(task);
49315 inode->i_uid = cred->euid;
49316 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49317 + inode->i_gid = grsec_proc_gid;
49318 +#else
49319 inode->i_gid = cred->egid;
49320 +#endif
49321 rcu_read_unlock();
49322 } else {
49323 inode->i_uid = GLOBAL_ROOT_UID;
49324 @@ -1744,7 +1862,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
49325 int fd = proc_fd(inode);
49326
49327 if (task) {
49328 - files = get_files_struct(task);
49329 + if (!gr_acl_handle_procpidmem(task))
49330 + files = get_files_struct(task);
49331 put_task_struct(task);
49332 }
49333 if (files) {
49334 @@ -2343,11 +2462,21 @@ static const struct file_operations proc_map_files_operations = {
49335 */
49336 static int proc_fd_permission(struct inode *inode, int mask)
49337 {
49338 + struct task_struct *task;
49339 int rv = generic_permission(inode, mask);
49340 - if (rv == 0)
49341 - return 0;
49342 +
49343 if (task_pid(current) == proc_pid(inode))
49344 rv = 0;
49345 +
49346 + task = get_proc_task(inode);
49347 + if (task == NULL)
49348 + return rv;
49349 +
49350 + if (gr_acl_handle_procpidmem(task))
49351 + rv = -EACCES;
49352 +
49353 + put_task_struct(task);
49354 +
49355 return rv;
49356 }
49357
49358 @@ -2457,6 +2586,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
49359 if (!task)
49360 goto out_no_task;
49361
49362 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49363 + goto out;
49364 +
49365 /*
49366 * Yes, it does not scale. And it should not. Don't add
49367 * new entries into /proc/<tgid>/ without very good reasons.
49368 @@ -2501,6 +2633,9 @@ static int proc_pident_readdir(struct file *filp,
49369 if (!task)
49370 goto out_no_task;
49371
49372 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49373 + goto out;
49374 +
49375 ret = 0;
49376 i = filp->f_pos;
49377 switch (i) {
49378 @@ -2771,7 +2906,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
49379 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
49380 void *cookie)
49381 {
49382 - char *s = nd_get_link(nd);
49383 + const char *s = nd_get_link(nd);
49384 if (!IS_ERR(s))
49385 __putname(s);
49386 }
49387 @@ -3040,7 +3175,7 @@ static const struct pid_entry tgid_base_stuff[] = {
49388 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
49389 #endif
49390 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49391 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49392 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49393 INF("syscall", S_IRUGO, proc_pid_syscall),
49394 #endif
49395 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49396 @@ -3065,10 +3200,10 @@ static const struct pid_entry tgid_base_stuff[] = {
49397 #ifdef CONFIG_SECURITY
49398 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49399 #endif
49400 -#ifdef CONFIG_KALLSYMS
49401 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49402 INF("wchan", S_IRUGO, proc_pid_wchan),
49403 #endif
49404 -#ifdef CONFIG_STACKTRACE
49405 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49406 ONE("stack", S_IRUGO, proc_pid_stack),
49407 #endif
49408 #ifdef CONFIG_SCHEDSTATS
49409 @@ -3102,6 +3237,9 @@ static const struct pid_entry tgid_base_stuff[] = {
49410 #ifdef CONFIG_HARDWALL
49411 INF("hardwall", S_IRUGO, proc_pid_hardwall),
49412 #endif
49413 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49414 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
49415 +#endif
49416 #ifdef CONFIG_USER_NS
49417 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
49418 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
49419 @@ -3233,7 +3371,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
49420 if (!inode)
49421 goto out;
49422
49423 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49424 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
49425 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49426 + inode->i_gid = grsec_proc_gid;
49427 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
49428 +#else
49429 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
49430 +#endif
49431 inode->i_op = &proc_tgid_base_inode_operations;
49432 inode->i_fop = &proc_tgid_base_operations;
49433 inode->i_flags|=S_IMMUTABLE;
49434 @@ -3275,7 +3420,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
49435 if (!task)
49436 goto out;
49437
49438 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49439 + goto out_put_task;
49440 +
49441 result = proc_pid_instantiate(dir, dentry, task, NULL);
49442 +out_put_task:
49443 put_task_struct(task);
49444 out:
49445 return result;
49446 @@ -3338,6 +3487,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
49447 static int fake_filldir(void *buf, const char *name, int namelen,
49448 loff_t offset, u64 ino, unsigned d_type)
49449 {
49450 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
49451 + __buf->error = -EINVAL;
49452 return 0;
49453 }
49454
49455 @@ -3404,7 +3555,7 @@ static const struct pid_entry tid_base_stuff[] = {
49456 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
49457 #endif
49458 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49459 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49460 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49461 INF("syscall", S_IRUGO, proc_pid_syscall),
49462 #endif
49463 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49464 @@ -3431,10 +3582,10 @@ static const struct pid_entry tid_base_stuff[] = {
49465 #ifdef CONFIG_SECURITY
49466 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49467 #endif
49468 -#ifdef CONFIG_KALLSYMS
49469 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49470 INF("wchan", S_IRUGO, proc_pid_wchan),
49471 #endif
49472 -#ifdef CONFIG_STACKTRACE
49473 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49474 ONE("stack", S_IRUGO, proc_pid_stack),
49475 #endif
49476 #ifdef CONFIG_SCHEDSTATS
49477 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
49478 index 82676e3..5f8518a 100644
49479 --- a/fs/proc/cmdline.c
49480 +++ b/fs/proc/cmdline.c
49481 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
49482
49483 static int __init proc_cmdline_init(void)
49484 {
49485 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49486 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
49487 +#else
49488 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
49489 +#endif
49490 return 0;
49491 }
49492 module_init(proc_cmdline_init);
49493 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
49494 index b143471..bb105e5 100644
49495 --- a/fs/proc/devices.c
49496 +++ b/fs/proc/devices.c
49497 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
49498
49499 static int __init proc_devices_init(void)
49500 {
49501 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49502 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
49503 +#else
49504 proc_create("devices", 0, NULL, &proc_devinfo_operations);
49505 +#endif
49506 return 0;
49507 }
49508 module_init(proc_devices_init);
49509 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
49510 index 7ac817b..c5c9eb0 100644
49511 --- a/fs/proc/inode.c
49512 +++ b/fs/proc/inode.c
49513 @@ -21,11 +21,17 @@
49514 #include <linux/seq_file.h>
49515 #include <linux/slab.h>
49516 #include <linux/mount.h>
49517 +#include <linux/grsecurity.h>
49518
49519 #include <asm/uaccess.h>
49520
49521 #include "internal.h"
49522
49523 +#ifdef CONFIG_PROC_SYSCTL
49524 +extern const struct inode_operations proc_sys_inode_operations;
49525 +extern const struct inode_operations proc_sys_dir_operations;
49526 +#endif
49527 +
49528 static void proc_evict_inode(struct inode *inode)
49529 {
49530 struct proc_dir_entry *de;
49531 @@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
49532 ns_ops = PROC_I(inode)->ns_ops;
49533 if (ns_ops && ns_ops->put)
49534 ns_ops->put(PROC_I(inode)->ns);
49535 +
49536 +#ifdef CONFIG_PROC_SYSCTL
49537 + if (inode->i_op == &proc_sys_inode_operations ||
49538 + inode->i_op == &proc_sys_dir_operations)
49539 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
49540 +#endif
49541 +
49542 }
49543
49544 static struct kmem_cache * proc_inode_cachep;
49545 @@ -456,7 +469,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
49546 if (de->mode) {
49547 inode->i_mode = de->mode;
49548 inode->i_uid = de->uid;
49549 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49550 + inode->i_gid = grsec_proc_gid;
49551 +#else
49552 inode->i_gid = de->gid;
49553 +#endif
49554 }
49555 if (de->size)
49556 inode->i_size = de->size;
49557 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
49558 index e1167a1..bd24f20 100644
49559 --- a/fs/proc/internal.h
49560 +++ b/fs/proc/internal.h
49561 @@ -52,6 +52,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
49562 struct pid *pid, struct task_struct *task);
49563 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49564 struct pid *pid, struct task_struct *task);
49565 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49566 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
49567 +#endif
49568 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
49569
49570 extern const struct file_operations proc_tid_children_operations;
49571 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
49572 index 86c67ee..cdca321 100644
49573 --- a/fs/proc/kcore.c
49574 +++ b/fs/proc/kcore.c
49575 @@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49576 * the addresses in the elf_phdr on our list.
49577 */
49578 start = kc_offset_to_vaddr(*fpos - elf_buflen);
49579 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
49580 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
49581 + if (tsz > buflen)
49582 tsz = buflen;
49583 -
49584 +
49585 while (buflen) {
49586 struct kcore_list *m;
49587
49588 @@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49589 kfree(elf_buf);
49590 } else {
49591 if (kern_addr_valid(start)) {
49592 - unsigned long n;
49593 + char *elf_buf;
49594 + mm_segment_t oldfs;
49595
49596 - n = copy_to_user(buffer, (char *)start, tsz);
49597 - /*
49598 - * We cannot distinguish between fault on source
49599 - * and fault on destination. When this happens
49600 - * we clear too and hope it will trigger the
49601 - * EFAULT again.
49602 - */
49603 - if (n) {
49604 - if (clear_user(buffer + tsz - n,
49605 - n))
49606 + elf_buf = kmalloc(tsz, GFP_KERNEL);
49607 + if (!elf_buf)
49608 + return -ENOMEM;
49609 + oldfs = get_fs();
49610 + set_fs(KERNEL_DS);
49611 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
49612 + set_fs(oldfs);
49613 + if (copy_to_user(buffer, elf_buf, tsz)) {
49614 + kfree(elf_buf);
49615 return -EFAULT;
49616 + }
49617 }
49618 + set_fs(oldfs);
49619 + kfree(elf_buf);
49620 } else {
49621 if (clear_user(buffer, tsz))
49622 return -EFAULT;
49623 @@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49624
49625 static int open_kcore(struct inode *inode, struct file *filp)
49626 {
49627 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
49628 + return -EPERM;
49629 +#endif
49630 if (!capable(CAP_SYS_RAWIO))
49631 return -EPERM;
49632 if (kcore_need_update)
49633 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
49634 index 80e4645..53e5fcf 100644
49635 --- a/fs/proc/meminfo.c
49636 +++ b/fs/proc/meminfo.c
49637 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
49638 vmi.used >> 10,
49639 vmi.largest_chunk >> 10
49640 #ifdef CONFIG_MEMORY_FAILURE
49641 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
49642 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
49643 #endif
49644 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
49645 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
49646 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
49647 index b1822dd..df622cb 100644
49648 --- a/fs/proc/nommu.c
49649 +++ b/fs/proc/nommu.c
49650 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
49651 if (len < 1)
49652 len = 1;
49653 seq_printf(m, "%*c", len, ' ');
49654 - seq_path(m, &file->f_path, "");
49655 + seq_path(m, &file->f_path, "\n\\");
49656 }
49657
49658 seq_putc(m, '\n');
49659 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
49660 index fe72cd0..cb9b67d 100644
49661 --- a/fs/proc/proc_net.c
49662 +++ b/fs/proc/proc_net.c
49663 @@ -23,6 +23,7 @@
49664 #include <linux/nsproxy.h>
49665 #include <net/net_namespace.h>
49666 #include <linux/seq_file.h>
49667 +#include <linux/grsecurity.h>
49668
49669 #include "internal.h"
49670
49671 @@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
49672 struct task_struct *task;
49673 struct nsproxy *ns;
49674 struct net *net = NULL;
49675 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49676 + const struct cred *cred = current_cred();
49677 +#endif
49678 +
49679 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49680 + if (cred->fsuid)
49681 + return net;
49682 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49683 + if (cred->fsuid && !in_group_p(grsec_proc_gid))
49684 + return net;
49685 +#endif
49686
49687 rcu_read_lock();
49688 task = pid_task(proc_pid(dir), PIDTYPE_PID);
49689 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
49690 index eb7cc91..7327a46 100644
49691 --- a/fs/proc/proc_sysctl.c
49692 +++ b/fs/proc/proc_sysctl.c
49693 @@ -12,11 +12,15 @@
49694 #include <linux/module.h>
49695 #include "internal.h"
49696
49697 +extern int gr_handle_chroot_sysctl(const int op);
49698 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
49699 + const int op);
49700 +
49701 static const struct dentry_operations proc_sys_dentry_operations;
49702 static const struct file_operations proc_sys_file_operations;
49703 -static const struct inode_operations proc_sys_inode_operations;
49704 +const struct inode_operations proc_sys_inode_operations;
49705 static const struct file_operations proc_sys_dir_file_operations;
49706 -static const struct inode_operations proc_sys_dir_operations;
49707 +const struct inode_operations proc_sys_dir_operations;
49708
49709 void proc_sys_poll_notify(struct ctl_table_poll *poll)
49710 {
49711 @@ -467,6 +471,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
49712
49713 err = NULL;
49714 d_set_d_op(dentry, &proc_sys_dentry_operations);
49715 +
49716 + gr_handle_proc_create(dentry, inode);
49717 +
49718 d_add(dentry, inode);
49719
49720 out:
49721 @@ -482,18 +489,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49722 struct inode *inode = filp->f_path.dentry->d_inode;
49723 struct ctl_table_header *head = grab_header(inode);
49724 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
49725 + int op = write ? MAY_WRITE : MAY_READ;
49726 ssize_t error;
49727 size_t res;
49728
49729 if (IS_ERR(head))
49730 return PTR_ERR(head);
49731
49732 +
49733 /*
49734 * At this point we know that the sysctl was not unregistered
49735 * and won't be until we finish.
49736 */
49737 error = -EPERM;
49738 - if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
49739 + if (sysctl_perm(head->root, table, op))
49740 goto out;
49741
49742 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
49743 @@ -501,6 +510,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49744 if (!table->proc_handler)
49745 goto out;
49746
49747 +#ifdef CONFIG_GRKERNSEC
49748 + error = -EPERM;
49749 + if (gr_handle_chroot_sysctl(op))
49750 + goto out;
49751 + dget(filp->f_path.dentry);
49752 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
49753 + dput(filp->f_path.dentry);
49754 + goto out;
49755 + }
49756 + dput(filp->f_path.dentry);
49757 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
49758 + goto out;
49759 + if (write && !capable(CAP_SYS_ADMIN))
49760 + goto out;
49761 +#endif
49762 +
49763 /* careful: calling conventions are nasty here */
49764 res = count;
49765 error = table->proc_handler(table, write, buf, &res, ppos);
49766 @@ -598,6 +623,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
49767 return -ENOMEM;
49768 } else {
49769 d_set_d_op(child, &proc_sys_dentry_operations);
49770 +
49771 + gr_handle_proc_create(child, inode);
49772 +
49773 d_add(child, inode);
49774 }
49775 } else {
49776 @@ -641,6 +669,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
49777 if ((*pos)++ < file->f_pos)
49778 return 0;
49779
49780 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
49781 + return 0;
49782 +
49783 if (unlikely(S_ISLNK(table->mode)))
49784 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
49785 else
49786 @@ -758,6 +789,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
49787 if (IS_ERR(head))
49788 return PTR_ERR(head);
49789
49790 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
49791 + return -ENOENT;
49792 +
49793 generic_fillattr(inode, stat);
49794 if (table)
49795 stat->mode = (stat->mode & S_IFMT) | table->mode;
49796 @@ -780,13 +814,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
49797 .llseek = generic_file_llseek,
49798 };
49799
49800 -static const struct inode_operations proc_sys_inode_operations = {
49801 +const struct inode_operations proc_sys_inode_operations = {
49802 .permission = proc_sys_permission,
49803 .setattr = proc_sys_setattr,
49804 .getattr = proc_sys_getattr,
49805 };
49806
49807 -static const struct inode_operations proc_sys_dir_operations = {
49808 +const struct inode_operations proc_sys_dir_operations = {
49809 .lookup = proc_sys_lookup,
49810 .permission = proc_sys_permission,
49811 .setattr = proc_sys_setattr,
49812 diff --git a/fs/proc/root.c b/fs/proc/root.c
49813 index 9a2d9fd..ddfc92a 100644
49814 --- a/fs/proc/root.c
49815 +++ b/fs/proc/root.c
49816 @@ -187,7 +187,15 @@ void __init proc_root_init(void)
49817 #ifdef CONFIG_PROC_DEVICETREE
49818 proc_device_tree_init();
49819 #endif
49820 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49821 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49822 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
49823 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49824 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
49825 +#endif
49826 +#else
49827 proc_mkdir("bus", NULL);
49828 +#endif
49829 proc_sys_init();
49830 }
49831
49832 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
49833 index 4540b8f..1b9772f 100644
49834 --- a/fs/proc/task_mmu.c
49835 +++ b/fs/proc/task_mmu.c
49836 @@ -11,12 +11,19 @@
49837 #include <linux/rmap.h>
49838 #include <linux/swap.h>
49839 #include <linux/swapops.h>
49840 +#include <linux/grsecurity.h>
49841
49842 #include <asm/elf.h>
49843 #include <asm/uaccess.h>
49844 #include <asm/tlbflush.h>
49845 #include "internal.h"
49846
49847 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49848 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49849 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
49850 + _mm->pax_flags & MF_PAX_SEGMEXEC))
49851 +#endif
49852 +
49853 void task_mem(struct seq_file *m, struct mm_struct *mm)
49854 {
49855 unsigned long data, text, lib, swap;
49856 @@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49857 "VmExe:\t%8lu kB\n"
49858 "VmLib:\t%8lu kB\n"
49859 "VmPTE:\t%8lu kB\n"
49860 - "VmSwap:\t%8lu kB\n",
49861 - hiwater_vm << (PAGE_SHIFT-10),
49862 + "VmSwap:\t%8lu kB\n"
49863 +
49864 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49865 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
49866 +#endif
49867 +
49868 + ,hiwater_vm << (PAGE_SHIFT-10),
49869 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
49870 mm->locked_vm << (PAGE_SHIFT-10),
49871 mm->pinned_vm << (PAGE_SHIFT-10),
49872 @@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49873 data << (PAGE_SHIFT-10),
49874 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
49875 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
49876 - swap << (PAGE_SHIFT-10));
49877 + swap << (PAGE_SHIFT-10)
49878 +
49879 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49880 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49881 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
49882 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
49883 +#else
49884 + , mm->context.user_cs_base
49885 + , mm->context.user_cs_limit
49886 +#endif
49887 +#endif
49888 +
49889 + );
49890 }
49891
49892 unsigned long task_vsize(struct mm_struct *mm)
49893 @@ -231,13 +255,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49894 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
49895 }
49896
49897 - /* We don't show the stack guard page in /proc/maps */
49898 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49899 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
49900 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
49901 +#else
49902 start = vma->vm_start;
49903 - if (stack_guard_page_start(vma, start))
49904 - start += PAGE_SIZE;
49905 end = vma->vm_end;
49906 - if (stack_guard_page_end(vma, end))
49907 - end -= PAGE_SIZE;
49908 +#endif
49909
49910 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
49911 start,
49912 @@ -246,7 +270,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49913 flags & VM_WRITE ? 'w' : '-',
49914 flags & VM_EXEC ? 'x' : '-',
49915 flags & VM_MAYSHARE ? 's' : 'p',
49916 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49917 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
49918 +#else
49919 pgoff,
49920 +#endif
49921 MAJOR(dev), MINOR(dev), ino, &len);
49922
49923 /*
49924 @@ -255,7 +283,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49925 */
49926 if (file) {
49927 pad_len_spaces(m, len);
49928 - seq_path(m, &file->f_path, "\n");
49929 + seq_path(m, &file->f_path, "\n\\");
49930 goto done;
49931 }
49932
49933 @@ -281,8 +309,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49934 * Thread stack in /proc/PID/task/TID/maps or
49935 * the main process stack.
49936 */
49937 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
49938 - vma->vm_end >= mm->start_stack)) {
49939 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
49940 + (vma->vm_start <= mm->start_stack &&
49941 + vma->vm_end >= mm->start_stack)) {
49942 name = "[stack]";
49943 } else {
49944 /* Thread stack in /proc/PID/maps */
49945 @@ -306,6 +335,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
49946 struct proc_maps_private *priv = m->private;
49947 struct task_struct *task = priv->task;
49948
49949 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49950 + if (current->exec_id != m->exec_id) {
49951 + gr_log_badprocpid("maps");
49952 + return 0;
49953 + }
49954 +#endif
49955 +
49956 show_map_vma(m, vma, is_pid);
49957
49958 if (m->count < m->size) /* vma is copied successfully */
49959 @@ -492,12 +528,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49960 .private = &mss,
49961 };
49962
49963 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49964 + if (current->exec_id != m->exec_id) {
49965 + gr_log_badprocpid("smaps");
49966 + return 0;
49967 + }
49968 +#endif
49969 memset(&mss, 0, sizeof mss);
49970 - mss.vma = vma;
49971 - /* mmap_sem is held in m_start */
49972 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49973 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49974 -
49975 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49976 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
49977 +#endif
49978 + mss.vma = vma;
49979 + /* mmap_sem is held in m_start */
49980 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49981 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49982 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49983 + }
49984 +#endif
49985 show_map_vma(m, vma, is_pid);
49986
49987 seq_printf(m,
49988 @@ -515,7 +562,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49989 "KernelPageSize: %8lu kB\n"
49990 "MMUPageSize: %8lu kB\n"
49991 "Locked: %8lu kB\n",
49992 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49993 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
49994 +#else
49995 (vma->vm_end - vma->vm_start) >> 10,
49996 +#endif
49997 mss.resident >> 10,
49998 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
49999 mss.shared_clean >> 10,
50000 @@ -1164,6 +1215,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
50001 int n;
50002 char buffer[50];
50003
50004 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50005 + if (current->exec_id != m->exec_id) {
50006 + gr_log_badprocpid("numa_maps");
50007 + return 0;
50008 + }
50009 +#endif
50010 +
50011 if (!mm)
50012 return 0;
50013
50014 @@ -1181,11 +1239,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
50015 mpol_to_str(buffer, sizeof(buffer), pol, 0);
50016 mpol_cond_put(pol);
50017
50018 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50019 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
50020 +#else
50021 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
50022 +#endif
50023
50024 if (file) {
50025 seq_printf(m, " file=");
50026 - seq_path(m, &file->f_path, "\n\t= ");
50027 + seq_path(m, &file->f_path, "\n\t\\= ");
50028 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
50029 seq_printf(m, " heap");
50030 } else {
50031 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
50032 index 1ccfa53..0848f95 100644
50033 --- a/fs/proc/task_nommu.c
50034 +++ b/fs/proc/task_nommu.c
50035 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
50036 else
50037 bytes += kobjsize(mm);
50038
50039 - if (current->fs && current->fs->users > 1)
50040 + if (current->fs && atomic_read(&current->fs->users) > 1)
50041 sbytes += kobjsize(current->fs);
50042 else
50043 bytes += kobjsize(current->fs);
50044 @@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
50045
50046 if (file) {
50047 pad_len_spaces(m, len);
50048 - seq_path(m, &file->f_path, "");
50049 + seq_path(m, &file->f_path, "\n\\");
50050 } else if (mm) {
50051 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
50052
50053 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
50054 index d67908b..d13f6a6 100644
50055 --- a/fs/quota/netlink.c
50056 +++ b/fs/quota/netlink.c
50057 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
50058 void quota_send_warning(short type, unsigned int id, dev_t dev,
50059 const char warntype)
50060 {
50061 - static atomic_t seq;
50062 + static atomic_unchecked_t seq;
50063 struct sk_buff *skb;
50064 void *msg_head;
50065 int ret;
50066 @@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
50067 "VFS: Not enough memory to send quota warning.\n");
50068 return;
50069 }
50070 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
50071 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
50072 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
50073 if (!msg_head) {
50074 printk(KERN_ERR
50075 diff --git a/fs/readdir.c b/fs/readdir.c
50076 index 39e3370..20d446d 100644
50077 --- a/fs/readdir.c
50078 +++ b/fs/readdir.c
50079 @@ -17,6 +17,7 @@
50080 #include <linux/security.h>
50081 #include <linux/syscalls.h>
50082 #include <linux/unistd.h>
50083 +#include <linux/namei.h>
50084
50085 #include <asm/uaccess.h>
50086
50087 @@ -67,6 +68,7 @@ struct old_linux_dirent {
50088
50089 struct readdir_callback {
50090 struct old_linux_dirent __user * dirent;
50091 + struct file * file;
50092 int result;
50093 };
50094
50095 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
50096 buf->result = -EOVERFLOW;
50097 return -EOVERFLOW;
50098 }
50099 +
50100 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50101 + return 0;
50102 +
50103 buf->result++;
50104 dirent = buf->dirent;
50105 if (!access_ok(VERIFY_WRITE, dirent,
50106 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
50107
50108 buf.result = 0;
50109 buf.dirent = dirent;
50110 + buf.file = file;
50111
50112 error = vfs_readdir(file, fillonedir, &buf);
50113 if (buf.result)
50114 @@ -141,6 +148,7 @@ struct linux_dirent {
50115 struct getdents_callback {
50116 struct linux_dirent __user * current_dir;
50117 struct linux_dirent __user * previous;
50118 + struct file * file;
50119 int count;
50120 int error;
50121 };
50122 @@ -162,6 +170,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
50123 buf->error = -EOVERFLOW;
50124 return -EOVERFLOW;
50125 }
50126 +
50127 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50128 + return 0;
50129 +
50130 dirent = buf->previous;
50131 if (dirent) {
50132 if (__put_user(offset, &dirent->d_off))
50133 @@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
50134 buf.previous = NULL;
50135 buf.count = count;
50136 buf.error = 0;
50137 + buf.file = file;
50138
50139 error = vfs_readdir(file, filldir, &buf);
50140 if (error >= 0)
50141 @@ -226,6 +239,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
50142 struct getdents_callback64 {
50143 struct linux_dirent64 __user * current_dir;
50144 struct linux_dirent64 __user * previous;
50145 + struct file *file;
50146 int count;
50147 int error;
50148 };
50149 @@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
50150 buf->error = -EINVAL; /* only used if we fail.. */
50151 if (reclen > buf->count)
50152 return -EINVAL;
50153 +
50154 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50155 + return 0;
50156 +
50157 dirent = buf->previous;
50158 if (dirent) {
50159 if (__put_user(offset, &dirent->d_off))
50160 @@ -287,6 +305,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
50161
50162 buf.current_dir = dirent;
50163 buf.previous = NULL;
50164 + buf.file = file;
50165 buf.count = count;
50166 buf.error = 0;
50167
50168 @@ -295,7 +314,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
50169 error = buf.error;
50170 lastdirent = buf.previous;
50171 if (lastdirent) {
50172 - typeof(lastdirent->d_off) d_off = file->f_pos;
50173 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
50174 if (__put_user(d_off, &lastdirent->d_off))
50175 error = -EFAULT;
50176 else
50177 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
50178 index 2b7882b..1c5ef48 100644
50179 --- a/fs/reiserfs/do_balan.c
50180 +++ b/fs/reiserfs/do_balan.c
50181 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
50182 return;
50183 }
50184
50185 - atomic_inc(&(fs_generation(tb->tb_sb)));
50186 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
50187 do_balance_starts(tb);
50188
50189 /* balance leaf returns 0 except if combining L R and S into
50190 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
50191 index e60e870..f40ac16 100644
50192 --- a/fs/reiserfs/procfs.c
50193 +++ b/fs/reiserfs/procfs.c
50194 @@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
50195 "SMALL_TAILS " : "NO_TAILS ",
50196 replay_only(sb) ? "REPLAY_ONLY " : "",
50197 convert_reiserfs(sb) ? "CONV " : "",
50198 - atomic_read(&r->s_generation_counter),
50199 + atomic_read_unchecked(&r->s_generation_counter),
50200 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
50201 SF(s_do_balance), SF(s_unneeded_left_neighbor),
50202 SF(s_good_search_by_key_reada), SF(s_bmaps),
50203 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
50204 index 33215f5..c5d427a 100644
50205 --- a/fs/reiserfs/reiserfs.h
50206 +++ b/fs/reiserfs/reiserfs.h
50207 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
50208 /* Comment? -Hans */
50209 wait_queue_head_t s_wait;
50210 /* To be obsoleted soon by per buffer seals.. -Hans */
50211 - atomic_t s_generation_counter; // increased by one every time the
50212 + atomic_unchecked_t s_generation_counter; // increased by one every time the
50213 // tree gets re-balanced
50214 unsigned long s_properties; /* File system properties. Currently holds
50215 on-disk FS format */
50216 @@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
50217 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
50218
50219 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
50220 -#define get_generation(s) atomic_read (&fs_generation(s))
50221 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
50222 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
50223 #define __fs_changed(gen,s) (gen != get_generation (s))
50224 #define fs_changed(gen,s) \
50225 diff --git a/fs/select.c b/fs/select.c
50226 index db14c78..3aae1bd 100644
50227 --- a/fs/select.c
50228 +++ b/fs/select.c
50229 @@ -20,6 +20,7 @@
50230 #include <linux/export.h>
50231 #include <linux/slab.h>
50232 #include <linux/poll.h>
50233 +#include <linux/security.h>
50234 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
50235 #include <linux/file.h>
50236 #include <linux/fdtable.h>
50237 @@ -831,6 +832,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
50238 struct poll_list *walk = head;
50239 unsigned long todo = nfds;
50240
50241 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
50242 if (nfds > rlimit(RLIMIT_NOFILE))
50243 return -EINVAL;
50244
50245 diff --git a/fs/seq_file.c b/fs/seq_file.c
50246 index 14cf9de..adc4d5b 100644
50247 --- a/fs/seq_file.c
50248 +++ b/fs/seq_file.c
50249 @@ -9,6 +9,7 @@
50250 #include <linux/export.h>
50251 #include <linux/seq_file.h>
50252 #include <linux/slab.h>
50253 +#include <linux/sched.h>
50254
50255 #include <asm/uaccess.h>
50256 #include <asm/page.h>
50257 @@ -56,6 +57,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
50258 memset(p, 0, sizeof(*p));
50259 mutex_init(&p->lock);
50260 p->op = op;
50261 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50262 + p->exec_id = current->exec_id;
50263 +#endif
50264
50265 /*
50266 * Wrappers around seq_open(e.g. swaps_open) need to be
50267 @@ -92,7 +96,7 @@ static int traverse(struct seq_file *m, loff_t offset)
50268 return 0;
50269 }
50270 if (!m->buf) {
50271 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50272 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
50273 if (!m->buf)
50274 return -ENOMEM;
50275 }
50276 @@ -132,7 +136,7 @@ static int traverse(struct seq_file *m, loff_t offset)
50277 Eoverflow:
50278 m->op->stop(m, p);
50279 kfree(m->buf);
50280 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50281 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
50282 return !m->buf ? -ENOMEM : -EAGAIN;
50283 }
50284
50285 @@ -187,7 +191,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
50286
50287 /* grab buffer if we didn't have one */
50288 if (!m->buf) {
50289 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50290 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
50291 if (!m->buf)
50292 goto Enomem;
50293 }
50294 @@ -228,7 +232,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
50295 goto Fill;
50296 m->op->stop(m, p);
50297 kfree(m->buf);
50298 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50299 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
50300 if (!m->buf)
50301 goto Enomem;
50302 m->count = 0;
50303 @@ -577,7 +581,7 @@ static void single_stop(struct seq_file *p, void *v)
50304 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
50305 void *data)
50306 {
50307 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
50308 + seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
50309 int res = -ENOMEM;
50310
50311 if (op) {
50312 diff --git a/fs/splice.c b/fs/splice.c
50313 index 41514dd..6564a93 100644
50314 --- a/fs/splice.c
50315 +++ b/fs/splice.c
50316 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50317 pipe_lock(pipe);
50318
50319 for (;;) {
50320 - if (!pipe->readers) {
50321 + if (!atomic_read(&pipe->readers)) {
50322 send_sig(SIGPIPE, current, 0);
50323 if (!ret)
50324 ret = -EPIPE;
50325 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50326 do_wakeup = 0;
50327 }
50328
50329 - pipe->waiting_writers++;
50330 + atomic_inc(&pipe->waiting_writers);
50331 pipe_wait(pipe);
50332 - pipe->waiting_writers--;
50333 + atomic_dec(&pipe->waiting_writers);
50334 }
50335
50336 pipe_unlock(pipe);
50337 @@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
50338 old_fs = get_fs();
50339 set_fs(get_ds());
50340 /* The cast to a user pointer is valid due to the set_fs() */
50341 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
50342 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
50343 set_fs(old_fs);
50344
50345 return res;
50346 @@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
50347 old_fs = get_fs();
50348 set_fs(get_ds());
50349 /* The cast to a user pointer is valid due to the set_fs() */
50350 - res = vfs_write(file, (const char __user *)buf, count, &pos);
50351 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
50352 set_fs(old_fs);
50353
50354 return res;
50355 @@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
50356 goto err;
50357
50358 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
50359 - vec[i].iov_base = (void __user *) page_address(page);
50360 + vec[i].iov_base = (void __force_user *) page_address(page);
50361 vec[i].iov_len = this_len;
50362 spd.pages[i] = page;
50363 spd.nr_pages++;
50364 @@ -849,10 +849,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
50365 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
50366 {
50367 while (!pipe->nrbufs) {
50368 - if (!pipe->writers)
50369 + if (!atomic_read(&pipe->writers))
50370 return 0;
50371
50372 - if (!pipe->waiting_writers && sd->num_spliced)
50373 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
50374 return 0;
50375
50376 if (sd->flags & SPLICE_F_NONBLOCK)
50377 @@ -1190,7 +1190,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
50378 * out of the pipe right after the splice_to_pipe(). So set
50379 * PIPE_READERS appropriately.
50380 */
50381 - pipe->readers = 1;
50382 + atomic_set(&pipe->readers, 1);
50383
50384 current->splice_pipe = pipe;
50385 }
50386 @@ -1743,9 +1743,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50387 ret = -ERESTARTSYS;
50388 break;
50389 }
50390 - if (!pipe->writers)
50391 + if (!atomic_read(&pipe->writers))
50392 break;
50393 - if (!pipe->waiting_writers) {
50394 + if (!atomic_read(&pipe->waiting_writers)) {
50395 if (flags & SPLICE_F_NONBLOCK) {
50396 ret = -EAGAIN;
50397 break;
50398 @@ -1777,7 +1777,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50399 pipe_lock(pipe);
50400
50401 while (pipe->nrbufs >= pipe->buffers) {
50402 - if (!pipe->readers) {
50403 + if (!atomic_read(&pipe->readers)) {
50404 send_sig(SIGPIPE, current, 0);
50405 ret = -EPIPE;
50406 break;
50407 @@ -1790,9 +1790,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50408 ret = -ERESTARTSYS;
50409 break;
50410 }
50411 - pipe->waiting_writers++;
50412 + atomic_inc(&pipe->waiting_writers);
50413 pipe_wait(pipe);
50414 - pipe->waiting_writers--;
50415 + atomic_dec(&pipe->waiting_writers);
50416 }
50417
50418 pipe_unlock(pipe);
50419 @@ -1828,14 +1828,14 @@ retry:
50420 pipe_double_lock(ipipe, opipe);
50421
50422 do {
50423 - if (!opipe->readers) {
50424 + if (!atomic_read(&opipe->readers)) {
50425 send_sig(SIGPIPE, current, 0);
50426 if (!ret)
50427 ret = -EPIPE;
50428 break;
50429 }
50430
50431 - if (!ipipe->nrbufs && !ipipe->writers)
50432 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
50433 break;
50434
50435 /*
50436 @@ -1932,7 +1932,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50437 pipe_double_lock(ipipe, opipe);
50438
50439 do {
50440 - if (!opipe->readers) {
50441 + if (!atomic_read(&opipe->readers)) {
50442 send_sig(SIGPIPE, current, 0);
50443 if (!ret)
50444 ret = -EPIPE;
50445 @@ -1977,7 +1977,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50446 * return EAGAIN if we have the potential of some data in the
50447 * future, otherwise just return 0
50448 */
50449 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
50450 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
50451 ret = -EAGAIN;
50452
50453 pipe_unlock(ipipe);
50454 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
50455 index 2fbdff6..5530a61 100644
50456 --- a/fs/sysfs/dir.c
50457 +++ b/fs/sysfs/dir.c
50458 @@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
50459 struct sysfs_dirent *sd;
50460 int rc;
50461
50462 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
50463 + const char *parent_name = parent_sd->s_name;
50464 +
50465 + mode = S_IFDIR | S_IRWXU;
50466 +
50467 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
50468 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
50469 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
50470 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
50471 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
50472 +#endif
50473 +
50474 /* allocate */
50475 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
50476 if (!sd)
50477 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
50478 index 00012e3..8392349 100644
50479 --- a/fs/sysfs/file.c
50480 +++ b/fs/sysfs/file.c
50481 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
50482
50483 struct sysfs_open_dirent {
50484 atomic_t refcnt;
50485 - atomic_t event;
50486 + atomic_unchecked_t event;
50487 wait_queue_head_t poll;
50488 struct list_head buffers; /* goes through sysfs_buffer.list */
50489 };
50490 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
50491 if (!sysfs_get_active(attr_sd))
50492 return -ENODEV;
50493
50494 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
50495 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
50496 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
50497
50498 sysfs_put_active(attr_sd);
50499 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
50500 return -ENOMEM;
50501
50502 atomic_set(&new_od->refcnt, 0);
50503 - atomic_set(&new_od->event, 1);
50504 + atomic_set_unchecked(&new_od->event, 1);
50505 init_waitqueue_head(&new_od->poll);
50506 INIT_LIST_HEAD(&new_od->buffers);
50507 goto retry;
50508 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
50509
50510 sysfs_put_active(attr_sd);
50511
50512 - if (buffer->event != atomic_read(&od->event))
50513 + if (buffer->event != atomic_read_unchecked(&od->event))
50514 goto trigger;
50515
50516 return DEFAULT_POLLMASK;
50517 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
50518
50519 od = sd->s_attr.open;
50520 if (od) {
50521 - atomic_inc(&od->event);
50522 + atomic_inc_unchecked(&od->event);
50523 wake_up_interruptible(&od->poll);
50524 }
50525
50526 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
50527 index a7ac78f..02158e1 100644
50528 --- a/fs/sysfs/symlink.c
50529 +++ b/fs/sysfs/symlink.c
50530 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
50531
50532 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
50533 {
50534 - char *page = nd_get_link(nd);
50535 + const char *page = nd_get_link(nd);
50536 if (!IS_ERR(page))
50537 free_page((unsigned long)page);
50538 }
50539 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
50540 index c175b4d..8f36a16 100644
50541 --- a/fs/udf/misc.c
50542 +++ b/fs/udf/misc.c
50543 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
50544
50545 u8 udf_tag_checksum(const struct tag *t)
50546 {
50547 - u8 *data = (u8 *)t;
50548 + const u8 *data = (const u8 *)t;
50549 u8 checksum = 0;
50550 int i;
50551 for (i = 0; i < sizeof(struct tag); ++i)
50552 diff --git a/fs/utimes.c b/fs/utimes.c
50553 index fa4dbe4..e12d1b9 100644
50554 --- a/fs/utimes.c
50555 +++ b/fs/utimes.c
50556 @@ -1,6 +1,7 @@
50557 #include <linux/compiler.h>
50558 #include <linux/file.h>
50559 #include <linux/fs.h>
50560 +#include <linux/security.h>
50561 #include <linux/linkage.h>
50562 #include <linux/mount.h>
50563 #include <linux/namei.h>
50564 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
50565 goto mnt_drop_write_and_out;
50566 }
50567 }
50568 +
50569 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
50570 + error = -EACCES;
50571 + goto mnt_drop_write_and_out;
50572 + }
50573 +
50574 mutex_lock(&inode->i_mutex);
50575 error = notify_change(path->dentry, &newattrs);
50576 mutex_unlock(&inode->i_mutex);
50577 diff --git a/fs/xattr.c b/fs/xattr.c
50578 index 4d45b71..2ec08e10 100644
50579 --- a/fs/xattr.c
50580 +++ b/fs/xattr.c
50581 @@ -316,7 +316,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
50582 * Extended attribute SET operations
50583 */
50584 static long
50585 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
50586 +setxattr(struct path *path, const char __user *name, const void __user *value,
50587 size_t size, int flags)
50588 {
50589 int error;
50590 @@ -349,7 +349,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
50591 }
50592 }
50593
50594 - error = vfs_setxattr(d, kname, kvalue, size, flags);
50595 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
50596 + error = -EACCES;
50597 + goto out;
50598 + }
50599 +
50600 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
50601 out:
50602 if (vvalue)
50603 vfree(vvalue);
50604 @@ -370,7 +375,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
50605 return error;
50606 error = mnt_want_write(path.mnt);
50607 if (!error) {
50608 - error = setxattr(path.dentry, name, value, size, flags);
50609 + error = setxattr(&path, name, value, size, flags);
50610 mnt_drop_write(path.mnt);
50611 }
50612 path_put(&path);
50613 @@ -389,7 +394,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
50614 return error;
50615 error = mnt_want_write(path.mnt);
50616 if (!error) {
50617 - error = setxattr(path.dentry, name, value, size, flags);
50618 + error = setxattr(&path, name, value, size, flags);
50619 mnt_drop_write(path.mnt);
50620 }
50621 path_put(&path);
50622 @@ -401,17 +406,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
50623 {
50624 int fput_needed;
50625 struct file *f;
50626 - struct dentry *dentry;
50627 int error = -EBADF;
50628
50629 f = fget_light(fd, &fput_needed);
50630 if (!f)
50631 return error;
50632 - dentry = f->f_path.dentry;
50633 - audit_inode(NULL, dentry);
50634 + audit_inode(NULL, f->f_path.dentry);
50635 error = mnt_want_write_file(f);
50636 if (!error) {
50637 - error = setxattr(dentry, name, value, size, flags);
50638 + error = setxattr(&f->f_path, name, value, size, flags);
50639 mnt_drop_write_file(f);
50640 }
50641 fput_light(f, fput_needed);
50642 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
50643 index 69d06b0..c0996e5 100644
50644 --- a/fs/xattr_acl.c
50645 +++ b/fs/xattr_acl.c
50646 @@ -17,8 +17,8 @@
50647 struct posix_acl *
50648 posix_acl_from_xattr(const void *value, size_t size)
50649 {
50650 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
50651 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
50652 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
50653 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
50654 int count;
50655 struct posix_acl *acl;
50656 struct posix_acl_entry *acl_e;
50657 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
50658 index 848ffa7..1f249bf 100644
50659 --- a/fs/xfs/xfs_bmap.c
50660 +++ b/fs/xfs/xfs_bmap.c
50661 @@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
50662 int nmap,
50663 int ret_nmap);
50664 #else
50665 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
50666 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
50667 #endif /* DEBUG */
50668
50669 STATIC int
50670 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
50671 index 1b9fc3e..e1bdde0 100644
50672 --- a/fs/xfs/xfs_dir2_sf.c
50673 +++ b/fs/xfs/xfs_dir2_sf.c
50674 @@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
50675 }
50676
50677 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
50678 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50679 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
50680 + char name[sfep->namelen];
50681 + memcpy(name, sfep->name, sfep->namelen);
50682 + if (filldir(dirent, name, sfep->namelen,
50683 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
50684 + *offset = off & 0x7fffffff;
50685 + return 0;
50686 + }
50687 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50688 off & 0x7fffffff, ino, DT_UNKNOWN)) {
50689 *offset = off & 0x7fffffff;
50690 return 0;
50691 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
50692 index 0e0232c..fa5c3fe 100644
50693 --- a/fs/xfs/xfs_ioctl.c
50694 +++ b/fs/xfs/xfs_ioctl.c
50695 @@ -126,7 +126,7 @@ xfs_find_handle(
50696 }
50697
50698 error = -EFAULT;
50699 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
50700 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
50701 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
50702 goto out_put;
50703
50704 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
50705 index 4e00cf0..3374374 100644
50706 --- a/fs/xfs/xfs_iops.c
50707 +++ b/fs/xfs/xfs_iops.c
50708 @@ -394,7 +394,7 @@ xfs_vn_put_link(
50709 struct nameidata *nd,
50710 void *p)
50711 {
50712 - char *s = nd_get_link(nd);
50713 + const char *s = nd_get_link(nd);
50714
50715 if (!IS_ERR(s))
50716 kfree(s);
50717 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
50718 new file mode 100644
50719 index 0000000..d38b430
50720 --- /dev/null
50721 +++ b/grsecurity/Kconfig
50722 @@ -0,0 +1,947 @@
50723 +#
50724 +# grecurity configuration
50725 +#
50726 +menu "Memory Protections"
50727 +depends on GRKERNSEC
50728 +
50729 +config GRKERNSEC_KMEM
50730 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
50731 + default y if GRKERNSEC_CONFIG_AUTO
50732 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
50733 + help
50734 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
50735 + be written to or read from to modify or leak the contents of the running
50736 + kernel. /dev/port will also not be allowed to be opened. If you have module
50737 + support disabled, enabling this will close up four ways that are
50738 + currently used to insert malicious code into the running kernel.
50739 + Even with all these features enabled, we still highly recommend that
50740 + you use the RBAC system, as it is still possible for an attacker to
50741 + modify the running kernel through privileged I/O granted by ioperm/iopl.
50742 + If you are not using XFree86, you may be able to stop this additional
50743 + case by enabling the 'Disable privileged I/O' option. Though nothing
50744 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
50745 + but only to video memory, which is the only writing we allow in this
50746 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
50747 + not be allowed to mprotect it with PROT_WRITE later.
50748 + It is highly recommended that you say Y here if you meet all the
50749 + conditions above.
50750 +
50751 +config GRKERNSEC_VM86
50752 + bool "Restrict VM86 mode"
50753 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50754 + depends on X86_32
50755 +
50756 + help
50757 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
50758 + make use of a special execution mode on 32bit x86 processors called
50759 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
50760 + video cards and will still work with this option enabled. The purpose
50761 + of the option is to prevent exploitation of emulation errors in
50762 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
50763 + Nearly all users should be able to enable this option.
50764 +
50765 +config GRKERNSEC_IO
50766 + bool "Disable privileged I/O"
50767 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50768 + depends on X86
50769 + select RTC_CLASS
50770 + select RTC_INTF_DEV
50771 + select RTC_DRV_CMOS
50772 +
50773 + help
50774 + If you say Y here, all ioperm and iopl calls will return an error.
50775 + Ioperm and iopl can be used to modify the running kernel.
50776 + Unfortunately, some programs need this access to operate properly,
50777 + the most notable of which are XFree86 and hwclock. hwclock can be
50778 + remedied by having RTC support in the kernel, so real-time
50779 + clock support is enabled if this option is enabled, to ensure
50780 + that hwclock operates correctly. XFree86 still will not
50781 + operate correctly with this option enabled, so DO NOT CHOOSE Y
50782 + IF YOU USE XFree86. If you use XFree86 and you still want to
50783 + protect your kernel against modification, use the RBAC system.
50784 +
50785 +config GRKERNSEC_PROC_MEMMAP
50786 + bool "Harden ASLR against information leaks and entropy reduction"
50787 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
50788 + depends on PAX_NOEXEC || PAX_ASLR
50789 + help
50790 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
50791 + give no information about the addresses of its mappings if
50792 + PaX features that rely on random addresses are enabled on the task.
50793 + In addition to sanitizing this information and disabling other
50794 + dangerous sources of information, this option causes reads of sensitive
50795 + /proc/<pid> entries where the file descriptor was opened in a different
50796 + task than the one performing the read. Such attempts are logged.
50797 + This option also limits argv/env strings for suid/sgid binaries
50798 + to 512KB to prevent a complete exhaustion of the stack entropy provided
50799 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
50800 + binaries to prevent alternative mmap layouts from being abused.
50801 +
50802 + If you use PaX it is essential that you say Y here as it closes up
50803 + several holes that make full ASLR useless locally.
50804 +
50805 +config GRKERNSEC_BRUTE
50806 + bool "Deter exploit bruteforcing"
50807 + default y if GRKERNSEC_CONFIG_AUTO
50808 + help
50809 + If you say Y here, attempts to bruteforce exploits against forking
50810 + daemons such as apache or sshd, as well as against suid/sgid binaries
50811 + will be deterred. When a child of a forking daemon is killed by PaX
50812 + or crashes due to an illegal instruction or other suspicious signal,
50813 + the parent process will be delayed 30 seconds upon every subsequent
50814 + fork until the administrator is able to assess the situation and
50815 + restart the daemon.
50816 + In the suid/sgid case, the attempt is logged, the user has all their
50817 + processes terminated, and they are prevented from executing any further
50818 + processes for 15 minutes.
50819 + It is recommended that you also enable signal logging in the auditing
50820 + section so that logs are generated when a process triggers a suspicious
50821 + signal.
50822 + If the sysctl option is enabled, a sysctl option with name
50823 + "deter_bruteforce" is created.
50824 +
50825 +
50826 +config GRKERNSEC_MODHARDEN
50827 + bool "Harden module auto-loading"
50828 + default y if GRKERNSEC_CONFIG_AUTO
50829 + depends on MODULES
50830 + help
50831 + If you say Y here, module auto-loading in response to use of some
50832 + feature implemented by an unloaded module will be restricted to
50833 + root users. Enabling this option helps defend against attacks
50834 + by unprivileged users who abuse the auto-loading behavior to
50835 + cause a vulnerable module to load that is then exploited.
50836 +
50837 + If this option prevents a legitimate use of auto-loading for a
50838 + non-root user, the administrator can execute modprobe manually
50839 + with the exact name of the module mentioned in the alert log.
50840 + Alternatively, the administrator can add the module to the list
50841 + of modules loaded at boot by modifying init scripts.
50842 +
50843 + Modification of init scripts will most likely be needed on
50844 + Ubuntu servers with encrypted home directory support enabled,
50845 + as the first non-root user logging in will cause the ecb(aes),
50846 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
50847 +
50848 +config GRKERNSEC_HIDESYM
50849 + bool "Hide kernel symbols"
50850 + default y if GRKERNSEC_CONFIG_AUTO
50851 + select PAX_USERCOPY_SLABS
50852 + help
50853 + If you say Y here, getting information on loaded modules, and
50854 + displaying all kernel symbols through a syscall will be restricted
50855 + to users with CAP_SYS_MODULE. For software compatibility reasons,
50856 + /proc/kallsyms will be restricted to the root user. The RBAC
50857 + system can hide that entry even from root.
50858 +
50859 + This option also prevents leaking of kernel addresses through
50860 + several /proc entries.
50861 +
50862 + Note that this option is only effective provided the following
50863 + conditions are met:
50864 + 1) The kernel using grsecurity is not precompiled by some distribution
50865 + 2) You have also enabled GRKERNSEC_DMESG
50866 + 3) You are using the RBAC system and hiding other files such as your
50867 + kernel image and System.map. Alternatively, enabling this option
50868 + causes the permissions on /boot, /lib/modules, and the kernel
50869 + source directory to change at compile time to prevent
50870 + reading by non-root users.
50871 + If the above conditions are met, this option will aid in providing a
50872 + useful protection against local kernel exploitation of overflows
50873 + and arbitrary read/write vulnerabilities.
50874 +
50875 +config GRKERNSEC_KERN_LOCKOUT
50876 + bool "Active kernel exploit response"
50877 + default y if GRKERNSEC_CONFIG_AUTO
50878 + depends on X86 || ARM || PPC || SPARC
50879 + help
50880 + If you say Y here, when a PaX alert is triggered due to suspicious
50881 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
50882 + or an OOPS occurs due to bad memory accesses, instead of just
50883 + terminating the offending process (and potentially allowing
50884 + a subsequent exploit from the same user), we will take one of two
50885 + actions:
50886 + If the user was root, we will panic the system
50887 + If the user was non-root, we will log the attempt, terminate
50888 + all processes owned by the user, then prevent them from creating
50889 + any new processes until the system is restarted
50890 + This deters repeated kernel exploitation/bruteforcing attempts
50891 + and is useful for later forensics.
50892 +
50893 +endmenu
50894 +menu "Role Based Access Control Options"
50895 +depends on GRKERNSEC
50896 +
50897 +config GRKERNSEC_RBAC_DEBUG
50898 + bool
50899 +
50900 +config GRKERNSEC_NO_RBAC
50901 + bool "Disable RBAC system"
50902 + help
50903 + If you say Y here, the /dev/grsec device will be removed from the kernel,
50904 + preventing the RBAC system from being enabled. You should only say Y
50905 + here if you have no intention of using the RBAC system, so as to prevent
50906 + an attacker with root access from misusing the RBAC system to hide files
50907 + and processes when loadable module support and /dev/[k]mem have been
50908 + locked down.
50909 +
50910 +config GRKERNSEC_ACL_HIDEKERN
50911 + bool "Hide kernel processes"
50912 + help
50913 + If you say Y here, all kernel threads will be hidden to all
50914 + processes but those whose subject has the "view hidden processes"
50915 + flag.
50916 +
50917 +config GRKERNSEC_ACL_MAXTRIES
50918 + int "Maximum tries before password lockout"
50919 + default 3
50920 + help
50921 + This option enforces the maximum number of times a user can attempt
50922 + to authorize themselves with the grsecurity RBAC system before being
50923 + denied the ability to attempt authorization again for a specified time.
50924 + The lower the number, the harder it will be to brute-force a password.
50925 +
50926 +config GRKERNSEC_ACL_TIMEOUT
50927 + int "Time to wait after max password tries, in seconds"
50928 + default 30
50929 + help
50930 + This option specifies the time the user must wait after attempting to
50931 + authorize to the RBAC system with the maximum number of invalid
50932 + passwords. The higher the number, the harder it will be to brute-force
50933 + a password.
50934 +
50935 +endmenu
50936 +menu "Filesystem Protections"
50937 +depends on GRKERNSEC
50938 +
50939 +config GRKERNSEC_PROC
50940 + bool "Proc restrictions"
50941 + default y if GRKERNSEC_CONFIG_AUTO
50942 + help
50943 + If you say Y here, the permissions of the /proc filesystem
50944 + will be altered to enhance system security and privacy. You MUST
50945 + choose either a user only restriction or a user and group restriction.
50946 + Depending upon the option you choose, you can either restrict users to
50947 + see only the processes they themselves run, or choose a group that can
50948 + view all processes and files normally restricted to root if you choose
50949 + the "restrict to user only" option. NOTE: If you're running identd or
50950 + ntpd as a non-root user, you will have to run it as the group you
50951 + specify here.
50952 +
50953 +config GRKERNSEC_PROC_USER
50954 + bool "Restrict /proc to user only"
50955 + depends on GRKERNSEC_PROC
50956 + help
50957 + If you say Y here, non-root users will only be able to view their own
50958 + processes, and restricts them from viewing network-related information,
50959 + and viewing kernel symbol and module information.
50960 +
50961 +config GRKERNSEC_PROC_USERGROUP
50962 + bool "Allow special group"
50963 + default y if GRKERNSEC_CONFIG_AUTO
50964 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
50965 + help
50966 + If you say Y here, you will be able to select a group that will be
50967 + able to view all processes and network-related information. If you've
50968 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
50969 + remain hidden. This option is useful if you want to run identd as
50970 + a non-root user. The group you select may also be chosen at boot time
50971 + via "grsec_proc_gid=" on the kernel commandline.
50972 +
50973 +config GRKERNSEC_PROC_GID
50974 + int "GID for special group"
50975 + depends on GRKERNSEC_PROC_USERGROUP
50976 + default 1001
50977 +
50978 +config GRKERNSEC_PROC_ADD
50979 + bool "Additional restrictions"
50980 + default y if GRKERNSEC_CONFIG_AUTO
50981 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
50982 + help
50983 + If you say Y here, additional restrictions will be placed on
50984 + /proc that keep normal users from viewing device information and
50985 + slabinfo information that could be useful for exploits.
50986 +
50987 +config GRKERNSEC_LINK
50988 + bool "Linking restrictions"
50989 + default y if GRKERNSEC_CONFIG_AUTO
50990 + help
50991 + If you say Y here, /tmp race exploits will be prevented, since users
50992 + will no longer be able to follow symlinks owned by other users in
50993 + world-writable +t directories (e.g. /tmp), unless the owner of the
50994 + symlink is the owner of the directory. users will also not be
50995 + able to hardlink to files they do not own. If the sysctl option is
50996 + enabled, a sysctl option with name "linking_restrictions" is created.
50997 +
50998 +config GRKERNSEC_SYMLINKOWN
50999 + bool "Kernel-enforced SymlinksIfOwnerMatch"
51000 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
51001 + help
51002 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
51003 + that prevents it from being used as a security feature. As Apache
51004 + verifies the symlink by performing a stat() against the target of
51005 + the symlink before it is followed, an attacker can setup a symlink
51006 + to point to a same-owned file, then replace the symlink with one
51007 + that targets another user's file just after Apache "validates" the
51008 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
51009 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
51010 + will be in place for the group you specify. If the sysctl option
51011 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
51012 + created.
51013 +
51014 +config GRKERNSEC_SYMLINKOWN_GID
51015 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
51016 + depends on GRKERNSEC_SYMLINKOWN
51017 + default 1006
51018 + help
51019 + Setting this GID determines what group kernel-enforced
51020 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
51021 + is enabled, a sysctl option with name "symlinkown_gid" is created.
51022 +
51023 +config GRKERNSEC_FIFO
51024 + bool "FIFO restrictions"
51025 + default y if GRKERNSEC_CONFIG_AUTO
51026 + help
51027 + If you say Y here, users will not be able to write to FIFOs they don't
51028 + own in world-writable +t directories (e.g. /tmp), unless the owner of
51029 + the FIFO is the same owner of the directory it's held in. If the sysctl
51030 + option is enabled, a sysctl option with name "fifo_restrictions" is
51031 + created.
51032 +
51033 +config GRKERNSEC_SYSFS_RESTRICT
51034 + bool "Sysfs/debugfs restriction"
51035 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
51036 + depends on SYSFS
51037 + help
51038 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
51039 + any filesystem normally mounted under it (e.g. debugfs) will be
51040 + mostly accessible only by root. These filesystems generally provide access
51041 + to hardware and debug information that isn't appropriate for unprivileged
51042 + users of the system. Sysfs and debugfs have also become a large source
51043 + of new vulnerabilities, ranging from infoleaks to local compromise.
51044 + There has been very little oversight with an eye toward security involved
51045 + in adding new exporters of information to these filesystems, so their
51046 + use is discouraged.
51047 + For reasons of compatibility, a few directories have been whitelisted
51048 + for access by non-root users:
51049 + /sys/fs/selinux
51050 + /sys/fs/fuse
51051 + /sys/devices/system/cpu
51052 +
51053 +config GRKERNSEC_ROFS
51054 + bool "Runtime read-only mount protection"
51055 + help
51056 + If you say Y here, a sysctl option with name "romount_protect" will
51057 + be created. By setting this option to 1 at runtime, filesystems
51058 + will be protected in the following ways:
51059 + * No new writable mounts will be allowed
51060 + * Existing read-only mounts won't be able to be remounted read/write
51061 + * Write operations will be denied on all block devices
51062 + This option acts independently of grsec_lock: once it is set to 1,
51063 + it cannot be turned off. Therefore, please be mindful of the resulting
51064 + behavior if this option is enabled in an init script on a read-only
51065 + filesystem. This feature is mainly intended for secure embedded systems.
51066 +
51067 +config GRKERNSEC_CHROOT
51068 + bool "Chroot jail restrictions"
51069 + default y if GRKERNSEC_CONFIG_AUTO
51070 + help
51071 + If you say Y here, you will be able to choose several options that will
51072 + make breaking out of a chrooted jail much more difficult. If you
51073 + encounter no software incompatibilities with the following options, it
51074 + is recommended that you enable each one.
51075 +
51076 +config GRKERNSEC_CHROOT_MOUNT
51077 + bool "Deny mounts"
51078 + default y if GRKERNSEC_CONFIG_AUTO
51079 + depends on GRKERNSEC_CHROOT
51080 + help
51081 + If you say Y here, processes inside a chroot will not be able to
51082 + mount or remount filesystems. If the sysctl option is enabled, a
51083 + sysctl option with name "chroot_deny_mount" is created.
51084 +
51085 +config GRKERNSEC_CHROOT_DOUBLE
51086 + bool "Deny double-chroots"
51087 + default y if GRKERNSEC_CONFIG_AUTO
51088 + depends on GRKERNSEC_CHROOT
51089 + help
51090 + If you say Y here, processes inside a chroot will not be able to chroot
51091 + again outside the chroot. This is a widely used method of breaking
51092 + out of a chroot jail and should not be allowed. If the sysctl
51093 + option is enabled, a sysctl option with name
51094 + "chroot_deny_chroot" is created.
51095 +
51096 +config GRKERNSEC_CHROOT_PIVOT
51097 + bool "Deny pivot_root in chroot"
51098 + default y if GRKERNSEC_CONFIG_AUTO
51099 + depends on GRKERNSEC_CHROOT
51100 + help
51101 + If you say Y here, processes inside a chroot will not be able to use
51102 + a function called pivot_root() that was introduced in Linux 2.3.41. It
51103 + works similar to chroot in that it changes the root filesystem. This
51104 + function could be misused in a chrooted process to attempt to break out
51105 + of the chroot, and therefore should not be allowed. If the sysctl
51106 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
51107 + created.
51108 +
51109 +config GRKERNSEC_CHROOT_CHDIR
51110 + bool "Enforce chdir(\"/\") on all chroots"
51111 + default y if GRKERNSEC_CONFIG_AUTO
51112 + depends on GRKERNSEC_CHROOT
51113 + help
51114 + If you say Y here, the current working directory of all newly-chrooted
51115 + applications will be set to the the root directory of the chroot.
51116 + The man page on chroot(2) states:
51117 + Note that this call does not change the current working
51118 + directory, so that `.' can be outside the tree rooted at
51119 + `/'. In particular, the super-user can escape from a
51120 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
51121 +
51122 + It is recommended that you say Y here, since it's not known to break
51123 + any software. If the sysctl option is enabled, a sysctl option with
51124 + name "chroot_enforce_chdir" is created.
51125 +
51126 +config GRKERNSEC_CHROOT_CHMOD
51127 + bool "Deny (f)chmod +s"
51128 + default y if GRKERNSEC_CONFIG_AUTO
51129 + depends on GRKERNSEC_CHROOT
51130 + help
51131 + If you say Y here, processes inside a chroot will not be able to chmod
51132 + or fchmod files to make them have suid or sgid bits. This protects
51133 + against another published method of breaking a chroot. If the sysctl
51134 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
51135 + created.
51136 +
51137 +config GRKERNSEC_CHROOT_FCHDIR
51138 + bool "Deny fchdir out of chroot"
51139 + default y if GRKERNSEC_CONFIG_AUTO
51140 + depends on GRKERNSEC_CHROOT
51141 + help
51142 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
51143 + to a file descriptor of the chrooting process that points to a directory
51144 + outside the filesystem will be stopped. If the sysctl option
51145 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
51146 +
51147 +config GRKERNSEC_CHROOT_MKNOD
51148 + bool "Deny mknod"
51149 + default y if GRKERNSEC_CONFIG_AUTO
51150 + depends on GRKERNSEC_CHROOT
51151 + help
51152 + If you say Y here, processes inside a chroot will not be allowed to
51153 + mknod. The problem with using mknod inside a chroot is that it
51154 + would allow an attacker to create a device entry that is the same
51155 + as one on the physical root of your system, which could range from
51156 + anything from the console device to a device for your harddrive (which
51157 + they could then use to wipe the drive or steal data). It is recommended
51158 + that you say Y here, unless you run into software incompatibilities.
51159 + If the sysctl option is enabled, a sysctl option with name
51160 + "chroot_deny_mknod" is created.
51161 +
51162 +config GRKERNSEC_CHROOT_SHMAT
51163 + bool "Deny shmat() out of chroot"
51164 + default y if GRKERNSEC_CONFIG_AUTO
51165 + depends on GRKERNSEC_CHROOT
51166 + help
51167 + If you say Y here, processes inside a chroot will not be able to attach
51168 + to shared memory segments that were created outside of the chroot jail.
51169 + It is recommended that you say Y here. If the sysctl option is enabled,
51170 + a sysctl option with name "chroot_deny_shmat" is created.
51171 +
51172 +config GRKERNSEC_CHROOT_UNIX
51173 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
51174 + default y if GRKERNSEC_CONFIG_AUTO
51175 + depends on GRKERNSEC_CHROOT
51176 + help
51177 + If you say Y here, processes inside a chroot will not be able to
51178 + connect to abstract (meaning not belonging to a filesystem) Unix
51179 + domain sockets that were bound outside of a chroot. It is recommended
51180 + that you say Y here. If the sysctl option is enabled, a sysctl option
51181 + with name "chroot_deny_unix" is created.
51182 +
51183 +config GRKERNSEC_CHROOT_FINDTASK
51184 + bool "Protect outside processes"
51185 + default y if GRKERNSEC_CONFIG_AUTO
51186 + depends on GRKERNSEC_CHROOT
51187 + help
51188 + If you say Y here, processes inside a chroot will not be able to
51189 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
51190 + getsid, or view any process outside of the chroot. If the sysctl
51191 + option is enabled, a sysctl option with name "chroot_findtask" is
51192 + created.
51193 +
51194 +config GRKERNSEC_CHROOT_NICE
51195 + bool "Restrict priority changes"
51196 + default y if GRKERNSEC_CONFIG_AUTO
51197 + depends on GRKERNSEC_CHROOT
51198 + help
51199 + If you say Y here, processes inside a chroot will not be able to raise
51200 + the priority of processes in the chroot, or alter the priority of
51201 + processes outside the chroot. This provides more security than simply
51202 + removing CAP_SYS_NICE from the process' capability set. If the
51203 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
51204 + is created.
51205 +
51206 +config GRKERNSEC_CHROOT_SYSCTL
51207 + bool "Deny sysctl writes"
51208 + default y if GRKERNSEC_CONFIG_AUTO
51209 + depends on GRKERNSEC_CHROOT
51210 + help
51211 + If you say Y here, an attacker in a chroot will not be able to
51212 + write to sysctl entries, either by sysctl(2) or through a /proc
51213 + interface. It is strongly recommended that you say Y here. If the
51214 + sysctl option is enabled, a sysctl option with name
51215 + "chroot_deny_sysctl" is created.
51216 +
51217 +config GRKERNSEC_CHROOT_CAPS
51218 + bool "Capability restrictions"
51219 + default y if GRKERNSEC_CONFIG_AUTO
51220 + depends on GRKERNSEC_CHROOT
51221 + help
51222 + If you say Y here, the capabilities on all processes within a
51223 + chroot jail will be lowered to stop module insertion, raw i/o,
51224 + system and net admin tasks, rebooting the system, modifying immutable
51225 + files, modifying IPC owned by another, and changing the system time.
51226 + This is left an option because it can break some apps. Disable this
51227 + if your chrooted apps are having problems performing those kinds of
51228 + tasks. If the sysctl option is enabled, a sysctl option with
51229 + name "chroot_caps" is created.
51230 +
51231 +endmenu
51232 +menu "Kernel Auditing"
51233 +depends on GRKERNSEC
51234 +
51235 +config GRKERNSEC_AUDIT_GROUP
51236 + bool "Single group for auditing"
51237 + help
51238 + If you say Y here, the exec, chdir, and (un)mount logging features
51239 + will only operate on a group you specify. This option is recommended
51240 + if you only want to watch certain users instead of having a large
51241 + amount of logs from the entire system. If the sysctl option is enabled,
51242 + a sysctl option with name "audit_group" is created.
51243 +
51244 +config GRKERNSEC_AUDIT_GID
51245 + int "GID for auditing"
51246 + depends on GRKERNSEC_AUDIT_GROUP
51247 + default 1007
51248 +
51249 +config GRKERNSEC_EXECLOG
51250 + bool "Exec logging"
51251 + help
51252 + If you say Y here, all execve() calls will be logged (since the
51253 + other exec*() calls are frontends to execve(), all execution
51254 + will be logged). Useful for shell-servers that like to keep track
51255 + of their users. If the sysctl option is enabled, a sysctl option with
51256 + name "exec_logging" is created.
51257 + WARNING: This option when enabled will produce a LOT of logs, especially
51258 + on an active system.
51259 +
51260 +config GRKERNSEC_RESLOG
51261 + bool "Resource logging"
51262 + default y if GRKERNSEC_CONFIG_AUTO
51263 + help
51264 + If you say Y here, all attempts to overstep resource limits will
51265 + be logged with the resource name, the requested size, and the current
51266 + limit. It is highly recommended that you say Y here. If the sysctl
51267 + option is enabled, a sysctl option with name "resource_logging" is
51268 + created. If the RBAC system is enabled, the sysctl value is ignored.
51269 +
51270 +config GRKERNSEC_CHROOT_EXECLOG
51271 + bool "Log execs within chroot"
51272 + help
51273 + If you say Y here, all executions inside a chroot jail will be logged
51274 + to syslog. This can cause a large amount of logs if certain
51275 + applications (eg. djb's daemontools) are installed on the system, and
51276 + is therefore left as an option. If the sysctl option is enabled, a
51277 + sysctl option with name "chroot_execlog" is created.
51278 +
51279 +config GRKERNSEC_AUDIT_PTRACE
51280 + bool "Ptrace logging"
51281 + help
51282 + If you say Y here, all attempts to attach to a process via ptrace
51283 + will be logged. If the sysctl option is enabled, a sysctl option
51284 + with name "audit_ptrace" is created.
51285 +
51286 +config GRKERNSEC_AUDIT_CHDIR
51287 + bool "Chdir logging"
51288 + help
51289 + If you say Y here, all chdir() calls will be logged. If the sysctl
51290 + option is enabled, a sysctl option with name "audit_chdir" is created.
51291 +
51292 +config GRKERNSEC_AUDIT_MOUNT
51293 + bool "(Un)Mount logging"
51294 + help
51295 + If you say Y here, all mounts and unmounts will be logged. If the
51296 + sysctl option is enabled, a sysctl option with name "audit_mount" is
51297 + created.
51298 +
51299 +config GRKERNSEC_SIGNAL
51300 + bool "Signal logging"
51301 + default y if GRKERNSEC_CONFIG_AUTO
51302 + help
51303 + If you say Y here, certain important signals will be logged, such as
51304 + SIGSEGV, which will as a result inform you of when a error in a program
51305 + occurred, which in some cases could mean a possible exploit attempt.
51306 + If the sysctl option is enabled, a sysctl option with name
51307 + "signal_logging" is created.
51308 +
51309 +config GRKERNSEC_FORKFAIL
51310 + bool "Fork failure logging"
51311 + help
51312 + If you say Y here, all failed fork() attempts will be logged.
51313 + This could suggest a fork bomb, or someone attempting to overstep
51314 + their process limit. If the sysctl option is enabled, a sysctl option
51315 + with name "forkfail_logging" is created.
51316 +
51317 +config GRKERNSEC_TIME
51318 + bool "Time change logging"
51319 + default y if GRKERNSEC_CONFIG_AUTO
51320 + help
51321 + If you say Y here, any changes of the system clock will be logged.
51322 + If the sysctl option is enabled, a sysctl option with name
51323 + "timechange_logging" is created.
51324 +
51325 +config GRKERNSEC_PROC_IPADDR
51326 + bool "/proc/<pid>/ipaddr support"
51327 + default y if GRKERNSEC_CONFIG_AUTO
51328 + help
51329 + If you say Y here, a new entry will be added to each /proc/<pid>
51330 + directory that contains the IP address of the person using the task.
51331 + The IP is carried across local TCP and AF_UNIX stream sockets.
51332 + This information can be useful for IDS/IPSes to perform remote response
51333 + to a local attack. The entry is readable by only the owner of the
51334 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
51335 + the RBAC system), and thus does not create privacy concerns.
51336 +
51337 +config GRKERNSEC_RWXMAP_LOG
51338 + bool 'Denied RWX mmap/mprotect logging'
51339 + default y if GRKERNSEC_CONFIG_AUTO
51340 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
51341 + help
51342 + If you say Y here, calls to mmap() and mprotect() with explicit
51343 + usage of PROT_WRITE and PROT_EXEC together will be logged when
51344 + denied by the PAX_MPROTECT feature. If the sysctl option is
51345 + enabled, a sysctl option with name "rwxmap_logging" is created.
51346 +
51347 +config GRKERNSEC_AUDIT_TEXTREL
51348 + bool 'ELF text relocations logging (READ HELP)'
51349 + depends on PAX_MPROTECT
51350 + help
51351 + If you say Y here, text relocations will be logged with the filename
51352 + of the offending library or binary. The purpose of the feature is
51353 + to help Linux distribution developers get rid of libraries and
51354 + binaries that need text relocations which hinder the future progress
51355 + of PaX. Only Linux distribution developers should say Y here, and
51356 + never on a production machine, as this option creates an information
51357 + leak that could aid an attacker in defeating the randomization of
51358 + a single memory region. If the sysctl option is enabled, a sysctl
51359 + option with name "audit_textrel" is created.
51360 +
51361 +endmenu
51362 +
51363 +menu "Executable Protections"
51364 +depends on GRKERNSEC
51365 +
51366 +config GRKERNSEC_DMESG
51367 + bool "Dmesg(8) restriction"
51368 + default y if GRKERNSEC_CONFIG_AUTO
51369 + help
51370 + If you say Y here, non-root users will not be able to use dmesg(8)
51371 + to view up to the last 4kb of messages in the kernel's log buffer.
51372 + The kernel's log buffer often contains kernel addresses and other
51373 + identifying information useful to an attacker in fingerprinting a
51374 + system for a targeted exploit.
51375 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
51376 + created.
51377 +
51378 +config GRKERNSEC_HARDEN_PTRACE
51379 + bool "Deter ptrace-based process snooping"
51380 + default y if GRKERNSEC_CONFIG_AUTO
51381 + help
51382 + If you say Y here, TTY sniffers and other malicious monitoring
51383 + programs implemented through ptrace will be defeated. If you
51384 + have been using the RBAC system, this option has already been
51385 + enabled for several years for all users, with the ability to make
51386 + fine-grained exceptions.
51387 +
51388 + This option only affects the ability of non-root users to ptrace
51389 + processes that are not a descendent of the ptracing process.
51390 + This means that strace ./binary and gdb ./binary will still work,
51391 + but attaching to arbitrary processes will not. If the sysctl
51392 + option is enabled, a sysctl option with name "harden_ptrace" is
51393 + created.
51394 +
51395 +config GRKERNSEC_PTRACE_READEXEC
51396 + bool "Require read access to ptrace sensitive binaries"
51397 + default y if GRKERNSEC_CONFIG_AUTO
51398 + help
51399 + If you say Y here, unprivileged users will not be able to ptrace unreadable
51400 + binaries. This option is useful in environments that
51401 + remove the read bits (e.g. file mode 4711) from suid binaries to
51402 + prevent infoleaking of their contents. This option adds
51403 + consistency to the use of that file mode, as the binary could normally
51404 + be read out when run without privileges while ptracing.
51405 +
51406 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
51407 + is created.
51408 +
51409 +config GRKERNSEC_SETXID
51410 + bool "Enforce consistent multithreaded privileges"
51411 + default y if GRKERNSEC_CONFIG_AUTO
51412 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
51413 + help
51414 + If you say Y here, a change from a root uid to a non-root uid
51415 + in a multithreaded application will cause the resulting uids,
51416 + gids, supplementary groups, and capabilities in that thread
51417 + to be propagated to the other threads of the process. In most
51418 + cases this is unnecessary, as glibc will emulate this behavior
51419 + on behalf of the application. Other libcs do not act in the
51420 + same way, allowing the other threads of the process to continue
51421 + running with root privileges. If the sysctl option is enabled,
51422 + a sysctl option with name "consistent_setxid" is created.
51423 +
51424 +config GRKERNSEC_TPE
51425 + bool "Trusted Path Execution (TPE)"
51426 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
51427 + help
51428 + If you say Y here, you will be able to choose a gid to add to the
51429 + supplementary groups of users you want to mark as "untrusted."
51430 + These users will not be able to execute any files that are not in
51431 + root-owned directories writable only by root. If the sysctl option
51432 + is enabled, a sysctl option with name "tpe" is created.
51433 +
51434 +config GRKERNSEC_TPE_ALL
51435 + bool "Partially restrict all non-root users"
51436 + depends on GRKERNSEC_TPE
51437 + help
51438 + If you say Y here, all non-root users will be covered under
51439 + a weaker TPE restriction. This is separate from, and in addition to,
51440 + the main TPE options that you have selected elsewhere. Thus, if a
51441 + "trusted" GID is chosen, this restriction applies to even that GID.
51442 + Under this restriction, all non-root users will only be allowed to
51443 + execute files in directories they own that are not group or
51444 + world-writable, or in directories owned by root and writable only by
51445 + root. If the sysctl option is enabled, a sysctl option with name
51446 + "tpe_restrict_all" is created.
51447 +
51448 +config GRKERNSEC_TPE_INVERT
51449 + bool "Invert GID option"
51450 + depends on GRKERNSEC_TPE
51451 + help
51452 + If you say Y here, the group you specify in the TPE configuration will
51453 + decide what group TPE restrictions will be *disabled* for. This
51454 + option is useful if you want TPE restrictions to be applied to most
51455 + users on the system. If the sysctl option is enabled, a sysctl option
51456 + with name "tpe_invert" is created. Unlike other sysctl options, this
51457 + entry will default to on for backward-compatibility.
51458 +
51459 +config GRKERNSEC_TPE_GID
51460 + int
51461 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
51462 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
51463 +
51464 +config GRKERNSEC_TPE_UNTRUSTED_GID
51465 + int "GID for TPE-untrusted users"
51466 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
51467 + default 1005
51468 + help
51469 + Setting this GID determines what group TPE restrictions will be
51470 + *enabled* for. If the sysctl option is enabled, a sysctl option
51471 + with name "tpe_gid" is created.
51472 +
51473 +config GRKERNSEC_TPE_TRUSTED_GID
51474 + int "GID for TPE-trusted users"
51475 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
51476 + default 1005
51477 + help
51478 + Setting this GID determines what group TPE restrictions will be
51479 + *disabled* for. If the sysctl option is enabled, a sysctl option
51480 + with name "tpe_gid" is created.
51481 +
51482 +endmenu
51483 +menu "Network Protections"
51484 +depends on GRKERNSEC
51485 +
51486 +config GRKERNSEC_RANDNET
51487 + bool "Larger entropy pools"
51488 + default y if GRKERNSEC_CONFIG_AUTO
51489 + help
51490 + If you say Y here, the entropy pools used for many features of Linux
51491 + and grsecurity will be doubled in size. Since several grsecurity
51492 + features use additional randomness, it is recommended that you say Y
51493 + here. Saying Y here has a similar effect as modifying
51494 + /proc/sys/kernel/random/poolsize.
51495 +
51496 +config GRKERNSEC_BLACKHOLE
51497 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
51498 + default y if GRKERNSEC_CONFIG_AUTO
51499 + depends on NET
51500 + help
51501 + If you say Y here, neither TCP resets nor ICMP
51502 + destination-unreachable packets will be sent in response to packets
51503 + sent to ports for which no associated listening process exists.
51504 + This feature supports both IPV4 and IPV6 and exempts the
51505 + loopback interface from blackholing. Enabling this feature
51506 + makes a host more resilient to DoS attacks and reduces network
51507 + visibility against scanners.
51508 +
51509 + The blackhole feature as-implemented is equivalent to the FreeBSD
51510 + blackhole feature, as it prevents RST responses to all packets, not
51511 + just SYNs. Under most application behavior this causes no
51512 + problems, but applications (like haproxy) may not close certain
51513 + connections in a way that cleanly terminates them on the remote
51514 + end, leaving the remote host in LAST_ACK state. Because of this
51515 + side-effect and to prevent intentional LAST_ACK DoSes, this
51516 + feature also adds automatic mitigation against such attacks.
51517 + The mitigation drastically reduces the amount of time a socket
51518 + can spend in LAST_ACK state. If you're using haproxy and not
51519 + all servers it connects to have this option enabled, consider
51520 + disabling this feature on the haproxy host.
51521 +
51522 + If the sysctl option is enabled, two sysctl options with names
51523 + "ip_blackhole" and "lastack_retries" will be created.
51524 + While "ip_blackhole" takes the standard zero/non-zero on/off
51525 + toggle, "lastack_retries" uses the same kinds of values as
51526 + "tcp_retries1" and "tcp_retries2". The default value of 4
51527 + prevents a socket from lasting more than 45 seconds in LAST_ACK
51528 + state.
51529 +
51530 +config GRKERNSEC_SOCKET
51531 + bool "Socket restrictions"
51532 + depends on NET
51533 + help
51534 + If you say Y here, you will be able to choose from several options.
51535 + If you assign a GID on your system and add it to the supplementary
51536 + groups of users you want to restrict socket access to, this patch
51537 + will perform up to three things, based on the option(s) you choose.
51538 +
51539 +config GRKERNSEC_SOCKET_ALL
51540 + bool "Deny any sockets to group"
51541 + depends on GRKERNSEC_SOCKET
51542 + help
51543 + If you say Y here, you will be able to choose a GID of whose users will
51544 + be unable to connect to other hosts from your machine or run server
51545 + applications from your machine. If the sysctl option is enabled, a
51546 + sysctl option with name "socket_all" is created.
51547 +
51548 +config GRKERNSEC_SOCKET_ALL_GID
51549 + int "GID to deny all sockets for"
51550 + depends on GRKERNSEC_SOCKET_ALL
51551 + default 1004
51552 + help
51553 + Here you can choose the GID to disable socket access for. Remember to
51554 + add the users you want socket access disabled for to the GID
51555 + specified here. If the sysctl option is enabled, a sysctl option
51556 + with name "socket_all_gid" is created.
51557 +
51558 +config GRKERNSEC_SOCKET_CLIENT
51559 + bool "Deny client sockets to group"
51560 + depends on GRKERNSEC_SOCKET
51561 + help
51562 + If you say Y here, you will be able to choose a GID of whose users will
51563 + be unable to connect to other hosts from your machine, but will be
51564 + able to run servers. If this option is enabled, all users in the group
51565 + you specify will have to use passive mode when initiating ftp transfers
51566 + from the shell on your machine. If the sysctl option is enabled, a
51567 + sysctl option with name "socket_client" is created.
51568 +
51569 +config GRKERNSEC_SOCKET_CLIENT_GID
51570 + int "GID to deny client sockets for"
51571 + depends on GRKERNSEC_SOCKET_CLIENT
51572 + default 1003
51573 + help
51574 + Here you can choose the GID to disable client socket access for.
51575 + Remember to add the users you want client socket access disabled for to
51576 + the GID specified here. If the sysctl option is enabled, a sysctl
51577 + option with name "socket_client_gid" is created.
51578 +
51579 +config GRKERNSEC_SOCKET_SERVER
51580 + bool "Deny server sockets to group"
51581 + depends on GRKERNSEC_SOCKET
51582 + help
51583 + If you say Y here, you will be able to choose a GID of whose users will
51584 + be unable to run server applications from your machine. If the sysctl
51585 + option is enabled, a sysctl option with name "socket_server" is created.
51586 +
51587 +config GRKERNSEC_SOCKET_SERVER_GID
51588 + int "GID to deny server sockets for"
51589 + depends on GRKERNSEC_SOCKET_SERVER
51590 + default 1002
51591 + help
51592 + Here you can choose the GID to disable server socket access for.
51593 + Remember to add the users you want server socket access disabled for to
51594 + the GID specified here. If the sysctl option is enabled, a sysctl
51595 + option with name "socket_server_gid" is created.
51596 +
51597 +endmenu
51598 +menu "Sysctl Support"
51599 +depends on GRKERNSEC && SYSCTL
51600 +
51601 +config GRKERNSEC_SYSCTL
51602 + bool "Sysctl support"
51603 + default y if GRKERNSEC_CONFIG_AUTO
51604 + help
51605 + If you say Y here, you will be able to change the options that
51606 + grsecurity runs with at bootup, without having to recompile your
51607 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
51608 + to enable (1) or disable (0) various features. All the sysctl entries
51609 + are mutable until the "grsec_lock" entry is set to a non-zero value.
51610 + All features enabled in the kernel configuration are disabled at boot
51611 + if you do not say Y to the "Turn on features by default" option.
51612 + All options should be set at startup, and the grsec_lock entry should
51613 + be set to a non-zero value after all the options are set.
51614 + *THIS IS EXTREMELY IMPORTANT*
51615 +
51616 +config GRKERNSEC_SYSCTL_DISTRO
51617 + bool "Extra sysctl support for distro makers (READ HELP)"
51618 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
51619 + help
51620 + If you say Y here, additional sysctl options will be created
51621 + for features that affect processes running as root. Therefore,
51622 + it is critical when using this option that the grsec_lock entry be
51623 + enabled after boot. Only distros with prebuilt kernel packages
51624 + with this option enabled that can ensure grsec_lock is enabled
51625 + after boot should use this option.
51626 + *Failure to set grsec_lock after boot makes all grsec features
51627 + this option covers useless*
51628 +
51629 + Currently this option creates the following sysctl entries:
51630 + "Disable Privileged I/O": "disable_priv_io"
51631 +
51632 +config GRKERNSEC_SYSCTL_ON
51633 + bool "Turn on features by default"
51634 + default y if GRKERNSEC_CONFIG_AUTO
51635 + depends on GRKERNSEC_SYSCTL
51636 + help
51637 + If you say Y here, instead of having all features enabled in the
51638 + kernel configuration disabled at boot time, the features will be
51639 + enabled at boot time. It is recommended you say Y here unless
51640 + there is some reason you would want all sysctl-tunable features to
51641 + be disabled by default. As mentioned elsewhere, it is important
51642 + to enable the grsec_lock entry once you have finished modifying
51643 + the sysctl entries.
51644 +
51645 +endmenu
51646 +menu "Logging Options"
51647 +depends on GRKERNSEC
51648 +
51649 +config GRKERNSEC_FLOODTIME
51650 + int "Seconds in between log messages (minimum)"
51651 + default 10
51652 + help
51653 + This option allows you to enforce the number of seconds between
51654 + grsecurity log messages. The default should be suitable for most
51655 + people, however, if you choose to change it, choose a value small enough
51656 + to allow informative logs to be produced, but large enough to
51657 + prevent flooding.
51658 +
51659 +config GRKERNSEC_FLOODBURST
51660 + int "Number of messages in a burst (maximum)"
51661 + default 6
51662 + help
51663 + This option allows you to choose the maximum number of messages allowed
51664 + within the flood time interval you chose in a separate option. The
51665 + default should be suitable for most people, however if you find that
51666 + many of your logs are being interpreted as flooding, you may want to
51667 + raise this value.
51668 +
51669 +endmenu
51670 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
51671 new file mode 100644
51672 index 0000000..1b9afa9
51673 --- /dev/null
51674 +++ b/grsecurity/Makefile
51675 @@ -0,0 +1,38 @@
51676 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
51677 +# during 2001-2009 it has been completely redesigned by Brad Spengler
51678 +# into an RBAC system
51679 +#
51680 +# All code in this directory and various hooks inserted throughout the kernel
51681 +# are copyright Brad Spengler - Open Source Security, Inc., and released
51682 +# under the GPL v2 or higher
51683 +
51684 +KBUILD_CFLAGS += -Werror
51685 +
51686 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
51687 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
51688 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
51689 +
51690 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
51691 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
51692 + gracl_learn.o grsec_log.o
51693 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
51694 +
51695 +ifdef CONFIG_NET
51696 +obj-y += grsec_sock.o
51697 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
51698 +endif
51699 +
51700 +ifndef CONFIG_GRKERNSEC
51701 +obj-y += grsec_disabled.o
51702 +endif
51703 +
51704 +ifdef CONFIG_GRKERNSEC_HIDESYM
51705 +extra-y := grsec_hidesym.o
51706 +$(obj)/grsec_hidesym.o:
51707 + @-chmod -f 500 /boot
51708 + @-chmod -f 500 /lib/modules
51709 + @-chmod -f 500 /lib64/modules
51710 + @-chmod -f 500 /lib32/modules
51711 + @-chmod -f 700 .
51712 + @echo ' grsec: protected kernel image paths'
51713 +endif
51714 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
51715 new file mode 100644
51716 index 0000000..3d58260
51717 --- /dev/null
51718 +++ b/grsecurity/gracl.c
51719 @@ -0,0 +1,4029 @@
51720 +#include <linux/kernel.h>
51721 +#include <linux/module.h>
51722 +#include <linux/sched.h>
51723 +#include <linux/mm.h>
51724 +#include <linux/file.h>
51725 +#include <linux/fs.h>
51726 +#include <linux/namei.h>
51727 +#include <linux/mount.h>
51728 +#include <linux/tty.h>
51729 +#include <linux/proc_fs.h>
51730 +#include <linux/lglock.h>
51731 +#include <linux/slab.h>
51732 +#include <linux/vmalloc.h>
51733 +#include <linux/types.h>
51734 +#include <linux/sysctl.h>
51735 +#include <linux/netdevice.h>
51736 +#include <linux/ptrace.h>
51737 +#include <linux/gracl.h>
51738 +#include <linux/gralloc.h>
51739 +#include <linux/security.h>
51740 +#include <linux/grinternal.h>
51741 +#include <linux/pid_namespace.h>
51742 +#include <linux/stop_machine.h>
51743 +#include <linux/fdtable.h>
51744 +#include <linux/percpu.h>
51745 +#include <linux/lglock.h>
51746 +#include "../fs/mount.h"
51747 +
51748 +#include <asm/uaccess.h>
51749 +#include <asm/errno.h>
51750 +#include <asm/mman.h>
51751 +
51752 +extern struct lglock vfsmount_lock;
51753 +
51754 +static struct acl_role_db acl_role_set;
51755 +static struct name_db name_set;
51756 +static struct inodev_db inodev_set;
51757 +
51758 +/* for keeping track of userspace pointers used for subjects, so we
51759 + can share references in the kernel as well
51760 +*/
51761 +
51762 +static struct path real_root;
51763 +
51764 +static struct acl_subj_map_db subj_map_set;
51765 +
51766 +static struct acl_role_label *default_role;
51767 +
51768 +static struct acl_role_label *role_list;
51769 +
51770 +static u16 acl_sp_role_value;
51771 +
51772 +extern char *gr_shared_page[4];
51773 +static DEFINE_MUTEX(gr_dev_mutex);
51774 +DEFINE_RWLOCK(gr_inode_lock);
51775 +
51776 +struct gr_arg *gr_usermode;
51777 +
51778 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
51779 +
51780 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
51781 +extern void gr_clear_learn_entries(void);
51782 +
51783 +#ifdef CONFIG_GRKERNSEC_RESLOG
51784 +extern void gr_log_resource(const struct task_struct *task,
51785 + const int res, const unsigned long wanted, const int gt);
51786 +#endif
51787 +
51788 +unsigned char *gr_system_salt;
51789 +unsigned char *gr_system_sum;
51790 +
51791 +static struct sprole_pw **acl_special_roles = NULL;
51792 +static __u16 num_sprole_pws = 0;
51793 +
51794 +static struct acl_role_label *kernel_role = NULL;
51795 +
51796 +static unsigned int gr_auth_attempts = 0;
51797 +static unsigned long gr_auth_expires = 0UL;
51798 +
51799 +#ifdef CONFIG_NET
51800 +extern struct vfsmount *sock_mnt;
51801 +#endif
51802 +
51803 +extern struct vfsmount *pipe_mnt;
51804 +extern struct vfsmount *shm_mnt;
51805 +#ifdef CONFIG_HUGETLBFS
51806 +extern struct vfsmount *hugetlbfs_vfsmount;
51807 +#endif
51808 +
51809 +static struct acl_object_label *fakefs_obj_rw;
51810 +static struct acl_object_label *fakefs_obj_rwx;
51811 +
51812 +extern int gr_init_uidset(void);
51813 +extern void gr_free_uidset(void);
51814 +extern void gr_remove_uid(uid_t uid);
51815 +extern int gr_find_uid(uid_t uid);
51816 +
51817 +__inline__ int
51818 +gr_acl_is_enabled(void)
51819 +{
51820 + return (gr_status & GR_READY);
51821 +}
51822 +
51823 +#ifdef CONFIG_BTRFS_FS
51824 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
51825 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
51826 +#endif
51827 +
51828 +static inline dev_t __get_dev(const struct dentry *dentry)
51829 +{
51830 +#ifdef CONFIG_BTRFS_FS
51831 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
51832 + return get_btrfs_dev_from_inode(dentry->d_inode);
51833 + else
51834 +#endif
51835 + return dentry->d_inode->i_sb->s_dev;
51836 +}
51837 +
51838 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
51839 +{
51840 + return __get_dev(dentry);
51841 +}
51842 +
51843 +static char gr_task_roletype_to_char(struct task_struct *task)
51844 +{
51845 + switch (task->role->roletype &
51846 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
51847 + GR_ROLE_SPECIAL)) {
51848 + case GR_ROLE_DEFAULT:
51849 + return 'D';
51850 + case GR_ROLE_USER:
51851 + return 'U';
51852 + case GR_ROLE_GROUP:
51853 + return 'G';
51854 + case GR_ROLE_SPECIAL:
51855 + return 'S';
51856 + }
51857 +
51858 + return 'X';
51859 +}
51860 +
51861 +char gr_roletype_to_char(void)
51862 +{
51863 + return gr_task_roletype_to_char(current);
51864 +}
51865 +
51866 +__inline__ int
51867 +gr_acl_tpe_check(void)
51868 +{
51869 + if (unlikely(!(gr_status & GR_READY)))
51870 + return 0;
51871 + if (current->role->roletype & GR_ROLE_TPE)
51872 + return 1;
51873 + else
51874 + return 0;
51875 +}
51876 +
51877 +int
51878 +gr_handle_rawio(const struct inode *inode)
51879 +{
51880 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
51881 + if (inode && S_ISBLK(inode->i_mode) &&
51882 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
51883 + !capable(CAP_SYS_RAWIO))
51884 + return 1;
51885 +#endif
51886 + return 0;
51887 +}
51888 +
51889 +static int
51890 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
51891 +{
51892 + if (likely(lena != lenb))
51893 + return 0;
51894 +
51895 + return !memcmp(a, b, lena);
51896 +}
51897 +
51898 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
51899 +{
51900 + *buflen -= namelen;
51901 + if (*buflen < 0)
51902 + return -ENAMETOOLONG;
51903 + *buffer -= namelen;
51904 + memcpy(*buffer, str, namelen);
51905 + return 0;
51906 +}
51907 +
51908 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
51909 +{
51910 + return prepend(buffer, buflen, name->name, name->len);
51911 +}
51912 +
51913 +static int prepend_path(const struct path *path, struct path *root,
51914 + char **buffer, int *buflen)
51915 +{
51916 + struct dentry *dentry = path->dentry;
51917 + struct vfsmount *vfsmnt = path->mnt;
51918 + struct mount *mnt = real_mount(vfsmnt);
51919 + bool slash = false;
51920 + int error = 0;
51921 +
51922 + while (dentry != root->dentry || vfsmnt != root->mnt) {
51923 + struct dentry * parent;
51924 +
51925 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
51926 + /* Global root? */
51927 + if (!mnt_has_parent(mnt)) {
51928 + goto out;
51929 + }
51930 + dentry = mnt->mnt_mountpoint;
51931 + mnt = mnt->mnt_parent;
51932 + vfsmnt = &mnt->mnt;
51933 + continue;
51934 + }
51935 + parent = dentry->d_parent;
51936 + prefetch(parent);
51937 + spin_lock(&dentry->d_lock);
51938 + error = prepend_name(buffer, buflen, &dentry->d_name);
51939 + spin_unlock(&dentry->d_lock);
51940 + if (!error)
51941 + error = prepend(buffer, buflen, "/", 1);
51942 + if (error)
51943 + break;
51944 +
51945 + slash = true;
51946 + dentry = parent;
51947 + }
51948 +
51949 +out:
51950 + if (!error && !slash)
51951 + error = prepend(buffer, buflen, "/", 1);
51952 +
51953 + return error;
51954 +}
51955 +
51956 +/* this must be called with vfsmount_lock and rename_lock held */
51957 +
51958 +static char *__our_d_path(const struct path *path, struct path *root,
51959 + char *buf, int buflen)
51960 +{
51961 + char *res = buf + buflen;
51962 + int error;
51963 +
51964 + prepend(&res, &buflen, "\0", 1);
51965 + error = prepend_path(path, root, &res, &buflen);
51966 + if (error)
51967 + return ERR_PTR(error);
51968 +
51969 + return res;
51970 +}
51971 +
51972 +static char *
51973 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
51974 +{
51975 + char *retval;
51976 +
51977 + retval = __our_d_path(path, root, buf, buflen);
51978 + if (unlikely(IS_ERR(retval)))
51979 + retval = strcpy(buf, "<path too long>");
51980 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
51981 + retval[1] = '\0';
51982 +
51983 + return retval;
51984 +}
51985 +
51986 +static char *
51987 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51988 + char *buf, int buflen)
51989 +{
51990 + struct path path;
51991 + char *res;
51992 +
51993 + path.dentry = (struct dentry *)dentry;
51994 + path.mnt = (struct vfsmount *)vfsmnt;
51995 +
51996 + /* we can use real_root.dentry, real_root.mnt, because this is only called
51997 + by the RBAC system */
51998 + res = gen_full_path(&path, &real_root, buf, buflen);
51999 +
52000 + return res;
52001 +}
52002 +
52003 +static char *
52004 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
52005 + char *buf, int buflen)
52006 +{
52007 + char *res;
52008 + struct path path;
52009 + struct path root;
52010 + struct task_struct *reaper = init_pid_ns.child_reaper;
52011 +
52012 + path.dentry = (struct dentry *)dentry;
52013 + path.mnt = (struct vfsmount *)vfsmnt;
52014 +
52015 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
52016 + get_fs_root(reaper->fs, &root);
52017 +
52018 + write_seqlock(&rename_lock);
52019 + br_read_lock(&vfsmount_lock);
52020 + res = gen_full_path(&path, &root, buf, buflen);
52021 + br_read_unlock(&vfsmount_lock);
52022 + write_sequnlock(&rename_lock);
52023 +
52024 + path_put(&root);
52025 + return res;
52026 +}
52027 +
52028 +static char *
52029 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
52030 +{
52031 + char *ret;
52032 + write_seqlock(&rename_lock);
52033 + br_read_lock(&vfsmount_lock);
52034 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
52035 + PAGE_SIZE);
52036 + br_read_unlock(&vfsmount_lock);
52037 + write_sequnlock(&rename_lock);
52038 + return ret;
52039 +}
52040 +
52041 +static char *
52042 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
52043 +{
52044 + char *ret;
52045 + char *buf;
52046 + int buflen;
52047 +
52048 + write_seqlock(&rename_lock);
52049 + br_read_lock(&vfsmount_lock);
52050 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
52051 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
52052 + buflen = (int)(ret - buf);
52053 + if (buflen >= 5)
52054 + prepend(&ret, &buflen, "/proc", 5);
52055 + else
52056 + ret = strcpy(buf, "<path too long>");
52057 + br_read_unlock(&vfsmount_lock);
52058 + write_sequnlock(&rename_lock);
52059 + return ret;
52060 +}
52061 +
52062 +char *
52063 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
52064 +{
52065 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
52066 + PAGE_SIZE);
52067 +}
52068 +
52069 +char *
52070 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
52071 +{
52072 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
52073 + PAGE_SIZE);
52074 +}
52075 +
52076 +char *
52077 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
52078 +{
52079 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
52080 + PAGE_SIZE);
52081 +}
52082 +
52083 +char *
52084 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
52085 +{
52086 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
52087 + PAGE_SIZE);
52088 +}
52089 +
52090 +char *
52091 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
52092 +{
52093 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
52094 + PAGE_SIZE);
52095 +}
52096 +
52097 +__inline__ __u32
52098 +to_gr_audit(const __u32 reqmode)
52099 +{
52100 + /* masks off auditable permission flags, then shifts them to create
52101 + auditing flags, and adds the special case of append auditing if
52102 + we're requesting write */
52103 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
52104 +}
52105 +
52106 +struct acl_subject_label *
52107 +lookup_subject_map(const struct acl_subject_label *userp)
52108 +{
52109 + unsigned int index = shash(userp, subj_map_set.s_size);
52110 + struct subject_map *match;
52111 +
52112 + match = subj_map_set.s_hash[index];
52113 +
52114 + while (match && match->user != userp)
52115 + match = match->next;
52116 +
52117 + if (match != NULL)
52118 + return match->kernel;
52119 + else
52120 + return NULL;
52121 +}
52122 +
52123 +static void
52124 +insert_subj_map_entry(struct subject_map *subjmap)
52125 +{
52126 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
52127 + struct subject_map **curr;
52128 +
52129 + subjmap->prev = NULL;
52130 +
52131 + curr = &subj_map_set.s_hash[index];
52132 + if (*curr != NULL)
52133 + (*curr)->prev = subjmap;
52134 +
52135 + subjmap->next = *curr;
52136 + *curr = subjmap;
52137 +
52138 + return;
52139 +}
52140 +
52141 +static struct acl_role_label *
52142 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
52143 + const gid_t gid)
52144 +{
52145 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
52146 + struct acl_role_label *match;
52147 + struct role_allowed_ip *ipp;
52148 + unsigned int x;
52149 + u32 curr_ip = task->signal->curr_ip;
52150 +
52151 + task->signal->saved_ip = curr_ip;
52152 +
52153 + match = acl_role_set.r_hash[index];
52154 +
52155 + while (match) {
52156 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
52157 + for (x = 0; x < match->domain_child_num; x++) {
52158 + if (match->domain_children[x] == uid)
52159 + goto found;
52160 + }
52161 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
52162 + break;
52163 + match = match->next;
52164 + }
52165 +found:
52166 + if (match == NULL) {
52167 + try_group:
52168 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
52169 + match = acl_role_set.r_hash[index];
52170 +
52171 + while (match) {
52172 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
52173 + for (x = 0; x < match->domain_child_num; x++) {
52174 + if (match->domain_children[x] == gid)
52175 + goto found2;
52176 + }
52177 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
52178 + break;
52179 + match = match->next;
52180 + }
52181 +found2:
52182 + if (match == NULL)
52183 + match = default_role;
52184 + if (match->allowed_ips == NULL)
52185 + return match;
52186 + else {
52187 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52188 + if (likely
52189 + ((ntohl(curr_ip) & ipp->netmask) ==
52190 + (ntohl(ipp->addr) & ipp->netmask)))
52191 + return match;
52192 + }
52193 + match = default_role;
52194 + }
52195 + } else if (match->allowed_ips == NULL) {
52196 + return match;
52197 + } else {
52198 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52199 + if (likely
52200 + ((ntohl(curr_ip) & ipp->netmask) ==
52201 + (ntohl(ipp->addr) & ipp->netmask)))
52202 + return match;
52203 + }
52204 + goto try_group;
52205 + }
52206 +
52207 + return match;
52208 +}
52209 +
52210 +struct acl_subject_label *
52211 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
52212 + const struct acl_role_label *role)
52213 +{
52214 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
52215 + struct acl_subject_label *match;
52216 +
52217 + match = role->subj_hash[index];
52218 +
52219 + while (match && (match->inode != ino || match->device != dev ||
52220 + (match->mode & GR_DELETED))) {
52221 + match = match->next;
52222 + }
52223 +
52224 + if (match && !(match->mode & GR_DELETED))
52225 + return match;
52226 + else
52227 + return NULL;
52228 +}
52229 +
52230 +struct acl_subject_label *
52231 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
52232 + const struct acl_role_label *role)
52233 +{
52234 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
52235 + struct acl_subject_label *match;
52236 +
52237 + match = role->subj_hash[index];
52238 +
52239 + while (match && (match->inode != ino || match->device != dev ||
52240 + !(match->mode & GR_DELETED))) {
52241 + match = match->next;
52242 + }
52243 +
52244 + if (match && (match->mode & GR_DELETED))
52245 + return match;
52246 + else
52247 + return NULL;
52248 +}
52249 +
52250 +static struct acl_object_label *
52251 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
52252 + const struct acl_subject_label *subj)
52253 +{
52254 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
52255 + struct acl_object_label *match;
52256 +
52257 + match = subj->obj_hash[index];
52258 +
52259 + while (match && (match->inode != ino || match->device != dev ||
52260 + (match->mode & GR_DELETED))) {
52261 + match = match->next;
52262 + }
52263 +
52264 + if (match && !(match->mode & GR_DELETED))
52265 + return match;
52266 + else
52267 + return NULL;
52268 +}
52269 +
52270 +static struct acl_object_label *
52271 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
52272 + const struct acl_subject_label *subj)
52273 +{
52274 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
52275 + struct acl_object_label *match;
52276 +
52277 + match = subj->obj_hash[index];
52278 +
52279 + while (match && (match->inode != ino || match->device != dev ||
52280 + !(match->mode & GR_DELETED))) {
52281 + match = match->next;
52282 + }
52283 +
52284 + if (match && (match->mode & GR_DELETED))
52285 + return match;
52286 +
52287 + match = subj->obj_hash[index];
52288 +
52289 + while (match && (match->inode != ino || match->device != dev ||
52290 + (match->mode & GR_DELETED))) {
52291 + match = match->next;
52292 + }
52293 +
52294 + if (match && !(match->mode & GR_DELETED))
52295 + return match;
52296 + else
52297 + return NULL;
52298 +}
52299 +
52300 +static struct name_entry *
52301 +lookup_name_entry(const char *name)
52302 +{
52303 + unsigned int len = strlen(name);
52304 + unsigned int key = full_name_hash(name, len);
52305 + unsigned int index = key % name_set.n_size;
52306 + struct name_entry *match;
52307 +
52308 + match = name_set.n_hash[index];
52309 +
52310 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
52311 + match = match->next;
52312 +
52313 + return match;
52314 +}
52315 +
52316 +static struct name_entry *
52317 +lookup_name_entry_create(const char *name)
52318 +{
52319 + unsigned int len = strlen(name);
52320 + unsigned int key = full_name_hash(name, len);
52321 + unsigned int index = key % name_set.n_size;
52322 + struct name_entry *match;
52323 +
52324 + match = name_set.n_hash[index];
52325 +
52326 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52327 + !match->deleted))
52328 + match = match->next;
52329 +
52330 + if (match && match->deleted)
52331 + return match;
52332 +
52333 + match = name_set.n_hash[index];
52334 +
52335 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52336 + match->deleted))
52337 + match = match->next;
52338 +
52339 + if (match && !match->deleted)
52340 + return match;
52341 + else
52342 + return NULL;
52343 +}
52344 +
52345 +static struct inodev_entry *
52346 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
52347 +{
52348 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
52349 + struct inodev_entry *match;
52350 +
52351 + match = inodev_set.i_hash[index];
52352 +
52353 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
52354 + match = match->next;
52355 +
52356 + return match;
52357 +}
52358 +
52359 +static void
52360 +insert_inodev_entry(struct inodev_entry *entry)
52361 +{
52362 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
52363 + inodev_set.i_size);
52364 + struct inodev_entry **curr;
52365 +
52366 + entry->prev = NULL;
52367 +
52368 + curr = &inodev_set.i_hash[index];
52369 + if (*curr != NULL)
52370 + (*curr)->prev = entry;
52371 +
52372 + entry->next = *curr;
52373 + *curr = entry;
52374 +
52375 + return;
52376 +}
52377 +
52378 +static void
52379 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
52380 +{
52381 + unsigned int index =
52382 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
52383 + struct acl_role_label **curr;
52384 + struct acl_role_label *tmp, *tmp2;
52385 +
52386 + curr = &acl_role_set.r_hash[index];
52387 +
52388 + /* simple case, slot is empty, just set it to our role */
52389 + if (*curr == NULL) {
52390 + *curr = role;
52391 + } else {
52392 + /* example:
52393 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
52394 + 2 -> 3
52395 + */
52396 + /* first check to see if we can already be reached via this slot */
52397 + tmp = *curr;
52398 + while (tmp && tmp != role)
52399 + tmp = tmp->next;
52400 + if (tmp == role) {
52401 + /* we don't need to add ourselves to this slot's chain */
52402 + return;
52403 + }
52404 + /* we need to add ourselves to this chain, two cases */
52405 + if (role->next == NULL) {
52406 + /* simple case, append the current chain to our role */
52407 + role->next = *curr;
52408 + *curr = role;
52409 + } else {
52410 + /* 1 -> 2 -> 3 -> 4
52411 + 2 -> 3 -> 4
52412 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
52413 + */
52414 + /* trickier case: walk our role's chain until we find
52415 + the role for the start of the current slot's chain */
52416 + tmp = role;
52417 + tmp2 = *curr;
52418 + while (tmp->next && tmp->next != tmp2)
52419 + tmp = tmp->next;
52420 + if (tmp->next == tmp2) {
52421 + /* from example above, we found 3, so just
52422 + replace this slot's chain with ours */
52423 + *curr = role;
52424 + } else {
52425 + /* we didn't find a subset of our role's chain
52426 + in the current slot's chain, so append their
52427 + chain to ours, and set us as the first role in
52428 + the slot's chain
52429 +
52430 + we could fold this case with the case above,
52431 + but making it explicit for clarity
52432 + */
52433 + tmp->next = tmp2;
52434 + *curr = role;
52435 + }
52436 + }
52437 + }
52438 +
52439 + return;
52440 +}
52441 +
52442 +static void
52443 +insert_acl_role_label(struct acl_role_label *role)
52444 +{
52445 + int i;
52446 +
52447 + if (role_list == NULL) {
52448 + role_list = role;
52449 + role->prev = NULL;
52450 + } else {
52451 + role->prev = role_list;
52452 + role_list = role;
52453 + }
52454 +
52455 + /* used for hash chains */
52456 + role->next = NULL;
52457 +
52458 + if (role->roletype & GR_ROLE_DOMAIN) {
52459 + for (i = 0; i < role->domain_child_num; i++)
52460 + __insert_acl_role_label(role, role->domain_children[i]);
52461 + } else
52462 + __insert_acl_role_label(role, role->uidgid);
52463 +}
52464 +
52465 +static int
52466 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
52467 +{
52468 + struct name_entry **curr, *nentry;
52469 + struct inodev_entry *ientry;
52470 + unsigned int len = strlen(name);
52471 + unsigned int key = full_name_hash(name, len);
52472 + unsigned int index = key % name_set.n_size;
52473 +
52474 + curr = &name_set.n_hash[index];
52475 +
52476 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
52477 + curr = &((*curr)->next);
52478 +
52479 + if (*curr != NULL)
52480 + return 1;
52481 +
52482 + nentry = acl_alloc(sizeof (struct name_entry));
52483 + if (nentry == NULL)
52484 + return 0;
52485 + ientry = acl_alloc(sizeof (struct inodev_entry));
52486 + if (ientry == NULL)
52487 + return 0;
52488 + ientry->nentry = nentry;
52489 +
52490 + nentry->key = key;
52491 + nentry->name = name;
52492 + nentry->inode = inode;
52493 + nentry->device = device;
52494 + nentry->len = len;
52495 + nentry->deleted = deleted;
52496 +
52497 + nentry->prev = NULL;
52498 + curr = &name_set.n_hash[index];
52499 + if (*curr != NULL)
52500 + (*curr)->prev = nentry;
52501 + nentry->next = *curr;
52502 + *curr = nentry;
52503 +
52504 + /* insert us into the table searchable by inode/dev */
52505 + insert_inodev_entry(ientry);
52506 +
52507 + return 1;
52508 +}
52509 +
52510 +static void
52511 +insert_acl_obj_label(struct acl_object_label *obj,
52512 + struct acl_subject_label *subj)
52513 +{
52514 + unsigned int index =
52515 + fhash(obj->inode, obj->device, subj->obj_hash_size);
52516 + struct acl_object_label **curr;
52517 +
52518 +
52519 + obj->prev = NULL;
52520 +
52521 + curr = &subj->obj_hash[index];
52522 + if (*curr != NULL)
52523 + (*curr)->prev = obj;
52524 +
52525 + obj->next = *curr;
52526 + *curr = obj;
52527 +
52528 + return;
52529 +}
52530 +
52531 +static void
52532 +insert_acl_subj_label(struct acl_subject_label *obj,
52533 + struct acl_role_label *role)
52534 +{
52535 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
52536 + struct acl_subject_label **curr;
52537 +
52538 + obj->prev = NULL;
52539 +
52540 + curr = &role->subj_hash[index];
52541 + if (*curr != NULL)
52542 + (*curr)->prev = obj;
52543 +
52544 + obj->next = *curr;
52545 + *curr = obj;
52546 +
52547 + return;
52548 +}
52549 +
52550 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
52551 +
52552 +static void *
52553 +create_table(__u32 * len, int elementsize)
52554 +{
52555 + unsigned int table_sizes[] = {
52556 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
52557 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
52558 + 4194301, 8388593, 16777213, 33554393, 67108859
52559 + };
52560 + void *newtable = NULL;
52561 + unsigned int pwr = 0;
52562 +
52563 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
52564 + table_sizes[pwr] <= *len)
52565 + pwr++;
52566 +
52567 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
52568 + return newtable;
52569 +
52570 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
52571 + newtable =
52572 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
52573 + else
52574 + newtable = vmalloc(table_sizes[pwr] * elementsize);
52575 +
52576 + *len = table_sizes[pwr];
52577 +
52578 + return newtable;
52579 +}
52580 +
52581 +static int
52582 +init_variables(const struct gr_arg *arg)
52583 +{
52584 + struct task_struct *reaper = init_pid_ns.child_reaper;
52585 + unsigned int stacksize;
52586 +
52587 + subj_map_set.s_size = arg->role_db.num_subjects;
52588 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
52589 + name_set.n_size = arg->role_db.num_objects;
52590 + inodev_set.i_size = arg->role_db.num_objects;
52591 +
52592 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
52593 + !name_set.n_size || !inodev_set.i_size)
52594 + return 1;
52595 +
52596 + if (!gr_init_uidset())
52597 + return 1;
52598 +
52599 + /* set up the stack that holds allocation info */
52600 +
52601 + stacksize = arg->role_db.num_pointers + 5;
52602 +
52603 + if (!acl_alloc_stack_init(stacksize))
52604 + return 1;
52605 +
52606 + /* grab reference for the real root dentry and vfsmount */
52607 + get_fs_root(reaper->fs, &real_root);
52608 +
52609 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52610 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
52611 +#endif
52612 +
52613 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
52614 + if (fakefs_obj_rw == NULL)
52615 + return 1;
52616 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
52617 +
52618 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
52619 + if (fakefs_obj_rwx == NULL)
52620 + return 1;
52621 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
52622 +
52623 + subj_map_set.s_hash =
52624 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
52625 + acl_role_set.r_hash =
52626 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
52627 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
52628 + inodev_set.i_hash =
52629 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
52630 +
52631 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
52632 + !name_set.n_hash || !inodev_set.i_hash)
52633 + return 1;
52634 +
52635 + memset(subj_map_set.s_hash, 0,
52636 + sizeof(struct subject_map *) * subj_map_set.s_size);
52637 + memset(acl_role_set.r_hash, 0,
52638 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
52639 + memset(name_set.n_hash, 0,
52640 + sizeof (struct name_entry *) * name_set.n_size);
52641 + memset(inodev_set.i_hash, 0,
52642 + sizeof (struct inodev_entry *) * inodev_set.i_size);
52643 +
52644 + return 0;
52645 +}
52646 +
52647 +/* free information not needed after startup
52648 + currently contains user->kernel pointer mappings for subjects
52649 +*/
52650 +
52651 +static void
52652 +free_init_variables(void)
52653 +{
52654 + __u32 i;
52655 +
52656 + if (subj_map_set.s_hash) {
52657 + for (i = 0; i < subj_map_set.s_size; i++) {
52658 + if (subj_map_set.s_hash[i]) {
52659 + kfree(subj_map_set.s_hash[i]);
52660 + subj_map_set.s_hash[i] = NULL;
52661 + }
52662 + }
52663 +
52664 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
52665 + PAGE_SIZE)
52666 + kfree(subj_map_set.s_hash);
52667 + else
52668 + vfree(subj_map_set.s_hash);
52669 + }
52670 +
52671 + return;
52672 +}
52673 +
52674 +static void
52675 +free_variables(void)
52676 +{
52677 + struct acl_subject_label *s;
52678 + struct acl_role_label *r;
52679 + struct task_struct *task, *task2;
52680 + unsigned int x;
52681 +
52682 + gr_clear_learn_entries();
52683 +
52684 + read_lock(&tasklist_lock);
52685 + do_each_thread(task2, task) {
52686 + task->acl_sp_role = 0;
52687 + task->acl_role_id = 0;
52688 + task->acl = NULL;
52689 + task->role = NULL;
52690 + } while_each_thread(task2, task);
52691 + read_unlock(&tasklist_lock);
52692 +
52693 + /* release the reference to the real root dentry and vfsmount */
52694 + path_put(&real_root);
52695 + memset(&real_root, 0, sizeof(real_root));
52696 +
52697 + /* free all object hash tables */
52698 +
52699 + FOR_EACH_ROLE_START(r)
52700 + if (r->subj_hash == NULL)
52701 + goto next_role;
52702 + FOR_EACH_SUBJECT_START(r, s, x)
52703 + if (s->obj_hash == NULL)
52704 + break;
52705 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52706 + kfree(s->obj_hash);
52707 + else
52708 + vfree(s->obj_hash);
52709 + FOR_EACH_SUBJECT_END(s, x)
52710 + FOR_EACH_NESTED_SUBJECT_START(r, s)
52711 + if (s->obj_hash == NULL)
52712 + break;
52713 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52714 + kfree(s->obj_hash);
52715 + else
52716 + vfree(s->obj_hash);
52717 + FOR_EACH_NESTED_SUBJECT_END(s)
52718 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
52719 + kfree(r->subj_hash);
52720 + else
52721 + vfree(r->subj_hash);
52722 + r->subj_hash = NULL;
52723 +next_role:
52724 + FOR_EACH_ROLE_END(r)
52725 +
52726 + acl_free_all();
52727 +
52728 + if (acl_role_set.r_hash) {
52729 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
52730 + PAGE_SIZE)
52731 + kfree(acl_role_set.r_hash);
52732 + else
52733 + vfree(acl_role_set.r_hash);
52734 + }
52735 + if (name_set.n_hash) {
52736 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
52737 + PAGE_SIZE)
52738 + kfree(name_set.n_hash);
52739 + else
52740 + vfree(name_set.n_hash);
52741 + }
52742 +
52743 + if (inodev_set.i_hash) {
52744 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
52745 + PAGE_SIZE)
52746 + kfree(inodev_set.i_hash);
52747 + else
52748 + vfree(inodev_set.i_hash);
52749 + }
52750 +
52751 + gr_free_uidset();
52752 +
52753 + memset(&name_set, 0, sizeof (struct name_db));
52754 + memset(&inodev_set, 0, sizeof (struct inodev_db));
52755 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
52756 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
52757 +
52758 + default_role = NULL;
52759 + kernel_role = NULL;
52760 + role_list = NULL;
52761 +
52762 + return;
52763 +}
52764 +
52765 +static __u32
52766 +count_user_objs(struct acl_object_label *userp)
52767 +{
52768 + struct acl_object_label o_tmp;
52769 + __u32 num = 0;
52770 +
52771 + while (userp) {
52772 + if (copy_from_user(&o_tmp, userp,
52773 + sizeof (struct acl_object_label)))
52774 + break;
52775 +
52776 + userp = o_tmp.prev;
52777 + num++;
52778 + }
52779 +
52780 + return num;
52781 +}
52782 +
52783 +static struct acl_subject_label *
52784 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
52785 +
52786 +static int
52787 +copy_user_glob(struct acl_object_label *obj)
52788 +{
52789 + struct acl_object_label *g_tmp, **guser;
52790 + unsigned int len;
52791 + char *tmp;
52792 +
52793 + if (obj->globbed == NULL)
52794 + return 0;
52795 +
52796 + guser = &obj->globbed;
52797 + while (*guser) {
52798 + g_tmp = (struct acl_object_label *)
52799 + acl_alloc(sizeof (struct acl_object_label));
52800 + if (g_tmp == NULL)
52801 + return -ENOMEM;
52802 +
52803 + if (copy_from_user(g_tmp, *guser,
52804 + sizeof (struct acl_object_label)))
52805 + return -EFAULT;
52806 +
52807 + len = strnlen_user(g_tmp->filename, PATH_MAX);
52808 +
52809 + if (!len || len >= PATH_MAX)
52810 + return -EINVAL;
52811 +
52812 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52813 + return -ENOMEM;
52814 +
52815 + if (copy_from_user(tmp, g_tmp->filename, len))
52816 + return -EFAULT;
52817 + tmp[len-1] = '\0';
52818 + g_tmp->filename = tmp;
52819 +
52820 + *guser = g_tmp;
52821 + guser = &(g_tmp->next);
52822 + }
52823 +
52824 + return 0;
52825 +}
52826 +
52827 +static int
52828 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
52829 + struct acl_role_label *role)
52830 +{
52831 + struct acl_object_label *o_tmp;
52832 + unsigned int len;
52833 + int ret;
52834 + char *tmp;
52835 +
52836 + while (userp) {
52837 + if ((o_tmp = (struct acl_object_label *)
52838 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
52839 + return -ENOMEM;
52840 +
52841 + if (copy_from_user(o_tmp, userp,
52842 + sizeof (struct acl_object_label)))
52843 + return -EFAULT;
52844 +
52845 + userp = o_tmp->prev;
52846 +
52847 + len = strnlen_user(o_tmp->filename, PATH_MAX);
52848 +
52849 + if (!len || len >= PATH_MAX)
52850 + return -EINVAL;
52851 +
52852 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52853 + return -ENOMEM;
52854 +
52855 + if (copy_from_user(tmp, o_tmp->filename, len))
52856 + return -EFAULT;
52857 + tmp[len-1] = '\0';
52858 + o_tmp->filename = tmp;
52859 +
52860 + insert_acl_obj_label(o_tmp, subj);
52861 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
52862 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
52863 + return -ENOMEM;
52864 +
52865 + ret = copy_user_glob(o_tmp);
52866 + if (ret)
52867 + return ret;
52868 +
52869 + if (o_tmp->nested) {
52870 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
52871 + if (IS_ERR(o_tmp->nested))
52872 + return PTR_ERR(o_tmp->nested);
52873 +
52874 + /* insert into nested subject list */
52875 + o_tmp->nested->next = role->hash->first;
52876 + role->hash->first = o_tmp->nested;
52877 + }
52878 + }
52879 +
52880 + return 0;
52881 +}
52882 +
52883 +static __u32
52884 +count_user_subjs(struct acl_subject_label *userp)
52885 +{
52886 + struct acl_subject_label s_tmp;
52887 + __u32 num = 0;
52888 +
52889 + while (userp) {
52890 + if (copy_from_user(&s_tmp, userp,
52891 + sizeof (struct acl_subject_label)))
52892 + break;
52893 +
52894 + userp = s_tmp.prev;
52895 + /* do not count nested subjects against this count, since
52896 + they are not included in the hash table, but are
52897 + attached to objects. We have already counted
52898 + the subjects in userspace for the allocation
52899 + stack
52900 + */
52901 + if (!(s_tmp.mode & GR_NESTED))
52902 + num++;
52903 + }
52904 +
52905 + return num;
52906 +}
52907 +
52908 +static int
52909 +copy_user_allowedips(struct acl_role_label *rolep)
52910 +{
52911 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
52912 +
52913 + ruserip = rolep->allowed_ips;
52914 +
52915 + while (ruserip) {
52916 + rlast = rtmp;
52917 +
52918 + if ((rtmp = (struct role_allowed_ip *)
52919 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
52920 + return -ENOMEM;
52921 +
52922 + if (copy_from_user(rtmp, ruserip,
52923 + sizeof (struct role_allowed_ip)))
52924 + return -EFAULT;
52925 +
52926 + ruserip = rtmp->prev;
52927 +
52928 + if (!rlast) {
52929 + rtmp->prev = NULL;
52930 + rolep->allowed_ips = rtmp;
52931 + } else {
52932 + rlast->next = rtmp;
52933 + rtmp->prev = rlast;
52934 + }
52935 +
52936 + if (!ruserip)
52937 + rtmp->next = NULL;
52938 + }
52939 +
52940 + return 0;
52941 +}
52942 +
52943 +static int
52944 +copy_user_transitions(struct acl_role_label *rolep)
52945 +{
52946 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
52947 +
52948 + unsigned int len;
52949 + char *tmp;
52950 +
52951 + rusertp = rolep->transitions;
52952 +
52953 + while (rusertp) {
52954 + rlast = rtmp;
52955 +
52956 + if ((rtmp = (struct role_transition *)
52957 + acl_alloc(sizeof (struct role_transition))) == NULL)
52958 + return -ENOMEM;
52959 +
52960 + if (copy_from_user(rtmp, rusertp,
52961 + sizeof (struct role_transition)))
52962 + return -EFAULT;
52963 +
52964 + rusertp = rtmp->prev;
52965 +
52966 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
52967 +
52968 + if (!len || len >= GR_SPROLE_LEN)
52969 + return -EINVAL;
52970 +
52971 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52972 + return -ENOMEM;
52973 +
52974 + if (copy_from_user(tmp, rtmp->rolename, len))
52975 + return -EFAULT;
52976 + tmp[len-1] = '\0';
52977 + rtmp->rolename = tmp;
52978 +
52979 + if (!rlast) {
52980 + rtmp->prev = NULL;
52981 + rolep->transitions = rtmp;
52982 + } else {
52983 + rlast->next = rtmp;
52984 + rtmp->prev = rlast;
52985 + }
52986 +
52987 + if (!rusertp)
52988 + rtmp->next = NULL;
52989 + }
52990 +
52991 + return 0;
52992 +}
52993 +
52994 +static struct acl_subject_label *
52995 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
52996 +{
52997 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
52998 + unsigned int len;
52999 + char *tmp;
53000 + __u32 num_objs;
53001 + struct acl_ip_label **i_tmp, *i_utmp2;
53002 + struct gr_hash_struct ghash;
53003 + struct subject_map *subjmap;
53004 + unsigned int i_num;
53005 + int err;
53006 +
53007 + s_tmp = lookup_subject_map(userp);
53008 +
53009 + /* we've already copied this subject into the kernel, just return
53010 + the reference to it, and don't copy it over again
53011 + */
53012 + if (s_tmp)
53013 + return(s_tmp);
53014 +
53015 + if ((s_tmp = (struct acl_subject_label *)
53016 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
53017 + return ERR_PTR(-ENOMEM);
53018 +
53019 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
53020 + if (subjmap == NULL)
53021 + return ERR_PTR(-ENOMEM);
53022 +
53023 + subjmap->user = userp;
53024 + subjmap->kernel = s_tmp;
53025 + insert_subj_map_entry(subjmap);
53026 +
53027 + if (copy_from_user(s_tmp, userp,
53028 + sizeof (struct acl_subject_label)))
53029 + return ERR_PTR(-EFAULT);
53030 +
53031 + len = strnlen_user(s_tmp->filename, PATH_MAX);
53032 +
53033 + if (!len || len >= PATH_MAX)
53034 + return ERR_PTR(-EINVAL);
53035 +
53036 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53037 + return ERR_PTR(-ENOMEM);
53038 +
53039 + if (copy_from_user(tmp, s_tmp->filename, len))
53040 + return ERR_PTR(-EFAULT);
53041 + tmp[len-1] = '\0';
53042 + s_tmp->filename = tmp;
53043 +
53044 + if (!strcmp(s_tmp->filename, "/"))
53045 + role->root_label = s_tmp;
53046 +
53047 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
53048 + return ERR_PTR(-EFAULT);
53049 +
53050 + /* copy user and group transition tables */
53051 +
53052 + if (s_tmp->user_trans_num) {
53053 + uid_t *uidlist;
53054 +
53055 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
53056 + if (uidlist == NULL)
53057 + return ERR_PTR(-ENOMEM);
53058 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
53059 + return ERR_PTR(-EFAULT);
53060 +
53061 + s_tmp->user_transitions = uidlist;
53062 + }
53063 +
53064 + if (s_tmp->group_trans_num) {
53065 + gid_t *gidlist;
53066 +
53067 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
53068 + if (gidlist == NULL)
53069 + return ERR_PTR(-ENOMEM);
53070 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
53071 + return ERR_PTR(-EFAULT);
53072 +
53073 + s_tmp->group_transitions = gidlist;
53074 + }
53075 +
53076 + /* set up object hash table */
53077 + num_objs = count_user_objs(ghash.first);
53078 +
53079 + s_tmp->obj_hash_size = num_objs;
53080 + s_tmp->obj_hash =
53081 + (struct acl_object_label **)
53082 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
53083 +
53084 + if (!s_tmp->obj_hash)
53085 + return ERR_PTR(-ENOMEM);
53086 +
53087 + memset(s_tmp->obj_hash, 0,
53088 + s_tmp->obj_hash_size *
53089 + sizeof (struct acl_object_label *));
53090 +
53091 + /* add in objects */
53092 + err = copy_user_objs(ghash.first, s_tmp, role);
53093 +
53094 + if (err)
53095 + return ERR_PTR(err);
53096 +
53097 + /* set pointer for parent subject */
53098 + if (s_tmp->parent_subject) {
53099 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
53100 +
53101 + if (IS_ERR(s_tmp2))
53102 + return s_tmp2;
53103 +
53104 + s_tmp->parent_subject = s_tmp2;
53105 + }
53106 +
53107 + /* add in ip acls */
53108 +
53109 + if (!s_tmp->ip_num) {
53110 + s_tmp->ips = NULL;
53111 + goto insert;
53112 + }
53113 +
53114 + i_tmp =
53115 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
53116 + sizeof (struct acl_ip_label *));
53117 +
53118 + if (!i_tmp)
53119 + return ERR_PTR(-ENOMEM);
53120 +
53121 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
53122 + *(i_tmp + i_num) =
53123 + (struct acl_ip_label *)
53124 + acl_alloc(sizeof (struct acl_ip_label));
53125 + if (!*(i_tmp + i_num))
53126 + return ERR_PTR(-ENOMEM);
53127 +
53128 + if (copy_from_user
53129 + (&i_utmp2, s_tmp->ips + i_num,
53130 + sizeof (struct acl_ip_label *)))
53131 + return ERR_PTR(-EFAULT);
53132 +
53133 + if (copy_from_user
53134 + (*(i_tmp + i_num), i_utmp2,
53135 + sizeof (struct acl_ip_label)))
53136 + return ERR_PTR(-EFAULT);
53137 +
53138 + if ((*(i_tmp + i_num))->iface == NULL)
53139 + continue;
53140 +
53141 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
53142 + if (!len || len >= IFNAMSIZ)
53143 + return ERR_PTR(-EINVAL);
53144 + tmp = acl_alloc(len);
53145 + if (tmp == NULL)
53146 + return ERR_PTR(-ENOMEM);
53147 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
53148 + return ERR_PTR(-EFAULT);
53149 + (*(i_tmp + i_num))->iface = tmp;
53150 + }
53151 +
53152 + s_tmp->ips = i_tmp;
53153 +
53154 +insert:
53155 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
53156 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
53157 + return ERR_PTR(-ENOMEM);
53158 +
53159 + return s_tmp;
53160 +}
53161 +
53162 +static int
53163 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
53164 +{
53165 + struct acl_subject_label s_pre;
53166 + struct acl_subject_label * ret;
53167 + int err;
53168 +
53169 + while (userp) {
53170 + if (copy_from_user(&s_pre, userp,
53171 + sizeof (struct acl_subject_label)))
53172 + return -EFAULT;
53173 +
53174 + /* do not add nested subjects here, add
53175 + while parsing objects
53176 + */
53177 +
53178 + if (s_pre.mode & GR_NESTED) {
53179 + userp = s_pre.prev;
53180 + continue;
53181 + }
53182 +
53183 + ret = do_copy_user_subj(userp, role);
53184 +
53185 + err = PTR_ERR(ret);
53186 + if (IS_ERR(ret))
53187 + return err;
53188 +
53189 + insert_acl_subj_label(ret, role);
53190 +
53191 + userp = s_pre.prev;
53192 + }
53193 +
53194 + return 0;
53195 +}
53196 +
53197 +static int
53198 +copy_user_acl(struct gr_arg *arg)
53199 +{
53200 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
53201 + struct acl_subject_label *subj_list;
53202 + struct sprole_pw *sptmp;
53203 + struct gr_hash_struct *ghash;
53204 + uid_t *domainlist;
53205 + unsigned int r_num;
53206 + unsigned int len;
53207 + char *tmp;
53208 + int err = 0;
53209 + __u16 i;
53210 + __u32 num_subjs;
53211 +
53212 + /* we need a default and kernel role */
53213 + if (arg->role_db.num_roles < 2)
53214 + return -EINVAL;
53215 +
53216 + /* copy special role authentication info from userspace */
53217 +
53218 + num_sprole_pws = arg->num_sprole_pws;
53219 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
53220 +
53221 + if (!acl_special_roles && num_sprole_pws)
53222 + return -ENOMEM;
53223 +
53224 + for (i = 0; i < num_sprole_pws; i++) {
53225 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
53226 + if (!sptmp)
53227 + return -ENOMEM;
53228 + if (copy_from_user(sptmp, arg->sprole_pws + i,
53229 + sizeof (struct sprole_pw)))
53230 + return -EFAULT;
53231 +
53232 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
53233 +
53234 + if (!len || len >= GR_SPROLE_LEN)
53235 + return -EINVAL;
53236 +
53237 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53238 + return -ENOMEM;
53239 +
53240 + if (copy_from_user(tmp, sptmp->rolename, len))
53241 + return -EFAULT;
53242 +
53243 + tmp[len-1] = '\0';
53244 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53245 + printk(KERN_ALERT "Copying special role %s\n", tmp);
53246 +#endif
53247 + sptmp->rolename = tmp;
53248 + acl_special_roles[i] = sptmp;
53249 + }
53250 +
53251 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
53252 +
53253 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
53254 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
53255 +
53256 + if (!r_tmp)
53257 + return -ENOMEM;
53258 +
53259 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
53260 + sizeof (struct acl_role_label *)))
53261 + return -EFAULT;
53262 +
53263 + if (copy_from_user(r_tmp, r_utmp2,
53264 + sizeof (struct acl_role_label)))
53265 + return -EFAULT;
53266 +
53267 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
53268 +
53269 + if (!len || len >= PATH_MAX)
53270 + return -EINVAL;
53271 +
53272 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53273 + return -ENOMEM;
53274 +
53275 + if (copy_from_user(tmp, r_tmp->rolename, len))
53276 + return -EFAULT;
53277 +
53278 + tmp[len-1] = '\0';
53279 + r_tmp->rolename = tmp;
53280 +
53281 + if (!strcmp(r_tmp->rolename, "default")
53282 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
53283 + default_role = r_tmp;
53284 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
53285 + kernel_role = r_tmp;
53286 + }
53287 +
53288 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
53289 + return -ENOMEM;
53290 +
53291 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
53292 + return -EFAULT;
53293 +
53294 + r_tmp->hash = ghash;
53295 +
53296 + num_subjs = count_user_subjs(r_tmp->hash->first);
53297 +
53298 + r_tmp->subj_hash_size = num_subjs;
53299 + r_tmp->subj_hash =
53300 + (struct acl_subject_label **)
53301 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
53302 +
53303 + if (!r_tmp->subj_hash)
53304 + return -ENOMEM;
53305 +
53306 + err = copy_user_allowedips(r_tmp);
53307 + if (err)
53308 + return err;
53309 +
53310 + /* copy domain info */
53311 + if (r_tmp->domain_children != NULL) {
53312 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
53313 + if (domainlist == NULL)
53314 + return -ENOMEM;
53315 +
53316 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
53317 + return -EFAULT;
53318 +
53319 + r_tmp->domain_children = domainlist;
53320 + }
53321 +
53322 + err = copy_user_transitions(r_tmp);
53323 + if (err)
53324 + return err;
53325 +
53326 + memset(r_tmp->subj_hash, 0,
53327 + r_tmp->subj_hash_size *
53328 + sizeof (struct acl_subject_label *));
53329 +
53330 + /* acquire the list of subjects, then NULL out
53331 + the list prior to parsing the subjects for this role,
53332 + as during this parsing the list is replaced with a list
53333 + of *nested* subjects for the role
53334 + */
53335 + subj_list = r_tmp->hash->first;
53336 +
53337 + /* set nested subject list to null */
53338 + r_tmp->hash->first = NULL;
53339 +
53340 + err = copy_user_subjs(subj_list, r_tmp);
53341 +
53342 + if (err)
53343 + return err;
53344 +
53345 + insert_acl_role_label(r_tmp);
53346 + }
53347 +
53348 + if (default_role == NULL || kernel_role == NULL)
53349 + return -EINVAL;
53350 +
53351 + return err;
53352 +}
53353 +
53354 +static int
53355 +gracl_init(struct gr_arg *args)
53356 +{
53357 + int error = 0;
53358 +
53359 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
53360 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
53361 +
53362 + if (init_variables(args)) {
53363 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
53364 + error = -ENOMEM;
53365 + free_variables();
53366 + goto out;
53367 + }
53368 +
53369 + error = copy_user_acl(args);
53370 + free_init_variables();
53371 + if (error) {
53372 + free_variables();
53373 + goto out;
53374 + }
53375 +
53376 + if ((error = gr_set_acls(0))) {
53377 + free_variables();
53378 + goto out;
53379 + }
53380 +
53381 + pax_open_kernel();
53382 + gr_status |= GR_READY;
53383 + pax_close_kernel();
53384 +
53385 + out:
53386 + return error;
53387 +}
53388 +
53389 +/* derived from glibc fnmatch() 0: match, 1: no match*/
53390 +
53391 +static int
53392 +glob_match(const char *p, const char *n)
53393 +{
53394 + char c;
53395 +
53396 + while ((c = *p++) != '\0') {
53397 + switch (c) {
53398 + case '?':
53399 + if (*n == '\0')
53400 + return 1;
53401 + else if (*n == '/')
53402 + return 1;
53403 + break;
53404 + case '\\':
53405 + if (*n != c)
53406 + return 1;
53407 + break;
53408 + case '*':
53409 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
53410 + if (*n == '/')
53411 + return 1;
53412 + else if (c == '?') {
53413 + if (*n == '\0')
53414 + return 1;
53415 + else
53416 + ++n;
53417 + }
53418 + }
53419 + if (c == '\0') {
53420 + return 0;
53421 + } else {
53422 + const char *endp;
53423 +
53424 + if ((endp = strchr(n, '/')) == NULL)
53425 + endp = n + strlen(n);
53426 +
53427 + if (c == '[') {
53428 + for (--p; n < endp; ++n)
53429 + if (!glob_match(p, n))
53430 + return 0;
53431 + } else if (c == '/') {
53432 + while (*n != '\0' && *n != '/')
53433 + ++n;
53434 + if (*n == '/' && !glob_match(p, n + 1))
53435 + return 0;
53436 + } else {
53437 + for (--p; n < endp; ++n)
53438 + if (*n == c && !glob_match(p, n))
53439 + return 0;
53440 + }
53441 +
53442 + return 1;
53443 + }
53444 + case '[':
53445 + {
53446 + int not;
53447 + char cold;
53448 +
53449 + if (*n == '\0' || *n == '/')
53450 + return 1;
53451 +
53452 + not = (*p == '!' || *p == '^');
53453 + if (not)
53454 + ++p;
53455 +
53456 + c = *p++;
53457 + for (;;) {
53458 + unsigned char fn = (unsigned char)*n;
53459 +
53460 + if (c == '\0')
53461 + return 1;
53462 + else {
53463 + if (c == fn)
53464 + goto matched;
53465 + cold = c;
53466 + c = *p++;
53467 +
53468 + if (c == '-' && *p != ']') {
53469 + unsigned char cend = *p++;
53470 +
53471 + if (cend == '\0')
53472 + return 1;
53473 +
53474 + if (cold <= fn && fn <= cend)
53475 + goto matched;
53476 +
53477 + c = *p++;
53478 + }
53479 + }
53480 +
53481 + if (c == ']')
53482 + break;
53483 + }
53484 + if (!not)
53485 + return 1;
53486 + break;
53487 + matched:
53488 + while (c != ']') {
53489 + if (c == '\0')
53490 + return 1;
53491 +
53492 + c = *p++;
53493 + }
53494 + if (not)
53495 + return 1;
53496 + }
53497 + break;
53498 + default:
53499 + if (c != *n)
53500 + return 1;
53501 + }
53502 +
53503 + ++n;
53504 + }
53505 +
53506 + if (*n == '\0')
53507 + return 0;
53508 +
53509 + if (*n == '/')
53510 + return 0;
53511 +
53512 + return 1;
53513 +}
53514 +
53515 +static struct acl_object_label *
53516 +chk_glob_label(struct acl_object_label *globbed,
53517 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
53518 +{
53519 + struct acl_object_label *tmp;
53520 +
53521 + if (*path == NULL)
53522 + *path = gr_to_filename_nolock(dentry, mnt);
53523 +
53524 + tmp = globbed;
53525 +
53526 + while (tmp) {
53527 + if (!glob_match(tmp->filename, *path))
53528 + return tmp;
53529 + tmp = tmp->next;
53530 + }
53531 +
53532 + return NULL;
53533 +}
53534 +
53535 +static struct acl_object_label *
53536 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53537 + const ino_t curr_ino, const dev_t curr_dev,
53538 + const struct acl_subject_label *subj, char **path, const int checkglob)
53539 +{
53540 + struct acl_subject_label *tmpsubj;
53541 + struct acl_object_label *retval;
53542 + struct acl_object_label *retval2;
53543 +
53544 + tmpsubj = (struct acl_subject_label *) subj;
53545 + read_lock(&gr_inode_lock);
53546 + do {
53547 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
53548 + if (retval) {
53549 + if (checkglob && retval->globbed) {
53550 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
53551 + if (retval2)
53552 + retval = retval2;
53553 + }
53554 + break;
53555 + }
53556 + } while ((tmpsubj = tmpsubj->parent_subject));
53557 + read_unlock(&gr_inode_lock);
53558 +
53559 + return retval;
53560 +}
53561 +
53562 +static __inline__ struct acl_object_label *
53563 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53564 + struct dentry *curr_dentry,
53565 + const struct acl_subject_label *subj, char **path, const int checkglob)
53566 +{
53567 + int newglob = checkglob;
53568 + ino_t inode;
53569 + dev_t device;
53570 +
53571 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
53572 + as we don't want a / * rule to match instead of the / object
53573 + don't do this for create lookups that call this function though, since they're looking up
53574 + on the parent and thus need globbing checks on all paths
53575 + */
53576 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
53577 + newglob = GR_NO_GLOB;
53578 +
53579 + spin_lock(&curr_dentry->d_lock);
53580 + inode = curr_dentry->d_inode->i_ino;
53581 + device = __get_dev(curr_dentry);
53582 + spin_unlock(&curr_dentry->d_lock);
53583 +
53584 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
53585 +}
53586 +
53587 +static struct acl_object_label *
53588 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53589 + const struct acl_subject_label *subj, char *path, const int checkglob)
53590 +{
53591 + struct dentry *dentry = (struct dentry *) l_dentry;
53592 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53593 + struct mount *real_mnt = real_mount(mnt);
53594 + struct acl_object_label *retval;
53595 + struct dentry *parent;
53596 +
53597 + write_seqlock(&rename_lock);
53598 + br_read_lock(&vfsmount_lock);
53599 +
53600 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
53601 +#ifdef CONFIG_NET
53602 + mnt == sock_mnt ||
53603 +#endif
53604 +#ifdef CONFIG_HUGETLBFS
53605 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
53606 +#endif
53607 + /* ignore Eric Biederman */
53608 + IS_PRIVATE(l_dentry->d_inode))) {
53609 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
53610 + goto out;
53611 + }
53612 +
53613 + for (;;) {
53614 + if (dentry == real_root.dentry && mnt == real_root.mnt)
53615 + break;
53616 +
53617 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53618 + if (!mnt_has_parent(real_mnt))
53619 + break;
53620 +
53621 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53622 + if (retval != NULL)
53623 + goto out;
53624 +
53625 + dentry = real_mnt->mnt_mountpoint;
53626 + real_mnt = real_mnt->mnt_parent;
53627 + mnt = &real_mnt->mnt;
53628 + continue;
53629 + }
53630 +
53631 + parent = dentry->d_parent;
53632 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53633 + if (retval != NULL)
53634 + goto out;
53635 +
53636 + dentry = parent;
53637 + }
53638 +
53639 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53640 +
53641 + /* real_root is pinned so we don't have to hold a reference */
53642 + if (retval == NULL)
53643 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
53644 +out:
53645 + br_read_unlock(&vfsmount_lock);
53646 + write_sequnlock(&rename_lock);
53647 +
53648 + BUG_ON(retval == NULL);
53649 +
53650 + return retval;
53651 +}
53652 +
53653 +static __inline__ struct acl_object_label *
53654 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53655 + const struct acl_subject_label *subj)
53656 +{
53657 + char *path = NULL;
53658 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
53659 +}
53660 +
53661 +static __inline__ struct acl_object_label *
53662 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53663 + const struct acl_subject_label *subj)
53664 +{
53665 + char *path = NULL;
53666 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
53667 +}
53668 +
53669 +static __inline__ struct acl_object_label *
53670 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53671 + const struct acl_subject_label *subj, char *path)
53672 +{
53673 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
53674 +}
53675 +
53676 +static struct acl_subject_label *
53677 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53678 + const struct acl_role_label *role)
53679 +{
53680 + struct dentry *dentry = (struct dentry *) l_dentry;
53681 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53682 + struct mount *real_mnt = real_mount(mnt);
53683 + struct acl_subject_label *retval;
53684 + struct dentry *parent;
53685 +
53686 + write_seqlock(&rename_lock);
53687 + br_read_lock(&vfsmount_lock);
53688 +
53689 + for (;;) {
53690 + if (dentry == real_root.dentry && mnt == real_root.mnt)
53691 + break;
53692 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53693 + if (!mnt_has_parent(real_mnt))
53694 + break;
53695 +
53696 + spin_lock(&dentry->d_lock);
53697 + read_lock(&gr_inode_lock);
53698 + retval =
53699 + lookup_acl_subj_label(dentry->d_inode->i_ino,
53700 + __get_dev(dentry), role);
53701 + read_unlock(&gr_inode_lock);
53702 + spin_unlock(&dentry->d_lock);
53703 + if (retval != NULL)
53704 + goto out;
53705 +
53706 + dentry = real_mnt->mnt_mountpoint;
53707 + real_mnt = real_mnt->mnt_parent;
53708 + mnt = &real_mnt->mnt;
53709 + continue;
53710 + }
53711 +
53712 + spin_lock(&dentry->d_lock);
53713 + read_lock(&gr_inode_lock);
53714 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53715 + __get_dev(dentry), role);
53716 + read_unlock(&gr_inode_lock);
53717 + parent = dentry->d_parent;
53718 + spin_unlock(&dentry->d_lock);
53719 +
53720 + if (retval != NULL)
53721 + goto out;
53722 +
53723 + dentry = parent;
53724 + }
53725 +
53726 + spin_lock(&dentry->d_lock);
53727 + read_lock(&gr_inode_lock);
53728 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53729 + __get_dev(dentry), role);
53730 + read_unlock(&gr_inode_lock);
53731 + spin_unlock(&dentry->d_lock);
53732 +
53733 + if (unlikely(retval == NULL)) {
53734 + /* real_root is pinned, we don't need to hold a reference */
53735 + read_lock(&gr_inode_lock);
53736 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
53737 + __get_dev(real_root.dentry), role);
53738 + read_unlock(&gr_inode_lock);
53739 + }
53740 +out:
53741 + br_read_unlock(&vfsmount_lock);
53742 + write_sequnlock(&rename_lock);
53743 +
53744 + BUG_ON(retval == NULL);
53745 +
53746 + return retval;
53747 +}
53748 +
53749 +static void
53750 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
53751 +{
53752 + struct task_struct *task = current;
53753 + const struct cred *cred = current_cred();
53754 +
53755 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
53756 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53757 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53758 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
53759 +
53760 + return;
53761 +}
53762 +
53763 +static void
53764 +gr_log_learn_id_change(const char type, const unsigned int real,
53765 + const unsigned int effective, const unsigned int fs)
53766 +{
53767 + struct task_struct *task = current;
53768 + const struct cred *cred = current_cred();
53769 +
53770 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
53771 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53772 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53773 + type, real, effective, fs, &task->signal->saved_ip);
53774 +
53775 + return;
53776 +}
53777 +
53778 +__u32
53779 +gr_search_file(const struct dentry * dentry, const __u32 mode,
53780 + const struct vfsmount * mnt)
53781 +{
53782 + __u32 retval = mode;
53783 + struct acl_subject_label *curracl;
53784 + struct acl_object_label *currobj;
53785 +
53786 + if (unlikely(!(gr_status & GR_READY)))
53787 + return (mode & ~GR_AUDITS);
53788 +
53789 + curracl = current->acl;
53790 +
53791 + currobj = chk_obj_label(dentry, mnt, curracl);
53792 + retval = currobj->mode & mode;
53793 +
53794 + /* if we're opening a specified transfer file for writing
53795 + (e.g. /dev/initctl), then transfer our role to init
53796 + */
53797 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
53798 + current->role->roletype & GR_ROLE_PERSIST)) {
53799 + struct task_struct *task = init_pid_ns.child_reaper;
53800 +
53801 + if (task->role != current->role) {
53802 + task->acl_sp_role = 0;
53803 + task->acl_role_id = current->acl_role_id;
53804 + task->role = current->role;
53805 + rcu_read_lock();
53806 + read_lock(&grsec_exec_file_lock);
53807 + gr_apply_subject_to_task(task);
53808 + read_unlock(&grsec_exec_file_lock);
53809 + rcu_read_unlock();
53810 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
53811 + }
53812 + }
53813 +
53814 + if (unlikely
53815 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
53816 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
53817 + __u32 new_mode = mode;
53818 +
53819 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53820 +
53821 + retval = new_mode;
53822 +
53823 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
53824 + new_mode |= GR_INHERIT;
53825 +
53826 + if (!(mode & GR_NOLEARN))
53827 + gr_log_learn(dentry, mnt, new_mode);
53828 + }
53829 +
53830 + return retval;
53831 +}
53832 +
53833 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
53834 + const struct dentry *parent,
53835 + const struct vfsmount *mnt)
53836 +{
53837 + struct name_entry *match;
53838 + struct acl_object_label *matchpo;
53839 + struct acl_subject_label *curracl;
53840 + char *path;
53841 +
53842 + if (unlikely(!(gr_status & GR_READY)))
53843 + return NULL;
53844 +
53845 + preempt_disable();
53846 + path = gr_to_filename_rbac(new_dentry, mnt);
53847 + match = lookup_name_entry_create(path);
53848 +
53849 + curracl = current->acl;
53850 +
53851 + if (match) {
53852 + read_lock(&gr_inode_lock);
53853 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
53854 + read_unlock(&gr_inode_lock);
53855 +
53856 + if (matchpo) {
53857 + preempt_enable();
53858 + return matchpo;
53859 + }
53860 + }
53861 +
53862 + // lookup parent
53863 +
53864 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
53865 +
53866 + preempt_enable();
53867 + return matchpo;
53868 +}
53869 +
53870 +__u32
53871 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
53872 + const struct vfsmount * mnt, const __u32 mode)
53873 +{
53874 + struct acl_object_label *matchpo;
53875 + __u32 retval;
53876 +
53877 + if (unlikely(!(gr_status & GR_READY)))
53878 + return (mode & ~GR_AUDITS);
53879 +
53880 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
53881 +
53882 + retval = matchpo->mode & mode;
53883 +
53884 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
53885 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53886 + __u32 new_mode = mode;
53887 +
53888 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53889 +
53890 + gr_log_learn(new_dentry, mnt, new_mode);
53891 + return new_mode;
53892 + }
53893 +
53894 + return retval;
53895 +}
53896 +
53897 +__u32
53898 +gr_check_link(const struct dentry * new_dentry,
53899 + const struct dentry * parent_dentry,
53900 + const struct vfsmount * parent_mnt,
53901 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
53902 +{
53903 + struct acl_object_label *obj;
53904 + __u32 oldmode, newmode;
53905 + __u32 needmode;
53906 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
53907 + GR_DELETE | GR_INHERIT;
53908 +
53909 + if (unlikely(!(gr_status & GR_READY)))
53910 + return (GR_CREATE | GR_LINK);
53911 +
53912 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
53913 + oldmode = obj->mode;
53914 +
53915 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
53916 + newmode = obj->mode;
53917 +
53918 + needmode = newmode & checkmodes;
53919 +
53920 + // old name for hardlink must have at least the permissions of the new name
53921 + if ((oldmode & needmode) != needmode)
53922 + goto bad;
53923 +
53924 + // if old name had restrictions/auditing, make sure the new name does as well
53925 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
53926 +
53927 + // don't allow hardlinking of suid/sgid/fcapped files without permission
53928 + if (is_privileged_binary(old_dentry))
53929 + needmode |= GR_SETID;
53930 +
53931 + if ((newmode & needmode) != needmode)
53932 + goto bad;
53933 +
53934 + // enforce minimum permissions
53935 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
53936 + return newmode;
53937 +bad:
53938 + needmode = oldmode;
53939 + if (is_privileged_binary(old_dentry))
53940 + needmode |= GR_SETID;
53941 +
53942 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
53943 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
53944 + return (GR_CREATE | GR_LINK);
53945 + } else if (newmode & GR_SUPPRESS)
53946 + return GR_SUPPRESS;
53947 + else
53948 + return 0;
53949 +}
53950 +
53951 +int
53952 +gr_check_hidden_task(const struct task_struct *task)
53953 +{
53954 + if (unlikely(!(gr_status & GR_READY)))
53955 + return 0;
53956 +
53957 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
53958 + return 1;
53959 +
53960 + return 0;
53961 +}
53962 +
53963 +int
53964 +gr_check_protected_task(const struct task_struct *task)
53965 +{
53966 + if (unlikely(!(gr_status & GR_READY) || !task))
53967 + return 0;
53968 +
53969 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53970 + task->acl != current->acl)
53971 + return 1;
53972 +
53973 + return 0;
53974 +}
53975 +
53976 +int
53977 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
53978 +{
53979 + struct task_struct *p;
53980 + int ret = 0;
53981 +
53982 + if (unlikely(!(gr_status & GR_READY) || !pid))
53983 + return ret;
53984 +
53985 + read_lock(&tasklist_lock);
53986 + do_each_pid_task(pid, type, p) {
53987 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53988 + p->acl != current->acl) {
53989 + ret = 1;
53990 + goto out;
53991 + }
53992 + } while_each_pid_task(pid, type, p);
53993 +out:
53994 + read_unlock(&tasklist_lock);
53995 +
53996 + return ret;
53997 +}
53998 +
53999 +void
54000 +gr_copy_label(struct task_struct *tsk)
54001 +{
54002 + tsk->signal->used_accept = 0;
54003 + tsk->acl_sp_role = 0;
54004 + tsk->acl_role_id = current->acl_role_id;
54005 + tsk->acl = current->acl;
54006 + tsk->role = current->role;
54007 + tsk->signal->curr_ip = current->signal->curr_ip;
54008 + tsk->signal->saved_ip = current->signal->saved_ip;
54009 + if (current->exec_file)
54010 + get_file(current->exec_file);
54011 + tsk->exec_file = current->exec_file;
54012 + tsk->is_writable = current->is_writable;
54013 + if (unlikely(current->signal->used_accept)) {
54014 + current->signal->curr_ip = 0;
54015 + current->signal->saved_ip = 0;
54016 + }
54017 +
54018 + return;
54019 +}
54020 +
54021 +static void
54022 +gr_set_proc_res(struct task_struct *task)
54023 +{
54024 + struct acl_subject_label *proc;
54025 + unsigned short i;
54026 +
54027 + proc = task->acl;
54028 +
54029 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
54030 + return;
54031 +
54032 + for (i = 0; i < RLIM_NLIMITS; i++) {
54033 + if (!(proc->resmask & (1 << i)))
54034 + continue;
54035 +
54036 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
54037 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
54038 + }
54039 +
54040 + return;
54041 +}
54042 +
54043 +extern int __gr_process_user_ban(struct user_struct *user);
54044 +
54045 +int
54046 +gr_check_user_change(int real, int effective, int fs)
54047 +{
54048 + unsigned int i;
54049 + __u16 num;
54050 + uid_t *uidlist;
54051 + int curuid;
54052 + int realok = 0;
54053 + int effectiveok = 0;
54054 + int fsok = 0;
54055 +
54056 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
54057 + struct user_struct *user;
54058 +
54059 + if (real == -1)
54060 + goto skipit;
54061 +
54062 + user = find_user(real);
54063 + if (user == NULL)
54064 + goto skipit;
54065 +
54066 + if (__gr_process_user_ban(user)) {
54067 + /* for find_user */
54068 + free_uid(user);
54069 + return 1;
54070 + }
54071 +
54072 + /* for find_user */
54073 + free_uid(user);
54074 +
54075 +skipit:
54076 +#endif
54077 +
54078 + if (unlikely(!(gr_status & GR_READY)))
54079 + return 0;
54080 +
54081 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54082 + gr_log_learn_id_change('u', real, effective, fs);
54083 +
54084 + num = current->acl->user_trans_num;
54085 + uidlist = current->acl->user_transitions;
54086 +
54087 + if (uidlist == NULL)
54088 + return 0;
54089 +
54090 + if (real == -1)
54091 + realok = 1;
54092 + if (effective == -1)
54093 + effectiveok = 1;
54094 + if (fs == -1)
54095 + fsok = 1;
54096 +
54097 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
54098 + for (i = 0; i < num; i++) {
54099 + curuid = (int)uidlist[i];
54100 + if (real == curuid)
54101 + realok = 1;
54102 + if (effective == curuid)
54103 + effectiveok = 1;
54104 + if (fs == curuid)
54105 + fsok = 1;
54106 + }
54107 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
54108 + for (i = 0; i < num; i++) {
54109 + curuid = (int)uidlist[i];
54110 + if (real == curuid)
54111 + break;
54112 + if (effective == curuid)
54113 + break;
54114 + if (fs == curuid)
54115 + break;
54116 + }
54117 + /* not in deny list */
54118 + if (i == num) {
54119 + realok = 1;
54120 + effectiveok = 1;
54121 + fsok = 1;
54122 + }
54123 + }
54124 +
54125 + if (realok && effectiveok && fsok)
54126 + return 0;
54127 + else {
54128 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
54129 + return 1;
54130 + }
54131 +}
54132 +
54133 +int
54134 +gr_check_group_change(int real, int effective, int fs)
54135 +{
54136 + unsigned int i;
54137 + __u16 num;
54138 + gid_t *gidlist;
54139 + int curgid;
54140 + int realok = 0;
54141 + int effectiveok = 0;
54142 + int fsok = 0;
54143 +
54144 + if (unlikely(!(gr_status & GR_READY)))
54145 + return 0;
54146 +
54147 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54148 + gr_log_learn_id_change('g', real, effective, fs);
54149 +
54150 + num = current->acl->group_trans_num;
54151 + gidlist = current->acl->group_transitions;
54152 +
54153 + if (gidlist == NULL)
54154 + return 0;
54155 +
54156 + if (real == -1)
54157 + realok = 1;
54158 + if (effective == -1)
54159 + effectiveok = 1;
54160 + if (fs == -1)
54161 + fsok = 1;
54162 +
54163 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
54164 + for (i = 0; i < num; i++) {
54165 + curgid = (int)gidlist[i];
54166 + if (real == curgid)
54167 + realok = 1;
54168 + if (effective == curgid)
54169 + effectiveok = 1;
54170 + if (fs == curgid)
54171 + fsok = 1;
54172 + }
54173 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
54174 + for (i = 0; i < num; i++) {
54175 + curgid = (int)gidlist[i];
54176 + if (real == curgid)
54177 + break;
54178 + if (effective == curgid)
54179 + break;
54180 + if (fs == curgid)
54181 + break;
54182 + }
54183 + /* not in deny list */
54184 + if (i == num) {
54185 + realok = 1;
54186 + effectiveok = 1;
54187 + fsok = 1;
54188 + }
54189 + }
54190 +
54191 + if (realok && effectiveok && fsok)
54192 + return 0;
54193 + else {
54194 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
54195 + return 1;
54196 + }
54197 +}
54198 +
54199 +extern int gr_acl_is_capable(const int cap);
54200 +
54201 +void
54202 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
54203 +{
54204 + struct acl_role_label *role = task->role;
54205 + struct acl_subject_label *subj = NULL;
54206 + struct acl_object_label *obj;
54207 + struct file *filp;
54208 +
54209 + if (unlikely(!(gr_status & GR_READY)))
54210 + return;
54211 +
54212 + filp = task->exec_file;
54213 +
54214 + /* kernel process, we'll give them the kernel role */
54215 + if (unlikely(!filp)) {
54216 + task->role = kernel_role;
54217 + task->acl = kernel_role->root_label;
54218 + return;
54219 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
54220 + role = lookup_acl_role_label(task, uid, gid);
54221 +
54222 + /* don't change the role if we're not a privileged process */
54223 + if (role && task->role != role &&
54224 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
54225 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
54226 + return;
54227 +
54228 + /* perform subject lookup in possibly new role
54229 + we can use this result below in the case where role == task->role
54230 + */
54231 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
54232 +
54233 + /* if we changed uid/gid, but result in the same role
54234 + and are using inheritance, don't lose the inherited subject
54235 + if current subject is other than what normal lookup
54236 + would result in, we arrived via inheritance, don't
54237 + lose subject
54238 + */
54239 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
54240 + (subj == task->acl)))
54241 + task->acl = subj;
54242 +
54243 + task->role = role;
54244 +
54245 + task->is_writable = 0;
54246 +
54247 + /* ignore additional mmap checks for processes that are writable
54248 + by the default ACL */
54249 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54250 + if (unlikely(obj->mode & GR_WRITE))
54251 + task->is_writable = 1;
54252 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54253 + if (unlikely(obj->mode & GR_WRITE))
54254 + task->is_writable = 1;
54255 +
54256 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54257 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54258 +#endif
54259 +
54260 + gr_set_proc_res(task);
54261 +
54262 + return;
54263 +}
54264 +
54265 +int
54266 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
54267 + const int unsafe_flags)
54268 +{
54269 + struct task_struct *task = current;
54270 + struct acl_subject_label *newacl;
54271 + struct acl_object_label *obj;
54272 + __u32 retmode;
54273 +
54274 + if (unlikely(!(gr_status & GR_READY)))
54275 + return 0;
54276 +
54277 + newacl = chk_subj_label(dentry, mnt, task->role);
54278 +
54279 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
54280 + did an exec
54281 + */
54282 + rcu_read_lock();
54283 + read_lock(&tasklist_lock);
54284 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
54285 + (task->parent->acl->mode & GR_POVERRIDE))) {
54286 + read_unlock(&tasklist_lock);
54287 + rcu_read_unlock();
54288 + goto skip_check;
54289 + }
54290 + read_unlock(&tasklist_lock);
54291 + rcu_read_unlock();
54292 +
54293 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
54294 + !(task->role->roletype & GR_ROLE_GOD) &&
54295 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
54296 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
54297 + if (unsafe_flags & LSM_UNSAFE_SHARE)
54298 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
54299 + else
54300 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
54301 + return -EACCES;
54302 + }
54303 +
54304 +skip_check:
54305 +
54306 + obj = chk_obj_label(dentry, mnt, task->acl);
54307 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
54308 +
54309 + if (!(task->acl->mode & GR_INHERITLEARN) &&
54310 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
54311 + if (obj->nested)
54312 + task->acl = obj->nested;
54313 + else
54314 + task->acl = newacl;
54315 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
54316 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
54317 +
54318 + task->is_writable = 0;
54319 +
54320 + /* ignore additional mmap checks for processes that are writable
54321 + by the default ACL */
54322 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
54323 + if (unlikely(obj->mode & GR_WRITE))
54324 + task->is_writable = 1;
54325 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
54326 + if (unlikely(obj->mode & GR_WRITE))
54327 + task->is_writable = 1;
54328 +
54329 + gr_set_proc_res(task);
54330 +
54331 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54332 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54333 +#endif
54334 + return 0;
54335 +}
54336 +
54337 +/* always called with valid inodev ptr */
54338 +static void
54339 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
54340 +{
54341 + struct acl_object_label *matchpo;
54342 + struct acl_subject_label *matchps;
54343 + struct acl_subject_label *subj;
54344 + struct acl_role_label *role;
54345 + unsigned int x;
54346 +
54347 + FOR_EACH_ROLE_START(role)
54348 + FOR_EACH_SUBJECT_START(role, subj, x)
54349 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
54350 + matchpo->mode |= GR_DELETED;
54351 + FOR_EACH_SUBJECT_END(subj,x)
54352 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
54353 + /* nested subjects aren't in the role's subj_hash table */
54354 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
54355 + matchpo->mode |= GR_DELETED;
54356 + FOR_EACH_NESTED_SUBJECT_END(subj)
54357 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
54358 + matchps->mode |= GR_DELETED;
54359 + FOR_EACH_ROLE_END(role)
54360 +
54361 + inodev->nentry->deleted = 1;
54362 +
54363 + return;
54364 +}
54365 +
54366 +void
54367 +gr_handle_delete(const ino_t ino, const dev_t dev)
54368 +{
54369 + struct inodev_entry *inodev;
54370 +
54371 + if (unlikely(!(gr_status & GR_READY)))
54372 + return;
54373 +
54374 + write_lock(&gr_inode_lock);
54375 + inodev = lookup_inodev_entry(ino, dev);
54376 + if (inodev != NULL)
54377 + do_handle_delete(inodev, ino, dev);
54378 + write_unlock(&gr_inode_lock);
54379 +
54380 + return;
54381 +}
54382 +
54383 +static void
54384 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
54385 + const ino_t newinode, const dev_t newdevice,
54386 + struct acl_subject_label *subj)
54387 +{
54388 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
54389 + struct acl_object_label *match;
54390 +
54391 + match = subj->obj_hash[index];
54392 +
54393 + while (match && (match->inode != oldinode ||
54394 + match->device != olddevice ||
54395 + !(match->mode & GR_DELETED)))
54396 + match = match->next;
54397 +
54398 + if (match && (match->inode == oldinode)
54399 + && (match->device == olddevice)
54400 + && (match->mode & GR_DELETED)) {
54401 + if (match->prev == NULL) {
54402 + subj->obj_hash[index] = match->next;
54403 + if (match->next != NULL)
54404 + match->next->prev = NULL;
54405 + } else {
54406 + match->prev->next = match->next;
54407 + if (match->next != NULL)
54408 + match->next->prev = match->prev;
54409 + }
54410 + match->prev = NULL;
54411 + match->next = NULL;
54412 + match->inode = newinode;
54413 + match->device = newdevice;
54414 + match->mode &= ~GR_DELETED;
54415 +
54416 + insert_acl_obj_label(match, subj);
54417 + }
54418 +
54419 + return;
54420 +}
54421 +
54422 +static void
54423 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
54424 + const ino_t newinode, const dev_t newdevice,
54425 + struct acl_role_label *role)
54426 +{
54427 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
54428 + struct acl_subject_label *match;
54429 +
54430 + match = role->subj_hash[index];
54431 +
54432 + while (match && (match->inode != oldinode ||
54433 + match->device != olddevice ||
54434 + !(match->mode & GR_DELETED)))
54435 + match = match->next;
54436 +
54437 + if (match && (match->inode == oldinode)
54438 + && (match->device == olddevice)
54439 + && (match->mode & GR_DELETED)) {
54440 + if (match->prev == NULL) {
54441 + role->subj_hash[index] = match->next;
54442 + if (match->next != NULL)
54443 + match->next->prev = NULL;
54444 + } else {
54445 + match->prev->next = match->next;
54446 + if (match->next != NULL)
54447 + match->next->prev = match->prev;
54448 + }
54449 + match->prev = NULL;
54450 + match->next = NULL;
54451 + match->inode = newinode;
54452 + match->device = newdevice;
54453 + match->mode &= ~GR_DELETED;
54454 +
54455 + insert_acl_subj_label(match, role);
54456 + }
54457 +
54458 + return;
54459 +}
54460 +
54461 +static void
54462 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
54463 + const ino_t newinode, const dev_t newdevice)
54464 +{
54465 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
54466 + struct inodev_entry *match;
54467 +
54468 + match = inodev_set.i_hash[index];
54469 +
54470 + while (match && (match->nentry->inode != oldinode ||
54471 + match->nentry->device != olddevice || !match->nentry->deleted))
54472 + match = match->next;
54473 +
54474 + if (match && (match->nentry->inode == oldinode)
54475 + && (match->nentry->device == olddevice) &&
54476 + match->nentry->deleted) {
54477 + if (match->prev == NULL) {
54478 + inodev_set.i_hash[index] = match->next;
54479 + if (match->next != NULL)
54480 + match->next->prev = NULL;
54481 + } else {
54482 + match->prev->next = match->next;
54483 + if (match->next != NULL)
54484 + match->next->prev = match->prev;
54485 + }
54486 + match->prev = NULL;
54487 + match->next = NULL;
54488 + match->nentry->inode = newinode;
54489 + match->nentry->device = newdevice;
54490 + match->nentry->deleted = 0;
54491 +
54492 + insert_inodev_entry(match);
54493 + }
54494 +
54495 + return;
54496 +}
54497 +
54498 +static void
54499 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
54500 +{
54501 + struct acl_subject_label *subj;
54502 + struct acl_role_label *role;
54503 + unsigned int x;
54504 +
54505 + FOR_EACH_ROLE_START(role)
54506 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
54507 +
54508 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
54509 + if ((subj->inode == ino) && (subj->device == dev)) {
54510 + subj->inode = ino;
54511 + subj->device = dev;
54512 + }
54513 + /* nested subjects aren't in the role's subj_hash table */
54514 + update_acl_obj_label(matchn->inode, matchn->device,
54515 + ino, dev, subj);
54516 + FOR_EACH_NESTED_SUBJECT_END(subj)
54517 + FOR_EACH_SUBJECT_START(role, subj, x)
54518 + update_acl_obj_label(matchn->inode, matchn->device,
54519 + ino, dev, subj);
54520 + FOR_EACH_SUBJECT_END(subj,x)
54521 + FOR_EACH_ROLE_END(role)
54522 +
54523 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
54524 +
54525 + return;
54526 +}
54527 +
54528 +static void
54529 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
54530 + const struct vfsmount *mnt)
54531 +{
54532 + ino_t ino = dentry->d_inode->i_ino;
54533 + dev_t dev = __get_dev(dentry);
54534 +
54535 + __do_handle_create(matchn, ino, dev);
54536 +
54537 + return;
54538 +}
54539 +
54540 +void
54541 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
54542 +{
54543 + struct name_entry *matchn;
54544 +
54545 + if (unlikely(!(gr_status & GR_READY)))
54546 + return;
54547 +
54548 + preempt_disable();
54549 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
54550 +
54551 + if (unlikely((unsigned long)matchn)) {
54552 + write_lock(&gr_inode_lock);
54553 + do_handle_create(matchn, dentry, mnt);
54554 + write_unlock(&gr_inode_lock);
54555 + }
54556 + preempt_enable();
54557 +
54558 + return;
54559 +}
54560 +
54561 +void
54562 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
54563 +{
54564 + struct name_entry *matchn;
54565 +
54566 + if (unlikely(!(gr_status & GR_READY)))
54567 + return;
54568 +
54569 + preempt_disable();
54570 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
54571 +
54572 + if (unlikely((unsigned long)matchn)) {
54573 + write_lock(&gr_inode_lock);
54574 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
54575 + write_unlock(&gr_inode_lock);
54576 + }
54577 + preempt_enable();
54578 +
54579 + return;
54580 +}
54581 +
54582 +void
54583 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
54584 + struct dentry *old_dentry,
54585 + struct dentry *new_dentry,
54586 + struct vfsmount *mnt, const __u8 replace)
54587 +{
54588 + struct name_entry *matchn;
54589 + struct inodev_entry *inodev;
54590 + struct inode *inode = new_dentry->d_inode;
54591 + ino_t old_ino = old_dentry->d_inode->i_ino;
54592 + dev_t old_dev = __get_dev(old_dentry);
54593 +
54594 + /* vfs_rename swaps the name and parent link for old_dentry and
54595 + new_dentry
54596 + at this point, old_dentry has the new name, parent link, and inode
54597 + for the renamed file
54598 + if a file is being replaced by a rename, new_dentry has the inode
54599 + and name for the replaced file
54600 + */
54601 +
54602 + if (unlikely(!(gr_status & GR_READY)))
54603 + return;
54604 +
54605 + preempt_disable();
54606 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
54607 +
54608 + /* we wouldn't have to check d_inode if it weren't for
54609 + NFS silly-renaming
54610 + */
54611 +
54612 + write_lock(&gr_inode_lock);
54613 + if (unlikely(replace && inode)) {
54614 + ino_t new_ino = inode->i_ino;
54615 + dev_t new_dev = __get_dev(new_dentry);
54616 +
54617 + inodev = lookup_inodev_entry(new_ino, new_dev);
54618 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
54619 + do_handle_delete(inodev, new_ino, new_dev);
54620 + }
54621 +
54622 + inodev = lookup_inodev_entry(old_ino, old_dev);
54623 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
54624 + do_handle_delete(inodev, old_ino, old_dev);
54625 +
54626 + if (unlikely((unsigned long)matchn))
54627 + do_handle_create(matchn, old_dentry, mnt);
54628 +
54629 + write_unlock(&gr_inode_lock);
54630 + preempt_enable();
54631 +
54632 + return;
54633 +}
54634 +
54635 +static int
54636 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
54637 + unsigned char **sum)
54638 +{
54639 + struct acl_role_label *r;
54640 + struct role_allowed_ip *ipp;
54641 + struct role_transition *trans;
54642 + unsigned int i;
54643 + int found = 0;
54644 + u32 curr_ip = current->signal->curr_ip;
54645 +
54646 + current->signal->saved_ip = curr_ip;
54647 +
54648 + /* check transition table */
54649 +
54650 + for (trans = current->role->transitions; trans; trans = trans->next) {
54651 + if (!strcmp(rolename, trans->rolename)) {
54652 + found = 1;
54653 + break;
54654 + }
54655 + }
54656 +
54657 + if (!found)
54658 + return 0;
54659 +
54660 + /* handle special roles that do not require authentication
54661 + and check ip */
54662 +
54663 + FOR_EACH_ROLE_START(r)
54664 + if (!strcmp(rolename, r->rolename) &&
54665 + (r->roletype & GR_ROLE_SPECIAL)) {
54666 + found = 0;
54667 + if (r->allowed_ips != NULL) {
54668 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
54669 + if ((ntohl(curr_ip) & ipp->netmask) ==
54670 + (ntohl(ipp->addr) & ipp->netmask))
54671 + found = 1;
54672 + }
54673 + } else
54674 + found = 2;
54675 + if (!found)
54676 + return 0;
54677 +
54678 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
54679 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
54680 + *salt = NULL;
54681 + *sum = NULL;
54682 + return 1;
54683 + }
54684 + }
54685 + FOR_EACH_ROLE_END(r)
54686 +
54687 + for (i = 0; i < num_sprole_pws; i++) {
54688 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
54689 + *salt = acl_special_roles[i]->salt;
54690 + *sum = acl_special_roles[i]->sum;
54691 + return 1;
54692 + }
54693 + }
54694 +
54695 + return 0;
54696 +}
54697 +
54698 +static void
54699 +assign_special_role(char *rolename)
54700 +{
54701 + struct acl_object_label *obj;
54702 + struct acl_role_label *r;
54703 + struct acl_role_label *assigned = NULL;
54704 + struct task_struct *tsk;
54705 + struct file *filp;
54706 +
54707 + FOR_EACH_ROLE_START(r)
54708 + if (!strcmp(rolename, r->rolename) &&
54709 + (r->roletype & GR_ROLE_SPECIAL)) {
54710 + assigned = r;
54711 + break;
54712 + }
54713 + FOR_EACH_ROLE_END(r)
54714 +
54715 + if (!assigned)
54716 + return;
54717 +
54718 + read_lock(&tasklist_lock);
54719 + read_lock(&grsec_exec_file_lock);
54720 +
54721 + tsk = current->real_parent;
54722 + if (tsk == NULL)
54723 + goto out_unlock;
54724 +
54725 + filp = tsk->exec_file;
54726 + if (filp == NULL)
54727 + goto out_unlock;
54728 +
54729 + tsk->is_writable = 0;
54730 +
54731 + tsk->acl_sp_role = 1;
54732 + tsk->acl_role_id = ++acl_sp_role_value;
54733 + tsk->role = assigned;
54734 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
54735 +
54736 + /* ignore additional mmap checks for processes that are writable
54737 + by the default ACL */
54738 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54739 + if (unlikely(obj->mode & GR_WRITE))
54740 + tsk->is_writable = 1;
54741 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
54742 + if (unlikely(obj->mode & GR_WRITE))
54743 + tsk->is_writable = 1;
54744 +
54745 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54746 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
54747 +#endif
54748 +
54749 +out_unlock:
54750 + read_unlock(&grsec_exec_file_lock);
54751 + read_unlock(&tasklist_lock);
54752 + return;
54753 +}
54754 +
54755 +int gr_check_secure_terminal(struct task_struct *task)
54756 +{
54757 + struct task_struct *p, *p2, *p3;
54758 + struct files_struct *files;
54759 + struct fdtable *fdt;
54760 + struct file *our_file = NULL, *file;
54761 + int i;
54762 +
54763 + if (task->signal->tty == NULL)
54764 + return 1;
54765 +
54766 + files = get_files_struct(task);
54767 + if (files != NULL) {
54768 + rcu_read_lock();
54769 + fdt = files_fdtable(files);
54770 + for (i=0; i < fdt->max_fds; i++) {
54771 + file = fcheck_files(files, i);
54772 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
54773 + get_file(file);
54774 + our_file = file;
54775 + }
54776 + }
54777 + rcu_read_unlock();
54778 + put_files_struct(files);
54779 + }
54780 +
54781 + if (our_file == NULL)
54782 + return 1;
54783 +
54784 + read_lock(&tasklist_lock);
54785 + do_each_thread(p2, p) {
54786 + files = get_files_struct(p);
54787 + if (files == NULL ||
54788 + (p->signal && p->signal->tty == task->signal->tty)) {
54789 + if (files != NULL)
54790 + put_files_struct(files);
54791 + continue;
54792 + }
54793 + rcu_read_lock();
54794 + fdt = files_fdtable(files);
54795 + for (i=0; i < fdt->max_fds; i++) {
54796 + file = fcheck_files(files, i);
54797 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
54798 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
54799 + p3 = task;
54800 + while (p3->pid > 0) {
54801 + if (p3 == p)
54802 + break;
54803 + p3 = p3->real_parent;
54804 + }
54805 + if (p3 == p)
54806 + break;
54807 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
54808 + gr_handle_alertkill(p);
54809 + rcu_read_unlock();
54810 + put_files_struct(files);
54811 + read_unlock(&tasklist_lock);
54812 + fput(our_file);
54813 + return 0;
54814 + }
54815 + }
54816 + rcu_read_unlock();
54817 + put_files_struct(files);
54818 + } while_each_thread(p2, p);
54819 + read_unlock(&tasklist_lock);
54820 +
54821 + fput(our_file);
54822 + return 1;
54823 +}
54824 +
54825 +static int gr_rbac_disable(void *unused)
54826 +{
54827 + pax_open_kernel();
54828 + gr_status &= ~GR_READY;
54829 + pax_close_kernel();
54830 +
54831 + return 0;
54832 +}
54833 +
54834 +ssize_t
54835 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
54836 +{
54837 + struct gr_arg_wrapper uwrap;
54838 + unsigned char *sprole_salt = NULL;
54839 + unsigned char *sprole_sum = NULL;
54840 + int error = sizeof (struct gr_arg_wrapper);
54841 + int error2 = 0;
54842 +
54843 + mutex_lock(&gr_dev_mutex);
54844 +
54845 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
54846 + error = -EPERM;
54847 + goto out;
54848 + }
54849 +
54850 + if (count != sizeof (struct gr_arg_wrapper)) {
54851 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
54852 + error = -EINVAL;
54853 + goto out;
54854 + }
54855 +
54856 +
54857 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
54858 + gr_auth_expires = 0;
54859 + gr_auth_attempts = 0;
54860 + }
54861 +
54862 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
54863 + error = -EFAULT;
54864 + goto out;
54865 + }
54866 +
54867 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
54868 + error = -EINVAL;
54869 + goto out;
54870 + }
54871 +
54872 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
54873 + error = -EFAULT;
54874 + goto out;
54875 + }
54876 +
54877 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54878 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54879 + time_after(gr_auth_expires, get_seconds())) {
54880 + error = -EBUSY;
54881 + goto out;
54882 + }
54883 +
54884 + /* if non-root trying to do anything other than use a special role,
54885 + do not attempt authentication, do not count towards authentication
54886 + locking
54887 + */
54888 +
54889 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
54890 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54891 + !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
54892 + error = -EPERM;
54893 + goto out;
54894 + }
54895 +
54896 + /* ensure pw and special role name are null terminated */
54897 +
54898 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
54899 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
54900 +
54901 + /* Okay.
54902 + * We have our enough of the argument structure..(we have yet
54903 + * to copy_from_user the tables themselves) . Copy the tables
54904 + * only if we need them, i.e. for loading operations. */
54905 +
54906 + switch (gr_usermode->mode) {
54907 + case GR_STATUS:
54908 + if (gr_status & GR_READY) {
54909 + error = 1;
54910 + if (!gr_check_secure_terminal(current))
54911 + error = 3;
54912 + } else
54913 + error = 2;
54914 + goto out;
54915 + case GR_SHUTDOWN:
54916 + if ((gr_status & GR_READY)
54917 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54918 + stop_machine(gr_rbac_disable, NULL, NULL);
54919 + free_variables();
54920 + memset(gr_usermode, 0, sizeof (struct gr_arg));
54921 + memset(gr_system_salt, 0, GR_SALT_LEN);
54922 + memset(gr_system_sum, 0, GR_SHA_LEN);
54923 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
54924 + } else if (gr_status & GR_READY) {
54925 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
54926 + error = -EPERM;
54927 + } else {
54928 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
54929 + error = -EAGAIN;
54930 + }
54931 + break;
54932 + case GR_ENABLE:
54933 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
54934 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
54935 + else {
54936 + if (gr_status & GR_READY)
54937 + error = -EAGAIN;
54938 + else
54939 + error = error2;
54940 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
54941 + }
54942 + break;
54943 + case GR_RELOAD:
54944 + if (!(gr_status & GR_READY)) {
54945 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
54946 + error = -EAGAIN;
54947 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54948 + stop_machine(gr_rbac_disable, NULL, NULL);
54949 + free_variables();
54950 + error2 = gracl_init(gr_usermode);
54951 + if (!error2)
54952 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
54953 + else {
54954 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54955 + error = error2;
54956 + }
54957 + } else {
54958 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54959 + error = -EPERM;
54960 + }
54961 + break;
54962 + case GR_SEGVMOD:
54963 + if (unlikely(!(gr_status & GR_READY))) {
54964 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
54965 + error = -EAGAIN;
54966 + break;
54967 + }
54968 +
54969 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54970 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
54971 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
54972 + struct acl_subject_label *segvacl;
54973 + segvacl =
54974 + lookup_acl_subj_label(gr_usermode->segv_inode,
54975 + gr_usermode->segv_device,
54976 + current->role);
54977 + if (segvacl) {
54978 + segvacl->crashes = 0;
54979 + segvacl->expires = 0;
54980 + }
54981 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
54982 + gr_remove_uid(gr_usermode->segv_uid);
54983 + }
54984 + } else {
54985 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
54986 + error = -EPERM;
54987 + }
54988 + break;
54989 + case GR_SPROLE:
54990 + case GR_SPROLEPAM:
54991 + if (unlikely(!(gr_status & GR_READY))) {
54992 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
54993 + error = -EAGAIN;
54994 + break;
54995 + }
54996 +
54997 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
54998 + current->role->expires = 0;
54999 + current->role->auth_attempts = 0;
55000 + }
55001 +
55002 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
55003 + time_after(current->role->expires, get_seconds())) {
55004 + error = -EBUSY;
55005 + goto out;
55006 + }
55007 +
55008 + if (lookup_special_role_auth
55009 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
55010 + && ((!sprole_salt && !sprole_sum)
55011 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
55012 + char *p = "";
55013 + assign_special_role(gr_usermode->sp_role);
55014 + read_lock(&tasklist_lock);
55015 + if (current->real_parent)
55016 + p = current->real_parent->role->rolename;
55017 + read_unlock(&tasklist_lock);
55018 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
55019 + p, acl_sp_role_value);
55020 + } else {
55021 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
55022 + error = -EPERM;
55023 + if(!(current->role->auth_attempts++))
55024 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
55025 +
55026 + goto out;
55027 + }
55028 + break;
55029 + case GR_UNSPROLE:
55030 + if (unlikely(!(gr_status & GR_READY))) {
55031 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
55032 + error = -EAGAIN;
55033 + break;
55034 + }
55035 +
55036 + if (current->role->roletype & GR_ROLE_SPECIAL) {
55037 + char *p = "";
55038 + int i = 0;
55039 +
55040 + read_lock(&tasklist_lock);
55041 + if (current->real_parent) {
55042 + p = current->real_parent->role->rolename;
55043 + i = current->real_parent->acl_role_id;
55044 + }
55045 + read_unlock(&tasklist_lock);
55046 +
55047 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
55048 + gr_set_acls(1);
55049 + } else {
55050 + error = -EPERM;
55051 + goto out;
55052 + }
55053 + break;
55054 + default:
55055 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
55056 + error = -EINVAL;
55057 + break;
55058 + }
55059 +
55060 + if (error != -EPERM)
55061 + goto out;
55062 +
55063 + if(!(gr_auth_attempts++))
55064 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
55065 +
55066 + out:
55067 + mutex_unlock(&gr_dev_mutex);
55068 + return error;
55069 +}
55070 +
55071 +/* must be called with
55072 + rcu_read_lock();
55073 + read_lock(&tasklist_lock);
55074 + read_lock(&grsec_exec_file_lock);
55075 +*/
55076 +int gr_apply_subject_to_task(struct task_struct *task)
55077 +{
55078 + struct acl_object_label *obj;
55079 + char *tmpname;
55080 + struct acl_subject_label *tmpsubj;
55081 + struct file *filp;
55082 + struct name_entry *nmatch;
55083 +
55084 + filp = task->exec_file;
55085 + if (filp == NULL)
55086 + return 0;
55087 +
55088 + /* the following is to apply the correct subject
55089 + on binaries running when the RBAC system
55090 + is enabled, when the binaries have been
55091 + replaced or deleted since their execution
55092 + -----
55093 + when the RBAC system starts, the inode/dev
55094 + from exec_file will be one the RBAC system
55095 + is unaware of. It only knows the inode/dev
55096 + of the present file on disk, or the absence
55097 + of it.
55098 + */
55099 + preempt_disable();
55100 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
55101 +
55102 + nmatch = lookup_name_entry(tmpname);
55103 + preempt_enable();
55104 + tmpsubj = NULL;
55105 + if (nmatch) {
55106 + if (nmatch->deleted)
55107 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
55108 + else
55109 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
55110 + if (tmpsubj != NULL)
55111 + task->acl = tmpsubj;
55112 + }
55113 + if (tmpsubj == NULL)
55114 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
55115 + task->role);
55116 + if (task->acl) {
55117 + task->is_writable = 0;
55118 + /* ignore additional mmap checks for processes that are writable
55119 + by the default ACL */
55120 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55121 + if (unlikely(obj->mode & GR_WRITE))
55122 + task->is_writable = 1;
55123 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
55124 + if (unlikely(obj->mode & GR_WRITE))
55125 + task->is_writable = 1;
55126 +
55127 + gr_set_proc_res(task);
55128 +
55129 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55130 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
55131 +#endif
55132 + } else {
55133 + return 1;
55134 + }
55135 +
55136 + return 0;
55137 +}
55138 +
55139 +int
55140 +gr_set_acls(const int type)
55141 +{
55142 + struct task_struct *task, *task2;
55143 + struct acl_role_label *role = current->role;
55144 + __u16 acl_role_id = current->acl_role_id;
55145 + const struct cred *cred;
55146 + int ret;
55147 +
55148 + rcu_read_lock();
55149 + read_lock(&tasklist_lock);
55150 + read_lock(&grsec_exec_file_lock);
55151 + do_each_thread(task2, task) {
55152 + /* check to see if we're called from the exit handler,
55153 + if so, only replace ACLs that have inherited the admin
55154 + ACL */
55155 +
55156 + if (type && (task->role != role ||
55157 + task->acl_role_id != acl_role_id))
55158 + continue;
55159 +
55160 + task->acl_role_id = 0;
55161 + task->acl_sp_role = 0;
55162 +
55163 + if (task->exec_file) {
55164 + cred = __task_cred(task);
55165 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
55166 + ret = gr_apply_subject_to_task(task);
55167 + if (ret) {
55168 + read_unlock(&grsec_exec_file_lock);
55169 + read_unlock(&tasklist_lock);
55170 + rcu_read_unlock();
55171 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
55172 + return ret;
55173 + }
55174 + } else {
55175 + // it's a kernel process
55176 + task->role = kernel_role;
55177 + task->acl = kernel_role->root_label;
55178 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
55179 + task->acl->mode &= ~GR_PROCFIND;
55180 +#endif
55181 + }
55182 + } while_each_thread(task2, task);
55183 + read_unlock(&grsec_exec_file_lock);
55184 + read_unlock(&tasklist_lock);
55185 + rcu_read_unlock();
55186 +
55187 + return 0;
55188 +}
55189 +
55190 +void
55191 +gr_learn_resource(const struct task_struct *task,
55192 + const int res, const unsigned long wanted, const int gt)
55193 +{
55194 + struct acl_subject_label *acl;
55195 + const struct cred *cred;
55196 +
55197 + if (unlikely((gr_status & GR_READY) &&
55198 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
55199 + goto skip_reslog;
55200 +
55201 +#ifdef CONFIG_GRKERNSEC_RESLOG
55202 + gr_log_resource(task, res, wanted, gt);
55203 +#endif
55204 + skip_reslog:
55205 +
55206 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
55207 + return;
55208 +
55209 + acl = task->acl;
55210 +
55211 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
55212 + !(acl->resmask & (1 << (unsigned short) res))))
55213 + return;
55214 +
55215 + if (wanted >= acl->res[res].rlim_cur) {
55216 + unsigned long res_add;
55217 +
55218 + res_add = wanted;
55219 + switch (res) {
55220 + case RLIMIT_CPU:
55221 + res_add += GR_RLIM_CPU_BUMP;
55222 + break;
55223 + case RLIMIT_FSIZE:
55224 + res_add += GR_RLIM_FSIZE_BUMP;
55225 + break;
55226 + case RLIMIT_DATA:
55227 + res_add += GR_RLIM_DATA_BUMP;
55228 + break;
55229 + case RLIMIT_STACK:
55230 + res_add += GR_RLIM_STACK_BUMP;
55231 + break;
55232 + case RLIMIT_CORE:
55233 + res_add += GR_RLIM_CORE_BUMP;
55234 + break;
55235 + case RLIMIT_RSS:
55236 + res_add += GR_RLIM_RSS_BUMP;
55237 + break;
55238 + case RLIMIT_NPROC:
55239 + res_add += GR_RLIM_NPROC_BUMP;
55240 + break;
55241 + case RLIMIT_NOFILE:
55242 + res_add += GR_RLIM_NOFILE_BUMP;
55243 + break;
55244 + case RLIMIT_MEMLOCK:
55245 + res_add += GR_RLIM_MEMLOCK_BUMP;
55246 + break;
55247 + case RLIMIT_AS:
55248 + res_add += GR_RLIM_AS_BUMP;
55249 + break;
55250 + case RLIMIT_LOCKS:
55251 + res_add += GR_RLIM_LOCKS_BUMP;
55252 + break;
55253 + case RLIMIT_SIGPENDING:
55254 + res_add += GR_RLIM_SIGPENDING_BUMP;
55255 + break;
55256 + case RLIMIT_MSGQUEUE:
55257 + res_add += GR_RLIM_MSGQUEUE_BUMP;
55258 + break;
55259 + case RLIMIT_NICE:
55260 + res_add += GR_RLIM_NICE_BUMP;
55261 + break;
55262 + case RLIMIT_RTPRIO:
55263 + res_add += GR_RLIM_RTPRIO_BUMP;
55264 + break;
55265 + case RLIMIT_RTTIME:
55266 + res_add += GR_RLIM_RTTIME_BUMP;
55267 + break;
55268 + }
55269 +
55270 + acl->res[res].rlim_cur = res_add;
55271 +
55272 + if (wanted > acl->res[res].rlim_max)
55273 + acl->res[res].rlim_max = res_add;
55274 +
55275 + /* only log the subject filename, since resource logging is supported for
55276 + single-subject learning only */
55277 + rcu_read_lock();
55278 + cred = __task_cred(task);
55279 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55280 + task->role->roletype, cred->uid, cred->gid, acl->filename,
55281 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
55282 + "", (unsigned long) res, &task->signal->saved_ip);
55283 + rcu_read_unlock();
55284 + }
55285 +
55286 + return;
55287 +}
55288 +
55289 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
55290 +void
55291 +pax_set_initial_flags(struct linux_binprm *bprm)
55292 +{
55293 + struct task_struct *task = current;
55294 + struct acl_subject_label *proc;
55295 + unsigned long flags;
55296 +
55297 + if (unlikely(!(gr_status & GR_READY)))
55298 + return;
55299 +
55300 + flags = pax_get_flags(task);
55301 +
55302 + proc = task->acl;
55303 +
55304 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
55305 + flags &= ~MF_PAX_PAGEEXEC;
55306 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
55307 + flags &= ~MF_PAX_SEGMEXEC;
55308 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
55309 + flags &= ~MF_PAX_RANDMMAP;
55310 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
55311 + flags &= ~MF_PAX_EMUTRAMP;
55312 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
55313 + flags &= ~MF_PAX_MPROTECT;
55314 +
55315 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
55316 + flags |= MF_PAX_PAGEEXEC;
55317 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
55318 + flags |= MF_PAX_SEGMEXEC;
55319 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
55320 + flags |= MF_PAX_RANDMMAP;
55321 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
55322 + flags |= MF_PAX_EMUTRAMP;
55323 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
55324 + flags |= MF_PAX_MPROTECT;
55325 +
55326 + pax_set_flags(task, flags);
55327 +
55328 + return;
55329 +}
55330 +#endif
55331 +
55332 +int
55333 +gr_handle_proc_ptrace(struct task_struct *task)
55334 +{
55335 + struct file *filp;
55336 + struct task_struct *tmp = task;
55337 + struct task_struct *curtemp = current;
55338 + __u32 retmode;
55339 +
55340 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55341 + if (unlikely(!(gr_status & GR_READY)))
55342 + return 0;
55343 +#endif
55344 +
55345 + read_lock(&tasklist_lock);
55346 + read_lock(&grsec_exec_file_lock);
55347 + filp = task->exec_file;
55348 +
55349 + while (tmp->pid > 0) {
55350 + if (tmp == curtemp)
55351 + break;
55352 + tmp = tmp->real_parent;
55353 + }
55354 +
55355 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
55356 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
55357 + read_unlock(&grsec_exec_file_lock);
55358 + read_unlock(&tasklist_lock);
55359 + return 1;
55360 + }
55361 +
55362 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55363 + if (!(gr_status & GR_READY)) {
55364 + read_unlock(&grsec_exec_file_lock);
55365 + read_unlock(&tasklist_lock);
55366 + return 0;
55367 + }
55368 +#endif
55369 +
55370 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
55371 + read_unlock(&grsec_exec_file_lock);
55372 + read_unlock(&tasklist_lock);
55373 +
55374 + if (retmode & GR_NOPTRACE)
55375 + return 1;
55376 +
55377 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
55378 + && (current->acl != task->acl || (current->acl != current->role->root_label
55379 + && current->pid != task->pid)))
55380 + return 1;
55381 +
55382 + return 0;
55383 +}
55384 +
55385 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
55386 +{
55387 + if (unlikely(!(gr_status & GR_READY)))
55388 + return;
55389 +
55390 + if (!(current->role->roletype & GR_ROLE_GOD))
55391 + return;
55392 +
55393 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
55394 + p->role->rolename, gr_task_roletype_to_char(p),
55395 + p->acl->filename);
55396 +}
55397 +
55398 +int
55399 +gr_handle_ptrace(struct task_struct *task, const long request)
55400 +{
55401 + struct task_struct *tmp = task;
55402 + struct task_struct *curtemp = current;
55403 + __u32 retmode;
55404 +
55405 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55406 + if (unlikely(!(gr_status & GR_READY)))
55407 + return 0;
55408 +#endif
55409 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
55410 + read_lock(&tasklist_lock);
55411 + while (tmp->pid > 0) {
55412 + if (tmp == curtemp)
55413 + break;
55414 + tmp = tmp->real_parent;
55415 + }
55416 +
55417 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
55418 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
55419 + read_unlock(&tasklist_lock);
55420 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55421 + return 1;
55422 + }
55423 + read_unlock(&tasklist_lock);
55424 + }
55425 +
55426 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55427 + if (!(gr_status & GR_READY))
55428 + return 0;
55429 +#endif
55430 +
55431 + read_lock(&grsec_exec_file_lock);
55432 + if (unlikely(!task->exec_file)) {
55433 + read_unlock(&grsec_exec_file_lock);
55434 + return 0;
55435 + }
55436 +
55437 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
55438 + read_unlock(&grsec_exec_file_lock);
55439 +
55440 + if (retmode & GR_NOPTRACE) {
55441 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55442 + return 1;
55443 + }
55444 +
55445 + if (retmode & GR_PTRACERD) {
55446 + switch (request) {
55447 + case PTRACE_SEIZE:
55448 + case PTRACE_POKETEXT:
55449 + case PTRACE_POKEDATA:
55450 + case PTRACE_POKEUSR:
55451 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
55452 + case PTRACE_SETREGS:
55453 + case PTRACE_SETFPREGS:
55454 +#endif
55455 +#ifdef CONFIG_X86
55456 + case PTRACE_SETFPXREGS:
55457 +#endif
55458 +#ifdef CONFIG_ALTIVEC
55459 + case PTRACE_SETVRREGS:
55460 +#endif
55461 + return 1;
55462 + default:
55463 + return 0;
55464 + }
55465 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
55466 + !(current->role->roletype & GR_ROLE_GOD) &&
55467 + (current->acl != task->acl)) {
55468 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55469 + return 1;
55470 + }
55471 +
55472 + return 0;
55473 +}
55474 +
55475 +static int is_writable_mmap(const struct file *filp)
55476 +{
55477 + struct task_struct *task = current;
55478 + struct acl_object_label *obj, *obj2;
55479 +
55480 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
55481 + !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))) {
55482 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55483 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
55484 + task->role->root_label);
55485 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
55486 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
55487 + return 1;
55488 + }
55489 + }
55490 + return 0;
55491 +}
55492 +
55493 +int
55494 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
55495 +{
55496 + __u32 mode;
55497 +
55498 + if (unlikely(!file || !(prot & PROT_EXEC)))
55499 + return 1;
55500 +
55501 + if (is_writable_mmap(file))
55502 + return 0;
55503 +
55504 + mode =
55505 + gr_search_file(file->f_path.dentry,
55506 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55507 + file->f_path.mnt);
55508 +
55509 + if (!gr_tpe_allow(file))
55510 + return 0;
55511 +
55512 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55513 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55514 + return 0;
55515 + } else if (unlikely(!(mode & GR_EXEC))) {
55516 + return 0;
55517 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55518 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55519 + return 1;
55520 + }
55521 +
55522 + return 1;
55523 +}
55524 +
55525 +int
55526 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
55527 +{
55528 + __u32 mode;
55529 +
55530 + if (unlikely(!file || !(prot & PROT_EXEC)))
55531 + return 1;
55532 +
55533 + if (is_writable_mmap(file))
55534 + return 0;
55535 +
55536 + mode =
55537 + gr_search_file(file->f_path.dentry,
55538 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55539 + file->f_path.mnt);
55540 +
55541 + if (!gr_tpe_allow(file))
55542 + return 0;
55543 +
55544 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55545 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55546 + return 0;
55547 + } else if (unlikely(!(mode & GR_EXEC))) {
55548 + return 0;
55549 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55550 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55551 + return 1;
55552 + }
55553 +
55554 + return 1;
55555 +}
55556 +
55557 +void
55558 +gr_acl_handle_psacct(struct task_struct *task, const long code)
55559 +{
55560 + unsigned long runtime;
55561 + unsigned long cputime;
55562 + unsigned int wday, cday;
55563 + __u8 whr, chr;
55564 + __u8 wmin, cmin;
55565 + __u8 wsec, csec;
55566 + struct timespec timeval;
55567 +
55568 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
55569 + !(task->acl->mode & GR_PROCACCT)))
55570 + return;
55571 +
55572 + do_posix_clock_monotonic_gettime(&timeval);
55573 + runtime = timeval.tv_sec - task->start_time.tv_sec;
55574 + wday = runtime / (3600 * 24);
55575 + runtime -= wday * (3600 * 24);
55576 + whr = runtime / 3600;
55577 + runtime -= whr * 3600;
55578 + wmin = runtime / 60;
55579 + runtime -= wmin * 60;
55580 + wsec = runtime;
55581 +
55582 + cputime = (task->utime + task->stime) / HZ;
55583 + cday = cputime / (3600 * 24);
55584 + cputime -= cday * (3600 * 24);
55585 + chr = cputime / 3600;
55586 + cputime -= chr * 3600;
55587 + cmin = cputime / 60;
55588 + cputime -= cmin * 60;
55589 + csec = cputime;
55590 +
55591 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
55592 +
55593 + return;
55594 +}
55595 +
55596 +void gr_set_kernel_label(struct task_struct *task)
55597 +{
55598 + if (gr_status & GR_READY) {
55599 + task->role = kernel_role;
55600 + task->acl = kernel_role->root_label;
55601 + }
55602 + return;
55603 +}
55604 +
55605 +#ifdef CONFIG_TASKSTATS
55606 +int gr_is_taskstats_denied(int pid)
55607 +{
55608 + struct task_struct *task;
55609 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55610 + const struct cred *cred;
55611 +#endif
55612 + int ret = 0;
55613 +
55614 + /* restrict taskstats viewing to un-chrooted root users
55615 + who have the 'view' subject flag if the RBAC system is enabled
55616 + */
55617 +
55618 + rcu_read_lock();
55619 + read_lock(&tasklist_lock);
55620 + task = find_task_by_vpid(pid);
55621 + if (task) {
55622 +#ifdef CONFIG_GRKERNSEC_CHROOT
55623 + if (proc_is_chrooted(task))
55624 + ret = -EACCES;
55625 +#endif
55626 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55627 + cred = __task_cred(task);
55628 +#ifdef CONFIG_GRKERNSEC_PROC_USER
55629 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
55630 + ret = -EACCES;
55631 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55632 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, grsec_proc_gid))
55633 + ret = -EACCES;
55634 +#endif
55635 +#endif
55636 + if (gr_status & GR_READY) {
55637 + if (!(task->acl->mode & GR_VIEW))
55638 + ret = -EACCES;
55639 + }
55640 + } else
55641 + ret = -ENOENT;
55642 +
55643 + read_unlock(&tasklist_lock);
55644 + rcu_read_unlock();
55645 +
55646 + return ret;
55647 +}
55648 +#endif
55649 +
55650 +/* AUXV entries are filled via a descendant of search_binary_handler
55651 + after we've already applied the subject for the target
55652 +*/
55653 +int gr_acl_enable_at_secure(void)
55654 +{
55655 + if (unlikely(!(gr_status & GR_READY)))
55656 + return 0;
55657 +
55658 + if (current->acl->mode & GR_ATSECURE)
55659 + return 1;
55660 +
55661 + return 0;
55662 +}
55663 +
55664 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
55665 +{
55666 + struct task_struct *task = current;
55667 + struct dentry *dentry = file->f_path.dentry;
55668 + struct vfsmount *mnt = file->f_path.mnt;
55669 + struct acl_object_label *obj, *tmp;
55670 + struct acl_subject_label *subj;
55671 + unsigned int bufsize;
55672 + int is_not_root;
55673 + char *path;
55674 + dev_t dev = __get_dev(dentry);
55675 +
55676 + if (unlikely(!(gr_status & GR_READY)))
55677 + return 1;
55678 +
55679 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55680 + return 1;
55681 +
55682 + /* ignore Eric Biederman */
55683 + if (IS_PRIVATE(dentry->d_inode))
55684 + return 1;
55685 +
55686 + subj = task->acl;
55687 + read_lock(&gr_inode_lock);
55688 + do {
55689 + obj = lookup_acl_obj_label(ino, dev, subj);
55690 + if (obj != NULL) {
55691 + read_unlock(&gr_inode_lock);
55692 + return (obj->mode & GR_FIND) ? 1 : 0;
55693 + }
55694 + } while ((subj = subj->parent_subject));
55695 + read_unlock(&gr_inode_lock);
55696 +
55697 + /* this is purely an optimization since we're looking for an object
55698 + for the directory we're doing a readdir on
55699 + if it's possible for any globbed object to match the entry we're
55700 + filling into the directory, then the object we find here will be
55701 + an anchor point with attached globbed objects
55702 + */
55703 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
55704 + if (obj->globbed == NULL)
55705 + return (obj->mode & GR_FIND) ? 1 : 0;
55706 +
55707 + is_not_root = ((obj->filename[0] == '/') &&
55708 + (obj->filename[1] == '\0')) ? 0 : 1;
55709 + bufsize = PAGE_SIZE - namelen - is_not_root;
55710 +
55711 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
55712 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
55713 + return 1;
55714 +
55715 + preempt_disable();
55716 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
55717 + bufsize);
55718 +
55719 + bufsize = strlen(path);
55720 +
55721 + /* if base is "/", don't append an additional slash */
55722 + if (is_not_root)
55723 + *(path + bufsize) = '/';
55724 + memcpy(path + bufsize + is_not_root, name, namelen);
55725 + *(path + bufsize + namelen + is_not_root) = '\0';
55726 +
55727 + tmp = obj->globbed;
55728 + while (tmp) {
55729 + if (!glob_match(tmp->filename, path)) {
55730 + preempt_enable();
55731 + return (tmp->mode & GR_FIND) ? 1 : 0;
55732 + }
55733 + tmp = tmp->next;
55734 + }
55735 + preempt_enable();
55736 + return (obj->mode & GR_FIND) ? 1 : 0;
55737 +}
55738 +
55739 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
55740 +EXPORT_SYMBOL(gr_acl_is_enabled);
55741 +#endif
55742 +EXPORT_SYMBOL(gr_learn_resource);
55743 +EXPORT_SYMBOL(gr_set_kernel_label);
55744 +#ifdef CONFIG_SECURITY
55745 +EXPORT_SYMBOL(gr_check_user_change);
55746 +EXPORT_SYMBOL(gr_check_group_change);
55747 +#endif
55748 +
55749 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
55750 new file mode 100644
55751 index 0000000..34fefda
55752 --- /dev/null
55753 +++ b/grsecurity/gracl_alloc.c
55754 @@ -0,0 +1,105 @@
55755 +#include <linux/kernel.h>
55756 +#include <linux/mm.h>
55757 +#include <linux/slab.h>
55758 +#include <linux/vmalloc.h>
55759 +#include <linux/gracl.h>
55760 +#include <linux/grsecurity.h>
55761 +
55762 +static unsigned long alloc_stack_next = 1;
55763 +static unsigned long alloc_stack_size = 1;
55764 +static void **alloc_stack;
55765 +
55766 +static __inline__ int
55767 +alloc_pop(void)
55768 +{
55769 + if (alloc_stack_next == 1)
55770 + return 0;
55771 +
55772 + kfree(alloc_stack[alloc_stack_next - 2]);
55773 +
55774 + alloc_stack_next--;
55775 +
55776 + return 1;
55777 +}
55778 +
55779 +static __inline__ int
55780 +alloc_push(void *buf)
55781 +{
55782 + if (alloc_stack_next >= alloc_stack_size)
55783 + return 1;
55784 +
55785 + alloc_stack[alloc_stack_next - 1] = buf;
55786 +
55787 + alloc_stack_next++;
55788 +
55789 + return 0;
55790 +}
55791 +
55792 +void *
55793 +acl_alloc(unsigned long len)
55794 +{
55795 + void *ret = NULL;
55796 +
55797 + if (!len || len > PAGE_SIZE)
55798 + goto out;
55799 +
55800 + ret = kmalloc(len, GFP_KERNEL);
55801 +
55802 + if (ret) {
55803 + if (alloc_push(ret)) {
55804 + kfree(ret);
55805 + ret = NULL;
55806 + }
55807 + }
55808 +
55809 +out:
55810 + return ret;
55811 +}
55812 +
55813 +void *
55814 +acl_alloc_num(unsigned long num, unsigned long len)
55815 +{
55816 + if (!len || (num > (PAGE_SIZE / len)))
55817 + return NULL;
55818 +
55819 + return acl_alloc(num * len);
55820 +}
55821 +
55822 +void
55823 +acl_free_all(void)
55824 +{
55825 + if (gr_acl_is_enabled() || !alloc_stack)
55826 + return;
55827 +
55828 + while (alloc_pop()) ;
55829 +
55830 + if (alloc_stack) {
55831 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
55832 + kfree(alloc_stack);
55833 + else
55834 + vfree(alloc_stack);
55835 + }
55836 +
55837 + alloc_stack = NULL;
55838 + alloc_stack_size = 1;
55839 + alloc_stack_next = 1;
55840 +
55841 + return;
55842 +}
55843 +
55844 +int
55845 +acl_alloc_stack_init(unsigned long size)
55846 +{
55847 + if ((size * sizeof (void *)) <= PAGE_SIZE)
55848 + alloc_stack =
55849 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
55850 + else
55851 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
55852 +
55853 + alloc_stack_size = size;
55854 +
55855 + if (!alloc_stack)
55856 + return 0;
55857 + else
55858 + return 1;
55859 +}
55860 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
55861 new file mode 100644
55862 index 0000000..6d21049
55863 --- /dev/null
55864 +++ b/grsecurity/gracl_cap.c
55865 @@ -0,0 +1,110 @@
55866 +#include <linux/kernel.h>
55867 +#include <linux/module.h>
55868 +#include <linux/sched.h>
55869 +#include <linux/gracl.h>
55870 +#include <linux/grsecurity.h>
55871 +#include <linux/grinternal.h>
55872 +
55873 +extern const char *captab_log[];
55874 +extern int captab_log_entries;
55875 +
55876 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
55877 +{
55878 + struct acl_subject_label *curracl;
55879 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55880 + kernel_cap_t cap_audit = __cap_empty_set;
55881 +
55882 + if (!gr_acl_is_enabled())
55883 + return 1;
55884 +
55885 + curracl = task->acl;
55886 +
55887 + cap_drop = curracl->cap_lower;
55888 + cap_mask = curracl->cap_mask;
55889 + cap_audit = curracl->cap_invert_audit;
55890 +
55891 + while ((curracl = curracl->parent_subject)) {
55892 + /* if the cap isn't specified in the current computed mask but is specified in the
55893 + current level subject, and is lowered in the current level subject, then add
55894 + it to the set of dropped capabilities
55895 + otherwise, add the current level subject's mask to the current computed mask
55896 + */
55897 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55898 + cap_raise(cap_mask, cap);
55899 + if (cap_raised(curracl->cap_lower, cap))
55900 + cap_raise(cap_drop, cap);
55901 + if (cap_raised(curracl->cap_invert_audit, cap))
55902 + cap_raise(cap_audit, cap);
55903 + }
55904 + }
55905 +
55906 + if (!cap_raised(cap_drop, cap)) {
55907 + if (cap_raised(cap_audit, cap))
55908 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
55909 + return 1;
55910 + }
55911 +
55912 + curracl = task->acl;
55913 +
55914 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
55915 + && cap_raised(cred->cap_effective, cap)) {
55916 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55917 + task->role->roletype, cred->uid,
55918 + cred->gid, task->exec_file ?
55919 + gr_to_filename(task->exec_file->f_path.dentry,
55920 + task->exec_file->f_path.mnt) : curracl->filename,
55921 + curracl->filename, 0UL,
55922 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
55923 + return 1;
55924 + }
55925 +
55926 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
55927 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
55928 +
55929 + return 0;
55930 +}
55931 +
55932 +int
55933 +gr_acl_is_capable(const int cap)
55934 +{
55935 + return gr_task_acl_is_capable(current, current_cred(), cap);
55936 +}
55937 +
55938 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
55939 +{
55940 + struct acl_subject_label *curracl;
55941 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55942 +
55943 + if (!gr_acl_is_enabled())
55944 + return 1;
55945 +
55946 + curracl = task->acl;
55947 +
55948 + cap_drop = curracl->cap_lower;
55949 + cap_mask = curracl->cap_mask;
55950 +
55951 + while ((curracl = curracl->parent_subject)) {
55952 + /* if the cap isn't specified in the current computed mask but is specified in the
55953 + current level subject, and is lowered in the current level subject, then add
55954 + it to the set of dropped capabilities
55955 + otherwise, add the current level subject's mask to the current computed mask
55956 + */
55957 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55958 + cap_raise(cap_mask, cap);
55959 + if (cap_raised(curracl->cap_lower, cap))
55960 + cap_raise(cap_drop, cap);
55961 + }
55962 + }
55963 +
55964 + if (!cap_raised(cap_drop, cap))
55965 + return 1;
55966 +
55967 + return 0;
55968 +}
55969 +
55970 +int
55971 +gr_acl_is_capable_nolog(const int cap)
55972 +{
55973 + return gr_task_acl_is_capable_nolog(current, cap);
55974 +}
55975 +
55976 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
55977 new file mode 100644
55978 index 0000000..d28e241
55979 --- /dev/null
55980 +++ b/grsecurity/gracl_fs.c
55981 @@ -0,0 +1,437 @@
55982 +#include <linux/kernel.h>
55983 +#include <linux/sched.h>
55984 +#include <linux/types.h>
55985 +#include <linux/fs.h>
55986 +#include <linux/file.h>
55987 +#include <linux/stat.h>
55988 +#include <linux/grsecurity.h>
55989 +#include <linux/grinternal.h>
55990 +#include <linux/gracl.h>
55991 +
55992 +umode_t
55993 +gr_acl_umask(void)
55994 +{
55995 + if (unlikely(!gr_acl_is_enabled()))
55996 + return 0;
55997 +
55998 + return current->role->umask;
55999 +}
56000 +
56001 +__u32
56002 +gr_acl_handle_hidden_file(const struct dentry * dentry,
56003 + const struct vfsmount * mnt)
56004 +{
56005 + __u32 mode;
56006 +
56007 + if (unlikely(!dentry->d_inode))
56008 + return GR_FIND;
56009 +
56010 + mode =
56011 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
56012 +
56013 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
56014 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
56015 + return mode;
56016 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
56017 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
56018 + return 0;
56019 + } else if (unlikely(!(mode & GR_FIND)))
56020 + return 0;
56021 +
56022 + return GR_FIND;
56023 +}
56024 +
56025 +__u32
56026 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
56027 + int acc_mode)
56028 +{
56029 + __u32 reqmode = GR_FIND;
56030 + __u32 mode;
56031 +
56032 + if (unlikely(!dentry->d_inode))
56033 + return reqmode;
56034 +
56035 + if (acc_mode & MAY_APPEND)
56036 + reqmode |= GR_APPEND;
56037 + else if (acc_mode & MAY_WRITE)
56038 + reqmode |= GR_WRITE;
56039 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
56040 + reqmode |= GR_READ;
56041 +
56042 + mode =
56043 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
56044 + mnt);
56045 +
56046 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56047 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
56048 + reqmode & GR_READ ? " reading" : "",
56049 + reqmode & GR_WRITE ? " writing" : reqmode &
56050 + GR_APPEND ? " appending" : "");
56051 + return reqmode;
56052 + } else
56053 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56054 + {
56055 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
56056 + reqmode & GR_READ ? " reading" : "",
56057 + reqmode & GR_WRITE ? " writing" : reqmode &
56058 + GR_APPEND ? " appending" : "");
56059 + return 0;
56060 + } else if (unlikely((mode & reqmode) != reqmode))
56061 + return 0;
56062 +
56063 + return reqmode;
56064 +}
56065 +
56066 +__u32
56067 +gr_acl_handle_creat(const struct dentry * dentry,
56068 + const struct dentry * p_dentry,
56069 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
56070 + const int imode)
56071 +{
56072 + __u32 reqmode = GR_WRITE | GR_CREATE;
56073 + __u32 mode;
56074 +
56075 + if (acc_mode & MAY_APPEND)
56076 + reqmode |= GR_APPEND;
56077 + // if a directory was required or the directory already exists, then
56078 + // don't count this open as a read
56079 + if ((acc_mode & MAY_READ) &&
56080 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
56081 + reqmode |= GR_READ;
56082 + if ((open_flags & O_CREAT) &&
56083 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
56084 + reqmode |= GR_SETID;
56085 +
56086 + mode =
56087 + gr_check_create(dentry, p_dentry, p_mnt,
56088 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
56089 +
56090 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56091 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
56092 + reqmode & GR_READ ? " reading" : "",
56093 + reqmode & GR_WRITE ? " writing" : reqmode &
56094 + GR_APPEND ? " appending" : "");
56095 + return reqmode;
56096 + } else
56097 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56098 + {
56099 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
56100 + reqmode & GR_READ ? " reading" : "",
56101 + reqmode & GR_WRITE ? " writing" : reqmode &
56102 + GR_APPEND ? " appending" : "");
56103 + return 0;
56104 + } else if (unlikely((mode & reqmode) != reqmode))
56105 + return 0;
56106 +
56107 + return reqmode;
56108 +}
56109 +
56110 +__u32
56111 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
56112 + const int fmode)
56113 +{
56114 + __u32 mode, reqmode = GR_FIND;
56115 +
56116 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
56117 + reqmode |= GR_EXEC;
56118 + if (fmode & S_IWOTH)
56119 + reqmode |= GR_WRITE;
56120 + if (fmode & S_IROTH)
56121 + reqmode |= GR_READ;
56122 +
56123 + mode =
56124 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
56125 + mnt);
56126 +
56127 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56128 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
56129 + reqmode & GR_READ ? " reading" : "",
56130 + reqmode & GR_WRITE ? " writing" : "",
56131 + reqmode & GR_EXEC ? " executing" : "");
56132 + return reqmode;
56133 + } else
56134 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56135 + {
56136 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
56137 + reqmode & GR_READ ? " reading" : "",
56138 + reqmode & GR_WRITE ? " writing" : "",
56139 + reqmode & GR_EXEC ? " executing" : "");
56140 + return 0;
56141 + } else if (unlikely((mode & reqmode) != reqmode))
56142 + return 0;
56143 +
56144 + return reqmode;
56145 +}
56146 +
56147 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
56148 +{
56149 + __u32 mode;
56150 +
56151 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
56152 +
56153 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
56154 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
56155 + return mode;
56156 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
56157 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
56158 + return 0;
56159 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
56160 + return 0;
56161 +
56162 + return (reqmode);
56163 +}
56164 +
56165 +__u32
56166 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
56167 +{
56168 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
56169 +}
56170 +
56171 +__u32
56172 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
56173 +{
56174 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
56175 +}
56176 +
56177 +__u32
56178 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
56179 +{
56180 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
56181 +}
56182 +
56183 +__u32
56184 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
56185 +{
56186 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
56187 +}
56188 +
56189 +__u32
56190 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
56191 + umode_t *modeptr)
56192 +{
56193 + umode_t mode;
56194 +
56195 + *modeptr &= ~gr_acl_umask();
56196 + mode = *modeptr;
56197 +
56198 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
56199 + return 1;
56200 +
56201 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
56202 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
56203 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
56204 + GR_CHMOD_ACL_MSG);
56205 + } else {
56206 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
56207 + }
56208 +}
56209 +
56210 +__u32
56211 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
56212 +{
56213 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
56214 +}
56215 +
56216 +__u32
56217 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
56218 +{
56219 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
56220 +}
56221 +
56222 +__u32
56223 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
56224 +{
56225 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
56226 +}
56227 +
56228 +__u32
56229 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
56230 +{
56231 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
56232 + GR_UNIXCONNECT_ACL_MSG);
56233 +}
56234 +
56235 +/* hardlinks require at minimum create and link permission,
56236 + any additional privilege required is based on the
56237 + privilege of the file being linked to
56238 +*/
56239 +__u32
56240 +gr_acl_handle_link(const struct dentry * new_dentry,
56241 + const struct dentry * parent_dentry,
56242 + const struct vfsmount * parent_mnt,
56243 + const struct dentry * old_dentry,
56244 + const struct vfsmount * old_mnt, const char *to)
56245 +{
56246 + __u32 mode;
56247 + __u32 needmode = GR_CREATE | GR_LINK;
56248 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
56249 +
56250 + mode =
56251 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
56252 + old_mnt);
56253 +
56254 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
56255 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
56256 + return mode;
56257 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56258 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
56259 + return 0;
56260 + } else if (unlikely((mode & needmode) != needmode))
56261 + return 0;
56262 +
56263 + return 1;
56264 +}
56265 +
56266 +__u32
56267 +gr_acl_handle_symlink(const struct dentry * new_dentry,
56268 + const struct dentry * parent_dentry,
56269 + const struct vfsmount * parent_mnt, const char *from)
56270 +{
56271 + __u32 needmode = GR_WRITE | GR_CREATE;
56272 + __u32 mode;
56273 +
56274 + mode =
56275 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
56276 + GR_CREATE | GR_AUDIT_CREATE |
56277 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
56278 +
56279 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
56280 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
56281 + return mode;
56282 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56283 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
56284 + return 0;
56285 + } else if (unlikely((mode & needmode) != needmode))
56286 + return 0;
56287 +
56288 + return (GR_WRITE | GR_CREATE);
56289 +}
56290 +
56291 +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)
56292 +{
56293 + __u32 mode;
56294 +
56295 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
56296 +
56297 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
56298 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
56299 + return mode;
56300 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
56301 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
56302 + return 0;
56303 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
56304 + return 0;
56305 +
56306 + return (reqmode);
56307 +}
56308 +
56309 +__u32
56310 +gr_acl_handle_mknod(const struct dentry * new_dentry,
56311 + const struct dentry * parent_dentry,
56312 + const struct vfsmount * parent_mnt,
56313 + const int mode)
56314 +{
56315 + __u32 reqmode = GR_WRITE | GR_CREATE;
56316 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
56317 + reqmode |= GR_SETID;
56318 +
56319 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56320 + reqmode, GR_MKNOD_ACL_MSG);
56321 +}
56322 +
56323 +__u32
56324 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
56325 + const struct dentry *parent_dentry,
56326 + const struct vfsmount *parent_mnt)
56327 +{
56328 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56329 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
56330 +}
56331 +
56332 +#define RENAME_CHECK_SUCCESS(old, new) \
56333 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
56334 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
56335 +
56336 +int
56337 +gr_acl_handle_rename(struct dentry *new_dentry,
56338 + struct dentry *parent_dentry,
56339 + const struct vfsmount *parent_mnt,
56340 + struct dentry *old_dentry,
56341 + struct inode *old_parent_inode,
56342 + struct vfsmount *old_mnt, const char *newname)
56343 +{
56344 + __u32 comp1, comp2;
56345 + int error = 0;
56346 +
56347 + if (unlikely(!gr_acl_is_enabled()))
56348 + return 0;
56349 +
56350 + if (!new_dentry->d_inode) {
56351 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
56352 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
56353 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
56354 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
56355 + GR_DELETE | GR_AUDIT_DELETE |
56356 + GR_AUDIT_READ | GR_AUDIT_WRITE |
56357 + GR_SUPPRESS, old_mnt);
56358 + } else {
56359 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
56360 + GR_CREATE | GR_DELETE |
56361 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
56362 + GR_AUDIT_READ | GR_AUDIT_WRITE |
56363 + GR_SUPPRESS, parent_mnt);
56364 + comp2 =
56365 + gr_search_file(old_dentry,
56366 + GR_READ | GR_WRITE | GR_AUDIT_READ |
56367 + GR_DELETE | GR_AUDIT_DELETE |
56368 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
56369 + }
56370 +
56371 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
56372 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
56373 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56374 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
56375 + && !(comp2 & GR_SUPPRESS)) {
56376 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56377 + error = -EACCES;
56378 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
56379 + error = -EACCES;
56380 +
56381 + return error;
56382 +}
56383 +
56384 +void
56385 +gr_acl_handle_exit(void)
56386 +{
56387 + u16 id;
56388 + char *rolename;
56389 + struct file *exec_file;
56390 +
56391 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
56392 + !(current->role->roletype & GR_ROLE_PERSIST))) {
56393 + id = current->acl_role_id;
56394 + rolename = current->role->rolename;
56395 + gr_set_acls(1);
56396 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
56397 + }
56398 +
56399 + write_lock(&grsec_exec_file_lock);
56400 + exec_file = current->exec_file;
56401 + current->exec_file = NULL;
56402 + write_unlock(&grsec_exec_file_lock);
56403 +
56404 + if (exec_file)
56405 + fput(exec_file);
56406 +}
56407 +
56408 +int
56409 +gr_acl_handle_procpidmem(const struct task_struct *task)
56410 +{
56411 + if (unlikely(!gr_acl_is_enabled()))
56412 + return 0;
56413 +
56414 + if (task != current && task->acl->mode & GR_PROTPROCFD)
56415 + return -EACCES;
56416 +
56417 + return 0;
56418 +}
56419 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
56420 new file mode 100644
56421 index 0000000..58800a7
56422 --- /dev/null
56423 +++ b/grsecurity/gracl_ip.c
56424 @@ -0,0 +1,384 @@
56425 +#include <linux/kernel.h>
56426 +#include <asm/uaccess.h>
56427 +#include <asm/errno.h>
56428 +#include <net/sock.h>
56429 +#include <linux/file.h>
56430 +#include <linux/fs.h>
56431 +#include <linux/net.h>
56432 +#include <linux/in.h>
56433 +#include <linux/skbuff.h>
56434 +#include <linux/ip.h>
56435 +#include <linux/udp.h>
56436 +#include <linux/types.h>
56437 +#include <linux/sched.h>
56438 +#include <linux/netdevice.h>
56439 +#include <linux/inetdevice.h>
56440 +#include <linux/gracl.h>
56441 +#include <linux/grsecurity.h>
56442 +#include <linux/grinternal.h>
56443 +
56444 +#define GR_BIND 0x01
56445 +#define GR_CONNECT 0x02
56446 +#define GR_INVERT 0x04
56447 +#define GR_BINDOVERRIDE 0x08
56448 +#define GR_CONNECTOVERRIDE 0x10
56449 +#define GR_SOCK_FAMILY 0x20
56450 +
56451 +static const char * gr_protocols[IPPROTO_MAX] = {
56452 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
56453 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
56454 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
56455 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
56456 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
56457 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
56458 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
56459 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
56460 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
56461 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
56462 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
56463 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
56464 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
56465 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
56466 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
56467 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
56468 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
56469 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
56470 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
56471 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
56472 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
56473 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
56474 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
56475 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
56476 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
56477 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
56478 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
56479 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
56480 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
56481 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
56482 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
56483 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
56484 + };
56485 +
56486 +static const char * gr_socktypes[SOCK_MAX] = {
56487 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
56488 + "unknown:7", "unknown:8", "unknown:9", "packet"
56489 + };
56490 +
56491 +static const char * gr_sockfamilies[AF_MAX+1] = {
56492 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
56493 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
56494 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
56495 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
56496 + };
56497 +
56498 +const char *
56499 +gr_proto_to_name(unsigned char proto)
56500 +{
56501 + return gr_protocols[proto];
56502 +}
56503 +
56504 +const char *
56505 +gr_socktype_to_name(unsigned char type)
56506 +{
56507 + return gr_socktypes[type];
56508 +}
56509 +
56510 +const char *
56511 +gr_sockfamily_to_name(unsigned char family)
56512 +{
56513 + return gr_sockfamilies[family];
56514 +}
56515 +
56516 +int
56517 +gr_search_socket(const int domain, const int type, const int protocol)
56518 +{
56519 + struct acl_subject_label *curr;
56520 + const struct cred *cred = current_cred();
56521 +
56522 + if (unlikely(!gr_acl_is_enabled()))
56523 + goto exit;
56524 +
56525 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
56526 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
56527 + goto exit; // let the kernel handle it
56528 +
56529 + curr = current->acl;
56530 +
56531 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
56532 + /* the family is allowed, if this is PF_INET allow it only if
56533 + the extra sock type/protocol checks pass */
56534 + if (domain == PF_INET)
56535 + goto inet_check;
56536 + goto exit;
56537 + } else {
56538 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56539 + __u32 fakeip = 0;
56540 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56541 + current->role->roletype, cred->uid,
56542 + cred->gid, current->exec_file ?
56543 + gr_to_filename(current->exec_file->f_path.dentry,
56544 + current->exec_file->f_path.mnt) :
56545 + curr->filename, curr->filename,
56546 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
56547 + &current->signal->saved_ip);
56548 + goto exit;
56549 + }
56550 + goto exit_fail;
56551 + }
56552 +
56553 +inet_check:
56554 + /* the rest of this checking is for IPv4 only */
56555 + if (!curr->ips)
56556 + goto exit;
56557 +
56558 + if ((curr->ip_type & (1 << type)) &&
56559 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
56560 + goto exit;
56561 +
56562 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56563 + /* we don't place acls on raw sockets , and sometimes
56564 + dgram/ip sockets are opened for ioctl and not
56565 + bind/connect, so we'll fake a bind learn log */
56566 + if (type == SOCK_RAW || type == SOCK_PACKET) {
56567 + __u32 fakeip = 0;
56568 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56569 + current->role->roletype, cred->uid,
56570 + cred->gid, current->exec_file ?
56571 + gr_to_filename(current->exec_file->f_path.dentry,
56572 + current->exec_file->f_path.mnt) :
56573 + curr->filename, curr->filename,
56574 + &fakeip, 0, type,
56575 + protocol, GR_CONNECT, &current->signal->saved_ip);
56576 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
56577 + __u32 fakeip = 0;
56578 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56579 + current->role->roletype, cred->uid,
56580 + cred->gid, current->exec_file ?
56581 + gr_to_filename(current->exec_file->f_path.dentry,
56582 + current->exec_file->f_path.mnt) :
56583 + curr->filename, curr->filename,
56584 + &fakeip, 0, type,
56585 + protocol, GR_BIND, &current->signal->saved_ip);
56586 + }
56587 + /* we'll log when they use connect or bind */
56588 + goto exit;
56589 + }
56590 +
56591 +exit_fail:
56592 + if (domain == PF_INET)
56593 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
56594 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
56595 + else
56596 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
56597 + gr_socktype_to_name(type), protocol);
56598 +
56599 + return 0;
56600 +exit:
56601 + return 1;
56602 +}
56603 +
56604 +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)
56605 +{
56606 + if ((ip->mode & mode) &&
56607 + (ip_port >= ip->low) &&
56608 + (ip_port <= ip->high) &&
56609 + ((ntohl(ip_addr) & our_netmask) ==
56610 + (ntohl(our_addr) & our_netmask))
56611 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
56612 + && (ip->type & (1 << type))) {
56613 + if (ip->mode & GR_INVERT)
56614 + return 2; // specifically denied
56615 + else
56616 + return 1; // allowed
56617 + }
56618 +
56619 + return 0; // not specifically allowed, may continue parsing
56620 +}
56621 +
56622 +static int
56623 +gr_search_connectbind(const int full_mode, struct sock *sk,
56624 + struct sockaddr_in *addr, const int type)
56625 +{
56626 + char iface[IFNAMSIZ] = {0};
56627 + struct acl_subject_label *curr;
56628 + struct acl_ip_label *ip;
56629 + struct inet_sock *isk;
56630 + struct net_device *dev;
56631 + struct in_device *idev;
56632 + unsigned long i;
56633 + int ret;
56634 + int mode = full_mode & (GR_BIND | GR_CONNECT);
56635 + __u32 ip_addr = 0;
56636 + __u32 our_addr;
56637 + __u32 our_netmask;
56638 + char *p;
56639 + __u16 ip_port = 0;
56640 + const struct cred *cred = current_cred();
56641 +
56642 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
56643 + return 0;
56644 +
56645 + curr = current->acl;
56646 + isk = inet_sk(sk);
56647 +
56648 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
56649 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
56650 + addr->sin_addr.s_addr = curr->inaddr_any_override;
56651 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
56652 + struct sockaddr_in saddr;
56653 + int err;
56654 +
56655 + saddr.sin_family = AF_INET;
56656 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
56657 + saddr.sin_port = isk->inet_sport;
56658 +
56659 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56660 + if (err)
56661 + return err;
56662 +
56663 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56664 + if (err)
56665 + return err;
56666 + }
56667 +
56668 + if (!curr->ips)
56669 + return 0;
56670 +
56671 + ip_addr = addr->sin_addr.s_addr;
56672 + ip_port = ntohs(addr->sin_port);
56673 +
56674 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56675 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56676 + current->role->roletype, cred->uid,
56677 + cred->gid, current->exec_file ?
56678 + gr_to_filename(current->exec_file->f_path.dentry,
56679 + current->exec_file->f_path.mnt) :
56680 + curr->filename, curr->filename,
56681 + &ip_addr, ip_port, type,
56682 + sk->sk_protocol, mode, &current->signal->saved_ip);
56683 + return 0;
56684 + }
56685 +
56686 + for (i = 0; i < curr->ip_num; i++) {
56687 + ip = *(curr->ips + i);
56688 + if (ip->iface != NULL) {
56689 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
56690 + p = strchr(iface, ':');
56691 + if (p != NULL)
56692 + *p = '\0';
56693 + dev = dev_get_by_name(sock_net(sk), iface);
56694 + if (dev == NULL)
56695 + continue;
56696 + idev = in_dev_get(dev);
56697 + if (idev == NULL) {
56698 + dev_put(dev);
56699 + continue;
56700 + }
56701 + rcu_read_lock();
56702 + for_ifa(idev) {
56703 + if (!strcmp(ip->iface, ifa->ifa_label)) {
56704 + our_addr = ifa->ifa_address;
56705 + our_netmask = 0xffffffff;
56706 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56707 + if (ret == 1) {
56708 + rcu_read_unlock();
56709 + in_dev_put(idev);
56710 + dev_put(dev);
56711 + return 0;
56712 + } else if (ret == 2) {
56713 + rcu_read_unlock();
56714 + in_dev_put(idev);
56715 + dev_put(dev);
56716 + goto denied;
56717 + }
56718 + }
56719 + } endfor_ifa(idev);
56720 + rcu_read_unlock();
56721 + in_dev_put(idev);
56722 + dev_put(dev);
56723 + } else {
56724 + our_addr = ip->addr;
56725 + our_netmask = ip->netmask;
56726 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56727 + if (ret == 1)
56728 + return 0;
56729 + else if (ret == 2)
56730 + goto denied;
56731 + }
56732 + }
56733 +
56734 +denied:
56735 + if (mode == GR_BIND)
56736 + 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));
56737 + else if (mode == GR_CONNECT)
56738 + 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));
56739 +
56740 + return -EACCES;
56741 +}
56742 +
56743 +int
56744 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
56745 +{
56746 + /* always allow disconnection of dgram sockets with connect */
56747 + if (addr->sin_family == AF_UNSPEC)
56748 + return 0;
56749 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
56750 +}
56751 +
56752 +int
56753 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
56754 +{
56755 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
56756 +}
56757 +
56758 +int gr_search_listen(struct socket *sock)
56759 +{
56760 + struct sock *sk = sock->sk;
56761 + struct sockaddr_in addr;
56762 +
56763 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56764 + addr.sin_port = inet_sk(sk)->inet_sport;
56765 +
56766 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56767 +}
56768 +
56769 +int gr_search_accept(struct socket *sock)
56770 +{
56771 + struct sock *sk = sock->sk;
56772 + struct sockaddr_in addr;
56773 +
56774 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56775 + addr.sin_port = inet_sk(sk)->inet_sport;
56776 +
56777 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56778 +}
56779 +
56780 +int
56781 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
56782 +{
56783 + if (addr)
56784 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
56785 + else {
56786 + struct sockaddr_in sin;
56787 + const struct inet_sock *inet = inet_sk(sk);
56788 +
56789 + sin.sin_addr.s_addr = inet->inet_daddr;
56790 + sin.sin_port = inet->inet_dport;
56791 +
56792 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56793 + }
56794 +}
56795 +
56796 +int
56797 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
56798 +{
56799 + struct sockaddr_in sin;
56800 +
56801 + if (unlikely(skb->len < sizeof (struct udphdr)))
56802 + return 0; // skip this packet
56803 +
56804 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
56805 + sin.sin_port = udp_hdr(skb)->source;
56806 +
56807 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56808 +}
56809 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
56810 new file mode 100644
56811 index 0000000..25f54ef
56812 --- /dev/null
56813 +++ b/grsecurity/gracl_learn.c
56814 @@ -0,0 +1,207 @@
56815 +#include <linux/kernel.h>
56816 +#include <linux/mm.h>
56817 +#include <linux/sched.h>
56818 +#include <linux/poll.h>
56819 +#include <linux/string.h>
56820 +#include <linux/file.h>
56821 +#include <linux/types.h>
56822 +#include <linux/vmalloc.h>
56823 +#include <linux/grinternal.h>
56824 +
56825 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
56826 + size_t count, loff_t *ppos);
56827 +extern int gr_acl_is_enabled(void);
56828 +
56829 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
56830 +static int gr_learn_attached;
56831 +
56832 +/* use a 512k buffer */
56833 +#define LEARN_BUFFER_SIZE (512 * 1024)
56834 +
56835 +static DEFINE_SPINLOCK(gr_learn_lock);
56836 +static DEFINE_MUTEX(gr_learn_user_mutex);
56837 +
56838 +/* we need to maintain two buffers, so that the kernel context of grlearn
56839 + uses a semaphore around the userspace copying, and the other kernel contexts
56840 + use a spinlock when copying into the buffer, since they cannot sleep
56841 +*/
56842 +static char *learn_buffer;
56843 +static char *learn_buffer_user;
56844 +static int learn_buffer_len;
56845 +static int learn_buffer_user_len;
56846 +
56847 +static ssize_t
56848 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
56849 +{
56850 + DECLARE_WAITQUEUE(wait, current);
56851 + ssize_t retval = 0;
56852 +
56853 + add_wait_queue(&learn_wait, &wait);
56854 + set_current_state(TASK_INTERRUPTIBLE);
56855 + do {
56856 + mutex_lock(&gr_learn_user_mutex);
56857 + spin_lock(&gr_learn_lock);
56858 + if (learn_buffer_len)
56859 + break;
56860 + spin_unlock(&gr_learn_lock);
56861 + mutex_unlock(&gr_learn_user_mutex);
56862 + if (file->f_flags & O_NONBLOCK) {
56863 + retval = -EAGAIN;
56864 + goto out;
56865 + }
56866 + if (signal_pending(current)) {
56867 + retval = -ERESTARTSYS;
56868 + goto out;
56869 + }
56870 +
56871 + schedule();
56872 + } while (1);
56873 +
56874 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
56875 + learn_buffer_user_len = learn_buffer_len;
56876 + retval = learn_buffer_len;
56877 + learn_buffer_len = 0;
56878 +
56879 + spin_unlock(&gr_learn_lock);
56880 +
56881 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
56882 + retval = -EFAULT;
56883 +
56884 + mutex_unlock(&gr_learn_user_mutex);
56885 +out:
56886 + set_current_state(TASK_RUNNING);
56887 + remove_wait_queue(&learn_wait, &wait);
56888 + return retval;
56889 +}
56890 +
56891 +static unsigned int
56892 +poll_learn(struct file * file, poll_table * wait)
56893 +{
56894 + poll_wait(file, &learn_wait, wait);
56895 +
56896 + if (learn_buffer_len)
56897 + return (POLLIN | POLLRDNORM);
56898 +
56899 + return 0;
56900 +}
56901 +
56902 +void
56903 +gr_clear_learn_entries(void)
56904 +{
56905 + char *tmp;
56906 +
56907 + mutex_lock(&gr_learn_user_mutex);
56908 + spin_lock(&gr_learn_lock);
56909 + tmp = learn_buffer;
56910 + learn_buffer = NULL;
56911 + spin_unlock(&gr_learn_lock);
56912 + if (tmp)
56913 + vfree(tmp);
56914 + if (learn_buffer_user != NULL) {
56915 + vfree(learn_buffer_user);
56916 + learn_buffer_user = NULL;
56917 + }
56918 + learn_buffer_len = 0;
56919 + mutex_unlock(&gr_learn_user_mutex);
56920 +
56921 + return;
56922 +}
56923 +
56924 +void
56925 +gr_add_learn_entry(const char *fmt, ...)
56926 +{
56927 + va_list args;
56928 + unsigned int len;
56929 +
56930 + if (!gr_learn_attached)
56931 + return;
56932 +
56933 + spin_lock(&gr_learn_lock);
56934 +
56935 + /* leave a gap at the end so we know when it's "full" but don't have to
56936 + compute the exact length of the string we're trying to append
56937 + */
56938 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
56939 + spin_unlock(&gr_learn_lock);
56940 + wake_up_interruptible(&learn_wait);
56941 + return;
56942 + }
56943 + if (learn_buffer == NULL) {
56944 + spin_unlock(&gr_learn_lock);
56945 + return;
56946 + }
56947 +
56948 + va_start(args, fmt);
56949 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
56950 + va_end(args);
56951 +
56952 + learn_buffer_len += len + 1;
56953 +
56954 + spin_unlock(&gr_learn_lock);
56955 + wake_up_interruptible(&learn_wait);
56956 +
56957 + return;
56958 +}
56959 +
56960 +static int
56961 +open_learn(struct inode *inode, struct file *file)
56962 +{
56963 + if (file->f_mode & FMODE_READ && gr_learn_attached)
56964 + return -EBUSY;
56965 + if (file->f_mode & FMODE_READ) {
56966 + int retval = 0;
56967 + mutex_lock(&gr_learn_user_mutex);
56968 + if (learn_buffer == NULL)
56969 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
56970 + if (learn_buffer_user == NULL)
56971 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
56972 + if (learn_buffer == NULL) {
56973 + retval = -ENOMEM;
56974 + goto out_error;
56975 + }
56976 + if (learn_buffer_user == NULL) {
56977 + retval = -ENOMEM;
56978 + goto out_error;
56979 + }
56980 + learn_buffer_len = 0;
56981 + learn_buffer_user_len = 0;
56982 + gr_learn_attached = 1;
56983 +out_error:
56984 + mutex_unlock(&gr_learn_user_mutex);
56985 + return retval;
56986 + }
56987 + return 0;
56988 +}
56989 +
56990 +static int
56991 +close_learn(struct inode *inode, struct file *file)
56992 +{
56993 + if (file->f_mode & FMODE_READ) {
56994 + char *tmp = NULL;
56995 + mutex_lock(&gr_learn_user_mutex);
56996 + spin_lock(&gr_learn_lock);
56997 + tmp = learn_buffer;
56998 + learn_buffer = NULL;
56999 + spin_unlock(&gr_learn_lock);
57000 + if (tmp)
57001 + vfree(tmp);
57002 + if (learn_buffer_user != NULL) {
57003 + vfree(learn_buffer_user);
57004 + learn_buffer_user = NULL;
57005 + }
57006 + learn_buffer_len = 0;
57007 + learn_buffer_user_len = 0;
57008 + gr_learn_attached = 0;
57009 + mutex_unlock(&gr_learn_user_mutex);
57010 + }
57011 +
57012 + return 0;
57013 +}
57014 +
57015 +const struct file_operations grsec_fops = {
57016 + .read = read_learn,
57017 + .write = write_grsec_handler,
57018 + .open = open_learn,
57019 + .release = close_learn,
57020 + .poll = poll_learn,
57021 +};
57022 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
57023 new file mode 100644
57024 index 0000000..39645c9
57025 --- /dev/null
57026 +++ b/grsecurity/gracl_res.c
57027 @@ -0,0 +1,68 @@
57028 +#include <linux/kernel.h>
57029 +#include <linux/sched.h>
57030 +#include <linux/gracl.h>
57031 +#include <linux/grinternal.h>
57032 +
57033 +static const char *restab_log[] = {
57034 + [RLIMIT_CPU] = "RLIMIT_CPU",
57035 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
57036 + [RLIMIT_DATA] = "RLIMIT_DATA",
57037 + [RLIMIT_STACK] = "RLIMIT_STACK",
57038 + [RLIMIT_CORE] = "RLIMIT_CORE",
57039 + [RLIMIT_RSS] = "RLIMIT_RSS",
57040 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
57041 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
57042 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
57043 + [RLIMIT_AS] = "RLIMIT_AS",
57044 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
57045 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
57046 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
57047 + [RLIMIT_NICE] = "RLIMIT_NICE",
57048 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
57049 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
57050 + [GR_CRASH_RES] = "RLIMIT_CRASH"
57051 +};
57052 +
57053 +void
57054 +gr_log_resource(const struct task_struct *task,
57055 + const int res, const unsigned long wanted, const int gt)
57056 +{
57057 + const struct cred *cred;
57058 + unsigned long rlim;
57059 +
57060 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
57061 + return;
57062 +
57063 + // not yet supported resource
57064 + if (unlikely(!restab_log[res]))
57065 + return;
57066 +
57067 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
57068 + rlim = task_rlimit_max(task, res);
57069 + else
57070 + rlim = task_rlimit(task, res);
57071 +
57072 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
57073 + return;
57074 +
57075 + rcu_read_lock();
57076 + cred = __task_cred(task);
57077 +
57078 + if (res == RLIMIT_NPROC &&
57079 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
57080 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
57081 + goto out_rcu_unlock;
57082 + else if (res == RLIMIT_MEMLOCK &&
57083 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
57084 + goto out_rcu_unlock;
57085 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
57086 + goto out_rcu_unlock;
57087 + rcu_read_unlock();
57088 +
57089 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
57090 +
57091 + return;
57092 +out_rcu_unlock:
57093 + rcu_read_unlock();
57094 + return;
57095 +}
57096 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
57097 new file mode 100644
57098 index 0000000..25197e9
57099 --- /dev/null
57100 +++ b/grsecurity/gracl_segv.c
57101 @@ -0,0 +1,299 @@
57102 +#include <linux/kernel.h>
57103 +#include <linux/mm.h>
57104 +#include <asm/uaccess.h>
57105 +#include <asm/errno.h>
57106 +#include <asm/mman.h>
57107 +#include <net/sock.h>
57108 +#include <linux/file.h>
57109 +#include <linux/fs.h>
57110 +#include <linux/net.h>
57111 +#include <linux/in.h>
57112 +#include <linux/slab.h>
57113 +#include <linux/types.h>
57114 +#include <linux/sched.h>
57115 +#include <linux/timer.h>
57116 +#include <linux/gracl.h>
57117 +#include <linux/grsecurity.h>
57118 +#include <linux/grinternal.h>
57119 +
57120 +static struct crash_uid *uid_set;
57121 +static unsigned short uid_used;
57122 +static DEFINE_SPINLOCK(gr_uid_lock);
57123 +extern rwlock_t gr_inode_lock;
57124 +extern struct acl_subject_label *
57125 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
57126 + struct acl_role_label *role);
57127 +
57128 +#ifdef CONFIG_BTRFS_FS
57129 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
57130 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
57131 +#endif
57132 +
57133 +static inline dev_t __get_dev(const struct dentry *dentry)
57134 +{
57135 +#ifdef CONFIG_BTRFS_FS
57136 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
57137 + return get_btrfs_dev_from_inode(dentry->d_inode);
57138 + else
57139 +#endif
57140 + return dentry->d_inode->i_sb->s_dev;
57141 +}
57142 +
57143 +int
57144 +gr_init_uidset(void)
57145 +{
57146 + uid_set =
57147 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
57148 + uid_used = 0;
57149 +
57150 + return uid_set ? 1 : 0;
57151 +}
57152 +
57153 +void
57154 +gr_free_uidset(void)
57155 +{
57156 + if (uid_set)
57157 + kfree(uid_set);
57158 +
57159 + return;
57160 +}
57161 +
57162 +int
57163 +gr_find_uid(const uid_t uid)
57164 +{
57165 + struct crash_uid *tmp = uid_set;
57166 + uid_t buid;
57167 + int low = 0, high = uid_used - 1, mid;
57168 +
57169 + while (high >= low) {
57170 + mid = (low + high) >> 1;
57171 + buid = tmp[mid].uid;
57172 + if (buid == uid)
57173 + return mid;
57174 + if (buid > uid)
57175 + high = mid - 1;
57176 + if (buid < uid)
57177 + low = mid + 1;
57178 + }
57179 +
57180 + return -1;
57181 +}
57182 +
57183 +static __inline__ void
57184 +gr_insertsort(void)
57185 +{
57186 + unsigned short i, j;
57187 + struct crash_uid index;
57188 +
57189 + for (i = 1; i < uid_used; i++) {
57190 + index = uid_set[i];
57191 + j = i;
57192 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
57193 + uid_set[j] = uid_set[j - 1];
57194 + j--;
57195 + }
57196 + uid_set[j] = index;
57197 + }
57198 +
57199 + return;
57200 +}
57201 +
57202 +static __inline__ void
57203 +gr_insert_uid(const uid_t uid, const unsigned long expires)
57204 +{
57205 + int loc;
57206 +
57207 + if (uid_used == GR_UIDTABLE_MAX)
57208 + return;
57209 +
57210 + loc = gr_find_uid(uid);
57211 +
57212 + if (loc >= 0) {
57213 + uid_set[loc].expires = expires;
57214 + return;
57215 + }
57216 +
57217 + uid_set[uid_used].uid = uid;
57218 + uid_set[uid_used].expires = expires;
57219 + uid_used++;
57220 +
57221 + gr_insertsort();
57222 +
57223 + return;
57224 +}
57225 +
57226 +void
57227 +gr_remove_uid(const unsigned short loc)
57228 +{
57229 + unsigned short i;
57230 +
57231 + for (i = loc + 1; i < uid_used; i++)
57232 + uid_set[i - 1] = uid_set[i];
57233 +
57234 + uid_used--;
57235 +
57236 + return;
57237 +}
57238 +
57239 +int
57240 +gr_check_crash_uid(const uid_t uid)
57241 +{
57242 + int loc;
57243 + int ret = 0;
57244 +
57245 + if (unlikely(!gr_acl_is_enabled()))
57246 + return 0;
57247 +
57248 + spin_lock(&gr_uid_lock);
57249 + loc = gr_find_uid(uid);
57250 +
57251 + if (loc < 0)
57252 + goto out_unlock;
57253 +
57254 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
57255 + gr_remove_uid(loc);
57256 + else
57257 + ret = 1;
57258 +
57259 +out_unlock:
57260 + spin_unlock(&gr_uid_lock);
57261 + return ret;
57262 +}
57263 +
57264 +static __inline__ int
57265 +proc_is_setxid(const struct cred *cred)
57266 +{
57267 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
57268 + !uid_eq(cred->uid, cred->fsuid))
57269 + return 1;
57270 + if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
57271 + !uid_eq(cred->gid, cred->fsgid))
57272 + return 1;
57273 +
57274 + return 0;
57275 +}
57276 +
57277 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
57278 +
57279 +void
57280 +gr_handle_crash(struct task_struct *task, const int sig)
57281 +{
57282 + struct acl_subject_label *curr;
57283 + struct task_struct *tsk, *tsk2;
57284 + const struct cred *cred;
57285 + const struct cred *cred2;
57286 +
57287 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
57288 + return;
57289 +
57290 + if (unlikely(!gr_acl_is_enabled()))
57291 + return;
57292 +
57293 + curr = task->acl;
57294 +
57295 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
57296 + return;
57297 +
57298 + if (time_before_eq(curr->expires, get_seconds())) {
57299 + curr->expires = 0;
57300 + curr->crashes = 0;
57301 + }
57302 +
57303 + curr->crashes++;
57304 +
57305 + if (!curr->expires)
57306 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
57307 +
57308 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57309 + time_after(curr->expires, get_seconds())) {
57310 + rcu_read_lock();
57311 + cred = __task_cred(task);
57312 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
57313 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57314 + spin_lock(&gr_uid_lock);
57315 + gr_insert_uid(cred->uid, curr->expires);
57316 + spin_unlock(&gr_uid_lock);
57317 + curr->expires = 0;
57318 + curr->crashes = 0;
57319 + read_lock(&tasklist_lock);
57320 + do_each_thread(tsk2, tsk) {
57321 + cred2 = __task_cred(tsk);
57322 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
57323 + gr_fake_force_sig(SIGKILL, tsk);
57324 + } while_each_thread(tsk2, tsk);
57325 + read_unlock(&tasklist_lock);
57326 + } else {
57327 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57328 + read_lock(&tasklist_lock);
57329 + read_lock(&grsec_exec_file_lock);
57330 + do_each_thread(tsk2, tsk) {
57331 + if (likely(tsk != task)) {
57332 + // if this thread has the same subject as the one that triggered
57333 + // RES_CRASH and it's the same binary, kill it
57334 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
57335 + gr_fake_force_sig(SIGKILL, tsk);
57336 + }
57337 + } while_each_thread(tsk2, tsk);
57338 + read_unlock(&grsec_exec_file_lock);
57339 + read_unlock(&tasklist_lock);
57340 + }
57341 + rcu_read_unlock();
57342 + }
57343 +
57344 + return;
57345 +}
57346 +
57347 +int
57348 +gr_check_crash_exec(const struct file *filp)
57349 +{
57350 + struct acl_subject_label *curr;
57351 +
57352 + if (unlikely(!gr_acl_is_enabled()))
57353 + return 0;
57354 +
57355 + read_lock(&gr_inode_lock);
57356 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
57357 + __get_dev(filp->f_path.dentry),
57358 + current->role);
57359 + read_unlock(&gr_inode_lock);
57360 +
57361 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
57362 + (!curr->crashes && !curr->expires))
57363 + return 0;
57364 +
57365 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57366 + time_after(curr->expires, get_seconds()))
57367 + return 1;
57368 + else if (time_before_eq(curr->expires, get_seconds())) {
57369 + curr->crashes = 0;
57370 + curr->expires = 0;
57371 + }
57372 +
57373 + return 0;
57374 +}
57375 +
57376 +void
57377 +gr_handle_alertkill(struct task_struct *task)
57378 +{
57379 + struct acl_subject_label *curracl;
57380 + __u32 curr_ip;
57381 + struct task_struct *p, *p2;
57382 +
57383 + if (unlikely(!gr_acl_is_enabled()))
57384 + return;
57385 +
57386 + curracl = task->acl;
57387 + curr_ip = task->signal->curr_ip;
57388 +
57389 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
57390 + read_lock(&tasklist_lock);
57391 + do_each_thread(p2, p) {
57392 + if (p->signal->curr_ip == curr_ip)
57393 + gr_fake_force_sig(SIGKILL, p);
57394 + } while_each_thread(p2, p);
57395 + read_unlock(&tasklist_lock);
57396 + } else if (curracl->mode & GR_KILLPROC)
57397 + gr_fake_force_sig(SIGKILL, task);
57398 +
57399 + return;
57400 +}
57401 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
57402 new file mode 100644
57403 index 0000000..9d83a69
57404 --- /dev/null
57405 +++ b/grsecurity/gracl_shm.c
57406 @@ -0,0 +1,40 @@
57407 +#include <linux/kernel.h>
57408 +#include <linux/mm.h>
57409 +#include <linux/sched.h>
57410 +#include <linux/file.h>
57411 +#include <linux/ipc.h>
57412 +#include <linux/gracl.h>
57413 +#include <linux/grsecurity.h>
57414 +#include <linux/grinternal.h>
57415 +
57416 +int
57417 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57418 + const time_t shm_createtime, const uid_t cuid, const int shmid)
57419 +{
57420 + struct task_struct *task;
57421 +
57422 + if (!gr_acl_is_enabled())
57423 + return 1;
57424 +
57425 + rcu_read_lock();
57426 + read_lock(&tasklist_lock);
57427 +
57428 + task = find_task_by_vpid(shm_cprid);
57429 +
57430 + if (unlikely(!task))
57431 + task = find_task_by_vpid(shm_lapid);
57432 +
57433 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
57434 + (task->pid == shm_lapid)) &&
57435 + (task->acl->mode & GR_PROTSHM) &&
57436 + (task->acl != current->acl))) {
57437 + read_unlock(&tasklist_lock);
57438 + rcu_read_unlock();
57439 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
57440 + return 0;
57441 + }
57442 + read_unlock(&tasklist_lock);
57443 + rcu_read_unlock();
57444 +
57445 + return 1;
57446 +}
57447 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
57448 new file mode 100644
57449 index 0000000..bc0be01
57450 --- /dev/null
57451 +++ b/grsecurity/grsec_chdir.c
57452 @@ -0,0 +1,19 @@
57453 +#include <linux/kernel.h>
57454 +#include <linux/sched.h>
57455 +#include <linux/fs.h>
57456 +#include <linux/file.h>
57457 +#include <linux/grsecurity.h>
57458 +#include <linux/grinternal.h>
57459 +
57460 +void
57461 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
57462 +{
57463 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57464 + if ((grsec_enable_chdir && grsec_enable_group &&
57465 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
57466 + !grsec_enable_group)) {
57467 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
57468 + }
57469 +#endif
57470 + return;
57471 +}
57472 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
57473 new file mode 100644
57474 index 0000000..9807ee2
57475 --- /dev/null
57476 +++ b/grsecurity/grsec_chroot.c
57477 @@ -0,0 +1,368 @@
57478 +#include <linux/kernel.h>
57479 +#include <linux/module.h>
57480 +#include <linux/sched.h>
57481 +#include <linux/file.h>
57482 +#include <linux/fs.h>
57483 +#include <linux/mount.h>
57484 +#include <linux/types.h>
57485 +#include "../fs/mount.h"
57486 +#include <linux/grsecurity.h>
57487 +#include <linux/grinternal.h>
57488 +
57489 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
57490 +{
57491 +#ifdef CONFIG_GRKERNSEC
57492 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
57493 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
57494 + task->gr_is_chrooted = 1;
57495 + else
57496 + task->gr_is_chrooted = 0;
57497 +
57498 + task->gr_chroot_dentry = path->dentry;
57499 +#endif
57500 + return;
57501 +}
57502 +
57503 +void gr_clear_chroot_entries(struct task_struct *task)
57504 +{
57505 +#ifdef CONFIG_GRKERNSEC
57506 + task->gr_is_chrooted = 0;
57507 + task->gr_chroot_dentry = NULL;
57508 +#endif
57509 + return;
57510 +}
57511 +
57512 +int
57513 +gr_handle_chroot_unix(const pid_t pid)
57514 +{
57515 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57516 + struct task_struct *p;
57517 +
57518 + if (unlikely(!grsec_enable_chroot_unix))
57519 + return 1;
57520 +
57521 + if (likely(!proc_is_chrooted(current)))
57522 + return 1;
57523 +
57524 + rcu_read_lock();
57525 + read_lock(&tasklist_lock);
57526 + p = find_task_by_vpid_unrestricted(pid);
57527 + if (unlikely(p && !have_same_root(current, p))) {
57528 + read_unlock(&tasklist_lock);
57529 + rcu_read_unlock();
57530 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
57531 + return 0;
57532 + }
57533 + read_unlock(&tasklist_lock);
57534 + rcu_read_unlock();
57535 +#endif
57536 + return 1;
57537 +}
57538 +
57539 +int
57540 +gr_handle_chroot_nice(void)
57541 +{
57542 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57543 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
57544 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
57545 + return -EPERM;
57546 + }
57547 +#endif
57548 + return 0;
57549 +}
57550 +
57551 +int
57552 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
57553 +{
57554 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57555 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
57556 + && proc_is_chrooted(current)) {
57557 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
57558 + return -EACCES;
57559 + }
57560 +#endif
57561 + return 0;
57562 +}
57563 +
57564 +int
57565 +gr_handle_chroot_rawio(const struct inode *inode)
57566 +{
57567 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57568 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
57569 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
57570 + return 1;
57571 +#endif
57572 + return 0;
57573 +}
57574 +
57575 +int
57576 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
57577 +{
57578 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57579 + struct task_struct *p;
57580 + int ret = 0;
57581 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
57582 + return ret;
57583 +
57584 + read_lock(&tasklist_lock);
57585 + do_each_pid_task(pid, type, p) {
57586 + if (!have_same_root(current, p)) {
57587 + ret = 1;
57588 + goto out;
57589 + }
57590 + } while_each_pid_task(pid, type, p);
57591 +out:
57592 + read_unlock(&tasklist_lock);
57593 + return ret;
57594 +#endif
57595 + return 0;
57596 +}
57597 +
57598 +int
57599 +gr_pid_is_chrooted(struct task_struct *p)
57600 +{
57601 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57602 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
57603 + return 0;
57604 +
57605 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
57606 + !have_same_root(current, p)) {
57607 + return 1;
57608 + }
57609 +#endif
57610 + return 0;
57611 +}
57612 +
57613 +EXPORT_SYMBOL(gr_pid_is_chrooted);
57614 +
57615 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
57616 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
57617 +{
57618 + struct path path, currentroot;
57619 + int ret = 0;
57620 +
57621 + path.dentry = (struct dentry *)u_dentry;
57622 + path.mnt = (struct vfsmount *)u_mnt;
57623 + get_fs_root(current->fs, &currentroot);
57624 + if (path_is_under(&path, &currentroot))
57625 + ret = 1;
57626 + path_put(&currentroot);
57627 +
57628 + return ret;
57629 +}
57630 +#endif
57631 +
57632 +int
57633 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
57634 +{
57635 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57636 + if (!grsec_enable_chroot_fchdir)
57637 + return 1;
57638 +
57639 + if (!proc_is_chrooted(current))
57640 + return 1;
57641 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
57642 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
57643 + return 0;
57644 + }
57645 +#endif
57646 + return 1;
57647 +}
57648 +
57649 +int
57650 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57651 + const time_t shm_createtime)
57652 +{
57653 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57654 + struct task_struct *p;
57655 + time_t starttime;
57656 +
57657 + if (unlikely(!grsec_enable_chroot_shmat))
57658 + return 1;
57659 +
57660 + if (likely(!proc_is_chrooted(current)))
57661 + return 1;
57662 +
57663 + rcu_read_lock();
57664 + read_lock(&tasklist_lock);
57665 +
57666 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
57667 + starttime = p->start_time.tv_sec;
57668 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
57669 + if (have_same_root(current, p)) {
57670 + goto allow;
57671 + } else {
57672 + read_unlock(&tasklist_lock);
57673 + rcu_read_unlock();
57674 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57675 + return 0;
57676 + }
57677 + }
57678 + /* creator exited, pid reuse, fall through to next check */
57679 + }
57680 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
57681 + if (unlikely(!have_same_root(current, p))) {
57682 + read_unlock(&tasklist_lock);
57683 + rcu_read_unlock();
57684 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57685 + return 0;
57686 + }
57687 + }
57688 +
57689 +allow:
57690 + read_unlock(&tasklist_lock);
57691 + rcu_read_unlock();
57692 +#endif
57693 + return 1;
57694 +}
57695 +
57696 +void
57697 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
57698 +{
57699 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57700 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
57701 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
57702 +#endif
57703 + return;
57704 +}
57705 +
57706 +int
57707 +gr_handle_chroot_mknod(const struct dentry *dentry,
57708 + const struct vfsmount *mnt, const int mode)
57709 +{
57710 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57711 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
57712 + proc_is_chrooted(current)) {
57713 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
57714 + return -EPERM;
57715 + }
57716 +#endif
57717 + return 0;
57718 +}
57719 +
57720 +int
57721 +gr_handle_chroot_mount(const struct dentry *dentry,
57722 + const struct vfsmount *mnt, const char *dev_name)
57723 +{
57724 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57725 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
57726 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
57727 + return -EPERM;
57728 + }
57729 +#endif
57730 + return 0;
57731 +}
57732 +
57733 +int
57734 +gr_handle_chroot_pivot(void)
57735 +{
57736 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57737 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
57738 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
57739 + return -EPERM;
57740 + }
57741 +#endif
57742 + return 0;
57743 +}
57744 +
57745 +int
57746 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
57747 +{
57748 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57749 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
57750 + !gr_is_outside_chroot(dentry, mnt)) {
57751 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
57752 + return -EPERM;
57753 + }
57754 +#endif
57755 + return 0;
57756 +}
57757 +
57758 +extern const char *captab_log[];
57759 +extern int captab_log_entries;
57760 +
57761 +int
57762 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57763 +{
57764 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57765 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57766 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57767 + if (cap_raised(chroot_caps, cap)) {
57768 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
57769 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
57770 + }
57771 + return 0;
57772 + }
57773 + }
57774 +#endif
57775 + return 1;
57776 +}
57777 +
57778 +int
57779 +gr_chroot_is_capable(const int cap)
57780 +{
57781 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57782 + return gr_task_chroot_is_capable(current, current_cred(), cap);
57783 +#endif
57784 + return 1;
57785 +}
57786 +
57787 +int
57788 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
57789 +{
57790 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57791 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57792 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57793 + if (cap_raised(chroot_caps, cap)) {
57794 + return 0;
57795 + }
57796 + }
57797 +#endif
57798 + return 1;
57799 +}
57800 +
57801 +int
57802 +gr_chroot_is_capable_nolog(const int cap)
57803 +{
57804 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57805 + return gr_task_chroot_is_capable_nolog(current, cap);
57806 +#endif
57807 + return 1;
57808 +}
57809 +
57810 +int
57811 +gr_handle_chroot_sysctl(const int op)
57812 +{
57813 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57814 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
57815 + proc_is_chrooted(current))
57816 + return -EACCES;
57817 +#endif
57818 + return 0;
57819 +}
57820 +
57821 +void
57822 +gr_handle_chroot_chdir(struct path *path)
57823 +{
57824 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57825 + if (grsec_enable_chroot_chdir)
57826 + set_fs_pwd(current->fs, path);
57827 +#endif
57828 + return;
57829 +}
57830 +
57831 +int
57832 +gr_handle_chroot_chmod(const struct dentry *dentry,
57833 + const struct vfsmount *mnt, const int mode)
57834 +{
57835 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57836 + /* allow chmod +s on directories, but not files */
57837 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
57838 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
57839 + proc_is_chrooted(current)) {
57840 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
57841 + return -EPERM;
57842 + }
57843 +#endif
57844 + return 0;
57845 +}
57846 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
57847 new file mode 100644
57848 index 0000000..213ad8b
57849 --- /dev/null
57850 +++ b/grsecurity/grsec_disabled.c
57851 @@ -0,0 +1,437 @@
57852 +#include <linux/kernel.h>
57853 +#include <linux/module.h>
57854 +#include <linux/sched.h>
57855 +#include <linux/file.h>
57856 +#include <linux/fs.h>
57857 +#include <linux/kdev_t.h>
57858 +#include <linux/net.h>
57859 +#include <linux/in.h>
57860 +#include <linux/ip.h>
57861 +#include <linux/skbuff.h>
57862 +#include <linux/sysctl.h>
57863 +
57864 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57865 +void
57866 +pax_set_initial_flags(struct linux_binprm *bprm)
57867 +{
57868 + return;
57869 +}
57870 +#endif
57871 +
57872 +#ifdef CONFIG_SYSCTL
57873 +__u32
57874 +gr_handle_sysctl(const struct ctl_table * table, const int op)
57875 +{
57876 + return 0;
57877 +}
57878 +#endif
57879 +
57880 +#ifdef CONFIG_TASKSTATS
57881 +int gr_is_taskstats_denied(int pid)
57882 +{
57883 + return 0;
57884 +}
57885 +#endif
57886 +
57887 +int
57888 +gr_acl_is_enabled(void)
57889 +{
57890 + return 0;
57891 +}
57892 +
57893 +void
57894 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
57895 +{
57896 + return;
57897 +}
57898 +
57899 +int
57900 +gr_handle_rawio(const struct inode *inode)
57901 +{
57902 + return 0;
57903 +}
57904 +
57905 +void
57906 +gr_acl_handle_psacct(struct task_struct *task, const long code)
57907 +{
57908 + return;
57909 +}
57910 +
57911 +int
57912 +gr_handle_ptrace(struct task_struct *task, const long request)
57913 +{
57914 + return 0;
57915 +}
57916 +
57917 +int
57918 +gr_handle_proc_ptrace(struct task_struct *task)
57919 +{
57920 + return 0;
57921 +}
57922 +
57923 +void
57924 +gr_learn_resource(const struct task_struct *task,
57925 + const int res, const unsigned long wanted, const int gt)
57926 +{
57927 + return;
57928 +}
57929 +
57930 +int
57931 +gr_set_acls(const int type)
57932 +{
57933 + return 0;
57934 +}
57935 +
57936 +int
57937 +gr_check_hidden_task(const struct task_struct *tsk)
57938 +{
57939 + return 0;
57940 +}
57941 +
57942 +int
57943 +gr_check_protected_task(const struct task_struct *task)
57944 +{
57945 + return 0;
57946 +}
57947 +
57948 +int
57949 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
57950 +{
57951 + return 0;
57952 +}
57953 +
57954 +void
57955 +gr_copy_label(struct task_struct *tsk)
57956 +{
57957 + return;
57958 +}
57959 +
57960 +void
57961 +gr_set_pax_flags(struct task_struct *task)
57962 +{
57963 + return;
57964 +}
57965 +
57966 +int
57967 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
57968 + const int unsafe_share)
57969 +{
57970 + return 0;
57971 +}
57972 +
57973 +void
57974 +gr_handle_delete(const ino_t ino, const dev_t dev)
57975 +{
57976 + return;
57977 +}
57978 +
57979 +void
57980 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
57981 +{
57982 + return;
57983 +}
57984 +
57985 +void
57986 +gr_handle_crash(struct task_struct *task, const int sig)
57987 +{
57988 + return;
57989 +}
57990 +
57991 +int
57992 +gr_check_crash_exec(const struct file *filp)
57993 +{
57994 + return 0;
57995 +}
57996 +
57997 +int
57998 +gr_check_crash_uid(const uid_t uid)
57999 +{
58000 + return 0;
58001 +}
58002 +
58003 +void
58004 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
58005 + struct dentry *old_dentry,
58006 + struct dentry *new_dentry,
58007 + struct vfsmount *mnt, const __u8 replace)
58008 +{
58009 + return;
58010 +}
58011 +
58012 +int
58013 +gr_search_socket(const int family, const int type, const int protocol)
58014 +{
58015 + return 1;
58016 +}
58017 +
58018 +int
58019 +gr_search_connectbind(const int mode, const struct socket *sock,
58020 + const struct sockaddr_in *addr)
58021 +{
58022 + return 0;
58023 +}
58024 +
58025 +void
58026 +gr_handle_alertkill(struct task_struct *task)
58027 +{
58028 + return;
58029 +}
58030 +
58031 +__u32
58032 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
58033 +{
58034 + return 1;
58035 +}
58036 +
58037 +__u32
58038 +gr_acl_handle_hidden_file(const struct dentry * dentry,
58039 + const struct vfsmount * mnt)
58040 +{
58041 + return 1;
58042 +}
58043 +
58044 +__u32
58045 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
58046 + int acc_mode)
58047 +{
58048 + return 1;
58049 +}
58050 +
58051 +__u32
58052 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
58053 +{
58054 + return 1;
58055 +}
58056 +
58057 +__u32
58058 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
58059 +{
58060 + return 1;
58061 +}
58062 +
58063 +int
58064 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
58065 + unsigned int *vm_flags)
58066 +{
58067 + return 1;
58068 +}
58069 +
58070 +__u32
58071 +gr_acl_handle_truncate(const struct dentry * dentry,
58072 + const struct vfsmount * mnt)
58073 +{
58074 + return 1;
58075 +}
58076 +
58077 +__u32
58078 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
58079 +{
58080 + return 1;
58081 +}
58082 +
58083 +__u32
58084 +gr_acl_handle_access(const struct dentry * dentry,
58085 + const struct vfsmount * mnt, const int fmode)
58086 +{
58087 + return 1;
58088 +}
58089 +
58090 +__u32
58091 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
58092 + umode_t *mode)
58093 +{
58094 + return 1;
58095 +}
58096 +
58097 +__u32
58098 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
58099 +{
58100 + return 1;
58101 +}
58102 +
58103 +__u32
58104 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
58105 +{
58106 + return 1;
58107 +}
58108 +
58109 +void
58110 +grsecurity_init(void)
58111 +{
58112 + return;
58113 +}
58114 +
58115 +umode_t gr_acl_umask(void)
58116 +{
58117 + return 0;
58118 +}
58119 +
58120 +__u32
58121 +gr_acl_handle_mknod(const struct dentry * new_dentry,
58122 + const struct dentry * parent_dentry,
58123 + const struct vfsmount * parent_mnt,
58124 + const int mode)
58125 +{
58126 + return 1;
58127 +}
58128 +
58129 +__u32
58130 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
58131 + const struct dentry * parent_dentry,
58132 + const struct vfsmount * parent_mnt)
58133 +{
58134 + return 1;
58135 +}
58136 +
58137 +__u32
58138 +gr_acl_handle_symlink(const struct dentry * new_dentry,
58139 + const struct dentry * parent_dentry,
58140 + const struct vfsmount * parent_mnt, const char *from)
58141 +{
58142 + return 1;
58143 +}
58144 +
58145 +__u32
58146 +gr_acl_handle_link(const struct dentry * new_dentry,
58147 + const struct dentry * parent_dentry,
58148 + const struct vfsmount * parent_mnt,
58149 + const struct dentry * old_dentry,
58150 + const struct vfsmount * old_mnt, const char *to)
58151 +{
58152 + return 1;
58153 +}
58154 +
58155 +int
58156 +gr_acl_handle_rename(const struct dentry *new_dentry,
58157 + const struct dentry *parent_dentry,
58158 + const struct vfsmount *parent_mnt,
58159 + const struct dentry *old_dentry,
58160 + const struct inode *old_parent_inode,
58161 + const struct vfsmount *old_mnt, const char *newname)
58162 +{
58163 + return 0;
58164 +}
58165 +
58166 +int
58167 +gr_acl_handle_filldir(const struct file *file, const char *name,
58168 + const int namelen, const ino_t ino)
58169 +{
58170 + return 1;
58171 +}
58172 +
58173 +int
58174 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
58175 + const time_t shm_createtime, const uid_t cuid, const int shmid)
58176 +{
58177 + return 1;
58178 +}
58179 +
58180 +int
58181 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
58182 +{
58183 + return 0;
58184 +}
58185 +
58186 +int
58187 +gr_search_accept(const struct socket *sock)
58188 +{
58189 + return 0;
58190 +}
58191 +
58192 +int
58193 +gr_search_listen(const struct socket *sock)
58194 +{
58195 + return 0;
58196 +}
58197 +
58198 +int
58199 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
58200 +{
58201 + return 0;
58202 +}
58203 +
58204 +__u32
58205 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
58206 +{
58207 + return 1;
58208 +}
58209 +
58210 +__u32
58211 +gr_acl_handle_creat(const struct dentry * dentry,
58212 + const struct dentry * p_dentry,
58213 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
58214 + const int imode)
58215 +{
58216 + return 1;
58217 +}
58218 +
58219 +void
58220 +gr_acl_handle_exit(void)
58221 +{
58222 + return;
58223 +}
58224 +
58225 +int
58226 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
58227 +{
58228 + return 1;
58229 +}
58230 +
58231 +void
58232 +gr_set_role_label(const uid_t uid, const gid_t gid)
58233 +{
58234 + return;
58235 +}
58236 +
58237 +int
58238 +gr_acl_handle_procpidmem(const struct task_struct *task)
58239 +{
58240 + return 0;
58241 +}
58242 +
58243 +int
58244 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
58245 +{
58246 + return 0;
58247 +}
58248 +
58249 +int
58250 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
58251 +{
58252 + return 0;
58253 +}
58254 +
58255 +void
58256 +gr_set_kernel_label(struct task_struct *task)
58257 +{
58258 + return;
58259 +}
58260 +
58261 +int
58262 +gr_check_user_change(int real, int effective, int fs)
58263 +{
58264 + return 0;
58265 +}
58266 +
58267 +int
58268 +gr_check_group_change(int real, int effective, int fs)
58269 +{
58270 + return 0;
58271 +}
58272 +
58273 +int gr_acl_enable_at_secure(void)
58274 +{
58275 + return 0;
58276 +}
58277 +
58278 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
58279 +{
58280 + return dentry->d_inode->i_sb->s_dev;
58281 +}
58282 +
58283 +EXPORT_SYMBOL(gr_learn_resource);
58284 +EXPORT_SYMBOL(gr_set_kernel_label);
58285 +#ifdef CONFIG_SECURITY
58286 +EXPORT_SYMBOL(gr_check_user_change);
58287 +EXPORT_SYMBOL(gr_check_group_change);
58288 +#endif
58289 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
58290 new file mode 100644
58291 index 0000000..abfa971
58292 --- /dev/null
58293 +++ b/grsecurity/grsec_exec.c
58294 @@ -0,0 +1,174 @@
58295 +#include <linux/kernel.h>
58296 +#include <linux/sched.h>
58297 +#include <linux/file.h>
58298 +#include <linux/binfmts.h>
58299 +#include <linux/fs.h>
58300 +#include <linux/types.h>
58301 +#include <linux/grdefs.h>
58302 +#include <linux/grsecurity.h>
58303 +#include <linux/grinternal.h>
58304 +#include <linux/capability.h>
58305 +#include <linux/module.h>
58306 +
58307 +#include <asm/uaccess.h>
58308 +
58309 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58310 +static char gr_exec_arg_buf[132];
58311 +static DEFINE_MUTEX(gr_exec_arg_mutex);
58312 +#endif
58313 +
58314 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
58315 +
58316 +void
58317 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
58318 +{
58319 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58320 + char *grarg = gr_exec_arg_buf;
58321 + unsigned int i, x, execlen = 0;
58322 + char c;
58323 +
58324 + if (!((grsec_enable_execlog && grsec_enable_group &&
58325 + in_group_p(grsec_audit_gid))
58326 + || (grsec_enable_execlog && !grsec_enable_group)))
58327 + return;
58328 +
58329 + mutex_lock(&gr_exec_arg_mutex);
58330 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
58331 +
58332 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
58333 + const char __user *p;
58334 + unsigned int len;
58335 +
58336 + p = get_user_arg_ptr(argv, i);
58337 + if (IS_ERR(p))
58338 + goto log;
58339 +
58340 + len = strnlen_user(p, 128 - execlen);
58341 + if (len > 128 - execlen)
58342 + len = 128 - execlen;
58343 + else if (len > 0)
58344 + len--;
58345 + if (copy_from_user(grarg + execlen, p, len))
58346 + goto log;
58347 +
58348 + /* rewrite unprintable characters */
58349 + for (x = 0; x < len; x++) {
58350 + c = *(grarg + execlen + x);
58351 + if (c < 32 || c > 126)
58352 + *(grarg + execlen + x) = ' ';
58353 + }
58354 +
58355 + execlen += len;
58356 + *(grarg + execlen) = ' ';
58357 + *(grarg + execlen + 1) = '\0';
58358 + execlen++;
58359 + }
58360 +
58361 + log:
58362 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
58363 + bprm->file->f_path.mnt, grarg);
58364 + mutex_unlock(&gr_exec_arg_mutex);
58365 +#endif
58366 + return;
58367 +}
58368 +
58369 +#ifdef CONFIG_GRKERNSEC
58370 +extern int gr_acl_is_capable(const int cap);
58371 +extern int gr_acl_is_capable_nolog(const int cap);
58372 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58373 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
58374 +extern int gr_chroot_is_capable(const int cap);
58375 +extern int gr_chroot_is_capable_nolog(const int cap);
58376 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58377 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
58378 +#endif
58379 +
58380 +const char *captab_log[] = {
58381 + "CAP_CHOWN",
58382 + "CAP_DAC_OVERRIDE",
58383 + "CAP_DAC_READ_SEARCH",
58384 + "CAP_FOWNER",
58385 + "CAP_FSETID",
58386 + "CAP_KILL",
58387 + "CAP_SETGID",
58388 + "CAP_SETUID",
58389 + "CAP_SETPCAP",
58390 + "CAP_LINUX_IMMUTABLE",
58391 + "CAP_NET_BIND_SERVICE",
58392 + "CAP_NET_BROADCAST",
58393 + "CAP_NET_ADMIN",
58394 + "CAP_NET_RAW",
58395 + "CAP_IPC_LOCK",
58396 + "CAP_IPC_OWNER",
58397 + "CAP_SYS_MODULE",
58398 + "CAP_SYS_RAWIO",
58399 + "CAP_SYS_CHROOT",
58400 + "CAP_SYS_PTRACE",
58401 + "CAP_SYS_PACCT",
58402 + "CAP_SYS_ADMIN",
58403 + "CAP_SYS_BOOT",
58404 + "CAP_SYS_NICE",
58405 + "CAP_SYS_RESOURCE",
58406 + "CAP_SYS_TIME",
58407 + "CAP_SYS_TTY_CONFIG",
58408 + "CAP_MKNOD",
58409 + "CAP_LEASE",
58410 + "CAP_AUDIT_WRITE",
58411 + "CAP_AUDIT_CONTROL",
58412 + "CAP_SETFCAP",
58413 + "CAP_MAC_OVERRIDE",
58414 + "CAP_MAC_ADMIN",
58415 + "CAP_SYSLOG",
58416 + "CAP_WAKE_ALARM"
58417 +};
58418 +
58419 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
58420 +
58421 +int gr_is_capable(const int cap)
58422 +{
58423 +#ifdef CONFIG_GRKERNSEC
58424 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
58425 + return 1;
58426 + return 0;
58427 +#else
58428 + return 1;
58429 +#endif
58430 +}
58431 +
58432 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
58433 +{
58434 +#ifdef CONFIG_GRKERNSEC
58435 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
58436 + return 1;
58437 + return 0;
58438 +#else
58439 + return 1;
58440 +#endif
58441 +}
58442 +
58443 +int gr_is_capable_nolog(const int cap)
58444 +{
58445 +#ifdef CONFIG_GRKERNSEC
58446 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
58447 + return 1;
58448 + return 0;
58449 +#else
58450 + return 1;
58451 +#endif
58452 +}
58453 +
58454 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
58455 +{
58456 +#ifdef CONFIG_GRKERNSEC
58457 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
58458 + return 1;
58459 + return 0;
58460 +#else
58461 + return 1;
58462 +#endif
58463 +}
58464 +
58465 +EXPORT_SYMBOL(gr_is_capable);
58466 +EXPORT_SYMBOL(gr_is_capable_nolog);
58467 +EXPORT_SYMBOL(gr_task_is_capable);
58468 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
58469 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
58470 new file mode 100644
58471 index 0000000..d3ee748
58472 --- /dev/null
58473 +++ b/grsecurity/grsec_fifo.c
58474 @@ -0,0 +1,24 @@
58475 +#include <linux/kernel.h>
58476 +#include <linux/sched.h>
58477 +#include <linux/fs.h>
58478 +#include <linux/file.h>
58479 +#include <linux/grinternal.h>
58480 +
58481 +int
58482 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
58483 + const struct dentry *dir, const int flag, const int acc_mode)
58484 +{
58485 +#ifdef CONFIG_GRKERNSEC_FIFO
58486 + const struct cred *cred = current_cred();
58487 +
58488 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
58489 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
58490 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
58491 + (cred->fsuid != dentry->d_inode->i_uid)) {
58492 + if (!inode_permission(dentry->d_inode, acc_mode))
58493 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
58494 + return -EACCES;
58495 + }
58496 +#endif
58497 + return 0;
58498 +}
58499 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
58500 new file mode 100644
58501 index 0000000..8ca18bf
58502 --- /dev/null
58503 +++ b/grsecurity/grsec_fork.c
58504 @@ -0,0 +1,23 @@
58505 +#include <linux/kernel.h>
58506 +#include <linux/sched.h>
58507 +#include <linux/grsecurity.h>
58508 +#include <linux/grinternal.h>
58509 +#include <linux/errno.h>
58510 +
58511 +void
58512 +gr_log_forkfail(const int retval)
58513 +{
58514 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58515 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
58516 + switch (retval) {
58517 + case -EAGAIN:
58518 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
58519 + break;
58520 + case -ENOMEM:
58521 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
58522 + break;
58523 + }
58524 + }
58525 +#endif
58526 + return;
58527 +}
58528 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
58529 new file mode 100644
58530 index 0000000..05a6015
58531 --- /dev/null
58532 +++ b/grsecurity/grsec_init.c
58533 @@ -0,0 +1,283 @@
58534 +#include <linux/kernel.h>
58535 +#include <linux/sched.h>
58536 +#include <linux/mm.h>
58537 +#include <linux/gracl.h>
58538 +#include <linux/slab.h>
58539 +#include <linux/vmalloc.h>
58540 +#include <linux/percpu.h>
58541 +#include <linux/module.h>
58542 +
58543 +int grsec_enable_ptrace_readexec;
58544 +int grsec_enable_setxid;
58545 +int grsec_enable_symlinkown;
58546 +int grsec_symlinkown_gid;
58547 +int grsec_enable_brute;
58548 +int grsec_enable_link;
58549 +int grsec_enable_dmesg;
58550 +int grsec_enable_harden_ptrace;
58551 +int grsec_enable_fifo;
58552 +int grsec_enable_execlog;
58553 +int grsec_enable_signal;
58554 +int grsec_enable_forkfail;
58555 +int grsec_enable_audit_ptrace;
58556 +int grsec_enable_time;
58557 +int grsec_enable_audit_textrel;
58558 +int grsec_enable_group;
58559 +int grsec_audit_gid;
58560 +int grsec_enable_chdir;
58561 +int grsec_enable_mount;
58562 +int grsec_enable_rofs;
58563 +int grsec_enable_chroot_findtask;
58564 +int grsec_enable_chroot_mount;
58565 +int grsec_enable_chroot_shmat;
58566 +int grsec_enable_chroot_fchdir;
58567 +int grsec_enable_chroot_double;
58568 +int grsec_enable_chroot_pivot;
58569 +int grsec_enable_chroot_chdir;
58570 +int grsec_enable_chroot_chmod;
58571 +int grsec_enable_chroot_mknod;
58572 +int grsec_enable_chroot_nice;
58573 +int grsec_enable_chroot_execlog;
58574 +int grsec_enable_chroot_caps;
58575 +int grsec_enable_chroot_sysctl;
58576 +int grsec_enable_chroot_unix;
58577 +int grsec_enable_tpe;
58578 +int grsec_tpe_gid;
58579 +int grsec_enable_blackhole;
58580 +#ifdef CONFIG_IPV6_MODULE
58581 +EXPORT_SYMBOL(grsec_enable_blackhole);
58582 +#endif
58583 +int grsec_lastack_retries;
58584 +int grsec_enable_tpe_all;
58585 +int grsec_enable_tpe_invert;
58586 +int grsec_enable_socket_all;
58587 +int grsec_socket_all_gid;
58588 +int grsec_enable_socket_client;
58589 +int grsec_socket_client_gid;
58590 +int grsec_enable_socket_server;
58591 +int grsec_socket_server_gid;
58592 +int grsec_resource_logging;
58593 +int grsec_disable_privio;
58594 +int grsec_enable_log_rwxmaps;
58595 +int grsec_lock;
58596 +
58597 +DEFINE_SPINLOCK(grsec_alert_lock);
58598 +unsigned long grsec_alert_wtime = 0;
58599 +unsigned long grsec_alert_fyet = 0;
58600 +
58601 +DEFINE_SPINLOCK(grsec_audit_lock);
58602 +
58603 +DEFINE_RWLOCK(grsec_exec_file_lock);
58604 +
58605 +char *gr_shared_page[4];
58606 +
58607 +char *gr_alert_log_fmt;
58608 +char *gr_audit_log_fmt;
58609 +char *gr_alert_log_buf;
58610 +char *gr_audit_log_buf;
58611 +
58612 +extern struct gr_arg *gr_usermode;
58613 +extern unsigned char *gr_system_salt;
58614 +extern unsigned char *gr_system_sum;
58615 +
58616 +void __init
58617 +grsecurity_init(void)
58618 +{
58619 + int j;
58620 + /* create the per-cpu shared pages */
58621 +
58622 +#ifdef CONFIG_X86
58623 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
58624 +#endif
58625 +
58626 + for (j = 0; j < 4; j++) {
58627 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
58628 + if (gr_shared_page[j] == NULL) {
58629 + panic("Unable to allocate grsecurity shared page");
58630 + return;
58631 + }
58632 + }
58633 +
58634 + /* allocate log buffers */
58635 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
58636 + if (!gr_alert_log_fmt) {
58637 + panic("Unable to allocate grsecurity alert log format buffer");
58638 + return;
58639 + }
58640 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
58641 + if (!gr_audit_log_fmt) {
58642 + panic("Unable to allocate grsecurity audit log format buffer");
58643 + return;
58644 + }
58645 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58646 + if (!gr_alert_log_buf) {
58647 + panic("Unable to allocate grsecurity alert log buffer");
58648 + return;
58649 + }
58650 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58651 + if (!gr_audit_log_buf) {
58652 + panic("Unable to allocate grsecurity audit log buffer");
58653 + return;
58654 + }
58655 +
58656 + /* allocate memory for authentication structure */
58657 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
58658 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
58659 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
58660 +
58661 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
58662 + panic("Unable to allocate grsecurity authentication structure");
58663 + return;
58664 + }
58665 +
58666 +
58667 +#ifdef CONFIG_GRKERNSEC_IO
58668 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
58669 + grsec_disable_privio = 1;
58670 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58671 + grsec_disable_privio = 1;
58672 +#else
58673 + grsec_disable_privio = 0;
58674 +#endif
58675 +#endif
58676 +
58677 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58678 + /* for backward compatibility, tpe_invert always defaults to on if
58679 + enabled in the kernel
58680 + */
58681 + grsec_enable_tpe_invert = 1;
58682 +#endif
58683 +
58684 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58685 +#ifndef CONFIG_GRKERNSEC_SYSCTL
58686 + grsec_lock = 1;
58687 +#endif
58688 +
58689 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58690 + grsec_enable_audit_textrel = 1;
58691 +#endif
58692 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58693 + grsec_enable_log_rwxmaps = 1;
58694 +#endif
58695 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
58696 + grsec_enable_group = 1;
58697 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
58698 +#endif
58699 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58700 + grsec_enable_ptrace_readexec = 1;
58701 +#endif
58702 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
58703 + grsec_enable_chdir = 1;
58704 +#endif
58705 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58706 + grsec_enable_harden_ptrace = 1;
58707 +#endif
58708 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58709 + grsec_enable_mount = 1;
58710 +#endif
58711 +#ifdef CONFIG_GRKERNSEC_LINK
58712 + grsec_enable_link = 1;
58713 +#endif
58714 +#ifdef CONFIG_GRKERNSEC_BRUTE
58715 + grsec_enable_brute = 1;
58716 +#endif
58717 +#ifdef CONFIG_GRKERNSEC_DMESG
58718 + grsec_enable_dmesg = 1;
58719 +#endif
58720 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58721 + grsec_enable_blackhole = 1;
58722 + grsec_lastack_retries = 4;
58723 +#endif
58724 +#ifdef CONFIG_GRKERNSEC_FIFO
58725 + grsec_enable_fifo = 1;
58726 +#endif
58727 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58728 + grsec_enable_execlog = 1;
58729 +#endif
58730 +#ifdef CONFIG_GRKERNSEC_SETXID
58731 + grsec_enable_setxid = 1;
58732 +#endif
58733 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58734 + grsec_enable_signal = 1;
58735 +#endif
58736 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58737 + grsec_enable_forkfail = 1;
58738 +#endif
58739 +#ifdef CONFIG_GRKERNSEC_TIME
58740 + grsec_enable_time = 1;
58741 +#endif
58742 +#ifdef CONFIG_GRKERNSEC_RESLOG
58743 + grsec_resource_logging = 1;
58744 +#endif
58745 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58746 + grsec_enable_chroot_findtask = 1;
58747 +#endif
58748 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
58749 + grsec_enable_chroot_unix = 1;
58750 +#endif
58751 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58752 + grsec_enable_chroot_mount = 1;
58753 +#endif
58754 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58755 + grsec_enable_chroot_fchdir = 1;
58756 +#endif
58757 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58758 + grsec_enable_chroot_shmat = 1;
58759 +#endif
58760 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58761 + grsec_enable_audit_ptrace = 1;
58762 +#endif
58763 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58764 + grsec_enable_chroot_double = 1;
58765 +#endif
58766 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58767 + grsec_enable_chroot_pivot = 1;
58768 +#endif
58769 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58770 + grsec_enable_chroot_chdir = 1;
58771 +#endif
58772 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58773 + grsec_enable_chroot_chmod = 1;
58774 +#endif
58775 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58776 + grsec_enable_chroot_mknod = 1;
58777 +#endif
58778 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58779 + grsec_enable_chroot_nice = 1;
58780 +#endif
58781 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58782 + grsec_enable_chroot_execlog = 1;
58783 +#endif
58784 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58785 + grsec_enable_chroot_caps = 1;
58786 +#endif
58787 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58788 + grsec_enable_chroot_sysctl = 1;
58789 +#endif
58790 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58791 + grsec_enable_symlinkown = 1;
58792 + grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
58793 +#endif
58794 +#ifdef CONFIG_GRKERNSEC_TPE
58795 + grsec_enable_tpe = 1;
58796 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
58797 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
58798 + grsec_enable_tpe_all = 1;
58799 +#endif
58800 +#endif
58801 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58802 + grsec_enable_socket_all = 1;
58803 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
58804 +#endif
58805 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58806 + grsec_enable_socket_client = 1;
58807 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
58808 +#endif
58809 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58810 + grsec_enable_socket_server = 1;
58811 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
58812 +#endif
58813 +#endif
58814 +
58815 + return;
58816 +}
58817 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
58818 new file mode 100644
58819 index 0000000..589481f
58820 --- /dev/null
58821 +++ b/grsecurity/grsec_link.c
58822 @@ -0,0 +1,58 @@
58823 +#include <linux/kernel.h>
58824 +#include <linux/sched.h>
58825 +#include <linux/fs.h>
58826 +#include <linux/file.h>
58827 +#include <linux/grinternal.h>
58828 +
58829 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
58830 +{
58831 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58832 + const struct inode *link_inode = link->dentry->d_inode;
58833 +
58834 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
58835 + /* ignore root-owned links, e.g. /proc/self */
58836 + !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
58837 + !uid_eq(link_inode->i_uid, target->i_uid)) {
58838 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
58839 + return 1;
58840 + }
58841 +#endif
58842 + return 0;
58843 +}
58844 +
58845 +int
58846 +gr_handle_follow_link(const struct inode *parent,
58847 + const struct inode *inode,
58848 + const struct dentry *dentry, const struct vfsmount *mnt)
58849 +{
58850 +#ifdef CONFIG_GRKERNSEC_LINK
58851 + const struct cred *cred = current_cred();
58852 +
58853 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
58854 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
58855 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
58856 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
58857 + return -EACCES;
58858 + }
58859 +#endif
58860 + return 0;
58861 +}
58862 +
58863 +int
58864 +gr_handle_hardlink(const struct dentry *dentry,
58865 + const struct vfsmount *mnt,
58866 + struct inode *inode, const int mode, const char *to)
58867 +{
58868 +#ifdef CONFIG_GRKERNSEC_LINK
58869 + const struct cred *cred = current_cred();
58870 +
58871 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
58872 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
58873 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
58874 + !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
58875 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
58876 + return -EPERM;
58877 + }
58878 +#endif
58879 + return 0;
58880 +}
58881 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
58882 new file mode 100644
58883 index 0000000..a45d2e9
58884 --- /dev/null
58885 +++ b/grsecurity/grsec_log.c
58886 @@ -0,0 +1,322 @@
58887 +#include <linux/kernel.h>
58888 +#include <linux/sched.h>
58889 +#include <linux/file.h>
58890 +#include <linux/tty.h>
58891 +#include <linux/fs.h>
58892 +#include <linux/grinternal.h>
58893 +
58894 +#ifdef CONFIG_TREE_PREEMPT_RCU
58895 +#define DISABLE_PREEMPT() preempt_disable()
58896 +#define ENABLE_PREEMPT() preempt_enable()
58897 +#else
58898 +#define DISABLE_PREEMPT()
58899 +#define ENABLE_PREEMPT()
58900 +#endif
58901 +
58902 +#define BEGIN_LOCKS(x) \
58903 + DISABLE_PREEMPT(); \
58904 + rcu_read_lock(); \
58905 + read_lock(&tasklist_lock); \
58906 + read_lock(&grsec_exec_file_lock); \
58907 + if (x != GR_DO_AUDIT) \
58908 + spin_lock(&grsec_alert_lock); \
58909 + else \
58910 + spin_lock(&grsec_audit_lock)
58911 +
58912 +#define END_LOCKS(x) \
58913 + if (x != GR_DO_AUDIT) \
58914 + spin_unlock(&grsec_alert_lock); \
58915 + else \
58916 + spin_unlock(&grsec_audit_lock); \
58917 + read_unlock(&grsec_exec_file_lock); \
58918 + read_unlock(&tasklist_lock); \
58919 + rcu_read_unlock(); \
58920 + ENABLE_PREEMPT(); \
58921 + if (x == GR_DONT_AUDIT) \
58922 + gr_handle_alertkill(current)
58923 +
58924 +enum {
58925 + FLOODING,
58926 + NO_FLOODING
58927 +};
58928 +
58929 +extern char *gr_alert_log_fmt;
58930 +extern char *gr_audit_log_fmt;
58931 +extern char *gr_alert_log_buf;
58932 +extern char *gr_audit_log_buf;
58933 +
58934 +static int gr_log_start(int audit)
58935 +{
58936 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
58937 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
58938 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58939 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
58940 + unsigned long curr_secs = get_seconds();
58941 +
58942 + if (audit == GR_DO_AUDIT)
58943 + goto set_fmt;
58944 +
58945 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
58946 + grsec_alert_wtime = curr_secs;
58947 + grsec_alert_fyet = 0;
58948 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
58949 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
58950 + grsec_alert_fyet++;
58951 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
58952 + grsec_alert_wtime = curr_secs;
58953 + grsec_alert_fyet++;
58954 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
58955 + return FLOODING;
58956 + }
58957 + else return FLOODING;
58958 +
58959 +set_fmt:
58960 +#endif
58961 + memset(buf, 0, PAGE_SIZE);
58962 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
58963 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
58964 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58965 + } else if (current->signal->curr_ip) {
58966 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
58967 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
58968 + } else if (gr_acl_is_enabled()) {
58969 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
58970 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58971 + } else {
58972 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
58973 + strcpy(buf, fmt);
58974 + }
58975 +
58976 + return NO_FLOODING;
58977 +}
58978 +
58979 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58980 + __attribute__ ((format (printf, 2, 0)));
58981 +
58982 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58983 +{
58984 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58985 + unsigned int len = strlen(buf);
58986 +
58987 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58988 +
58989 + return;
58990 +}
58991 +
58992 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58993 + __attribute__ ((format (printf, 2, 3)));
58994 +
58995 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58996 +{
58997 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58998 + unsigned int len = strlen(buf);
58999 + va_list ap;
59000 +
59001 + va_start(ap, msg);
59002 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
59003 + va_end(ap);
59004 +
59005 + return;
59006 +}
59007 +
59008 +static void gr_log_end(int audit, int append_default)
59009 +{
59010 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59011 +
59012 + if (append_default) {
59013 + unsigned int len = strlen(buf);
59014 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
59015 + }
59016 +
59017 + printk("%s\n", buf);
59018 +
59019 + return;
59020 +}
59021 +
59022 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
59023 +{
59024 + int logtype;
59025 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
59026 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
59027 + void *voidptr = NULL;
59028 + int num1 = 0, num2 = 0;
59029 + unsigned long ulong1 = 0, ulong2 = 0;
59030 + struct dentry *dentry = NULL;
59031 + struct vfsmount *mnt = NULL;
59032 + struct file *file = NULL;
59033 + struct task_struct *task = NULL;
59034 + const struct cred *cred, *pcred;
59035 + va_list ap;
59036 +
59037 + BEGIN_LOCKS(audit);
59038 + logtype = gr_log_start(audit);
59039 + if (logtype == FLOODING) {
59040 + END_LOCKS(audit);
59041 + return;
59042 + }
59043 + va_start(ap, argtypes);
59044 + switch (argtypes) {
59045 + case GR_TTYSNIFF:
59046 + task = va_arg(ap, struct task_struct *);
59047 + 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);
59048 + break;
59049 + case GR_SYSCTL_HIDDEN:
59050 + str1 = va_arg(ap, char *);
59051 + gr_log_middle_varargs(audit, msg, result, str1);
59052 + break;
59053 + case GR_RBAC:
59054 + dentry = va_arg(ap, struct dentry *);
59055 + mnt = va_arg(ap, struct vfsmount *);
59056 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
59057 + break;
59058 + case GR_RBAC_STR:
59059 + dentry = va_arg(ap, struct dentry *);
59060 + mnt = va_arg(ap, struct vfsmount *);
59061 + str1 = va_arg(ap, char *);
59062 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
59063 + break;
59064 + case GR_STR_RBAC:
59065 + str1 = va_arg(ap, char *);
59066 + dentry = va_arg(ap, struct dentry *);
59067 + mnt = va_arg(ap, struct vfsmount *);
59068 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
59069 + break;
59070 + case GR_RBAC_MODE2:
59071 + dentry = va_arg(ap, struct dentry *);
59072 + mnt = va_arg(ap, struct vfsmount *);
59073 + str1 = va_arg(ap, char *);
59074 + str2 = va_arg(ap, char *);
59075 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
59076 + break;
59077 + case GR_RBAC_MODE3:
59078 + dentry = va_arg(ap, struct dentry *);
59079 + mnt = va_arg(ap, struct vfsmount *);
59080 + str1 = va_arg(ap, char *);
59081 + str2 = va_arg(ap, char *);
59082 + str3 = va_arg(ap, char *);
59083 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
59084 + break;
59085 + case GR_FILENAME:
59086 + dentry = va_arg(ap, struct dentry *);
59087 + mnt = va_arg(ap, struct vfsmount *);
59088 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
59089 + break;
59090 + case GR_STR_FILENAME:
59091 + str1 = va_arg(ap, char *);
59092 + dentry = va_arg(ap, struct dentry *);
59093 + mnt = va_arg(ap, struct vfsmount *);
59094 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
59095 + break;
59096 + case GR_FILENAME_STR:
59097 + dentry = va_arg(ap, struct dentry *);
59098 + mnt = va_arg(ap, struct vfsmount *);
59099 + str1 = va_arg(ap, char *);
59100 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
59101 + break;
59102 + case GR_FILENAME_TWO_INT:
59103 + dentry = va_arg(ap, struct dentry *);
59104 + mnt = va_arg(ap, struct vfsmount *);
59105 + num1 = va_arg(ap, int);
59106 + num2 = va_arg(ap, int);
59107 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
59108 + break;
59109 + case GR_FILENAME_TWO_INT_STR:
59110 + dentry = va_arg(ap, struct dentry *);
59111 + mnt = va_arg(ap, struct vfsmount *);
59112 + num1 = va_arg(ap, int);
59113 + num2 = va_arg(ap, int);
59114 + str1 = va_arg(ap, char *);
59115 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
59116 + break;
59117 + case GR_TEXTREL:
59118 + file = va_arg(ap, struct file *);
59119 + ulong1 = va_arg(ap, unsigned long);
59120 + ulong2 = va_arg(ap, unsigned long);
59121 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
59122 + break;
59123 + case GR_PTRACE:
59124 + task = va_arg(ap, struct task_struct *);
59125 + 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);
59126 + break;
59127 + case GR_RESOURCE:
59128 + task = va_arg(ap, struct task_struct *);
59129 + cred = __task_cred(task);
59130 + pcred = __task_cred(task->real_parent);
59131 + ulong1 = va_arg(ap, unsigned long);
59132 + str1 = va_arg(ap, char *);
59133 + ulong2 = va_arg(ap, unsigned long);
59134 + 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);
59135 + break;
59136 + case GR_CAP:
59137 + task = va_arg(ap, struct task_struct *);
59138 + cred = __task_cred(task);
59139 + pcred = __task_cred(task->real_parent);
59140 + str1 = va_arg(ap, char *);
59141 + 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);
59142 + break;
59143 + case GR_SIG:
59144 + str1 = va_arg(ap, char *);
59145 + voidptr = va_arg(ap, void *);
59146 + gr_log_middle_varargs(audit, msg, str1, voidptr);
59147 + break;
59148 + case GR_SIG2:
59149 + task = va_arg(ap, struct task_struct *);
59150 + cred = __task_cred(task);
59151 + pcred = __task_cred(task->real_parent);
59152 + num1 = va_arg(ap, int);
59153 + 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);
59154 + break;
59155 + case GR_CRASH1:
59156 + task = va_arg(ap, struct task_struct *);
59157 + cred = __task_cred(task);
59158 + pcred = __task_cred(task->real_parent);
59159 + ulong1 = va_arg(ap, unsigned long);
59160 + 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);
59161 + break;
59162 + case GR_CRASH2:
59163 + task = va_arg(ap, struct task_struct *);
59164 + cred = __task_cred(task);
59165 + pcred = __task_cred(task->real_parent);
59166 + ulong1 = va_arg(ap, unsigned long);
59167 + 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);
59168 + break;
59169 + case GR_RWXMAP:
59170 + file = va_arg(ap, struct file *);
59171 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
59172 + break;
59173 + case GR_PSACCT:
59174 + {
59175 + unsigned int wday, cday;
59176 + __u8 whr, chr;
59177 + __u8 wmin, cmin;
59178 + __u8 wsec, csec;
59179 + char cur_tty[64] = { 0 };
59180 + char parent_tty[64] = { 0 };
59181 +
59182 + task = va_arg(ap, struct task_struct *);
59183 + wday = va_arg(ap, unsigned int);
59184 + cday = va_arg(ap, unsigned int);
59185 + whr = va_arg(ap, int);
59186 + chr = va_arg(ap, int);
59187 + wmin = va_arg(ap, int);
59188 + cmin = va_arg(ap, int);
59189 + wsec = va_arg(ap, int);
59190 + csec = va_arg(ap, int);
59191 + ulong1 = va_arg(ap, unsigned long);
59192 + cred = __task_cred(task);
59193 + pcred = __task_cred(task->real_parent);
59194 +
59195 + 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);
59196 + }
59197 + break;
59198 + default:
59199 + gr_log_middle(audit, msg, ap);
59200 + }
59201 + va_end(ap);
59202 + // these don't need DEFAULTSECARGS printed on the end
59203 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
59204 + gr_log_end(audit, 0);
59205 + else
59206 + gr_log_end(audit, 1);
59207 + END_LOCKS(audit);
59208 +}
59209 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
59210 new file mode 100644
59211 index 0000000..f536303
59212 --- /dev/null
59213 +++ b/grsecurity/grsec_mem.c
59214 @@ -0,0 +1,40 @@
59215 +#include <linux/kernel.h>
59216 +#include <linux/sched.h>
59217 +#include <linux/mm.h>
59218 +#include <linux/mman.h>
59219 +#include <linux/grinternal.h>
59220 +
59221 +void
59222 +gr_handle_ioperm(void)
59223 +{
59224 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
59225 + return;
59226 +}
59227 +
59228 +void
59229 +gr_handle_iopl(void)
59230 +{
59231 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
59232 + return;
59233 +}
59234 +
59235 +void
59236 +gr_handle_mem_readwrite(u64 from, u64 to)
59237 +{
59238 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
59239 + return;
59240 +}
59241 +
59242 +void
59243 +gr_handle_vm86(void)
59244 +{
59245 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
59246 + return;
59247 +}
59248 +
59249 +void
59250 +gr_log_badprocpid(const char *entry)
59251 +{
59252 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
59253 + return;
59254 +}
59255 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
59256 new file mode 100644
59257 index 0000000..2131422
59258 --- /dev/null
59259 +++ b/grsecurity/grsec_mount.c
59260 @@ -0,0 +1,62 @@
59261 +#include <linux/kernel.h>
59262 +#include <linux/sched.h>
59263 +#include <linux/mount.h>
59264 +#include <linux/grsecurity.h>
59265 +#include <linux/grinternal.h>
59266 +
59267 +void
59268 +gr_log_remount(const char *devname, const int retval)
59269 +{
59270 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59271 + if (grsec_enable_mount && (retval >= 0))
59272 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
59273 +#endif
59274 + return;
59275 +}
59276 +
59277 +void
59278 +gr_log_unmount(const char *devname, const int retval)
59279 +{
59280 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59281 + if (grsec_enable_mount && (retval >= 0))
59282 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
59283 +#endif
59284 + return;
59285 +}
59286 +
59287 +void
59288 +gr_log_mount(const char *from, const char *to, const int retval)
59289 +{
59290 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59291 + if (grsec_enable_mount && (retval >= 0))
59292 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
59293 +#endif
59294 + return;
59295 +}
59296 +
59297 +int
59298 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
59299 +{
59300 +#ifdef CONFIG_GRKERNSEC_ROFS
59301 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
59302 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
59303 + return -EPERM;
59304 + } else
59305 + return 0;
59306 +#endif
59307 + return 0;
59308 +}
59309 +
59310 +int
59311 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
59312 +{
59313 +#ifdef CONFIG_GRKERNSEC_ROFS
59314 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
59315 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
59316 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
59317 + return -EPERM;
59318 + } else
59319 + return 0;
59320 +#endif
59321 + return 0;
59322 +}
59323 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
59324 new file mode 100644
59325 index 0000000..a3b12a0
59326 --- /dev/null
59327 +++ b/grsecurity/grsec_pax.c
59328 @@ -0,0 +1,36 @@
59329 +#include <linux/kernel.h>
59330 +#include <linux/sched.h>
59331 +#include <linux/mm.h>
59332 +#include <linux/file.h>
59333 +#include <linux/grinternal.h>
59334 +#include <linux/grsecurity.h>
59335 +
59336 +void
59337 +gr_log_textrel(struct vm_area_struct * vma)
59338 +{
59339 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59340 + if (grsec_enable_audit_textrel)
59341 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
59342 +#endif
59343 + return;
59344 +}
59345 +
59346 +void
59347 +gr_log_rwxmmap(struct file *file)
59348 +{
59349 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59350 + if (grsec_enable_log_rwxmaps)
59351 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
59352 +#endif
59353 + return;
59354 +}
59355 +
59356 +void
59357 +gr_log_rwxmprotect(struct file *file)
59358 +{
59359 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59360 + if (grsec_enable_log_rwxmaps)
59361 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
59362 +#endif
59363 + return;
59364 +}
59365 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
59366 new file mode 100644
59367 index 0000000..f7f29aa
59368 --- /dev/null
59369 +++ b/grsecurity/grsec_ptrace.c
59370 @@ -0,0 +1,30 @@
59371 +#include <linux/kernel.h>
59372 +#include <linux/sched.h>
59373 +#include <linux/grinternal.h>
59374 +#include <linux/security.h>
59375 +
59376 +void
59377 +gr_audit_ptrace(struct task_struct *task)
59378 +{
59379 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59380 + if (grsec_enable_audit_ptrace)
59381 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
59382 +#endif
59383 + return;
59384 +}
59385 +
59386 +int
59387 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
59388 +{
59389 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59390 + const struct dentry *dentry = file->f_path.dentry;
59391 + const struct vfsmount *mnt = file->f_path.mnt;
59392 +
59393 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
59394 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
59395 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
59396 + return -EACCES;
59397 + }
59398 +#endif
59399 + return 0;
59400 +}
59401 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
59402 new file mode 100644
59403 index 0000000..b4ac94c
59404 --- /dev/null
59405 +++ b/grsecurity/grsec_sig.c
59406 @@ -0,0 +1,209 @@
59407 +#include <linux/kernel.h>
59408 +#include <linux/sched.h>
59409 +#include <linux/delay.h>
59410 +#include <linux/grsecurity.h>
59411 +#include <linux/grinternal.h>
59412 +#include <linux/hardirq.h>
59413 +
59414 +char *signames[] = {
59415 + [SIGSEGV] = "Segmentation fault",
59416 + [SIGILL] = "Illegal instruction",
59417 + [SIGABRT] = "Abort",
59418 + [SIGBUS] = "Invalid alignment/Bus error"
59419 +};
59420 +
59421 +void
59422 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
59423 +{
59424 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59425 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
59426 + (sig == SIGABRT) || (sig == SIGBUS))) {
59427 + if (t->pid == current->pid) {
59428 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
59429 + } else {
59430 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
59431 + }
59432 + }
59433 +#endif
59434 + return;
59435 +}
59436 +
59437 +int
59438 +gr_handle_signal(const struct task_struct *p, const int sig)
59439 +{
59440 +#ifdef CONFIG_GRKERNSEC
59441 + /* ignore the 0 signal for protected task checks */
59442 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
59443 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
59444 + return -EPERM;
59445 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
59446 + return -EPERM;
59447 + }
59448 +#endif
59449 + return 0;
59450 +}
59451 +
59452 +#ifdef CONFIG_GRKERNSEC
59453 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
59454 +
59455 +int gr_fake_force_sig(int sig, struct task_struct *t)
59456 +{
59457 + unsigned long int flags;
59458 + int ret, blocked, ignored;
59459 + struct k_sigaction *action;
59460 +
59461 + spin_lock_irqsave(&t->sighand->siglock, flags);
59462 + action = &t->sighand->action[sig-1];
59463 + ignored = action->sa.sa_handler == SIG_IGN;
59464 + blocked = sigismember(&t->blocked, sig);
59465 + if (blocked || ignored) {
59466 + action->sa.sa_handler = SIG_DFL;
59467 + if (blocked) {
59468 + sigdelset(&t->blocked, sig);
59469 + recalc_sigpending_and_wake(t);
59470 + }
59471 + }
59472 + if (action->sa.sa_handler == SIG_DFL)
59473 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
59474 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
59475 +
59476 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
59477 +
59478 + return ret;
59479 +}
59480 +#endif
59481 +
59482 +#ifdef CONFIG_GRKERNSEC_BRUTE
59483 +#define GR_USER_BAN_TIME (15 * 60)
59484 +
59485 +static int __get_dumpable(unsigned long mm_flags)
59486 +{
59487 + int ret;
59488 +
59489 + ret = mm_flags & MMF_DUMPABLE_MASK;
59490 + return (ret >= 2) ? 2 : ret;
59491 +}
59492 +#endif
59493 +
59494 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
59495 +{
59496 +#ifdef CONFIG_GRKERNSEC_BRUTE
59497 + kuid_t uid = GLOBAL_ROOT_UID;
59498 +
59499 + if (!grsec_enable_brute)
59500 + return;
59501 +
59502 + rcu_read_lock();
59503 + read_lock(&tasklist_lock);
59504 + read_lock(&grsec_exec_file_lock);
59505 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
59506 + p->real_parent->brute = 1;
59507 + else {
59508 + const struct cred *cred = __task_cred(p), *cred2;
59509 + struct task_struct *tsk, *tsk2;
59510 +
59511 + if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
59512 + struct user_struct *user;
59513 +
59514 + uid = cred->uid;
59515 +
59516 + /* this is put upon execution past expiration */
59517 + user = find_user(uid);
59518 + if (user == NULL)
59519 + goto unlock;
59520 + user->banned = 1;
59521 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
59522 + if (user->ban_expires == ~0UL)
59523 + user->ban_expires--;
59524 +
59525 + do_each_thread(tsk2, tsk) {
59526 + cred2 = __task_cred(tsk);
59527 + if (tsk != p && uid_eq(cred2->uid, uid))
59528 + gr_fake_force_sig(SIGKILL, tsk);
59529 + } while_each_thread(tsk2, tsk);
59530 + }
59531 + }
59532 +unlock:
59533 + read_unlock(&grsec_exec_file_lock);
59534 + read_unlock(&tasklist_lock);
59535 + rcu_read_unlock();
59536 +
59537 + if (!uid_eq(uid, GLOBAL_ROOT_UID))
59538 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
59539 + from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
59540 +
59541 +#endif
59542 + return;
59543 +}
59544 +
59545 +void gr_handle_brute_check(void)
59546 +{
59547 +#ifdef CONFIG_GRKERNSEC_BRUTE
59548 + if (current->brute)
59549 + msleep(30 * 1000);
59550 +#endif
59551 + return;
59552 +}
59553 +
59554 +void gr_handle_kernel_exploit(void)
59555 +{
59556 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
59557 + const struct cred *cred;
59558 + struct task_struct *tsk, *tsk2;
59559 + struct user_struct *user;
59560 + kuid_t uid;
59561 +
59562 + if (in_irq() || in_serving_softirq() || in_nmi())
59563 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
59564 +
59565 + uid = current_uid();
59566 +
59567 + if (uid_eq(uid, GLOBAL_ROOT_UID))
59568 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
59569 + else {
59570 + /* kill all the processes of this user, hold a reference
59571 + to their creds struct, and prevent them from creating
59572 + another process until system reset
59573 + */
59574 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
59575 + from_kuid_munged(&init_user_ns, uid));
59576 + /* we intentionally leak this ref */
59577 + user = get_uid(current->cred->user);
59578 + if (user) {
59579 + user->banned = 1;
59580 + user->ban_expires = ~0UL;
59581 + }
59582 +
59583 + read_lock(&tasklist_lock);
59584 + do_each_thread(tsk2, tsk) {
59585 + cred = __task_cred(tsk);
59586 + if (uid_eq(cred->uid, uid))
59587 + gr_fake_force_sig(SIGKILL, tsk);
59588 + } while_each_thread(tsk2, tsk);
59589 + read_unlock(&tasklist_lock);
59590 + }
59591 +#endif
59592 +}
59593 +
59594 +int __gr_process_user_ban(struct user_struct *user)
59595 +{
59596 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59597 + if (unlikely(user->banned)) {
59598 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
59599 + user->banned = 0;
59600 + user->ban_expires = 0;
59601 + free_uid(user);
59602 + } else
59603 + return -EPERM;
59604 + }
59605 +#endif
59606 + return 0;
59607 +}
59608 +
59609 +int gr_process_user_ban(void)
59610 +{
59611 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59612 + return __gr_process_user_ban(current->cred->user);
59613 +#endif
59614 + return 0;
59615 +}
59616 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
59617 new file mode 100644
59618 index 0000000..4030d57
59619 --- /dev/null
59620 +++ b/grsecurity/grsec_sock.c
59621 @@ -0,0 +1,244 @@
59622 +#include <linux/kernel.h>
59623 +#include <linux/module.h>
59624 +#include <linux/sched.h>
59625 +#include <linux/file.h>
59626 +#include <linux/net.h>
59627 +#include <linux/in.h>
59628 +#include <linux/ip.h>
59629 +#include <net/sock.h>
59630 +#include <net/inet_sock.h>
59631 +#include <linux/grsecurity.h>
59632 +#include <linux/grinternal.h>
59633 +#include <linux/gracl.h>
59634 +
59635 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
59636 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
59637 +
59638 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
59639 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
59640 +
59641 +#ifdef CONFIG_UNIX_MODULE
59642 +EXPORT_SYMBOL(gr_acl_handle_unix);
59643 +EXPORT_SYMBOL(gr_acl_handle_mknod);
59644 +EXPORT_SYMBOL(gr_handle_chroot_unix);
59645 +EXPORT_SYMBOL(gr_handle_create);
59646 +#endif
59647 +
59648 +#ifdef CONFIG_GRKERNSEC
59649 +#define gr_conn_table_size 32749
59650 +struct conn_table_entry {
59651 + struct conn_table_entry *next;
59652 + struct signal_struct *sig;
59653 +};
59654 +
59655 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
59656 +DEFINE_SPINLOCK(gr_conn_table_lock);
59657 +
59658 +extern const char * gr_socktype_to_name(unsigned char type);
59659 +extern const char * gr_proto_to_name(unsigned char proto);
59660 +extern const char * gr_sockfamily_to_name(unsigned char family);
59661 +
59662 +static __inline__ int
59663 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
59664 +{
59665 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
59666 +}
59667 +
59668 +static __inline__ int
59669 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
59670 + __u16 sport, __u16 dport)
59671 +{
59672 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
59673 + sig->gr_sport == sport && sig->gr_dport == dport))
59674 + return 1;
59675 + else
59676 + return 0;
59677 +}
59678 +
59679 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
59680 +{
59681 + struct conn_table_entry **match;
59682 + unsigned int index;
59683 +
59684 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59685 + sig->gr_sport, sig->gr_dport,
59686 + gr_conn_table_size);
59687 +
59688 + newent->sig = sig;
59689 +
59690 + match = &gr_conn_table[index];
59691 + newent->next = *match;
59692 + *match = newent;
59693 +
59694 + return;
59695 +}
59696 +
59697 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
59698 +{
59699 + struct conn_table_entry *match, *last = NULL;
59700 + unsigned int index;
59701 +
59702 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59703 + sig->gr_sport, sig->gr_dport,
59704 + gr_conn_table_size);
59705 +
59706 + match = gr_conn_table[index];
59707 + while (match && !conn_match(match->sig,
59708 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
59709 + sig->gr_dport)) {
59710 + last = match;
59711 + match = match->next;
59712 + }
59713 +
59714 + if (match) {
59715 + if (last)
59716 + last->next = match->next;
59717 + else
59718 + gr_conn_table[index] = NULL;
59719 + kfree(match);
59720 + }
59721 +
59722 + return;
59723 +}
59724 +
59725 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
59726 + __u16 sport, __u16 dport)
59727 +{
59728 + struct conn_table_entry *match;
59729 + unsigned int index;
59730 +
59731 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
59732 +
59733 + match = gr_conn_table[index];
59734 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
59735 + match = match->next;
59736 +
59737 + if (match)
59738 + return match->sig;
59739 + else
59740 + return NULL;
59741 +}
59742 +
59743 +#endif
59744 +
59745 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
59746 +{
59747 +#ifdef CONFIG_GRKERNSEC
59748 + struct signal_struct *sig = task->signal;
59749 + struct conn_table_entry *newent;
59750 +
59751 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
59752 + if (newent == NULL)
59753 + return;
59754 + /* no bh lock needed since we are called with bh disabled */
59755 + spin_lock(&gr_conn_table_lock);
59756 + gr_del_task_from_ip_table_nolock(sig);
59757 + sig->gr_saddr = inet->inet_rcv_saddr;
59758 + sig->gr_daddr = inet->inet_daddr;
59759 + sig->gr_sport = inet->inet_sport;
59760 + sig->gr_dport = inet->inet_dport;
59761 + gr_add_to_task_ip_table_nolock(sig, newent);
59762 + spin_unlock(&gr_conn_table_lock);
59763 +#endif
59764 + return;
59765 +}
59766 +
59767 +void gr_del_task_from_ip_table(struct task_struct *task)
59768 +{
59769 +#ifdef CONFIG_GRKERNSEC
59770 + spin_lock_bh(&gr_conn_table_lock);
59771 + gr_del_task_from_ip_table_nolock(task->signal);
59772 + spin_unlock_bh(&gr_conn_table_lock);
59773 +#endif
59774 + return;
59775 +}
59776 +
59777 +void
59778 +gr_attach_curr_ip(const struct sock *sk)
59779 +{
59780 +#ifdef CONFIG_GRKERNSEC
59781 + struct signal_struct *p, *set;
59782 + const struct inet_sock *inet = inet_sk(sk);
59783 +
59784 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
59785 + return;
59786 +
59787 + set = current->signal;
59788 +
59789 + spin_lock_bh(&gr_conn_table_lock);
59790 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
59791 + inet->inet_dport, inet->inet_sport);
59792 + if (unlikely(p != NULL)) {
59793 + set->curr_ip = p->curr_ip;
59794 + set->used_accept = 1;
59795 + gr_del_task_from_ip_table_nolock(p);
59796 + spin_unlock_bh(&gr_conn_table_lock);
59797 + return;
59798 + }
59799 + spin_unlock_bh(&gr_conn_table_lock);
59800 +
59801 + set->curr_ip = inet->inet_daddr;
59802 + set->used_accept = 1;
59803 +#endif
59804 + return;
59805 +}
59806 +
59807 +int
59808 +gr_handle_sock_all(const int family, const int type, const int protocol)
59809 +{
59810 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59811 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
59812 + (family != AF_UNIX)) {
59813 + if (family == AF_INET)
59814 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
59815 + else
59816 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
59817 + return -EACCES;
59818 + }
59819 +#endif
59820 + return 0;
59821 +}
59822 +
59823 +int
59824 +gr_handle_sock_server(const struct sockaddr *sck)
59825 +{
59826 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59827 + if (grsec_enable_socket_server &&
59828 + in_group_p(grsec_socket_server_gid) &&
59829 + sck && (sck->sa_family != AF_UNIX) &&
59830 + (sck->sa_family != AF_LOCAL)) {
59831 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59832 + return -EACCES;
59833 + }
59834 +#endif
59835 + return 0;
59836 +}
59837 +
59838 +int
59839 +gr_handle_sock_server_other(const struct sock *sck)
59840 +{
59841 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59842 + if (grsec_enable_socket_server &&
59843 + in_group_p(grsec_socket_server_gid) &&
59844 + sck && (sck->sk_family != AF_UNIX) &&
59845 + (sck->sk_family != AF_LOCAL)) {
59846 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59847 + return -EACCES;
59848 + }
59849 +#endif
59850 + return 0;
59851 +}
59852 +
59853 +int
59854 +gr_handle_sock_client(const struct sockaddr *sck)
59855 +{
59856 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59857 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
59858 + sck && (sck->sa_family != AF_UNIX) &&
59859 + (sck->sa_family != AF_LOCAL)) {
59860 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
59861 + return -EACCES;
59862 + }
59863 +#endif
59864 + return 0;
59865 +}
59866 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
59867 new file mode 100644
59868 index 0000000..f55ef0f
59869 --- /dev/null
59870 +++ b/grsecurity/grsec_sysctl.c
59871 @@ -0,0 +1,469 @@
59872 +#include <linux/kernel.h>
59873 +#include <linux/sched.h>
59874 +#include <linux/sysctl.h>
59875 +#include <linux/grsecurity.h>
59876 +#include <linux/grinternal.h>
59877 +
59878 +int
59879 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
59880 +{
59881 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59882 + if (dirname == NULL || name == NULL)
59883 + return 0;
59884 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
59885 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
59886 + return -EACCES;
59887 + }
59888 +#endif
59889 + return 0;
59890 +}
59891 +
59892 +#ifdef CONFIG_GRKERNSEC_ROFS
59893 +static int __maybe_unused one = 1;
59894 +#endif
59895 +
59896 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
59897 +struct ctl_table grsecurity_table[] = {
59898 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59899 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
59900 +#ifdef CONFIG_GRKERNSEC_IO
59901 + {
59902 + .procname = "disable_priv_io",
59903 + .data = &grsec_disable_privio,
59904 + .maxlen = sizeof(int),
59905 + .mode = 0600,
59906 + .proc_handler = &proc_dointvec,
59907 + },
59908 +#endif
59909 +#endif
59910 +#ifdef CONFIG_GRKERNSEC_LINK
59911 + {
59912 + .procname = "linking_restrictions",
59913 + .data = &grsec_enable_link,
59914 + .maxlen = sizeof(int),
59915 + .mode = 0600,
59916 + .proc_handler = &proc_dointvec,
59917 + },
59918 +#endif
59919 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
59920 + {
59921 + .procname = "enforce_symlinksifowner",
59922 + .data = &grsec_enable_symlinkown,
59923 + .maxlen = sizeof(int),
59924 + .mode = 0600,
59925 + .proc_handler = &proc_dointvec,
59926 + },
59927 + {
59928 + .procname = "symlinkown_gid",
59929 + .data = &grsec_symlinkown_gid,
59930 + .maxlen = sizeof(int),
59931 + .mode = 0600,
59932 + .proc_handler = &proc_dointvec,
59933 + },
59934 +#endif
59935 +#ifdef CONFIG_GRKERNSEC_BRUTE
59936 + {
59937 + .procname = "deter_bruteforce",
59938 + .data = &grsec_enable_brute,
59939 + .maxlen = sizeof(int),
59940 + .mode = 0600,
59941 + .proc_handler = &proc_dointvec,
59942 + },
59943 +#endif
59944 +#ifdef CONFIG_GRKERNSEC_FIFO
59945 + {
59946 + .procname = "fifo_restrictions",
59947 + .data = &grsec_enable_fifo,
59948 + .maxlen = sizeof(int),
59949 + .mode = 0600,
59950 + .proc_handler = &proc_dointvec,
59951 + },
59952 +#endif
59953 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59954 + {
59955 + .procname = "ptrace_readexec",
59956 + .data = &grsec_enable_ptrace_readexec,
59957 + .maxlen = sizeof(int),
59958 + .mode = 0600,
59959 + .proc_handler = &proc_dointvec,
59960 + },
59961 +#endif
59962 +#ifdef CONFIG_GRKERNSEC_SETXID
59963 + {
59964 + .procname = "consistent_setxid",
59965 + .data = &grsec_enable_setxid,
59966 + .maxlen = sizeof(int),
59967 + .mode = 0600,
59968 + .proc_handler = &proc_dointvec,
59969 + },
59970 +#endif
59971 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
59972 + {
59973 + .procname = "ip_blackhole",
59974 + .data = &grsec_enable_blackhole,
59975 + .maxlen = sizeof(int),
59976 + .mode = 0600,
59977 + .proc_handler = &proc_dointvec,
59978 + },
59979 + {
59980 + .procname = "lastack_retries",
59981 + .data = &grsec_lastack_retries,
59982 + .maxlen = sizeof(int),
59983 + .mode = 0600,
59984 + .proc_handler = &proc_dointvec,
59985 + },
59986 +#endif
59987 +#ifdef CONFIG_GRKERNSEC_EXECLOG
59988 + {
59989 + .procname = "exec_logging",
59990 + .data = &grsec_enable_execlog,
59991 + .maxlen = sizeof(int),
59992 + .mode = 0600,
59993 + .proc_handler = &proc_dointvec,
59994 + },
59995 +#endif
59996 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59997 + {
59998 + .procname = "rwxmap_logging",
59999 + .data = &grsec_enable_log_rwxmaps,
60000 + .maxlen = sizeof(int),
60001 + .mode = 0600,
60002 + .proc_handler = &proc_dointvec,
60003 + },
60004 +#endif
60005 +#ifdef CONFIG_GRKERNSEC_SIGNAL
60006 + {
60007 + .procname = "signal_logging",
60008 + .data = &grsec_enable_signal,
60009 + .maxlen = sizeof(int),
60010 + .mode = 0600,
60011 + .proc_handler = &proc_dointvec,
60012 + },
60013 +#endif
60014 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
60015 + {
60016 + .procname = "forkfail_logging",
60017 + .data = &grsec_enable_forkfail,
60018 + .maxlen = sizeof(int),
60019 + .mode = 0600,
60020 + .proc_handler = &proc_dointvec,
60021 + },
60022 +#endif
60023 +#ifdef CONFIG_GRKERNSEC_TIME
60024 + {
60025 + .procname = "timechange_logging",
60026 + .data = &grsec_enable_time,
60027 + .maxlen = sizeof(int),
60028 + .mode = 0600,
60029 + .proc_handler = &proc_dointvec,
60030 + },
60031 +#endif
60032 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
60033 + {
60034 + .procname = "chroot_deny_shmat",
60035 + .data = &grsec_enable_chroot_shmat,
60036 + .maxlen = sizeof(int),
60037 + .mode = 0600,
60038 + .proc_handler = &proc_dointvec,
60039 + },
60040 +#endif
60041 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
60042 + {
60043 + .procname = "chroot_deny_unix",
60044 + .data = &grsec_enable_chroot_unix,
60045 + .maxlen = sizeof(int),
60046 + .mode = 0600,
60047 + .proc_handler = &proc_dointvec,
60048 + },
60049 +#endif
60050 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
60051 + {
60052 + .procname = "chroot_deny_mount",
60053 + .data = &grsec_enable_chroot_mount,
60054 + .maxlen = sizeof(int),
60055 + .mode = 0600,
60056 + .proc_handler = &proc_dointvec,
60057 + },
60058 +#endif
60059 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
60060 + {
60061 + .procname = "chroot_deny_fchdir",
60062 + .data = &grsec_enable_chroot_fchdir,
60063 + .maxlen = sizeof(int),
60064 + .mode = 0600,
60065 + .proc_handler = &proc_dointvec,
60066 + },
60067 +#endif
60068 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
60069 + {
60070 + .procname = "chroot_deny_chroot",
60071 + .data = &grsec_enable_chroot_double,
60072 + .maxlen = sizeof(int),
60073 + .mode = 0600,
60074 + .proc_handler = &proc_dointvec,
60075 + },
60076 +#endif
60077 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
60078 + {
60079 + .procname = "chroot_deny_pivot",
60080 + .data = &grsec_enable_chroot_pivot,
60081 + .maxlen = sizeof(int),
60082 + .mode = 0600,
60083 + .proc_handler = &proc_dointvec,
60084 + },
60085 +#endif
60086 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
60087 + {
60088 + .procname = "chroot_enforce_chdir",
60089 + .data = &grsec_enable_chroot_chdir,
60090 + .maxlen = sizeof(int),
60091 + .mode = 0600,
60092 + .proc_handler = &proc_dointvec,
60093 + },
60094 +#endif
60095 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
60096 + {
60097 + .procname = "chroot_deny_chmod",
60098 + .data = &grsec_enable_chroot_chmod,
60099 + .maxlen = sizeof(int),
60100 + .mode = 0600,
60101 + .proc_handler = &proc_dointvec,
60102 + },
60103 +#endif
60104 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
60105 + {
60106 + .procname = "chroot_deny_mknod",
60107 + .data = &grsec_enable_chroot_mknod,
60108 + .maxlen = sizeof(int),
60109 + .mode = 0600,
60110 + .proc_handler = &proc_dointvec,
60111 + },
60112 +#endif
60113 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
60114 + {
60115 + .procname = "chroot_restrict_nice",
60116 + .data = &grsec_enable_chroot_nice,
60117 + .maxlen = sizeof(int),
60118 + .mode = 0600,
60119 + .proc_handler = &proc_dointvec,
60120 + },
60121 +#endif
60122 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
60123 + {
60124 + .procname = "chroot_execlog",
60125 + .data = &grsec_enable_chroot_execlog,
60126 + .maxlen = sizeof(int),
60127 + .mode = 0600,
60128 + .proc_handler = &proc_dointvec,
60129 + },
60130 +#endif
60131 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60132 + {
60133 + .procname = "chroot_caps",
60134 + .data = &grsec_enable_chroot_caps,
60135 + .maxlen = sizeof(int),
60136 + .mode = 0600,
60137 + .proc_handler = &proc_dointvec,
60138 + },
60139 +#endif
60140 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
60141 + {
60142 + .procname = "chroot_deny_sysctl",
60143 + .data = &grsec_enable_chroot_sysctl,
60144 + .maxlen = sizeof(int),
60145 + .mode = 0600,
60146 + .proc_handler = &proc_dointvec,
60147 + },
60148 +#endif
60149 +#ifdef CONFIG_GRKERNSEC_TPE
60150 + {
60151 + .procname = "tpe",
60152 + .data = &grsec_enable_tpe,
60153 + .maxlen = sizeof(int),
60154 + .mode = 0600,
60155 + .proc_handler = &proc_dointvec,
60156 + },
60157 + {
60158 + .procname = "tpe_gid",
60159 + .data = &grsec_tpe_gid,
60160 + .maxlen = sizeof(int),
60161 + .mode = 0600,
60162 + .proc_handler = &proc_dointvec,
60163 + },
60164 +#endif
60165 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60166 + {
60167 + .procname = "tpe_invert",
60168 + .data = &grsec_enable_tpe_invert,
60169 + .maxlen = sizeof(int),
60170 + .mode = 0600,
60171 + .proc_handler = &proc_dointvec,
60172 + },
60173 +#endif
60174 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
60175 + {
60176 + .procname = "tpe_restrict_all",
60177 + .data = &grsec_enable_tpe_all,
60178 + .maxlen = sizeof(int),
60179 + .mode = 0600,
60180 + .proc_handler = &proc_dointvec,
60181 + },
60182 +#endif
60183 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
60184 + {
60185 + .procname = "socket_all",
60186 + .data = &grsec_enable_socket_all,
60187 + .maxlen = sizeof(int),
60188 + .mode = 0600,
60189 + .proc_handler = &proc_dointvec,
60190 + },
60191 + {
60192 + .procname = "socket_all_gid",
60193 + .data = &grsec_socket_all_gid,
60194 + .maxlen = sizeof(int),
60195 + .mode = 0600,
60196 + .proc_handler = &proc_dointvec,
60197 + },
60198 +#endif
60199 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
60200 + {
60201 + .procname = "socket_client",
60202 + .data = &grsec_enable_socket_client,
60203 + .maxlen = sizeof(int),
60204 + .mode = 0600,
60205 + .proc_handler = &proc_dointvec,
60206 + },
60207 + {
60208 + .procname = "socket_client_gid",
60209 + .data = &grsec_socket_client_gid,
60210 + .maxlen = sizeof(int),
60211 + .mode = 0600,
60212 + .proc_handler = &proc_dointvec,
60213 + },
60214 +#endif
60215 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60216 + {
60217 + .procname = "socket_server",
60218 + .data = &grsec_enable_socket_server,
60219 + .maxlen = sizeof(int),
60220 + .mode = 0600,
60221 + .proc_handler = &proc_dointvec,
60222 + },
60223 + {
60224 + .procname = "socket_server_gid",
60225 + .data = &grsec_socket_server_gid,
60226 + .maxlen = sizeof(int),
60227 + .mode = 0600,
60228 + .proc_handler = &proc_dointvec,
60229 + },
60230 +#endif
60231 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
60232 + {
60233 + .procname = "audit_group",
60234 + .data = &grsec_enable_group,
60235 + .maxlen = sizeof(int),
60236 + .mode = 0600,
60237 + .proc_handler = &proc_dointvec,
60238 + },
60239 + {
60240 + .procname = "audit_gid",
60241 + .data = &grsec_audit_gid,
60242 + .maxlen = sizeof(int),
60243 + .mode = 0600,
60244 + .proc_handler = &proc_dointvec,
60245 + },
60246 +#endif
60247 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
60248 + {
60249 + .procname = "audit_chdir",
60250 + .data = &grsec_enable_chdir,
60251 + .maxlen = sizeof(int),
60252 + .mode = 0600,
60253 + .proc_handler = &proc_dointvec,
60254 + },
60255 +#endif
60256 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60257 + {
60258 + .procname = "audit_mount",
60259 + .data = &grsec_enable_mount,
60260 + .maxlen = sizeof(int),
60261 + .mode = 0600,
60262 + .proc_handler = &proc_dointvec,
60263 + },
60264 +#endif
60265 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
60266 + {
60267 + .procname = "audit_textrel",
60268 + .data = &grsec_enable_audit_textrel,
60269 + .maxlen = sizeof(int),
60270 + .mode = 0600,
60271 + .proc_handler = &proc_dointvec,
60272 + },
60273 +#endif
60274 +#ifdef CONFIG_GRKERNSEC_DMESG
60275 + {
60276 + .procname = "dmesg",
60277 + .data = &grsec_enable_dmesg,
60278 + .maxlen = sizeof(int),
60279 + .mode = 0600,
60280 + .proc_handler = &proc_dointvec,
60281 + },
60282 +#endif
60283 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60284 + {
60285 + .procname = "chroot_findtask",
60286 + .data = &grsec_enable_chroot_findtask,
60287 + .maxlen = sizeof(int),
60288 + .mode = 0600,
60289 + .proc_handler = &proc_dointvec,
60290 + },
60291 +#endif
60292 +#ifdef CONFIG_GRKERNSEC_RESLOG
60293 + {
60294 + .procname = "resource_logging",
60295 + .data = &grsec_resource_logging,
60296 + .maxlen = sizeof(int),
60297 + .mode = 0600,
60298 + .proc_handler = &proc_dointvec,
60299 + },
60300 +#endif
60301 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
60302 + {
60303 + .procname = "audit_ptrace",
60304 + .data = &grsec_enable_audit_ptrace,
60305 + .maxlen = sizeof(int),
60306 + .mode = 0600,
60307 + .proc_handler = &proc_dointvec,
60308 + },
60309 +#endif
60310 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60311 + {
60312 + .procname = "harden_ptrace",
60313 + .data = &grsec_enable_harden_ptrace,
60314 + .maxlen = sizeof(int),
60315 + .mode = 0600,
60316 + .proc_handler = &proc_dointvec,
60317 + },
60318 +#endif
60319 + {
60320 + .procname = "grsec_lock",
60321 + .data = &grsec_lock,
60322 + .maxlen = sizeof(int),
60323 + .mode = 0600,
60324 + .proc_handler = &proc_dointvec,
60325 + },
60326 +#endif
60327 +#ifdef CONFIG_GRKERNSEC_ROFS
60328 + {
60329 + .procname = "romount_protect",
60330 + .data = &grsec_enable_rofs,
60331 + .maxlen = sizeof(int),
60332 + .mode = 0600,
60333 + .proc_handler = &proc_dointvec_minmax,
60334 + .extra1 = &one,
60335 + .extra2 = &one,
60336 + },
60337 +#endif
60338 + { }
60339 +};
60340 +#endif
60341 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
60342 new file mode 100644
60343 index 0000000..0dc13c3
60344 --- /dev/null
60345 +++ b/grsecurity/grsec_time.c
60346 @@ -0,0 +1,16 @@
60347 +#include <linux/kernel.h>
60348 +#include <linux/sched.h>
60349 +#include <linux/grinternal.h>
60350 +#include <linux/module.h>
60351 +
60352 +void
60353 +gr_log_timechange(void)
60354 +{
60355 +#ifdef CONFIG_GRKERNSEC_TIME
60356 + if (grsec_enable_time)
60357 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
60358 +#endif
60359 + return;
60360 +}
60361 +
60362 +EXPORT_SYMBOL(gr_log_timechange);
60363 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
60364 new file mode 100644
60365 index 0000000..07e0dc0
60366 --- /dev/null
60367 +++ b/grsecurity/grsec_tpe.c
60368 @@ -0,0 +1,73 @@
60369 +#include <linux/kernel.h>
60370 +#include <linux/sched.h>
60371 +#include <linux/file.h>
60372 +#include <linux/fs.h>
60373 +#include <linux/grinternal.h>
60374 +
60375 +extern int gr_acl_tpe_check(void);
60376 +
60377 +int
60378 +gr_tpe_allow(const struct file *file)
60379 +{
60380 +#ifdef CONFIG_GRKERNSEC
60381 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
60382 + const struct cred *cred = current_cred();
60383 + char *msg = NULL;
60384 + char *msg2 = NULL;
60385 +
60386 + // never restrict root
60387 + if (!cred->uid)
60388 + return 1;
60389 +
60390 + if (grsec_enable_tpe) {
60391 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60392 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
60393 + msg = "not being in trusted group";
60394 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
60395 + msg = "being in untrusted group";
60396 +#else
60397 + if (in_group_p(grsec_tpe_gid))
60398 + msg = "being in untrusted group";
60399 +#endif
60400 + }
60401 + if (!msg && gr_acl_tpe_check())
60402 + msg = "being in untrusted role";
60403 +
60404 + // not in any affected group/role
60405 + if (!msg)
60406 + goto next_check;
60407 +
60408 + if (inode->i_uid)
60409 + msg2 = "file in non-root-owned directory";
60410 + else if (inode->i_mode & S_IWOTH)
60411 + msg2 = "file in world-writable directory";
60412 + else if (inode->i_mode & S_IWGRP)
60413 + msg2 = "file in group-writable directory";
60414 +
60415 + if (msg && msg2) {
60416 + char fullmsg[70] = {0};
60417 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
60418 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
60419 + return 0;
60420 + }
60421 + msg = NULL;
60422 +next_check:
60423 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
60424 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
60425 + return 1;
60426 +
60427 + if (inode->i_uid && (inode->i_uid != cred->uid))
60428 + msg = "directory not owned by user";
60429 + else if (inode->i_mode & S_IWOTH)
60430 + msg = "file in world-writable directory";
60431 + else if (inode->i_mode & S_IWGRP)
60432 + msg = "file in group-writable directory";
60433 +
60434 + if (msg) {
60435 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
60436 + return 0;
60437 + }
60438 +#endif
60439 +#endif
60440 + return 1;
60441 +}
60442 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
60443 new file mode 100644
60444 index 0000000..9f7b1ac
60445 --- /dev/null
60446 +++ b/grsecurity/grsum.c
60447 @@ -0,0 +1,61 @@
60448 +#include <linux/err.h>
60449 +#include <linux/kernel.h>
60450 +#include <linux/sched.h>
60451 +#include <linux/mm.h>
60452 +#include <linux/scatterlist.h>
60453 +#include <linux/crypto.h>
60454 +#include <linux/gracl.h>
60455 +
60456 +
60457 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
60458 +#error "crypto and sha256 must be built into the kernel"
60459 +#endif
60460 +
60461 +int
60462 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
60463 +{
60464 + char *p;
60465 + struct crypto_hash *tfm;
60466 + struct hash_desc desc;
60467 + struct scatterlist sg;
60468 + unsigned char temp_sum[GR_SHA_LEN];
60469 + volatile int retval = 0;
60470 + volatile int dummy = 0;
60471 + unsigned int i;
60472 +
60473 + sg_init_table(&sg, 1);
60474 +
60475 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
60476 + if (IS_ERR(tfm)) {
60477 + /* should never happen, since sha256 should be built in */
60478 + return 1;
60479 + }
60480 +
60481 + desc.tfm = tfm;
60482 + desc.flags = 0;
60483 +
60484 + crypto_hash_init(&desc);
60485 +
60486 + p = salt;
60487 + sg_set_buf(&sg, p, GR_SALT_LEN);
60488 + crypto_hash_update(&desc, &sg, sg.length);
60489 +
60490 + p = entry->pw;
60491 + sg_set_buf(&sg, p, strlen(p));
60492 +
60493 + crypto_hash_update(&desc, &sg, sg.length);
60494 +
60495 + crypto_hash_final(&desc, temp_sum);
60496 +
60497 + memset(entry->pw, 0, GR_PW_LEN);
60498 +
60499 + for (i = 0; i < GR_SHA_LEN; i++)
60500 + if (sum[i] != temp_sum[i])
60501 + retval = 1;
60502 + else
60503 + dummy = 1; // waste a cycle
60504 +
60505 + crypto_free_hash(tfm);
60506 +
60507 + return retval;
60508 +}
60509 diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
60510 index bde976e..a1cc32a 100644
60511 --- a/include/acpi/acpi_bus.h
60512 +++ b/include/acpi/acpi_bus.h
60513 @@ -136,7 +136,7 @@ struct acpi_device_ops {
60514 acpi_op_bind bind;
60515 acpi_op_unbind unbind;
60516 acpi_op_notify notify;
60517 -};
60518 +} __no_const;
60519
60520 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
60521
60522 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
60523 index 77ff547..181834f 100644
60524 --- a/include/asm-generic/4level-fixup.h
60525 +++ b/include/asm-generic/4level-fixup.h
60526 @@ -13,8 +13,10 @@
60527 #define pmd_alloc(mm, pud, address) \
60528 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
60529 NULL: pmd_offset(pud, address))
60530 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
60531
60532 #define pud_alloc(mm, pgd, address) (pgd)
60533 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
60534 #define pud_offset(pgd, start) (pgd)
60535 #define pud_none(pud) 0
60536 #define pud_bad(pud) 0
60537 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
60538 index b7babf0..3ba8aee 100644
60539 --- a/include/asm-generic/atomic-long.h
60540 +++ b/include/asm-generic/atomic-long.h
60541 @@ -22,6 +22,12 @@
60542
60543 typedef atomic64_t atomic_long_t;
60544
60545 +#ifdef CONFIG_PAX_REFCOUNT
60546 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
60547 +#else
60548 +typedef atomic64_t atomic_long_unchecked_t;
60549 +#endif
60550 +
60551 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
60552
60553 static inline long atomic_long_read(atomic_long_t *l)
60554 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60555 return (long)atomic64_read(v);
60556 }
60557
60558 +#ifdef CONFIG_PAX_REFCOUNT
60559 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60560 +{
60561 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60562 +
60563 + return (long)atomic64_read_unchecked(v);
60564 +}
60565 +#endif
60566 +
60567 static inline void atomic_long_set(atomic_long_t *l, long i)
60568 {
60569 atomic64_t *v = (atomic64_t *)l;
60570 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60571 atomic64_set(v, i);
60572 }
60573
60574 +#ifdef CONFIG_PAX_REFCOUNT
60575 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60576 +{
60577 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60578 +
60579 + atomic64_set_unchecked(v, i);
60580 +}
60581 +#endif
60582 +
60583 static inline void atomic_long_inc(atomic_long_t *l)
60584 {
60585 atomic64_t *v = (atomic64_t *)l;
60586 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60587 atomic64_inc(v);
60588 }
60589
60590 +#ifdef CONFIG_PAX_REFCOUNT
60591 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60592 +{
60593 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60594 +
60595 + atomic64_inc_unchecked(v);
60596 +}
60597 +#endif
60598 +
60599 static inline void atomic_long_dec(atomic_long_t *l)
60600 {
60601 atomic64_t *v = (atomic64_t *)l;
60602 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60603 atomic64_dec(v);
60604 }
60605
60606 +#ifdef CONFIG_PAX_REFCOUNT
60607 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60608 +{
60609 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60610 +
60611 + atomic64_dec_unchecked(v);
60612 +}
60613 +#endif
60614 +
60615 static inline void atomic_long_add(long i, atomic_long_t *l)
60616 {
60617 atomic64_t *v = (atomic64_t *)l;
60618 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60619 atomic64_add(i, v);
60620 }
60621
60622 +#ifdef CONFIG_PAX_REFCOUNT
60623 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60624 +{
60625 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60626 +
60627 + atomic64_add_unchecked(i, v);
60628 +}
60629 +#endif
60630 +
60631 static inline void atomic_long_sub(long i, atomic_long_t *l)
60632 {
60633 atomic64_t *v = (atomic64_t *)l;
60634 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60635 atomic64_sub(i, v);
60636 }
60637
60638 +#ifdef CONFIG_PAX_REFCOUNT
60639 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60640 +{
60641 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60642 +
60643 + atomic64_sub_unchecked(i, v);
60644 +}
60645 +#endif
60646 +
60647 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60648 {
60649 atomic64_t *v = (atomic64_t *)l;
60650 @@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60651 return (long)atomic64_inc_return(v);
60652 }
60653
60654 +#ifdef CONFIG_PAX_REFCOUNT
60655 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60656 +{
60657 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60658 +
60659 + return (long)atomic64_inc_return_unchecked(v);
60660 +}
60661 +#endif
60662 +
60663 static inline long atomic_long_dec_return(atomic_long_t *l)
60664 {
60665 atomic64_t *v = (atomic64_t *)l;
60666 @@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60667
60668 typedef atomic_t atomic_long_t;
60669
60670 +#ifdef CONFIG_PAX_REFCOUNT
60671 +typedef atomic_unchecked_t atomic_long_unchecked_t;
60672 +#else
60673 +typedef atomic_t atomic_long_unchecked_t;
60674 +#endif
60675 +
60676 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
60677 static inline long atomic_long_read(atomic_long_t *l)
60678 {
60679 @@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60680 return (long)atomic_read(v);
60681 }
60682
60683 +#ifdef CONFIG_PAX_REFCOUNT
60684 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60685 +{
60686 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60687 +
60688 + return (long)atomic_read_unchecked(v);
60689 +}
60690 +#endif
60691 +
60692 static inline void atomic_long_set(atomic_long_t *l, long i)
60693 {
60694 atomic_t *v = (atomic_t *)l;
60695 @@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60696 atomic_set(v, i);
60697 }
60698
60699 +#ifdef CONFIG_PAX_REFCOUNT
60700 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60701 +{
60702 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60703 +
60704 + atomic_set_unchecked(v, i);
60705 +}
60706 +#endif
60707 +
60708 static inline void atomic_long_inc(atomic_long_t *l)
60709 {
60710 atomic_t *v = (atomic_t *)l;
60711 @@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60712 atomic_inc(v);
60713 }
60714
60715 +#ifdef CONFIG_PAX_REFCOUNT
60716 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60717 +{
60718 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60719 +
60720 + atomic_inc_unchecked(v);
60721 +}
60722 +#endif
60723 +
60724 static inline void atomic_long_dec(atomic_long_t *l)
60725 {
60726 atomic_t *v = (atomic_t *)l;
60727 @@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60728 atomic_dec(v);
60729 }
60730
60731 +#ifdef CONFIG_PAX_REFCOUNT
60732 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60733 +{
60734 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60735 +
60736 + atomic_dec_unchecked(v);
60737 +}
60738 +#endif
60739 +
60740 static inline void atomic_long_add(long i, atomic_long_t *l)
60741 {
60742 atomic_t *v = (atomic_t *)l;
60743 @@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60744 atomic_add(i, v);
60745 }
60746
60747 +#ifdef CONFIG_PAX_REFCOUNT
60748 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60749 +{
60750 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60751 +
60752 + atomic_add_unchecked(i, v);
60753 +}
60754 +#endif
60755 +
60756 static inline void atomic_long_sub(long i, atomic_long_t *l)
60757 {
60758 atomic_t *v = (atomic_t *)l;
60759 @@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60760 atomic_sub(i, v);
60761 }
60762
60763 +#ifdef CONFIG_PAX_REFCOUNT
60764 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60765 +{
60766 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60767 +
60768 + atomic_sub_unchecked(i, v);
60769 +}
60770 +#endif
60771 +
60772 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60773 {
60774 atomic_t *v = (atomic_t *)l;
60775 @@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60776 return (long)atomic_inc_return(v);
60777 }
60778
60779 +#ifdef CONFIG_PAX_REFCOUNT
60780 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60781 +{
60782 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60783 +
60784 + return (long)atomic_inc_return_unchecked(v);
60785 +}
60786 +#endif
60787 +
60788 static inline long atomic_long_dec_return(atomic_long_t *l)
60789 {
60790 atomic_t *v = (atomic_t *)l;
60791 @@ -255,4 +393,55 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60792
60793 #endif /* BITS_PER_LONG == 64 */
60794
60795 +#ifdef CONFIG_PAX_REFCOUNT
60796 +static inline void pax_refcount_needs_these_functions(void)
60797 +{
60798 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
60799 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
60800 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
60801 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
60802 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
60803 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
60804 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
60805 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
60806 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
60807 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
60808 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
60809 +#ifdef CONFIG_X86
60810 + atomic_clear_mask_unchecked(0, NULL);
60811 + atomic_set_mask_unchecked(0, NULL);
60812 +#endif
60813 +
60814 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
60815 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
60816 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
60817 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
60818 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
60819 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
60820 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
60821 +}
60822 +#else
60823 +#define atomic_read_unchecked(v) atomic_read(v)
60824 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
60825 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
60826 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
60827 +#define atomic_inc_unchecked(v) atomic_inc(v)
60828 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
60829 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
60830 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
60831 +#define atomic_dec_unchecked(v) atomic_dec(v)
60832 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
60833 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
60834 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
60835 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
60836 +
60837 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
60838 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
60839 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
60840 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
60841 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
60842 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
60843 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
60844 +#endif
60845 +
60846 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
60847 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
60848 index 1ced641..c896ee8 100644
60849 --- a/include/asm-generic/atomic.h
60850 +++ b/include/asm-generic/atomic.h
60851 @@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
60852 * Atomically clears the bits set in @mask from @v
60853 */
60854 #ifndef atomic_clear_mask
60855 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
60856 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
60857 {
60858 unsigned long flags;
60859
60860 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
60861 index b18ce4f..2ee2843 100644
60862 --- a/include/asm-generic/atomic64.h
60863 +++ b/include/asm-generic/atomic64.h
60864 @@ -16,6 +16,8 @@ typedef struct {
60865 long long counter;
60866 } atomic64_t;
60867
60868 +typedef atomic64_t atomic64_unchecked_t;
60869 +
60870 #define ATOMIC64_INIT(i) { (i) }
60871
60872 extern long long atomic64_read(const atomic64_t *v);
60873 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
60874 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
60875 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
60876
60877 +#define atomic64_read_unchecked(v) atomic64_read(v)
60878 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
60879 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
60880 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
60881 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
60882 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
60883 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
60884 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
60885 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
60886 +
60887 #endif /* _ASM_GENERIC_ATOMIC64_H */
60888 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
60889 index 1bfcfe5..e04c5c9 100644
60890 --- a/include/asm-generic/cache.h
60891 +++ b/include/asm-generic/cache.h
60892 @@ -6,7 +6,7 @@
60893 * cache lines need to provide their own cache.h.
60894 */
60895
60896 -#define L1_CACHE_SHIFT 5
60897 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
60898 +#define L1_CACHE_SHIFT 5UL
60899 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
60900
60901 #endif /* __ASM_GENERIC_CACHE_H */
60902 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
60903 index 0d68a1e..b74a761 100644
60904 --- a/include/asm-generic/emergency-restart.h
60905 +++ b/include/asm-generic/emergency-restart.h
60906 @@ -1,7 +1,7 @@
60907 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
60908 #define _ASM_GENERIC_EMERGENCY_RESTART_H
60909
60910 -static inline void machine_emergency_restart(void)
60911 +static inline __noreturn void machine_emergency_restart(void)
60912 {
60913 machine_restart(NULL);
60914 }
60915 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
60916 index 90f99c7..00ce236 100644
60917 --- a/include/asm-generic/kmap_types.h
60918 +++ b/include/asm-generic/kmap_types.h
60919 @@ -2,9 +2,9 @@
60920 #define _ASM_GENERIC_KMAP_TYPES_H
60921
60922 #ifdef __WITH_KM_FENCE
60923 -# define KM_TYPE_NR 41
60924 +# define KM_TYPE_NR 42
60925 #else
60926 -# define KM_TYPE_NR 20
60927 +# define KM_TYPE_NR 21
60928 #endif
60929
60930 #endif
60931 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
60932 index 9ceb03b..2efbcbd 100644
60933 --- a/include/asm-generic/local.h
60934 +++ b/include/asm-generic/local.h
60935 @@ -39,6 +39,7 @@ typedef struct
60936 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
60937 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
60938 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
60939 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
60940
60941 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
60942 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
60943 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
60944 index 725612b..9cc513a 100644
60945 --- a/include/asm-generic/pgtable-nopmd.h
60946 +++ b/include/asm-generic/pgtable-nopmd.h
60947 @@ -1,14 +1,19 @@
60948 #ifndef _PGTABLE_NOPMD_H
60949 #define _PGTABLE_NOPMD_H
60950
60951 -#ifndef __ASSEMBLY__
60952 -
60953 #include <asm-generic/pgtable-nopud.h>
60954
60955 -struct mm_struct;
60956 -
60957 #define __PAGETABLE_PMD_FOLDED
60958
60959 +#define PMD_SHIFT PUD_SHIFT
60960 +#define PTRS_PER_PMD 1
60961 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
60962 +#define PMD_MASK (~(PMD_SIZE-1))
60963 +
60964 +#ifndef __ASSEMBLY__
60965 +
60966 +struct mm_struct;
60967 +
60968 /*
60969 * Having the pmd type consist of a pud gets the size right, and allows
60970 * us to conceptually access the pud entry that this pmd is folded into
60971 @@ -16,11 +21,6 @@ struct mm_struct;
60972 */
60973 typedef struct { pud_t pud; } pmd_t;
60974
60975 -#define PMD_SHIFT PUD_SHIFT
60976 -#define PTRS_PER_PMD 1
60977 -#define PMD_SIZE (1UL << PMD_SHIFT)
60978 -#define PMD_MASK (~(PMD_SIZE-1))
60979 -
60980 /*
60981 * The "pud_xxx()" functions here are trivial for a folded two-level
60982 * setup: the pmd is never bad, and a pmd always exists (as it's folded
60983 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
60984 index 810431d..0ec4804f 100644
60985 --- a/include/asm-generic/pgtable-nopud.h
60986 +++ b/include/asm-generic/pgtable-nopud.h
60987 @@ -1,10 +1,15 @@
60988 #ifndef _PGTABLE_NOPUD_H
60989 #define _PGTABLE_NOPUD_H
60990
60991 -#ifndef __ASSEMBLY__
60992 -
60993 #define __PAGETABLE_PUD_FOLDED
60994
60995 +#define PUD_SHIFT PGDIR_SHIFT
60996 +#define PTRS_PER_PUD 1
60997 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
60998 +#define PUD_MASK (~(PUD_SIZE-1))
60999 +
61000 +#ifndef __ASSEMBLY__
61001 +
61002 /*
61003 * Having the pud type consist of a pgd gets the size right, and allows
61004 * us to conceptually access the pgd entry that this pud is folded into
61005 @@ -12,11 +17,6 @@
61006 */
61007 typedef struct { pgd_t pgd; } pud_t;
61008
61009 -#define PUD_SHIFT PGDIR_SHIFT
61010 -#define PTRS_PER_PUD 1
61011 -#define PUD_SIZE (1UL << PUD_SHIFT)
61012 -#define PUD_MASK (~(PUD_SIZE-1))
61013 -
61014 /*
61015 * The "pgd_xxx()" functions here are trivial for a folded two-level
61016 * setup: the pud is never bad, and a pud always exists (as it's folded
61017 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
61018 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
61019
61020 #define pgd_populate(mm, pgd, pud) do { } while (0)
61021 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
61022 /*
61023 * (puds are folded into pgds so this doesn't get actually called,
61024 * but the define is needed for a generic inline function.)
61025 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
61026 index ff4947b..f48183f 100644
61027 --- a/include/asm-generic/pgtable.h
61028 +++ b/include/asm-generic/pgtable.h
61029 @@ -530,6 +530,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
61030 #endif
61031 }
61032
61033 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
61034 +static inline unsigned long pax_open_kernel(void) { return 0; }
61035 +#endif
61036 +
61037 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
61038 +static inline unsigned long pax_close_kernel(void) { return 0; }
61039 +#endif
61040 +
61041 #endif /* CONFIG_MMU */
61042
61043 #endif /* !__ASSEMBLY__ */
61044 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
61045 index 4e2e1cc..12c266b 100644
61046 --- a/include/asm-generic/vmlinux.lds.h
61047 +++ b/include/asm-generic/vmlinux.lds.h
61048 @@ -218,6 +218,7 @@
61049 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
61050 VMLINUX_SYMBOL(__start_rodata) = .; \
61051 *(.rodata) *(.rodata.*) \
61052 + *(.data..read_only) \
61053 *(__vermagic) /* Kernel version magic */ \
61054 . = ALIGN(8); \
61055 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
61056 @@ -716,17 +717,18 @@
61057 * section in the linker script will go there too. @phdr should have
61058 * a leading colon.
61059 *
61060 - * Note that this macros defines __per_cpu_load as an absolute symbol.
61061 + * Note that this macros defines per_cpu_load as an absolute symbol.
61062 * If there is no need to put the percpu section at a predetermined
61063 * address, use PERCPU_SECTION.
61064 */
61065 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
61066 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
61067 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
61068 + per_cpu_load = .; \
61069 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
61070 - LOAD_OFFSET) { \
61071 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
61072 PERCPU_INPUT(cacheline) \
61073 } phdr \
61074 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
61075 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
61076
61077 /**
61078 * PERCPU_SECTION - define output section for percpu area, simple version
61079 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
61080 index d6b67bb..a272c29 100644
61081 --- a/include/drm/drmP.h
61082 +++ b/include/drm/drmP.h
61083 @@ -72,6 +72,7 @@
61084 #include <linux/workqueue.h>
61085 #include <linux/poll.h>
61086 #include <asm/pgalloc.h>
61087 +#include <asm/local.h>
61088 #include "drm.h"
61089
61090 #include <linux/idr.h>
61091 @@ -1067,7 +1068,7 @@ struct drm_device {
61092
61093 /** \name Usage Counters */
61094 /*@{ */
61095 - int open_count; /**< Outstanding files open */
61096 + local_t open_count; /**< Outstanding files open */
61097 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
61098 atomic_t vma_count; /**< Outstanding vma areas open */
61099 int buf_use; /**< Buffers in use -- cannot alloc */
61100 @@ -1078,7 +1079,7 @@ struct drm_device {
61101 /*@{ */
61102 unsigned long counters;
61103 enum drm_stat_type types[15];
61104 - atomic_t counts[15];
61105 + atomic_unchecked_t counts[15];
61106 /*@} */
61107
61108 struct list_head filelist;
61109 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
61110 index e01cc80..319855d 100644
61111 --- a/include/drm/drm_crtc_helper.h
61112 +++ b/include/drm/drm_crtc_helper.h
61113 @@ -81,7 +81,7 @@ struct drm_crtc_helper_funcs {
61114
61115 /* disable crtc when not in use - more explicit than dpms off */
61116 void (*disable)(struct drm_crtc *crtc);
61117 -};
61118 +} __no_const;
61119
61120 /**
61121 * drm_encoder_helper_funcs - helper operations for encoders
61122 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
61123 struct drm_connector *connector);
61124 /* disable encoder when not in use - more explicit than dpms off */
61125 void (*disable)(struct drm_encoder *encoder);
61126 -};
61127 +} __no_const;
61128
61129 /**
61130 * drm_connector_helper_funcs - helper operations for connectors
61131 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
61132 index d6d1da4..fdd1ac5 100644
61133 --- a/include/drm/ttm/ttm_memory.h
61134 +++ b/include/drm/ttm/ttm_memory.h
61135 @@ -48,7 +48,7 @@
61136
61137 struct ttm_mem_shrink {
61138 int (*do_shrink) (struct ttm_mem_shrink *);
61139 -};
61140 +} __no_const;
61141
61142 /**
61143 * struct ttm_mem_global - Global memory accounting structure.
61144 diff --git a/include/linux/a.out.h b/include/linux/a.out.h
61145 index e86dfca..40cc55f 100644
61146 --- a/include/linux/a.out.h
61147 +++ b/include/linux/a.out.h
61148 @@ -39,6 +39,14 @@ enum machine_type {
61149 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
61150 };
61151
61152 +/* Constants for the N_FLAGS field */
61153 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
61154 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
61155 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
61156 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
61157 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
61158 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
61159 +
61160 #if !defined (N_MAGIC)
61161 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
61162 #endif
61163 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
61164 index 06fd4bb..1caec0d 100644
61165 --- a/include/linux/atmdev.h
61166 +++ b/include/linux/atmdev.h
61167 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
61168 #endif
61169
61170 struct k_atm_aal_stats {
61171 -#define __HANDLE_ITEM(i) atomic_t i
61172 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
61173 __AAL_STAT_ITEMS
61174 #undef __HANDLE_ITEM
61175 };
61176 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
61177 index 366422b..1fa7f84 100644
61178 --- a/include/linux/binfmts.h
61179 +++ b/include/linux/binfmts.h
61180 @@ -89,6 +89,7 @@ struct linux_binfmt {
61181 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
61182 int (*load_shlib)(struct file *);
61183 int (*core_dump)(struct coredump_params *cprm);
61184 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
61185 unsigned long min_coredump; /* minimal dump size */
61186 };
61187
61188 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
61189 index 4a2ab7c..a2de7a8 100644
61190 --- a/include/linux/blkdev.h
61191 +++ b/include/linux/blkdev.h
61192 @@ -1420,7 +1420,7 @@ struct block_device_operations {
61193 /* this callback is with swap_lock and sometimes page table lock held */
61194 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
61195 struct module *owner;
61196 -};
61197 +} __do_const;
61198
61199 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
61200 unsigned long);
61201 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
61202 index 4d1a074..88f929a 100644
61203 --- a/include/linux/blktrace_api.h
61204 +++ b/include/linux/blktrace_api.h
61205 @@ -162,7 +162,7 @@ struct blk_trace {
61206 struct dentry *dir;
61207 struct dentry *dropped_file;
61208 struct dentry *msg_file;
61209 - atomic_t dropped;
61210 + atomic_unchecked_t dropped;
61211 };
61212
61213 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
61214 diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
61215 index 83195fb..0b0f77d 100644
61216 --- a/include/linux/byteorder/little_endian.h
61217 +++ b/include/linux/byteorder/little_endian.h
61218 @@ -42,51 +42,51 @@
61219
61220 static inline __le64 __cpu_to_le64p(const __u64 *p)
61221 {
61222 - return (__force __le64)*p;
61223 + return (__force const __le64)*p;
61224 }
61225 static inline __u64 __le64_to_cpup(const __le64 *p)
61226 {
61227 - return (__force __u64)*p;
61228 + return (__force const __u64)*p;
61229 }
61230 static inline __le32 __cpu_to_le32p(const __u32 *p)
61231 {
61232 - return (__force __le32)*p;
61233 + return (__force const __le32)*p;
61234 }
61235 static inline __u32 __le32_to_cpup(const __le32 *p)
61236 {
61237 - return (__force __u32)*p;
61238 + return (__force const __u32)*p;
61239 }
61240 static inline __le16 __cpu_to_le16p(const __u16 *p)
61241 {
61242 - return (__force __le16)*p;
61243 + return (__force const __le16)*p;
61244 }
61245 static inline __u16 __le16_to_cpup(const __le16 *p)
61246 {
61247 - return (__force __u16)*p;
61248 + return (__force const __u16)*p;
61249 }
61250 static inline __be64 __cpu_to_be64p(const __u64 *p)
61251 {
61252 - return (__force __be64)__swab64p(p);
61253 + return (__force const __be64)__swab64p(p);
61254 }
61255 static inline __u64 __be64_to_cpup(const __be64 *p)
61256 {
61257 - return __swab64p((__u64 *)p);
61258 + return __swab64p((const __u64 *)p);
61259 }
61260 static inline __be32 __cpu_to_be32p(const __u32 *p)
61261 {
61262 - return (__force __be32)__swab32p(p);
61263 + return (__force const __be32)__swab32p(p);
61264 }
61265 static inline __u32 __be32_to_cpup(const __be32 *p)
61266 {
61267 - return __swab32p((__u32 *)p);
61268 + return __swab32p((const __u32 *)p);
61269 }
61270 static inline __be16 __cpu_to_be16p(const __u16 *p)
61271 {
61272 - return (__force __be16)__swab16p(p);
61273 + return (__force const __be16)__swab16p(p);
61274 }
61275 static inline __u16 __be16_to_cpup(const __be16 *p)
61276 {
61277 - return __swab16p((__u16 *)p);
61278 + return __swab16p((const __u16 *)p);
61279 }
61280 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
61281 #define __le64_to_cpus(x) do { (void)(x); } while (0)
61282 diff --git a/include/linux/cache.h b/include/linux/cache.h
61283 index 4c57065..4307975 100644
61284 --- a/include/linux/cache.h
61285 +++ b/include/linux/cache.h
61286 @@ -16,6 +16,10 @@
61287 #define __read_mostly
61288 #endif
61289
61290 +#ifndef __read_only
61291 +#define __read_only __read_mostly
61292 +#endif
61293 +
61294 #ifndef ____cacheline_aligned
61295 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
61296 #endif
61297 diff --git a/include/linux/capability.h b/include/linux/capability.h
61298 index d10b7ed..0288b79 100644
61299 --- a/include/linux/capability.h
61300 +++ b/include/linux/capability.h
61301 @@ -553,10 +553,15 @@ extern bool capable(int cap);
61302 extern bool ns_capable(struct user_namespace *ns, int cap);
61303 extern bool nsown_capable(int cap);
61304 extern bool inode_capable(const struct inode *inode, int cap);
61305 +extern bool capable_nolog(int cap);
61306 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
61307 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
61308
61309 /* audit system wants to get cap info from files as well */
61310 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
61311
61312 +extern int is_privileged_binary(const struct dentry *dentry);
61313 +
61314 #endif /* __KERNEL__ */
61315
61316 #endif /* !_LINUX_CAPABILITY_H */
61317 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
61318 index 42e55de..1cd0e66 100644
61319 --- a/include/linux/cleancache.h
61320 +++ b/include/linux/cleancache.h
61321 @@ -31,7 +31,7 @@ struct cleancache_ops {
61322 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
61323 void (*invalidate_inode)(int, struct cleancache_filekey);
61324 void (*invalidate_fs)(int);
61325 -};
61326 +} __no_const;
61327
61328 extern struct cleancache_ops
61329 cleancache_register_ops(struct cleancache_ops *ops);
61330 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
61331 index 77335fa..6cbe7dd 100644
61332 --- a/include/linux/clk-provider.h
61333 +++ b/include/linux/clk-provider.h
61334 @@ -111,6 +111,7 @@ struct clk_ops {
61335 unsigned long);
61336 void (*init)(struct clk_hw *hw);
61337 };
61338 +typedef struct clk_ops __no_const clk_ops_no_const;
61339
61340 /**
61341 * struct clk_init_data - holds init data that's common to all clocks and is
61342 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
61343 index 934bc34..1b47129 100644
61344 --- a/include/linux/compiler-gcc4.h
61345 +++ b/include/linux/compiler-gcc4.h
61346 @@ -32,6 +32,21 @@
61347 #define __linktime_error(message) __attribute__((__error__(message)))
61348
61349 #if __GNUC_MINOR__ >= 5
61350 +
61351 +#ifdef CONSTIFY_PLUGIN
61352 +#define __no_const __attribute__((no_const))
61353 +#define __do_const __attribute__((do_const))
61354 +#endif
61355 +
61356 +#ifdef SIZE_OVERFLOW_PLUGIN
61357 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
61358 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
61359 +#endif
61360 +
61361 +#ifdef LATENT_ENTROPY_PLUGIN
61362 +#define __latent_entropy __attribute__((latent_entropy))
61363 +#endif
61364 +
61365 /*
61366 * Mark a position in code as unreachable. This can be used to
61367 * suppress control flow warnings after asm blocks that transfer
61368 @@ -47,6 +62,11 @@
61369 #define __noclone __attribute__((__noclone__))
61370
61371 #endif
61372 +
61373 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
61374 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
61375 +#define __bos0(ptr) __bos((ptr), 0)
61376 +#define __bos1(ptr) __bos((ptr), 1)
61377 #endif
61378
61379 #if __GNUC_MINOR__ >= 6
61380 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
61381 index f430e41..38be90f 100644
61382 --- a/include/linux/compiler.h
61383 +++ b/include/linux/compiler.h
61384 @@ -5,31 +5,62 @@
61385
61386 #ifdef __CHECKER__
61387 # define __user __attribute__((noderef, address_space(1)))
61388 +# define __force_user __force __user
61389 # define __kernel __attribute__((address_space(0)))
61390 +# define __force_kernel __force __kernel
61391 # define __safe __attribute__((safe))
61392 # define __force __attribute__((force))
61393 # define __nocast __attribute__((nocast))
61394 # define __iomem __attribute__((noderef, address_space(2)))
61395 +# define __force_iomem __force __iomem
61396 # define __acquires(x) __attribute__((context(x,0,1)))
61397 # define __releases(x) __attribute__((context(x,1,0)))
61398 # define __acquire(x) __context__(x,1)
61399 # define __release(x) __context__(x,-1)
61400 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
61401 # define __percpu __attribute__((noderef, address_space(3)))
61402 +# define __force_percpu __force __percpu
61403 #ifdef CONFIG_SPARSE_RCU_POINTER
61404 # define __rcu __attribute__((noderef, address_space(4)))
61405 +# define __force_rcu __force __rcu
61406 #else
61407 # define __rcu
61408 +# define __force_rcu
61409 #endif
61410 extern void __chk_user_ptr(const volatile void __user *);
61411 extern void __chk_io_ptr(const volatile void __iomem *);
61412 +#elif defined(CHECKER_PLUGIN)
61413 +//# define __user
61414 +//# define __force_user
61415 +//# define __kernel
61416 +//# define __force_kernel
61417 +# define __safe
61418 +# define __force
61419 +# define __nocast
61420 +# define __iomem
61421 +# define __force_iomem
61422 +# define __chk_user_ptr(x) (void)0
61423 +# define __chk_io_ptr(x) (void)0
61424 +# define __builtin_warning(x, y...) (1)
61425 +# define __acquires(x)
61426 +# define __releases(x)
61427 +# define __acquire(x) (void)0
61428 +# define __release(x) (void)0
61429 +# define __cond_lock(x,c) (c)
61430 +# define __percpu
61431 +# define __force_percpu
61432 +# define __rcu
61433 +# define __force_rcu
61434 #else
61435 # define __user
61436 +# define __force_user
61437 # define __kernel
61438 +# define __force_kernel
61439 # define __safe
61440 # define __force
61441 # define __nocast
61442 # define __iomem
61443 +# define __force_iomem
61444 # define __chk_user_ptr(x) (void)0
61445 # define __chk_io_ptr(x) (void)0
61446 # define __builtin_warning(x, y...) (1)
61447 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
61448 # define __release(x) (void)0
61449 # define __cond_lock(x,c) (c)
61450 # define __percpu
61451 +# define __force_percpu
61452 # define __rcu
61453 +# define __force_rcu
61454 #endif
61455
61456 #ifdef __KERNEL__
61457 @@ -264,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61458 # define __attribute_const__ /* unimplemented */
61459 #endif
61460
61461 +#ifndef __no_const
61462 +# define __no_const
61463 +#endif
61464 +
61465 +#ifndef __do_const
61466 +# define __do_const
61467 +#endif
61468 +
61469 +#ifndef __size_overflow
61470 +# define __size_overflow(...)
61471 +#endif
61472 +
61473 +#ifndef __intentional_overflow
61474 +# define __intentional_overflow(...)
61475 +#endif
61476 +
61477 +#ifndef __latent_entropy
61478 +# define __latent_entropy
61479 +#endif
61480 +
61481 /*
61482 * Tell gcc if a function is cold. The compiler will assume any path
61483 * directly leading to the call is unlikely.
61484 @@ -273,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61485 #define __cold
61486 #endif
61487
61488 +#ifndef __alloc_size
61489 +#define __alloc_size(...)
61490 +#endif
61491 +
61492 +#ifndef __bos
61493 +#define __bos(ptr, arg)
61494 +#endif
61495 +
61496 +#ifndef __bos0
61497 +#define __bos0(ptr)
61498 +#endif
61499 +
61500 +#ifndef __bos1
61501 +#define __bos1(ptr)
61502 +#endif
61503 +
61504 /* Simple shorthand for a section definition */
61505 #ifndef __section
61506 # define __section(S) __attribute__ ((__section__(#S)))
61507 @@ -312,6 +381,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61508 * use is to mediate communication between process-level code and irq/NMI
61509 * handlers, all running on the same CPU.
61510 */
61511 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
61512 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
61513 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
61514
61515 #endif /* __LINUX_COMPILER_H */
61516 diff --git a/include/linux/cred.h b/include/linux/cred.h
61517 index ebbed2c..908cc2c 100644
61518 --- a/include/linux/cred.h
61519 +++ b/include/linux/cred.h
61520 @@ -208,6 +208,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
61521 static inline void validate_process_creds(void)
61522 {
61523 }
61524 +static inline void validate_task_creds(struct task_struct *task)
61525 +{
61526 +}
61527 #endif
61528
61529 /**
61530 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
61531 index b92eadf..b4ecdc1 100644
61532 --- a/include/linux/crypto.h
61533 +++ b/include/linux/crypto.h
61534 @@ -373,7 +373,7 @@ struct cipher_tfm {
61535 const u8 *key, unsigned int keylen);
61536 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61537 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61538 -};
61539 +} __no_const;
61540
61541 struct hash_tfm {
61542 int (*init)(struct hash_desc *desc);
61543 @@ -394,13 +394,13 @@ struct compress_tfm {
61544 int (*cot_decompress)(struct crypto_tfm *tfm,
61545 const u8 *src, unsigned int slen,
61546 u8 *dst, unsigned int *dlen);
61547 -};
61548 +} __no_const;
61549
61550 struct rng_tfm {
61551 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
61552 unsigned int dlen);
61553 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
61554 -};
61555 +} __no_const;
61556
61557 #define crt_ablkcipher crt_u.ablkcipher
61558 #define crt_aead crt_u.aead
61559 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
61560 index 7925bf0..d5143d2 100644
61561 --- a/include/linux/decompress/mm.h
61562 +++ b/include/linux/decompress/mm.h
61563 @@ -77,7 +77,7 @@ static void free(void *where)
61564 * warnings when not needed (indeed large_malloc / large_free are not
61565 * needed by inflate */
61566
61567 -#define malloc(a) kmalloc(a, GFP_KERNEL)
61568 +#define malloc(a) kmalloc((a), GFP_KERNEL)
61569 #define free(a) kfree(a)
61570
61571 #define large_malloc(a) vmalloc(a)
61572 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
61573 index 94af418..b1ca7a2 100644
61574 --- a/include/linux/dma-mapping.h
61575 +++ b/include/linux/dma-mapping.h
61576 @@ -54,7 +54,7 @@ struct dma_map_ops {
61577 u64 (*get_required_mask)(struct device *dev);
61578 #endif
61579 int is_phys;
61580 -};
61581 +} __do_const;
61582
61583 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
61584
61585 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
61586 index 9c02a45..89fdd73 100644
61587 --- a/include/linux/dmaengine.h
61588 +++ b/include/linux/dmaengine.h
61589 @@ -1017,9 +1017,9 @@ struct dma_pinned_list {
61590 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
61591 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
61592
61593 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
61594 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
61595 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
61596 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
61597 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
61598 struct dma_pinned_list *pinned_list, struct page *page,
61599 unsigned int offset, size_t len);
61600
61601 diff --git a/include/linux/efi.h b/include/linux/efi.h
61602 index 5782114..e9b1ba1 100644
61603 --- a/include/linux/efi.h
61604 +++ b/include/linux/efi.h
61605 @@ -640,7 +640,7 @@ struct efivar_operations {
61606 efi_get_variable_t *get_variable;
61607 efi_get_next_variable_t *get_next_variable;
61608 efi_set_variable_t *set_variable;
61609 -};
61610 +} __no_const;
61611
61612 struct efivars {
61613 /*
61614 diff --git a/include/linux/elf.h b/include/linux/elf.h
61615 index 999b4f5..57753b4 100644
61616 --- a/include/linux/elf.h
61617 +++ b/include/linux/elf.h
61618 @@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
61619 #define PT_GNU_EH_FRAME 0x6474e550
61620
61621 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
61622 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
61623 +
61624 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
61625 +
61626 +/* Constants for the e_flags field */
61627 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
61628 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
61629 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
61630 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
61631 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
61632 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
61633
61634 /*
61635 * Extended Numbering
61636 @@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
61637 #define DT_DEBUG 21
61638 #define DT_TEXTREL 22
61639 #define DT_JMPREL 23
61640 +#define DT_FLAGS 30
61641 + #define DF_TEXTREL 0x00000004
61642 #define DT_ENCODING 32
61643 #define OLD_DT_LOOS 0x60000000
61644 #define DT_LOOS 0x6000000d
61645 @@ -243,6 +256,19 @@ typedef struct elf64_hdr {
61646 #define PF_W 0x2
61647 #define PF_X 0x1
61648
61649 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
61650 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
61651 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
61652 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
61653 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
61654 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
61655 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
61656 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
61657 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
61658 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
61659 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
61660 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
61661 +
61662 typedef struct elf32_phdr{
61663 Elf32_Word p_type;
61664 Elf32_Off p_offset;
61665 @@ -335,6 +361,8 @@ typedef struct elf64_shdr {
61666 #define EI_OSABI 7
61667 #define EI_PAD 8
61668
61669 +#define EI_PAX 14
61670 +
61671 #define ELFMAG0 0x7f /* EI_MAG */
61672 #define ELFMAG1 'E'
61673 #define ELFMAG2 'L'
61674 @@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
61675 #define elf_note elf32_note
61676 #define elf_addr_t Elf32_Off
61677 #define Elf_Half Elf32_Half
61678 +#define elf_dyn Elf32_Dyn
61679
61680 #else
61681
61682 @@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
61683 #define elf_note elf64_note
61684 #define elf_addr_t Elf64_Off
61685 #define Elf_Half Elf64_Half
61686 +#define elf_dyn Elf64_Dyn
61687
61688 #endif
61689
61690 diff --git a/include/linux/filter.h b/include/linux/filter.h
61691 index 82b0135..917914d 100644
61692 --- a/include/linux/filter.h
61693 +++ b/include/linux/filter.h
61694 @@ -146,6 +146,7 @@ struct compat_sock_fprog {
61695
61696 struct sk_buff;
61697 struct sock;
61698 +struct bpf_jit_work;
61699
61700 struct sk_filter
61701 {
61702 @@ -153,6 +154,9 @@ struct sk_filter
61703 unsigned int len; /* Number of filter blocks */
61704 unsigned int (*bpf_func)(const struct sk_buff *skb,
61705 const struct sock_filter *filter);
61706 +#ifdef CONFIG_BPF_JIT
61707 + struct bpf_jit_work *work;
61708 +#endif
61709 struct rcu_head rcu;
61710 struct sock_filter insns[0];
61711 };
61712 diff --git a/include/linux/firewire.h b/include/linux/firewire.h
61713 index db04ec5..f6ed627 100644
61714 --- a/include/linux/firewire.h
61715 +++ b/include/linux/firewire.h
61716 @@ -430,7 +430,7 @@ struct fw_iso_context {
61717 union {
61718 fw_iso_callback_t sc;
61719 fw_iso_mc_callback_t mc;
61720 - } callback;
61721 + } __no_const callback;
61722 void *callback_data;
61723 };
61724
61725 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
61726 index 0e4e2ee..4ff4312 100644
61727 --- a/include/linux/frontswap.h
61728 +++ b/include/linux/frontswap.h
61729 @@ -11,7 +11,7 @@ struct frontswap_ops {
61730 int (*load)(unsigned, pgoff_t, struct page *);
61731 void (*invalidate_page)(unsigned, pgoff_t);
61732 void (*invalidate_area)(unsigned);
61733 -};
61734 +} __no_const;
61735
61736 extern bool frontswap_enabled;
61737 extern struct frontswap_ops
61738 diff --git a/include/linux/fs.h b/include/linux/fs.h
61739 index aa11047..7d046d0 100644
61740 --- a/include/linux/fs.h
61741 +++ b/include/linux/fs.h
61742 @@ -1802,7 +1802,8 @@ struct file_operations {
61743 int (*setlease)(struct file *, long, struct file_lock **);
61744 long (*fallocate)(struct file *file, int mode, loff_t offset,
61745 loff_t len);
61746 -};
61747 +} __do_const;
61748 +typedef struct file_operations __no_const file_operations_no_const;
61749
61750 struct inode_operations {
61751 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
61752 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
61753 index 003dc0f..3c4ea97 100644
61754 --- a/include/linux/fs_struct.h
61755 +++ b/include/linux/fs_struct.h
61756 @@ -6,7 +6,7 @@
61757 #include <linux/seqlock.h>
61758
61759 struct fs_struct {
61760 - int users;
61761 + atomic_t users;
61762 spinlock_t lock;
61763 seqcount_t seq;
61764 int umask;
61765 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
61766 index ce31408..b1ad003 100644
61767 --- a/include/linux/fscache-cache.h
61768 +++ b/include/linux/fscache-cache.h
61769 @@ -102,7 +102,7 @@ struct fscache_operation {
61770 fscache_operation_release_t release;
61771 };
61772
61773 -extern atomic_t fscache_op_debug_id;
61774 +extern atomic_unchecked_t fscache_op_debug_id;
61775 extern void fscache_op_work_func(struct work_struct *work);
61776
61777 extern void fscache_enqueue_operation(struct fscache_operation *);
61778 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
61779 {
61780 INIT_WORK(&op->work, fscache_op_work_func);
61781 atomic_set(&op->usage, 1);
61782 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
61783 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
61784 op->processor = processor;
61785 op->release = release;
61786 INIT_LIST_HEAD(&op->pend_link);
61787 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
61788 index a6dfe69..569586df 100644
61789 --- a/include/linux/fsnotify.h
61790 +++ b/include/linux/fsnotify.h
61791 @@ -315,7 +315,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
61792 */
61793 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
61794 {
61795 - return kstrdup(name, GFP_KERNEL);
61796 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
61797 }
61798
61799 /*
61800 diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
61801 index 63d966d..cdcb717 100644
61802 --- a/include/linux/fsnotify_backend.h
61803 +++ b/include/linux/fsnotify_backend.h
61804 @@ -105,6 +105,7 @@ struct fsnotify_ops {
61805 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
61806 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
61807 };
61808 +typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
61809
61810 /*
61811 * A group is a "thing" that wants to receive notification about filesystem
61812 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
61813 index 642928c..e6c83a7 100644
61814 --- a/include/linux/ftrace_event.h
61815 +++ b/include/linux/ftrace_event.h
61816 @@ -97,7 +97,7 @@ struct trace_event_functions {
61817 trace_print_func raw;
61818 trace_print_func hex;
61819 trace_print_func binary;
61820 -};
61821 +} __no_const;
61822
61823 struct trace_event {
61824 struct hlist_node node;
61825 @@ -266,7 +266,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
61826 extern int trace_add_event_call(struct ftrace_event_call *call);
61827 extern void trace_remove_event_call(struct ftrace_event_call *call);
61828
61829 -#define is_signed_type(type) (((type)(-1)) < 0)
61830 +#define is_signed_type(type) (((type)(-1)) < (type)1)
61831
61832 int trace_set_clr_event(const char *system, const char *event, int set);
61833
61834 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
61835 index 4f440b3..342233a 100644
61836 --- a/include/linux/genhd.h
61837 +++ b/include/linux/genhd.h
61838 @@ -190,7 +190,7 @@ struct gendisk {
61839 struct kobject *slave_dir;
61840
61841 struct timer_rand_state *random;
61842 - atomic_t sync_io; /* RAID */
61843 + atomic_unchecked_t sync_io; /* RAID */
61844 struct disk_events *ev;
61845 #ifdef CONFIG_BLK_DEV_INTEGRITY
61846 struct blk_integrity *integrity;
61847 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
61848 index 4883f39..26688a8 100644
61849 --- a/include/linux/gfp.h
61850 +++ b/include/linux/gfp.h
61851 @@ -39,6 +39,12 @@ struct vm_area_struct;
61852 #define ___GFP_OTHER_NODE 0x800000u
61853 #define ___GFP_WRITE 0x1000000u
61854
61855 +#ifdef CONFIG_PAX_USERCOPY_SLABS
61856 +#define ___GFP_USERCOPY 0x2000000u
61857 +#else
61858 +#define ___GFP_USERCOPY 0
61859 +#endif
61860 +
61861 /*
61862 * GFP bitmasks..
61863 *
61864 @@ -93,6 +99,7 @@ struct vm_area_struct;
61865 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
61866 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
61867 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
61868 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
61869
61870 /*
61871 * This may seem redundant, but it's a way of annotating false positives vs.
61872 @@ -100,7 +107,7 @@ struct vm_area_struct;
61873 */
61874 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
61875
61876 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
61877 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
61878 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
61879
61880 /* This equals 0, but use constants in case they ever change */
61881 @@ -154,6 +161,8 @@ struct vm_area_struct;
61882 /* 4GB DMA on some platforms */
61883 #define GFP_DMA32 __GFP_DMA32
61884
61885 +#define GFP_USERCOPY __GFP_USERCOPY
61886 +
61887 /* Convert GFP flags to their corresponding migrate type */
61888 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
61889 {
61890 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
61891 new file mode 100644
61892 index 0000000..c938b1f
61893 --- /dev/null
61894 +++ b/include/linux/gracl.h
61895 @@ -0,0 +1,319 @@
61896 +#ifndef GR_ACL_H
61897 +#define GR_ACL_H
61898 +
61899 +#include <linux/grdefs.h>
61900 +#include <linux/resource.h>
61901 +#include <linux/capability.h>
61902 +#include <linux/dcache.h>
61903 +#include <asm/resource.h>
61904 +
61905 +/* Major status information */
61906 +
61907 +#define GR_VERSION "grsecurity 2.9.1"
61908 +#define GRSECURITY_VERSION 0x2901
61909 +
61910 +enum {
61911 + GR_SHUTDOWN = 0,
61912 + GR_ENABLE = 1,
61913 + GR_SPROLE = 2,
61914 + GR_RELOAD = 3,
61915 + GR_SEGVMOD = 4,
61916 + GR_STATUS = 5,
61917 + GR_UNSPROLE = 6,
61918 + GR_PASSSET = 7,
61919 + GR_SPROLEPAM = 8,
61920 +};
61921 +
61922 +/* Password setup definitions
61923 + * kernel/grhash.c */
61924 +enum {
61925 + GR_PW_LEN = 128,
61926 + GR_SALT_LEN = 16,
61927 + GR_SHA_LEN = 32,
61928 +};
61929 +
61930 +enum {
61931 + GR_SPROLE_LEN = 64,
61932 +};
61933 +
61934 +enum {
61935 + GR_NO_GLOB = 0,
61936 + GR_REG_GLOB,
61937 + GR_CREATE_GLOB
61938 +};
61939 +
61940 +#define GR_NLIMITS 32
61941 +
61942 +/* Begin Data Structures */
61943 +
61944 +struct sprole_pw {
61945 + unsigned char *rolename;
61946 + unsigned char salt[GR_SALT_LEN];
61947 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
61948 +};
61949 +
61950 +struct name_entry {
61951 + __u32 key;
61952 + ino_t inode;
61953 + dev_t device;
61954 + char *name;
61955 + __u16 len;
61956 + __u8 deleted;
61957 + struct name_entry *prev;
61958 + struct name_entry *next;
61959 +};
61960 +
61961 +struct inodev_entry {
61962 + struct name_entry *nentry;
61963 + struct inodev_entry *prev;
61964 + struct inodev_entry *next;
61965 +};
61966 +
61967 +struct acl_role_db {
61968 + struct acl_role_label **r_hash;
61969 + __u32 r_size;
61970 +};
61971 +
61972 +struct inodev_db {
61973 + struct inodev_entry **i_hash;
61974 + __u32 i_size;
61975 +};
61976 +
61977 +struct name_db {
61978 + struct name_entry **n_hash;
61979 + __u32 n_size;
61980 +};
61981 +
61982 +struct crash_uid {
61983 + uid_t uid;
61984 + unsigned long expires;
61985 +};
61986 +
61987 +struct gr_hash_struct {
61988 + void **table;
61989 + void **nametable;
61990 + void *first;
61991 + __u32 table_size;
61992 + __u32 used_size;
61993 + int type;
61994 +};
61995 +
61996 +/* Userspace Grsecurity ACL data structures */
61997 +
61998 +struct acl_subject_label {
61999 + char *filename;
62000 + ino_t inode;
62001 + dev_t device;
62002 + __u32 mode;
62003 + kernel_cap_t cap_mask;
62004 + kernel_cap_t cap_lower;
62005 + kernel_cap_t cap_invert_audit;
62006 +
62007 + struct rlimit res[GR_NLIMITS];
62008 + __u32 resmask;
62009 +
62010 + __u8 user_trans_type;
62011 + __u8 group_trans_type;
62012 + uid_t *user_transitions;
62013 + gid_t *group_transitions;
62014 + __u16 user_trans_num;
62015 + __u16 group_trans_num;
62016 +
62017 + __u32 sock_families[2];
62018 + __u32 ip_proto[8];
62019 + __u32 ip_type;
62020 + struct acl_ip_label **ips;
62021 + __u32 ip_num;
62022 + __u32 inaddr_any_override;
62023 +
62024 + __u32 crashes;
62025 + unsigned long expires;
62026 +
62027 + struct acl_subject_label *parent_subject;
62028 + struct gr_hash_struct *hash;
62029 + struct acl_subject_label *prev;
62030 + struct acl_subject_label *next;
62031 +
62032 + struct acl_object_label **obj_hash;
62033 + __u32 obj_hash_size;
62034 + __u16 pax_flags;
62035 +};
62036 +
62037 +struct role_allowed_ip {
62038 + __u32 addr;
62039 + __u32 netmask;
62040 +
62041 + struct role_allowed_ip *prev;
62042 + struct role_allowed_ip *next;
62043 +};
62044 +
62045 +struct role_transition {
62046 + char *rolename;
62047 +
62048 + struct role_transition *prev;
62049 + struct role_transition *next;
62050 +};
62051 +
62052 +struct acl_role_label {
62053 + char *rolename;
62054 + uid_t uidgid;
62055 + __u16 roletype;
62056 +
62057 + __u16 auth_attempts;
62058 + unsigned long expires;
62059 +
62060 + struct acl_subject_label *root_label;
62061 + struct gr_hash_struct *hash;
62062 +
62063 + struct acl_role_label *prev;
62064 + struct acl_role_label *next;
62065 +
62066 + struct role_transition *transitions;
62067 + struct role_allowed_ip *allowed_ips;
62068 + uid_t *domain_children;
62069 + __u16 domain_child_num;
62070 +
62071 + umode_t umask;
62072 +
62073 + struct acl_subject_label **subj_hash;
62074 + __u32 subj_hash_size;
62075 +};
62076 +
62077 +struct user_acl_role_db {
62078 + struct acl_role_label **r_table;
62079 + __u32 num_pointers; /* Number of allocations to track */
62080 + __u32 num_roles; /* Number of roles */
62081 + __u32 num_domain_children; /* Number of domain children */
62082 + __u32 num_subjects; /* Number of subjects */
62083 + __u32 num_objects; /* Number of objects */
62084 +};
62085 +
62086 +struct acl_object_label {
62087 + char *filename;
62088 + ino_t inode;
62089 + dev_t device;
62090 + __u32 mode;
62091 +
62092 + struct acl_subject_label *nested;
62093 + struct acl_object_label *globbed;
62094 +
62095 + /* next two structures not used */
62096 +
62097 + struct acl_object_label *prev;
62098 + struct acl_object_label *next;
62099 +};
62100 +
62101 +struct acl_ip_label {
62102 + char *iface;
62103 + __u32 addr;
62104 + __u32 netmask;
62105 + __u16 low, high;
62106 + __u8 mode;
62107 + __u32 type;
62108 + __u32 proto[8];
62109 +
62110 + /* next two structures not used */
62111 +
62112 + struct acl_ip_label *prev;
62113 + struct acl_ip_label *next;
62114 +};
62115 +
62116 +struct gr_arg {
62117 + struct user_acl_role_db role_db;
62118 + unsigned char pw[GR_PW_LEN];
62119 + unsigned char salt[GR_SALT_LEN];
62120 + unsigned char sum[GR_SHA_LEN];
62121 + unsigned char sp_role[GR_SPROLE_LEN];
62122 + struct sprole_pw *sprole_pws;
62123 + dev_t segv_device;
62124 + ino_t segv_inode;
62125 + uid_t segv_uid;
62126 + __u16 num_sprole_pws;
62127 + __u16 mode;
62128 +};
62129 +
62130 +struct gr_arg_wrapper {
62131 + struct gr_arg *arg;
62132 + __u32 version;
62133 + __u32 size;
62134 +};
62135 +
62136 +struct subject_map {
62137 + struct acl_subject_label *user;
62138 + struct acl_subject_label *kernel;
62139 + struct subject_map *prev;
62140 + struct subject_map *next;
62141 +};
62142 +
62143 +struct acl_subj_map_db {
62144 + struct subject_map **s_hash;
62145 + __u32 s_size;
62146 +};
62147 +
62148 +/* End Data Structures Section */
62149 +
62150 +/* Hash functions generated by empirical testing by Brad Spengler
62151 + Makes good use of the low bits of the inode. Generally 0-1 times
62152 + in loop for successful match. 0-3 for unsuccessful match.
62153 + Shift/add algorithm with modulus of table size and an XOR*/
62154 +
62155 +static __inline__ unsigned int
62156 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
62157 +{
62158 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
62159 +}
62160 +
62161 + static __inline__ unsigned int
62162 +shash(const struct acl_subject_label *userp, const unsigned int sz)
62163 +{
62164 + return ((const unsigned long)userp % sz);
62165 +}
62166 +
62167 +static __inline__ unsigned int
62168 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
62169 +{
62170 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
62171 +}
62172 +
62173 +static __inline__ unsigned int
62174 +nhash(const char *name, const __u16 len, const unsigned int sz)
62175 +{
62176 + return full_name_hash((const unsigned char *)name, len) % sz;
62177 +}
62178 +
62179 +#define FOR_EACH_ROLE_START(role) \
62180 + role = role_list; \
62181 + while (role) {
62182 +
62183 +#define FOR_EACH_ROLE_END(role) \
62184 + role = role->prev; \
62185 + }
62186 +
62187 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
62188 + subj = NULL; \
62189 + iter = 0; \
62190 + while (iter < role->subj_hash_size) { \
62191 + if (subj == NULL) \
62192 + subj = role->subj_hash[iter]; \
62193 + if (subj == NULL) { \
62194 + iter++; \
62195 + continue; \
62196 + }
62197 +
62198 +#define FOR_EACH_SUBJECT_END(subj,iter) \
62199 + subj = subj->next; \
62200 + if (subj == NULL) \
62201 + iter++; \
62202 + }
62203 +
62204 +
62205 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
62206 + subj = role->hash->first; \
62207 + while (subj != NULL) {
62208 +
62209 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
62210 + subj = subj->next; \
62211 + }
62212 +
62213 +#endif
62214 +
62215 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
62216 new file mode 100644
62217 index 0000000..323ecf2
62218 --- /dev/null
62219 +++ b/include/linux/gralloc.h
62220 @@ -0,0 +1,9 @@
62221 +#ifndef __GRALLOC_H
62222 +#define __GRALLOC_H
62223 +
62224 +void acl_free_all(void);
62225 +int acl_alloc_stack_init(unsigned long size);
62226 +void *acl_alloc(unsigned long len);
62227 +void *acl_alloc_num(unsigned long num, unsigned long len);
62228 +
62229 +#endif
62230 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
62231 new file mode 100644
62232 index 0000000..b30e9bc
62233 --- /dev/null
62234 +++ b/include/linux/grdefs.h
62235 @@ -0,0 +1,140 @@
62236 +#ifndef GRDEFS_H
62237 +#define GRDEFS_H
62238 +
62239 +/* Begin grsecurity status declarations */
62240 +
62241 +enum {
62242 + GR_READY = 0x01,
62243 + GR_STATUS_INIT = 0x00 // disabled state
62244 +};
62245 +
62246 +/* Begin ACL declarations */
62247 +
62248 +/* Role flags */
62249 +
62250 +enum {
62251 + GR_ROLE_USER = 0x0001,
62252 + GR_ROLE_GROUP = 0x0002,
62253 + GR_ROLE_DEFAULT = 0x0004,
62254 + GR_ROLE_SPECIAL = 0x0008,
62255 + GR_ROLE_AUTH = 0x0010,
62256 + GR_ROLE_NOPW = 0x0020,
62257 + GR_ROLE_GOD = 0x0040,
62258 + GR_ROLE_LEARN = 0x0080,
62259 + GR_ROLE_TPE = 0x0100,
62260 + GR_ROLE_DOMAIN = 0x0200,
62261 + GR_ROLE_PAM = 0x0400,
62262 + GR_ROLE_PERSIST = 0x0800
62263 +};
62264 +
62265 +/* ACL Subject and Object mode flags */
62266 +enum {
62267 + GR_DELETED = 0x80000000
62268 +};
62269 +
62270 +/* ACL Object-only mode flags */
62271 +enum {
62272 + GR_READ = 0x00000001,
62273 + GR_APPEND = 0x00000002,
62274 + GR_WRITE = 0x00000004,
62275 + GR_EXEC = 0x00000008,
62276 + GR_FIND = 0x00000010,
62277 + GR_INHERIT = 0x00000020,
62278 + GR_SETID = 0x00000040,
62279 + GR_CREATE = 0x00000080,
62280 + GR_DELETE = 0x00000100,
62281 + GR_LINK = 0x00000200,
62282 + GR_AUDIT_READ = 0x00000400,
62283 + GR_AUDIT_APPEND = 0x00000800,
62284 + GR_AUDIT_WRITE = 0x00001000,
62285 + GR_AUDIT_EXEC = 0x00002000,
62286 + GR_AUDIT_FIND = 0x00004000,
62287 + GR_AUDIT_INHERIT= 0x00008000,
62288 + GR_AUDIT_SETID = 0x00010000,
62289 + GR_AUDIT_CREATE = 0x00020000,
62290 + GR_AUDIT_DELETE = 0x00040000,
62291 + GR_AUDIT_LINK = 0x00080000,
62292 + GR_PTRACERD = 0x00100000,
62293 + GR_NOPTRACE = 0x00200000,
62294 + GR_SUPPRESS = 0x00400000,
62295 + GR_NOLEARN = 0x00800000,
62296 + GR_INIT_TRANSFER= 0x01000000
62297 +};
62298 +
62299 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
62300 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
62301 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
62302 +
62303 +/* ACL subject-only mode flags */
62304 +enum {
62305 + GR_KILL = 0x00000001,
62306 + GR_VIEW = 0x00000002,
62307 + GR_PROTECTED = 0x00000004,
62308 + GR_LEARN = 0x00000008,
62309 + GR_OVERRIDE = 0x00000010,
62310 + /* just a placeholder, this mode is only used in userspace */
62311 + GR_DUMMY = 0x00000020,
62312 + GR_PROTSHM = 0x00000040,
62313 + GR_KILLPROC = 0x00000080,
62314 + GR_KILLIPPROC = 0x00000100,
62315 + /* just a placeholder, this mode is only used in userspace */
62316 + GR_NOTROJAN = 0x00000200,
62317 + GR_PROTPROCFD = 0x00000400,
62318 + GR_PROCACCT = 0x00000800,
62319 + GR_RELAXPTRACE = 0x00001000,
62320 + GR_NESTED = 0x00002000,
62321 + GR_INHERITLEARN = 0x00004000,
62322 + GR_PROCFIND = 0x00008000,
62323 + GR_POVERRIDE = 0x00010000,
62324 + GR_KERNELAUTH = 0x00020000,
62325 + GR_ATSECURE = 0x00040000,
62326 + GR_SHMEXEC = 0x00080000
62327 +};
62328 +
62329 +enum {
62330 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
62331 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
62332 + GR_PAX_ENABLE_MPROTECT = 0x0004,
62333 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
62334 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
62335 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
62336 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
62337 + GR_PAX_DISABLE_MPROTECT = 0x0400,
62338 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
62339 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
62340 +};
62341 +
62342 +enum {
62343 + GR_ID_USER = 0x01,
62344 + GR_ID_GROUP = 0x02,
62345 +};
62346 +
62347 +enum {
62348 + GR_ID_ALLOW = 0x01,
62349 + GR_ID_DENY = 0x02,
62350 +};
62351 +
62352 +#define GR_CRASH_RES 31
62353 +#define GR_UIDTABLE_MAX 500
62354 +
62355 +/* begin resource learning section */
62356 +enum {
62357 + GR_RLIM_CPU_BUMP = 60,
62358 + GR_RLIM_FSIZE_BUMP = 50000,
62359 + GR_RLIM_DATA_BUMP = 10000,
62360 + GR_RLIM_STACK_BUMP = 1000,
62361 + GR_RLIM_CORE_BUMP = 10000,
62362 + GR_RLIM_RSS_BUMP = 500000,
62363 + GR_RLIM_NPROC_BUMP = 1,
62364 + GR_RLIM_NOFILE_BUMP = 5,
62365 + GR_RLIM_MEMLOCK_BUMP = 50000,
62366 + GR_RLIM_AS_BUMP = 500000,
62367 + GR_RLIM_LOCKS_BUMP = 2,
62368 + GR_RLIM_SIGPENDING_BUMP = 5,
62369 + GR_RLIM_MSGQUEUE_BUMP = 10000,
62370 + GR_RLIM_NICE_BUMP = 1,
62371 + GR_RLIM_RTPRIO_BUMP = 1,
62372 + GR_RLIM_RTTIME_BUMP = 1000000
62373 +};
62374 +
62375 +#endif
62376 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
62377 new file mode 100644
62378 index 0000000..c9292f7
62379 --- /dev/null
62380 +++ b/include/linux/grinternal.h
62381 @@ -0,0 +1,223 @@
62382 +#ifndef __GRINTERNAL_H
62383 +#define __GRINTERNAL_H
62384 +
62385 +#ifdef CONFIG_GRKERNSEC
62386 +
62387 +#include <linux/fs.h>
62388 +#include <linux/mnt_namespace.h>
62389 +#include <linux/nsproxy.h>
62390 +#include <linux/gracl.h>
62391 +#include <linux/grdefs.h>
62392 +#include <linux/grmsg.h>
62393 +
62394 +void gr_add_learn_entry(const char *fmt, ...)
62395 + __attribute__ ((format (printf, 1, 2)));
62396 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
62397 + const struct vfsmount *mnt);
62398 +__u32 gr_check_create(const struct dentry *new_dentry,
62399 + const struct dentry *parent,
62400 + const struct vfsmount *mnt, const __u32 mode);
62401 +int gr_check_protected_task(const struct task_struct *task);
62402 +__u32 to_gr_audit(const __u32 reqmode);
62403 +int gr_set_acls(const int type);
62404 +int gr_apply_subject_to_task(struct task_struct *task);
62405 +int gr_acl_is_enabled(void);
62406 +char gr_roletype_to_char(void);
62407 +
62408 +void gr_handle_alertkill(struct task_struct *task);
62409 +char *gr_to_filename(const struct dentry *dentry,
62410 + const struct vfsmount *mnt);
62411 +char *gr_to_filename1(const struct dentry *dentry,
62412 + const struct vfsmount *mnt);
62413 +char *gr_to_filename2(const struct dentry *dentry,
62414 + const struct vfsmount *mnt);
62415 +char *gr_to_filename3(const struct dentry *dentry,
62416 + const struct vfsmount *mnt);
62417 +
62418 +extern int grsec_enable_ptrace_readexec;
62419 +extern int grsec_enable_harden_ptrace;
62420 +extern int grsec_enable_link;
62421 +extern int grsec_enable_fifo;
62422 +extern int grsec_enable_execve;
62423 +extern int grsec_enable_shm;
62424 +extern int grsec_enable_execlog;
62425 +extern int grsec_enable_signal;
62426 +extern int grsec_enable_audit_ptrace;
62427 +extern int grsec_enable_forkfail;
62428 +extern int grsec_enable_time;
62429 +extern int grsec_enable_rofs;
62430 +extern int grsec_enable_chroot_shmat;
62431 +extern int grsec_enable_chroot_mount;
62432 +extern int grsec_enable_chroot_double;
62433 +extern int grsec_enable_chroot_pivot;
62434 +extern int grsec_enable_chroot_chdir;
62435 +extern int grsec_enable_chroot_chmod;
62436 +extern int grsec_enable_chroot_mknod;
62437 +extern int grsec_enable_chroot_fchdir;
62438 +extern int grsec_enable_chroot_nice;
62439 +extern int grsec_enable_chroot_execlog;
62440 +extern int grsec_enable_chroot_caps;
62441 +extern int grsec_enable_chroot_sysctl;
62442 +extern int grsec_enable_chroot_unix;
62443 +extern int grsec_enable_symlinkown;
62444 +extern int grsec_symlinkown_gid;
62445 +extern int grsec_enable_tpe;
62446 +extern int grsec_tpe_gid;
62447 +extern int grsec_enable_tpe_all;
62448 +extern int grsec_enable_tpe_invert;
62449 +extern int grsec_enable_socket_all;
62450 +extern int grsec_socket_all_gid;
62451 +extern int grsec_enable_socket_client;
62452 +extern int grsec_socket_client_gid;
62453 +extern int grsec_enable_socket_server;
62454 +extern int grsec_socket_server_gid;
62455 +extern int grsec_audit_gid;
62456 +extern int grsec_enable_group;
62457 +extern int grsec_enable_audit_textrel;
62458 +extern int grsec_enable_log_rwxmaps;
62459 +extern int grsec_enable_mount;
62460 +extern int grsec_enable_chdir;
62461 +extern int grsec_resource_logging;
62462 +extern int grsec_enable_blackhole;
62463 +extern int grsec_lastack_retries;
62464 +extern int grsec_enable_brute;
62465 +extern int grsec_lock;
62466 +
62467 +extern spinlock_t grsec_alert_lock;
62468 +extern unsigned long grsec_alert_wtime;
62469 +extern unsigned long grsec_alert_fyet;
62470 +
62471 +extern spinlock_t grsec_audit_lock;
62472 +
62473 +extern rwlock_t grsec_exec_file_lock;
62474 +
62475 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
62476 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
62477 + (tsk)->exec_file->f_vfsmnt) : "/")
62478 +
62479 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
62480 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
62481 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62482 +
62483 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
62484 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
62485 + (tsk)->exec_file->f_vfsmnt) : "/")
62486 +
62487 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
62488 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
62489 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62490 +
62491 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
62492 +
62493 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
62494 +
62495 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
62496 + (task)->pid, (cred)->uid, \
62497 + (cred)->euid, (cred)->gid, (cred)->egid, \
62498 + gr_parent_task_fullpath(task), \
62499 + (task)->real_parent->comm, (task)->real_parent->pid, \
62500 + (pcred)->uid, (pcred)->euid, \
62501 + (pcred)->gid, (pcred)->egid
62502 +
62503 +#define GR_CHROOT_CAPS {{ \
62504 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
62505 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
62506 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
62507 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
62508 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
62509 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
62510 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
62511 +
62512 +#define security_learn(normal_msg,args...) \
62513 +({ \
62514 + read_lock(&grsec_exec_file_lock); \
62515 + gr_add_learn_entry(normal_msg "\n", ## args); \
62516 + read_unlock(&grsec_exec_file_lock); \
62517 +})
62518 +
62519 +enum {
62520 + GR_DO_AUDIT,
62521 + GR_DONT_AUDIT,
62522 + /* used for non-audit messages that we shouldn't kill the task on */
62523 + GR_DONT_AUDIT_GOOD
62524 +};
62525 +
62526 +enum {
62527 + GR_TTYSNIFF,
62528 + GR_RBAC,
62529 + GR_RBAC_STR,
62530 + GR_STR_RBAC,
62531 + GR_RBAC_MODE2,
62532 + GR_RBAC_MODE3,
62533 + GR_FILENAME,
62534 + GR_SYSCTL_HIDDEN,
62535 + GR_NOARGS,
62536 + GR_ONE_INT,
62537 + GR_ONE_INT_TWO_STR,
62538 + GR_ONE_STR,
62539 + GR_STR_INT,
62540 + GR_TWO_STR_INT,
62541 + GR_TWO_INT,
62542 + GR_TWO_U64,
62543 + GR_THREE_INT,
62544 + GR_FIVE_INT_TWO_STR,
62545 + GR_TWO_STR,
62546 + GR_THREE_STR,
62547 + GR_FOUR_STR,
62548 + GR_STR_FILENAME,
62549 + GR_FILENAME_STR,
62550 + GR_FILENAME_TWO_INT,
62551 + GR_FILENAME_TWO_INT_STR,
62552 + GR_TEXTREL,
62553 + GR_PTRACE,
62554 + GR_RESOURCE,
62555 + GR_CAP,
62556 + GR_SIG,
62557 + GR_SIG2,
62558 + GR_CRASH1,
62559 + GR_CRASH2,
62560 + GR_PSACCT,
62561 + GR_RWXMAP
62562 +};
62563 +
62564 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
62565 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
62566 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
62567 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
62568 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
62569 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
62570 +#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)
62571 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
62572 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
62573 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
62574 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
62575 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
62576 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
62577 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
62578 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
62579 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
62580 +#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)
62581 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
62582 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
62583 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
62584 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
62585 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
62586 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
62587 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
62588 +#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)
62589 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
62590 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
62591 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
62592 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
62593 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
62594 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
62595 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
62596 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
62597 +#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)
62598 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
62599 +
62600 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
62601 +
62602 +#endif
62603 +
62604 +#endif
62605 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
62606 new file mode 100644
62607 index 0000000..54f4e85
62608 --- /dev/null
62609 +++ b/include/linux/grmsg.h
62610 @@ -0,0 +1,110 @@
62611 +#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"
62612 +#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"
62613 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
62614 +#define GR_STOPMOD_MSG "denied modification of module state by "
62615 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
62616 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
62617 +#define GR_IOPERM_MSG "denied use of ioperm() by "
62618 +#define GR_IOPL_MSG "denied use of iopl() by "
62619 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
62620 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
62621 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
62622 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
62623 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
62624 +#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"
62625 +#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"
62626 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
62627 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
62628 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
62629 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
62630 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
62631 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
62632 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
62633 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
62634 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
62635 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
62636 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
62637 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
62638 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
62639 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
62640 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
62641 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
62642 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
62643 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
62644 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
62645 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
62646 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
62647 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
62648 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
62649 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
62650 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
62651 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
62652 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
62653 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
62654 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
62655 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
62656 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
62657 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
62658 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
62659 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
62660 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
62661 +#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"
62662 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
62663 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
62664 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
62665 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
62666 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
62667 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
62668 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
62669 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
62670 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
62671 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
62672 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
62673 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
62674 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
62675 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
62676 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
62677 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
62678 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
62679 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
62680 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
62681 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
62682 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
62683 +#define GR_NICE_CHROOT_MSG "denied priority change by "
62684 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
62685 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
62686 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
62687 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
62688 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
62689 +#define GR_TIME_MSG "time set by "
62690 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
62691 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
62692 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
62693 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
62694 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
62695 +#define GR_BIND_MSG "denied bind() by "
62696 +#define GR_CONNECT_MSG "denied connect() by "
62697 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
62698 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
62699 +#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"
62700 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
62701 +#define GR_CAP_ACL_MSG "use of %s denied for "
62702 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
62703 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
62704 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
62705 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
62706 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
62707 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
62708 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
62709 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
62710 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
62711 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
62712 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
62713 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
62714 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
62715 +#define GR_VM86_MSG "denied use of vm86 by "
62716 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
62717 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
62718 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
62719 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
62720 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
62721 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
62722 new file mode 100644
62723 index 0000000..f9b9a21
62724 --- /dev/null
62725 +++ b/include/linux/grsecurity.h
62726 @@ -0,0 +1,238 @@
62727 +#ifndef GR_SECURITY_H
62728 +#define GR_SECURITY_H
62729 +#include <linux/fs.h>
62730 +#include <linux/fs_struct.h>
62731 +#include <linux/binfmts.h>
62732 +#include <linux/gracl.h>
62733 +
62734 +/* notify of brain-dead configs */
62735 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62736 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
62737 +#endif
62738 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
62739 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
62740 +#endif
62741 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
62742 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
62743 +#endif
62744 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
62745 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
62746 +#endif
62747 +
62748 +#include <linux/compat.h>
62749 +
62750 +struct user_arg_ptr {
62751 +#ifdef CONFIG_COMPAT
62752 + bool is_compat;
62753 +#endif
62754 + union {
62755 + const char __user *const __user *native;
62756 +#ifdef CONFIG_COMPAT
62757 + compat_uptr_t __user *compat;
62758 +#endif
62759 + } ptr;
62760 +};
62761 +
62762 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
62763 +void gr_handle_brute_check(void);
62764 +void gr_handle_kernel_exploit(void);
62765 +int gr_process_user_ban(void);
62766 +
62767 +char gr_roletype_to_char(void);
62768 +
62769 +int gr_acl_enable_at_secure(void);
62770 +
62771 +int gr_check_user_change(int real, int effective, int fs);
62772 +int gr_check_group_change(int real, int effective, int fs);
62773 +
62774 +void gr_del_task_from_ip_table(struct task_struct *p);
62775 +
62776 +int gr_pid_is_chrooted(struct task_struct *p);
62777 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
62778 +int gr_handle_chroot_nice(void);
62779 +int gr_handle_chroot_sysctl(const int op);
62780 +int gr_handle_chroot_setpriority(struct task_struct *p,
62781 + const int niceval);
62782 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
62783 +int gr_handle_chroot_chroot(const struct dentry *dentry,
62784 + const struct vfsmount *mnt);
62785 +void gr_handle_chroot_chdir(struct path *path);
62786 +int gr_handle_chroot_chmod(const struct dentry *dentry,
62787 + const struct vfsmount *mnt, const int mode);
62788 +int gr_handle_chroot_mknod(const struct dentry *dentry,
62789 + const struct vfsmount *mnt, const int mode);
62790 +int gr_handle_chroot_mount(const struct dentry *dentry,
62791 + const struct vfsmount *mnt,
62792 + const char *dev_name);
62793 +int gr_handle_chroot_pivot(void);
62794 +int gr_handle_chroot_unix(const pid_t pid);
62795 +
62796 +int gr_handle_rawio(const struct inode *inode);
62797 +
62798 +void gr_handle_ioperm(void);
62799 +void gr_handle_iopl(void);
62800 +
62801 +umode_t gr_acl_umask(void);
62802 +
62803 +int gr_tpe_allow(const struct file *file);
62804 +
62805 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
62806 +void gr_clear_chroot_entries(struct task_struct *task);
62807 +
62808 +void gr_log_forkfail(const int retval);
62809 +void gr_log_timechange(void);
62810 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
62811 +void gr_log_chdir(const struct dentry *dentry,
62812 + const struct vfsmount *mnt);
62813 +void gr_log_chroot_exec(const struct dentry *dentry,
62814 + const struct vfsmount *mnt);
62815 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
62816 +void gr_log_remount(const char *devname, const int retval);
62817 +void gr_log_unmount(const char *devname, const int retval);
62818 +void gr_log_mount(const char *from, const char *to, const int retval);
62819 +void gr_log_textrel(struct vm_area_struct *vma);
62820 +void gr_log_rwxmmap(struct file *file);
62821 +void gr_log_rwxmprotect(struct file *file);
62822 +
62823 +int gr_handle_follow_link(const struct inode *parent,
62824 + const struct inode *inode,
62825 + const struct dentry *dentry,
62826 + const struct vfsmount *mnt);
62827 +int gr_handle_fifo(const struct dentry *dentry,
62828 + const struct vfsmount *mnt,
62829 + const struct dentry *dir, const int flag,
62830 + const int acc_mode);
62831 +int gr_handle_hardlink(const struct dentry *dentry,
62832 + const struct vfsmount *mnt,
62833 + struct inode *inode,
62834 + const int mode, const char *to);
62835 +
62836 +int gr_is_capable(const int cap);
62837 +int gr_is_capable_nolog(const int cap);
62838 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
62839 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
62840 +
62841 +void gr_learn_resource(const struct task_struct *task, const int limit,
62842 + const unsigned long wanted, const int gt);
62843 +void gr_copy_label(struct task_struct *tsk);
62844 +void gr_handle_crash(struct task_struct *task, const int sig);
62845 +int gr_handle_signal(const struct task_struct *p, const int sig);
62846 +int gr_check_crash_uid(const uid_t uid);
62847 +int gr_check_protected_task(const struct task_struct *task);
62848 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
62849 +int gr_acl_handle_mmap(const struct file *file,
62850 + const unsigned long prot);
62851 +int gr_acl_handle_mprotect(const struct file *file,
62852 + const unsigned long prot);
62853 +int gr_check_hidden_task(const struct task_struct *tsk);
62854 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
62855 + const struct vfsmount *mnt);
62856 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
62857 + const struct vfsmount *mnt);
62858 +__u32 gr_acl_handle_access(const struct dentry *dentry,
62859 + const struct vfsmount *mnt, const int fmode);
62860 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
62861 + const struct vfsmount *mnt, umode_t *mode);
62862 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
62863 + const struct vfsmount *mnt);
62864 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
62865 + const struct vfsmount *mnt);
62866 +int gr_handle_ptrace(struct task_struct *task, const long request);
62867 +int gr_handle_proc_ptrace(struct task_struct *task);
62868 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
62869 + const struct vfsmount *mnt);
62870 +int gr_check_crash_exec(const struct file *filp);
62871 +int gr_acl_is_enabled(void);
62872 +void gr_set_kernel_label(struct task_struct *task);
62873 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
62874 + const gid_t gid);
62875 +int gr_set_proc_label(const struct dentry *dentry,
62876 + const struct vfsmount *mnt,
62877 + const int unsafe_flags);
62878 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
62879 + const struct vfsmount *mnt);
62880 +__u32 gr_acl_handle_open(const struct dentry *dentry,
62881 + const struct vfsmount *mnt, int acc_mode);
62882 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
62883 + const struct dentry *p_dentry,
62884 + const struct vfsmount *p_mnt,
62885 + int open_flags, int acc_mode, const int imode);
62886 +void gr_handle_create(const struct dentry *dentry,
62887 + const struct vfsmount *mnt);
62888 +void gr_handle_proc_create(const struct dentry *dentry,
62889 + const struct inode *inode);
62890 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
62891 + const struct dentry *parent_dentry,
62892 + const struct vfsmount *parent_mnt,
62893 + const int mode);
62894 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
62895 + const struct dentry *parent_dentry,
62896 + const struct vfsmount *parent_mnt);
62897 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
62898 + const struct vfsmount *mnt);
62899 +void gr_handle_delete(const ino_t ino, const dev_t dev);
62900 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
62901 + const struct vfsmount *mnt);
62902 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
62903 + const struct dentry *parent_dentry,
62904 + const struct vfsmount *parent_mnt,
62905 + const char *from);
62906 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
62907 + const struct dentry *parent_dentry,
62908 + const struct vfsmount *parent_mnt,
62909 + const struct dentry *old_dentry,
62910 + const struct vfsmount *old_mnt, const char *to);
62911 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
62912 +int gr_acl_handle_rename(struct dentry *new_dentry,
62913 + struct dentry *parent_dentry,
62914 + const struct vfsmount *parent_mnt,
62915 + struct dentry *old_dentry,
62916 + struct inode *old_parent_inode,
62917 + struct vfsmount *old_mnt, const char *newname);
62918 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
62919 + struct dentry *old_dentry,
62920 + struct dentry *new_dentry,
62921 + struct vfsmount *mnt, const __u8 replace);
62922 +__u32 gr_check_link(const struct dentry *new_dentry,
62923 + const struct dentry *parent_dentry,
62924 + const struct vfsmount *parent_mnt,
62925 + const struct dentry *old_dentry,
62926 + const struct vfsmount *old_mnt);
62927 +int gr_acl_handle_filldir(const struct file *file, const char *name,
62928 + const unsigned int namelen, const ino_t ino);
62929 +
62930 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
62931 + const struct vfsmount *mnt);
62932 +void gr_acl_handle_exit(void);
62933 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
62934 +int gr_acl_handle_procpidmem(const struct task_struct *task);
62935 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
62936 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
62937 +void gr_audit_ptrace(struct task_struct *task);
62938 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
62939 +
62940 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
62941 +
62942 +#ifdef CONFIG_GRKERNSEC
62943 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
62944 +void gr_handle_vm86(void);
62945 +void gr_handle_mem_readwrite(u64 from, u64 to);
62946 +
62947 +void gr_log_badprocpid(const char *entry);
62948 +
62949 +extern int grsec_enable_dmesg;
62950 +extern int grsec_disable_privio;
62951 +
62952 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62953 +extern int grsec_proc_gid;
62954 +#endif
62955 +
62956 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62957 +extern int grsec_enable_chroot_findtask;
62958 +#endif
62959 +#ifdef CONFIG_GRKERNSEC_SETXID
62960 +extern int grsec_enable_setxid;
62961 +#endif
62962 +#endif
62963 +
62964 +#endif
62965 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
62966 new file mode 100644
62967 index 0000000..e7ffaaf
62968 --- /dev/null
62969 +++ b/include/linux/grsock.h
62970 @@ -0,0 +1,19 @@
62971 +#ifndef __GRSOCK_H
62972 +#define __GRSOCK_H
62973 +
62974 +extern void gr_attach_curr_ip(const struct sock *sk);
62975 +extern int gr_handle_sock_all(const int family, const int type,
62976 + const int protocol);
62977 +extern int gr_handle_sock_server(const struct sockaddr *sck);
62978 +extern int gr_handle_sock_server_other(const struct sock *sck);
62979 +extern int gr_handle_sock_client(const struct sockaddr *sck);
62980 +extern int gr_search_connect(struct socket * sock,
62981 + struct sockaddr_in * addr);
62982 +extern int gr_search_bind(struct socket * sock,
62983 + struct sockaddr_in * addr);
62984 +extern int gr_search_listen(struct socket * sock);
62985 +extern int gr_search_accept(struct socket * sock);
62986 +extern int gr_search_socket(const int domain, const int type,
62987 + const int protocol);
62988 +
62989 +#endif
62990 diff --git a/include/linux/hid.h b/include/linux/hid.h
62991 index 42970de..5db3c92 100644
62992 --- a/include/linux/hid.h
62993 +++ b/include/linux/hid.h
62994 @@ -705,7 +705,7 @@ struct hid_ll_driver {
62995 unsigned int code, int value);
62996
62997 int (*parse)(struct hid_device *hdev);
62998 -};
62999 +} __no_const;
63000
63001 #define PM_HINT_FULLON 1<<5
63002 #define PM_HINT_NORMAL 1<<1
63003 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
63004 index ef788b5..ac41b7b 100644
63005 --- a/include/linux/highmem.h
63006 +++ b/include/linux/highmem.h
63007 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
63008 kunmap_atomic(kaddr);
63009 }
63010
63011 +static inline void sanitize_highpage(struct page *page)
63012 +{
63013 + void *kaddr;
63014 + unsigned long flags;
63015 +
63016 + local_irq_save(flags);
63017 + kaddr = kmap_atomic(page);
63018 + clear_page(kaddr);
63019 + kunmap_atomic(kaddr);
63020 + local_irq_restore(flags);
63021 +}
63022 +
63023 static inline void zero_user_segments(struct page *page,
63024 unsigned start1, unsigned end1,
63025 unsigned start2, unsigned end2)
63026 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
63027 index 5970266..1c48c3b 100644
63028 --- a/include/linux/i2c.h
63029 +++ b/include/linux/i2c.h
63030 @@ -369,6 +369,7 @@ struct i2c_algorithm {
63031 /* To determine what the adapter supports */
63032 u32 (*functionality) (struct i2c_adapter *);
63033 };
63034 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
63035
63036 /*
63037 * i2c_adapter is the structure used to identify a physical i2c bus along
63038 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
63039 index d23c3c2..eb63c81 100644
63040 --- a/include/linux/i2o.h
63041 +++ b/include/linux/i2o.h
63042 @@ -565,7 +565,7 @@ struct i2o_controller {
63043 struct i2o_device *exec; /* Executive */
63044 #if BITS_PER_LONG == 64
63045 spinlock_t context_list_lock; /* lock for context_list */
63046 - atomic_t context_list_counter; /* needed for unique contexts */
63047 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
63048 struct list_head context_list; /* list of context id's
63049 and pointers */
63050 #endif
63051 diff --git a/include/linux/if_team.h b/include/linux/if_team.h
63052 index aa2e167..84024ce 100644
63053 --- a/include/linux/if_team.h
63054 +++ b/include/linux/if_team.h
63055 @@ -109,6 +109,7 @@ struct team_mode_ops {
63056 void (*port_enabled)(struct team *team, struct team_port *port);
63057 void (*port_disabled)(struct team *team, struct team_port *port);
63058 };
63059 +typedef struct team_mode_ops __no_const team_mode_ops_no_const;
63060
63061 enum team_option_type {
63062 TEAM_OPTION_TYPE_U32,
63063 @@ -181,7 +182,7 @@ struct team {
63064 struct list_head option_inst_list; /* list of option instances */
63065
63066 const struct team_mode *mode;
63067 - struct team_mode_ops ops;
63068 + team_mode_ops_no_const ops;
63069 long mode_priv[TEAM_MODE_PRIV_LONGS];
63070 };
63071
63072 diff --git a/include/linux/init.h b/include/linux/init.h
63073 index 5e664f6..0a1225c 100644
63074 --- a/include/linux/init.h
63075 +++ b/include/linux/init.h
63076 @@ -39,9 +39,15 @@
63077 * Also note, that this data cannot be "const".
63078 */
63079
63080 +#ifdef MODULE
63081 +#define add_latent_entropy
63082 +#else
63083 +#define add_latent_entropy __latent_entropy
63084 +#endif
63085 +
63086 /* These are for everybody (although not all archs will actually
63087 discard it in modules) */
63088 -#define __init __section(.init.text) __cold notrace
63089 +#define __init __section(.init.text) __cold notrace add_latent_entropy
63090 #define __initdata __section(.init.data)
63091 #define __initconst __section(.init.rodata)
63092 #define __exitdata __section(.exit.data)
63093 @@ -83,7 +89,7 @@
63094 #define __exit __section(.exit.text) __exitused __cold notrace
63095
63096 /* Used for HOTPLUG */
63097 -#define __devinit __section(.devinit.text) __cold notrace
63098 +#define __devinit __section(.devinit.text) __cold notrace add_latent_entropy
63099 #define __devinitdata __section(.devinit.data)
63100 #define __devinitconst __section(.devinit.rodata)
63101 #define __devexit __section(.devexit.text) __exitused __cold notrace
63102 @@ -91,7 +97,7 @@
63103 #define __devexitconst __section(.devexit.rodata)
63104
63105 /* Used for HOTPLUG_CPU */
63106 -#define __cpuinit __section(.cpuinit.text) __cold notrace
63107 +#define __cpuinit __section(.cpuinit.text) __cold notrace add_latent_entropy
63108 #define __cpuinitdata __section(.cpuinit.data)
63109 #define __cpuinitconst __section(.cpuinit.rodata)
63110 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
63111 @@ -99,7 +105,7 @@
63112 #define __cpuexitconst __section(.cpuexit.rodata)
63113
63114 /* Used for MEMORY_HOTPLUG */
63115 -#define __meminit __section(.meminit.text) __cold notrace
63116 +#define __meminit __section(.meminit.text) __cold notrace add_latent_entropy
63117 #define __meminitdata __section(.meminit.data)
63118 #define __meminitconst __section(.meminit.rodata)
63119 #define __memexit __section(.memexit.text) __exitused __cold notrace
63120 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
63121 index 89f1cb1..7986c0f 100644
63122 --- a/include/linux/init_task.h
63123 +++ b/include/linux/init_task.h
63124 @@ -143,6 +143,12 @@ extern struct task_group root_task_group;
63125
63126 #define INIT_TASK_COMM "swapper"
63127
63128 +#ifdef CONFIG_X86
63129 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
63130 +#else
63131 +#define INIT_TASK_THREAD_INFO
63132 +#endif
63133 +
63134 /*
63135 * INIT_TASK is used to set up the first task table, touch at
63136 * your own risk!. Base=0, limit=0x1fffff (=2MB)
63137 @@ -182,6 +188,7 @@ extern struct task_group root_task_group;
63138 RCU_POINTER_INITIALIZER(cred, &init_cred), \
63139 .comm = INIT_TASK_COMM, \
63140 .thread = INIT_THREAD, \
63141 + INIT_TASK_THREAD_INFO \
63142 .fs = &init_fs, \
63143 .files = &init_files, \
63144 .signal = &init_signals, \
63145 diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
63146 index 78e2ada..745564d 100644
63147 --- a/include/linux/intel-iommu.h
63148 +++ b/include/linux/intel-iommu.h
63149 @@ -296,7 +296,7 @@ struct iommu_flush {
63150 u8 fm, u64 type);
63151 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
63152 unsigned int size_order, u64 type);
63153 -};
63154 +} __no_const;
63155
63156 enum {
63157 SR_DMAR_FECTL_REG,
63158 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
63159 index c5f856a..d29c117 100644
63160 --- a/include/linux/interrupt.h
63161 +++ b/include/linux/interrupt.h
63162 @@ -433,7 +433,7 @@ enum
63163 /* map softirq index to softirq name. update 'softirq_to_name' in
63164 * kernel/softirq.c when adding a new softirq.
63165 */
63166 -extern char *softirq_to_name[NR_SOFTIRQS];
63167 +extern const char * const softirq_to_name[NR_SOFTIRQS];
63168
63169 /* softirq mask and active fields moved to irq_cpustat_t in
63170 * asm/hardirq.h to get better cache usage. KAO
63171 @@ -441,12 +441,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
63172
63173 struct softirq_action
63174 {
63175 - void (*action)(struct softirq_action *);
63176 + void (*action)(void);
63177 };
63178
63179 asmlinkage void do_softirq(void);
63180 asmlinkage void __do_softirq(void);
63181 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
63182 +extern void open_softirq(int nr, void (*action)(void));
63183 extern void softirq_init(void);
63184 extern void __raise_softirq_irqoff(unsigned int nr);
63185
63186 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
63187 index 6883e19..06992b1 100644
63188 --- a/include/linux/kallsyms.h
63189 +++ b/include/linux/kallsyms.h
63190 @@ -15,7 +15,8 @@
63191
63192 struct module;
63193
63194 -#ifdef CONFIG_KALLSYMS
63195 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
63196 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63197 /* Lookup the address for a symbol. Returns 0 if not found. */
63198 unsigned long kallsyms_lookup_name(const char *name);
63199
63200 @@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
63201 /* Stupid that this does nothing, but I didn't create this mess. */
63202 #define __print_symbol(fmt, addr)
63203 #endif /*CONFIG_KALLSYMS*/
63204 +#else /* when included by kallsyms.c, vsnprintf.c, or
63205 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
63206 +extern void __print_symbol(const char *fmt, unsigned long address);
63207 +extern int sprint_backtrace(char *buffer, unsigned long address);
63208 +extern int sprint_symbol(char *buffer, unsigned long address);
63209 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
63210 +const char *kallsyms_lookup(unsigned long addr,
63211 + unsigned long *symbolsize,
63212 + unsigned long *offset,
63213 + char **modname, char *namebuf);
63214 +#endif
63215
63216 /* This macro allows us to keep printk typechecking */
63217 static __printf(1, 2)
63218 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
63219 index c4d2fc1..5df9c19 100644
63220 --- a/include/linux/kgdb.h
63221 +++ b/include/linux/kgdb.h
63222 @@ -53,7 +53,7 @@ extern int kgdb_connected;
63223 extern int kgdb_io_module_registered;
63224
63225 extern atomic_t kgdb_setting_breakpoint;
63226 -extern atomic_t kgdb_cpu_doing_single_step;
63227 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
63228
63229 extern struct task_struct *kgdb_usethread;
63230 extern struct task_struct *kgdb_contthread;
63231 @@ -252,7 +252,7 @@ struct kgdb_arch {
63232 void (*disable_hw_break)(struct pt_regs *regs);
63233 void (*remove_all_hw_break)(void);
63234 void (*correct_hw_break)(void);
63235 -};
63236 +} __do_const;
63237
63238 /**
63239 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
63240 @@ -277,7 +277,7 @@ struct kgdb_io {
63241 void (*pre_exception) (void);
63242 void (*post_exception) (void);
63243 int is_console;
63244 -};
63245 +} __do_const;
63246
63247 extern struct kgdb_arch arch_kgdb_ops;
63248
63249 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
63250 index 5398d58..5883a34 100644
63251 --- a/include/linux/kmod.h
63252 +++ b/include/linux/kmod.h
63253 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
63254 * usually useless though. */
63255 extern __printf(2, 3)
63256 int __request_module(bool wait, const char *name, ...);
63257 +extern __printf(3, 4)
63258 +int ___request_module(bool wait, char *param_name, const char *name, ...);
63259 #define request_module(mod...) __request_module(true, mod)
63260 #define request_module_nowait(mod...) __request_module(false, mod)
63261 #define try_then_request_module(x, mod...) \
63262 diff --git a/include/linux/kref.h b/include/linux/kref.h
63263 index 65af688..0592677 100644
63264 --- a/include/linux/kref.h
63265 +++ b/include/linux/kref.h
63266 @@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
63267 static inline int kref_sub(struct kref *kref, unsigned int count,
63268 void (*release)(struct kref *kref))
63269 {
63270 - WARN_ON(release == NULL);
63271 + BUG_ON(release == NULL);
63272
63273 if (atomic_sub_and_test((int) count, &kref->refcount)) {
63274 release(kref);
63275 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
63276 index b70b48b..0d7153b 100644
63277 --- a/include/linux/kvm_host.h
63278 +++ b/include/linux/kvm_host.h
63279 @@ -351,7 +351,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
63280 void vcpu_load(struct kvm_vcpu *vcpu);
63281 void vcpu_put(struct kvm_vcpu *vcpu);
63282
63283 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63284 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63285 struct module *module);
63286 void kvm_exit(void);
63287
63288 @@ -517,7 +517,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
63289 struct kvm_guest_debug *dbg);
63290 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
63291
63292 -int kvm_arch_init(void *opaque);
63293 +int kvm_arch_init(const void *opaque);
63294 void kvm_arch_exit(void);
63295
63296 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
63297 diff --git a/include/linux/libata.h b/include/linux/libata.h
63298 index 64f90e1..32b945b 100644
63299 --- a/include/linux/libata.h
63300 +++ b/include/linux/libata.h
63301 @@ -909,7 +909,7 @@ struct ata_port_operations {
63302 * fields must be pointers.
63303 */
63304 const struct ata_port_operations *inherits;
63305 -};
63306 +} __do_const;
63307
63308 struct ata_port_info {
63309 unsigned long flags;
63310 diff --git a/include/linux/memory.h b/include/linux/memory.h
63311 index ff9a9f8..c715deb 100644
63312 --- a/include/linux/memory.h
63313 +++ b/include/linux/memory.h
63314 @@ -143,7 +143,7 @@ struct memory_accessor {
63315 size_t count);
63316 ssize_t (*write)(struct memory_accessor *, const char *buf,
63317 off_t offset, size_t count);
63318 -};
63319 +} __no_const;
63320
63321 /*
63322 * Kernel text modification mutex, used for code patching. Users of this lock
63323 diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
63324 index 1318ca6..7521340 100644
63325 --- a/include/linux/mfd/abx500.h
63326 +++ b/include/linux/mfd/abx500.h
63327 @@ -452,6 +452,7 @@ struct abx500_ops {
63328 int (*event_registers_startup_state_get) (struct device *, u8 *);
63329 int (*startup_irq_enabled) (struct device *, unsigned int);
63330 };
63331 +typedef struct abx500_ops __no_const abx500_ops_no_const;
63332
63333 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
63334 void abx500_remove_ops(struct device *dev);
63335 diff --git a/include/linux/mfd/abx500/ux500_chargalg.h b/include/linux/mfd/abx500/ux500_chargalg.h
63336 index 9b07725..3d55001 100644
63337 --- a/include/linux/mfd/abx500/ux500_chargalg.h
63338 +++ b/include/linux/mfd/abx500/ux500_chargalg.h
63339 @@ -19,7 +19,7 @@ struct ux500_charger_ops {
63340 int (*enable) (struct ux500_charger *, int, int, int);
63341 int (*kick_wd) (struct ux500_charger *);
63342 int (*update_curr) (struct ux500_charger *, int);
63343 -};
63344 +} __no_const;
63345
63346 /**
63347 * struct ux500_charger - power supply ux500 charger sub class
63348 diff --git a/include/linux/mm.h b/include/linux/mm.h
63349 index 311be90..5f1638c 100644
63350 --- a/include/linux/mm.h
63351 +++ b/include/linux/mm.h
63352 @@ -116,7 +116,14 @@ extern unsigned int kobjsize(const void *objp);
63353
63354 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
63355 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
63356 +
63357 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
63358 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
63359 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
63360 +#else
63361 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
63362 +#endif
63363 +
63364 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
63365 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
63366
63367 @@ -1038,34 +1045,6 @@ int set_page_dirty(struct page *page);
63368 int set_page_dirty_lock(struct page *page);
63369 int clear_page_dirty_for_io(struct page *page);
63370
63371 -/* Is the vma a continuation of the stack vma above it? */
63372 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
63373 -{
63374 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
63375 -}
63376 -
63377 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
63378 - unsigned long addr)
63379 -{
63380 - return (vma->vm_flags & VM_GROWSDOWN) &&
63381 - (vma->vm_start == addr) &&
63382 - !vma_growsdown(vma->vm_prev, addr);
63383 -}
63384 -
63385 -/* Is the vma a continuation of the stack vma below it? */
63386 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
63387 -{
63388 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
63389 -}
63390 -
63391 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
63392 - unsigned long addr)
63393 -{
63394 - return (vma->vm_flags & VM_GROWSUP) &&
63395 - (vma->vm_end == addr) &&
63396 - !vma_growsup(vma->vm_next, addr);
63397 -}
63398 -
63399 extern pid_t
63400 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
63401
63402 @@ -1164,6 +1143,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
63403 }
63404 #endif
63405
63406 +#ifdef CONFIG_MMU
63407 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
63408 +#else
63409 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
63410 +{
63411 + return __pgprot(0);
63412 +}
63413 +#endif
63414 +
63415 int vma_wants_writenotify(struct vm_area_struct *vma);
63416
63417 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
63418 @@ -1182,8 +1170,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
63419 {
63420 return 0;
63421 }
63422 +
63423 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
63424 + unsigned long address)
63425 +{
63426 + return 0;
63427 +}
63428 #else
63429 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63430 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63431 #endif
63432
63433 #ifdef __PAGETABLE_PMD_FOLDED
63434 @@ -1192,8 +1187,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
63435 {
63436 return 0;
63437 }
63438 +
63439 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
63440 + unsigned long address)
63441 +{
63442 + return 0;
63443 +}
63444 #else
63445 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
63446 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
63447 #endif
63448
63449 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
63450 @@ -1211,11 +1213,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
63451 NULL: pud_offset(pgd, address);
63452 }
63453
63454 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
63455 +{
63456 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
63457 + NULL: pud_offset(pgd, address);
63458 +}
63459 +
63460 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
63461 {
63462 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
63463 NULL: pmd_offset(pud, address);
63464 }
63465 +
63466 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
63467 +{
63468 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
63469 + NULL: pmd_offset(pud, address);
63470 +}
63471 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
63472
63473 #if USE_SPLIT_PTLOCKS
63474 @@ -1426,6 +1440,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
63475 unsigned long, unsigned long,
63476 unsigned long, unsigned long);
63477 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
63478 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
63479
63480 /* These take the mm semaphore themselves */
63481 extern unsigned long vm_brk(unsigned long, unsigned long);
63482 @@ -1489,6 +1504,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
63483 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
63484 struct vm_area_struct **pprev);
63485
63486 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
63487 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
63488 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
63489 +
63490 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
63491 NULL if none. Assume start_addr < end_addr. */
63492 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
63493 @@ -1517,15 +1536,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
63494 return vma;
63495 }
63496
63497 -#ifdef CONFIG_MMU
63498 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
63499 -#else
63500 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
63501 -{
63502 - return __pgprot(0);
63503 -}
63504 -#endif
63505 -
63506 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
63507 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
63508 unsigned long pfn, unsigned long size, pgprot_t);
63509 @@ -1631,7 +1641,7 @@ extern int unpoison_memory(unsigned long pfn);
63510 extern int sysctl_memory_failure_early_kill;
63511 extern int sysctl_memory_failure_recovery;
63512 extern void shake_page(struct page *p, int access);
63513 -extern atomic_long_t mce_bad_pages;
63514 +extern atomic_long_unchecked_t mce_bad_pages;
63515 extern int soft_offline_page(struct page *page, int flags);
63516
63517 extern void dump_page(struct page *page);
63518 @@ -1662,5 +1672,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
63519 static inline bool page_is_guard(struct page *page) { return false; }
63520 #endif /* CONFIG_DEBUG_PAGEALLOC */
63521
63522 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63523 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
63524 +#else
63525 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
63526 +#endif
63527 +
63528 #endif /* __KERNEL__ */
63529 #endif /* _LINUX_MM_H */
63530 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
63531 index bf78672..debc693 100644
63532 --- a/include/linux/mm_types.h
63533 +++ b/include/linux/mm_types.h
63534 @@ -279,6 +279,8 @@ struct vm_area_struct {
63535 #ifdef CONFIG_NUMA
63536 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
63537 #endif
63538 +
63539 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
63540 };
63541
63542 struct core_thread {
63543 @@ -353,7 +355,7 @@ struct mm_struct {
63544 unsigned long def_flags;
63545 unsigned long nr_ptes; /* Page table pages */
63546 unsigned long start_code, end_code, start_data, end_data;
63547 - unsigned long start_brk, brk, start_stack;
63548 + unsigned long brk_gap, start_brk, brk, start_stack;
63549 unsigned long arg_start, arg_end, env_start, env_end;
63550
63551 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
63552 @@ -405,6 +407,24 @@ struct mm_struct {
63553 struct cpumask cpumask_allocation;
63554 #endif
63555 struct uprobes_state uprobes_state;
63556 +
63557 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63558 + unsigned long pax_flags;
63559 +#endif
63560 +
63561 +#ifdef CONFIG_PAX_DLRESOLVE
63562 + unsigned long call_dl_resolve;
63563 +#endif
63564 +
63565 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
63566 + unsigned long call_syscall;
63567 +#endif
63568 +
63569 +#ifdef CONFIG_PAX_ASLR
63570 + unsigned long delta_mmap; /* randomized offset */
63571 + unsigned long delta_stack; /* randomized offset */
63572 +#endif
63573 +
63574 };
63575
63576 static inline void mm_init_cpumask(struct mm_struct *mm)
63577 diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
63578 index 1d1b1e1..2a13c78 100644
63579 --- a/include/linux/mmu_notifier.h
63580 +++ b/include/linux/mmu_notifier.h
63581 @@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
63582 */
63583 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
63584 ({ \
63585 - pte_t __pte; \
63586 + pte_t ___pte; \
63587 struct vm_area_struct *___vma = __vma; \
63588 unsigned long ___address = __address; \
63589 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
63590 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
63591 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
63592 - __pte; \
63593 + ___pte; \
63594 })
63595
63596 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
63597 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
63598 index 2daa54f..bfdf2f5 100644
63599 --- a/include/linux/mmzone.h
63600 +++ b/include/linux/mmzone.h
63601 @@ -414,7 +414,7 @@ struct zone {
63602 unsigned long flags; /* zone flags, see below */
63603
63604 /* Zone statistics */
63605 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63606 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63607
63608 /*
63609 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
63610 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
63611 index 6955045..ebdb7cd 100644
63612 --- a/include/linux/mod_devicetable.h
63613 +++ b/include/linux/mod_devicetable.h
63614 @@ -12,7 +12,7 @@
63615 typedef unsigned long kernel_ulong_t;
63616 #endif
63617
63618 -#define PCI_ANY_ID (~0)
63619 +#define PCI_ANY_ID ((__u16)~0)
63620
63621 struct pci_device_id {
63622 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
63623 @@ -139,7 +139,7 @@ struct usb_device_id {
63624 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
63625 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
63626
63627 -#define HID_ANY_ID (~0)
63628 +#define HID_ANY_ID (~0U)
63629 #define HID_BUS_ANY 0xffff
63630 #define HID_GROUP_ANY 0x0000
63631
63632 diff --git a/include/linux/module.h b/include/linux/module.h
63633 index fbcafe2..e5d9587 100644
63634 --- a/include/linux/module.h
63635 +++ b/include/linux/module.h
63636 @@ -17,6 +17,7 @@
63637 #include <linux/moduleparam.h>
63638 #include <linux/tracepoint.h>
63639 #include <linux/export.h>
63640 +#include <linux/fs.h>
63641
63642 #include <linux/percpu.h>
63643 #include <asm/module.h>
63644 @@ -273,19 +274,16 @@ struct module
63645 int (*init)(void);
63646
63647 /* If this is non-NULL, vfree after init() returns */
63648 - void *module_init;
63649 + void *module_init_rx, *module_init_rw;
63650
63651 /* Here is the actual code + data, vfree'd on unload. */
63652 - void *module_core;
63653 + void *module_core_rx, *module_core_rw;
63654
63655 /* Here are the sizes of the init and core sections */
63656 - unsigned int init_size, core_size;
63657 + unsigned int init_size_rw, core_size_rw;
63658
63659 /* The size of the executable code in each section. */
63660 - unsigned int init_text_size, core_text_size;
63661 -
63662 - /* Size of RO sections of the module (text+rodata) */
63663 - unsigned int init_ro_size, core_ro_size;
63664 + unsigned int init_size_rx, core_size_rx;
63665
63666 /* Arch-specific module values */
63667 struct mod_arch_specific arch;
63668 @@ -341,6 +339,10 @@ struct module
63669 #ifdef CONFIG_EVENT_TRACING
63670 struct ftrace_event_call **trace_events;
63671 unsigned int num_trace_events;
63672 + struct file_operations trace_id;
63673 + struct file_operations trace_enable;
63674 + struct file_operations trace_format;
63675 + struct file_operations trace_filter;
63676 #endif
63677 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
63678 unsigned int num_ftrace_callsites;
63679 @@ -388,16 +390,46 @@ bool is_module_address(unsigned long addr);
63680 bool is_module_percpu_address(unsigned long addr);
63681 bool is_module_text_address(unsigned long addr);
63682
63683 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
63684 +{
63685 +
63686 +#ifdef CONFIG_PAX_KERNEXEC
63687 + if (ktla_ktva(addr) >= (unsigned long)start &&
63688 + ktla_ktva(addr) < (unsigned long)start + size)
63689 + return 1;
63690 +#endif
63691 +
63692 + return ((void *)addr >= start && (void *)addr < start + size);
63693 +}
63694 +
63695 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
63696 +{
63697 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
63698 +}
63699 +
63700 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
63701 +{
63702 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
63703 +}
63704 +
63705 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
63706 +{
63707 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
63708 +}
63709 +
63710 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
63711 +{
63712 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
63713 +}
63714 +
63715 static inline int within_module_core(unsigned long addr, struct module *mod)
63716 {
63717 - return (unsigned long)mod->module_core <= addr &&
63718 - addr < (unsigned long)mod->module_core + mod->core_size;
63719 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
63720 }
63721
63722 static inline int within_module_init(unsigned long addr, struct module *mod)
63723 {
63724 - return (unsigned long)mod->module_init <= addr &&
63725 - addr < (unsigned long)mod->module_init + mod->init_size;
63726 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
63727 }
63728
63729 /* Search for module by name: must hold module_mutex. */
63730 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
63731 index b2be02e..72d2f78 100644
63732 --- a/include/linux/moduleloader.h
63733 +++ b/include/linux/moduleloader.h
63734 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
63735
63736 /* Allocator used for allocating struct module, core sections and init
63737 sections. Returns NULL on failure. */
63738 -void *module_alloc(unsigned long size);
63739 +void *module_alloc(unsigned long size) __size_overflow(1);
63740 +
63741 +#ifdef CONFIG_PAX_KERNEXEC
63742 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
63743 +#else
63744 +#define module_alloc_exec(x) module_alloc(x)
63745 +#endif
63746
63747 /* Free memory returned from module_alloc. */
63748 void module_free(struct module *mod, void *module_region);
63749
63750 +#ifdef CONFIG_PAX_KERNEXEC
63751 +void module_free_exec(struct module *mod, void *module_region);
63752 +#else
63753 +#define module_free_exec(x, y) module_free((x), (y))
63754 +#endif
63755 +
63756 /* Apply the given relocation to the (simplified) ELF. Return -error
63757 or 0. */
63758 int apply_relocate(Elf_Shdr *sechdrs,
63759 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
63760 index d6a5806..7c13347 100644
63761 --- a/include/linux/moduleparam.h
63762 +++ b/include/linux/moduleparam.h
63763 @@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
63764 * @len is usually just sizeof(string).
63765 */
63766 #define module_param_string(name, string, len, perm) \
63767 - static const struct kparam_string __param_string_##name \
63768 + static const struct kparam_string __param_string_##name __used \
63769 = { len, string }; \
63770 __module_param_call(MODULE_PARAM_PREFIX, name, \
63771 &param_ops_string, \
63772 @@ -425,7 +425,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
63773 */
63774 #define module_param_array_named(name, array, type, nump, perm) \
63775 param_check_##type(name, &(array)[0]); \
63776 - static const struct kparam_array __param_arr_##name \
63777 + static const struct kparam_array __param_arr_##name __used \
63778 = { .max = ARRAY_SIZE(array), .num = nump, \
63779 .ops = &param_ops_##type, \
63780 .elemsize = sizeof(array[0]), .elem = array }; \
63781 diff --git a/include/linux/namei.h b/include/linux/namei.h
63782 index 4bf19d8..5268cea 100644
63783 --- a/include/linux/namei.h
63784 +++ b/include/linux/namei.h
63785 @@ -18,7 +18,7 @@ struct nameidata {
63786 unsigned seq;
63787 int last_type;
63788 unsigned depth;
63789 - char *saved_names[MAX_NESTED_LINKS + 1];
63790 + const char *saved_names[MAX_NESTED_LINKS + 1];
63791 };
63792
63793 /*
63794 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
63795
63796 extern void nd_jump_link(struct nameidata *nd, struct path *path);
63797
63798 -static inline void nd_set_link(struct nameidata *nd, char *path)
63799 +static inline void nd_set_link(struct nameidata *nd, const char *path)
63800 {
63801 nd->saved_names[nd->depth] = path;
63802 }
63803
63804 -static inline char *nd_get_link(struct nameidata *nd)
63805 +static inline const char *nd_get_link(const struct nameidata *nd)
63806 {
63807 return nd->saved_names[nd->depth];
63808 }
63809 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
63810 index 59dc05f3..c905a34 100644
63811 --- a/include/linux/netdevice.h
63812 +++ b/include/linux/netdevice.h
63813 @@ -1027,6 +1027,7 @@ struct net_device_ops {
63814 struct net_device *dev,
63815 int idx);
63816 };
63817 +typedef struct net_device_ops __no_const net_device_ops_no_const;
63818
63819 /*
63820 * The DEVICE structure.
63821 @@ -1087,7 +1088,7 @@ struct net_device {
63822 int iflink;
63823
63824 struct net_device_stats stats;
63825 - atomic_long_t rx_dropped; /* dropped packets by core network
63826 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
63827 * Do not use this in drivers.
63828 */
63829
63830 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
63831 new file mode 100644
63832 index 0000000..33f4af8
63833 --- /dev/null
63834 +++ b/include/linux/netfilter/xt_gradm.h
63835 @@ -0,0 +1,9 @@
63836 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
63837 +#define _LINUX_NETFILTER_XT_GRADM_H 1
63838 +
63839 +struct xt_gradm_mtinfo {
63840 + __u16 flags;
63841 + __u16 invflags;
63842 +};
63843 +
63844 +#endif
63845 diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
63846 index c65a18a..0c05f3a 100644
63847 --- a/include/linux/of_pdt.h
63848 +++ b/include/linux/of_pdt.h
63849 @@ -32,7 +32,7 @@ struct of_pdt_ops {
63850
63851 /* return 0 on success; fill in 'len' with number of bytes in path */
63852 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
63853 -};
63854 +} __no_const;
63855
63856 extern void *prom_early_alloc(unsigned long size);
63857
63858 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
63859 index a4c5624..79d6d88 100644
63860 --- a/include/linux/oprofile.h
63861 +++ b/include/linux/oprofile.h
63862 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
63863 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
63864 char const * name, ulong * val);
63865
63866 -/** Create a file for read-only access to an atomic_t. */
63867 +/** Create a file for read-only access to an atomic_unchecked_t. */
63868 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
63869 - char const * name, atomic_t * val);
63870 + char const * name, atomic_unchecked_t * val);
63871
63872 /** create a directory */
63873 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
63874 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
63875 index bdb4161..f373d41 100644
63876 --- a/include/linux/perf_event.h
63877 +++ b/include/linux/perf_event.h
63878 @@ -882,8 +882,8 @@ struct perf_event {
63879
63880 enum perf_event_active_state state;
63881 unsigned int attach_state;
63882 - local64_t count;
63883 - atomic64_t child_count;
63884 + local64_t count; /* PaX: fix it one day */
63885 + atomic64_unchecked_t child_count;
63886
63887 /*
63888 * These are the total time in nanoseconds that the event
63889 @@ -934,8 +934,8 @@ struct perf_event {
63890 * These accumulate total time (in nanoseconds) that children
63891 * events have been enabled and running, respectively.
63892 */
63893 - atomic64_t child_total_time_enabled;
63894 - atomic64_t child_total_time_running;
63895 + atomic64_unchecked_t child_total_time_enabled;
63896 + atomic64_unchecked_t child_total_time_running;
63897
63898 /*
63899 * Protect attach/detach and child_list:
63900 diff --git a/include/linux/personality.h b/include/linux/personality.h
63901 index 8fc7dd1a..c19d89e 100644
63902 --- a/include/linux/personality.h
63903 +++ b/include/linux/personality.h
63904 @@ -44,6 +44,7 @@ enum {
63905 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
63906 ADDR_NO_RANDOMIZE | \
63907 ADDR_COMPAT_LAYOUT | \
63908 + ADDR_LIMIT_3GB | \
63909 MMAP_PAGE_ZERO)
63910
63911 /*
63912 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
63913 index ad1a427..6419649 100644
63914 --- a/include/linux/pipe_fs_i.h
63915 +++ b/include/linux/pipe_fs_i.h
63916 @@ -45,9 +45,9 @@ struct pipe_buffer {
63917 struct pipe_inode_info {
63918 wait_queue_head_t wait;
63919 unsigned int nrbufs, curbuf, buffers;
63920 - unsigned int readers;
63921 - unsigned int writers;
63922 - unsigned int waiting_writers;
63923 + atomic_t readers;
63924 + atomic_t writers;
63925 + atomic_t waiting_writers;
63926 unsigned int r_counter;
63927 unsigned int w_counter;
63928 struct page *tmp_page;
63929 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
63930 index f271860..6b3bec5 100644
63931 --- a/include/linux/pm_runtime.h
63932 +++ b/include/linux/pm_runtime.h
63933 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
63934
63935 static inline void pm_runtime_mark_last_busy(struct device *dev)
63936 {
63937 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
63938 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
63939 }
63940
63941 #else /* !CONFIG_PM_RUNTIME */
63942 diff --git a/include/linux/poison.h b/include/linux/poison.h
63943 index 2110a81..13a11bb 100644
63944 --- a/include/linux/poison.h
63945 +++ b/include/linux/poison.h
63946 @@ -19,8 +19,8 @@
63947 * under normal circumstances, used to verify that nobody uses
63948 * non-initialized list entries.
63949 */
63950 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
63951 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
63952 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
63953 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
63954
63955 /********** include/linux/timer.h **********/
63956 /*
63957 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
63958 index 5a710b9..0b0dab9 100644
63959 --- a/include/linux/preempt.h
63960 +++ b/include/linux/preempt.h
63961 @@ -126,7 +126,7 @@ struct preempt_ops {
63962 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
63963 void (*sched_out)(struct preempt_notifier *notifier,
63964 struct task_struct *next);
63965 -};
63966 +} __no_const;
63967
63968 /**
63969 * preempt_notifier - key for installing preemption notifiers
63970 diff --git a/include/linux/printk.h b/include/linux/printk.h
63971 index 9afc01e..92c32e8 100644
63972 --- a/include/linux/printk.h
63973 +++ b/include/linux/printk.h
63974 @@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
63975 extern int printk_needs_cpu(int cpu);
63976 extern void printk_tick(void);
63977
63978 +extern int kptr_restrict;
63979 +
63980 #ifdef CONFIG_PRINTK
63981 asmlinkage __printf(5, 0)
63982 int vprintk_emit(int facility, int level,
63983 @@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
63984
63985 extern int printk_delay_msec;
63986 extern int dmesg_restrict;
63987 -extern int kptr_restrict;
63988
63989 void log_buf_kexec_setup(void);
63990 void __init setup_log_buf(int early);
63991 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
63992 index 3fd2e87..d93a721 100644
63993 --- a/include/linux/proc_fs.h
63994 +++ b/include/linux/proc_fs.h
63995 @@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
63996 return proc_create_data(name, mode, parent, proc_fops, NULL);
63997 }
63998
63999 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
64000 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
64001 +{
64002 +#ifdef CONFIG_GRKERNSEC_PROC_USER
64003 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
64004 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64005 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
64006 +#else
64007 + return proc_create_data(name, mode, parent, proc_fops, NULL);
64008 +#endif
64009 +}
64010 +
64011 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
64012 umode_t mode, struct proc_dir_entry *base,
64013 read_proc_t *read_proc, void * data)
64014 @@ -258,7 +270,7 @@ union proc_op {
64015 int (*proc_show)(struct seq_file *m,
64016 struct pid_namespace *ns, struct pid *pid,
64017 struct task_struct *task);
64018 -};
64019 +} __no_const;
64020
64021 struct ctl_table_header;
64022 struct ctl_table;
64023 diff --git a/include/linux/random.h b/include/linux/random.h
64024 index ac621ce..c1215f3 100644
64025 --- a/include/linux/random.h
64026 +++ b/include/linux/random.h
64027 @@ -53,6 +53,10 @@ extern void add_input_randomness(unsigned int type, unsigned int code,
64028 unsigned int value);
64029 extern void add_interrupt_randomness(int irq, int irq_flags);
64030
64031 +#ifdef CONFIG_PAX_LATENT_ENTROPY
64032 +extern void transfer_latent_entropy(void);
64033 +#endif
64034 +
64035 extern void get_random_bytes(void *buf, int nbytes);
64036 extern void get_random_bytes_arch(void *buf, int nbytes);
64037 void generate_random_uuid(unsigned char uuid_out[16]);
64038 @@ -69,12 +73,17 @@ void srandom32(u32 seed);
64039
64040 u32 prandom32(struct rnd_state *);
64041
64042 +static inline unsigned long pax_get_random_long(void)
64043 +{
64044 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
64045 +}
64046 +
64047 /*
64048 * Handle minimum values for seeds
64049 */
64050 static inline u32 __seed(u32 x, u32 m)
64051 {
64052 - return (x < m) ? x + m : x;
64053 + return (x <= m) ? x + m + 1 : x;
64054 }
64055
64056 /**
64057 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
64058 index e0879a7..a12f962 100644
64059 --- a/include/linux/reboot.h
64060 +++ b/include/linux/reboot.h
64061 @@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
64062 * Architecture-specific implementations of sys_reboot commands.
64063 */
64064
64065 -extern void machine_restart(char *cmd);
64066 -extern void machine_halt(void);
64067 -extern void machine_power_off(void);
64068 +extern void machine_restart(char *cmd) __noreturn;
64069 +extern void machine_halt(void) __noreturn;
64070 +extern void machine_power_off(void) __noreturn;
64071
64072 extern void machine_shutdown(void);
64073 struct pt_regs;
64074 @@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
64075 */
64076
64077 extern void kernel_restart_prepare(char *cmd);
64078 -extern void kernel_restart(char *cmd);
64079 -extern void kernel_halt(void);
64080 -extern void kernel_power_off(void);
64081 +extern void kernel_restart(char *cmd) __noreturn;
64082 +extern void kernel_halt(void) __noreturn;
64083 +extern void kernel_power_off(void) __noreturn;
64084
64085 extern int C_A_D; /* for sysctl */
64086 void ctrl_alt_del(void);
64087 @@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
64088 * Emergency restart, callable from an interrupt handler.
64089 */
64090
64091 -extern void emergency_restart(void);
64092 +extern void emergency_restart(void) __noreturn;
64093 #include <asm/emergency-restart.h>
64094
64095 #endif
64096 diff --git a/include/linux/relay.h b/include/linux/relay.h
64097 index 91cacc3..b55ff74 100644
64098 --- a/include/linux/relay.h
64099 +++ b/include/linux/relay.h
64100 @@ -160,7 +160,7 @@ struct rchan_callbacks
64101 * The callback should return 0 if successful, negative if not.
64102 */
64103 int (*remove_buf_file)(struct dentry *dentry);
64104 -};
64105 +} __no_const;
64106
64107 /*
64108 * CONFIG_RELAY kernel API, kernel/relay.c
64109 diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
64110 index 6fdf027..ff72610 100644
64111 --- a/include/linux/rfkill.h
64112 +++ b/include/linux/rfkill.h
64113 @@ -147,6 +147,7 @@ struct rfkill_ops {
64114 void (*query)(struct rfkill *rfkill, void *data);
64115 int (*set_block)(void *data, bool blocked);
64116 };
64117 +typedef struct rfkill_ops __no_const rfkill_ops_no_const;
64118
64119 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
64120 /**
64121 diff --git a/include/linux/rio.h b/include/linux/rio.h
64122 index a90ebad..fd87b5d 100644
64123 --- a/include/linux/rio.h
64124 +++ b/include/linux/rio.h
64125 @@ -321,7 +321,7 @@ struct rio_ops {
64126 int mbox, void *buffer, size_t len);
64127 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
64128 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
64129 -};
64130 +} __no_const;
64131
64132 #define RIO_RESOURCE_MEM 0x00000100
64133 #define RIO_RESOURCE_DOORBELL 0x00000200
64134 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
64135 index 3fce545..b4fed6e 100644
64136 --- a/include/linux/rmap.h
64137 +++ b/include/linux/rmap.h
64138 @@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
64139 void anon_vma_init(void); /* create anon_vma_cachep */
64140 int anon_vma_prepare(struct vm_area_struct *);
64141 void unlink_anon_vmas(struct vm_area_struct *);
64142 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
64143 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
64144 void anon_vma_moveto_tail(struct vm_area_struct *);
64145 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
64146 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
64147
64148 static inline void anon_vma_merge(struct vm_area_struct *vma,
64149 struct vm_area_struct *next)
64150 diff --git a/include/linux/sched.h b/include/linux/sched.h
64151 index 23bddac..5976055 100644
64152 --- a/include/linux/sched.h
64153 +++ b/include/linux/sched.h
64154 @@ -101,6 +101,7 @@ struct bio_list;
64155 struct fs_struct;
64156 struct perf_event_context;
64157 struct blk_plug;
64158 +struct linux_binprm;
64159
64160 /*
64161 * List of flags we want to share for kernel threads,
64162 @@ -384,10 +385,13 @@ struct user_namespace;
64163 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
64164
64165 extern int sysctl_max_map_count;
64166 +extern unsigned long sysctl_heap_stack_gap;
64167
64168 #include <linux/aio.h>
64169
64170 #ifdef CONFIG_MMU
64171 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
64172 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
64173 extern void arch_pick_mmap_layout(struct mm_struct *mm);
64174 extern unsigned long
64175 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
64176 @@ -651,6 +655,17 @@ struct signal_struct {
64177 #ifdef CONFIG_TASKSTATS
64178 struct taskstats *stats;
64179 #endif
64180 +
64181 +#ifdef CONFIG_GRKERNSEC
64182 + u32 curr_ip;
64183 + u32 saved_ip;
64184 + u32 gr_saddr;
64185 + u32 gr_daddr;
64186 + u16 gr_sport;
64187 + u16 gr_dport;
64188 + u8 used_accept:1;
64189 +#endif
64190 +
64191 #ifdef CONFIG_AUDIT
64192 unsigned audit_tty;
64193 struct tty_audit_buf *tty_audit_buf;
64194 @@ -734,6 +749,11 @@ struct user_struct {
64195 struct key *session_keyring; /* UID's default session keyring */
64196 #endif
64197
64198 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
64199 + unsigned int banned;
64200 + unsigned long ban_expires;
64201 +#endif
64202 +
64203 /* Hash table maintenance information */
64204 struct hlist_node uidhash_node;
64205 kuid_t uid;
64206 @@ -1356,8 +1376,8 @@ struct task_struct {
64207 struct list_head thread_group;
64208
64209 struct completion *vfork_done; /* for vfork() */
64210 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
64211 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64212 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
64213 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64214
64215 cputime_t utime, stime, utimescaled, stimescaled;
64216 cputime_t gtime;
64217 @@ -1373,11 +1393,6 @@ struct task_struct {
64218 struct task_cputime cputime_expires;
64219 struct list_head cpu_timers[3];
64220
64221 -/* process credentials */
64222 - const struct cred __rcu *real_cred; /* objective and real subjective task
64223 - * credentials (COW) */
64224 - const struct cred __rcu *cred; /* effective (overridable) subjective task
64225 - * credentials (COW) */
64226 char comm[TASK_COMM_LEN]; /* executable name excluding path
64227 - access with [gs]et_task_comm (which lock
64228 it with task_lock())
64229 @@ -1394,6 +1409,10 @@ struct task_struct {
64230 #endif
64231 /* CPU-specific state of this task */
64232 struct thread_struct thread;
64233 +/* thread_info moved to task_struct */
64234 +#ifdef CONFIG_X86
64235 + struct thread_info tinfo;
64236 +#endif
64237 /* filesystem information */
64238 struct fs_struct *fs;
64239 /* open file information */
64240 @@ -1467,6 +1486,10 @@ struct task_struct {
64241 gfp_t lockdep_reclaim_gfp;
64242 #endif
64243
64244 +/* process credentials */
64245 + const struct cred __rcu *real_cred; /* objective and real subjective task
64246 + * credentials (COW) */
64247 +
64248 /* journalling filesystem info */
64249 void *journal_info;
64250
64251 @@ -1505,6 +1528,10 @@ struct task_struct {
64252 /* cg_list protected by css_set_lock and tsk->alloc_lock */
64253 struct list_head cg_list;
64254 #endif
64255 +
64256 + const struct cred __rcu *cred; /* effective (overridable) subjective task
64257 + * credentials (COW) */
64258 +
64259 #ifdef CONFIG_FUTEX
64260 struct robust_list_head __user *robust_list;
64261 #ifdef CONFIG_COMPAT
64262 @@ -1589,8 +1616,74 @@ struct task_struct {
64263 #ifdef CONFIG_UPROBES
64264 struct uprobe_task *utask;
64265 #endif
64266 +
64267 +#ifdef CONFIG_GRKERNSEC
64268 + /* grsecurity */
64269 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64270 + u64 exec_id;
64271 +#endif
64272 +#ifdef CONFIG_GRKERNSEC_SETXID
64273 + const struct cred *delayed_cred;
64274 +#endif
64275 + struct dentry *gr_chroot_dentry;
64276 + struct acl_subject_label *acl;
64277 + struct acl_role_label *role;
64278 + struct file *exec_file;
64279 + u16 acl_role_id;
64280 + /* is this the task that authenticated to the special role */
64281 + u8 acl_sp_role;
64282 + u8 is_writable;
64283 + u8 brute;
64284 + u8 gr_is_chrooted;
64285 +#endif
64286 +
64287 };
64288
64289 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
64290 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
64291 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
64292 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
64293 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
64294 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
64295 +
64296 +#ifdef CONFIG_PAX_SOFTMODE
64297 +extern int pax_softmode;
64298 +#endif
64299 +
64300 +extern int pax_check_flags(unsigned long *);
64301 +
64302 +/* if tsk != current then task_lock must be held on it */
64303 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
64304 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
64305 +{
64306 + if (likely(tsk->mm))
64307 + return tsk->mm->pax_flags;
64308 + else
64309 + return 0UL;
64310 +}
64311 +
64312 +/* if tsk != current then task_lock must be held on it */
64313 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
64314 +{
64315 + if (likely(tsk->mm)) {
64316 + tsk->mm->pax_flags = flags;
64317 + return 0;
64318 + }
64319 + return -EINVAL;
64320 +}
64321 +#endif
64322 +
64323 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
64324 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
64325 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
64326 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
64327 +#endif
64328 +
64329 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
64330 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
64331 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
64332 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
64333 +
64334 /* Future-safe accessor for struct task_struct's cpus_allowed. */
64335 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
64336
64337 @@ -2125,7 +2218,9 @@ void yield(void);
64338 extern struct exec_domain default_exec_domain;
64339
64340 union thread_union {
64341 +#ifndef CONFIG_X86
64342 struct thread_info thread_info;
64343 +#endif
64344 unsigned long stack[THREAD_SIZE/sizeof(long)];
64345 };
64346
64347 @@ -2158,6 +2253,7 @@ extern struct pid_namespace init_pid_ns;
64348 */
64349
64350 extern struct task_struct *find_task_by_vpid(pid_t nr);
64351 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
64352 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
64353 struct pid_namespace *ns);
64354
64355 @@ -2314,7 +2410,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
64356 extern void exit_itimers(struct signal_struct *);
64357 extern void flush_itimer_signals(void);
64358
64359 -extern void do_group_exit(int);
64360 +extern __noreturn void do_group_exit(int);
64361
64362 extern void daemonize(const char *, ...);
64363 extern int allow_signal(int);
64364 @@ -2515,9 +2611,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
64365
64366 #endif
64367
64368 -static inline int object_is_on_stack(void *obj)
64369 +static inline int object_starts_on_stack(void *obj)
64370 {
64371 - void *stack = task_stack_page(current);
64372 + const void *stack = task_stack_page(current);
64373
64374 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
64375 }
64376 diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
64377 index 899fbb4..1cb4138 100644
64378 --- a/include/linux/screen_info.h
64379 +++ b/include/linux/screen_info.h
64380 @@ -43,7 +43,8 @@ struct screen_info {
64381 __u16 pages; /* 0x32 */
64382 __u16 vesa_attributes; /* 0x34 */
64383 __u32 capabilities; /* 0x36 */
64384 - __u8 _reserved[6]; /* 0x3a */
64385 + __u16 vesapm_size; /* 0x3a */
64386 + __u8 _reserved[4]; /* 0x3c */
64387 } __attribute__((packed));
64388
64389 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
64390 diff --git a/include/linux/security.h b/include/linux/security.h
64391 index d143b8e..9f27b95 100644
64392 --- a/include/linux/security.h
64393 +++ b/include/linux/security.h
64394 @@ -26,6 +26,7 @@
64395 #include <linux/capability.h>
64396 #include <linux/slab.h>
64397 #include <linux/err.h>
64398 +#include <linux/grsecurity.h>
64399
64400 struct linux_binprm;
64401 struct cred;
64402 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
64403 index 83c44ee..e8a9eba 100644
64404 --- a/include/linux/seq_file.h
64405 +++ b/include/linux/seq_file.h
64406 @@ -25,6 +25,9 @@ struct seq_file {
64407 struct mutex lock;
64408 const struct seq_operations *op;
64409 int poll_event;
64410 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64411 + u64 exec_id;
64412 +#endif
64413 void *private;
64414 };
64415
64416 @@ -34,6 +37,7 @@ struct seq_operations {
64417 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
64418 int (*show) (struct seq_file *m, void *v);
64419 };
64420 +typedef struct seq_operations __no_const seq_operations_no_const;
64421
64422 #define SEQ_SKIP 1
64423
64424 diff --git a/include/linux/shm.h b/include/linux/shm.h
64425 index edd0868..f98feee 100644
64426 --- a/include/linux/shm.h
64427 +++ b/include/linux/shm.h
64428 @@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
64429
64430 /* The task created the shm object. NULL if the task is dead. */
64431 struct task_struct *shm_creator;
64432 +#ifdef CONFIG_GRKERNSEC
64433 + time_t shm_createtime;
64434 + pid_t shm_lapid;
64435 +#endif
64436 };
64437
64438 /* shm_mode upper byte flags */
64439 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
64440 index f3165d2..2cb3cb7 100644
64441 --- a/include/linux/skbuff.h
64442 +++ b/include/linux/skbuff.h
64443 @@ -577,7 +577,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
64444 extern struct sk_buff *__alloc_skb(unsigned int size,
64445 gfp_t priority, int flags, int node);
64446 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
64447 -static inline struct sk_buff *alloc_skb(unsigned int size,
64448 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
64449 gfp_t priority)
64450 {
64451 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
64452 @@ -687,7 +687,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
64453 */
64454 static inline int skb_queue_empty(const struct sk_buff_head *list)
64455 {
64456 - return list->next == (struct sk_buff *)list;
64457 + return list->next == (const struct sk_buff *)list;
64458 }
64459
64460 /**
64461 @@ -700,7 +700,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
64462 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64463 const struct sk_buff *skb)
64464 {
64465 - return skb->next == (struct sk_buff *)list;
64466 + return skb->next == (const struct sk_buff *)list;
64467 }
64468
64469 /**
64470 @@ -713,7 +713,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64471 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
64472 const struct sk_buff *skb)
64473 {
64474 - return skb->prev == (struct sk_buff *)list;
64475 + return skb->prev == (const struct sk_buff *)list;
64476 }
64477
64478 /**
64479 @@ -1623,7 +1623,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
64480 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
64481 */
64482 #ifndef NET_SKB_PAD
64483 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
64484 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
64485 #endif
64486
64487 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
64488 @@ -2201,7 +2201,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
64489 int noblock, int *err);
64490 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
64491 struct poll_table_struct *wait);
64492 -extern int skb_copy_datagram_iovec(const struct sk_buff *from,
64493 +extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
64494 int offset, struct iovec *to,
64495 int size);
64496 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
64497 diff --git a/include/linux/slab.h b/include/linux/slab.h
64498 index 0dd2dfa..2b8677c 100644
64499 --- a/include/linux/slab.h
64500 +++ b/include/linux/slab.h
64501 @@ -11,12 +11,20 @@
64502
64503 #include <linux/gfp.h>
64504 #include <linux/types.h>
64505 +#include <linux/err.h>
64506
64507 /*
64508 * Flags to pass to kmem_cache_create().
64509 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
64510 */
64511 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
64512 +
64513 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64514 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
64515 +#else
64516 +#define SLAB_USERCOPY 0x00000000UL
64517 +#endif
64518 +
64519 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
64520 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
64521 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
64522 @@ -87,10 +95,13 @@
64523 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
64524 * Both make kfree a no-op.
64525 */
64526 -#define ZERO_SIZE_PTR ((void *)16)
64527 +#define ZERO_SIZE_PTR \
64528 +({ \
64529 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
64530 + (void *)(-MAX_ERRNO-1L); \
64531 +})
64532
64533 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
64534 - (unsigned long)ZERO_SIZE_PTR)
64535 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
64536
64537 /*
64538 * Common fields provided in kmem_cache by all slab allocators
64539 @@ -185,6 +196,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
64540 void kfree(const void *);
64541 void kzfree(const void *);
64542 size_t ksize(const void *);
64543 +const char *check_heap_object(const void *ptr, unsigned long n, bool to);
64544 +bool is_usercopy_object(const void *ptr);
64545
64546 /*
64547 * Allocator specific definitions. These are mainly used to establish optimized
64548 @@ -322,7 +335,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
64549 */
64550 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64551 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
64552 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64553 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
64554 #define kmalloc_track_caller(size, flags) \
64555 __kmalloc_track_caller(size, flags, _RET_IP_)
64556 #else
64557 @@ -341,7 +354,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64558 */
64559 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64560 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
64561 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
64562 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
64563 #define kmalloc_node_track_caller(size, flags, node) \
64564 __kmalloc_node_track_caller(size, flags, node, \
64565 _RET_IP_)
64566 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
64567 index 0c634fa..8616300 100644
64568 --- a/include/linux/slab_def.h
64569 +++ b/include/linux/slab_def.h
64570 @@ -69,10 +69,10 @@ struct kmem_cache {
64571 unsigned long node_allocs;
64572 unsigned long node_frees;
64573 unsigned long node_overflow;
64574 - atomic_t allochit;
64575 - atomic_t allocmiss;
64576 - atomic_t freehit;
64577 - atomic_t freemiss;
64578 + atomic_unchecked_t allochit;
64579 + atomic_unchecked_t allocmiss;
64580 + atomic_unchecked_t freehit;
64581 + atomic_unchecked_t freemiss;
64582
64583 /*
64584 * If debugging is enabled, then the allocator can add additional
64585 @@ -105,11 +105,16 @@ struct cache_sizes {
64586 #ifdef CONFIG_ZONE_DMA
64587 struct kmem_cache *cs_dmacachep;
64588 #endif
64589 +
64590 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64591 + struct kmem_cache *cs_usercopycachep;
64592 +#endif
64593 +
64594 };
64595 extern struct cache_sizes malloc_sizes[];
64596
64597 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64598 -void *__kmalloc(size_t size, gfp_t flags);
64599 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
64600
64601 #ifdef CONFIG_TRACING
64602 extern void *kmem_cache_alloc_trace(size_t size,
64603 @@ -152,6 +157,13 @@ found:
64604 cachep = malloc_sizes[i].cs_dmacachep;
64605 else
64606 #endif
64607 +
64608 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64609 + if (flags & GFP_USERCOPY)
64610 + cachep = malloc_sizes[i].cs_usercopycachep;
64611 + else
64612 +#endif
64613 +
64614 cachep = malloc_sizes[i].cs_cachep;
64615
64616 ret = kmem_cache_alloc_trace(size, cachep, flags);
64617 @@ -162,7 +174,7 @@ found:
64618 }
64619
64620 #ifdef CONFIG_NUMA
64621 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
64622 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64623 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64624
64625 #ifdef CONFIG_TRACING
64626 @@ -205,6 +217,13 @@ found:
64627 cachep = malloc_sizes[i].cs_dmacachep;
64628 else
64629 #endif
64630 +
64631 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64632 + if (flags & GFP_USERCOPY)
64633 + cachep = malloc_sizes[i].cs_usercopycachep;
64634 + else
64635 +#endif
64636 +
64637 cachep = malloc_sizes[i].cs_cachep;
64638
64639 return kmem_cache_alloc_node_trace(size, cachep, flags, node);
64640 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
64641 index 0ec00b3..22b4715 100644
64642 --- a/include/linux/slob_def.h
64643 +++ b/include/linux/slob_def.h
64644 @@ -9,7 +9,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
64645 return kmem_cache_alloc_node(cachep, flags, -1);
64646 }
64647
64648 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
64649 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64650
64651 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
64652 {
64653 @@ -29,7 +29,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64654 return __kmalloc_node(size, flags, -1);
64655 }
64656
64657 -static __always_inline void *__kmalloc(size_t size, gfp_t flags)
64658 +static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
64659 {
64660 return kmalloc(size, flags);
64661 }
64662 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
64663 index df448ad..b99e7f6 100644
64664 --- a/include/linux/slub_def.h
64665 +++ b/include/linux/slub_def.h
64666 @@ -91,7 +91,7 @@ struct kmem_cache {
64667 struct kmem_cache_order_objects max;
64668 struct kmem_cache_order_objects min;
64669 gfp_t allocflags; /* gfp flags to use on each alloc */
64670 - int refcount; /* Refcount for slab cache destroy */
64671 + atomic_t refcount; /* Refcount for slab cache destroy */
64672 void (*ctor)(void *);
64673 int inuse; /* Offset to metadata */
64674 int align; /* Alignment */
64675 @@ -152,7 +152,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
64676 * Sorry that the following has to be that ugly but some versions of GCC
64677 * have trouble with constant propagation and loops.
64678 */
64679 -static __always_inline int kmalloc_index(size_t size)
64680 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
64681 {
64682 if (!size)
64683 return 0;
64684 @@ -217,7 +217,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
64685 }
64686
64687 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64688 -void *__kmalloc(size_t size, gfp_t flags);
64689 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
64690
64691 static __always_inline void *
64692 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
64693 @@ -258,7 +258,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
64694 }
64695 #endif
64696
64697 -static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
64698 +static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
64699 {
64700 unsigned int order = get_order(size);
64701 return kmalloc_order_trace(size, flags, order);
64702 @@ -283,7 +283,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64703 }
64704
64705 #ifdef CONFIG_NUMA
64706 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
64707 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64708 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64709
64710 #ifdef CONFIG_TRACING
64711 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
64712 index de8832d..0147b46 100644
64713 --- a/include/linux/sonet.h
64714 +++ b/include/linux/sonet.h
64715 @@ -61,7 +61,7 @@ struct sonet_stats {
64716 #include <linux/atomic.h>
64717
64718 struct k_sonet_stats {
64719 -#define __HANDLE_ITEM(i) atomic_t i
64720 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
64721 __SONET_ITEMS
64722 #undef __HANDLE_ITEM
64723 };
64724 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
64725 index 523547e..2cb7140 100644
64726 --- a/include/linux/sunrpc/clnt.h
64727 +++ b/include/linux/sunrpc/clnt.h
64728 @@ -174,9 +174,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
64729 {
64730 switch (sap->sa_family) {
64731 case AF_INET:
64732 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
64733 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
64734 case AF_INET6:
64735 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
64736 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
64737 }
64738 return 0;
64739 }
64740 @@ -209,7 +209,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
64741 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
64742 const struct sockaddr *src)
64743 {
64744 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
64745 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
64746 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
64747
64748 dsin->sin_family = ssin->sin_family;
64749 @@ -312,7 +312,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
64750 if (sa->sa_family != AF_INET6)
64751 return 0;
64752
64753 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
64754 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
64755 }
64756
64757 #endif /* __KERNEL__ */
64758 diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
64759 index dc0c3cc..8503fb6 100644
64760 --- a/include/linux/sunrpc/sched.h
64761 +++ b/include/linux/sunrpc/sched.h
64762 @@ -106,6 +106,7 @@ struct rpc_call_ops {
64763 void (*rpc_count_stats)(struct rpc_task *, void *);
64764 void (*rpc_release)(void *);
64765 };
64766 +typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
64767
64768 struct rpc_task_setup {
64769 struct rpc_task *task;
64770 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
64771 index 0b8e3e6..33e0a01 100644
64772 --- a/include/linux/sunrpc/svc_rdma.h
64773 +++ b/include/linux/sunrpc/svc_rdma.h
64774 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
64775 extern unsigned int svcrdma_max_requests;
64776 extern unsigned int svcrdma_max_req_size;
64777
64778 -extern atomic_t rdma_stat_recv;
64779 -extern atomic_t rdma_stat_read;
64780 -extern atomic_t rdma_stat_write;
64781 -extern atomic_t rdma_stat_sq_starve;
64782 -extern atomic_t rdma_stat_rq_starve;
64783 -extern atomic_t rdma_stat_rq_poll;
64784 -extern atomic_t rdma_stat_rq_prod;
64785 -extern atomic_t rdma_stat_sq_poll;
64786 -extern atomic_t rdma_stat_sq_prod;
64787 +extern atomic_unchecked_t rdma_stat_recv;
64788 +extern atomic_unchecked_t rdma_stat_read;
64789 +extern atomic_unchecked_t rdma_stat_write;
64790 +extern atomic_unchecked_t rdma_stat_sq_starve;
64791 +extern atomic_unchecked_t rdma_stat_rq_starve;
64792 +extern atomic_unchecked_t rdma_stat_rq_poll;
64793 +extern atomic_unchecked_t rdma_stat_rq_prod;
64794 +extern atomic_unchecked_t rdma_stat_sq_poll;
64795 +extern atomic_unchecked_t rdma_stat_sq_prod;
64796
64797 #define RPCRDMA_VERSION 1
64798
64799 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
64800 index c34b4c8..a65b67d 100644
64801 --- a/include/linux/sysctl.h
64802 +++ b/include/linux/sysctl.h
64803 @@ -155,7 +155,11 @@ enum
64804 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
64805 };
64806
64807 -
64808 +#ifdef CONFIG_PAX_SOFTMODE
64809 +enum {
64810 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
64811 +};
64812 +#endif
64813
64814 /* CTL_VM names: */
64815 enum
64816 @@ -948,6 +952,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
64817
64818 extern int proc_dostring(struct ctl_table *, int,
64819 void __user *, size_t *, loff_t *);
64820 +extern int proc_dostring_modpriv(struct ctl_table *, int,
64821 + void __user *, size_t *, loff_t *);
64822 extern int proc_dointvec(struct ctl_table *, int,
64823 void __user *, size_t *, loff_t *);
64824 extern int proc_dointvec_minmax(struct ctl_table *, int,
64825 diff --git a/include/linux/tty.h b/include/linux/tty.h
64826 index 9f47ab5..73da944 100644
64827 --- a/include/linux/tty.h
64828 +++ b/include/linux/tty.h
64829 @@ -225,7 +225,7 @@ struct tty_port {
64830 const struct tty_port_operations *ops; /* Port operations */
64831 spinlock_t lock; /* Lock protecting tty field */
64832 int blocked_open; /* Waiting to open */
64833 - int count; /* Usage count */
64834 + atomic_t count; /* Usage count */
64835 wait_queue_head_t open_wait; /* Open waiters */
64836 wait_queue_head_t close_wait; /* Close waiters */
64837 wait_queue_head_t delta_msr_wait; /* Modem status change */
64838 @@ -525,7 +525,7 @@ extern int tty_port_open(struct tty_port *port,
64839 struct tty_struct *tty, struct file *filp);
64840 static inline int tty_port_users(struct tty_port *port)
64841 {
64842 - return port->count + port->blocked_open;
64843 + return atomic_read(&port->count) + port->blocked_open;
64844 }
64845
64846 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
64847 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
64848 index fb79dd8d..07d4773 100644
64849 --- a/include/linux/tty_ldisc.h
64850 +++ b/include/linux/tty_ldisc.h
64851 @@ -149,7 +149,7 @@ struct tty_ldisc_ops {
64852
64853 struct module *owner;
64854
64855 - int refcount;
64856 + atomic_t refcount;
64857 };
64858
64859 struct tty_ldisc {
64860 diff --git a/include/linux/types.h b/include/linux/types.h
64861 index bf0dd75..a1f23aaa 100644
64862 --- a/include/linux/types.h
64863 +++ b/include/linux/types.h
64864 @@ -220,10 +220,26 @@ typedef struct {
64865 int counter;
64866 } atomic_t;
64867
64868 +#ifdef CONFIG_PAX_REFCOUNT
64869 +typedef struct {
64870 + int counter;
64871 +} atomic_unchecked_t;
64872 +#else
64873 +typedef atomic_t atomic_unchecked_t;
64874 +#endif
64875 +
64876 #ifdef CONFIG_64BIT
64877 typedef struct {
64878 long counter;
64879 } atomic64_t;
64880 +
64881 +#ifdef CONFIG_PAX_REFCOUNT
64882 +typedef struct {
64883 + long counter;
64884 +} atomic64_unchecked_t;
64885 +#else
64886 +typedef atomic64_t atomic64_unchecked_t;
64887 +#endif
64888 #endif
64889
64890 struct list_head {
64891 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
64892 index 5ca0951..ab496a5 100644
64893 --- a/include/linux/uaccess.h
64894 +++ b/include/linux/uaccess.h
64895 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
64896 long ret; \
64897 mm_segment_t old_fs = get_fs(); \
64898 \
64899 - set_fs(KERNEL_DS); \
64900 pagefault_disable(); \
64901 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
64902 - pagefault_enable(); \
64903 + set_fs(KERNEL_DS); \
64904 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
64905 set_fs(old_fs); \
64906 + pagefault_enable(); \
64907 ret; \
64908 })
64909
64910 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
64911 index 99c1b4d..bb94261 100644
64912 --- a/include/linux/unaligned/access_ok.h
64913 +++ b/include/linux/unaligned/access_ok.h
64914 @@ -6,32 +6,32 @@
64915
64916 static inline u16 get_unaligned_le16(const void *p)
64917 {
64918 - return le16_to_cpup((__le16 *)p);
64919 + return le16_to_cpup((const __le16 *)p);
64920 }
64921
64922 static inline u32 get_unaligned_le32(const void *p)
64923 {
64924 - return le32_to_cpup((__le32 *)p);
64925 + return le32_to_cpup((const __le32 *)p);
64926 }
64927
64928 static inline u64 get_unaligned_le64(const void *p)
64929 {
64930 - return le64_to_cpup((__le64 *)p);
64931 + return le64_to_cpup((const __le64 *)p);
64932 }
64933
64934 static inline u16 get_unaligned_be16(const void *p)
64935 {
64936 - return be16_to_cpup((__be16 *)p);
64937 + return be16_to_cpup((const __be16 *)p);
64938 }
64939
64940 static inline u32 get_unaligned_be32(const void *p)
64941 {
64942 - return be32_to_cpup((__be32 *)p);
64943 + return be32_to_cpup((const __be32 *)p);
64944 }
64945
64946 static inline u64 get_unaligned_be64(const void *p)
64947 {
64948 - return be64_to_cpup((__be64 *)p);
64949 + return be64_to_cpup((const __be64 *)p);
64950 }
64951
64952 static inline void put_unaligned_le16(u16 val, void *p)
64953 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
64954 index c5d36c6..8478c90 100644
64955 --- a/include/linux/usb/renesas_usbhs.h
64956 +++ b/include/linux/usb/renesas_usbhs.h
64957 @@ -39,7 +39,7 @@ enum {
64958 */
64959 struct renesas_usbhs_driver_callback {
64960 int (*notify_hotplug)(struct platform_device *pdev);
64961 -};
64962 +} __no_const;
64963
64964 /*
64965 * callback functions for platform
64966 @@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
64967 * VBUS control is needed for Host
64968 */
64969 int (*set_vbus)(struct platform_device *pdev, int enable);
64970 -};
64971 +} __no_const;
64972
64973 /*
64974 * parameters for renesas usbhs
64975 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
64976 index 6f8fbcf..8259001 100644
64977 --- a/include/linux/vermagic.h
64978 +++ b/include/linux/vermagic.h
64979 @@ -25,9 +25,35 @@
64980 #define MODULE_ARCH_VERMAGIC ""
64981 #endif
64982
64983 +#ifdef CONFIG_PAX_REFCOUNT
64984 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
64985 +#else
64986 +#define MODULE_PAX_REFCOUNT ""
64987 +#endif
64988 +
64989 +#ifdef CONSTIFY_PLUGIN
64990 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
64991 +#else
64992 +#define MODULE_CONSTIFY_PLUGIN ""
64993 +#endif
64994 +
64995 +#ifdef STACKLEAK_PLUGIN
64996 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
64997 +#else
64998 +#define MODULE_STACKLEAK_PLUGIN ""
64999 +#endif
65000 +
65001 +#ifdef CONFIG_GRKERNSEC
65002 +#define MODULE_GRSEC "GRSEC "
65003 +#else
65004 +#define MODULE_GRSEC ""
65005 +#endif
65006 +
65007 #define VERMAGIC_STRING \
65008 UTS_RELEASE " " \
65009 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
65010 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
65011 - MODULE_ARCH_VERMAGIC
65012 + MODULE_ARCH_VERMAGIC \
65013 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
65014 + MODULE_GRSEC
65015
65016 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
65017 index 6071e91..ca6a489 100644
65018 --- a/include/linux/vmalloc.h
65019 +++ b/include/linux/vmalloc.h
65020 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
65021 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
65022 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
65023 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
65024 +
65025 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
65026 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
65027 +#endif
65028 +
65029 /* bits [20..32] reserved for arch specific ioremap internals */
65030
65031 /*
65032 @@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
65033 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
65034 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
65035 unsigned long start, unsigned long end, gfp_t gfp_mask,
65036 - pgprot_t prot, int node, const void *caller);
65037 + pgprot_t prot, int node, const void *caller) __size_overflow(1);
65038 extern void vfree(const void *addr);
65039
65040 extern void *vmap(struct page **pages, unsigned int count,
65041 @@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
65042 extern void free_vm_area(struct vm_struct *area);
65043
65044 /* for /dev/kmem */
65045 -extern long vread(char *buf, char *addr, unsigned long count);
65046 -extern long vwrite(char *buf, char *addr, unsigned long count);
65047 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
65048 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
65049
65050 /*
65051 * Internals. Dont't use..
65052 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
65053 index ad2cfd5..74c94ad 100644
65054 --- a/include/linux/vmstat.h
65055 +++ b/include/linux/vmstat.h
65056 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
65057 /*
65058 * Zone based page accounting with per cpu differentials.
65059 */
65060 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65061 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65062
65063 static inline void zone_page_state_add(long x, struct zone *zone,
65064 enum zone_stat_item item)
65065 {
65066 - atomic_long_add(x, &zone->vm_stat[item]);
65067 - atomic_long_add(x, &vm_stat[item]);
65068 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
65069 + atomic_long_add_unchecked(x, &vm_stat[item]);
65070 }
65071
65072 static inline unsigned long global_page_state(enum zone_stat_item item)
65073 {
65074 - long x = atomic_long_read(&vm_stat[item]);
65075 + long x = atomic_long_read_unchecked(&vm_stat[item]);
65076 #ifdef CONFIG_SMP
65077 if (x < 0)
65078 x = 0;
65079 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
65080 static inline unsigned long zone_page_state(struct zone *zone,
65081 enum zone_stat_item item)
65082 {
65083 - long x = atomic_long_read(&zone->vm_stat[item]);
65084 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
65085 #ifdef CONFIG_SMP
65086 if (x < 0)
65087 x = 0;
65088 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
65089 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
65090 enum zone_stat_item item)
65091 {
65092 - long x = atomic_long_read(&zone->vm_stat[item]);
65093 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
65094
65095 #ifdef CONFIG_SMP
65096 int cpu;
65097 @@ -216,8 +216,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
65098
65099 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
65100 {
65101 - atomic_long_inc(&zone->vm_stat[item]);
65102 - atomic_long_inc(&vm_stat[item]);
65103 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
65104 + atomic_long_inc_unchecked(&vm_stat[item]);
65105 }
65106
65107 static inline void __inc_zone_page_state(struct page *page,
65108 @@ -228,8 +228,8 @@ static inline void __inc_zone_page_state(struct page *page,
65109
65110 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
65111 {
65112 - atomic_long_dec(&zone->vm_stat[item]);
65113 - atomic_long_dec(&vm_stat[item]);
65114 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
65115 + atomic_long_dec_unchecked(&vm_stat[item]);
65116 }
65117
65118 static inline void __dec_zone_page_state(struct page *page,
65119 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
65120 index e5d1220..ef6e406 100644
65121 --- a/include/linux/xattr.h
65122 +++ b/include/linux/xattr.h
65123 @@ -57,6 +57,11 @@
65124 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
65125 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
65126
65127 +/* User namespace */
65128 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
65129 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
65130 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
65131 +
65132 #ifdef __KERNEL__
65133
65134 #include <linux/types.h>
65135 diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
65136 index 944ecdf..a3994fc 100644
65137 --- a/include/media/saa7146_vv.h
65138 +++ b/include/media/saa7146_vv.h
65139 @@ -161,8 +161,8 @@ struct saa7146_ext_vv
65140 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
65141
65142 /* the extension can override this */
65143 - struct v4l2_ioctl_ops vid_ops;
65144 - struct v4l2_ioctl_ops vbi_ops;
65145 + v4l2_ioctl_ops_no_const vid_ops;
65146 + v4l2_ioctl_ops_no_const vbi_ops;
65147 /* pointer to the saa7146 core ops */
65148 const struct v4l2_ioctl_ops *core_ops;
65149
65150 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
65151 index 5c416cd..20021aa 100644
65152 --- a/include/media/v4l2-dev.h
65153 +++ b/include/media/v4l2-dev.h
65154 @@ -73,7 +73,8 @@ struct v4l2_file_operations {
65155 int (*mmap) (struct file *, struct vm_area_struct *);
65156 int (*open) (struct file *);
65157 int (*release) (struct file *);
65158 -};
65159 +} __do_const;
65160 +typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
65161
65162 /*
65163 * Newer version of video_device, handled by videodev2.c
65164 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
65165 index e614c9c..20602b7 100644
65166 --- a/include/media/v4l2-ioctl.h
65167 +++ b/include/media/v4l2-ioctl.h
65168 @@ -289,7 +289,7 @@ struct v4l2_ioctl_ops {
65169 long (*vidioc_default) (struct file *file, void *fh,
65170 bool valid_prio, int cmd, void *arg);
65171 };
65172 -
65173 +typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
65174
65175 /* v4l debugging and diagnostics */
65176
65177 diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
65178 index bcb9cc3..f4ec722e 100644
65179 --- a/include/net/caif/caif_hsi.h
65180 +++ b/include/net/caif/caif_hsi.h
65181 @@ -98,7 +98,7 @@ struct cfhsi_cb_ops {
65182 void (*rx_done_cb) (struct cfhsi_cb_ops *drv);
65183 void (*wake_up_cb) (struct cfhsi_cb_ops *drv);
65184 void (*wake_down_cb) (struct cfhsi_cb_ops *drv);
65185 -};
65186 +} __no_const;
65187
65188 /* Structure implemented by HSI device. */
65189 struct cfhsi_ops {
65190 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
65191 index 9e5425b..8136ffc 100644
65192 --- a/include/net/caif/cfctrl.h
65193 +++ b/include/net/caif/cfctrl.h
65194 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
65195 void (*radioset_rsp)(void);
65196 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
65197 struct cflayer *client_layer);
65198 -};
65199 +} __no_const;
65200
65201 /* Link Setup Parameters for CAIF-Links. */
65202 struct cfctrl_link_param {
65203 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
65204 struct cfctrl {
65205 struct cfsrvl serv;
65206 struct cfctrl_rsp res;
65207 - atomic_t req_seq_no;
65208 - atomic_t rsp_seq_no;
65209 + atomic_unchecked_t req_seq_no;
65210 + atomic_unchecked_t rsp_seq_no;
65211 struct list_head list;
65212 /* Protects from simultaneous access to first_req list */
65213 spinlock_t info_list_lock;
65214 diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
65215 index f10553c..fb5204b 100644
65216 --- a/include/net/cfg80211.h
65217 +++ b/include/net/cfg80211.h
65218 @@ -2633,6 +2633,15 @@ unsigned int ieee80211_get_hdrlen_from_skb(const struct sk_buff *skb);
65219 unsigned int __attribute_const__ ieee80211_hdrlen(__le16 fc);
65220
65221 /**
65222 + * ieee80211_get_mesh_hdrlen - get mesh extension header length
65223 + * @meshhdr: the mesh extension header, only the flags field
65224 + * (first byte) will be accessed
65225 + * Returns the length of the extension header, which is always at
65226 + * least 6 bytes and at most 18 if address 5 and 6 are present.
65227 + */
65228 +unsigned int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr);
65229 +
65230 +/**
65231 * DOC: Data path helpers
65232 *
65233 * In addition to generic utilities, cfg80211 also offers
65234 diff --git a/include/net/flow.h b/include/net/flow.h
65235 index 628e11b..4c475df 100644
65236 --- a/include/net/flow.h
65237 +++ b/include/net/flow.h
65238 @@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
65239
65240 extern void flow_cache_flush(void);
65241 extern void flow_cache_flush_deferred(void);
65242 -extern atomic_t flow_cache_genid;
65243 +extern atomic_unchecked_t flow_cache_genid;
65244
65245 #endif
65246 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
65247 index 53f464d..ba76aaa 100644
65248 --- a/include/net/inetpeer.h
65249 +++ b/include/net/inetpeer.h
65250 @@ -47,8 +47,8 @@ struct inet_peer {
65251 */
65252 union {
65253 struct {
65254 - atomic_t rid; /* Frag reception counter */
65255 - atomic_t ip_id_count; /* IP ID for the next packet */
65256 + atomic_unchecked_t rid; /* Frag reception counter */
65257 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
65258 };
65259 struct rcu_head rcu;
65260 struct inet_peer *gc_next;
65261 @@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
65262 more++;
65263 inet_peer_refcheck(p);
65264 do {
65265 - old = atomic_read(&p->ip_id_count);
65266 + old = atomic_read_unchecked(&p->ip_id_count);
65267 new = old + more;
65268 if (!new)
65269 new = 1;
65270 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
65271 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
65272 return new;
65273 }
65274
65275 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
65276 index 9497be1..5a4fafe 100644
65277 --- a/include/net/ip_fib.h
65278 +++ b/include/net/ip_fib.h
65279 @@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
65280
65281 #define FIB_RES_SADDR(net, res) \
65282 ((FIB_RES_NH(res).nh_saddr_genid == \
65283 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
65284 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
65285 FIB_RES_NH(res).nh_saddr : \
65286 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
65287 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
65288 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
65289 index 95374d1..2300e36 100644
65290 --- a/include/net/ip_vs.h
65291 +++ b/include/net/ip_vs.h
65292 @@ -510,7 +510,7 @@ struct ip_vs_conn {
65293 struct ip_vs_conn *control; /* Master control connection */
65294 atomic_t n_control; /* Number of controlled ones */
65295 struct ip_vs_dest *dest; /* real server */
65296 - atomic_t in_pkts; /* incoming packet counter */
65297 + atomic_unchecked_t in_pkts; /* incoming packet counter */
65298
65299 /* packet transmitter for different forwarding methods. If it
65300 mangles the packet, it must return NF_DROP or better NF_STOLEN,
65301 @@ -648,7 +648,7 @@ struct ip_vs_dest {
65302 __be16 port; /* port number of the server */
65303 union nf_inet_addr addr; /* IP address of the server */
65304 volatile unsigned int flags; /* dest status flags */
65305 - atomic_t conn_flags; /* flags to copy to conn */
65306 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
65307 atomic_t weight; /* server weight */
65308
65309 atomic_t refcnt; /* reference counter */
65310 diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
65311 index 69b610a..fe3962c 100644
65312 --- a/include/net/irda/ircomm_core.h
65313 +++ b/include/net/irda/ircomm_core.h
65314 @@ -51,7 +51,7 @@ typedef struct {
65315 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
65316 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
65317 struct ircomm_info *);
65318 -} call_t;
65319 +} __no_const call_t;
65320
65321 struct ircomm_cb {
65322 irda_queue_t queue;
65323 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
65324 index 59ba38bc..d515662 100644
65325 --- a/include/net/irda/ircomm_tty.h
65326 +++ b/include/net/irda/ircomm_tty.h
65327 @@ -35,6 +35,7 @@
65328 #include <linux/termios.h>
65329 #include <linux/timer.h>
65330 #include <linux/tty.h> /* struct tty_struct */
65331 +#include <asm/local.h>
65332
65333 #include <net/irda/irias_object.h>
65334 #include <net/irda/ircomm_core.h>
65335 @@ -105,8 +106,8 @@ struct ircomm_tty_cb {
65336 unsigned short close_delay;
65337 unsigned short closing_wait; /* time to wait before closing */
65338
65339 - int open_count;
65340 - int blocked_open; /* # of blocked opens */
65341 + local_t open_count;
65342 + local_t blocked_open; /* # of blocked opens */
65343
65344 /* Protect concurent access to :
65345 * o self->open_count
65346 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
65347 index cc7c197..9f2da2a 100644
65348 --- a/include/net/iucv/af_iucv.h
65349 +++ b/include/net/iucv/af_iucv.h
65350 @@ -141,7 +141,7 @@ struct iucv_sock {
65351 struct iucv_sock_list {
65352 struct hlist_head head;
65353 rwlock_t lock;
65354 - atomic_t autobind_name;
65355 + atomic_unchecked_t autobind_name;
65356 };
65357
65358 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
65359 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
65360 index 344d898..2ae1302 100644
65361 --- a/include/net/neighbour.h
65362 +++ b/include/net/neighbour.h
65363 @@ -123,7 +123,7 @@ struct neigh_ops {
65364 void (*error_report)(struct neighbour *, struct sk_buff *);
65365 int (*output)(struct neighbour *, struct sk_buff *);
65366 int (*connected_output)(struct neighbour *, struct sk_buff *);
65367 -};
65368 +} __do_const;
65369
65370 struct pneigh_entry {
65371 struct pneigh_entry *next;
65372 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
65373 index fd87963..312a11f 100644
65374 --- a/include/net/net_namespace.h
65375 +++ b/include/net/net_namespace.h
65376 @@ -102,7 +102,7 @@ struct net {
65377 #endif
65378 struct netns_ipvs *ipvs;
65379 struct sock *diag_nlsk;
65380 - atomic_t rt_genid;
65381 + atomic_unchecked_t rt_genid;
65382 };
65383
65384
65385 @@ -303,12 +303,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
65386
65387 static inline int rt_genid(struct net *net)
65388 {
65389 - return atomic_read(&net->rt_genid);
65390 + return atomic_read_unchecked(&net->rt_genid);
65391 }
65392
65393 static inline void rt_genid_bump(struct net *net)
65394 {
65395 - atomic_inc(&net->rt_genid);
65396 + atomic_inc_unchecked(&net->rt_genid);
65397 }
65398
65399 #endif /* __NET_NET_NAMESPACE_H */
65400 diff --git a/include/net/netdma.h b/include/net/netdma.h
65401 index 8ba8ce2..99b7fff 100644
65402 --- a/include/net/netdma.h
65403 +++ b/include/net/netdma.h
65404 @@ -24,7 +24,7 @@
65405 #include <linux/dmaengine.h>
65406 #include <linux/skbuff.h>
65407
65408 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
65409 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
65410 struct sk_buff *skb, int offset, struct iovec *to,
65411 size_t len, struct dma_pinned_list *pinned_list);
65412
65413 diff --git a/include/net/netlink.h b/include/net/netlink.h
65414 index 785f37a..c81dc0c 100644
65415 --- a/include/net/netlink.h
65416 +++ b/include/net/netlink.h
65417 @@ -520,7 +520,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
65418 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
65419 {
65420 if (mark)
65421 - skb_trim(skb, (unsigned char *) mark - skb->data);
65422 + skb_trim(skb, (const unsigned char *) mark - skb->data);
65423 }
65424
65425 /**
65426 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
65427 index eb24dbc..567d6ed 100644
65428 --- a/include/net/netns/ipv4.h
65429 +++ b/include/net/netns/ipv4.h
65430 @@ -65,7 +65,7 @@ struct netns_ipv4 {
65431 unsigned int sysctl_ping_group_range[2];
65432 long sysctl_tcp_mem[3];
65433
65434 - atomic_t dev_addr_genid;
65435 + atomic_unchecked_t dev_addr_genid;
65436
65437 #ifdef CONFIG_IP_MROUTE
65438 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
65439 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
65440 index ff49964..1411fee 100644
65441 --- a/include/net/sctp/sctp.h
65442 +++ b/include/net/sctp/sctp.h
65443 @@ -320,9 +320,9 @@ do { \
65444
65445 #else /* SCTP_DEBUG */
65446
65447 -#define SCTP_DEBUG_PRINTK(whatever...)
65448 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
65449 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
65450 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
65451 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
65452 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
65453 #define SCTP_ENABLE_DEBUG
65454 #define SCTP_DISABLE_DEBUG
65455 #define SCTP_ASSERT(expr, str, func)
65456 diff --git a/include/net/sock.h b/include/net/sock.h
65457 index adb7da2..1100002 100644
65458 --- a/include/net/sock.h
65459 +++ b/include/net/sock.h
65460 @@ -305,7 +305,7 @@ struct sock {
65461 #ifdef CONFIG_RPS
65462 __u32 sk_rxhash;
65463 #endif
65464 - atomic_t sk_drops;
65465 + atomic_unchecked_t sk_drops;
65466 int sk_rcvbuf;
65467
65468 struct sk_filter __rcu *sk_filter;
65469 @@ -1764,7 +1764,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
65470 }
65471
65472 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
65473 - char __user *from, char *to,
65474 + char __user *from, unsigned char *to,
65475 int copy, int offset)
65476 {
65477 if (skb->ip_summed == CHECKSUM_NONE) {
65478 @@ -2023,7 +2023,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
65479 }
65480 }
65481
65482 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
65483 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
65484
65485 static inline struct page *sk_stream_alloc_page(struct sock *sk)
65486 {
65487 diff --git a/include/net/tcp.h b/include/net/tcp.h
65488 index 1f000ff..e5a8dfb 100644
65489 --- a/include/net/tcp.h
65490 +++ b/include/net/tcp.h
65491 @@ -508,7 +508,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
65492 extern void tcp_xmit_retransmit_queue(struct sock *);
65493 extern void tcp_simple_retransmit(struct sock *);
65494 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
65495 -extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
65496 +extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
65497
65498 extern void tcp_send_probe0(struct sock *);
65499 extern void tcp_send_partial(struct sock *);
65500 @@ -677,8 +677,8 @@ struct tcp_skb_cb {
65501 struct inet6_skb_parm h6;
65502 #endif
65503 } header; /* For incoming frames */
65504 - __u32 seq; /* Starting sequence number */
65505 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
65506 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
65507 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
65508 __u32 when; /* used to compute rtt's */
65509 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
65510
65511 @@ -692,7 +692,7 @@ struct tcp_skb_cb {
65512
65513 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
65514 /* 1 byte hole */
65515 - __u32 ack_seq; /* Sequence number ACK'd */
65516 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
65517 };
65518
65519 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
65520 @@ -1502,7 +1502,7 @@ struct tcp_seq_afinfo {
65521 char *name;
65522 sa_family_t family;
65523 const struct file_operations *seq_fops;
65524 - struct seq_operations seq_ops;
65525 + seq_operations_no_const seq_ops;
65526 };
65527
65528 struct tcp_iter_state {
65529 diff --git a/include/net/udp.h b/include/net/udp.h
65530 index 065f379..b661b40 100644
65531 --- a/include/net/udp.h
65532 +++ b/include/net/udp.h
65533 @@ -244,7 +244,7 @@ struct udp_seq_afinfo {
65534 sa_family_t family;
65535 struct udp_table *udp_table;
65536 const struct file_operations *seq_fops;
65537 - struct seq_operations seq_ops;
65538 + seq_operations_no_const seq_ops;
65539 };
65540
65541 struct udp_iter_state {
65542 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
65543 index 639dd13..15b206c 100644
65544 --- a/include/net/xfrm.h
65545 +++ b/include/net/xfrm.h
65546 @@ -514,7 +514,7 @@ struct xfrm_policy {
65547 struct timer_list timer;
65548
65549 struct flow_cache_object flo;
65550 - atomic_t genid;
65551 + atomic_unchecked_t genid;
65552 u32 priority;
65553 u32 index;
65554 struct xfrm_mark mark;
65555 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
65556 index 1a046b1..ee0bef0 100644
65557 --- a/include/rdma/iw_cm.h
65558 +++ b/include/rdma/iw_cm.h
65559 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
65560 int backlog);
65561
65562 int (*destroy_listen)(struct iw_cm_id *cm_id);
65563 -};
65564 +} __no_const;
65565
65566 /**
65567 * iw_create_cm_id - Create an IW CM identifier.
65568 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
65569 index 399162b..b337f1a 100644
65570 --- a/include/scsi/libfc.h
65571 +++ b/include/scsi/libfc.h
65572 @@ -762,6 +762,7 @@ struct libfc_function_template {
65573 */
65574 void (*disc_stop_final) (struct fc_lport *);
65575 };
65576 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
65577
65578 /**
65579 * struct fc_disc - Discovery context
65580 @@ -866,7 +867,7 @@ struct fc_lport {
65581 struct fc_vport *vport;
65582
65583 /* Operational Information */
65584 - struct libfc_function_template tt;
65585 + libfc_function_template_no_const tt;
65586 u8 link_up;
65587 u8 qfull;
65588 enum fc_lport_state state;
65589 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
65590 index 9895f69..f1418f0 100644
65591 --- a/include/scsi/scsi_device.h
65592 +++ b/include/scsi/scsi_device.h
65593 @@ -166,9 +166,9 @@ struct scsi_device {
65594 unsigned int max_device_blocked; /* what device_blocked counts down from */
65595 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
65596
65597 - atomic_t iorequest_cnt;
65598 - atomic_t iodone_cnt;
65599 - atomic_t ioerr_cnt;
65600 + atomic_unchecked_t iorequest_cnt;
65601 + atomic_unchecked_t iodone_cnt;
65602 + atomic_unchecked_t ioerr_cnt;
65603
65604 struct device sdev_gendev,
65605 sdev_dev;
65606 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
65607 index b797e8f..8e2c3aa 100644
65608 --- a/include/scsi/scsi_transport_fc.h
65609 +++ b/include/scsi/scsi_transport_fc.h
65610 @@ -751,7 +751,8 @@ struct fc_function_template {
65611 unsigned long show_host_system_hostname:1;
65612
65613 unsigned long disable_target_scan:1;
65614 -};
65615 +} __do_const;
65616 +typedef struct fc_function_template __no_const fc_function_template_no_const;
65617
65618
65619 /**
65620 diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
65621 index 030b87c..98a6954 100644
65622 --- a/include/sound/ak4xxx-adda.h
65623 +++ b/include/sound/ak4xxx-adda.h
65624 @@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
65625 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
65626 unsigned char val);
65627 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
65628 -};
65629 +} __no_const;
65630
65631 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
65632
65633 diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
65634 index 8c05e47..2b5df97 100644
65635 --- a/include/sound/hwdep.h
65636 +++ b/include/sound/hwdep.h
65637 @@ -49,7 +49,7 @@ struct snd_hwdep_ops {
65638 struct snd_hwdep_dsp_status *status);
65639 int (*dsp_load)(struct snd_hwdep *hw,
65640 struct snd_hwdep_dsp_image *image);
65641 -};
65642 +} __no_const;
65643
65644 struct snd_hwdep {
65645 struct snd_card *card;
65646 diff --git a/include/sound/info.h b/include/sound/info.h
65647 index 9ca1a49..aba1728 100644
65648 --- a/include/sound/info.h
65649 +++ b/include/sound/info.h
65650 @@ -44,7 +44,7 @@ struct snd_info_entry_text {
65651 struct snd_info_buffer *buffer);
65652 void (*write)(struct snd_info_entry *entry,
65653 struct snd_info_buffer *buffer);
65654 -};
65655 +} __no_const;
65656
65657 struct snd_info_entry_ops {
65658 int (*open)(struct snd_info_entry *entry,
65659 diff --git a/include/sound/pcm.h b/include/sound/pcm.h
65660 index cdca2ab..10bbe05 100644
65661 --- a/include/sound/pcm.h
65662 +++ b/include/sound/pcm.h
65663 @@ -81,6 +81,7 @@ struct snd_pcm_ops {
65664 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
65665 int (*ack)(struct snd_pcm_substream *substream);
65666 };
65667 +typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
65668
65669 /*
65670 *
65671 diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
65672 index af1b49e..a5d55a5 100644
65673 --- a/include/sound/sb16_csp.h
65674 +++ b/include/sound/sb16_csp.h
65675 @@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
65676 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
65677 int (*csp_stop) (struct snd_sb_csp * p);
65678 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
65679 -};
65680 +} __no_const;
65681
65682 /*
65683 * CSP private data
65684 diff --git a/include/sound/soc.h b/include/sound/soc.h
65685 index e063380..e8077d5 100644
65686 --- a/include/sound/soc.h
65687 +++ b/include/sound/soc.h
65688 @@ -801,7 +801,7 @@ struct snd_soc_platform_driver {
65689 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
65690 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
65691 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
65692 -};
65693 +} __do_const;
65694
65695 struct snd_soc_platform {
65696 const char *name;
65697 @@ -1016,7 +1016,7 @@ struct snd_soc_pcm_runtime {
65698 struct snd_soc_dai_link *dai_link;
65699 struct mutex pcm_mutex;
65700 enum snd_soc_pcm_subclass pcm_subclass;
65701 - struct snd_pcm_ops ops;
65702 + snd_pcm_ops_no_const ops;
65703
65704 unsigned int dev_registered:1;
65705
65706 diff --git a/include/sound/tea575x-tuner.h b/include/sound/tea575x-tuner.h
65707 index fe8590c..aaed363 100644
65708 --- a/include/sound/tea575x-tuner.h
65709 +++ b/include/sound/tea575x-tuner.h
65710 @@ -48,7 +48,7 @@ struct snd_tea575x_ops {
65711
65712 struct snd_tea575x {
65713 struct v4l2_device *v4l2_dev;
65714 - struct v4l2_file_operations fops;
65715 + v4l2_file_operations_no_const fops;
65716 struct video_device vd; /* video device */
65717 int radio_nr; /* radio_nr */
65718 bool tea5759; /* 5759 chip is present */
65719 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
65720 index 5be8937..a8e46e9 100644
65721 --- a/include/target/target_core_base.h
65722 +++ b/include/target/target_core_base.h
65723 @@ -434,7 +434,7 @@ struct t10_reservation_ops {
65724 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
65725 int (*t10_pr_register)(struct se_cmd *);
65726 int (*t10_pr_clear)(struct se_cmd *);
65727 -};
65728 +} __no_const;
65729
65730 struct t10_reservation {
65731 /* Reservation effects all target ports */
65732 @@ -758,7 +758,7 @@ struct se_device {
65733 spinlock_t stats_lock;
65734 /* Active commands on this virtual SE device */
65735 atomic_t simple_cmds;
65736 - atomic_t dev_ordered_id;
65737 + atomic_unchecked_t dev_ordered_id;
65738 atomic_t dev_ordered_sync;
65739 atomic_t dev_qf_count;
65740 struct se_obj dev_obj;
65741 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
65742 new file mode 100644
65743 index 0000000..2efe49d
65744 --- /dev/null
65745 +++ b/include/trace/events/fs.h
65746 @@ -0,0 +1,53 @@
65747 +#undef TRACE_SYSTEM
65748 +#define TRACE_SYSTEM fs
65749 +
65750 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
65751 +#define _TRACE_FS_H
65752 +
65753 +#include <linux/fs.h>
65754 +#include <linux/tracepoint.h>
65755 +
65756 +TRACE_EVENT(do_sys_open,
65757 +
65758 + TP_PROTO(char *filename, int flags, int mode),
65759 +
65760 + TP_ARGS(filename, flags, mode),
65761 +
65762 + TP_STRUCT__entry(
65763 + __string( filename, filename )
65764 + __field( int, flags )
65765 + __field( int, mode )
65766 + ),
65767 +
65768 + TP_fast_assign(
65769 + __assign_str(filename, filename);
65770 + __entry->flags = flags;
65771 + __entry->mode = mode;
65772 + ),
65773 +
65774 + TP_printk("\"%s\" %x %o",
65775 + __get_str(filename), __entry->flags, __entry->mode)
65776 +);
65777 +
65778 +TRACE_EVENT(open_exec,
65779 +
65780 + TP_PROTO(const char *filename),
65781 +
65782 + TP_ARGS(filename),
65783 +
65784 + TP_STRUCT__entry(
65785 + __string( filename, filename )
65786 + ),
65787 +
65788 + TP_fast_assign(
65789 + __assign_str(filename, filename);
65790 + ),
65791 +
65792 + TP_printk("\"%s\"",
65793 + __get_str(filename))
65794 +);
65795 +
65796 +#endif /* _TRACE_FS_H */
65797 +
65798 +/* This part must be outside protection */
65799 +#include <trace/define_trace.h>
65800 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
65801 index 1c09820..7f5ec79 100644
65802 --- a/include/trace/events/irq.h
65803 +++ b/include/trace/events/irq.h
65804 @@ -36,7 +36,7 @@ struct softirq_action;
65805 */
65806 TRACE_EVENT(irq_handler_entry,
65807
65808 - TP_PROTO(int irq, struct irqaction *action),
65809 + TP_PROTO(int irq, const struct irqaction *action),
65810
65811 TP_ARGS(irq, action),
65812
65813 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
65814 */
65815 TRACE_EVENT(irq_handler_exit,
65816
65817 - TP_PROTO(int irq, struct irqaction *action, int ret),
65818 + TP_PROTO(int irq, const struct irqaction *action, int ret),
65819
65820 TP_ARGS(irq, action, ret),
65821
65822 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
65823 index f9466fa..f4e2b81 100644
65824 --- a/include/video/udlfb.h
65825 +++ b/include/video/udlfb.h
65826 @@ -53,10 +53,10 @@ struct dlfb_data {
65827 u32 pseudo_palette[256];
65828 int blank_mode; /*one of FB_BLANK_ */
65829 /* blit-only rendering path metrics, exposed through sysfs */
65830 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65831 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
65832 - atomic_t bytes_sent; /* to usb, after compression including overhead */
65833 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
65834 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65835 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
65836 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
65837 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
65838 };
65839
65840 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
65841 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
65842 index 0993a22..32ba2fe 100644
65843 --- a/include/video/uvesafb.h
65844 +++ b/include/video/uvesafb.h
65845 @@ -177,6 +177,7 @@ struct uvesafb_par {
65846 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
65847 u8 pmi_setpal; /* PMI for palette changes */
65848 u16 *pmi_base; /* protected mode interface location */
65849 + u8 *pmi_code; /* protected mode code location */
65850 void *pmi_start;
65851 void *pmi_pal;
65852 u8 *vbe_state_orig; /*
65853 diff --git a/init/Kconfig b/init/Kconfig
65854 index af6c7f8..5c188f8 100644
65855 --- a/init/Kconfig
65856 +++ b/init/Kconfig
65857 @@ -850,6 +850,7 @@ endif # CGROUPS
65858
65859 config CHECKPOINT_RESTORE
65860 bool "Checkpoint/restore support" if EXPERT
65861 + depends on !GRKERNSEC
65862 default n
65863 help
65864 Enables additional kernel features in a sake of checkpoint/restore.
65865 @@ -1029,6 +1030,7 @@ config UIDGID_CONVERTED
65866 # Security modules
65867 depends on SECURITY_TOMOYO = n
65868 depends on SECURITY_APPARMOR = n
65869 + depends on GRKERNSEC = n
65870
65871 config UIDGID_STRICT_TYPE_CHECKS
65872 bool "Require conversions between uid/gids and their internal representation"
65873 @@ -1416,7 +1418,7 @@ config SLUB_DEBUG
65874
65875 config COMPAT_BRK
65876 bool "Disable heap randomization"
65877 - default y
65878 + default n
65879 help
65880 Randomizing heap placement makes heap exploits harder, but it
65881 also breaks ancient binaries (including anything libc5 based).
65882 @@ -1599,7 +1601,7 @@ config INIT_ALL_POSSIBLE
65883 config STOP_MACHINE
65884 bool
65885 default y
65886 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
65887 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
65888 help
65889 Need stop_machine() primitive.
65890
65891 diff --git a/init/Makefile b/init/Makefile
65892 index 7bc47ee..6da2dc7 100644
65893 --- a/init/Makefile
65894 +++ b/init/Makefile
65895 @@ -2,6 +2,9 @@
65896 # Makefile for the linux kernel.
65897 #
65898
65899 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
65900 +asflags-y := $(GCC_PLUGINS_AFLAGS)
65901 +
65902 obj-y := main.o version.o mounts.o
65903 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
65904 obj-y += noinitramfs.o
65905 diff --git a/init/do_mounts.c b/init/do_mounts.c
65906 index d3f0aee..c9322f5 100644
65907 --- a/init/do_mounts.c
65908 +++ b/init/do_mounts.c
65909 @@ -336,11 +336,11 @@ static void __init get_fs_names(char *page)
65910 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
65911 {
65912 struct super_block *s;
65913 - int err = sys_mount(name, "/root", fs, flags, data);
65914 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
65915 if (err)
65916 return err;
65917
65918 - sys_chdir("/root");
65919 + sys_chdir((const char __force_user *)"/root");
65920 s = current->fs->pwd.dentry->d_sb;
65921 ROOT_DEV = s->s_dev;
65922 printk(KERN_INFO
65923 @@ -460,18 +460,18 @@ void __init change_floppy(char *fmt, ...)
65924 va_start(args, fmt);
65925 vsprintf(buf, fmt, args);
65926 va_end(args);
65927 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
65928 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
65929 if (fd >= 0) {
65930 sys_ioctl(fd, FDEJECT, 0);
65931 sys_close(fd);
65932 }
65933 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
65934 - fd = sys_open("/dev/console", O_RDWR, 0);
65935 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
65936 if (fd >= 0) {
65937 sys_ioctl(fd, TCGETS, (long)&termios);
65938 termios.c_lflag &= ~ICANON;
65939 sys_ioctl(fd, TCSETSF, (long)&termios);
65940 - sys_read(fd, &c, 1);
65941 + sys_read(fd, (char __user *)&c, 1);
65942 termios.c_lflag |= ICANON;
65943 sys_ioctl(fd, TCSETSF, (long)&termios);
65944 sys_close(fd);
65945 @@ -565,6 +565,6 @@ void __init prepare_namespace(void)
65946 mount_root();
65947 out:
65948 devtmpfs_mount("dev");
65949 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
65950 - sys_chroot(".");
65951 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65952 + sys_chroot((const char __force_user *)".");
65953 }
65954 diff --git a/init/do_mounts.h b/init/do_mounts.h
65955 index f5b978a..69dbfe8 100644
65956 --- a/init/do_mounts.h
65957 +++ b/init/do_mounts.h
65958 @@ -15,15 +15,15 @@ extern int root_mountflags;
65959
65960 static inline int create_dev(char *name, dev_t dev)
65961 {
65962 - sys_unlink(name);
65963 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
65964 + sys_unlink((char __force_user *)name);
65965 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
65966 }
65967
65968 #if BITS_PER_LONG == 32
65969 static inline u32 bstat(char *name)
65970 {
65971 struct stat64 stat;
65972 - if (sys_stat64(name, &stat) != 0)
65973 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
65974 return 0;
65975 if (!S_ISBLK(stat.st_mode))
65976 return 0;
65977 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
65978 static inline u32 bstat(char *name)
65979 {
65980 struct stat stat;
65981 - if (sys_newstat(name, &stat) != 0)
65982 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
65983 return 0;
65984 if (!S_ISBLK(stat.st_mode))
65985 return 0;
65986 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
65987 index 135959a2..28a3f43 100644
65988 --- a/init/do_mounts_initrd.c
65989 +++ b/init/do_mounts_initrd.c
65990 @@ -53,13 +53,13 @@ static void __init handle_initrd(void)
65991 create_dev("/dev/root.old", Root_RAM0);
65992 /* mount initrd on rootfs' /root */
65993 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
65994 - sys_mkdir("/old", 0700);
65995 - root_fd = sys_open("/", 0, 0);
65996 - old_fd = sys_open("/old", 0, 0);
65997 + sys_mkdir((const char __force_user *)"/old", 0700);
65998 + root_fd = sys_open((const char __force_user *)"/", 0, 0);
65999 + old_fd = sys_open((const char __force_user *)"/old", 0, 0);
66000 /* move initrd over / and chdir/chroot in initrd root */
66001 - sys_chdir("/root");
66002 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
66003 - sys_chroot(".");
66004 + sys_chdir((const char __force_user *)"/root");
66005 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
66006 + sys_chroot((const char __force_user *)".");
66007
66008 /*
66009 * In case that a resume from disk is carried out by linuxrc or one of
66010 @@ -76,15 +76,15 @@ static void __init handle_initrd(void)
66011
66012 /* move initrd to rootfs' /old */
66013 sys_fchdir(old_fd);
66014 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
66015 + sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
66016 /* switch root and cwd back to / of rootfs */
66017 sys_fchdir(root_fd);
66018 - sys_chroot(".");
66019 + sys_chroot((const char __force_user *)".");
66020 sys_close(old_fd);
66021 sys_close(root_fd);
66022
66023 if (new_decode_dev(real_root_dev) == Root_RAM0) {
66024 - sys_chdir("/old");
66025 + sys_chdir((const char __force_user *)"/old");
66026 return;
66027 }
66028
66029 @@ -92,17 +92,17 @@ static void __init handle_initrd(void)
66030 mount_root();
66031
66032 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
66033 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
66034 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
66035 if (!error)
66036 printk("okay\n");
66037 else {
66038 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
66039 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
66040 if (error == -ENOENT)
66041 printk("/initrd does not exist. Ignored.\n");
66042 else
66043 printk("failed\n");
66044 printk(KERN_NOTICE "Unmounting old root\n");
66045 - sys_umount("/old", MNT_DETACH);
66046 + sys_umount((char __force_user *)"/old", MNT_DETACH);
66047 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
66048 if (fd < 0) {
66049 error = fd;
66050 @@ -125,11 +125,11 @@ int __init initrd_load(void)
66051 * mounted in the normal path.
66052 */
66053 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
66054 - sys_unlink("/initrd.image");
66055 + sys_unlink((const char __force_user *)"/initrd.image");
66056 handle_initrd();
66057 return 1;
66058 }
66059 }
66060 - sys_unlink("/initrd.image");
66061 + sys_unlink((const char __force_user *)"/initrd.image");
66062 return 0;
66063 }
66064 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
66065 index 8cb6db5..d729f50 100644
66066 --- a/init/do_mounts_md.c
66067 +++ b/init/do_mounts_md.c
66068 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
66069 partitioned ? "_d" : "", minor,
66070 md_setup_args[ent].device_names);
66071
66072 - fd = sys_open(name, 0, 0);
66073 + fd = sys_open((char __force_user *)name, 0, 0);
66074 if (fd < 0) {
66075 printk(KERN_ERR "md: open failed - cannot start "
66076 "array %s\n", name);
66077 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
66078 * array without it
66079 */
66080 sys_close(fd);
66081 - fd = sys_open(name, 0, 0);
66082 + fd = sys_open((char __force_user *)name, 0, 0);
66083 sys_ioctl(fd, BLKRRPART, 0);
66084 }
66085 sys_close(fd);
66086 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
66087
66088 wait_for_device_probe();
66089
66090 - fd = sys_open("/dev/md0", 0, 0);
66091 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
66092 if (fd >= 0) {
66093 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
66094 sys_close(fd);
66095 diff --git a/init/init_task.c b/init/init_task.c
66096 index 8b2f399..f0797c9 100644
66097 --- a/init/init_task.c
66098 +++ b/init/init_task.c
66099 @@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
66100 * Initial thread structure. Alignment of this is handled by a special
66101 * linker map entry.
66102 */
66103 +#ifdef CONFIG_X86
66104 +union thread_union init_thread_union __init_task_data;
66105 +#else
66106 union thread_union init_thread_union __init_task_data =
66107 { INIT_THREAD_INFO(init_task) };
66108 +#endif
66109 diff --git a/init/initramfs.c b/init/initramfs.c
66110 index 84c6bf1..8899338 100644
66111 --- a/init/initramfs.c
66112 +++ b/init/initramfs.c
66113 @@ -84,7 +84,7 @@ static void __init free_hash(void)
66114 }
66115 }
66116
66117 -static long __init do_utime(char *filename, time_t mtime)
66118 +static long __init do_utime(char __force_user *filename, time_t mtime)
66119 {
66120 struct timespec t[2];
66121
66122 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
66123 struct dir_entry *de, *tmp;
66124 list_for_each_entry_safe(de, tmp, &dir_list, list) {
66125 list_del(&de->list);
66126 - do_utime(de->name, de->mtime);
66127 + do_utime((char __force_user *)de->name, de->mtime);
66128 kfree(de->name);
66129 kfree(de);
66130 }
66131 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
66132 if (nlink >= 2) {
66133 char *old = find_link(major, minor, ino, mode, collected);
66134 if (old)
66135 - return (sys_link(old, collected) < 0) ? -1 : 1;
66136 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
66137 }
66138 return 0;
66139 }
66140 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
66141 {
66142 struct stat st;
66143
66144 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
66145 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
66146 if (S_ISDIR(st.st_mode))
66147 - sys_rmdir(path);
66148 + sys_rmdir((char __force_user *)path);
66149 else
66150 - sys_unlink(path);
66151 + sys_unlink((char __force_user *)path);
66152 }
66153 }
66154
66155 @@ -315,7 +315,7 @@ static int __init do_name(void)
66156 int openflags = O_WRONLY|O_CREAT;
66157 if (ml != 1)
66158 openflags |= O_TRUNC;
66159 - wfd = sys_open(collected, openflags, mode);
66160 + wfd = sys_open((char __force_user *)collected, openflags, mode);
66161
66162 if (wfd >= 0) {
66163 sys_fchown(wfd, uid, gid);
66164 @@ -327,17 +327,17 @@ static int __init do_name(void)
66165 }
66166 }
66167 } else if (S_ISDIR(mode)) {
66168 - sys_mkdir(collected, mode);
66169 - sys_chown(collected, uid, gid);
66170 - sys_chmod(collected, mode);
66171 + sys_mkdir((char __force_user *)collected, mode);
66172 + sys_chown((char __force_user *)collected, uid, gid);
66173 + sys_chmod((char __force_user *)collected, mode);
66174 dir_add(collected, mtime);
66175 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
66176 S_ISFIFO(mode) || S_ISSOCK(mode)) {
66177 if (maybe_link() == 0) {
66178 - sys_mknod(collected, mode, rdev);
66179 - sys_chown(collected, uid, gid);
66180 - sys_chmod(collected, mode);
66181 - do_utime(collected, mtime);
66182 + sys_mknod((char __force_user *)collected, mode, rdev);
66183 + sys_chown((char __force_user *)collected, uid, gid);
66184 + sys_chmod((char __force_user *)collected, mode);
66185 + do_utime((char __force_user *)collected, mtime);
66186 }
66187 }
66188 return 0;
66189 @@ -346,15 +346,15 @@ static int __init do_name(void)
66190 static int __init do_copy(void)
66191 {
66192 if (count >= body_len) {
66193 - sys_write(wfd, victim, body_len);
66194 + sys_write(wfd, (char __force_user *)victim, body_len);
66195 sys_close(wfd);
66196 - do_utime(vcollected, mtime);
66197 + do_utime((char __force_user *)vcollected, mtime);
66198 kfree(vcollected);
66199 eat(body_len);
66200 state = SkipIt;
66201 return 0;
66202 } else {
66203 - sys_write(wfd, victim, count);
66204 + sys_write(wfd, (char __force_user *)victim, count);
66205 body_len -= count;
66206 eat(count);
66207 return 1;
66208 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
66209 {
66210 collected[N_ALIGN(name_len) + body_len] = '\0';
66211 clean_path(collected, 0);
66212 - sys_symlink(collected + N_ALIGN(name_len), collected);
66213 - sys_lchown(collected, uid, gid);
66214 - do_utime(collected, mtime);
66215 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
66216 + sys_lchown((char __force_user *)collected, uid, gid);
66217 + do_utime((char __force_user *)collected, mtime);
66218 state = SkipIt;
66219 next_state = Reset;
66220 return 0;
66221 diff --git a/init/main.c b/init/main.c
66222 index d61ec54..bd3144f 100644
66223 --- a/init/main.c
66224 +++ b/init/main.c
66225 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
66226 extern void tc_init(void);
66227 #endif
66228
66229 +extern void grsecurity_init(void);
66230 +
66231 /*
66232 * Debug helper: via this flag we know that we are in 'early bootup code'
66233 * where only the boot processor is running with IRQ disabled. This means
66234 @@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
66235
66236 __setup("reset_devices", set_reset_devices);
66237
66238 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66239 +int grsec_proc_gid = CONFIG_GRKERNSEC_PROC_GID;
66240 +static int __init setup_grsec_proc_gid(char *str)
66241 +{
66242 + grsec_proc_gid = (int)simple_strtol(str, NULL, 0);
66243 + return 1;
66244 +}
66245 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
66246 +#endif
66247 +
66248 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
66249 +extern char pax_enter_kernel_user[];
66250 +extern char pax_exit_kernel_user[];
66251 +extern pgdval_t clone_pgd_mask;
66252 +#endif
66253 +
66254 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
66255 +static int __init setup_pax_nouderef(char *str)
66256 +{
66257 +#ifdef CONFIG_X86_32
66258 + unsigned int cpu;
66259 + struct desc_struct *gdt;
66260 +
66261 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
66262 + gdt = get_cpu_gdt_table(cpu);
66263 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
66264 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
66265 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
66266 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
66267 + }
66268 + loadsegment(ds, __KERNEL_DS);
66269 + loadsegment(es, __KERNEL_DS);
66270 + loadsegment(ss, __KERNEL_DS);
66271 +#else
66272 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
66273 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
66274 + clone_pgd_mask = ~(pgdval_t)0UL;
66275 +#endif
66276 +
66277 + return 0;
66278 +}
66279 +early_param("pax_nouderef", setup_pax_nouderef);
66280 +#endif
66281 +
66282 +#ifdef CONFIG_PAX_SOFTMODE
66283 +int pax_softmode;
66284 +
66285 +static int __init setup_pax_softmode(char *str)
66286 +{
66287 + get_option(&str, &pax_softmode);
66288 + return 1;
66289 +}
66290 +__setup("pax_softmode=", setup_pax_softmode);
66291 +#endif
66292 +
66293 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
66294 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
66295 static const char *panic_later, *panic_param;
66296 @@ -678,6 +735,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
66297 {
66298 int count = preempt_count();
66299 int ret;
66300 + const char *msg1 = "", *msg2 = "";
66301
66302 if (initcall_debug)
66303 ret = do_one_initcall_debug(fn);
66304 @@ -690,15 +748,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
66305 sprintf(msgbuf, "error code %d ", ret);
66306
66307 if (preempt_count() != count) {
66308 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
66309 + msg1 = " preemption imbalance";
66310 preempt_count() = count;
66311 }
66312 if (irqs_disabled()) {
66313 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
66314 + msg2 = " disabled interrupts";
66315 local_irq_enable();
66316 }
66317 - if (msgbuf[0]) {
66318 - printk("initcall %pF returned with %s\n", fn, msgbuf);
66319 + if (msgbuf[0] || *msg1 || *msg2) {
66320 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
66321 }
66322
66323 return ret;
66324 @@ -752,8 +810,14 @@ static void __init do_initcall_level(int level)
66325 level, level,
66326 &repair_env_string);
66327
66328 - for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
66329 + for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
66330 do_one_initcall(*fn);
66331 +
66332 +#ifdef CONFIG_PAX_LATENT_ENTROPY
66333 + transfer_latent_entropy();
66334 +#endif
66335 +
66336 + }
66337 }
66338
66339 static void __init do_initcalls(void)
66340 @@ -787,8 +851,14 @@ static void __init do_pre_smp_initcalls(void)
66341 {
66342 initcall_t *fn;
66343
66344 - for (fn = __initcall_start; fn < __initcall0_start; fn++)
66345 + for (fn = __initcall_start; fn < __initcall0_start; fn++) {
66346 do_one_initcall(*fn);
66347 +
66348 +#ifdef CONFIG_PAX_LATENT_ENTROPY
66349 + transfer_latent_entropy();
66350 +#endif
66351 +
66352 + }
66353 }
66354
66355 static void run_init_process(const char *init_filename)
66356 @@ -870,7 +940,7 @@ static int __init kernel_init(void * unused)
66357 do_basic_setup();
66358
66359 /* Open the /dev/console on the rootfs, this should never fail */
66360 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
66361 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
66362 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
66363
66364 (void) sys_dup(0);
66365 @@ -883,11 +953,13 @@ static int __init kernel_init(void * unused)
66366 if (!ramdisk_execute_command)
66367 ramdisk_execute_command = "/init";
66368
66369 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
66370 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
66371 ramdisk_execute_command = NULL;
66372 prepare_namespace();
66373 }
66374
66375 + grsecurity_init();
66376 +
66377 /*
66378 * Ok, we have completed the initial bootup, and
66379 * we're essentially up and running. Get rid of the
66380 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
66381 index 9a08acc..e65ebe7 100644
66382 --- a/ipc/mqueue.c
66383 +++ b/ipc/mqueue.c
66384 @@ -279,6 +279,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
66385 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
66386 info->attr.mq_msgsize);
66387
66388 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
66389 spin_lock(&mq_lock);
66390 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
66391 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
66392 diff --git a/ipc/msg.c b/ipc/msg.c
66393 index 7385de2..a8180e08 100644
66394 --- a/ipc/msg.c
66395 +++ b/ipc/msg.c
66396 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
66397 return security_msg_queue_associate(msq, msgflg);
66398 }
66399
66400 +static struct ipc_ops msg_ops = {
66401 + .getnew = newque,
66402 + .associate = msg_security,
66403 + .more_checks = NULL
66404 +};
66405 +
66406 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
66407 {
66408 struct ipc_namespace *ns;
66409 - struct ipc_ops msg_ops;
66410 struct ipc_params msg_params;
66411
66412 ns = current->nsproxy->ipc_ns;
66413
66414 - msg_ops.getnew = newque;
66415 - msg_ops.associate = msg_security;
66416 - msg_ops.more_checks = NULL;
66417 -
66418 msg_params.key = key;
66419 msg_params.flg = msgflg;
66420
66421 diff --git a/ipc/sem.c b/ipc/sem.c
66422 index 5215a81..cfc0cac 100644
66423 --- a/ipc/sem.c
66424 +++ b/ipc/sem.c
66425 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
66426 return 0;
66427 }
66428
66429 +static struct ipc_ops sem_ops = {
66430 + .getnew = newary,
66431 + .associate = sem_security,
66432 + .more_checks = sem_more_checks
66433 +};
66434 +
66435 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66436 {
66437 struct ipc_namespace *ns;
66438 - struct ipc_ops sem_ops;
66439 struct ipc_params sem_params;
66440
66441 ns = current->nsproxy->ipc_ns;
66442 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66443 if (nsems < 0 || nsems > ns->sc_semmsl)
66444 return -EINVAL;
66445
66446 - sem_ops.getnew = newary;
66447 - sem_ops.associate = sem_security;
66448 - sem_ops.more_checks = sem_more_checks;
66449 -
66450 sem_params.key = key;
66451 sem_params.flg = semflg;
66452 sem_params.u.nsems = nsems;
66453 diff --git a/ipc/shm.c b/ipc/shm.c
66454 index 00faa05..7040960 100644
66455 --- a/ipc/shm.c
66456 +++ b/ipc/shm.c
66457 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
66458 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
66459 #endif
66460
66461 +#ifdef CONFIG_GRKERNSEC
66462 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66463 + const time_t shm_createtime, const uid_t cuid,
66464 + const int shmid);
66465 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66466 + const time_t shm_createtime);
66467 +#endif
66468 +
66469 void shm_init_ns(struct ipc_namespace *ns)
66470 {
66471 ns->shm_ctlmax = SHMMAX;
66472 @@ -520,6 +528,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
66473 shp->shm_lprid = 0;
66474 shp->shm_atim = shp->shm_dtim = 0;
66475 shp->shm_ctim = get_seconds();
66476 +#ifdef CONFIG_GRKERNSEC
66477 + {
66478 + struct timespec timeval;
66479 + do_posix_clock_monotonic_gettime(&timeval);
66480 +
66481 + shp->shm_createtime = timeval.tv_sec;
66482 + }
66483 +#endif
66484 shp->shm_segsz = size;
66485 shp->shm_nattch = 0;
66486 shp->shm_file = file;
66487 @@ -571,18 +587,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
66488 return 0;
66489 }
66490
66491 +static struct ipc_ops shm_ops = {
66492 + .getnew = newseg,
66493 + .associate = shm_security,
66494 + .more_checks = shm_more_checks
66495 +};
66496 +
66497 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
66498 {
66499 struct ipc_namespace *ns;
66500 - struct ipc_ops shm_ops;
66501 struct ipc_params shm_params;
66502
66503 ns = current->nsproxy->ipc_ns;
66504
66505 - shm_ops.getnew = newseg;
66506 - shm_ops.associate = shm_security;
66507 - shm_ops.more_checks = shm_more_checks;
66508 -
66509 shm_params.key = key;
66510 shm_params.flg = shmflg;
66511 shm_params.u.size = size;
66512 @@ -1001,6 +1018,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
66513 f_mode = FMODE_READ | FMODE_WRITE;
66514 }
66515 if (shmflg & SHM_EXEC) {
66516 +
66517 +#ifdef CONFIG_PAX_MPROTECT
66518 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
66519 + goto out;
66520 +#endif
66521 +
66522 prot |= PROT_EXEC;
66523 acc_mode |= S_IXUGO;
66524 }
66525 @@ -1024,9 +1047,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
66526 if (err)
66527 goto out_unlock;
66528
66529 +#ifdef CONFIG_GRKERNSEC
66530 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
66531 + shp->shm_perm.cuid, shmid) ||
66532 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
66533 + err = -EACCES;
66534 + goto out_unlock;
66535 + }
66536 +#endif
66537 +
66538 path = shp->shm_file->f_path;
66539 path_get(&path);
66540 shp->shm_nattch++;
66541 +#ifdef CONFIG_GRKERNSEC
66542 + shp->shm_lapid = current->pid;
66543 +#endif
66544 size = i_size_read(path.dentry->d_inode);
66545 shm_unlock(shp);
66546
66547 diff --git a/kernel/acct.c b/kernel/acct.c
66548 index 02e6167..54824f7 100644
66549 --- a/kernel/acct.c
66550 +++ b/kernel/acct.c
66551 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
66552 */
66553 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
66554 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
66555 - file->f_op->write(file, (char *)&ac,
66556 + file->f_op->write(file, (char __force_user *)&ac,
66557 sizeof(acct_t), &file->f_pos);
66558 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
66559 set_fs(fs);
66560 diff --git a/kernel/audit.c b/kernel/audit.c
66561 index a8c84be..8bd034c 100644
66562 --- a/kernel/audit.c
66563 +++ b/kernel/audit.c
66564 @@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
66565 3) suppressed due to audit_rate_limit
66566 4) suppressed due to audit_backlog_limit
66567 */
66568 -static atomic_t audit_lost = ATOMIC_INIT(0);
66569 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
66570
66571 /* The netlink socket. */
66572 static struct sock *audit_sock;
66573 @@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
66574 unsigned long now;
66575 int print;
66576
66577 - atomic_inc(&audit_lost);
66578 + atomic_inc_unchecked(&audit_lost);
66579
66580 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
66581
66582 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
66583 printk(KERN_WARNING
66584 "audit: audit_lost=%d audit_rate_limit=%d "
66585 "audit_backlog_limit=%d\n",
66586 - atomic_read(&audit_lost),
66587 + atomic_read_unchecked(&audit_lost),
66588 audit_rate_limit,
66589 audit_backlog_limit);
66590 audit_panic(message);
66591 @@ -690,7 +690,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
66592 status_set.pid = audit_pid;
66593 status_set.rate_limit = audit_rate_limit;
66594 status_set.backlog_limit = audit_backlog_limit;
66595 - status_set.lost = atomic_read(&audit_lost);
66596 + status_set.lost = atomic_read_unchecked(&audit_lost);
66597 status_set.backlog = skb_queue_len(&audit_skb_queue);
66598 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
66599 &status_set, sizeof(status_set));
66600 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
66601 index 4b96415..d8c16ee 100644
66602 --- a/kernel/auditsc.c
66603 +++ b/kernel/auditsc.c
66604 @@ -2289,7 +2289,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
66605 }
66606
66607 /* global counter which is incremented every time something logs in */
66608 -static atomic_t session_id = ATOMIC_INIT(0);
66609 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
66610
66611 /**
66612 * audit_set_loginuid - set current task's audit_context loginuid
66613 @@ -2313,7 +2313,7 @@ int audit_set_loginuid(uid_t loginuid)
66614 return -EPERM;
66615 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
66616
66617 - sessionid = atomic_inc_return(&session_id);
66618 + sessionid = atomic_inc_return_unchecked(&session_id);
66619 if (context && context->in_syscall) {
66620 struct audit_buffer *ab;
66621
66622 diff --git a/kernel/capability.c b/kernel/capability.c
66623 index 493d972..ea17248 100644
66624 --- a/kernel/capability.c
66625 +++ b/kernel/capability.c
66626 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
66627 * before modification is attempted and the application
66628 * fails.
66629 */
66630 + if (tocopy > ARRAY_SIZE(kdata))
66631 + return -EFAULT;
66632 +
66633 if (copy_to_user(dataptr, kdata, tocopy
66634 * sizeof(struct __user_cap_data_struct))) {
66635 return -EFAULT;
66636 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
66637 int ret;
66638
66639 rcu_read_lock();
66640 - ret = security_capable(__task_cred(t), ns, cap);
66641 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
66642 + gr_task_is_capable(t, __task_cred(t), cap);
66643 rcu_read_unlock();
66644
66645 - return (ret == 0);
66646 + return ret;
66647 }
66648
66649 /**
66650 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
66651 int ret;
66652
66653 rcu_read_lock();
66654 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
66655 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
66656 rcu_read_unlock();
66657
66658 - return (ret == 0);
66659 + return ret;
66660 }
66661
66662 /**
66663 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
66664 BUG();
66665 }
66666
66667 - if (security_capable(current_cred(), ns, cap) == 0) {
66668 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
66669 current->flags |= PF_SUPERPRIV;
66670 return true;
66671 }
66672 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
66673 }
66674 EXPORT_SYMBOL(ns_capable);
66675
66676 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
66677 +{
66678 + if (unlikely(!cap_valid(cap))) {
66679 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
66680 + BUG();
66681 + }
66682 +
66683 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
66684 + current->flags |= PF_SUPERPRIV;
66685 + return true;
66686 + }
66687 + return false;
66688 +}
66689 +EXPORT_SYMBOL(ns_capable_nolog);
66690 +
66691 /**
66692 * capable - Determine if the current task has a superior capability in effect
66693 * @cap: The capability to be tested for
66694 @@ -408,6 +427,12 @@ bool capable(int cap)
66695 }
66696 EXPORT_SYMBOL(capable);
66697
66698 +bool capable_nolog(int cap)
66699 +{
66700 + return ns_capable_nolog(&init_user_ns, cap);
66701 +}
66702 +EXPORT_SYMBOL(capable_nolog);
66703 +
66704 /**
66705 * nsown_capable - Check superior capability to one's own user_ns
66706 * @cap: The capability in question
66707 @@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
66708
66709 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
66710 }
66711 +
66712 +bool inode_capable_nolog(const struct inode *inode, int cap)
66713 +{
66714 + struct user_namespace *ns = current_user_ns();
66715 +
66716 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
66717 +}
66718 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
66719 index ff2bce5..a41e8f9 100644
66720 --- a/kernel/cgroup.c
66721 +++ b/kernel/cgroup.c
66722 @@ -5390,7 +5390,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
66723 struct css_set *cg = link->cg;
66724 struct task_struct *task;
66725 int count = 0;
66726 - seq_printf(seq, "css_set %p\n", cg);
66727 + seq_printf(seq, "css_set %pK\n", cg);
66728 list_for_each_entry(task, &cg->tasks, cg_list) {
66729 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
66730 seq_puts(seq, " ...\n");
66731 diff --git a/kernel/compat.c b/kernel/compat.c
66732 index c28a306..b4d0cf3 100644
66733 --- a/kernel/compat.c
66734 +++ b/kernel/compat.c
66735 @@ -13,6 +13,7 @@
66736
66737 #include <linux/linkage.h>
66738 #include <linux/compat.h>
66739 +#include <linux/module.h>
66740 #include <linux/errno.h>
66741 #include <linux/time.h>
66742 #include <linux/signal.h>
66743 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
66744 mm_segment_t oldfs;
66745 long ret;
66746
66747 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
66748 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
66749 oldfs = get_fs();
66750 set_fs(KERNEL_DS);
66751 ret = hrtimer_nanosleep_restart(restart);
66752 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
66753 oldfs = get_fs();
66754 set_fs(KERNEL_DS);
66755 ret = hrtimer_nanosleep(&tu,
66756 - rmtp ? (struct timespec __user *)&rmt : NULL,
66757 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
66758 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
66759 set_fs(oldfs);
66760
66761 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
66762 mm_segment_t old_fs = get_fs();
66763
66764 set_fs(KERNEL_DS);
66765 - ret = sys_sigpending((old_sigset_t __user *) &s);
66766 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
66767 set_fs(old_fs);
66768 if (ret == 0)
66769 ret = put_user(s, set);
66770 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
66771 mm_segment_t old_fs = get_fs();
66772
66773 set_fs(KERNEL_DS);
66774 - ret = sys_old_getrlimit(resource, &r);
66775 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
66776 set_fs(old_fs);
66777
66778 if (!ret) {
66779 @@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
66780 mm_segment_t old_fs = get_fs();
66781
66782 set_fs(KERNEL_DS);
66783 - ret = sys_getrusage(who, (struct rusage __user *) &r);
66784 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
66785 set_fs(old_fs);
66786
66787 if (ret)
66788 @@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
66789 set_fs (KERNEL_DS);
66790 ret = sys_wait4(pid,
66791 (stat_addr ?
66792 - (unsigned int __user *) &status : NULL),
66793 - options, (struct rusage __user *) &r);
66794 + (unsigned int __force_user *) &status : NULL),
66795 + options, (struct rusage __force_user *) &r);
66796 set_fs (old_fs);
66797
66798 if (ret > 0) {
66799 @@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
66800 memset(&info, 0, sizeof(info));
66801
66802 set_fs(KERNEL_DS);
66803 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
66804 - uru ? (struct rusage __user *)&ru : NULL);
66805 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
66806 + uru ? (struct rusage __force_user *)&ru : NULL);
66807 set_fs(old_fs);
66808
66809 if ((ret < 0) || (info.si_signo == 0))
66810 @@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
66811 oldfs = get_fs();
66812 set_fs(KERNEL_DS);
66813 err = sys_timer_settime(timer_id, flags,
66814 - (struct itimerspec __user *) &newts,
66815 - (struct itimerspec __user *) &oldts);
66816 + (struct itimerspec __force_user *) &newts,
66817 + (struct itimerspec __force_user *) &oldts);
66818 set_fs(oldfs);
66819 if (!err && old && put_compat_itimerspec(old, &oldts))
66820 return -EFAULT;
66821 @@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
66822 oldfs = get_fs();
66823 set_fs(KERNEL_DS);
66824 err = sys_timer_gettime(timer_id,
66825 - (struct itimerspec __user *) &ts);
66826 + (struct itimerspec __force_user *) &ts);
66827 set_fs(oldfs);
66828 if (!err && put_compat_itimerspec(setting, &ts))
66829 return -EFAULT;
66830 @@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
66831 oldfs = get_fs();
66832 set_fs(KERNEL_DS);
66833 err = sys_clock_settime(which_clock,
66834 - (struct timespec __user *) &ts);
66835 + (struct timespec __force_user *) &ts);
66836 set_fs(oldfs);
66837 return err;
66838 }
66839 @@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
66840 oldfs = get_fs();
66841 set_fs(KERNEL_DS);
66842 err = sys_clock_gettime(which_clock,
66843 - (struct timespec __user *) &ts);
66844 + (struct timespec __force_user *) &ts);
66845 set_fs(oldfs);
66846 if (!err && put_compat_timespec(&ts, tp))
66847 return -EFAULT;
66848 @@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
66849
66850 oldfs = get_fs();
66851 set_fs(KERNEL_DS);
66852 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
66853 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
66854 set_fs(oldfs);
66855
66856 err = compat_put_timex(utp, &txc);
66857 @@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
66858 oldfs = get_fs();
66859 set_fs(KERNEL_DS);
66860 err = sys_clock_getres(which_clock,
66861 - (struct timespec __user *) &ts);
66862 + (struct timespec __force_user *) &ts);
66863 set_fs(oldfs);
66864 if (!err && tp && put_compat_timespec(&ts, tp))
66865 return -EFAULT;
66866 @@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
66867 long err;
66868 mm_segment_t oldfs;
66869 struct timespec tu;
66870 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
66871 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
66872
66873 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
66874 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
66875 oldfs = get_fs();
66876 set_fs(KERNEL_DS);
66877 err = clock_nanosleep_restart(restart);
66878 @@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
66879 oldfs = get_fs();
66880 set_fs(KERNEL_DS);
66881 err = sys_clock_nanosleep(which_clock, flags,
66882 - (struct timespec __user *) &in,
66883 - (struct timespec __user *) &out);
66884 + (struct timespec __force_user *) &in,
66885 + (struct timespec __force_user *) &out);
66886 set_fs(oldfs);
66887
66888 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
66889 diff --git a/kernel/configs.c b/kernel/configs.c
66890 index 42e8fa0..9e7406b 100644
66891 --- a/kernel/configs.c
66892 +++ b/kernel/configs.c
66893 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
66894 struct proc_dir_entry *entry;
66895
66896 /* create the current config file */
66897 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
66898 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
66899 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
66900 + &ikconfig_file_ops);
66901 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66902 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
66903 + &ikconfig_file_ops);
66904 +#endif
66905 +#else
66906 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
66907 &ikconfig_file_ops);
66908 +#endif
66909 +
66910 if (!entry)
66911 return -ENOMEM;
66912
66913 diff --git a/kernel/cred.c b/kernel/cred.c
66914 index de728ac..e3c267c 100644
66915 --- a/kernel/cred.c
66916 +++ b/kernel/cred.c
66917 @@ -207,6 +207,16 @@ void exit_creds(struct task_struct *tsk)
66918 validate_creds(cred);
66919 alter_cred_subscribers(cred, -1);
66920 put_cred(cred);
66921 +
66922 +#ifdef CONFIG_GRKERNSEC_SETXID
66923 + cred = (struct cred *) tsk->delayed_cred;
66924 + if (cred != NULL) {
66925 + tsk->delayed_cred = NULL;
66926 + validate_creds(cred);
66927 + alter_cred_subscribers(cred, -1);
66928 + put_cred(cred);
66929 + }
66930 +#endif
66931 }
66932
66933 /**
66934 @@ -469,7 +479,7 @@ error_put:
66935 * Always returns 0 thus allowing this function to be tail-called at the end
66936 * of, say, sys_setgid().
66937 */
66938 -int commit_creds(struct cred *new)
66939 +static int __commit_creds(struct cred *new)
66940 {
66941 struct task_struct *task = current;
66942 const struct cred *old = task->real_cred;
66943 @@ -488,6 +498,8 @@ int commit_creds(struct cred *new)
66944
66945 get_cred(new); /* we will require a ref for the subj creds too */
66946
66947 + gr_set_role_label(task, new->uid, new->gid);
66948 +
66949 /* dumpability changes */
66950 if (!uid_eq(old->euid, new->euid) ||
66951 !gid_eq(old->egid, new->egid) ||
66952 @@ -537,6 +549,101 @@ int commit_creds(struct cred *new)
66953 put_cred(old);
66954 return 0;
66955 }
66956 +#ifdef CONFIG_GRKERNSEC_SETXID
66957 +extern int set_user(struct cred *new);
66958 +
66959 +void gr_delayed_cred_worker(void)
66960 +{
66961 + const struct cred *new = current->delayed_cred;
66962 + struct cred *ncred;
66963 +
66964 + current->delayed_cred = NULL;
66965 +
66966 + if (current_uid() && new != NULL) {
66967 + // from doing get_cred on it when queueing this
66968 + put_cred(new);
66969 + return;
66970 + } else if (new == NULL)
66971 + return;
66972 +
66973 + ncred = prepare_creds();
66974 + if (!ncred)
66975 + goto die;
66976 + // uids
66977 + ncred->uid = new->uid;
66978 + ncred->euid = new->euid;
66979 + ncred->suid = new->suid;
66980 + ncred->fsuid = new->fsuid;
66981 + // gids
66982 + ncred->gid = new->gid;
66983 + ncred->egid = new->egid;
66984 + ncred->sgid = new->sgid;
66985 + ncred->fsgid = new->fsgid;
66986 + // groups
66987 + if (set_groups(ncred, new->group_info) < 0) {
66988 + abort_creds(ncred);
66989 + goto die;
66990 + }
66991 + // caps
66992 + ncred->securebits = new->securebits;
66993 + ncred->cap_inheritable = new->cap_inheritable;
66994 + ncred->cap_permitted = new->cap_permitted;
66995 + ncred->cap_effective = new->cap_effective;
66996 + ncred->cap_bset = new->cap_bset;
66997 +
66998 + if (set_user(ncred)) {
66999 + abort_creds(ncred);
67000 + goto die;
67001 + }
67002 +
67003 + // from doing get_cred on it when queueing this
67004 + put_cred(new);
67005 +
67006 + __commit_creds(ncred);
67007 + return;
67008 +die:
67009 + // from doing get_cred on it when queueing this
67010 + put_cred(new);
67011 + do_group_exit(SIGKILL);
67012 +}
67013 +#endif
67014 +
67015 +int commit_creds(struct cred *new)
67016 +{
67017 +#ifdef CONFIG_GRKERNSEC_SETXID
67018 + int ret;
67019 + int schedule_it = 0;
67020 + struct task_struct *t;
67021 +
67022 + /* we won't get called with tasklist_lock held for writing
67023 + and interrupts disabled as the cred struct in that case is
67024 + init_cred
67025 + */
67026 + if (grsec_enable_setxid && !current_is_single_threaded() &&
67027 + !current_uid() && new->uid) {
67028 + schedule_it = 1;
67029 + }
67030 + ret = __commit_creds(new);
67031 + if (schedule_it) {
67032 + rcu_read_lock();
67033 + read_lock(&tasklist_lock);
67034 + for (t = next_thread(current); t != current;
67035 + t = next_thread(t)) {
67036 + if (t->delayed_cred == NULL) {
67037 + t->delayed_cred = get_cred(new);
67038 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
67039 + set_tsk_need_resched(t);
67040 + }
67041 + }
67042 + read_unlock(&tasklist_lock);
67043 + rcu_read_unlock();
67044 + }
67045 + return ret;
67046 +#else
67047 + return __commit_creds(new);
67048 +#endif
67049 +}
67050 +
67051 EXPORT_SYMBOL(commit_creds);
67052
67053 /**
67054 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
67055 index 0557f24..1a00d9a 100644
67056 --- a/kernel/debug/debug_core.c
67057 +++ b/kernel/debug/debug_core.c
67058 @@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
67059 */
67060 static atomic_t masters_in_kgdb;
67061 static atomic_t slaves_in_kgdb;
67062 -static atomic_t kgdb_break_tasklet_var;
67063 +static atomic_unchecked_t kgdb_break_tasklet_var;
67064 atomic_t kgdb_setting_breakpoint;
67065
67066 struct task_struct *kgdb_usethread;
67067 @@ -132,7 +132,7 @@ int kgdb_single_step;
67068 static pid_t kgdb_sstep_pid;
67069
67070 /* to keep track of the CPU which is doing the single stepping*/
67071 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
67072 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
67073
67074 /*
67075 * If you are debugging a problem where roundup (the collection of
67076 @@ -540,7 +540,7 @@ return_normal:
67077 * kernel will only try for the value of sstep_tries before
67078 * giving up and continuing on.
67079 */
67080 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
67081 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
67082 (kgdb_info[cpu].task &&
67083 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
67084 atomic_set(&kgdb_active, -1);
67085 @@ -634,8 +634,8 @@ cpu_master_loop:
67086 }
67087
67088 kgdb_restore:
67089 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
67090 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
67091 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
67092 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
67093 if (kgdb_info[sstep_cpu].task)
67094 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
67095 else
67096 @@ -861,18 +861,18 @@ static void kgdb_unregister_callbacks(void)
67097 static void kgdb_tasklet_bpt(unsigned long ing)
67098 {
67099 kgdb_breakpoint();
67100 - atomic_set(&kgdb_break_tasklet_var, 0);
67101 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
67102 }
67103
67104 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
67105
67106 void kgdb_schedule_breakpoint(void)
67107 {
67108 - if (atomic_read(&kgdb_break_tasklet_var) ||
67109 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
67110 atomic_read(&kgdb_active) != -1 ||
67111 atomic_read(&kgdb_setting_breakpoint))
67112 return;
67113 - atomic_inc(&kgdb_break_tasklet_var);
67114 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
67115 tasklet_schedule(&kgdb_tasklet_breakpoint);
67116 }
67117 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
67118 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
67119 index 31df170..bc98840 100644
67120 --- a/kernel/debug/kdb/kdb_main.c
67121 +++ b/kernel/debug/kdb/kdb_main.c
67122 @@ -1971,7 +1971,7 @@ static int kdb_lsmod(int argc, const char **argv)
67123 list_for_each_entry(mod, kdb_modules, list) {
67124
67125 kdb_printf("%-20s%8u 0x%p ", mod->name,
67126 - mod->core_size, (void *)mod);
67127 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
67128 #ifdef CONFIG_MODULE_UNLOAD
67129 kdb_printf("%4ld ", module_refcount(mod));
67130 #endif
67131 @@ -1981,7 +1981,7 @@ static int kdb_lsmod(int argc, const char **argv)
67132 kdb_printf(" (Loading)");
67133 else
67134 kdb_printf(" (Live)");
67135 - kdb_printf(" 0x%p", mod->module_core);
67136 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
67137
67138 #ifdef CONFIG_MODULE_UNLOAD
67139 {
67140 diff --git a/kernel/events/core.c b/kernel/events/core.c
67141 index 7fee567..8affa2c 100644
67142 --- a/kernel/events/core.c
67143 +++ b/kernel/events/core.c
67144 @@ -181,7 +181,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
67145 return 0;
67146 }
67147
67148 -static atomic64_t perf_event_id;
67149 +static atomic64_unchecked_t perf_event_id;
67150
67151 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
67152 enum event_type_t event_type);
67153 @@ -2665,7 +2665,7 @@ static void __perf_event_read(void *info)
67154
67155 static inline u64 perf_event_count(struct perf_event *event)
67156 {
67157 - return local64_read(&event->count) + atomic64_read(&event->child_count);
67158 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
67159 }
67160
67161 static u64 perf_event_read(struct perf_event *event)
67162 @@ -2995,9 +2995,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
67163 mutex_lock(&event->child_mutex);
67164 total += perf_event_read(event);
67165 *enabled += event->total_time_enabled +
67166 - atomic64_read(&event->child_total_time_enabled);
67167 + atomic64_read_unchecked(&event->child_total_time_enabled);
67168 *running += event->total_time_running +
67169 - atomic64_read(&event->child_total_time_running);
67170 + atomic64_read_unchecked(&event->child_total_time_running);
67171
67172 list_for_each_entry(child, &event->child_list, child_list) {
67173 total += perf_event_read(child);
67174 @@ -3406,10 +3406,10 @@ void perf_event_update_userpage(struct perf_event *event)
67175 userpg->offset -= local64_read(&event->hw.prev_count);
67176
67177 userpg->time_enabled = enabled +
67178 - atomic64_read(&event->child_total_time_enabled);
67179 + atomic64_read_unchecked(&event->child_total_time_enabled);
67180
67181 userpg->time_running = running +
67182 - atomic64_read(&event->child_total_time_running);
67183 + atomic64_read_unchecked(&event->child_total_time_running);
67184
67185 arch_perf_update_userpage(userpg, now);
67186
67187 @@ -3842,11 +3842,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
67188 values[n++] = perf_event_count(event);
67189 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
67190 values[n++] = enabled +
67191 - atomic64_read(&event->child_total_time_enabled);
67192 + atomic64_read_unchecked(&event->child_total_time_enabled);
67193 }
67194 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
67195 values[n++] = running +
67196 - atomic64_read(&event->child_total_time_running);
67197 + atomic64_read_unchecked(&event->child_total_time_running);
67198 }
67199 if (read_format & PERF_FORMAT_ID)
67200 values[n++] = primary_event_id(event);
67201 @@ -4524,12 +4524,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
67202 * need to add enough zero bytes after the string to handle
67203 * the 64bit alignment we do later.
67204 */
67205 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
67206 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
67207 if (!buf) {
67208 name = strncpy(tmp, "//enomem", sizeof(tmp));
67209 goto got_name;
67210 }
67211 - name = d_path(&file->f_path, buf, PATH_MAX);
67212 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
67213 if (IS_ERR(name)) {
67214 name = strncpy(tmp, "//toolong", sizeof(tmp));
67215 goto got_name;
67216 @@ -5968,7 +5968,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
67217 event->parent = parent_event;
67218
67219 event->ns = get_pid_ns(current->nsproxy->pid_ns);
67220 - event->id = atomic64_inc_return(&perf_event_id);
67221 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
67222
67223 event->state = PERF_EVENT_STATE_INACTIVE;
67224
67225 @@ -6567,10 +6567,10 @@ static void sync_child_event(struct perf_event *child_event,
67226 /*
67227 * Add back the child's count to the parent's count:
67228 */
67229 - atomic64_add(child_val, &parent_event->child_count);
67230 - atomic64_add(child_event->total_time_enabled,
67231 + atomic64_add_unchecked(child_val, &parent_event->child_count);
67232 + atomic64_add_unchecked(child_event->total_time_enabled,
67233 &parent_event->child_total_time_enabled);
67234 - atomic64_add(child_event->total_time_running,
67235 + atomic64_add_unchecked(child_event->total_time_running,
67236 &parent_event->child_total_time_running);
67237
67238 /*
67239 diff --git a/kernel/exit.c b/kernel/exit.c
67240 index f65345f9..9c28dab 100644
67241 --- a/kernel/exit.c
67242 +++ b/kernel/exit.c
67243 @@ -59,6 +59,10 @@
67244 #include <asm/pgtable.h>
67245 #include <asm/mmu_context.h>
67246
67247 +#ifdef CONFIG_GRKERNSEC
67248 +extern rwlock_t grsec_exec_file_lock;
67249 +#endif
67250 +
67251 static void exit_mm(struct task_struct * tsk);
67252
67253 static void __unhash_process(struct task_struct *p, bool group_dead)
67254 @@ -182,6 +186,10 @@ void release_task(struct task_struct * p)
67255 struct task_struct *leader;
67256 int zap_leader;
67257 repeat:
67258 +#ifdef CONFIG_NET
67259 + gr_del_task_from_ip_table(p);
67260 +#endif
67261 +
67262 /* don't need to get the RCU readlock here - the process is dead and
67263 * can't be modifying its own credentials. But shut RCU-lockdep up */
67264 rcu_read_lock();
67265 @@ -394,7 +402,7 @@ int allow_signal(int sig)
67266 * know it'll be handled, so that they don't get converted to
67267 * SIGKILL or just silently dropped.
67268 */
67269 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
67270 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
67271 recalc_sigpending();
67272 spin_unlock_irq(&current->sighand->siglock);
67273 return 0;
67274 @@ -430,6 +438,17 @@ void daemonize(const char *name, ...)
67275 vsnprintf(current->comm, sizeof(current->comm), name, args);
67276 va_end(args);
67277
67278 +#ifdef CONFIG_GRKERNSEC
67279 + write_lock(&grsec_exec_file_lock);
67280 + if (current->exec_file) {
67281 + fput(current->exec_file);
67282 + current->exec_file = NULL;
67283 + }
67284 + write_unlock(&grsec_exec_file_lock);
67285 +#endif
67286 +
67287 + gr_set_kernel_label(current);
67288 +
67289 /*
67290 * If we were started as result of loading a module, close all of the
67291 * user space pages. We don't need them, and if we didn't close them
67292 @@ -907,6 +926,8 @@ void do_exit(long code)
67293 struct task_struct *tsk = current;
67294 int group_dead;
67295
67296 + set_fs(USER_DS);
67297 +
67298 profile_task_exit(tsk);
67299
67300 WARN_ON(blk_needs_flush_plug(tsk));
67301 @@ -923,7 +944,6 @@ void do_exit(long code)
67302 * mm_release()->clear_child_tid() from writing to a user-controlled
67303 * kernel address.
67304 */
67305 - set_fs(USER_DS);
67306
67307 ptrace_event(PTRACE_EVENT_EXIT, code);
67308
67309 @@ -982,6 +1002,9 @@ void do_exit(long code)
67310 tsk->exit_code = code;
67311 taskstats_exit(tsk, group_dead);
67312
67313 + gr_acl_handle_psacct(tsk, code);
67314 + gr_acl_handle_exit();
67315 +
67316 exit_mm(tsk);
67317
67318 if (group_dead)
67319 @@ -1099,7 +1122,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
67320 * Take down every thread in the group. This is called by fatal signals
67321 * as well as by sys_exit_group (below).
67322 */
67323 -void
67324 +__noreturn void
67325 do_group_exit(int exit_code)
67326 {
67327 struct signal_struct *sig = current->signal;
67328 diff --git a/kernel/fork.c b/kernel/fork.c
67329 index 2c8857e..288c9c7 100644
67330 --- a/kernel/fork.c
67331 +++ b/kernel/fork.c
67332 @@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
67333 *stackend = STACK_END_MAGIC; /* for overflow detection */
67334
67335 #ifdef CONFIG_CC_STACKPROTECTOR
67336 - tsk->stack_canary = get_random_int();
67337 + tsk->stack_canary = pax_get_random_long();
67338 #endif
67339
67340 /*
67341 @@ -343,13 +343,78 @@ free_tsk:
67342 }
67343
67344 #ifdef CONFIG_MMU
67345 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
67346 +{
67347 + struct vm_area_struct *tmp;
67348 + unsigned long charge;
67349 + struct mempolicy *pol;
67350 + struct file *file;
67351 +
67352 + charge = 0;
67353 + if (mpnt->vm_flags & VM_ACCOUNT) {
67354 + unsigned long len = vma_pages(mpnt);
67355 +
67356 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
67357 + goto fail_nomem;
67358 + charge = len;
67359 + }
67360 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67361 + if (!tmp)
67362 + goto fail_nomem;
67363 + *tmp = *mpnt;
67364 + tmp->vm_mm = mm;
67365 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
67366 + pol = mpol_dup(vma_policy(mpnt));
67367 + if (IS_ERR(pol))
67368 + goto fail_nomem_policy;
67369 + vma_set_policy(tmp, pol);
67370 + if (anon_vma_fork(tmp, mpnt))
67371 + goto fail_nomem_anon_vma_fork;
67372 + tmp->vm_flags &= ~VM_LOCKED;
67373 + tmp->vm_next = tmp->vm_prev = NULL;
67374 + tmp->vm_mirror = NULL;
67375 + file = tmp->vm_file;
67376 + if (file) {
67377 + struct inode *inode = file->f_path.dentry->d_inode;
67378 + struct address_space *mapping = file->f_mapping;
67379 +
67380 + get_file(file);
67381 + if (tmp->vm_flags & VM_DENYWRITE)
67382 + atomic_dec(&inode->i_writecount);
67383 + mutex_lock(&mapping->i_mmap_mutex);
67384 + if (tmp->vm_flags & VM_SHARED)
67385 + mapping->i_mmap_writable++;
67386 + flush_dcache_mmap_lock(mapping);
67387 + /* insert tmp into the share list, just after mpnt */
67388 + vma_prio_tree_add(tmp, mpnt);
67389 + flush_dcache_mmap_unlock(mapping);
67390 + mutex_unlock(&mapping->i_mmap_mutex);
67391 + }
67392 +
67393 + /*
67394 + * Clear hugetlb-related page reserves for children. This only
67395 + * affects MAP_PRIVATE mappings. Faults generated by the child
67396 + * are not guaranteed to succeed, even if read-only
67397 + */
67398 + if (is_vm_hugetlb_page(tmp))
67399 + reset_vma_resv_huge_pages(tmp);
67400 +
67401 + return tmp;
67402 +
67403 +fail_nomem_anon_vma_fork:
67404 + mpol_put(pol);
67405 +fail_nomem_policy:
67406 + kmem_cache_free(vm_area_cachep, tmp);
67407 +fail_nomem:
67408 + vm_unacct_memory(charge);
67409 + return NULL;
67410 +}
67411 +
67412 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67413 {
67414 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
67415 struct rb_node **rb_link, *rb_parent;
67416 int retval;
67417 - unsigned long charge;
67418 - struct mempolicy *pol;
67419
67420 down_write(&oldmm->mmap_sem);
67421 flush_cache_dup_mm(oldmm);
67422 @@ -361,8 +426,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67423 mm->locked_vm = 0;
67424 mm->mmap = NULL;
67425 mm->mmap_cache = NULL;
67426 - mm->free_area_cache = oldmm->mmap_base;
67427 - mm->cached_hole_size = ~0UL;
67428 + mm->free_area_cache = oldmm->free_area_cache;
67429 + mm->cached_hole_size = oldmm->cached_hole_size;
67430 mm->map_count = 0;
67431 cpumask_clear(mm_cpumask(mm));
67432 mm->mm_rb = RB_ROOT;
67433 @@ -378,52 +443,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67434
67435 prev = NULL;
67436 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
67437 - struct file *file;
67438 -
67439 if (mpnt->vm_flags & VM_DONTCOPY) {
67440 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
67441 -vma_pages(mpnt));
67442 continue;
67443 }
67444 - charge = 0;
67445 - if (mpnt->vm_flags & VM_ACCOUNT) {
67446 - unsigned long len = vma_pages(mpnt);
67447 -
67448 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
67449 - goto fail_nomem;
67450 - charge = len;
67451 - }
67452 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67453 - if (!tmp)
67454 - goto fail_nomem;
67455 - *tmp = *mpnt;
67456 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
67457 - pol = mpol_dup(vma_policy(mpnt));
67458 - retval = PTR_ERR(pol);
67459 - if (IS_ERR(pol))
67460 - goto fail_nomem_policy;
67461 - vma_set_policy(tmp, pol);
67462 - tmp->vm_mm = mm;
67463 - if (anon_vma_fork(tmp, mpnt))
67464 - goto fail_nomem_anon_vma_fork;
67465 - tmp->vm_flags &= ~VM_LOCKED;
67466 - tmp->vm_next = tmp->vm_prev = NULL;
67467 - file = tmp->vm_file;
67468 - if (file) {
67469 - struct inode *inode = file->f_path.dentry->d_inode;
67470 - struct address_space *mapping = file->f_mapping;
67471 -
67472 - get_file(file);
67473 - if (tmp->vm_flags & VM_DENYWRITE)
67474 - atomic_dec(&inode->i_writecount);
67475 - mutex_lock(&mapping->i_mmap_mutex);
67476 - if (tmp->vm_flags & VM_SHARED)
67477 - mapping->i_mmap_writable++;
67478 - flush_dcache_mmap_lock(mapping);
67479 - /* insert tmp into the share list, just after mpnt */
67480 - vma_prio_tree_add(tmp, mpnt);
67481 - flush_dcache_mmap_unlock(mapping);
67482 - mutex_unlock(&mapping->i_mmap_mutex);
67483 + tmp = dup_vma(mm, oldmm, mpnt);
67484 + if (!tmp) {
67485 + retval = -ENOMEM;
67486 + goto out;
67487 }
67488
67489 /*
67490 @@ -455,9 +483,34 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67491 if (retval)
67492 goto out;
67493
67494 - if (file)
67495 + if (tmp->vm_file)
67496 uprobe_mmap(tmp);
67497 }
67498 +
67499 +#ifdef CONFIG_PAX_SEGMEXEC
67500 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
67501 + struct vm_area_struct *mpnt_m;
67502 +
67503 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
67504 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
67505 +
67506 + if (!mpnt->vm_mirror)
67507 + continue;
67508 +
67509 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
67510 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
67511 + mpnt->vm_mirror = mpnt_m;
67512 + } else {
67513 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
67514 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
67515 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
67516 + mpnt->vm_mirror->vm_mirror = mpnt;
67517 + }
67518 + }
67519 + BUG_ON(mpnt_m);
67520 + }
67521 +#endif
67522 +
67523 /* a new mm has just been created */
67524 arch_dup_mmap(oldmm, mm);
67525 retval = 0;
67526 @@ -466,14 +519,6 @@ out:
67527 flush_tlb_mm(oldmm);
67528 up_write(&oldmm->mmap_sem);
67529 return retval;
67530 -fail_nomem_anon_vma_fork:
67531 - mpol_put(pol);
67532 -fail_nomem_policy:
67533 - kmem_cache_free(vm_area_cachep, tmp);
67534 -fail_nomem:
67535 - retval = -ENOMEM;
67536 - vm_unacct_memory(charge);
67537 - goto out;
67538 }
67539
67540 static inline int mm_alloc_pgd(struct mm_struct *mm)
67541 @@ -710,8 +755,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
67542 return ERR_PTR(err);
67543
67544 mm = get_task_mm(task);
67545 - if (mm && mm != current->mm &&
67546 - !ptrace_may_access(task, mode)) {
67547 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
67548 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
67549 mmput(mm);
67550 mm = ERR_PTR(-EACCES);
67551 }
67552 @@ -932,13 +977,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
67553 spin_unlock(&fs->lock);
67554 return -EAGAIN;
67555 }
67556 - fs->users++;
67557 + atomic_inc(&fs->users);
67558 spin_unlock(&fs->lock);
67559 return 0;
67560 }
67561 tsk->fs = copy_fs_struct(fs);
67562 if (!tsk->fs)
67563 return -ENOMEM;
67564 + /* Carry through gr_chroot_dentry and is_chrooted instead
67565 + of recomputing it here. Already copied when the task struct
67566 + is duplicated. This allows pivot_root to not be treated as
67567 + a chroot
67568 + */
67569 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
67570 +
67571 return 0;
67572 }
67573
67574 @@ -1205,6 +1257,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
67575 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
67576 #endif
67577 retval = -EAGAIN;
67578 +
67579 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
67580 +
67581 if (atomic_read(&p->real_cred->user->processes) >=
67582 task_rlimit(p, RLIMIT_NPROC)) {
67583 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
67584 @@ -1427,6 +1482,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
67585 /* Need tasklist lock for parent etc handling! */
67586 write_lock_irq(&tasklist_lock);
67587
67588 + /* synchronizes with gr_set_acls() */
67589 + gr_copy_label(p);
67590 +
67591 /* CLONE_PARENT re-uses the old parent */
67592 if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) {
67593 p->real_parent = current->real_parent;
67594 @@ -1537,6 +1595,8 @@ bad_fork_cleanup_count:
67595 bad_fork_free:
67596 free_task(p);
67597 fork_out:
67598 + gr_log_forkfail(retval);
67599 +
67600 return ERR_PTR(retval);
67601 }
67602
67603 @@ -1637,6 +1697,8 @@ long do_fork(unsigned long clone_flags,
67604 if (clone_flags & CLONE_PARENT_SETTID)
67605 put_user(nr, parent_tidptr);
67606
67607 + gr_handle_brute_check();
67608 +
67609 if (clone_flags & CLONE_VFORK) {
67610 p->vfork_done = &vfork;
67611 init_completion(&vfork);
67612 @@ -1735,7 +1797,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
67613 return 0;
67614
67615 /* don't need lock here; in the worst case we'll do useless copy */
67616 - if (fs->users == 1)
67617 + if (atomic_read(&fs->users) == 1)
67618 return 0;
67619
67620 *new_fsp = copy_fs_struct(fs);
67621 @@ -1824,7 +1886,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
67622 fs = current->fs;
67623 spin_lock(&fs->lock);
67624 current->fs = new_fs;
67625 - if (--fs->users)
67626 + gr_set_chroot_entries(current, &current->fs->root);
67627 + if (atomic_dec_return(&fs->users))
67628 new_fs = NULL;
67629 else
67630 new_fs = fs;
67631 diff --git a/kernel/futex.c b/kernel/futex.c
67632 index 3717e7b..473c750 100644
67633 --- a/kernel/futex.c
67634 +++ b/kernel/futex.c
67635 @@ -54,6 +54,7 @@
67636 #include <linux/mount.h>
67637 #include <linux/pagemap.h>
67638 #include <linux/syscalls.h>
67639 +#include <linux/ptrace.h>
67640 #include <linux/signal.h>
67641 #include <linux/export.h>
67642 #include <linux/magic.h>
67643 @@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
67644 struct page *page, *page_head;
67645 int err, ro = 0;
67646
67647 +#ifdef CONFIG_PAX_SEGMEXEC
67648 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
67649 + return -EFAULT;
67650 +#endif
67651 +
67652 /*
67653 * The futex address must be "naturally" aligned.
67654 */
67655 @@ -2714,6 +2720,7 @@ static int __init futex_init(void)
67656 {
67657 u32 curval;
67658 int i;
67659 + mm_segment_t oldfs;
67660
67661 /*
67662 * This will fail and we want it. Some arch implementations do
67663 @@ -2725,8 +2732,11 @@ static int __init futex_init(void)
67664 * implementation, the non-functional ones will return
67665 * -ENOSYS.
67666 */
67667 + oldfs = get_fs();
67668 + set_fs(USER_DS);
67669 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
67670 futex_cmpxchg_enabled = 1;
67671 + set_fs(oldfs);
67672
67673 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
67674 plist_head_init(&futex_queues[i].chain);
67675 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
67676 index 9b22d03..6295b62 100644
67677 --- a/kernel/gcov/base.c
67678 +++ b/kernel/gcov/base.c
67679 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
67680 }
67681
67682 #ifdef CONFIG_MODULES
67683 -static inline int within(void *addr, void *start, unsigned long size)
67684 -{
67685 - return ((addr >= start) && (addr < start + size));
67686 -}
67687 -
67688 /* Update list and generate events when modules are unloaded. */
67689 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67690 void *data)
67691 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67692 prev = NULL;
67693 /* Remove entries located in module from linked list. */
67694 for (info = gcov_info_head; info; info = info->next) {
67695 - if (within(info, mod->module_core, mod->core_size)) {
67696 + if (within_module_core_rw((unsigned long)info, mod)) {
67697 if (prev)
67698 prev->next = info->next;
67699 else
67700 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
67701 index 6db7a5e..25b6648 100644
67702 --- a/kernel/hrtimer.c
67703 +++ b/kernel/hrtimer.c
67704 @@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
67705 local_irq_restore(flags);
67706 }
67707
67708 -static void run_hrtimer_softirq(struct softirq_action *h)
67709 +static void run_hrtimer_softirq(void)
67710 {
67711 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
67712
67713 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
67714 index 4304919..408c4c0 100644
67715 --- a/kernel/jump_label.c
67716 +++ b/kernel/jump_label.c
67717 @@ -13,6 +13,7 @@
67718 #include <linux/sort.h>
67719 #include <linux/err.h>
67720 #include <linux/static_key.h>
67721 +#include <linux/mm.h>
67722
67723 #ifdef HAVE_JUMP_LABEL
67724
67725 @@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
67726
67727 size = (((unsigned long)stop - (unsigned long)start)
67728 / sizeof(struct jump_entry));
67729 + pax_open_kernel();
67730 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
67731 + pax_close_kernel();
67732 }
67733
67734 static void jump_label_update(struct static_key *key, int enable);
67735 @@ -356,10 +359,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
67736 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
67737 struct jump_entry *iter;
67738
67739 + pax_open_kernel();
67740 for (iter = iter_start; iter < iter_stop; iter++) {
67741 if (within_module_init(iter->code, mod))
67742 iter->code = 0;
67743 }
67744 + pax_close_kernel();
67745 }
67746
67747 static int
67748 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
67749 index 2169fee..45c017a 100644
67750 --- a/kernel/kallsyms.c
67751 +++ b/kernel/kallsyms.c
67752 @@ -11,6 +11,9 @@
67753 * Changed the compression method from stem compression to "table lookup"
67754 * compression (see scripts/kallsyms.c for a more complete description)
67755 */
67756 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67757 +#define __INCLUDED_BY_HIDESYM 1
67758 +#endif
67759 #include <linux/kallsyms.h>
67760 #include <linux/module.h>
67761 #include <linux/init.h>
67762 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
67763
67764 static inline int is_kernel_inittext(unsigned long addr)
67765 {
67766 + if (system_state != SYSTEM_BOOTING)
67767 + return 0;
67768 +
67769 if (addr >= (unsigned long)_sinittext
67770 && addr <= (unsigned long)_einittext)
67771 return 1;
67772 return 0;
67773 }
67774
67775 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67776 +#ifdef CONFIG_MODULES
67777 +static inline int is_module_text(unsigned long addr)
67778 +{
67779 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
67780 + return 1;
67781 +
67782 + addr = ktla_ktva(addr);
67783 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
67784 +}
67785 +#else
67786 +static inline int is_module_text(unsigned long addr)
67787 +{
67788 + return 0;
67789 +}
67790 +#endif
67791 +#endif
67792 +
67793 static inline int is_kernel_text(unsigned long addr)
67794 {
67795 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
67796 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
67797
67798 static inline int is_kernel(unsigned long addr)
67799 {
67800 +
67801 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67802 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
67803 + return 1;
67804 +
67805 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
67806 +#else
67807 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
67808 +#endif
67809 +
67810 return 1;
67811 return in_gate_area_no_mm(addr);
67812 }
67813
67814 static int is_ksym_addr(unsigned long addr)
67815 {
67816 +
67817 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67818 + if (is_module_text(addr))
67819 + return 0;
67820 +#endif
67821 +
67822 if (all_var)
67823 return is_kernel(addr);
67824
67825 @@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
67826
67827 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
67828 {
67829 - iter->name[0] = '\0';
67830 iter->nameoff = get_symbol_offset(new_pos);
67831 iter->pos = new_pos;
67832 }
67833 @@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
67834 {
67835 struct kallsym_iter *iter = m->private;
67836
67837 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67838 + if (current_uid())
67839 + return 0;
67840 +#endif
67841 +
67842 /* Some debugging symbols have no name. Ignore them. */
67843 if (!iter->name[0])
67844 return 0;
67845 @@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
67846 */
67847 type = iter->exported ? toupper(iter->type) :
67848 tolower(iter->type);
67849 +
67850 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
67851 type, iter->name, iter->module_name);
67852 } else
67853 @@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
67854 struct kallsym_iter *iter;
67855 int ret;
67856
67857 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
67858 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
67859 if (!iter)
67860 return -ENOMEM;
67861 reset_iter(iter, 0);
67862 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
67863 index 30b7b22..c726387 100644
67864 --- a/kernel/kcmp.c
67865 +++ b/kernel/kcmp.c
67866 @@ -98,6 +98,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
67867 struct task_struct *task1, *task2;
67868 int ret;
67869
67870 +#ifdef CONFIG_GRKERNSEC
67871 + return -ENOSYS;
67872 +#endif
67873 +
67874 rcu_read_lock();
67875
67876 /*
67877 diff --git a/kernel/kexec.c b/kernel/kexec.c
67878 index 0668d58..591b6fc 100644
67879 --- a/kernel/kexec.c
67880 +++ b/kernel/kexec.c
67881 @@ -1046,7 +1046,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
67882 unsigned long flags)
67883 {
67884 struct compat_kexec_segment in;
67885 - struct kexec_segment out, __user *ksegments;
67886 + struct kexec_segment out;
67887 + struct kexec_segment __user *ksegments;
67888 unsigned long i, result;
67889
67890 /* Don't allow clients that don't understand the native
67891 diff --git a/kernel/kmod.c b/kernel/kmod.c
67892 index 6f99aea..eb6e3a0 100644
67893 --- a/kernel/kmod.c
67894 +++ b/kernel/kmod.c
67895 @@ -73,7 +73,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
67896 kfree(info->argv);
67897 }
67898
67899 -static int call_modprobe(char *module_name, int wait)
67900 +static int call_modprobe(char *module_name, char *module_param, int wait)
67901 {
67902 static char *envp[] = {
67903 "HOME=/",
67904 @@ -82,7 +82,7 @@ static int call_modprobe(char *module_name, int wait)
67905 NULL
67906 };
67907
67908 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
67909 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
67910 if (!argv)
67911 goto out;
67912
67913 @@ -94,7 +94,8 @@ static int call_modprobe(char *module_name, int wait)
67914 argv[1] = "-q";
67915 argv[2] = "--";
67916 argv[3] = module_name; /* check free_modprobe_argv() */
67917 - argv[4] = NULL;
67918 + argv[4] = module_param;
67919 + argv[5] = NULL;
67920
67921 return call_usermodehelper_fns(modprobe_path, argv, envp,
67922 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
67923 @@ -119,9 +120,8 @@ out:
67924 * If module auto-loading support is disabled then this function
67925 * becomes a no-operation.
67926 */
67927 -int __request_module(bool wait, const char *fmt, ...)
67928 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
67929 {
67930 - va_list args;
67931 char module_name[MODULE_NAME_LEN];
67932 unsigned int max_modprobes;
67933 int ret;
67934 @@ -129,9 +129,7 @@ int __request_module(bool wait, const char *fmt, ...)
67935 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
67936 static int kmod_loop_msg;
67937
67938 - va_start(args, fmt);
67939 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
67940 - va_end(args);
67941 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
67942 if (ret >= MODULE_NAME_LEN)
67943 return -ENAMETOOLONG;
67944
67945 @@ -139,6 +137,20 @@ int __request_module(bool wait, const char *fmt, ...)
67946 if (ret)
67947 return ret;
67948
67949 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67950 + if (!current_uid()) {
67951 + /* hack to workaround consolekit/udisks stupidity */
67952 + read_lock(&tasklist_lock);
67953 + if (!strcmp(current->comm, "mount") &&
67954 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
67955 + read_unlock(&tasklist_lock);
67956 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
67957 + return -EPERM;
67958 + }
67959 + read_unlock(&tasklist_lock);
67960 + }
67961 +#endif
67962 +
67963 /* If modprobe needs a service that is in a module, we get a recursive
67964 * loop. Limit the number of running kmod threads to max_threads/2 or
67965 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
67966 @@ -167,11 +179,52 @@ int __request_module(bool wait, const char *fmt, ...)
67967
67968 trace_module_request(module_name, wait, _RET_IP_);
67969
67970 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
67971 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
67972
67973 atomic_dec(&kmod_concurrent);
67974 return ret;
67975 }
67976 +
67977 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
67978 +{
67979 + va_list args;
67980 + int ret;
67981 +
67982 + va_start(args, fmt);
67983 + ret = ____request_module(wait, module_param, fmt, args);
67984 + va_end(args);
67985 +
67986 + return ret;
67987 +}
67988 +
67989 +int __request_module(bool wait, const char *fmt, ...)
67990 +{
67991 + va_list args;
67992 + int ret;
67993 +
67994 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67995 + if (current_uid()) {
67996 + char module_param[MODULE_NAME_LEN];
67997 +
67998 + memset(module_param, 0, sizeof(module_param));
67999 +
68000 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
68001 +
68002 + va_start(args, fmt);
68003 + ret = ____request_module(wait, module_param, fmt, args);
68004 + va_end(args);
68005 +
68006 + return ret;
68007 + }
68008 +#endif
68009 +
68010 + va_start(args, fmt);
68011 + ret = ____request_module(wait, NULL, fmt, args);
68012 + va_end(args);
68013 +
68014 + return ret;
68015 +}
68016 +
68017 EXPORT_SYMBOL(__request_module);
68018 #endif /* CONFIG_MODULES */
68019
68020 @@ -280,7 +333,7 @@ static int wait_for_helper(void *data)
68021 *
68022 * Thus the __user pointer cast is valid here.
68023 */
68024 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
68025 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
68026
68027 /*
68028 * If ret is 0, either ____call_usermodehelper failed and the
68029 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
68030 index c62b854..6fc810d 100644
68031 --- a/kernel/kprobes.c
68032 +++ b/kernel/kprobes.c
68033 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
68034 * kernel image and loaded module images reside. This is required
68035 * so x86_64 can correctly handle the %rip-relative fixups.
68036 */
68037 - kip->insns = module_alloc(PAGE_SIZE);
68038 + kip->insns = module_alloc_exec(PAGE_SIZE);
68039 if (!kip->insns) {
68040 kfree(kip);
68041 return NULL;
68042 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
68043 */
68044 if (!list_is_singular(&kip->list)) {
68045 list_del(&kip->list);
68046 - module_free(NULL, kip->insns);
68047 + module_free_exec(NULL, kip->insns);
68048 kfree(kip);
68049 }
68050 return 1;
68051 @@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
68052 {
68053 int i, err = 0;
68054 unsigned long offset = 0, size = 0;
68055 - char *modname, namebuf[128];
68056 + char *modname, namebuf[KSYM_NAME_LEN];
68057 const char *symbol_name;
68058 void *addr;
68059 struct kprobe_blackpoint *kb;
68060 @@ -2040,11 +2040,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
68061 kprobe_type = "k";
68062
68063 if (sym)
68064 - seq_printf(pi, "%p %s %s+0x%x %s ",
68065 + seq_printf(pi, "%pK %s %s+0x%x %s ",
68066 p->addr, kprobe_type, sym, offset,
68067 (modname ? modname : " "));
68068 else
68069 - seq_printf(pi, "%p %s %p ",
68070 + seq_printf(pi, "%pK %s %pK ",
68071 p->addr, kprobe_type, p->addr);
68072
68073 if (!pp)
68074 @@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
68075 const char *sym = NULL;
68076 unsigned int i = *(loff_t *) v;
68077 unsigned long offset = 0;
68078 - char *modname, namebuf[128];
68079 + char *modname, namebuf[KSYM_NAME_LEN];
68080
68081 head = &kprobe_table[i];
68082 preempt_disable();
68083 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
68084 index 4e316e1..5501eef 100644
68085 --- a/kernel/ksysfs.c
68086 +++ b/kernel/ksysfs.c
68087 @@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
68088 {
68089 if (count+1 > UEVENT_HELPER_PATH_LEN)
68090 return -ENOENT;
68091 + if (!capable(CAP_SYS_ADMIN))
68092 + return -EPERM;
68093 memcpy(uevent_helper, buf, count);
68094 uevent_helper[count] = '\0';
68095 if (count && uevent_helper[count-1] == '\n')
68096 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
68097 index ea9ee45..67ebc8f 100644
68098 --- a/kernel/lockdep.c
68099 +++ b/kernel/lockdep.c
68100 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
68101 end = (unsigned long) &_end,
68102 addr = (unsigned long) obj;
68103
68104 +#ifdef CONFIG_PAX_KERNEXEC
68105 + start = ktla_ktva(start);
68106 +#endif
68107 +
68108 /*
68109 * static variable?
68110 */
68111 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
68112 if (!static_obj(lock->key)) {
68113 debug_locks_off();
68114 printk("INFO: trying to register non-static key.\n");
68115 + printk("lock:%pS key:%pS.\n", lock, lock->key);
68116 printk("the code is fine but needs lockdep annotation.\n");
68117 printk("turning off the locking correctness validator.\n");
68118 dump_stack();
68119 @@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
68120 if (!class)
68121 return 0;
68122 }
68123 - atomic_inc((atomic_t *)&class->ops);
68124 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
68125 if (very_verbose(class)) {
68126 printk("\nacquire class [%p] %s", class->key, class->name);
68127 if (class->name_version > 1)
68128 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
68129 index 91c32a0..7b88d63 100644
68130 --- a/kernel/lockdep_proc.c
68131 +++ b/kernel/lockdep_proc.c
68132 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
68133
68134 static void print_name(struct seq_file *m, struct lock_class *class)
68135 {
68136 - char str[128];
68137 + char str[KSYM_NAME_LEN];
68138 const char *name = class->name;
68139
68140 if (!name) {
68141 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
68142 return 0;
68143 }
68144
68145 - seq_printf(m, "%p", class->key);
68146 + seq_printf(m, "%pK", class->key);
68147 #ifdef CONFIG_DEBUG_LOCKDEP
68148 seq_printf(m, " OPS:%8ld", class->ops);
68149 #endif
68150 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
68151
68152 list_for_each_entry(entry, &class->locks_after, entry) {
68153 if (entry->distance == 1) {
68154 - seq_printf(m, " -> [%p] ", entry->class->key);
68155 + seq_printf(m, " -> [%pK] ", entry->class->key);
68156 print_name(m, entry->class);
68157 seq_puts(m, "\n");
68158 }
68159 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
68160 if (!class->key)
68161 continue;
68162
68163 - seq_printf(m, "[%p] ", class->key);
68164 + seq_printf(m, "[%pK] ", class->key);
68165 print_name(m, class);
68166 seq_puts(m, "\n");
68167 }
68168 @@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
68169 if (!i)
68170 seq_line(m, '-', 40-namelen, namelen);
68171
68172 - snprintf(ip, sizeof(ip), "[<%p>]",
68173 + snprintf(ip, sizeof(ip), "[<%pK>]",
68174 (void *)class->contention_point[i]);
68175 seq_printf(m, "%40s %14lu %29s %pS\n",
68176 name, stats->contention_point[i],
68177 @@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
68178 if (!i)
68179 seq_line(m, '-', 40-namelen, namelen);
68180
68181 - snprintf(ip, sizeof(ip), "[<%p>]",
68182 + snprintf(ip, sizeof(ip), "[<%pK>]",
68183 (void *)class->contending_point[i]);
68184 seq_printf(m, "%40s %14lu %29s %pS\n",
68185 name, stats->contending_point[i],
68186 diff --git a/kernel/module.c b/kernel/module.c
68187 index 9ad9ee9..de7a157 100644
68188 --- a/kernel/module.c
68189 +++ b/kernel/module.c
68190 @@ -58,6 +58,7 @@
68191 #include <linux/jump_label.h>
68192 #include <linux/pfn.h>
68193 #include <linux/bsearch.h>
68194 +#include <linux/grsecurity.h>
68195
68196 #define CREATE_TRACE_POINTS
68197 #include <trace/events/module.h>
68198 @@ -114,7 +115,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
68199
68200 /* Bounds of module allocation, for speeding __module_address.
68201 * Protected by module_mutex. */
68202 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
68203 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
68204 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
68205
68206 int register_module_notifier(struct notifier_block * nb)
68207 {
68208 @@ -278,7 +280,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
68209 return true;
68210
68211 list_for_each_entry_rcu(mod, &modules, list) {
68212 - struct symsearch arr[] = {
68213 + struct symsearch modarr[] = {
68214 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
68215 NOT_GPL_ONLY, false },
68216 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
68217 @@ -300,7 +302,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
68218 #endif
68219 };
68220
68221 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
68222 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
68223 return true;
68224 }
68225 return false;
68226 @@ -432,7 +434,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
68227 static int percpu_modalloc(struct module *mod,
68228 unsigned long size, unsigned long align)
68229 {
68230 - if (align > PAGE_SIZE) {
68231 + if (align-1 >= PAGE_SIZE) {
68232 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
68233 mod->name, align, PAGE_SIZE);
68234 align = PAGE_SIZE;
68235 @@ -1032,7 +1034,7 @@ struct module_attribute module_uevent =
68236 static ssize_t show_coresize(struct module_attribute *mattr,
68237 struct module_kobject *mk, char *buffer)
68238 {
68239 - return sprintf(buffer, "%u\n", mk->mod->core_size);
68240 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
68241 }
68242
68243 static struct module_attribute modinfo_coresize =
68244 @@ -1041,7 +1043,7 @@ static struct module_attribute modinfo_coresize =
68245 static ssize_t show_initsize(struct module_attribute *mattr,
68246 struct module_kobject *mk, char *buffer)
68247 {
68248 - return sprintf(buffer, "%u\n", mk->mod->init_size);
68249 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
68250 }
68251
68252 static struct module_attribute modinfo_initsize =
68253 @@ -1255,7 +1257,7 @@ resolve_symbol_wait(struct module *mod,
68254 */
68255 #ifdef CONFIG_SYSFS
68256
68257 -#ifdef CONFIG_KALLSYMS
68258 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
68259 static inline bool sect_empty(const Elf_Shdr *sect)
68260 {
68261 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
68262 @@ -1721,21 +1723,21 @@ static void set_section_ro_nx(void *base,
68263
68264 static void unset_module_core_ro_nx(struct module *mod)
68265 {
68266 - set_page_attributes(mod->module_core + mod->core_text_size,
68267 - mod->module_core + mod->core_size,
68268 + set_page_attributes(mod->module_core_rw,
68269 + mod->module_core_rw + mod->core_size_rw,
68270 set_memory_x);
68271 - set_page_attributes(mod->module_core,
68272 - mod->module_core + mod->core_ro_size,
68273 + set_page_attributes(mod->module_core_rx,
68274 + mod->module_core_rx + mod->core_size_rx,
68275 set_memory_rw);
68276 }
68277
68278 static void unset_module_init_ro_nx(struct module *mod)
68279 {
68280 - set_page_attributes(mod->module_init + mod->init_text_size,
68281 - mod->module_init + mod->init_size,
68282 + set_page_attributes(mod->module_init_rw,
68283 + mod->module_init_rw + mod->init_size_rw,
68284 set_memory_x);
68285 - set_page_attributes(mod->module_init,
68286 - mod->module_init + mod->init_ro_size,
68287 + set_page_attributes(mod->module_init_rx,
68288 + mod->module_init_rx + mod->init_size_rx,
68289 set_memory_rw);
68290 }
68291
68292 @@ -1746,14 +1748,14 @@ void set_all_modules_text_rw(void)
68293
68294 mutex_lock(&module_mutex);
68295 list_for_each_entry_rcu(mod, &modules, list) {
68296 - if ((mod->module_core) && (mod->core_text_size)) {
68297 - set_page_attributes(mod->module_core,
68298 - mod->module_core + mod->core_text_size,
68299 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
68300 + set_page_attributes(mod->module_core_rx,
68301 + mod->module_core_rx + mod->core_size_rx,
68302 set_memory_rw);
68303 }
68304 - if ((mod->module_init) && (mod->init_text_size)) {
68305 - set_page_attributes(mod->module_init,
68306 - mod->module_init + mod->init_text_size,
68307 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
68308 + set_page_attributes(mod->module_init_rx,
68309 + mod->module_init_rx + mod->init_size_rx,
68310 set_memory_rw);
68311 }
68312 }
68313 @@ -1767,14 +1769,14 @@ void set_all_modules_text_ro(void)
68314
68315 mutex_lock(&module_mutex);
68316 list_for_each_entry_rcu(mod, &modules, list) {
68317 - if ((mod->module_core) && (mod->core_text_size)) {
68318 - set_page_attributes(mod->module_core,
68319 - mod->module_core + mod->core_text_size,
68320 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
68321 + set_page_attributes(mod->module_core_rx,
68322 + mod->module_core_rx + mod->core_size_rx,
68323 set_memory_ro);
68324 }
68325 - if ((mod->module_init) && (mod->init_text_size)) {
68326 - set_page_attributes(mod->module_init,
68327 - mod->module_init + mod->init_text_size,
68328 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
68329 + set_page_attributes(mod->module_init_rx,
68330 + mod->module_init_rx + mod->init_size_rx,
68331 set_memory_ro);
68332 }
68333 }
68334 @@ -1820,16 +1822,19 @@ static void free_module(struct module *mod)
68335
68336 /* This may be NULL, but that's OK */
68337 unset_module_init_ro_nx(mod);
68338 - module_free(mod, mod->module_init);
68339 + module_free(mod, mod->module_init_rw);
68340 + module_free_exec(mod, mod->module_init_rx);
68341 kfree(mod->args);
68342 percpu_modfree(mod);
68343
68344 /* Free lock-classes: */
68345 - lockdep_free_key_range(mod->module_core, mod->core_size);
68346 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
68347 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
68348
68349 /* Finally, free the core (containing the module structure) */
68350 unset_module_core_ro_nx(mod);
68351 - module_free(mod, mod->module_core);
68352 + module_free_exec(mod, mod->module_core_rx);
68353 + module_free(mod, mod->module_core_rw);
68354
68355 #ifdef CONFIG_MPU
68356 update_protections(current->mm);
68357 @@ -1899,9 +1904,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68358 int ret = 0;
68359 const struct kernel_symbol *ksym;
68360
68361 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68362 + int is_fs_load = 0;
68363 + int register_filesystem_found = 0;
68364 + char *p;
68365 +
68366 + p = strstr(mod->args, "grsec_modharden_fs");
68367 + if (p) {
68368 + char *endptr = p + strlen("grsec_modharden_fs");
68369 + /* copy \0 as well */
68370 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
68371 + is_fs_load = 1;
68372 + }
68373 +#endif
68374 +
68375 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
68376 const char *name = info->strtab + sym[i].st_name;
68377
68378 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68379 + /* it's a real shame this will never get ripped and copied
68380 + upstream! ;(
68381 + */
68382 + if (is_fs_load && !strcmp(name, "register_filesystem"))
68383 + register_filesystem_found = 1;
68384 +#endif
68385 +
68386 switch (sym[i].st_shndx) {
68387 case SHN_COMMON:
68388 /* We compiled with -fno-common. These are not
68389 @@ -1922,7 +1949,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68390 ksym = resolve_symbol_wait(mod, info, name);
68391 /* Ok if resolved. */
68392 if (ksym && !IS_ERR(ksym)) {
68393 + pax_open_kernel();
68394 sym[i].st_value = ksym->value;
68395 + pax_close_kernel();
68396 break;
68397 }
68398
68399 @@ -1941,11 +1970,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68400 secbase = (unsigned long)mod_percpu(mod);
68401 else
68402 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
68403 + pax_open_kernel();
68404 sym[i].st_value += secbase;
68405 + pax_close_kernel();
68406 break;
68407 }
68408 }
68409
68410 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68411 + if (is_fs_load && !register_filesystem_found) {
68412 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
68413 + ret = -EPERM;
68414 + }
68415 +#endif
68416 +
68417 return ret;
68418 }
68419
68420 @@ -2049,22 +2087,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
68421 || s->sh_entsize != ~0UL
68422 || strstarts(sname, ".init"))
68423 continue;
68424 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
68425 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68426 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
68427 + else
68428 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
68429 pr_debug("\t%s\n", sname);
68430 }
68431 - switch (m) {
68432 - case 0: /* executable */
68433 - mod->core_size = debug_align(mod->core_size);
68434 - mod->core_text_size = mod->core_size;
68435 - break;
68436 - case 1: /* RO: text and ro-data */
68437 - mod->core_size = debug_align(mod->core_size);
68438 - mod->core_ro_size = mod->core_size;
68439 - break;
68440 - case 3: /* whole core */
68441 - mod->core_size = debug_align(mod->core_size);
68442 - break;
68443 - }
68444 }
68445
68446 pr_debug("Init section allocation order:\n");
68447 @@ -2078,23 +2106,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
68448 || s->sh_entsize != ~0UL
68449 || !strstarts(sname, ".init"))
68450 continue;
68451 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
68452 - | INIT_OFFSET_MASK);
68453 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68454 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
68455 + else
68456 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
68457 + s->sh_entsize |= INIT_OFFSET_MASK;
68458 pr_debug("\t%s\n", sname);
68459 }
68460 - switch (m) {
68461 - case 0: /* executable */
68462 - mod->init_size = debug_align(mod->init_size);
68463 - mod->init_text_size = mod->init_size;
68464 - break;
68465 - case 1: /* RO: text and ro-data */
68466 - mod->init_size = debug_align(mod->init_size);
68467 - mod->init_ro_size = mod->init_size;
68468 - break;
68469 - case 3: /* whole init */
68470 - mod->init_size = debug_align(mod->init_size);
68471 - break;
68472 - }
68473 }
68474 }
68475
68476 @@ -2266,7 +2284,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
68477
68478 /* Put symbol section at end of init part of module. */
68479 symsect->sh_flags |= SHF_ALLOC;
68480 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
68481 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
68482 info->index.sym) | INIT_OFFSET_MASK;
68483 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
68484
68485 @@ -2281,13 +2299,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
68486 }
68487
68488 /* Append room for core symbols at end of core part. */
68489 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
68490 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
68491 - mod->core_size += strtab_size;
68492 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
68493 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
68494 + mod->core_size_rx += strtab_size;
68495
68496 /* Put string table section at end of init part of module. */
68497 strsect->sh_flags |= SHF_ALLOC;
68498 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
68499 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
68500 info->index.str) | INIT_OFFSET_MASK;
68501 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
68502 }
68503 @@ -2305,12 +2323,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
68504 /* Make sure we get permanent strtab: don't use info->strtab. */
68505 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
68506
68507 + pax_open_kernel();
68508 +
68509 /* Set types up while we still have access to sections. */
68510 for (i = 0; i < mod->num_symtab; i++)
68511 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
68512
68513 - mod->core_symtab = dst = mod->module_core + info->symoffs;
68514 - mod->core_strtab = s = mod->module_core + info->stroffs;
68515 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
68516 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
68517 src = mod->symtab;
68518 *dst = *src;
68519 *s++ = 0;
68520 @@ -2323,6 +2343,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
68521 s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1;
68522 }
68523 mod->core_num_syms = ndst;
68524 +
68525 + pax_close_kernel();
68526 }
68527 #else
68528 static inline void layout_symtab(struct module *mod, struct load_info *info)
68529 @@ -2356,17 +2378,33 @@ void * __weak module_alloc(unsigned long size)
68530 return size == 0 ? NULL : vmalloc_exec(size);
68531 }
68532
68533 -static void *module_alloc_update_bounds(unsigned long size)
68534 +static void *module_alloc_update_bounds_rw(unsigned long size)
68535 {
68536 void *ret = module_alloc(size);
68537
68538 if (ret) {
68539 mutex_lock(&module_mutex);
68540 /* Update module bounds. */
68541 - if ((unsigned long)ret < module_addr_min)
68542 - module_addr_min = (unsigned long)ret;
68543 - if ((unsigned long)ret + size > module_addr_max)
68544 - module_addr_max = (unsigned long)ret + size;
68545 + if ((unsigned long)ret < module_addr_min_rw)
68546 + module_addr_min_rw = (unsigned long)ret;
68547 + if ((unsigned long)ret + size > module_addr_max_rw)
68548 + module_addr_max_rw = (unsigned long)ret + size;
68549 + mutex_unlock(&module_mutex);
68550 + }
68551 + return ret;
68552 +}
68553 +
68554 +static void *module_alloc_update_bounds_rx(unsigned long size)
68555 +{
68556 + void *ret = module_alloc_exec(size);
68557 +
68558 + if (ret) {
68559 + mutex_lock(&module_mutex);
68560 + /* Update module bounds. */
68561 + if ((unsigned long)ret < module_addr_min_rx)
68562 + module_addr_min_rx = (unsigned long)ret;
68563 + if ((unsigned long)ret + size > module_addr_max_rx)
68564 + module_addr_max_rx = (unsigned long)ret + size;
68565 mutex_unlock(&module_mutex);
68566 }
68567 return ret;
68568 @@ -2544,8 +2582,14 @@ static struct module *setup_load_info(struct load_info *info)
68569 static int check_modinfo(struct module *mod, struct load_info *info)
68570 {
68571 const char *modmagic = get_modinfo(info, "vermagic");
68572 + const char *license = get_modinfo(info, "license");
68573 int err;
68574
68575 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
68576 + if (!license || !license_is_gpl_compatible(license))
68577 + return -ENOEXEC;
68578 +#endif
68579 +
68580 /* This is allowed: modprobe --force will invalidate it. */
68581 if (!modmagic) {
68582 err = try_to_force_load(mod, "bad vermagic");
68583 @@ -2568,7 +2612,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
68584 }
68585
68586 /* Set up license info based on the info section */
68587 - set_license(mod, get_modinfo(info, "license"));
68588 + set_license(mod, license);
68589
68590 return 0;
68591 }
68592 @@ -2662,7 +2706,7 @@ static int move_module(struct module *mod, struct load_info *info)
68593 void *ptr;
68594
68595 /* Do the allocs. */
68596 - ptr = module_alloc_update_bounds(mod->core_size);
68597 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
68598 /*
68599 * The pointer to this block is stored in the module structure
68600 * which is inside the block. Just mark it as not being a
68601 @@ -2672,23 +2716,50 @@ static int move_module(struct module *mod, struct load_info *info)
68602 if (!ptr)
68603 return -ENOMEM;
68604
68605 - memset(ptr, 0, mod->core_size);
68606 - mod->module_core = ptr;
68607 + memset(ptr, 0, mod->core_size_rw);
68608 + mod->module_core_rw = ptr;
68609
68610 - ptr = module_alloc_update_bounds(mod->init_size);
68611 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
68612 /*
68613 * The pointer to this block is stored in the module structure
68614 * which is inside the block. This block doesn't need to be
68615 * scanned as it contains data and code that will be freed
68616 * after the module is initialized.
68617 */
68618 - kmemleak_ignore(ptr);
68619 - if (!ptr && mod->init_size) {
68620 - module_free(mod, mod->module_core);
68621 + kmemleak_not_leak(ptr);
68622 + if (!ptr && mod->init_size_rw) {
68623 + module_free(mod, mod->module_core_rw);
68624 return -ENOMEM;
68625 }
68626 - memset(ptr, 0, mod->init_size);
68627 - mod->module_init = ptr;
68628 + memset(ptr, 0, mod->init_size_rw);
68629 + mod->module_init_rw = ptr;
68630 +
68631 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
68632 + kmemleak_not_leak(ptr);
68633 + if (!ptr) {
68634 + module_free(mod, mod->module_init_rw);
68635 + module_free(mod, mod->module_core_rw);
68636 + return -ENOMEM;
68637 + }
68638 +
68639 + pax_open_kernel();
68640 + memset(ptr, 0, mod->core_size_rx);
68641 + pax_close_kernel();
68642 + mod->module_core_rx = ptr;
68643 +
68644 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
68645 + kmemleak_not_leak(ptr);
68646 + if (!ptr && mod->init_size_rx) {
68647 + module_free_exec(mod, mod->module_core_rx);
68648 + module_free(mod, mod->module_init_rw);
68649 + module_free(mod, mod->module_core_rw);
68650 + return -ENOMEM;
68651 + }
68652 +
68653 + pax_open_kernel();
68654 + memset(ptr, 0, mod->init_size_rx);
68655 + pax_close_kernel();
68656 + mod->module_init_rx = ptr;
68657
68658 /* Transfer each section which specifies SHF_ALLOC */
68659 pr_debug("final section addresses:\n");
68660 @@ -2699,16 +2770,45 @@ static int move_module(struct module *mod, struct load_info *info)
68661 if (!(shdr->sh_flags & SHF_ALLOC))
68662 continue;
68663
68664 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
68665 - dest = mod->module_init
68666 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68667 - else
68668 - dest = mod->module_core + shdr->sh_entsize;
68669 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
68670 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68671 + dest = mod->module_init_rw
68672 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68673 + else
68674 + dest = mod->module_init_rx
68675 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68676 + } else {
68677 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68678 + dest = mod->module_core_rw + shdr->sh_entsize;
68679 + else
68680 + dest = mod->module_core_rx + shdr->sh_entsize;
68681 + }
68682 +
68683 + if (shdr->sh_type != SHT_NOBITS) {
68684 +
68685 +#ifdef CONFIG_PAX_KERNEXEC
68686 +#ifdef CONFIG_X86_64
68687 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
68688 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
68689 +#endif
68690 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
68691 + pax_open_kernel();
68692 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68693 + pax_close_kernel();
68694 + } else
68695 +#endif
68696
68697 - if (shdr->sh_type != SHT_NOBITS)
68698 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68699 + }
68700 /* Update sh_addr to point to copy in image. */
68701 - shdr->sh_addr = (unsigned long)dest;
68702 +
68703 +#ifdef CONFIG_PAX_KERNEXEC
68704 + if (shdr->sh_flags & SHF_EXECINSTR)
68705 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
68706 + else
68707 +#endif
68708 +
68709 + shdr->sh_addr = (unsigned long)dest;
68710 pr_debug("\t0x%lx %s\n",
68711 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
68712 }
68713 @@ -2763,12 +2863,12 @@ static void flush_module_icache(const struct module *mod)
68714 * Do it before processing of module parameters, so the module
68715 * can provide parameter accessor functions of its own.
68716 */
68717 - if (mod->module_init)
68718 - flush_icache_range((unsigned long)mod->module_init,
68719 - (unsigned long)mod->module_init
68720 - + mod->init_size);
68721 - flush_icache_range((unsigned long)mod->module_core,
68722 - (unsigned long)mod->module_core + mod->core_size);
68723 + if (mod->module_init_rx)
68724 + flush_icache_range((unsigned long)mod->module_init_rx,
68725 + (unsigned long)mod->module_init_rx
68726 + + mod->init_size_rx);
68727 + flush_icache_range((unsigned long)mod->module_core_rx,
68728 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
68729
68730 set_fs(old_fs);
68731 }
68732 @@ -2838,8 +2938,10 @@ out:
68733 static void module_deallocate(struct module *mod, struct load_info *info)
68734 {
68735 percpu_modfree(mod);
68736 - module_free(mod, mod->module_init);
68737 - module_free(mod, mod->module_core);
68738 + module_free_exec(mod, mod->module_init_rx);
68739 + module_free_exec(mod, mod->module_core_rx);
68740 + module_free(mod, mod->module_init_rw);
68741 + module_free(mod, mod->module_core_rw);
68742 }
68743
68744 int __weak module_finalize(const Elf_Ehdr *hdr,
68745 @@ -2852,7 +2954,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
68746 static int post_relocation(struct module *mod, const struct load_info *info)
68747 {
68748 /* Sort exception table now relocations are done. */
68749 + pax_open_kernel();
68750 sort_extable(mod->extable, mod->extable + mod->num_exentries);
68751 + pax_close_kernel();
68752
68753 /* Copy relocated percpu area over. */
68754 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
68755 @@ -2903,9 +3007,38 @@ static struct module *load_module(void __user *umod,
68756 if (err)
68757 goto free_unload;
68758
68759 + /* Now copy in args */
68760 + mod->args = strndup_user(uargs, ~0UL >> 1);
68761 + if (IS_ERR(mod->args)) {
68762 + err = PTR_ERR(mod->args);
68763 + goto free_unload;
68764 + }
68765 +
68766 /* Set up MODINFO_ATTR fields */
68767 setup_modinfo(mod, &info);
68768
68769 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68770 + {
68771 + char *p, *p2;
68772 +
68773 + if (strstr(mod->args, "grsec_modharden_netdev")) {
68774 + 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);
68775 + err = -EPERM;
68776 + goto free_modinfo;
68777 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
68778 + p += strlen("grsec_modharden_normal");
68779 + p2 = strstr(p, "_");
68780 + if (p2) {
68781 + *p2 = '\0';
68782 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
68783 + *p2 = '_';
68784 + }
68785 + err = -EPERM;
68786 + goto free_modinfo;
68787 + }
68788 + }
68789 +#endif
68790 +
68791 /* Fix up syms, so that st_value is a pointer to location. */
68792 err = simplify_symbols(mod, &info);
68793 if (err < 0)
68794 @@ -2921,13 +3054,6 @@ static struct module *load_module(void __user *umod,
68795
68796 flush_module_icache(mod);
68797
68798 - /* Now copy in args */
68799 - mod->args = strndup_user(uargs, ~0UL >> 1);
68800 - if (IS_ERR(mod->args)) {
68801 - err = PTR_ERR(mod->args);
68802 - goto free_arch_cleanup;
68803 - }
68804 -
68805 /* Mark state as coming so strong_try_module_get() ignores us. */
68806 mod->state = MODULE_STATE_COMING;
68807
68808 @@ -2985,11 +3111,10 @@ static struct module *load_module(void __user *umod,
68809 unlock:
68810 mutex_unlock(&module_mutex);
68811 synchronize_sched();
68812 - kfree(mod->args);
68813 - free_arch_cleanup:
68814 module_arch_cleanup(mod);
68815 free_modinfo:
68816 free_modinfo(mod);
68817 + kfree(mod->args);
68818 free_unload:
68819 module_unload_free(mod);
68820 free_module:
68821 @@ -3030,16 +3155,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
68822 MODULE_STATE_COMING, mod);
68823
68824 /* Set RO and NX regions for core */
68825 - set_section_ro_nx(mod->module_core,
68826 - mod->core_text_size,
68827 - mod->core_ro_size,
68828 - mod->core_size);
68829 + set_section_ro_nx(mod->module_core_rx,
68830 + mod->core_size_rx,
68831 + mod->core_size_rx,
68832 + mod->core_size_rx);
68833
68834 /* Set RO and NX regions for init */
68835 - set_section_ro_nx(mod->module_init,
68836 - mod->init_text_size,
68837 - mod->init_ro_size,
68838 - mod->init_size);
68839 + set_section_ro_nx(mod->module_init_rx,
68840 + mod->init_size_rx,
68841 + mod->init_size_rx,
68842 + mod->init_size_rx);
68843
68844 do_mod_ctors(mod);
68845 /* Start the module */
68846 @@ -3085,11 +3210,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
68847 mod->strtab = mod->core_strtab;
68848 #endif
68849 unset_module_init_ro_nx(mod);
68850 - module_free(mod, mod->module_init);
68851 - mod->module_init = NULL;
68852 - mod->init_size = 0;
68853 - mod->init_ro_size = 0;
68854 - mod->init_text_size = 0;
68855 + module_free(mod, mod->module_init_rw);
68856 + module_free_exec(mod, mod->module_init_rx);
68857 + mod->module_init_rw = NULL;
68858 + mod->module_init_rx = NULL;
68859 + mod->init_size_rw = 0;
68860 + mod->init_size_rx = 0;
68861 mutex_unlock(&module_mutex);
68862
68863 return 0;
68864 @@ -3120,10 +3246,16 @@ static const char *get_ksymbol(struct module *mod,
68865 unsigned long nextval;
68866
68867 /* At worse, next value is at end of module */
68868 - if (within_module_init(addr, mod))
68869 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
68870 + if (within_module_init_rx(addr, mod))
68871 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
68872 + else if (within_module_init_rw(addr, mod))
68873 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
68874 + else if (within_module_core_rx(addr, mod))
68875 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
68876 + else if (within_module_core_rw(addr, mod))
68877 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
68878 else
68879 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
68880 + return NULL;
68881
68882 /* Scan for closest preceding symbol, and next symbol. (ELF
68883 starts real symbols at 1). */
68884 @@ -3358,7 +3490,7 @@ static int m_show(struct seq_file *m, void *p)
68885 char buf[8];
68886
68887 seq_printf(m, "%s %u",
68888 - mod->name, mod->init_size + mod->core_size);
68889 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
68890 print_unload_info(m, mod);
68891
68892 /* Informative for users. */
68893 @@ -3367,7 +3499,7 @@ static int m_show(struct seq_file *m, void *p)
68894 mod->state == MODULE_STATE_COMING ? "Loading":
68895 "Live");
68896 /* Used by oprofile and other similar tools. */
68897 - seq_printf(m, " 0x%pK", mod->module_core);
68898 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
68899
68900 /* Taints info */
68901 if (mod->taints)
68902 @@ -3403,7 +3535,17 @@ static const struct file_operations proc_modules_operations = {
68903
68904 static int __init proc_modules_init(void)
68905 {
68906 +#ifndef CONFIG_GRKERNSEC_HIDESYM
68907 +#ifdef CONFIG_GRKERNSEC_PROC_USER
68908 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68909 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68910 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
68911 +#else
68912 proc_create("modules", 0, NULL, &proc_modules_operations);
68913 +#endif
68914 +#else
68915 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68916 +#endif
68917 return 0;
68918 }
68919 module_init(proc_modules_init);
68920 @@ -3462,12 +3604,12 @@ struct module *__module_address(unsigned long addr)
68921 {
68922 struct module *mod;
68923
68924 - if (addr < module_addr_min || addr > module_addr_max)
68925 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
68926 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
68927 return NULL;
68928
68929 list_for_each_entry_rcu(mod, &modules, list)
68930 - if (within_module_core(addr, mod)
68931 - || within_module_init(addr, mod))
68932 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
68933 return mod;
68934 return NULL;
68935 }
68936 @@ -3501,11 +3643,20 @@ bool is_module_text_address(unsigned long addr)
68937 */
68938 struct module *__module_text_address(unsigned long addr)
68939 {
68940 - struct module *mod = __module_address(addr);
68941 + struct module *mod;
68942 +
68943 +#ifdef CONFIG_X86_32
68944 + addr = ktla_ktva(addr);
68945 +#endif
68946 +
68947 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
68948 + return NULL;
68949 +
68950 + mod = __module_address(addr);
68951 +
68952 if (mod) {
68953 /* Make sure it's within the text section. */
68954 - if (!within(addr, mod->module_init, mod->init_text_size)
68955 - && !within(addr, mod->module_core, mod->core_text_size))
68956 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
68957 mod = NULL;
68958 }
68959 return mod;
68960 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
68961 index 7e3443f..b2a1e6b 100644
68962 --- a/kernel/mutex-debug.c
68963 +++ b/kernel/mutex-debug.c
68964 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
68965 }
68966
68967 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68968 - struct thread_info *ti)
68969 + struct task_struct *task)
68970 {
68971 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
68972
68973 /* Mark the current thread as blocked on the lock: */
68974 - ti->task->blocked_on = waiter;
68975 + task->blocked_on = waiter;
68976 }
68977
68978 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68979 - struct thread_info *ti)
68980 + struct task_struct *task)
68981 {
68982 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
68983 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
68984 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
68985 - ti->task->blocked_on = NULL;
68986 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
68987 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
68988 + task->blocked_on = NULL;
68989
68990 list_del_init(&waiter->list);
68991 waiter->task = NULL;
68992 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
68993 index 0799fd3..d06ae3b 100644
68994 --- a/kernel/mutex-debug.h
68995 +++ b/kernel/mutex-debug.h
68996 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
68997 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
68998 extern void debug_mutex_add_waiter(struct mutex *lock,
68999 struct mutex_waiter *waiter,
69000 - struct thread_info *ti);
69001 + struct task_struct *task);
69002 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
69003 - struct thread_info *ti);
69004 + struct task_struct *task);
69005 extern void debug_mutex_unlock(struct mutex *lock);
69006 extern void debug_mutex_init(struct mutex *lock, const char *name,
69007 struct lock_class_key *key);
69008 diff --git a/kernel/mutex.c b/kernel/mutex.c
69009 index a307cc9..27fd2e9 100644
69010 --- a/kernel/mutex.c
69011 +++ b/kernel/mutex.c
69012 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
69013 spin_lock_mutex(&lock->wait_lock, flags);
69014
69015 debug_mutex_lock_common(lock, &waiter);
69016 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
69017 + debug_mutex_add_waiter(lock, &waiter, task);
69018
69019 /* add waiting tasks to the end of the waitqueue (FIFO): */
69020 list_add_tail(&waiter.list, &lock->wait_list);
69021 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
69022 * TASK_UNINTERRUPTIBLE case.)
69023 */
69024 if (unlikely(signal_pending_state(state, task))) {
69025 - mutex_remove_waiter(lock, &waiter,
69026 - task_thread_info(task));
69027 + mutex_remove_waiter(lock, &waiter, task);
69028 mutex_release(&lock->dep_map, 1, ip);
69029 spin_unlock_mutex(&lock->wait_lock, flags);
69030
69031 @@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
69032 done:
69033 lock_acquired(&lock->dep_map, ip);
69034 /* got the lock - rejoice! */
69035 - mutex_remove_waiter(lock, &waiter, current_thread_info());
69036 + mutex_remove_waiter(lock, &waiter, task);
69037 mutex_set_owner(lock);
69038
69039 /* set it to 0 if there are no waiters left: */
69040 diff --git a/kernel/panic.c b/kernel/panic.c
69041 index e1b2822..5edc1d9 100644
69042 --- a/kernel/panic.c
69043 +++ b/kernel/panic.c
69044 @@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
69045 const char *board;
69046
69047 printk(KERN_WARNING "------------[ cut here ]------------\n");
69048 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
69049 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
69050 board = dmi_get_system_info(DMI_PRODUCT_NAME);
69051 if (board)
69052 printk(KERN_WARNING "Hardware name: %s\n", board);
69053 @@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
69054 */
69055 void __stack_chk_fail(void)
69056 {
69057 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
69058 + dump_stack();
69059 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
69060 __builtin_return_address(0));
69061 }
69062 EXPORT_SYMBOL(__stack_chk_fail);
69063 diff --git a/kernel/pid.c b/kernel/pid.c
69064 index e86b291a..e8b0fb5 100644
69065 --- a/kernel/pid.c
69066 +++ b/kernel/pid.c
69067 @@ -33,6 +33,7 @@
69068 #include <linux/rculist.h>
69069 #include <linux/bootmem.h>
69070 #include <linux/hash.h>
69071 +#include <linux/security.h>
69072 #include <linux/pid_namespace.h>
69073 #include <linux/init_task.h>
69074 #include <linux/syscalls.h>
69075 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
69076
69077 int pid_max = PID_MAX_DEFAULT;
69078
69079 -#define RESERVED_PIDS 300
69080 +#define RESERVED_PIDS 500
69081
69082 int pid_max_min = RESERVED_PIDS + 1;
69083 int pid_max_max = PID_MAX_LIMIT;
69084 @@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
69085 */
69086 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
69087 {
69088 + struct task_struct *task;
69089 +
69090 rcu_lockdep_assert(rcu_read_lock_held(),
69091 "find_task_by_pid_ns() needs rcu_read_lock()"
69092 " protection");
69093 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
69094 +
69095 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
69096 +
69097 + if (gr_pid_is_chrooted(task))
69098 + return NULL;
69099 +
69100 + return task;
69101 }
69102
69103 struct task_struct *find_task_by_vpid(pid_t vnr)
69104 @@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
69105 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
69106 }
69107
69108 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
69109 +{
69110 + rcu_lockdep_assert(rcu_read_lock_held(),
69111 + "find_task_by_pid_ns() needs rcu_read_lock()"
69112 + " protection");
69113 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
69114 +}
69115 +
69116 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
69117 {
69118 struct pid *pid;
69119 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
69120 index 125cb67..a4d1c30 100644
69121 --- a/kernel/posix-cpu-timers.c
69122 +++ b/kernel/posix-cpu-timers.c
69123 @@ -6,6 +6,7 @@
69124 #include <linux/posix-timers.h>
69125 #include <linux/errno.h>
69126 #include <linux/math64.h>
69127 +#include <linux/security.h>
69128 #include <asm/uaccess.h>
69129 #include <linux/kernel_stat.h>
69130 #include <trace/events/timer.h>
69131 @@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
69132
69133 static __init int init_posix_cpu_timers(void)
69134 {
69135 - struct k_clock process = {
69136 + static struct k_clock process = {
69137 .clock_getres = process_cpu_clock_getres,
69138 .clock_get = process_cpu_clock_get,
69139 .timer_create = process_cpu_timer_create,
69140 .nsleep = process_cpu_nsleep,
69141 .nsleep_restart = process_cpu_nsleep_restart,
69142 };
69143 - struct k_clock thread = {
69144 + static struct k_clock thread = {
69145 .clock_getres = thread_cpu_clock_getres,
69146 .clock_get = thread_cpu_clock_get,
69147 .timer_create = thread_cpu_timer_create,
69148 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
69149 index 69185ae..cc2847a 100644
69150 --- a/kernel/posix-timers.c
69151 +++ b/kernel/posix-timers.c
69152 @@ -43,6 +43,7 @@
69153 #include <linux/idr.h>
69154 #include <linux/posix-clock.h>
69155 #include <linux/posix-timers.h>
69156 +#include <linux/grsecurity.h>
69157 #include <linux/syscalls.h>
69158 #include <linux/wait.h>
69159 #include <linux/workqueue.h>
69160 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
69161 * which we beg off on and pass to do_sys_settimeofday().
69162 */
69163
69164 -static struct k_clock posix_clocks[MAX_CLOCKS];
69165 +static struct k_clock *posix_clocks[MAX_CLOCKS];
69166
69167 /*
69168 * These ones are defined below.
69169 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
69170 */
69171 static __init int init_posix_timers(void)
69172 {
69173 - struct k_clock clock_realtime = {
69174 + static struct k_clock clock_realtime = {
69175 .clock_getres = hrtimer_get_res,
69176 .clock_get = posix_clock_realtime_get,
69177 .clock_set = posix_clock_realtime_set,
69178 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
69179 .timer_get = common_timer_get,
69180 .timer_del = common_timer_del,
69181 };
69182 - struct k_clock clock_monotonic = {
69183 + static struct k_clock clock_monotonic = {
69184 .clock_getres = hrtimer_get_res,
69185 .clock_get = posix_ktime_get_ts,
69186 .nsleep = common_nsleep,
69187 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
69188 .timer_get = common_timer_get,
69189 .timer_del = common_timer_del,
69190 };
69191 - struct k_clock clock_monotonic_raw = {
69192 + static struct k_clock clock_monotonic_raw = {
69193 .clock_getres = hrtimer_get_res,
69194 .clock_get = posix_get_monotonic_raw,
69195 };
69196 - struct k_clock clock_realtime_coarse = {
69197 + static struct k_clock clock_realtime_coarse = {
69198 .clock_getres = posix_get_coarse_res,
69199 .clock_get = posix_get_realtime_coarse,
69200 };
69201 - struct k_clock clock_monotonic_coarse = {
69202 + static struct k_clock clock_monotonic_coarse = {
69203 .clock_getres = posix_get_coarse_res,
69204 .clock_get = posix_get_monotonic_coarse,
69205 };
69206 - struct k_clock clock_boottime = {
69207 + static struct k_clock clock_boottime = {
69208 .clock_getres = hrtimer_get_res,
69209 .clock_get = posix_get_boottime,
69210 .nsleep = common_nsleep,
69211 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
69212 return;
69213 }
69214
69215 - posix_clocks[clock_id] = *new_clock;
69216 + posix_clocks[clock_id] = new_clock;
69217 }
69218 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
69219
69220 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
69221 return (id & CLOCKFD_MASK) == CLOCKFD ?
69222 &clock_posix_dynamic : &clock_posix_cpu;
69223
69224 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
69225 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
69226 return NULL;
69227 - return &posix_clocks[id];
69228 + return posix_clocks[id];
69229 }
69230
69231 static int common_timer_create(struct k_itimer *new_timer)
69232 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
69233 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
69234 return -EFAULT;
69235
69236 + /* only the CLOCK_REALTIME clock can be set, all other clocks
69237 + have their clock_set fptr set to a nosettime dummy function
69238 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
69239 + call common_clock_set, which calls do_sys_settimeofday, which
69240 + we hook
69241 + */
69242 +
69243 return kc->clock_set(which_clock, &new_tp);
69244 }
69245
69246 diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
69247 index d523593..68197a4 100644
69248 --- a/kernel/power/poweroff.c
69249 +++ b/kernel/power/poweroff.c
69250 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
69251 .enable_mask = SYSRQ_ENABLE_BOOT,
69252 };
69253
69254 -static int pm_sysrq_init(void)
69255 +static int __init pm_sysrq_init(void)
69256 {
69257 register_sysrq_key('o', &sysrq_poweroff_op);
69258 return 0;
69259 diff --git a/kernel/power/process.c b/kernel/power/process.c
69260 index 19db29f..33b52b6 100644
69261 --- a/kernel/power/process.c
69262 +++ b/kernel/power/process.c
69263 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
69264 u64 elapsed_csecs64;
69265 unsigned int elapsed_csecs;
69266 bool wakeup = false;
69267 + bool timedout = false;
69268
69269 do_gettimeofday(&start);
69270
69271 @@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
69272
69273 while (true) {
69274 todo = 0;
69275 + if (time_after(jiffies, end_time))
69276 + timedout = true;
69277 read_lock(&tasklist_lock);
69278 do_each_thread(g, p) {
69279 if (p == current || !freeze_task(p))
69280 @@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
69281 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
69282 * transition can't race with task state testing here.
69283 */
69284 - if (!task_is_stopped_or_traced(p) &&
69285 - !freezer_should_skip(p))
69286 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
69287 todo++;
69288 + if (timedout) {
69289 + printk(KERN_ERR "Task refusing to freeze:\n");
69290 + sched_show_task(p);
69291 + }
69292 + }
69293 } while_each_thread(g, p);
69294 read_unlock(&tasklist_lock);
69295
69296 @@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
69297 todo += wq_busy;
69298 }
69299
69300 - if (!todo || time_after(jiffies, end_time))
69301 + if (!todo || timedout)
69302 break;
69303
69304 if (pm_wakeup_pending()) {
69305 diff --git a/kernel/printk.c b/kernel/printk.c
69306 index 66a2ea3..10f3a01 100644
69307 --- a/kernel/printk.c
69308 +++ b/kernel/printk.c
69309 @@ -817,6 +817,11 @@ static int check_syslog_permissions(int type, bool from_file)
69310 if (from_file && type != SYSLOG_ACTION_OPEN)
69311 return 0;
69312
69313 +#ifdef CONFIG_GRKERNSEC_DMESG
69314 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
69315 + return -EPERM;
69316 +#endif
69317 +
69318 if (syslog_action_restricted(type)) {
69319 if (capable(CAP_SYSLOG))
69320 return 0;
69321 diff --git a/kernel/profile.c b/kernel/profile.c
69322 index 76b8e77..a2930e8 100644
69323 --- a/kernel/profile.c
69324 +++ b/kernel/profile.c
69325 @@ -39,7 +39,7 @@ struct profile_hit {
69326 /* Oprofile timer tick hook */
69327 static int (*timer_hook)(struct pt_regs *) __read_mostly;
69328
69329 -static atomic_t *prof_buffer;
69330 +static atomic_unchecked_t *prof_buffer;
69331 static unsigned long prof_len, prof_shift;
69332
69333 int prof_on __read_mostly;
69334 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
69335 hits[i].pc = 0;
69336 continue;
69337 }
69338 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69339 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69340 hits[i].hits = hits[i].pc = 0;
69341 }
69342 }
69343 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69344 * Add the current hit(s) and flush the write-queue out
69345 * to the global buffer:
69346 */
69347 - atomic_add(nr_hits, &prof_buffer[pc]);
69348 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
69349 for (i = 0; i < NR_PROFILE_HIT; ++i) {
69350 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69351 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69352 hits[i].pc = hits[i].hits = 0;
69353 }
69354 out:
69355 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69356 {
69357 unsigned long pc;
69358 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
69359 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69360 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69361 }
69362 #endif /* !CONFIG_SMP */
69363
69364 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
69365 return -EFAULT;
69366 buf++; p++; count--; read++;
69367 }
69368 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
69369 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
69370 if (copy_to_user(buf, (void *)pnt, count))
69371 return -EFAULT;
69372 read += count;
69373 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
69374 }
69375 #endif
69376 profile_discard_flip_buffers();
69377 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
69378 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
69379 return count;
69380 }
69381
69382 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
69383 index a232bb5..2a65ef9 100644
69384 --- a/kernel/ptrace.c
69385 +++ b/kernel/ptrace.c
69386 @@ -279,7 +279,7 @@ static int ptrace_attach(struct task_struct *task, long request,
69387
69388 if (seize)
69389 flags |= PT_SEIZED;
69390 - if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
69391 + if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
69392 flags |= PT_PTRACE_CAP;
69393 task->ptrace = flags;
69394
69395 @@ -486,7 +486,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
69396 break;
69397 return -EIO;
69398 }
69399 - if (copy_to_user(dst, buf, retval))
69400 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
69401 return -EFAULT;
69402 copied += retval;
69403 src += retval;
69404 @@ -671,7 +671,7 @@ int ptrace_request(struct task_struct *child, long request,
69405 bool seized = child->ptrace & PT_SEIZED;
69406 int ret = -EIO;
69407 siginfo_t siginfo, *si;
69408 - void __user *datavp = (void __user *) data;
69409 + void __user *datavp = (__force void __user *) data;
69410 unsigned long __user *datalp = datavp;
69411 unsigned long flags;
69412
69413 @@ -873,14 +873,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
69414 goto out;
69415 }
69416
69417 + if (gr_handle_ptrace(child, request)) {
69418 + ret = -EPERM;
69419 + goto out_put_task_struct;
69420 + }
69421 +
69422 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69423 ret = ptrace_attach(child, request, addr, data);
69424 /*
69425 * Some architectures need to do book-keeping after
69426 * a ptrace attach.
69427 */
69428 - if (!ret)
69429 + if (!ret) {
69430 arch_ptrace_attach(child);
69431 + gr_audit_ptrace(child);
69432 + }
69433 goto out_put_task_struct;
69434 }
69435
69436 @@ -906,7 +913,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
69437 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
69438 if (copied != sizeof(tmp))
69439 return -EIO;
69440 - return put_user(tmp, (unsigned long __user *)data);
69441 + return put_user(tmp, (__force unsigned long __user *)data);
69442 }
69443
69444 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
69445 @@ -1016,14 +1023,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
69446 goto out;
69447 }
69448
69449 + if (gr_handle_ptrace(child, request)) {
69450 + ret = -EPERM;
69451 + goto out_put_task_struct;
69452 + }
69453 +
69454 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69455 ret = ptrace_attach(child, request, addr, data);
69456 /*
69457 * Some architectures need to do book-keeping after
69458 * a ptrace attach.
69459 */
69460 - if (!ret)
69461 + if (!ret) {
69462 arch_ptrace_attach(child);
69463 + gr_audit_ptrace(child);
69464 + }
69465 goto out_put_task_struct;
69466 }
69467
69468 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
69469 index 547b1fe..65e874e 100644
69470 --- a/kernel/rcutiny.c
69471 +++ b/kernel/rcutiny.c
69472 @@ -46,7 +46,7 @@
69473 struct rcu_ctrlblk;
69474 static void invoke_rcu_callbacks(void);
69475 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
69476 -static void rcu_process_callbacks(struct softirq_action *unused);
69477 +static void rcu_process_callbacks(void);
69478 static void __call_rcu(struct rcu_head *head,
69479 void (*func)(struct rcu_head *rcu),
69480 struct rcu_ctrlblk *rcp);
69481 @@ -307,7 +307,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
69482 rcu_is_callbacks_kthread()));
69483 }
69484
69485 -static void rcu_process_callbacks(struct softirq_action *unused)
69486 +static void rcu_process_callbacks(void)
69487 {
69488 __rcu_process_callbacks(&rcu_sched_ctrlblk);
69489 __rcu_process_callbacks(&rcu_bh_ctrlblk);
69490 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
69491 index 918fd1e..85089bb 100644
69492 --- a/kernel/rcutiny_plugin.h
69493 +++ b/kernel/rcutiny_plugin.h
69494 @@ -893,7 +893,7 @@ static int rcu_kthread(void *arg)
69495 have_rcu_kthread_work = morework;
69496 local_irq_restore(flags);
69497 if (work)
69498 - rcu_process_callbacks(NULL);
69499 + rcu_process_callbacks();
69500 schedule_timeout_interruptible(1); /* Leave CPU for others. */
69501 }
69502
69503 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
69504 index 25b1503..1988a74 100644
69505 --- a/kernel/rcutorture.c
69506 +++ b/kernel/rcutorture.c
69507 @@ -162,12 +162,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
69508 { 0 };
69509 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
69510 { 0 };
69511 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69512 -static atomic_t n_rcu_torture_alloc;
69513 -static atomic_t n_rcu_torture_alloc_fail;
69514 -static atomic_t n_rcu_torture_free;
69515 -static atomic_t n_rcu_torture_mberror;
69516 -static atomic_t n_rcu_torture_error;
69517 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69518 +static atomic_unchecked_t n_rcu_torture_alloc;
69519 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
69520 +static atomic_unchecked_t n_rcu_torture_free;
69521 +static atomic_unchecked_t n_rcu_torture_mberror;
69522 +static atomic_unchecked_t n_rcu_torture_error;
69523 static long n_rcu_torture_barrier_error;
69524 static long n_rcu_torture_boost_ktrerror;
69525 static long n_rcu_torture_boost_rterror;
69526 @@ -265,11 +265,11 @@ rcu_torture_alloc(void)
69527
69528 spin_lock_bh(&rcu_torture_lock);
69529 if (list_empty(&rcu_torture_freelist)) {
69530 - atomic_inc(&n_rcu_torture_alloc_fail);
69531 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
69532 spin_unlock_bh(&rcu_torture_lock);
69533 return NULL;
69534 }
69535 - atomic_inc(&n_rcu_torture_alloc);
69536 + atomic_inc_unchecked(&n_rcu_torture_alloc);
69537 p = rcu_torture_freelist.next;
69538 list_del_init(p);
69539 spin_unlock_bh(&rcu_torture_lock);
69540 @@ -282,7 +282,7 @@ rcu_torture_alloc(void)
69541 static void
69542 rcu_torture_free(struct rcu_torture *p)
69543 {
69544 - atomic_inc(&n_rcu_torture_free);
69545 + atomic_inc_unchecked(&n_rcu_torture_free);
69546 spin_lock_bh(&rcu_torture_lock);
69547 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
69548 spin_unlock_bh(&rcu_torture_lock);
69549 @@ -403,7 +403,7 @@ rcu_torture_cb(struct rcu_head *p)
69550 i = rp->rtort_pipe_count;
69551 if (i > RCU_TORTURE_PIPE_LEN)
69552 i = RCU_TORTURE_PIPE_LEN;
69553 - atomic_inc(&rcu_torture_wcount[i]);
69554 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69555 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69556 rp->rtort_mbtest = 0;
69557 rcu_torture_free(rp);
69558 @@ -452,7 +452,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
69559 i = rp->rtort_pipe_count;
69560 if (i > RCU_TORTURE_PIPE_LEN)
69561 i = RCU_TORTURE_PIPE_LEN;
69562 - atomic_inc(&rcu_torture_wcount[i]);
69563 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69564 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69565 rp->rtort_mbtest = 0;
69566 list_del(&rp->rtort_free);
69567 @@ -995,7 +995,7 @@ rcu_torture_writer(void *arg)
69568 i = old_rp->rtort_pipe_count;
69569 if (i > RCU_TORTURE_PIPE_LEN)
69570 i = RCU_TORTURE_PIPE_LEN;
69571 - atomic_inc(&rcu_torture_wcount[i]);
69572 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69573 old_rp->rtort_pipe_count++;
69574 cur_ops->deferred_free(old_rp);
69575 }
69576 @@ -1080,7 +1080,7 @@ static void rcu_torture_timer(unsigned long unused)
69577 }
69578 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
69579 if (p->rtort_mbtest == 0)
69580 - atomic_inc(&n_rcu_torture_mberror);
69581 + atomic_inc_unchecked(&n_rcu_torture_mberror);
69582 spin_lock(&rand_lock);
69583 cur_ops->read_delay(&rand);
69584 n_rcu_torture_timers++;
69585 @@ -1144,7 +1144,7 @@ rcu_torture_reader(void *arg)
69586 }
69587 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
69588 if (p->rtort_mbtest == 0)
69589 - atomic_inc(&n_rcu_torture_mberror);
69590 + atomic_inc_unchecked(&n_rcu_torture_mberror);
69591 cur_ops->read_delay(&rand);
69592 preempt_disable();
69593 pipe_count = p->rtort_pipe_count;
69594 @@ -1203,11 +1203,11 @@ rcu_torture_printk(char *page)
69595 rcu_torture_current,
69596 rcu_torture_current_version,
69597 list_empty(&rcu_torture_freelist),
69598 - atomic_read(&n_rcu_torture_alloc),
69599 - atomic_read(&n_rcu_torture_alloc_fail),
69600 - atomic_read(&n_rcu_torture_free));
69601 + atomic_read_unchecked(&n_rcu_torture_alloc),
69602 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
69603 + atomic_read_unchecked(&n_rcu_torture_free));
69604 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
69605 - atomic_read(&n_rcu_torture_mberror),
69606 + atomic_read_unchecked(&n_rcu_torture_mberror),
69607 n_rcu_torture_boost_ktrerror,
69608 n_rcu_torture_boost_rterror);
69609 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
69610 @@ -1224,14 +1224,14 @@ rcu_torture_printk(char *page)
69611 n_barrier_attempts,
69612 n_rcu_torture_barrier_error);
69613 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
69614 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
69615 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
69616 n_rcu_torture_barrier_error != 0 ||
69617 n_rcu_torture_boost_ktrerror != 0 ||
69618 n_rcu_torture_boost_rterror != 0 ||
69619 n_rcu_torture_boost_failure != 0 ||
69620 i > 1) {
69621 cnt += sprintf(&page[cnt], "!!! ");
69622 - atomic_inc(&n_rcu_torture_error);
69623 + atomic_inc_unchecked(&n_rcu_torture_error);
69624 WARN_ON_ONCE(1);
69625 }
69626 cnt += sprintf(&page[cnt], "Reader Pipe: ");
69627 @@ -1245,7 +1245,7 @@ rcu_torture_printk(char *page)
69628 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
69629 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69630 cnt += sprintf(&page[cnt], " %d",
69631 - atomic_read(&rcu_torture_wcount[i]));
69632 + atomic_read_unchecked(&rcu_torture_wcount[i]));
69633 }
69634 cnt += sprintf(&page[cnt], "\n");
69635 if (cur_ops->stats)
69636 @@ -1905,7 +1905,7 @@ rcu_torture_cleanup(void)
69637
69638 if (cur_ops->cleanup)
69639 cur_ops->cleanup();
69640 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
69641 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
69642 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
69643 else if (n_online_successes != n_online_attempts ||
69644 n_offline_successes != n_offline_attempts)
69645 @@ -1974,18 +1974,18 @@ rcu_torture_init(void)
69646
69647 rcu_torture_current = NULL;
69648 rcu_torture_current_version = 0;
69649 - atomic_set(&n_rcu_torture_alloc, 0);
69650 - atomic_set(&n_rcu_torture_alloc_fail, 0);
69651 - atomic_set(&n_rcu_torture_free, 0);
69652 - atomic_set(&n_rcu_torture_mberror, 0);
69653 - atomic_set(&n_rcu_torture_error, 0);
69654 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
69655 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
69656 + atomic_set_unchecked(&n_rcu_torture_free, 0);
69657 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
69658 + atomic_set_unchecked(&n_rcu_torture_error, 0);
69659 n_rcu_torture_barrier_error = 0;
69660 n_rcu_torture_boost_ktrerror = 0;
69661 n_rcu_torture_boost_rterror = 0;
69662 n_rcu_torture_boost_failure = 0;
69663 n_rcu_torture_boosts = 0;
69664 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
69665 - atomic_set(&rcu_torture_wcount[i], 0);
69666 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
69667 for_each_possible_cpu(cpu) {
69668 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69669 per_cpu(rcu_torture_count, cpu)[i] = 0;
69670 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
69671 index f7bcd9e..8973e14 100644
69672 --- a/kernel/rcutree.c
69673 +++ b/kernel/rcutree.c
69674 @@ -369,9 +369,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
69675 rcu_prepare_for_idle(smp_processor_id());
69676 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
69677 smp_mb__before_atomic_inc(); /* See above. */
69678 - atomic_inc(&rdtp->dynticks);
69679 + atomic_inc_unchecked(&rdtp->dynticks);
69680 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
69681 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
69682 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
69683
69684 /*
69685 * The idle task is not permitted to enter the idle loop while
69686 @@ -460,10 +460,10 @@ void rcu_irq_exit(void)
69687 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
69688 {
69689 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
69690 - atomic_inc(&rdtp->dynticks);
69691 + atomic_inc_unchecked(&rdtp->dynticks);
69692 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
69693 smp_mb__after_atomic_inc(); /* See above. */
69694 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
69695 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
69696 rcu_cleanup_after_idle(smp_processor_id());
69697 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
69698 if (!is_idle_task(current)) {
69699 @@ -557,14 +557,14 @@ void rcu_nmi_enter(void)
69700 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
69701
69702 if (rdtp->dynticks_nmi_nesting == 0 &&
69703 - (atomic_read(&rdtp->dynticks) & 0x1))
69704 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
69705 return;
69706 rdtp->dynticks_nmi_nesting++;
69707 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
69708 - atomic_inc(&rdtp->dynticks);
69709 + atomic_inc_unchecked(&rdtp->dynticks);
69710 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
69711 smp_mb__after_atomic_inc(); /* See above. */
69712 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
69713 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
69714 }
69715
69716 /**
69717 @@ -583,9 +583,9 @@ void rcu_nmi_exit(void)
69718 return;
69719 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
69720 smp_mb__before_atomic_inc(); /* See above. */
69721 - atomic_inc(&rdtp->dynticks);
69722 + atomic_inc_unchecked(&rdtp->dynticks);
69723 smp_mb__after_atomic_inc(); /* Force delay to next write. */
69724 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
69725 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
69726 }
69727
69728 /**
69729 @@ -599,7 +599,7 @@ int rcu_is_cpu_idle(void)
69730 int ret;
69731
69732 preempt_disable();
69733 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
69734 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
69735 preempt_enable();
69736 return ret;
69737 }
69738 @@ -667,7 +667,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
69739 */
69740 static int dyntick_save_progress_counter(struct rcu_data *rdp)
69741 {
69742 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
69743 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
69744 return (rdp->dynticks_snap & 0x1) == 0;
69745 }
69746
69747 @@ -682,7 +682,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
69748 unsigned int curr;
69749 unsigned int snap;
69750
69751 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
69752 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
69753 snap = (unsigned int)rdp->dynticks_snap;
69754
69755 /*
69756 @@ -712,10 +712,10 @@ static int jiffies_till_stall_check(void)
69757 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
69758 */
69759 if (till_stall_check < 3) {
69760 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
69761 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
69762 till_stall_check = 3;
69763 } else if (till_stall_check > 300) {
69764 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
69765 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
69766 till_stall_check = 300;
69767 }
69768 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
69769 @@ -1351,7 +1351,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
69770 rsp->qlen += rdp->qlen;
69771 rdp->n_cbs_orphaned += rdp->qlen;
69772 rdp->qlen_lazy = 0;
69773 - ACCESS_ONCE(rdp->qlen) = 0;
69774 + ACCESS_ONCE_RW(rdp->qlen) = 0;
69775 }
69776
69777 /*
69778 @@ -1604,7 +1604,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
69779 }
69780 smp_mb(); /* List handling before counting for rcu_barrier(). */
69781 rdp->qlen_lazy -= count_lazy;
69782 - ACCESS_ONCE(rdp->qlen) -= count;
69783 + ACCESS_ONCE_RW(rdp->qlen) -= count;
69784 rdp->n_cbs_invoked += count;
69785
69786 /* Reinstate batch limit if we have worked down the excess. */
69787 @@ -1836,7 +1836,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
69788 /*
69789 * Do RCU core processing for the current CPU.
69790 */
69791 -static void rcu_process_callbacks(struct softirq_action *unused)
69792 +static void rcu_process_callbacks(void)
69793 {
69794 struct rcu_state *rsp;
69795
69796 @@ -1943,7 +1943,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
69797 rdp = this_cpu_ptr(rsp->rda);
69798
69799 /* Add the callback to our list. */
69800 - ACCESS_ONCE(rdp->qlen)++;
69801 + ACCESS_ONCE_RW(rdp->qlen)++;
69802 if (lazy)
69803 rdp->qlen_lazy++;
69804 else
69805 @@ -2057,8 +2057,8 @@ void synchronize_rcu_bh(void)
69806 }
69807 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
69808
69809 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
69810 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
69811 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
69812 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
69813
69814 static int synchronize_sched_expedited_cpu_stop(void *data)
69815 {
69816 @@ -2119,7 +2119,7 @@ void synchronize_sched_expedited(void)
69817 int firstsnap, s, snap, trycount = 0;
69818
69819 /* Note that atomic_inc_return() implies full memory barrier. */
69820 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
69821 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
69822 get_online_cpus();
69823 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
69824
69825 @@ -2141,7 +2141,7 @@ void synchronize_sched_expedited(void)
69826 }
69827
69828 /* Check to see if someone else did our work for us. */
69829 - s = atomic_read(&sync_sched_expedited_done);
69830 + s = atomic_read_unchecked(&sync_sched_expedited_done);
69831 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
69832 smp_mb(); /* ensure test happens before caller kfree */
69833 return;
69834 @@ -2156,7 +2156,7 @@ void synchronize_sched_expedited(void)
69835 * grace period works for us.
69836 */
69837 get_online_cpus();
69838 - snap = atomic_read(&sync_sched_expedited_started);
69839 + snap = atomic_read_unchecked(&sync_sched_expedited_started);
69840 smp_mb(); /* ensure read is before try_stop_cpus(). */
69841 }
69842
69843 @@ -2167,12 +2167,12 @@ void synchronize_sched_expedited(void)
69844 * than we did beat us to the punch.
69845 */
69846 do {
69847 - s = atomic_read(&sync_sched_expedited_done);
69848 + s = atomic_read_unchecked(&sync_sched_expedited_done);
69849 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
69850 smp_mb(); /* ensure test happens before caller kfree */
69851 break;
69852 }
69853 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
69854 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
69855
69856 put_online_cpus();
69857 }
69858 @@ -2366,7 +2366,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
69859 * ACCESS_ONCE() to prevent the compiler from speculating
69860 * the increment to precede the early-exit check.
69861 */
69862 - ACCESS_ONCE(rsp->n_barrier_done)++;
69863 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
69864 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
69865 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
69866 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
69867 @@ -2448,7 +2448,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
69868
69869 /* Increment ->n_barrier_done to prevent duplicate work. */
69870 smp_mb(); /* Keep increment after above mechanism. */
69871 - ACCESS_ONCE(rsp->n_barrier_done)++;
69872 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
69873 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
69874 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
69875 smp_mb(); /* Keep increment before caller's subsequent code. */
69876 @@ -2495,10 +2495,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
69877 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
69878 init_callback_list(rdp);
69879 rdp->qlen_lazy = 0;
69880 - ACCESS_ONCE(rdp->qlen) = 0;
69881 + ACCESS_ONCE_RW(rdp->qlen) = 0;
69882 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
69883 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
69884 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
69885 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
69886 rdp->cpu = cpu;
69887 rdp->rsp = rsp;
69888 raw_spin_unlock_irqrestore(&rnp->lock, flags);
69889 @@ -2526,8 +2526,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
69890 rdp->n_force_qs_snap = rsp->n_force_qs;
69891 rdp->blimit = blimit;
69892 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
69893 - atomic_set(&rdp->dynticks->dynticks,
69894 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
69895 + atomic_set_unchecked(&rdp->dynticks->dynticks,
69896 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
69897 rcu_prepare_for_idle_init(cpu);
69898 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
69899
69900 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
69901 index 4d29169..d104a3c 100644
69902 --- a/kernel/rcutree.h
69903 +++ b/kernel/rcutree.h
69904 @@ -86,7 +86,7 @@ struct rcu_dynticks {
69905 long long dynticks_nesting; /* Track irq/process nesting level. */
69906 /* Process level is worth LLONG_MAX/2. */
69907 int dynticks_nmi_nesting; /* Track NMI nesting level. */
69908 - atomic_t dynticks; /* Even value for idle, else odd. */
69909 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
69910 #ifdef CONFIG_RCU_FAST_NO_HZ
69911 int dyntick_drain; /* Prepare-for-idle state variable. */
69912 unsigned long dyntick_holdoff;
69913 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
69914 index 7f3244c..417d606 100644
69915 --- a/kernel/rcutree_plugin.h
69916 +++ b/kernel/rcutree_plugin.h
69917 @@ -843,7 +843,7 @@ void synchronize_rcu_expedited(void)
69918
69919 /* Clean up and exit. */
69920 smp_mb(); /* ensure expedited GP seen before counter increment. */
69921 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
69922 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
69923 unlock_mb_ret:
69924 mutex_unlock(&sync_rcu_preempt_exp_mutex);
69925 mb_ret:
69926 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
69927 index abffb48..cbfa6d3 100644
69928 --- a/kernel/rcutree_trace.c
69929 +++ b/kernel/rcutree_trace.c
69930 @@ -93,7 +93,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
69931 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
69932 rdp->qs_pending);
69933 seq_printf(m, " dt=%d/%llx/%d df=%lu",
69934 - atomic_read(&rdp->dynticks->dynticks),
69935 + atomic_read_unchecked(&rdp->dynticks->dynticks),
69936 rdp->dynticks->dynticks_nesting,
69937 rdp->dynticks->dynticks_nmi_nesting,
69938 rdp->dynticks_fqs);
69939 @@ -157,7 +157,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
69940 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
69941 rdp->qs_pending);
69942 seq_printf(m, ",%d,%llx,%d,%lu",
69943 - atomic_read(&rdp->dynticks->dynticks),
69944 + atomic_read_unchecked(&rdp->dynticks->dynticks),
69945 rdp->dynticks->dynticks_nesting,
69946 rdp->dynticks->dynticks_nmi_nesting,
69947 rdp->dynticks_fqs);
69948 diff --git a/kernel/resource.c b/kernel/resource.c
69949 index 34d4588..10baa6a 100644
69950 --- a/kernel/resource.c
69951 +++ b/kernel/resource.c
69952 @@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
69953
69954 static int __init ioresources_init(void)
69955 {
69956 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
69957 +#ifdef CONFIG_GRKERNSEC_PROC_USER
69958 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
69959 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
69960 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69961 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
69962 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
69963 +#endif
69964 +#else
69965 proc_create("ioports", 0, NULL, &proc_ioports_operations);
69966 proc_create("iomem", 0, NULL, &proc_iomem_operations);
69967 +#endif
69968 return 0;
69969 }
69970 __initcall(ioresources_init);
69971 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
69972 index 98ec494..4241d6d 100644
69973 --- a/kernel/rtmutex-tester.c
69974 +++ b/kernel/rtmutex-tester.c
69975 @@ -20,7 +20,7 @@
69976 #define MAX_RT_TEST_MUTEXES 8
69977
69978 static spinlock_t rttest_lock;
69979 -static atomic_t rttest_event;
69980 +static atomic_unchecked_t rttest_event;
69981
69982 struct test_thread_data {
69983 int opcode;
69984 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69985
69986 case RTTEST_LOCKCONT:
69987 td->mutexes[td->opdata] = 1;
69988 - td->event = atomic_add_return(1, &rttest_event);
69989 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69990 return 0;
69991
69992 case RTTEST_RESET:
69993 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69994 return 0;
69995
69996 case RTTEST_RESETEVENT:
69997 - atomic_set(&rttest_event, 0);
69998 + atomic_set_unchecked(&rttest_event, 0);
69999 return 0;
70000
70001 default:
70002 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70003 return ret;
70004
70005 td->mutexes[id] = 1;
70006 - td->event = atomic_add_return(1, &rttest_event);
70007 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70008 rt_mutex_lock(&mutexes[id]);
70009 - td->event = atomic_add_return(1, &rttest_event);
70010 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70011 td->mutexes[id] = 4;
70012 return 0;
70013
70014 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70015 return ret;
70016
70017 td->mutexes[id] = 1;
70018 - td->event = atomic_add_return(1, &rttest_event);
70019 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70020 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
70021 - td->event = atomic_add_return(1, &rttest_event);
70022 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70023 td->mutexes[id] = ret ? 0 : 4;
70024 return ret ? -EINTR : 0;
70025
70026 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70027 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
70028 return ret;
70029
70030 - td->event = atomic_add_return(1, &rttest_event);
70031 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70032 rt_mutex_unlock(&mutexes[id]);
70033 - td->event = atomic_add_return(1, &rttest_event);
70034 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70035 td->mutexes[id] = 0;
70036 return 0;
70037
70038 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
70039 break;
70040
70041 td->mutexes[dat] = 2;
70042 - td->event = atomic_add_return(1, &rttest_event);
70043 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70044 break;
70045
70046 default:
70047 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
70048 return;
70049
70050 td->mutexes[dat] = 3;
70051 - td->event = atomic_add_return(1, &rttest_event);
70052 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70053 break;
70054
70055 case RTTEST_LOCKNOWAIT:
70056 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
70057 return;
70058
70059 td->mutexes[dat] = 1;
70060 - td->event = atomic_add_return(1, &rttest_event);
70061 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70062 return;
70063
70064 default:
70065 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
70066 index 0984a21..939f183 100644
70067 --- a/kernel/sched/auto_group.c
70068 +++ b/kernel/sched/auto_group.c
70069 @@ -11,7 +11,7 @@
70070
70071 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
70072 static struct autogroup autogroup_default;
70073 -static atomic_t autogroup_seq_nr;
70074 +static atomic_unchecked_t autogroup_seq_nr;
70075
70076 void __init autogroup_init(struct task_struct *init_task)
70077 {
70078 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
70079
70080 kref_init(&ag->kref);
70081 init_rwsem(&ag->lock);
70082 - ag->id = atomic_inc_return(&autogroup_seq_nr);
70083 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
70084 ag->tg = tg;
70085 #ifdef CONFIG_RT_GROUP_SCHED
70086 /*
70087 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
70088 index 1a48cdb..d3949ff 100644
70089 --- a/kernel/sched/core.c
70090 +++ b/kernel/sched/core.c
70091 @@ -4103,6 +4103,8 @@ int can_nice(const struct task_struct *p, const int nice)
70092 /* convert nice value [19,-20] to rlimit style value [1,40] */
70093 int nice_rlim = 20 - nice;
70094
70095 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
70096 +
70097 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
70098 capable(CAP_SYS_NICE));
70099 }
70100 @@ -4136,7 +4138,8 @@ SYSCALL_DEFINE1(nice, int, increment)
70101 if (nice > 19)
70102 nice = 19;
70103
70104 - if (increment < 0 && !can_nice(current, nice))
70105 + if (increment < 0 && (!can_nice(current, nice) ||
70106 + gr_handle_chroot_nice()))
70107 return -EPERM;
70108
70109 retval = security_task_setnice(current, nice);
70110 @@ -4290,6 +4293,7 @@ recheck:
70111 unsigned long rlim_rtprio =
70112 task_rlimit(p, RLIMIT_RTPRIO);
70113
70114 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
70115 /* can't set/change the rt policy */
70116 if (policy != p->policy && !rlim_rtprio)
70117 return -EPERM;
70118 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
70119 index 96e2b18..bb31eec 100644
70120 --- a/kernel/sched/fair.c
70121 +++ b/kernel/sched/fair.c
70122 @@ -4923,7 +4923,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
70123 * run_rebalance_domains is triggered when needed from the scheduler tick.
70124 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
70125 */
70126 -static void run_rebalance_domains(struct softirq_action *h)
70127 +static void run_rebalance_domains(void)
70128 {
70129 int this_cpu = smp_processor_id();
70130 struct rq *this_rq = cpu_rq(this_cpu);
70131 diff --git a/kernel/signal.c b/kernel/signal.c
70132 index be4f856..453401c 100644
70133 --- a/kernel/signal.c
70134 +++ b/kernel/signal.c
70135 @@ -48,12 +48,12 @@ static struct kmem_cache *sigqueue_cachep;
70136
70137 int print_fatal_signals __read_mostly;
70138
70139 -static void __user *sig_handler(struct task_struct *t, int sig)
70140 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
70141 {
70142 return t->sighand->action[sig - 1].sa.sa_handler;
70143 }
70144
70145 -static int sig_handler_ignored(void __user *handler, int sig)
70146 +static int sig_handler_ignored(__sighandler_t handler, int sig)
70147 {
70148 /* Is it explicitly or implicitly ignored? */
70149 return handler == SIG_IGN ||
70150 @@ -62,7 +62,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
70151
70152 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
70153 {
70154 - void __user *handler;
70155 + __sighandler_t handler;
70156
70157 handler = sig_handler(t, sig);
70158
70159 @@ -366,6 +366,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
70160 atomic_inc(&user->sigpending);
70161 rcu_read_unlock();
70162
70163 + if (!override_rlimit)
70164 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
70165 +
70166 if (override_rlimit ||
70167 atomic_read(&user->sigpending) <=
70168 task_rlimit(t, RLIMIT_SIGPENDING)) {
70169 @@ -490,7 +493,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
70170
70171 int unhandled_signal(struct task_struct *tsk, int sig)
70172 {
70173 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
70174 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
70175 if (is_global_init(tsk))
70176 return 1;
70177 if (handler != SIG_IGN && handler != SIG_DFL)
70178 @@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
70179 }
70180 }
70181
70182 + /* allow glibc communication via tgkill to other threads in our
70183 + thread group */
70184 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
70185 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
70186 + && gr_handle_signal(t, sig))
70187 + return -EPERM;
70188 +
70189 return security_task_kill(t, info, sig, 0);
70190 }
70191
70192 @@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
70193 return send_signal(sig, info, p, 1);
70194 }
70195
70196 -static int
70197 +int
70198 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70199 {
70200 return send_signal(sig, info, t, 0);
70201 @@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70202 unsigned long int flags;
70203 int ret, blocked, ignored;
70204 struct k_sigaction *action;
70205 + int is_unhandled = 0;
70206
70207 spin_lock_irqsave(&t->sighand->siglock, flags);
70208 action = &t->sighand->action[sig-1];
70209 @@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70210 }
70211 if (action->sa.sa_handler == SIG_DFL)
70212 t->signal->flags &= ~SIGNAL_UNKILLABLE;
70213 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
70214 + is_unhandled = 1;
70215 ret = specific_send_sig_info(sig, info, t);
70216 spin_unlock_irqrestore(&t->sighand->siglock, flags);
70217
70218 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
70219 + normal operation */
70220 + if (is_unhandled) {
70221 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
70222 + gr_handle_crash(t, sig);
70223 + }
70224 +
70225 return ret;
70226 }
70227
70228 @@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
70229 ret = check_kill_permission(sig, info, p);
70230 rcu_read_unlock();
70231
70232 - if (!ret && sig)
70233 + if (!ret && sig) {
70234 ret = do_send_sig_info(sig, info, p, true);
70235 + if (!ret)
70236 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
70237 + }
70238
70239 return ret;
70240 }
70241 @@ -2873,7 +2896,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
70242 int error = -ESRCH;
70243
70244 rcu_read_lock();
70245 - p = find_task_by_vpid(pid);
70246 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
70247 + /* allow glibc communication via tgkill to other threads in our
70248 + thread group */
70249 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
70250 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
70251 + p = find_task_by_vpid_unrestricted(pid);
70252 + else
70253 +#endif
70254 + p = find_task_by_vpid(pid);
70255 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
70256 error = check_kill_permission(sig, info, p);
70257 /*
70258 diff --git a/kernel/softirq.c b/kernel/softirq.c
70259 index b73e681..645ab62 100644
70260 --- a/kernel/softirq.c
70261 +++ b/kernel/softirq.c
70262 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
70263
70264 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
70265
70266 -char *softirq_to_name[NR_SOFTIRQS] = {
70267 +const char * const softirq_to_name[NR_SOFTIRQS] = {
70268 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
70269 "TASKLET", "SCHED", "HRTIMER", "RCU"
70270 };
70271 @@ -243,7 +243,7 @@ restart:
70272 kstat_incr_softirqs_this_cpu(vec_nr);
70273
70274 trace_softirq_entry(vec_nr);
70275 - h->action(h);
70276 + h->action();
70277 trace_softirq_exit(vec_nr);
70278 if (unlikely(prev_count != preempt_count())) {
70279 printk(KERN_ERR "huh, entered softirq %u %s %p"
70280 @@ -390,9 +390,11 @@ void __raise_softirq_irqoff(unsigned int nr)
70281 or_softirq_pending(1UL << nr);
70282 }
70283
70284 -void open_softirq(int nr, void (*action)(struct softirq_action *))
70285 +void open_softirq(int nr, void (*action)(void))
70286 {
70287 - softirq_vec[nr].action = action;
70288 + pax_open_kernel();
70289 + *(void **)&softirq_vec[nr].action = action;
70290 + pax_close_kernel();
70291 }
70292
70293 /*
70294 @@ -446,7 +448,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
70295
70296 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
70297
70298 -static void tasklet_action(struct softirq_action *a)
70299 +static void tasklet_action(void)
70300 {
70301 struct tasklet_struct *list;
70302
70303 @@ -481,7 +483,7 @@ static void tasklet_action(struct softirq_action *a)
70304 }
70305 }
70306
70307 -static void tasklet_hi_action(struct softirq_action *a)
70308 +static void tasklet_hi_action(void)
70309 {
70310 struct tasklet_struct *list;
70311
70312 diff --git a/kernel/srcu.c b/kernel/srcu.c
70313 index 2095be3..9a5b89d 100644
70314 --- a/kernel/srcu.c
70315 +++ b/kernel/srcu.c
70316 @@ -302,9 +302,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
70317 preempt_disable();
70318 idx = rcu_dereference_index_check(sp->completed,
70319 rcu_read_lock_sched_held()) & 0x1;
70320 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
70321 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
70322 smp_mb(); /* B */ /* Avoid leaking the critical section. */
70323 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
70324 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
70325 preempt_enable();
70326 return idx;
70327 }
70328 @@ -320,7 +320,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
70329 {
70330 preempt_disable();
70331 smp_mb(); /* C */ /* Avoid leaking the critical section. */
70332 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
70333 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
70334 preempt_enable();
70335 }
70336 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
70337 diff --git a/kernel/sys.c b/kernel/sys.c
70338 index 909148a..cd51acf 100644
70339 --- a/kernel/sys.c
70340 +++ b/kernel/sys.c
70341 @@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
70342 error = -EACCES;
70343 goto out;
70344 }
70345 +
70346 + if (gr_handle_chroot_setpriority(p, niceval)) {
70347 + error = -EACCES;
70348 + goto out;
70349 + }
70350 +
70351 no_nice = security_task_setnice(p, niceval);
70352 if (no_nice) {
70353 error = no_nice;
70354 @@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
70355 goto error;
70356 }
70357
70358 + if (gr_check_group_change(new->gid, new->egid, -1))
70359 + goto error;
70360 +
70361 if (rgid != (gid_t) -1 ||
70362 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
70363 new->sgid = new->egid;
70364 @@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
70365 old = current_cred();
70366
70367 retval = -EPERM;
70368 +
70369 + if (gr_check_group_change(kgid, kgid, kgid))
70370 + goto error;
70371 +
70372 if (nsown_capable(CAP_SETGID))
70373 new->gid = new->egid = new->sgid = new->fsgid = kgid;
70374 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
70375 @@ -647,7 +660,7 @@ error:
70376 /*
70377 * change the user struct in a credentials set to match the new UID
70378 */
70379 -static int set_user(struct cred *new)
70380 +int set_user(struct cred *new)
70381 {
70382 struct user_struct *new_user;
70383
70384 @@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
70385 goto error;
70386 }
70387
70388 + if (gr_check_user_change(new->uid, new->euid, -1))
70389 + goto error;
70390 +
70391 if (!uid_eq(new->uid, old->uid)) {
70392 retval = set_user(new);
70393 if (retval < 0)
70394 @@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
70395 old = current_cred();
70396
70397 retval = -EPERM;
70398 +
70399 + if (gr_check_crash_uid(kuid))
70400 + goto error;
70401 + if (gr_check_user_change(kuid, kuid, kuid))
70402 + goto error;
70403 +
70404 if (nsown_capable(CAP_SETUID)) {
70405 new->suid = new->uid = kuid;
70406 if (!uid_eq(kuid, old->uid)) {
70407 @@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
70408 goto error;
70409 }
70410
70411 + if (gr_check_user_change(kruid, keuid, -1))
70412 + goto error;
70413 +
70414 if (ruid != (uid_t) -1) {
70415 new->uid = kruid;
70416 if (!uid_eq(kruid, old->uid)) {
70417 @@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
70418 goto error;
70419 }
70420
70421 + if (gr_check_group_change(krgid, kegid, -1))
70422 + goto error;
70423 +
70424 if (rgid != (gid_t) -1)
70425 new->gid = krgid;
70426 if (egid != (gid_t) -1)
70427 @@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70428 if (!uid_valid(kuid))
70429 return old_fsuid;
70430
70431 + if (gr_check_user_change(-1, -1, kuid))
70432 + goto error;
70433 +
70434 new = prepare_creds();
70435 if (!new)
70436 return old_fsuid;
70437 @@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70438 }
70439 }
70440
70441 +error:
70442 abort_creds(new);
70443 return old_fsuid;
70444
70445 @@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
70446 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
70447 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
70448 nsown_capable(CAP_SETGID)) {
70449 + if (gr_check_group_change(-1, -1, kgid))
70450 + goto error;
70451 +
70452 if (!gid_eq(kgid, old->fsgid)) {
70453 new->fsgid = kgid;
70454 goto change_okay;
70455 }
70456 }
70457
70458 +error:
70459 abort_creds(new);
70460 return old_fsgid;
70461
70462 @@ -1340,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
70463 return -EFAULT;
70464
70465 down_read(&uts_sem);
70466 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
70467 + error = __copy_to_user(name->sysname, &utsname()->sysname,
70468 __OLD_UTS_LEN);
70469 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
70470 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
70471 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
70472 __OLD_UTS_LEN);
70473 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
70474 - error |= __copy_to_user(&name->release, &utsname()->release,
70475 + error |= __copy_to_user(name->release, &utsname()->release,
70476 __OLD_UTS_LEN);
70477 error |= __put_user(0, name->release + __OLD_UTS_LEN);
70478 - error |= __copy_to_user(&name->version, &utsname()->version,
70479 + error |= __copy_to_user(name->version, &utsname()->version,
70480 __OLD_UTS_LEN);
70481 error |= __put_user(0, name->version + __OLD_UTS_LEN);
70482 - error |= __copy_to_user(&name->machine, &utsname()->machine,
70483 + error |= __copy_to_user(name->machine, &utsname()->machine,
70484 __OLD_UTS_LEN);
70485 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
70486 up_read(&uts_sem);
70487 @@ -2026,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
70488 error = get_dumpable(me->mm);
70489 break;
70490 case PR_SET_DUMPABLE:
70491 - if (arg2 < 0 || arg2 > 1) {
70492 + if (arg2 > 1) {
70493 error = -EINVAL;
70494 break;
70495 }
70496 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
70497 index 87174ef..68cbb82 100644
70498 --- a/kernel/sysctl.c
70499 +++ b/kernel/sysctl.c
70500 @@ -92,7 +92,6 @@
70501
70502
70503 #if defined(CONFIG_SYSCTL)
70504 -
70505 /* External variables not in a header file. */
70506 extern int sysctl_overcommit_memory;
70507 extern int sysctl_overcommit_ratio;
70508 @@ -170,10 +169,8 @@ static int proc_taint(struct ctl_table *table, int write,
70509 void __user *buffer, size_t *lenp, loff_t *ppos);
70510 #endif
70511
70512 -#ifdef CONFIG_PRINTK
70513 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70514 void __user *buffer, size_t *lenp, loff_t *ppos);
70515 -#endif
70516
70517 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
70518 void __user *buffer, size_t *lenp, loff_t *ppos);
70519 @@ -202,6 +199,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
70520
70521 #endif
70522
70523 +extern struct ctl_table grsecurity_table[];
70524 +
70525 static struct ctl_table kern_table[];
70526 static struct ctl_table vm_table[];
70527 static struct ctl_table fs_table[];
70528 @@ -216,6 +215,20 @@ extern struct ctl_table epoll_table[];
70529 int sysctl_legacy_va_layout;
70530 #endif
70531
70532 +#ifdef CONFIG_PAX_SOFTMODE
70533 +static ctl_table pax_table[] = {
70534 + {
70535 + .procname = "softmode",
70536 + .data = &pax_softmode,
70537 + .maxlen = sizeof(unsigned int),
70538 + .mode = 0600,
70539 + .proc_handler = &proc_dointvec,
70540 + },
70541 +
70542 + { }
70543 +};
70544 +#endif
70545 +
70546 /* The default sysctl tables: */
70547
70548 static struct ctl_table sysctl_base_table[] = {
70549 @@ -262,6 +275,22 @@ static int max_extfrag_threshold = 1000;
70550 #endif
70551
70552 static struct ctl_table kern_table[] = {
70553 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
70554 + {
70555 + .procname = "grsecurity",
70556 + .mode = 0500,
70557 + .child = grsecurity_table,
70558 + },
70559 +#endif
70560 +
70561 +#ifdef CONFIG_PAX_SOFTMODE
70562 + {
70563 + .procname = "pax",
70564 + .mode = 0500,
70565 + .child = pax_table,
70566 + },
70567 +#endif
70568 +
70569 {
70570 .procname = "sched_child_runs_first",
70571 .data = &sysctl_sched_child_runs_first,
70572 @@ -546,7 +575,7 @@ static struct ctl_table kern_table[] = {
70573 .data = &modprobe_path,
70574 .maxlen = KMOD_PATH_LEN,
70575 .mode = 0644,
70576 - .proc_handler = proc_dostring,
70577 + .proc_handler = proc_dostring_modpriv,
70578 },
70579 {
70580 .procname = "modules_disabled",
70581 @@ -713,16 +742,20 @@ static struct ctl_table kern_table[] = {
70582 .extra1 = &zero,
70583 .extra2 = &one,
70584 },
70585 +#endif
70586 {
70587 .procname = "kptr_restrict",
70588 .data = &kptr_restrict,
70589 .maxlen = sizeof(int),
70590 .mode = 0644,
70591 .proc_handler = proc_dointvec_minmax_sysadmin,
70592 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70593 + .extra1 = &two,
70594 +#else
70595 .extra1 = &zero,
70596 +#endif
70597 .extra2 = &two,
70598 },
70599 -#endif
70600 {
70601 .procname = "ngroups_max",
70602 .data = &ngroups_max,
70603 @@ -1219,6 +1252,13 @@ static struct ctl_table vm_table[] = {
70604 .proc_handler = proc_dointvec_minmax,
70605 .extra1 = &zero,
70606 },
70607 + {
70608 + .procname = "heap_stack_gap",
70609 + .data = &sysctl_heap_stack_gap,
70610 + .maxlen = sizeof(sysctl_heap_stack_gap),
70611 + .mode = 0644,
70612 + .proc_handler = proc_doulongvec_minmax,
70613 + },
70614 #else
70615 {
70616 .procname = "nr_trim_pages",
70617 @@ -1670,6 +1710,16 @@ int proc_dostring(struct ctl_table *table, int write,
70618 buffer, lenp, ppos);
70619 }
70620
70621 +int proc_dostring_modpriv(struct ctl_table *table, int write,
70622 + void __user *buffer, size_t *lenp, loff_t *ppos)
70623 +{
70624 + if (write && !capable(CAP_SYS_MODULE))
70625 + return -EPERM;
70626 +
70627 + return _proc_do_string(table->data, table->maxlen, write,
70628 + buffer, lenp, ppos);
70629 +}
70630 +
70631 static size_t proc_skip_spaces(char **buf)
70632 {
70633 size_t ret;
70634 @@ -1775,6 +1825,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
70635 len = strlen(tmp);
70636 if (len > *size)
70637 len = *size;
70638 + if (len > sizeof(tmp))
70639 + len = sizeof(tmp);
70640 if (copy_to_user(*buf, tmp, len))
70641 return -EFAULT;
70642 *size -= len;
70643 @@ -1967,7 +2019,6 @@ static int proc_taint(struct ctl_table *table, int write,
70644 return err;
70645 }
70646
70647 -#ifdef CONFIG_PRINTK
70648 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70649 void __user *buffer, size_t *lenp, loff_t *ppos)
70650 {
70651 @@ -1976,7 +2027,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70652
70653 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
70654 }
70655 -#endif
70656
70657 struct do_proc_dointvec_minmax_conv_param {
70658 int *min;
70659 @@ -2119,8 +2169,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
70660 *i = val;
70661 } else {
70662 val = convdiv * (*i) / convmul;
70663 - if (!first)
70664 + if (!first) {
70665 err = proc_put_char(&buffer, &left, '\t');
70666 + if (err)
70667 + break;
70668 + }
70669 err = proc_put_long(&buffer, &left, val, false);
70670 if (err)
70671 break;
70672 @@ -2512,6 +2565,12 @@ int proc_dostring(struct ctl_table *table, int write,
70673 return -ENOSYS;
70674 }
70675
70676 +int proc_dostring_modpriv(struct ctl_table *table, int write,
70677 + void __user *buffer, size_t *lenp, loff_t *ppos)
70678 +{
70679 + return -ENOSYS;
70680 +}
70681 +
70682 int proc_dointvec(struct ctl_table *table, int write,
70683 void __user *buffer, size_t *lenp, loff_t *ppos)
70684 {
70685 @@ -2568,5 +2627,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
70686 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
70687 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
70688 EXPORT_SYMBOL(proc_dostring);
70689 +EXPORT_SYMBOL(proc_dostring_modpriv);
70690 EXPORT_SYMBOL(proc_doulongvec_minmax);
70691 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
70692 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
70693 index 65bdcf1..21eb831 100644
70694 --- a/kernel/sysctl_binary.c
70695 +++ b/kernel/sysctl_binary.c
70696 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
70697 int i;
70698
70699 set_fs(KERNEL_DS);
70700 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
70701 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
70702 set_fs(old_fs);
70703 if (result < 0)
70704 goto out_kfree;
70705 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
70706 }
70707
70708 set_fs(KERNEL_DS);
70709 - result = vfs_write(file, buffer, str - buffer, &pos);
70710 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
70711 set_fs(old_fs);
70712 if (result < 0)
70713 goto out_kfree;
70714 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
70715 int i;
70716
70717 set_fs(KERNEL_DS);
70718 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
70719 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
70720 set_fs(old_fs);
70721 if (result < 0)
70722 goto out_kfree;
70723 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
70724 }
70725
70726 set_fs(KERNEL_DS);
70727 - result = vfs_write(file, buffer, str - buffer, &pos);
70728 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
70729 set_fs(old_fs);
70730 if (result < 0)
70731 goto out_kfree;
70732 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
70733 int i;
70734
70735 set_fs(KERNEL_DS);
70736 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
70737 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
70738 set_fs(old_fs);
70739 if (result < 0)
70740 goto out;
70741 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
70742 __le16 dnaddr;
70743
70744 set_fs(KERNEL_DS);
70745 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
70746 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
70747 set_fs(old_fs);
70748 if (result < 0)
70749 goto out;
70750 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
70751 le16_to_cpu(dnaddr) & 0x3ff);
70752
70753 set_fs(KERNEL_DS);
70754 - result = vfs_write(file, buf, len, &pos);
70755 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
70756 set_fs(old_fs);
70757 if (result < 0)
70758 goto out;
70759 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
70760 index d0a3279..db0ad99 100644
70761 --- a/kernel/taskstats.c
70762 +++ b/kernel/taskstats.c
70763 @@ -27,9 +27,12 @@
70764 #include <linux/cgroup.h>
70765 #include <linux/fs.h>
70766 #include <linux/file.h>
70767 +#include <linux/grsecurity.h>
70768 #include <net/genetlink.h>
70769 #include <linux/atomic.h>
70770
70771 +extern int gr_is_taskstats_denied(int pid);
70772 +
70773 /*
70774 * Maximum length of a cpumask that can be specified in
70775 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
70776 @@ -561,6 +564,9 @@ err:
70777
70778 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
70779 {
70780 + if (gr_is_taskstats_denied(current->pid))
70781 + return -EACCES;
70782 +
70783 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
70784 return cmd_attr_register_cpumask(info);
70785 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
70786 diff --git a/kernel/time.c b/kernel/time.c
70787 index ba744cf..267b7c5 100644
70788 --- a/kernel/time.c
70789 +++ b/kernel/time.c
70790 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
70791 return error;
70792
70793 if (tz) {
70794 + /* we log in do_settimeofday called below, so don't log twice
70795 + */
70796 + if (!tv)
70797 + gr_log_timechange();
70798 +
70799 sys_tz = *tz;
70800 update_vsyscall_tz();
70801 if (firsttime) {
70802 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
70803 index aa27d39..34d221c 100644
70804 --- a/kernel/time/alarmtimer.c
70805 +++ b/kernel/time/alarmtimer.c
70806 @@ -779,7 +779,7 @@ static int __init alarmtimer_init(void)
70807 struct platform_device *pdev;
70808 int error = 0;
70809 int i;
70810 - struct k_clock alarm_clock = {
70811 + static struct k_clock alarm_clock = {
70812 .clock_getres = alarm_clock_getres,
70813 .clock_get = alarm_clock_get,
70814 .timer_create = alarm_timer_create,
70815 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
70816 index f113755..ec24223 100644
70817 --- a/kernel/time/tick-broadcast.c
70818 +++ b/kernel/time/tick-broadcast.c
70819 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
70820 * then clear the broadcast bit.
70821 */
70822 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
70823 - int cpu = smp_processor_id();
70824 + cpu = smp_processor_id();
70825
70826 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
70827 tick_broadcast_clear_oneshot(cpu);
70828 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
70829 index f791637..00051de 100644
70830 --- a/kernel/time/timekeeping.c
70831 +++ b/kernel/time/timekeeping.c
70832 @@ -14,6 +14,7 @@
70833 #include <linux/init.h>
70834 #include <linux/mm.h>
70835 #include <linux/sched.h>
70836 +#include <linux/grsecurity.h>
70837 #include <linux/syscore_ops.h>
70838 #include <linux/clocksource.h>
70839 #include <linux/jiffies.h>
70840 @@ -434,6 +435,8 @@ int do_settimeofday(const struct timespec *tv)
70841 if (!timespec_valid_strict(tv))
70842 return -EINVAL;
70843
70844 + gr_log_timechange();
70845 +
70846 write_seqlock_irqsave(&tk->lock, flags);
70847
70848 timekeeping_forward_now(tk);
70849 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
70850 index af5a7e9..715611a 100644
70851 --- a/kernel/time/timer_list.c
70852 +++ b/kernel/time/timer_list.c
70853 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
70854
70855 static void print_name_offset(struct seq_file *m, void *sym)
70856 {
70857 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70858 + SEQ_printf(m, "<%p>", NULL);
70859 +#else
70860 char symname[KSYM_NAME_LEN];
70861
70862 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
70863 SEQ_printf(m, "<%pK>", sym);
70864 else
70865 SEQ_printf(m, "%s", symname);
70866 +#endif
70867 }
70868
70869 static void
70870 @@ -112,7 +116,11 @@ next_one:
70871 static void
70872 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
70873 {
70874 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70875 + SEQ_printf(m, " .base: %p\n", NULL);
70876 +#else
70877 SEQ_printf(m, " .base: %pK\n", base);
70878 +#endif
70879 SEQ_printf(m, " .index: %d\n",
70880 base->index);
70881 SEQ_printf(m, " .resolution: %Lu nsecs\n",
70882 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
70883 {
70884 struct proc_dir_entry *pe;
70885
70886 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70887 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
70888 +#else
70889 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
70890 +#endif
70891 if (!pe)
70892 return -ENOMEM;
70893 return 0;
70894 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
70895 index 0b537f2..40d6c20 100644
70896 --- a/kernel/time/timer_stats.c
70897 +++ b/kernel/time/timer_stats.c
70898 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
70899 static unsigned long nr_entries;
70900 static struct entry entries[MAX_ENTRIES];
70901
70902 -static atomic_t overflow_count;
70903 +static atomic_unchecked_t overflow_count;
70904
70905 /*
70906 * The entries are in a hash-table, for fast lookup:
70907 @@ -140,7 +140,7 @@ static void reset_entries(void)
70908 nr_entries = 0;
70909 memset(entries, 0, sizeof(entries));
70910 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
70911 - atomic_set(&overflow_count, 0);
70912 + atomic_set_unchecked(&overflow_count, 0);
70913 }
70914
70915 static struct entry *alloc_entry(void)
70916 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70917 if (likely(entry))
70918 entry->count++;
70919 else
70920 - atomic_inc(&overflow_count);
70921 + atomic_inc_unchecked(&overflow_count);
70922
70923 out_unlock:
70924 raw_spin_unlock_irqrestore(lock, flags);
70925 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70926
70927 static void print_name_offset(struct seq_file *m, unsigned long addr)
70928 {
70929 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70930 + seq_printf(m, "<%p>", NULL);
70931 +#else
70932 char symname[KSYM_NAME_LEN];
70933
70934 if (lookup_symbol_name(addr, symname) < 0)
70935 - seq_printf(m, "<%p>", (void *)addr);
70936 + seq_printf(m, "<%pK>", (void *)addr);
70937 else
70938 seq_printf(m, "%s", symname);
70939 +#endif
70940 }
70941
70942 static int tstats_show(struct seq_file *m, void *v)
70943 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
70944
70945 seq_puts(m, "Timer Stats Version: v0.2\n");
70946 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
70947 - if (atomic_read(&overflow_count))
70948 + if (atomic_read_unchecked(&overflow_count))
70949 seq_printf(m, "Overflow: %d entries\n",
70950 - atomic_read(&overflow_count));
70951 + atomic_read_unchecked(&overflow_count));
70952
70953 for (i = 0; i < nr_entries; i++) {
70954 entry = entries + i;
70955 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
70956 {
70957 struct proc_dir_entry *pe;
70958
70959 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70960 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
70961 +#else
70962 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
70963 +#endif
70964 if (!pe)
70965 return -ENOMEM;
70966 return 0;
70967 diff --git a/kernel/timer.c b/kernel/timer.c
70968 index 46ef2b1..ad081f144 100644
70969 --- a/kernel/timer.c
70970 +++ b/kernel/timer.c
70971 @@ -1377,7 +1377,7 @@ void update_process_times(int user_tick)
70972 /*
70973 * This function runs timers and the timer-tq in bottom half context.
70974 */
70975 -static void run_timer_softirq(struct softirq_action *h)
70976 +static void run_timer_softirq(void)
70977 {
70978 struct tvec_base *base = __this_cpu_read(tvec_bases);
70979
70980 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
70981 index c0bd030..62a1927 100644
70982 --- a/kernel/trace/blktrace.c
70983 +++ b/kernel/trace/blktrace.c
70984 @@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
70985 struct blk_trace *bt = filp->private_data;
70986 char buf[16];
70987
70988 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
70989 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
70990
70991 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
70992 }
70993 @@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
70994 return 1;
70995
70996 bt = buf->chan->private_data;
70997 - atomic_inc(&bt->dropped);
70998 + atomic_inc_unchecked(&bt->dropped);
70999 return 0;
71000 }
71001
71002 @@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
71003
71004 bt->dir = dir;
71005 bt->dev = dev;
71006 - atomic_set(&bt->dropped, 0);
71007 + atomic_set_unchecked(&bt->dropped, 0);
71008
71009 ret = -EIO;
71010 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
71011 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
71012 index b4f20fb..483c5fa 100644
71013 --- a/kernel/trace/ftrace.c
71014 +++ b/kernel/trace/ftrace.c
71015 @@ -1785,12 +1785,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
71016 if (unlikely(ftrace_disabled))
71017 return 0;
71018
71019 + ret = ftrace_arch_code_modify_prepare();
71020 + FTRACE_WARN_ON(ret);
71021 + if (ret)
71022 + return 0;
71023 +
71024 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
71025 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
71026 if (ret) {
71027 ftrace_bug(ret, ip);
71028 - return 0;
71029 }
71030 - return 1;
71031 + return ret ? 0 : 1;
71032 }
71033
71034 /*
71035 @@ -2885,7 +2890,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
71036
71037 int
71038 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
71039 - void *data)
71040 + void *data)
71041 {
71042 struct ftrace_func_probe *entry;
71043 struct ftrace_page *pg;
71044 @@ -3697,8 +3702,10 @@ static int ftrace_process_locs(struct module *mod,
71045 if (!count)
71046 return 0;
71047
71048 + pax_open_kernel();
71049 sort(start, count, sizeof(*start),
71050 ftrace_cmp_ips, ftrace_swap_ips);
71051 + pax_close_kernel();
71052
71053 start_pg = ftrace_allocate_pages(count);
71054 if (!start_pg)
71055 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
71056 index 5c38c81..88012af 100644
71057 --- a/kernel/trace/trace.c
71058 +++ b/kernel/trace/trace.c
71059 @@ -4437,10 +4437,9 @@ static const struct file_operations tracing_dyn_info_fops = {
71060 };
71061 #endif
71062
71063 -static struct dentry *d_tracer;
71064 -
71065 struct dentry *tracing_init_dentry(void)
71066 {
71067 + static struct dentry *d_tracer;
71068 static int once;
71069
71070 if (d_tracer)
71071 @@ -4460,10 +4459,9 @@ struct dentry *tracing_init_dentry(void)
71072 return d_tracer;
71073 }
71074
71075 -static struct dentry *d_percpu;
71076 -
71077 struct dentry *tracing_dentry_percpu(void)
71078 {
71079 + static struct dentry *d_percpu;
71080 static int once;
71081 struct dentry *d_tracer;
71082
71083 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
71084 index 29111da..d190fe2 100644
71085 --- a/kernel/trace/trace_events.c
71086 +++ b/kernel/trace/trace_events.c
71087 @@ -1308,10 +1308,6 @@ static LIST_HEAD(ftrace_module_file_list);
71088 struct ftrace_module_file_ops {
71089 struct list_head list;
71090 struct module *mod;
71091 - struct file_operations id;
71092 - struct file_operations enable;
71093 - struct file_operations format;
71094 - struct file_operations filter;
71095 };
71096
71097 static struct ftrace_module_file_ops *
71098 @@ -1332,17 +1328,12 @@ trace_create_file_ops(struct module *mod)
71099
71100 file_ops->mod = mod;
71101
71102 - file_ops->id = ftrace_event_id_fops;
71103 - file_ops->id.owner = mod;
71104 -
71105 - file_ops->enable = ftrace_enable_fops;
71106 - file_ops->enable.owner = mod;
71107 -
71108 - file_ops->filter = ftrace_event_filter_fops;
71109 - file_ops->filter.owner = mod;
71110 -
71111 - file_ops->format = ftrace_event_format_fops;
71112 - file_ops->format.owner = mod;
71113 + pax_open_kernel();
71114 + *(void **)&mod->trace_id.owner = mod;
71115 + *(void **)&mod->trace_enable.owner = mod;
71116 + *(void **)&mod->trace_filter.owner = mod;
71117 + *(void **)&mod->trace_format.owner = mod;
71118 + pax_close_kernel();
71119
71120 list_add(&file_ops->list, &ftrace_module_file_list);
71121
71122 @@ -1366,8 +1357,8 @@ static void trace_module_add_events(struct module *mod)
71123
71124 for_each_event(call, start, end) {
71125 __trace_add_event_call(*call, mod,
71126 - &file_ops->id, &file_ops->enable,
71127 - &file_ops->filter, &file_ops->format);
71128 + &mod->trace_id, &mod->trace_enable,
71129 + &mod->trace_filter, &mod->trace_format);
71130 }
71131 }
71132
71133 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
71134 index fd3c8aa..5f324a6 100644
71135 --- a/kernel/trace/trace_mmiotrace.c
71136 +++ b/kernel/trace/trace_mmiotrace.c
71137 @@ -24,7 +24,7 @@ struct header_iter {
71138 static struct trace_array *mmio_trace_array;
71139 static bool overrun_detected;
71140 static unsigned long prev_overruns;
71141 -static atomic_t dropped_count;
71142 +static atomic_unchecked_t dropped_count;
71143
71144 static void mmio_reset_data(struct trace_array *tr)
71145 {
71146 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
71147
71148 static unsigned long count_overruns(struct trace_iterator *iter)
71149 {
71150 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
71151 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
71152 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
71153
71154 if (over > prev_overruns)
71155 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
71156 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
71157 sizeof(*entry), 0, pc);
71158 if (!event) {
71159 - atomic_inc(&dropped_count);
71160 + atomic_inc_unchecked(&dropped_count);
71161 return;
71162 }
71163 entry = ring_buffer_event_data(event);
71164 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
71165 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
71166 sizeof(*entry), 0, pc);
71167 if (!event) {
71168 - atomic_inc(&dropped_count);
71169 + atomic_inc_unchecked(&dropped_count);
71170 return;
71171 }
71172 entry = ring_buffer_event_data(event);
71173 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
71174 index 123b189..97b81f5 100644
71175 --- a/kernel/trace/trace_output.c
71176 +++ b/kernel/trace/trace_output.c
71177 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
71178
71179 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
71180 if (!IS_ERR(p)) {
71181 - p = mangle_path(s->buffer + s->len, p, "\n");
71182 + p = mangle_path(s->buffer + s->len, p, "\n\\");
71183 if (p) {
71184 s->len = p - s->buffer;
71185 return 1;
71186 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
71187 index d4545f4..a9010a1 100644
71188 --- a/kernel/trace/trace_stack.c
71189 +++ b/kernel/trace/trace_stack.c
71190 @@ -53,7 +53,7 @@ static inline void check_stack(void)
71191 return;
71192
71193 /* we do not handle interrupt stacks yet */
71194 - if (!object_is_on_stack(&this_size))
71195 + if (!object_starts_on_stack(&this_size))
71196 return;
71197
71198 local_irq_save(flags);
71199 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
71200 index 872bd6d..31601a2 100644
71201 --- a/kernel/workqueue.c
71202 +++ b/kernel/workqueue.c
71203 @@ -1422,7 +1422,7 @@ retry:
71204 /* morph UNBOUND to REBIND atomically */
71205 worker_flags &= ~WORKER_UNBOUND;
71206 worker_flags |= WORKER_REBIND;
71207 - ACCESS_ONCE(worker->flags) = worker_flags;
71208 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
71209
71210 idle_rebind.cnt++;
71211 worker->idle_rebind = &idle_rebind;
71212 @@ -1448,7 +1448,7 @@ retry:
71213 /* morph UNBOUND to REBIND atomically */
71214 worker_flags &= ~WORKER_UNBOUND;
71215 worker_flags |= WORKER_REBIND;
71216 - ACCESS_ONCE(worker->flags) = worker_flags;
71217 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
71218
71219 if (test_and_set_bit(WORK_STRUCT_PENDING_BIT,
71220 work_data_bits(rebind_work)))
71221 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
71222 index 2403a63..5c4be4c 100644
71223 --- a/lib/Kconfig.debug
71224 +++ b/lib/Kconfig.debug
71225 @@ -1252,6 +1252,7 @@ config LATENCYTOP
71226 depends on DEBUG_KERNEL
71227 depends on STACKTRACE_SUPPORT
71228 depends on PROC_FS
71229 + depends on !GRKERNSEC_HIDESYM
71230 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
71231 select KALLSYMS
71232 select KALLSYMS_ALL
71233 @@ -1267,7 +1268,7 @@ source kernel/trace/Kconfig
71234
71235 config PROVIDE_OHCI1394_DMA_INIT
71236 bool "Remote debugging over FireWire early on boot"
71237 - depends on PCI && X86
71238 + depends on PCI && X86 && !GRKERNSEC
71239 help
71240 If you want to debug problems which hang or crash the kernel early
71241 on boot and the crashing machine has a FireWire port, you can use
71242 @@ -1296,7 +1297,7 @@ config PROVIDE_OHCI1394_DMA_INIT
71243
71244 config FIREWIRE_OHCI_REMOTE_DMA
71245 bool "Remote debugging over FireWire with firewire-ohci"
71246 - depends on FIREWIRE_OHCI
71247 + depends on FIREWIRE_OHCI && !GRKERNSEC
71248 help
71249 This option lets you use the FireWire bus for remote debugging
71250 with help of the firewire-ohci driver. It enables unfiltered
71251 diff --git a/lib/bitmap.c b/lib/bitmap.c
71252 index 06fdfa1..97c5c7d 100644
71253 --- a/lib/bitmap.c
71254 +++ b/lib/bitmap.c
71255 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
71256 {
71257 int c, old_c, totaldigits, ndigits, nchunks, nbits;
71258 u32 chunk;
71259 - const char __user __force *ubuf = (const char __user __force *)buf;
71260 + const char __user *ubuf = (const char __force_user *)buf;
71261
71262 bitmap_zero(maskp, nmaskbits);
71263
71264 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
71265 {
71266 if (!access_ok(VERIFY_READ, ubuf, ulen))
71267 return -EFAULT;
71268 - return __bitmap_parse((const char __force *)ubuf,
71269 + return __bitmap_parse((const char __force_kernel *)ubuf,
71270 ulen, 1, maskp, nmaskbits);
71271
71272 }
71273 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
71274 {
71275 unsigned a, b;
71276 int c, old_c, totaldigits;
71277 - const char __user __force *ubuf = (const char __user __force *)buf;
71278 + const char __user *ubuf = (const char __force_user *)buf;
71279 int exp_digit, in_range;
71280
71281 totaldigits = c = 0;
71282 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
71283 {
71284 if (!access_ok(VERIFY_READ, ubuf, ulen))
71285 return -EFAULT;
71286 - return __bitmap_parselist((const char __force *)ubuf,
71287 + return __bitmap_parselist((const char __force_kernel *)ubuf,
71288 ulen, 1, maskp, nmaskbits);
71289 }
71290 EXPORT_SYMBOL(bitmap_parselist_user);
71291 diff --git a/lib/bug.c b/lib/bug.c
71292 index a28c141..2bd3d95 100644
71293 --- a/lib/bug.c
71294 +++ b/lib/bug.c
71295 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
71296 return BUG_TRAP_TYPE_NONE;
71297
71298 bug = find_bug(bugaddr);
71299 + if (!bug)
71300 + return BUG_TRAP_TYPE_NONE;
71301
71302 file = NULL;
71303 line = 0;
71304 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
71305 index d11808c..dc2d6f8 100644
71306 --- a/lib/debugobjects.c
71307 +++ b/lib/debugobjects.c
71308 @@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
71309 if (limit > 4)
71310 return;
71311
71312 - is_on_stack = object_is_on_stack(addr);
71313 + is_on_stack = object_starts_on_stack(addr);
71314 if (is_on_stack == onstack)
71315 return;
71316
71317 diff --git a/lib/devres.c b/lib/devres.c
71318 index 80b9c76..9e32279 100644
71319 --- a/lib/devres.c
71320 +++ b/lib/devres.c
71321 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
71322 void devm_iounmap(struct device *dev, void __iomem *addr)
71323 {
71324 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
71325 - (void *)addr));
71326 + (void __force *)addr));
71327 iounmap(addr);
71328 }
71329 EXPORT_SYMBOL(devm_iounmap);
71330 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
71331 {
71332 ioport_unmap(addr);
71333 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
71334 - devm_ioport_map_match, (void *)addr));
71335 + devm_ioport_map_match, (void __force *)addr));
71336 }
71337 EXPORT_SYMBOL(devm_ioport_unmap);
71338
71339 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
71340 index 66ce414..6f0a0dd 100644
71341 --- a/lib/dma-debug.c
71342 +++ b/lib/dma-debug.c
71343 @@ -924,7 +924,7 @@ out:
71344
71345 static void check_for_stack(struct device *dev, void *addr)
71346 {
71347 - if (object_is_on_stack(addr))
71348 + if (object_starts_on_stack(addr))
71349 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
71350 "stack [addr=%p]\n", addr);
71351 }
71352 diff --git a/lib/inflate.c b/lib/inflate.c
71353 index 013a761..c28f3fc 100644
71354 --- a/lib/inflate.c
71355 +++ b/lib/inflate.c
71356 @@ -269,7 +269,7 @@ static void free(void *where)
71357 malloc_ptr = free_mem_ptr;
71358 }
71359 #else
71360 -#define malloc(a) kmalloc(a, GFP_KERNEL)
71361 +#define malloc(a) kmalloc((a), GFP_KERNEL)
71362 #define free(a) kfree(a)
71363 #endif
71364
71365 diff --git a/lib/ioremap.c b/lib/ioremap.c
71366 index 0c9216c..863bd89 100644
71367 --- a/lib/ioremap.c
71368 +++ b/lib/ioremap.c
71369 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
71370 unsigned long next;
71371
71372 phys_addr -= addr;
71373 - pmd = pmd_alloc(&init_mm, pud, addr);
71374 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
71375 if (!pmd)
71376 return -ENOMEM;
71377 do {
71378 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
71379 unsigned long next;
71380
71381 phys_addr -= addr;
71382 - pud = pud_alloc(&init_mm, pgd, addr);
71383 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
71384 if (!pud)
71385 return -ENOMEM;
71386 do {
71387 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
71388 index bd2bea9..6b3c95e 100644
71389 --- a/lib/is_single_threaded.c
71390 +++ b/lib/is_single_threaded.c
71391 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
71392 struct task_struct *p, *t;
71393 bool ret;
71394
71395 + if (!mm)
71396 + return true;
71397 +
71398 if (atomic_read(&task->signal->live) != 1)
71399 return false;
71400
71401 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
71402 index e796429..6e38f9f 100644
71403 --- a/lib/radix-tree.c
71404 +++ b/lib/radix-tree.c
71405 @@ -92,7 +92,7 @@ struct radix_tree_preload {
71406 int nr;
71407 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
71408 };
71409 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
71410 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
71411
71412 static inline void *ptr_to_indirect(void *ptr)
71413 {
71414 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
71415 index bb2b201..46abaf9 100644
71416 --- a/lib/strncpy_from_user.c
71417 +++ b/lib/strncpy_from_user.c
71418 @@ -21,7 +21,7 @@
71419 */
71420 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
71421 {
71422 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
71423 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
71424 long res = 0;
71425
71426 /*
71427 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
71428 index a28df52..3d55877 100644
71429 --- a/lib/strnlen_user.c
71430 +++ b/lib/strnlen_user.c
71431 @@ -26,7 +26,7 @@
71432 */
71433 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
71434 {
71435 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
71436 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
71437 long align, res = 0;
71438 unsigned long c;
71439
71440 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
71441 index 0e33754..50a0e63 100644
71442 --- a/lib/vsprintf.c
71443 +++ b/lib/vsprintf.c
71444 @@ -16,6 +16,9 @@
71445 * - scnprintf and vscnprintf
71446 */
71447
71448 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71449 +#define __INCLUDED_BY_HIDESYM 1
71450 +#endif
71451 #include <stdarg.h>
71452 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
71453 #include <linux/types.h>
71454 @@ -536,7 +539,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
71455 char sym[KSYM_SYMBOL_LEN];
71456 if (ext == 'B')
71457 sprint_backtrace(sym, value);
71458 - else if (ext != 'f' && ext != 's')
71459 + else if (ext != 'f' && ext != 's' && ext != 'a')
71460 sprint_symbol(sym, value);
71461 else
71462 sprint_symbol_no_offset(sym, value);
71463 @@ -969,7 +972,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
71464 return number(buf, end, *(const netdev_features_t *)addr, spec);
71465 }
71466
71467 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71468 +int kptr_restrict __read_mostly = 2;
71469 +#else
71470 int kptr_restrict __read_mostly;
71471 +#endif
71472
71473 /*
71474 * Show a '%p' thing. A kernel extension is that the '%p' is followed
71475 @@ -983,6 +990,8 @@ int kptr_restrict __read_mostly;
71476 * - 'S' For symbolic direct pointers with offset
71477 * - 's' For symbolic direct pointers without offset
71478 * - 'B' For backtraced symbolic direct pointers with offset
71479 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
71480 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
71481 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
71482 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
71483 * - 'M' For a 6-byte MAC address, it prints the address in the
71484 @@ -1038,12 +1047,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71485
71486 if (!ptr && *fmt != 'K') {
71487 /*
71488 - * Print (null) with the same width as a pointer so it makes
71489 + * Print (nil) with the same width as a pointer so it makes
71490 * tabular output look nice.
71491 */
71492 if (spec.field_width == -1)
71493 spec.field_width = default_width;
71494 - return string(buf, end, "(null)", spec);
71495 + return string(buf, end, "(nil)", spec);
71496 }
71497
71498 switch (*fmt) {
71499 @@ -1053,6 +1062,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71500 /* Fallthrough */
71501 case 'S':
71502 case 's':
71503 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71504 + break;
71505 +#else
71506 + return symbol_string(buf, end, ptr, spec, *fmt);
71507 +#endif
71508 + case 'A':
71509 + case 'a':
71510 case 'B':
71511 return symbol_string(buf, end, ptr, spec, *fmt);
71512 case 'R':
71513 @@ -1093,6 +1109,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71514 va_end(va);
71515 return buf;
71516 }
71517 + case 'P':
71518 + break;
71519 case 'K':
71520 /*
71521 * %pK cannot be used in IRQ context because its test
71522 @@ -1116,6 +1134,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71523 }
71524 break;
71525 }
71526 +
71527 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71528 + /* 'P' = approved pointers to copy to userland,
71529 + as in the /proc/kallsyms case, as we make it display nothing
71530 + for non-root users, and the real contents for root users
71531 + Also ignore 'K' pointers, since we force their NULLing for non-root users
71532 + above
71533 + */
71534 + if (ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
71535 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
71536 + dump_stack();
71537 + ptr = NULL;
71538 + }
71539 +#endif
71540 +
71541 spec.flags |= SMALL;
71542 if (spec.field_width == -1) {
71543 spec.field_width = default_width;
71544 @@ -1831,11 +1864,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
71545 typeof(type) value; \
71546 if (sizeof(type) == 8) { \
71547 args = PTR_ALIGN(args, sizeof(u32)); \
71548 - *(u32 *)&value = *(u32 *)args; \
71549 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
71550 + *(u32 *)&value = *(const u32 *)args; \
71551 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
71552 } else { \
71553 args = PTR_ALIGN(args, sizeof(type)); \
71554 - value = *(typeof(type) *)args; \
71555 + value = *(const typeof(type) *)args; \
71556 } \
71557 args += sizeof(type); \
71558 value; \
71559 @@ -1898,7 +1931,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
71560 case FORMAT_TYPE_STR: {
71561 const char *str_arg = args;
71562 args += strlen(str_arg) + 1;
71563 - str = string(str, end, (char *)str_arg, spec);
71564 + str = string(str, end, str_arg, spec);
71565 break;
71566 }
71567
71568 diff --git a/localversion-grsec b/localversion-grsec
71569 new file mode 100644
71570 index 0000000..7cd6065
71571 --- /dev/null
71572 +++ b/localversion-grsec
71573 @@ -0,0 +1 @@
71574 +-grsec
71575 diff --git a/mm/Kconfig b/mm/Kconfig
71576 index d5c8019..f513038 100644
71577 --- a/mm/Kconfig
71578 +++ b/mm/Kconfig
71579 @@ -251,10 +251,10 @@ config KSM
71580 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
71581
71582 config DEFAULT_MMAP_MIN_ADDR
71583 - int "Low address space to protect from user allocation"
71584 + int "Low address space to protect from user allocation"
71585 depends on MMU
71586 - default 4096
71587 - help
71588 + default 65536
71589 + help
71590 This is the portion of low virtual memory which should be protected
71591 from userspace allocation. Keeping a user from writing to low pages
71592 can help reduce the impact of kernel NULL pointer bugs.
71593 @@ -285,7 +285,7 @@ config MEMORY_FAILURE
71594
71595 config HWPOISON_INJECT
71596 tristate "HWPoison pages injector"
71597 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
71598 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
71599 select PROC_PAGE_MONITOR
71600
71601 config NOMMU_INITIAL_TRIM_EXCESS
71602 diff --git a/mm/filemap.c b/mm/filemap.c
71603 index 3843445..4fe6833 100644
71604 --- a/mm/filemap.c
71605 +++ b/mm/filemap.c
71606 @@ -1746,7 +1746,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
71607 struct address_space *mapping = file->f_mapping;
71608
71609 if (!mapping->a_ops->readpage)
71610 - return -ENOEXEC;
71611 + return -ENODEV;
71612 file_accessed(file);
71613 vma->vm_ops = &generic_file_vm_ops;
71614 vma->vm_flags |= VM_CAN_NONLINEAR;
71615 @@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
71616 *pos = i_size_read(inode);
71617
71618 if (limit != RLIM_INFINITY) {
71619 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
71620 if (*pos >= limit) {
71621 send_sig(SIGXFSZ, current, 0);
71622 return -EFBIG;
71623 diff --git a/mm/fremap.c b/mm/fremap.c
71624 index 9ed4fd4..c42648d 100644
71625 --- a/mm/fremap.c
71626 +++ b/mm/fremap.c
71627 @@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
71628 retry:
71629 vma = find_vma(mm, start);
71630
71631 +#ifdef CONFIG_PAX_SEGMEXEC
71632 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
71633 + goto out;
71634 +#endif
71635 +
71636 /*
71637 * Make sure the vma is shared, that it supports prefaulting,
71638 * and that the remapped range is valid and fully within
71639 diff --git a/mm/highmem.c b/mm/highmem.c
71640 index d517cd1..006a1c5 100644
71641 --- a/mm/highmem.c
71642 +++ b/mm/highmem.c
71643 @@ -137,9 +137,10 @@ static void flush_all_zero_pkmaps(void)
71644 * So no dangers, even with speculative execution.
71645 */
71646 page = pte_page(pkmap_page_table[i]);
71647 + pax_open_kernel();
71648 pte_clear(&init_mm, (unsigned long)page_address(page),
71649 &pkmap_page_table[i]);
71650 -
71651 + pax_close_kernel();
71652 set_page_address(page, NULL);
71653 need_flush = 1;
71654 }
71655 @@ -198,9 +199,11 @@ start:
71656 }
71657 }
71658 vaddr = PKMAP_ADDR(last_pkmap_nr);
71659 +
71660 + pax_open_kernel();
71661 set_pte_at(&init_mm, vaddr,
71662 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
71663 -
71664 + pax_close_kernel();
71665 pkmap_count[last_pkmap_nr] = 1;
71666 set_page_address(page, (void *)vaddr);
71667
71668 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
71669 index 141dbb6..ebff057 100644
71670 --- a/mm/huge_memory.c
71671 +++ b/mm/huge_memory.c
71672 @@ -735,7 +735,7 @@ out:
71673 * run pte_offset_map on the pmd, if an huge pmd could
71674 * materialize from under us from a different thread.
71675 */
71676 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
71677 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
71678 return VM_FAULT_OOM;
71679 /* if an huge pmd materialized from under us just retry later */
71680 if (unlikely(pmd_trans_huge(*pmd)))
71681 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
71682 index 3adceaf..dccfea3 100644
71683 --- a/mm/hugetlb.c
71684 +++ b/mm/hugetlb.c
71685 @@ -2512,6 +2512,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
71686 return 1;
71687 }
71688
71689 +#ifdef CONFIG_PAX_SEGMEXEC
71690 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
71691 +{
71692 + struct mm_struct *mm = vma->vm_mm;
71693 + struct vm_area_struct *vma_m;
71694 + unsigned long address_m;
71695 + pte_t *ptep_m;
71696 +
71697 + vma_m = pax_find_mirror_vma(vma);
71698 + if (!vma_m)
71699 + return;
71700 +
71701 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71702 + address_m = address + SEGMEXEC_TASK_SIZE;
71703 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
71704 + get_page(page_m);
71705 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
71706 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
71707 +}
71708 +#endif
71709 +
71710 /*
71711 * Hugetlb_cow() should be called with page lock of the original hugepage held.
71712 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
71713 @@ -2628,6 +2649,11 @@ retry_avoidcopy:
71714 make_huge_pte(vma, new_page, 1));
71715 page_remove_rmap(old_page);
71716 hugepage_add_new_anon_rmap(new_page, vma, address);
71717 +
71718 +#ifdef CONFIG_PAX_SEGMEXEC
71719 + pax_mirror_huge_pte(vma, address, new_page);
71720 +#endif
71721 +
71722 /* Make the old page be freed below */
71723 new_page = old_page;
71724 mmu_notifier_invalidate_range_end(mm,
71725 @@ -2786,6 +2812,10 @@ retry:
71726 && (vma->vm_flags & VM_SHARED)));
71727 set_huge_pte_at(mm, address, ptep, new_pte);
71728
71729 +#ifdef CONFIG_PAX_SEGMEXEC
71730 + pax_mirror_huge_pte(vma, address, page);
71731 +#endif
71732 +
71733 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
71734 /* Optimization, do the COW without a second fault */
71735 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
71736 @@ -2815,6 +2845,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71737 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
71738 struct hstate *h = hstate_vma(vma);
71739
71740 +#ifdef CONFIG_PAX_SEGMEXEC
71741 + struct vm_area_struct *vma_m;
71742 +#endif
71743 +
71744 address &= huge_page_mask(h);
71745
71746 ptep = huge_pte_offset(mm, address);
71747 @@ -2828,6 +2862,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71748 VM_FAULT_SET_HINDEX(hstate_index(h));
71749 }
71750
71751 +#ifdef CONFIG_PAX_SEGMEXEC
71752 + vma_m = pax_find_mirror_vma(vma);
71753 + if (vma_m) {
71754 + unsigned long address_m;
71755 +
71756 + if (vma->vm_start > vma_m->vm_start) {
71757 + address_m = address;
71758 + address -= SEGMEXEC_TASK_SIZE;
71759 + vma = vma_m;
71760 + h = hstate_vma(vma);
71761 + } else
71762 + address_m = address + SEGMEXEC_TASK_SIZE;
71763 +
71764 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
71765 + return VM_FAULT_OOM;
71766 + address_m &= HPAGE_MASK;
71767 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
71768 + }
71769 +#endif
71770 +
71771 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
71772 if (!ptep)
71773 return VM_FAULT_OOM;
71774 diff --git a/mm/internal.h b/mm/internal.h
71775 index b8c91b3..93e95a3 100644
71776 --- a/mm/internal.h
71777 +++ b/mm/internal.h
71778 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
71779 * in mm/page_alloc.c
71780 */
71781 extern void __free_pages_bootmem(struct page *page, unsigned int order);
71782 +extern void free_compound_page(struct page *page);
71783 extern void prep_compound_page(struct page *page, unsigned long order);
71784 #ifdef CONFIG_MEMORY_FAILURE
71785 extern bool is_free_buddy_page(struct page *page);
71786 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
71787 index 45eb621..6ccd8ea 100644
71788 --- a/mm/kmemleak.c
71789 +++ b/mm/kmemleak.c
71790 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
71791
71792 for (i = 0; i < object->trace_len; i++) {
71793 void *ptr = (void *)object->trace[i];
71794 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
71795 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
71796 }
71797 }
71798
71799 diff --git a/mm/maccess.c b/mm/maccess.c
71800 index d53adf9..03a24bf 100644
71801 --- a/mm/maccess.c
71802 +++ b/mm/maccess.c
71803 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
71804 set_fs(KERNEL_DS);
71805 pagefault_disable();
71806 ret = __copy_from_user_inatomic(dst,
71807 - (__force const void __user *)src, size);
71808 + (const void __force_user *)src, size);
71809 pagefault_enable();
71810 set_fs(old_fs);
71811
71812 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
71813
71814 set_fs(KERNEL_DS);
71815 pagefault_disable();
71816 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
71817 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
71818 pagefault_enable();
71819 set_fs(old_fs);
71820
71821 diff --git a/mm/madvise.c b/mm/madvise.c
71822 index 14d260f..b2a80fd 100644
71823 --- a/mm/madvise.c
71824 +++ b/mm/madvise.c
71825 @@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
71826 pgoff_t pgoff;
71827 unsigned long new_flags = vma->vm_flags;
71828
71829 +#ifdef CONFIG_PAX_SEGMEXEC
71830 + struct vm_area_struct *vma_m;
71831 +#endif
71832 +
71833 switch (behavior) {
71834 case MADV_NORMAL:
71835 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
71836 @@ -119,6 +123,13 @@ success:
71837 /*
71838 * vm_flags is protected by the mmap_sem held in write mode.
71839 */
71840 +
71841 +#ifdef CONFIG_PAX_SEGMEXEC
71842 + vma_m = pax_find_mirror_vma(vma);
71843 + if (vma_m)
71844 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
71845 +#endif
71846 +
71847 vma->vm_flags = new_flags;
71848
71849 out:
71850 @@ -177,6 +188,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
71851 struct vm_area_struct ** prev,
71852 unsigned long start, unsigned long end)
71853 {
71854 +
71855 +#ifdef CONFIG_PAX_SEGMEXEC
71856 + struct vm_area_struct *vma_m;
71857 +#endif
71858 +
71859 *prev = vma;
71860 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
71861 return -EINVAL;
71862 @@ -189,6 +205,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
71863 zap_page_range(vma, start, end - start, &details);
71864 } else
71865 zap_page_range(vma, start, end - start, NULL);
71866 +
71867 +#ifdef CONFIG_PAX_SEGMEXEC
71868 + vma_m = pax_find_mirror_vma(vma);
71869 + if (vma_m) {
71870 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
71871 + struct zap_details details = {
71872 + .nonlinear_vma = vma_m,
71873 + .last_index = ULONG_MAX,
71874 + };
71875 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
71876 + } else
71877 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
71878 + }
71879 +#endif
71880 +
71881 return 0;
71882 }
71883
71884 @@ -393,6 +424,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
71885 if (end < start)
71886 goto out;
71887
71888 +#ifdef CONFIG_PAX_SEGMEXEC
71889 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
71890 + if (end > SEGMEXEC_TASK_SIZE)
71891 + goto out;
71892 + } else
71893 +#endif
71894 +
71895 + if (end > TASK_SIZE)
71896 + goto out;
71897 +
71898 error = 0;
71899 if (end == start)
71900 goto out;
71901 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
71902 index a6e2141..eaf5aad 100644
71903 --- a/mm/memory-failure.c
71904 +++ b/mm/memory-failure.c
71905 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
71906
71907 int sysctl_memory_failure_recovery __read_mostly = 1;
71908
71909 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
71910 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
71911
71912 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
71913
71914 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
71915 pfn, t->comm, t->pid);
71916 si.si_signo = SIGBUS;
71917 si.si_errno = 0;
71918 - si.si_addr = (void *)addr;
71919 + si.si_addr = (void __user *)addr;
71920 #ifdef __ARCH_SI_TRAPNO
71921 si.si_trapno = trapno;
71922 #endif
71923 @@ -1038,7 +1038,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71924 }
71925
71926 nr_pages = 1 << compound_trans_order(hpage);
71927 - atomic_long_add(nr_pages, &mce_bad_pages);
71928 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
71929
71930 /*
71931 * We need/can do nothing about count=0 pages.
71932 @@ -1068,7 +1068,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71933 if (!PageHWPoison(hpage)
71934 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
71935 || (p != hpage && TestSetPageHWPoison(hpage))) {
71936 - atomic_long_sub(nr_pages, &mce_bad_pages);
71937 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71938 return 0;
71939 }
71940 set_page_hwpoison_huge_page(hpage);
71941 @@ -1126,7 +1126,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71942 }
71943 if (hwpoison_filter(p)) {
71944 if (TestClearPageHWPoison(p))
71945 - atomic_long_sub(nr_pages, &mce_bad_pages);
71946 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71947 unlock_page(hpage);
71948 put_page(hpage);
71949 return 0;
71950 @@ -1321,7 +1321,7 @@ int unpoison_memory(unsigned long pfn)
71951 return 0;
71952 }
71953 if (TestClearPageHWPoison(p))
71954 - atomic_long_sub(nr_pages, &mce_bad_pages);
71955 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71956 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
71957 return 0;
71958 }
71959 @@ -1335,7 +1335,7 @@ int unpoison_memory(unsigned long pfn)
71960 */
71961 if (TestClearPageHWPoison(page)) {
71962 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
71963 - atomic_long_sub(nr_pages, &mce_bad_pages);
71964 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71965 freeit = 1;
71966 if (PageHuge(page))
71967 clear_page_hwpoison_huge_page(page);
71968 @@ -1440,7 +1440,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
71969 }
71970 done:
71971 if (!PageHWPoison(hpage))
71972 - atomic_long_add(1 << compound_trans_order(hpage),
71973 + atomic_long_add_unchecked(1 << compound_trans_order(hpage),
71974 &mce_bad_pages);
71975 set_page_hwpoison_huge_page(hpage);
71976 dequeue_hwpoisoned_huge_page(hpage);
71977 @@ -1572,7 +1572,7 @@ int soft_offline_page(struct page *page, int flags)
71978 return ret;
71979
71980 done:
71981 - atomic_long_add(1, &mce_bad_pages);
71982 + atomic_long_add_unchecked(1, &mce_bad_pages);
71983 SetPageHWPoison(page);
71984 /* keep elevated page count for bad page */
71985 return ret;
71986 diff --git a/mm/memory.c b/mm/memory.c
71987 index 5736170..8e04800 100644
71988 --- a/mm/memory.c
71989 +++ b/mm/memory.c
71990 @@ -426,6 +426,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
71991 free_pte_range(tlb, pmd, addr);
71992 } while (pmd++, addr = next, addr != end);
71993
71994 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
71995 start &= PUD_MASK;
71996 if (start < floor)
71997 return;
71998 @@ -440,6 +441,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
71999 pmd = pmd_offset(pud, start);
72000 pud_clear(pud);
72001 pmd_free_tlb(tlb, pmd, start);
72002 +#endif
72003 +
72004 }
72005
72006 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
72007 @@ -459,6 +462,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
72008 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
72009 } while (pud++, addr = next, addr != end);
72010
72011 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
72012 start &= PGDIR_MASK;
72013 if (start < floor)
72014 return;
72015 @@ -473,6 +477,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
72016 pud = pud_offset(pgd, start);
72017 pgd_clear(pgd);
72018 pud_free_tlb(tlb, pud, start);
72019 +#endif
72020 +
72021 }
72022
72023 /*
72024 @@ -1614,12 +1620,6 @@ no_page_table:
72025 return page;
72026 }
72027
72028 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
72029 -{
72030 - return stack_guard_page_start(vma, addr) ||
72031 - stack_guard_page_end(vma, addr+PAGE_SIZE);
72032 -}
72033 -
72034 /**
72035 * __get_user_pages() - pin user pages in memory
72036 * @tsk: task_struct of target task
72037 @@ -1692,10 +1692,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
72038 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
72039 i = 0;
72040
72041 - do {
72042 + while (nr_pages) {
72043 struct vm_area_struct *vma;
72044
72045 - vma = find_extend_vma(mm, start);
72046 + vma = find_vma(mm, start);
72047 if (!vma && in_gate_area(mm, start)) {
72048 unsigned long pg = start & PAGE_MASK;
72049 pgd_t *pgd;
72050 @@ -1743,7 +1743,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
72051 goto next_page;
72052 }
72053
72054 - if (!vma ||
72055 + if (!vma || start < vma->vm_start ||
72056 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
72057 !(vm_flags & vma->vm_flags))
72058 return i ? : -EFAULT;
72059 @@ -1770,11 +1770,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
72060 int ret;
72061 unsigned int fault_flags = 0;
72062
72063 - /* For mlock, just skip the stack guard page. */
72064 - if (foll_flags & FOLL_MLOCK) {
72065 - if (stack_guard_page(vma, start))
72066 - goto next_page;
72067 - }
72068 if (foll_flags & FOLL_WRITE)
72069 fault_flags |= FAULT_FLAG_WRITE;
72070 if (nonblocking)
72071 @@ -1848,7 +1843,7 @@ next_page:
72072 start += PAGE_SIZE;
72073 nr_pages--;
72074 } while (nr_pages && start < vma->vm_end);
72075 - } while (nr_pages);
72076 + }
72077 return i;
72078 }
72079 EXPORT_SYMBOL(__get_user_pages);
72080 @@ -2055,6 +2050,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
72081 page_add_file_rmap(page);
72082 set_pte_at(mm, addr, pte, mk_pte(page, prot));
72083
72084 +#ifdef CONFIG_PAX_SEGMEXEC
72085 + pax_mirror_file_pte(vma, addr, page, ptl);
72086 +#endif
72087 +
72088 retval = 0;
72089 pte_unmap_unlock(pte, ptl);
72090 return retval;
72091 @@ -2089,10 +2088,22 @@ out:
72092 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
72093 struct page *page)
72094 {
72095 +
72096 +#ifdef CONFIG_PAX_SEGMEXEC
72097 + struct vm_area_struct *vma_m;
72098 +#endif
72099 +
72100 if (addr < vma->vm_start || addr >= vma->vm_end)
72101 return -EFAULT;
72102 if (!page_count(page))
72103 return -EINVAL;
72104 +
72105 +#ifdef CONFIG_PAX_SEGMEXEC
72106 + vma_m = pax_find_mirror_vma(vma);
72107 + if (vma_m)
72108 + vma_m->vm_flags |= VM_INSERTPAGE;
72109 +#endif
72110 +
72111 vma->vm_flags |= VM_INSERTPAGE;
72112 return insert_page(vma, addr, page, vma->vm_page_prot);
72113 }
72114 @@ -2178,6 +2189,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
72115 unsigned long pfn)
72116 {
72117 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
72118 + BUG_ON(vma->vm_mirror);
72119
72120 if (addr < vma->vm_start || addr >= vma->vm_end)
72121 return -EFAULT;
72122 @@ -2385,7 +2397,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
72123
72124 BUG_ON(pud_huge(*pud));
72125
72126 - pmd = pmd_alloc(mm, pud, addr);
72127 + pmd = (mm == &init_mm) ?
72128 + pmd_alloc_kernel(mm, pud, addr) :
72129 + pmd_alloc(mm, pud, addr);
72130 if (!pmd)
72131 return -ENOMEM;
72132 do {
72133 @@ -2405,7 +2419,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
72134 unsigned long next;
72135 int err;
72136
72137 - pud = pud_alloc(mm, pgd, addr);
72138 + pud = (mm == &init_mm) ?
72139 + pud_alloc_kernel(mm, pgd, addr) :
72140 + pud_alloc(mm, pgd, addr);
72141 if (!pud)
72142 return -ENOMEM;
72143 do {
72144 @@ -2493,6 +2509,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
72145 copy_user_highpage(dst, src, va, vma);
72146 }
72147
72148 +#ifdef CONFIG_PAX_SEGMEXEC
72149 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
72150 +{
72151 + struct mm_struct *mm = vma->vm_mm;
72152 + spinlock_t *ptl;
72153 + pte_t *pte, entry;
72154 +
72155 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
72156 + entry = *pte;
72157 + if (!pte_present(entry)) {
72158 + if (!pte_none(entry)) {
72159 + BUG_ON(pte_file(entry));
72160 + free_swap_and_cache(pte_to_swp_entry(entry));
72161 + pte_clear_not_present_full(mm, address, pte, 0);
72162 + }
72163 + } else {
72164 + struct page *page;
72165 +
72166 + flush_cache_page(vma, address, pte_pfn(entry));
72167 + entry = ptep_clear_flush(vma, address, pte);
72168 + BUG_ON(pte_dirty(entry));
72169 + page = vm_normal_page(vma, address, entry);
72170 + if (page) {
72171 + update_hiwater_rss(mm);
72172 + if (PageAnon(page))
72173 + dec_mm_counter_fast(mm, MM_ANONPAGES);
72174 + else
72175 + dec_mm_counter_fast(mm, MM_FILEPAGES);
72176 + page_remove_rmap(page);
72177 + page_cache_release(page);
72178 + }
72179 + }
72180 + pte_unmap_unlock(pte, ptl);
72181 +}
72182 +
72183 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
72184 + *
72185 + * the ptl of the lower mapped page is held on entry and is not released on exit
72186 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
72187 + */
72188 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
72189 +{
72190 + struct mm_struct *mm = vma->vm_mm;
72191 + unsigned long address_m;
72192 + spinlock_t *ptl_m;
72193 + struct vm_area_struct *vma_m;
72194 + pmd_t *pmd_m;
72195 + pte_t *pte_m, entry_m;
72196 +
72197 + BUG_ON(!page_m || !PageAnon(page_m));
72198 +
72199 + vma_m = pax_find_mirror_vma(vma);
72200 + if (!vma_m)
72201 + return;
72202 +
72203 + BUG_ON(!PageLocked(page_m));
72204 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72205 + address_m = address + SEGMEXEC_TASK_SIZE;
72206 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72207 + pte_m = pte_offset_map(pmd_m, address_m);
72208 + ptl_m = pte_lockptr(mm, pmd_m);
72209 + if (ptl != ptl_m) {
72210 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72211 + if (!pte_none(*pte_m))
72212 + goto out;
72213 + }
72214 +
72215 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
72216 + page_cache_get(page_m);
72217 + page_add_anon_rmap(page_m, vma_m, address_m);
72218 + inc_mm_counter_fast(mm, MM_ANONPAGES);
72219 + set_pte_at(mm, address_m, pte_m, entry_m);
72220 + update_mmu_cache(vma_m, address_m, entry_m);
72221 +out:
72222 + if (ptl != ptl_m)
72223 + spin_unlock(ptl_m);
72224 + pte_unmap(pte_m);
72225 + unlock_page(page_m);
72226 +}
72227 +
72228 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
72229 +{
72230 + struct mm_struct *mm = vma->vm_mm;
72231 + unsigned long address_m;
72232 + spinlock_t *ptl_m;
72233 + struct vm_area_struct *vma_m;
72234 + pmd_t *pmd_m;
72235 + pte_t *pte_m, entry_m;
72236 +
72237 + BUG_ON(!page_m || PageAnon(page_m));
72238 +
72239 + vma_m = pax_find_mirror_vma(vma);
72240 + if (!vma_m)
72241 + return;
72242 +
72243 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72244 + address_m = address + SEGMEXEC_TASK_SIZE;
72245 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72246 + pte_m = pte_offset_map(pmd_m, address_m);
72247 + ptl_m = pte_lockptr(mm, pmd_m);
72248 + if (ptl != ptl_m) {
72249 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72250 + if (!pte_none(*pte_m))
72251 + goto out;
72252 + }
72253 +
72254 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
72255 + page_cache_get(page_m);
72256 + page_add_file_rmap(page_m);
72257 + inc_mm_counter_fast(mm, MM_FILEPAGES);
72258 + set_pte_at(mm, address_m, pte_m, entry_m);
72259 + update_mmu_cache(vma_m, address_m, entry_m);
72260 +out:
72261 + if (ptl != ptl_m)
72262 + spin_unlock(ptl_m);
72263 + pte_unmap(pte_m);
72264 +}
72265 +
72266 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
72267 +{
72268 + struct mm_struct *mm = vma->vm_mm;
72269 + unsigned long address_m;
72270 + spinlock_t *ptl_m;
72271 + struct vm_area_struct *vma_m;
72272 + pmd_t *pmd_m;
72273 + pte_t *pte_m, entry_m;
72274 +
72275 + vma_m = pax_find_mirror_vma(vma);
72276 + if (!vma_m)
72277 + return;
72278 +
72279 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72280 + address_m = address + SEGMEXEC_TASK_SIZE;
72281 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72282 + pte_m = pte_offset_map(pmd_m, address_m);
72283 + ptl_m = pte_lockptr(mm, pmd_m);
72284 + if (ptl != ptl_m) {
72285 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72286 + if (!pte_none(*pte_m))
72287 + goto out;
72288 + }
72289 +
72290 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
72291 + set_pte_at(mm, address_m, pte_m, entry_m);
72292 +out:
72293 + if (ptl != ptl_m)
72294 + spin_unlock(ptl_m);
72295 + pte_unmap(pte_m);
72296 +}
72297 +
72298 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
72299 +{
72300 + struct page *page_m;
72301 + pte_t entry;
72302 +
72303 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
72304 + goto out;
72305 +
72306 + entry = *pte;
72307 + page_m = vm_normal_page(vma, address, entry);
72308 + if (!page_m)
72309 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
72310 + else if (PageAnon(page_m)) {
72311 + if (pax_find_mirror_vma(vma)) {
72312 + pte_unmap_unlock(pte, ptl);
72313 + lock_page(page_m);
72314 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
72315 + if (pte_same(entry, *pte))
72316 + pax_mirror_anon_pte(vma, address, page_m, ptl);
72317 + else
72318 + unlock_page(page_m);
72319 + }
72320 + } else
72321 + pax_mirror_file_pte(vma, address, page_m, ptl);
72322 +
72323 +out:
72324 + pte_unmap_unlock(pte, ptl);
72325 +}
72326 +#endif
72327 +
72328 /*
72329 * This routine handles present pages, when users try to write
72330 * to a shared page. It is done by copying the page to a new address
72331 @@ -2703,6 +2899,12 @@ gotten:
72332 */
72333 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72334 if (likely(pte_same(*page_table, orig_pte))) {
72335 +
72336 +#ifdef CONFIG_PAX_SEGMEXEC
72337 + if (pax_find_mirror_vma(vma))
72338 + BUG_ON(!trylock_page(new_page));
72339 +#endif
72340 +
72341 if (old_page) {
72342 if (!PageAnon(old_page)) {
72343 dec_mm_counter_fast(mm, MM_FILEPAGES);
72344 @@ -2754,6 +2956,10 @@ gotten:
72345 page_remove_rmap(old_page);
72346 }
72347
72348 +#ifdef CONFIG_PAX_SEGMEXEC
72349 + pax_mirror_anon_pte(vma, address, new_page, ptl);
72350 +#endif
72351 +
72352 /* Free the old page.. */
72353 new_page = old_page;
72354 ret |= VM_FAULT_WRITE;
72355 @@ -3033,6 +3239,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72356 swap_free(entry);
72357 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
72358 try_to_free_swap(page);
72359 +
72360 +#ifdef CONFIG_PAX_SEGMEXEC
72361 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
72362 +#endif
72363 +
72364 unlock_page(page);
72365 if (swapcache) {
72366 /*
72367 @@ -3056,6 +3267,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72368
72369 /* No need to invalidate - it was non-present before */
72370 update_mmu_cache(vma, address, page_table);
72371 +
72372 +#ifdef CONFIG_PAX_SEGMEXEC
72373 + pax_mirror_anon_pte(vma, address, page, ptl);
72374 +#endif
72375 +
72376 unlock:
72377 pte_unmap_unlock(page_table, ptl);
72378 out:
72379 @@ -3075,40 +3291,6 @@ out_release:
72380 }
72381
72382 /*
72383 - * This is like a special single-page "expand_{down|up}wards()",
72384 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
72385 - * doesn't hit another vma.
72386 - */
72387 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
72388 -{
72389 - address &= PAGE_MASK;
72390 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
72391 - struct vm_area_struct *prev = vma->vm_prev;
72392 -
72393 - /*
72394 - * Is there a mapping abutting this one below?
72395 - *
72396 - * That's only ok if it's the same stack mapping
72397 - * that has gotten split..
72398 - */
72399 - if (prev && prev->vm_end == address)
72400 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
72401 -
72402 - expand_downwards(vma, address - PAGE_SIZE);
72403 - }
72404 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
72405 - struct vm_area_struct *next = vma->vm_next;
72406 -
72407 - /* As VM_GROWSDOWN but s/below/above/ */
72408 - if (next && next->vm_start == address + PAGE_SIZE)
72409 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
72410 -
72411 - expand_upwards(vma, address + PAGE_SIZE);
72412 - }
72413 - return 0;
72414 -}
72415 -
72416 -/*
72417 * We enter with non-exclusive mmap_sem (to exclude vma changes,
72418 * but allow concurrent faults), and pte mapped but not yet locked.
72419 * We return with mmap_sem still held, but pte unmapped and unlocked.
72420 @@ -3117,27 +3299,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
72421 unsigned long address, pte_t *page_table, pmd_t *pmd,
72422 unsigned int flags)
72423 {
72424 - struct page *page;
72425 + struct page *page = NULL;
72426 spinlock_t *ptl;
72427 pte_t entry;
72428
72429 - pte_unmap(page_table);
72430 -
72431 - /* Check if we need to add a guard page to the stack */
72432 - if (check_stack_guard_page(vma, address) < 0)
72433 - return VM_FAULT_SIGBUS;
72434 -
72435 - /* Use the zero-page for reads */
72436 if (!(flags & FAULT_FLAG_WRITE)) {
72437 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
72438 vma->vm_page_prot));
72439 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72440 + ptl = pte_lockptr(mm, pmd);
72441 + spin_lock(ptl);
72442 if (!pte_none(*page_table))
72443 goto unlock;
72444 goto setpte;
72445 }
72446
72447 /* Allocate our own private page. */
72448 + pte_unmap(page_table);
72449 +
72450 if (unlikely(anon_vma_prepare(vma)))
72451 goto oom;
72452 page = alloc_zeroed_user_highpage_movable(vma, address);
72453 @@ -3156,6 +3334,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
72454 if (!pte_none(*page_table))
72455 goto release;
72456
72457 +#ifdef CONFIG_PAX_SEGMEXEC
72458 + if (pax_find_mirror_vma(vma))
72459 + BUG_ON(!trylock_page(page));
72460 +#endif
72461 +
72462 inc_mm_counter_fast(mm, MM_ANONPAGES);
72463 page_add_new_anon_rmap(page, vma, address);
72464 setpte:
72465 @@ -3163,6 +3346,12 @@ setpte:
72466
72467 /* No need to invalidate - it was non-present before */
72468 update_mmu_cache(vma, address, page_table);
72469 +
72470 +#ifdef CONFIG_PAX_SEGMEXEC
72471 + if (page)
72472 + pax_mirror_anon_pte(vma, address, page, ptl);
72473 +#endif
72474 +
72475 unlock:
72476 pte_unmap_unlock(page_table, ptl);
72477 return 0;
72478 @@ -3306,6 +3495,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72479 */
72480 /* Only go through if we didn't race with anybody else... */
72481 if (likely(pte_same(*page_table, orig_pte))) {
72482 +
72483 +#ifdef CONFIG_PAX_SEGMEXEC
72484 + if (anon && pax_find_mirror_vma(vma))
72485 + BUG_ON(!trylock_page(page));
72486 +#endif
72487 +
72488 flush_icache_page(vma, page);
72489 entry = mk_pte(page, vma->vm_page_prot);
72490 if (flags & FAULT_FLAG_WRITE)
72491 @@ -3325,6 +3520,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72492
72493 /* no need to invalidate: a not-present page won't be cached */
72494 update_mmu_cache(vma, address, page_table);
72495 +
72496 +#ifdef CONFIG_PAX_SEGMEXEC
72497 + if (anon)
72498 + pax_mirror_anon_pte(vma, address, page, ptl);
72499 + else
72500 + pax_mirror_file_pte(vma, address, page, ptl);
72501 +#endif
72502 +
72503 } else {
72504 if (cow_page)
72505 mem_cgroup_uncharge_page(cow_page);
72506 @@ -3479,6 +3682,12 @@ int handle_pte_fault(struct mm_struct *mm,
72507 if (flags & FAULT_FLAG_WRITE)
72508 flush_tlb_fix_spurious_fault(vma, address);
72509 }
72510 +
72511 +#ifdef CONFIG_PAX_SEGMEXEC
72512 + pax_mirror_pte(vma, address, pte, pmd, ptl);
72513 + return 0;
72514 +#endif
72515 +
72516 unlock:
72517 pte_unmap_unlock(pte, ptl);
72518 return 0;
72519 @@ -3495,6 +3704,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72520 pmd_t *pmd;
72521 pte_t *pte;
72522
72523 +#ifdef CONFIG_PAX_SEGMEXEC
72524 + struct vm_area_struct *vma_m;
72525 +#endif
72526 +
72527 __set_current_state(TASK_RUNNING);
72528
72529 count_vm_event(PGFAULT);
72530 @@ -3506,6 +3719,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72531 if (unlikely(is_vm_hugetlb_page(vma)))
72532 return hugetlb_fault(mm, vma, address, flags);
72533
72534 +#ifdef CONFIG_PAX_SEGMEXEC
72535 + vma_m = pax_find_mirror_vma(vma);
72536 + if (vma_m) {
72537 + unsigned long address_m;
72538 + pgd_t *pgd_m;
72539 + pud_t *pud_m;
72540 + pmd_t *pmd_m;
72541 +
72542 + if (vma->vm_start > vma_m->vm_start) {
72543 + address_m = address;
72544 + address -= SEGMEXEC_TASK_SIZE;
72545 + vma = vma_m;
72546 + } else
72547 + address_m = address + SEGMEXEC_TASK_SIZE;
72548 +
72549 + pgd_m = pgd_offset(mm, address_m);
72550 + pud_m = pud_alloc(mm, pgd_m, address_m);
72551 + if (!pud_m)
72552 + return VM_FAULT_OOM;
72553 + pmd_m = pmd_alloc(mm, pud_m, address_m);
72554 + if (!pmd_m)
72555 + return VM_FAULT_OOM;
72556 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
72557 + return VM_FAULT_OOM;
72558 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
72559 + }
72560 +#endif
72561 +
72562 retry:
72563 pgd = pgd_offset(mm, address);
72564 pud = pud_alloc(mm, pgd, address);
72565 @@ -3547,7 +3788,7 @@ retry:
72566 * run pte_offset_map on the pmd, if an huge pmd could
72567 * materialize from under us from a different thread.
72568 */
72569 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
72570 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
72571 return VM_FAULT_OOM;
72572 /* if an huge pmd materialized from under us just retry later */
72573 if (unlikely(pmd_trans_huge(*pmd)))
72574 @@ -3584,6 +3825,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
72575 spin_unlock(&mm->page_table_lock);
72576 return 0;
72577 }
72578 +
72579 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
72580 +{
72581 + pud_t *new = pud_alloc_one(mm, address);
72582 + if (!new)
72583 + return -ENOMEM;
72584 +
72585 + smp_wmb(); /* See comment in __pte_alloc */
72586 +
72587 + spin_lock(&mm->page_table_lock);
72588 + if (pgd_present(*pgd)) /* Another has populated it */
72589 + pud_free(mm, new);
72590 + else
72591 + pgd_populate_kernel(mm, pgd, new);
72592 + spin_unlock(&mm->page_table_lock);
72593 + return 0;
72594 +}
72595 #endif /* __PAGETABLE_PUD_FOLDED */
72596
72597 #ifndef __PAGETABLE_PMD_FOLDED
72598 @@ -3614,6 +3872,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
72599 spin_unlock(&mm->page_table_lock);
72600 return 0;
72601 }
72602 +
72603 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
72604 +{
72605 + pmd_t *new = pmd_alloc_one(mm, address);
72606 + if (!new)
72607 + return -ENOMEM;
72608 +
72609 + smp_wmb(); /* See comment in __pte_alloc */
72610 +
72611 + spin_lock(&mm->page_table_lock);
72612 +#ifndef __ARCH_HAS_4LEVEL_HACK
72613 + if (pud_present(*pud)) /* Another has populated it */
72614 + pmd_free(mm, new);
72615 + else
72616 + pud_populate_kernel(mm, pud, new);
72617 +#else
72618 + if (pgd_present(*pud)) /* Another has populated it */
72619 + pmd_free(mm, new);
72620 + else
72621 + pgd_populate_kernel(mm, pud, new);
72622 +#endif /* __ARCH_HAS_4LEVEL_HACK */
72623 + spin_unlock(&mm->page_table_lock);
72624 + return 0;
72625 +}
72626 #endif /* __PAGETABLE_PMD_FOLDED */
72627
72628 int make_pages_present(unsigned long addr, unsigned long end)
72629 @@ -3651,7 +3933,7 @@ static int __init gate_vma_init(void)
72630 gate_vma.vm_start = FIXADDR_USER_START;
72631 gate_vma.vm_end = FIXADDR_USER_END;
72632 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
72633 - gate_vma.vm_page_prot = __P101;
72634 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
72635
72636 return 0;
72637 }
72638 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
72639 index 3d64b36..c6ab69c 100644
72640 --- a/mm/mempolicy.c
72641 +++ b/mm/mempolicy.c
72642 @@ -655,6 +655,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
72643 unsigned long vmstart;
72644 unsigned long vmend;
72645
72646 +#ifdef CONFIG_PAX_SEGMEXEC
72647 + struct vm_area_struct *vma_m;
72648 +#endif
72649 +
72650 vma = find_vma(mm, start);
72651 if (!vma || vma->vm_start > start)
72652 return -EFAULT;
72653 @@ -691,9 +695,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
72654 if (err)
72655 goto out;
72656 }
72657 +
72658 err = vma_replace_policy(vma, new_pol);
72659 if (err)
72660 goto out;
72661 +
72662 +#ifdef CONFIG_PAX_SEGMEXEC
72663 + vma_m = pax_find_mirror_vma(vma);
72664 + if (vma_m) {
72665 + err = vma_replace_policy(vma_m, new_pol);
72666 + if (err)
72667 + goto out;
72668 + }
72669 +#endif
72670 +
72671 }
72672
72673 out:
72674 @@ -1147,6 +1162,17 @@ static long do_mbind(unsigned long start, unsigned long len,
72675
72676 if (end < start)
72677 return -EINVAL;
72678 +
72679 +#ifdef CONFIG_PAX_SEGMEXEC
72680 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
72681 + if (end > SEGMEXEC_TASK_SIZE)
72682 + return -EINVAL;
72683 + } else
72684 +#endif
72685 +
72686 + if (end > TASK_SIZE)
72687 + return -EINVAL;
72688 +
72689 if (end == start)
72690 return 0;
72691
72692 @@ -1370,8 +1396,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
72693 */
72694 tcred = __task_cred(task);
72695 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
72696 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
72697 - !capable(CAP_SYS_NICE)) {
72698 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
72699 rcu_read_unlock();
72700 err = -EPERM;
72701 goto out_put;
72702 @@ -1402,6 +1427,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
72703 goto out;
72704 }
72705
72706 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
72707 + if (mm != current->mm &&
72708 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
72709 + mmput(mm);
72710 + err = -EPERM;
72711 + goto out;
72712 + }
72713 +#endif
72714 +
72715 err = do_migrate_pages(mm, old, new,
72716 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
72717
72718 diff --git a/mm/migrate.c b/mm/migrate.c
72719 index 77ed2d7..317d528 100644
72720 --- a/mm/migrate.c
72721 +++ b/mm/migrate.c
72722 @@ -1350,8 +1350,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
72723 */
72724 tcred = __task_cred(task);
72725 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
72726 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
72727 - !capable(CAP_SYS_NICE)) {
72728 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
72729 rcu_read_unlock();
72730 err = -EPERM;
72731 goto out;
72732 diff --git a/mm/mlock.c b/mm/mlock.c
72733 index ef726e8..cd7f1ec 100644
72734 --- a/mm/mlock.c
72735 +++ b/mm/mlock.c
72736 @@ -13,6 +13,7 @@
72737 #include <linux/pagemap.h>
72738 #include <linux/mempolicy.h>
72739 #include <linux/syscalls.h>
72740 +#include <linux/security.h>
72741 #include <linux/sched.h>
72742 #include <linux/export.h>
72743 #include <linux/rmap.h>
72744 @@ -376,7 +377,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
72745 {
72746 unsigned long nstart, end, tmp;
72747 struct vm_area_struct * vma, * prev;
72748 - int error;
72749 + int error = 0;
72750
72751 VM_BUG_ON(start & ~PAGE_MASK);
72752 VM_BUG_ON(len != PAGE_ALIGN(len));
72753 @@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
72754 return -EINVAL;
72755 if (end == start)
72756 return 0;
72757 + if (end > TASK_SIZE)
72758 + return -EINVAL;
72759 +
72760 vma = find_vma(current->mm, start);
72761 if (!vma || vma->vm_start > start)
72762 return -ENOMEM;
72763 @@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
72764 for (nstart = start ; ; ) {
72765 vm_flags_t newflags;
72766
72767 +#ifdef CONFIG_PAX_SEGMEXEC
72768 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72769 + break;
72770 +#endif
72771 +
72772 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
72773
72774 newflags = vma->vm_flags | VM_LOCKED;
72775 @@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
72776 lock_limit >>= PAGE_SHIFT;
72777
72778 /* check against resource limits */
72779 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
72780 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
72781 error = do_mlock(start, len, 1);
72782 up_write(&current->mm->mmap_sem);
72783 @@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
72784 static int do_mlockall(int flags)
72785 {
72786 struct vm_area_struct * vma, * prev = NULL;
72787 - unsigned int def_flags = 0;
72788
72789 if (flags & MCL_FUTURE)
72790 - def_flags = VM_LOCKED;
72791 - current->mm->def_flags = def_flags;
72792 + current->mm->def_flags |= VM_LOCKED;
72793 + else
72794 + current->mm->def_flags &= ~VM_LOCKED;
72795 if (flags == MCL_FUTURE)
72796 goto out;
72797
72798 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
72799 vm_flags_t newflags;
72800
72801 +#ifdef CONFIG_PAX_SEGMEXEC
72802 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72803 + break;
72804 +#endif
72805 +
72806 + BUG_ON(vma->vm_end > TASK_SIZE);
72807 newflags = vma->vm_flags | VM_LOCKED;
72808 if (!(flags & MCL_CURRENT))
72809 newflags &= ~VM_LOCKED;
72810 @@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
72811 lock_limit >>= PAGE_SHIFT;
72812
72813 ret = -ENOMEM;
72814 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
72815 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
72816 capable(CAP_IPC_LOCK))
72817 ret = do_mlockall(flags);
72818 diff --git a/mm/mmap.c b/mm/mmap.c
72819 index ae18a48..86cf99e 100644
72820 --- a/mm/mmap.c
72821 +++ b/mm/mmap.c
72822 @@ -47,6 +47,16 @@
72823 #define arch_rebalance_pgtables(addr, len) (addr)
72824 #endif
72825
72826 +static inline void verify_mm_writelocked(struct mm_struct *mm)
72827 +{
72828 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
72829 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
72830 + up_read(&mm->mmap_sem);
72831 + BUG();
72832 + }
72833 +#endif
72834 +}
72835 +
72836 static void unmap_region(struct mm_struct *mm,
72837 struct vm_area_struct *vma, struct vm_area_struct *prev,
72838 unsigned long start, unsigned long end);
72839 @@ -72,22 +82,32 @@ static void unmap_region(struct mm_struct *mm,
72840 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
72841 *
72842 */
72843 -pgprot_t protection_map[16] = {
72844 +pgprot_t protection_map[16] __read_only = {
72845 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
72846 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
72847 };
72848
72849 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
72850 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
72851 {
72852 - return __pgprot(pgprot_val(protection_map[vm_flags &
72853 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
72854 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
72855 pgprot_val(arch_vm_get_page_prot(vm_flags)));
72856 +
72857 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72858 + if (!(__supported_pte_mask & _PAGE_NX) &&
72859 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
72860 + (vm_flags & (VM_READ | VM_WRITE)))
72861 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
72862 +#endif
72863 +
72864 + return prot;
72865 }
72866 EXPORT_SYMBOL(vm_get_page_prot);
72867
72868 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
72869 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
72870 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
72871 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
72872 /*
72873 * Make sure vm_committed_as in one cacheline and not cacheline shared with
72874 * other variables. It can be updated by several CPUs frequently.
72875 @@ -229,6 +249,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
72876 struct vm_area_struct *next = vma->vm_next;
72877
72878 might_sleep();
72879 + BUG_ON(vma->vm_mirror);
72880 if (vma->vm_ops && vma->vm_ops->close)
72881 vma->vm_ops->close(vma);
72882 if (vma->vm_file) {
72883 @@ -275,6 +296,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
72884 * not page aligned -Ram Gupta
72885 */
72886 rlim = rlimit(RLIMIT_DATA);
72887 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
72888 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
72889 (mm->end_data - mm->start_data) > rlim)
72890 goto out;
72891 @@ -708,6 +730,12 @@ static int
72892 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
72893 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72894 {
72895 +
72896 +#ifdef CONFIG_PAX_SEGMEXEC
72897 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
72898 + return 0;
72899 +#endif
72900 +
72901 if (is_mergeable_vma(vma, file, vm_flags) &&
72902 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
72903 if (vma->vm_pgoff == vm_pgoff)
72904 @@ -727,6 +755,12 @@ static int
72905 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
72906 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72907 {
72908 +
72909 +#ifdef CONFIG_PAX_SEGMEXEC
72910 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
72911 + return 0;
72912 +#endif
72913 +
72914 if (is_mergeable_vma(vma, file, vm_flags) &&
72915 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
72916 pgoff_t vm_pglen;
72917 @@ -769,13 +803,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
72918 struct vm_area_struct *vma_merge(struct mm_struct *mm,
72919 struct vm_area_struct *prev, unsigned long addr,
72920 unsigned long end, unsigned long vm_flags,
72921 - struct anon_vma *anon_vma, struct file *file,
72922 + struct anon_vma *anon_vma, struct file *file,
72923 pgoff_t pgoff, struct mempolicy *policy)
72924 {
72925 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
72926 struct vm_area_struct *area, *next;
72927 int err;
72928
72929 +#ifdef CONFIG_PAX_SEGMEXEC
72930 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
72931 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
72932 +
72933 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
72934 +#endif
72935 +
72936 /*
72937 * We later require that vma->vm_flags == vm_flags,
72938 * so this tests vma->vm_flags & VM_SPECIAL, too.
72939 @@ -791,6 +832,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72940 if (next && next->vm_end == end) /* cases 6, 7, 8 */
72941 next = next->vm_next;
72942
72943 +#ifdef CONFIG_PAX_SEGMEXEC
72944 + if (prev)
72945 + prev_m = pax_find_mirror_vma(prev);
72946 + if (area)
72947 + area_m = pax_find_mirror_vma(area);
72948 + if (next)
72949 + next_m = pax_find_mirror_vma(next);
72950 +#endif
72951 +
72952 /*
72953 * Can it merge with the predecessor?
72954 */
72955 @@ -810,9 +860,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72956 /* cases 1, 6 */
72957 err = vma_adjust(prev, prev->vm_start,
72958 next->vm_end, prev->vm_pgoff, NULL);
72959 - } else /* cases 2, 5, 7 */
72960 +
72961 +#ifdef CONFIG_PAX_SEGMEXEC
72962 + if (!err && prev_m)
72963 + err = vma_adjust(prev_m, prev_m->vm_start,
72964 + next_m->vm_end, prev_m->vm_pgoff, NULL);
72965 +#endif
72966 +
72967 + } else { /* cases 2, 5, 7 */
72968 err = vma_adjust(prev, prev->vm_start,
72969 end, prev->vm_pgoff, NULL);
72970 +
72971 +#ifdef CONFIG_PAX_SEGMEXEC
72972 + if (!err && prev_m)
72973 + err = vma_adjust(prev_m, prev_m->vm_start,
72974 + end_m, prev_m->vm_pgoff, NULL);
72975 +#endif
72976 +
72977 + }
72978 if (err)
72979 return NULL;
72980 khugepaged_enter_vma_merge(prev);
72981 @@ -826,12 +891,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72982 mpol_equal(policy, vma_policy(next)) &&
72983 can_vma_merge_before(next, vm_flags,
72984 anon_vma, file, pgoff+pglen)) {
72985 - if (prev && addr < prev->vm_end) /* case 4 */
72986 + if (prev && addr < prev->vm_end) { /* case 4 */
72987 err = vma_adjust(prev, prev->vm_start,
72988 addr, prev->vm_pgoff, NULL);
72989 - else /* cases 3, 8 */
72990 +
72991 +#ifdef CONFIG_PAX_SEGMEXEC
72992 + if (!err && prev_m)
72993 + err = vma_adjust(prev_m, prev_m->vm_start,
72994 + addr_m, prev_m->vm_pgoff, NULL);
72995 +#endif
72996 +
72997 + } else { /* cases 3, 8 */
72998 err = vma_adjust(area, addr, next->vm_end,
72999 next->vm_pgoff - pglen, NULL);
73000 +
73001 +#ifdef CONFIG_PAX_SEGMEXEC
73002 + if (!err && area_m)
73003 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
73004 + next_m->vm_pgoff - pglen, NULL);
73005 +#endif
73006 +
73007 + }
73008 if (err)
73009 return NULL;
73010 khugepaged_enter_vma_merge(area);
73011 @@ -940,16 +1020,13 @@ none:
73012 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
73013 struct file *file, long pages)
73014 {
73015 - const unsigned long stack_flags
73016 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
73017 -
73018 mm->total_vm += pages;
73019
73020 if (file) {
73021 mm->shared_vm += pages;
73022 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
73023 mm->exec_vm += pages;
73024 - } else if (flags & stack_flags)
73025 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
73026 mm->stack_vm += pages;
73027 if (flags & (VM_RESERVED|VM_IO))
73028 mm->reserved_vm += pages;
73029 @@ -987,7 +1064,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73030 * (the exception is when the underlying filesystem is noexec
73031 * mounted, in which case we dont add PROT_EXEC.)
73032 */
73033 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
73034 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
73035 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
73036 prot |= PROT_EXEC;
73037
73038 @@ -1013,7 +1090,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73039 /* Obtain the address to map to. we verify (or select) it and ensure
73040 * that it represents a valid section of the address space.
73041 */
73042 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
73043 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
73044 if (addr & ~PAGE_MASK)
73045 return addr;
73046
73047 @@ -1024,6 +1101,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73048 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
73049 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
73050
73051 +#ifdef CONFIG_PAX_MPROTECT
73052 + if (mm->pax_flags & MF_PAX_MPROTECT) {
73053 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
73054 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
73055 + gr_log_rwxmmap(file);
73056 +
73057 +#ifdef CONFIG_PAX_EMUPLT
73058 + vm_flags &= ~VM_EXEC;
73059 +#else
73060 + return -EPERM;
73061 +#endif
73062 +
73063 + }
73064 +
73065 + if (!(vm_flags & VM_EXEC))
73066 + vm_flags &= ~VM_MAYEXEC;
73067 +#else
73068 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
73069 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
73070 +#endif
73071 + else
73072 + vm_flags &= ~VM_MAYWRITE;
73073 + }
73074 +#endif
73075 +
73076 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
73077 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
73078 + vm_flags &= ~VM_PAGEEXEC;
73079 +#endif
73080 +
73081 if (flags & MAP_LOCKED)
73082 if (!can_do_mlock())
73083 return -EPERM;
73084 @@ -1035,6 +1142,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73085 locked += mm->locked_vm;
73086 lock_limit = rlimit(RLIMIT_MEMLOCK);
73087 lock_limit >>= PAGE_SHIFT;
73088 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
73089 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
73090 return -EAGAIN;
73091 }
73092 @@ -1101,6 +1209,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73093 }
73094 }
73095
73096 + if (!gr_acl_handle_mmap(file, prot))
73097 + return -EACCES;
73098 +
73099 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
73100 }
73101
73102 @@ -1177,7 +1288,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
73103 vm_flags_t vm_flags = vma->vm_flags;
73104
73105 /* If it was private or non-writable, the write bit is already clear */
73106 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
73107 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
73108 return 0;
73109
73110 /* The backer wishes to know when pages are first written to? */
73111 @@ -1226,14 +1337,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
73112 unsigned long charged = 0;
73113 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
73114
73115 +#ifdef CONFIG_PAX_SEGMEXEC
73116 + struct vm_area_struct *vma_m = NULL;
73117 +#endif
73118 +
73119 + /*
73120 + * mm->mmap_sem is required to protect against another thread
73121 + * changing the mappings in case we sleep.
73122 + */
73123 + verify_mm_writelocked(mm);
73124 +
73125 /* Clear old maps */
73126 error = -ENOMEM;
73127 -munmap_back:
73128 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73129 if (vma && vma->vm_start < addr + len) {
73130 if (do_munmap(mm, addr, len))
73131 return -ENOMEM;
73132 - goto munmap_back;
73133 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73134 + BUG_ON(vma && vma->vm_start < addr + len);
73135 }
73136
73137 /* Check against address space limit. */
73138 @@ -1282,6 +1403,16 @@ munmap_back:
73139 goto unacct_error;
73140 }
73141
73142 +#ifdef CONFIG_PAX_SEGMEXEC
73143 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
73144 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73145 + if (!vma_m) {
73146 + error = -ENOMEM;
73147 + goto free_vma;
73148 + }
73149 + }
73150 +#endif
73151 +
73152 vma->vm_mm = mm;
73153 vma->vm_start = addr;
73154 vma->vm_end = addr + len;
73155 @@ -1306,6 +1437,19 @@ munmap_back:
73156 error = file->f_op->mmap(file, vma);
73157 if (error)
73158 goto unmap_and_free_vma;
73159 +
73160 +#ifdef CONFIG_PAX_SEGMEXEC
73161 + if (vma_m && (vm_flags & VM_EXECUTABLE))
73162 + added_exe_file_vma(mm);
73163 +#endif
73164 +
73165 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
73166 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
73167 + vma->vm_flags |= VM_PAGEEXEC;
73168 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
73169 + }
73170 +#endif
73171 +
73172 if (vm_flags & VM_EXECUTABLE)
73173 added_exe_file_vma(mm);
73174
73175 @@ -1343,6 +1487,11 @@ munmap_back:
73176 vma_link(mm, vma, prev, rb_link, rb_parent);
73177 file = vma->vm_file;
73178
73179 +#ifdef CONFIG_PAX_SEGMEXEC
73180 + if (vma_m)
73181 + BUG_ON(pax_mirror_vma(vma_m, vma));
73182 +#endif
73183 +
73184 /* Once vma denies write, undo our temporary denial count */
73185 if (correct_wcount)
73186 atomic_inc(&inode->i_writecount);
73187 @@ -1350,6 +1499,7 @@ out:
73188 perf_event_mmap(vma);
73189
73190 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
73191 + track_exec_limit(mm, addr, addr + len, vm_flags);
73192 if (vm_flags & VM_LOCKED) {
73193 if (!mlock_vma_pages_range(vma, addr, addr + len))
73194 mm->locked_vm += (len >> PAGE_SHIFT);
73195 @@ -1371,6 +1521,12 @@ unmap_and_free_vma:
73196 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
73197 charged = 0;
73198 free_vma:
73199 +
73200 +#ifdef CONFIG_PAX_SEGMEXEC
73201 + if (vma_m)
73202 + kmem_cache_free(vm_area_cachep, vma_m);
73203 +#endif
73204 +
73205 kmem_cache_free(vm_area_cachep, vma);
73206 unacct_error:
73207 if (charged)
73208 @@ -1378,6 +1534,44 @@ unacct_error:
73209 return error;
73210 }
73211
73212 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
73213 +{
73214 + if (!vma) {
73215 +#ifdef CONFIG_STACK_GROWSUP
73216 + if (addr > sysctl_heap_stack_gap)
73217 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
73218 + else
73219 + vma = find_vma(current->mm, 0);
73220 + if (vma && (vma->vm_flags & VM_GROWSUP))
73221 + return false;
73222 +#endif
73223 + return true;
73224 + }
73225 +
73226 + if (addr + len > vma->vm_start)
73227 + return false;
73228 +
73229 + if (vma->vm_flags & VM_GROWSDOWN)
73230 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
73231 +#ifdef CONFIG_STACK_GROWSUP
73232 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
73233 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
73234 +#endif
73235 +
73236 + return true;
73237 +}
73238 +
73239 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
73240 +{
73241 + if (vma->vm_start < len)
73242 + return -ENOMEM;
73243 + if (!(vma->vm_flags & VM_GROWSDOWN))
73244 + return vma->vm_start - len;
73245 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
73246 + return vma->vm_start - len - sysctl_heap_stack_gap;
73247 + return -ENOMEM;
73248 +}
73249 +
73250 /* Get an address range which is currently unmapped.
73251 * For shmat() with addr=0.
73252 *
73253 @@ -1404,18 +1598,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
73254 if (flags & MAP_FIXED)
73255 return addr;
73256
73257 +#ifdef CONFIG_PAX_RANDMMAP
73258 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73259 +#endif
73260 +
73261 if (addr) {
73262 addr = PAGE_ALIGN(addr);
73263 - vma = find_vma(mm, addr);
73264 - if (TASK_SIZE - len >= addr &&
73265 - (!vma || addr + len <= vma->vm_start))
73266 - return addr;
73267 + if (TASK_SIZE - len >= addr) {
73268 + vma = find_vma(mm, addr);
73269 + if (check_heap_stack_gap(vma, addr, len))
73270 + return addr;
73271 + }
73272 }
73273 if (len > mm->cached_hole_size) {
73274 - start_addr = addr = mm->free_area_cache;
73275 + start_addr = addr = mm->free_area_cache;
73276 } else {
73277 - start_addr = addr = TASK_UNMAPPED_BASE;
73278 - mm->cached_hole_size = 0;
73279 + start_addr = addr = mm->mmap_base;
73280 + mm->cached_hole_size = 0;
73281 }
73282
73283 full_search:
73284 @@ -1426,34 +1625,40 @@ full_search:
73285 * Start a new search - just in case we missed
73286 * some holes.
73287 */
73288 - if (start_addr != TASK_UNMAPPED_BASE) {
73289 - addr = TASK_UNMAPPED_BASE;
73290 - start_addr = addr;
73291 + if (start_addr != mm->mmap_base) {
73292 + start_addr = addr = mm->mmap_base;
73293 mm->cached_hole_size = 0;
73294 goto full_search;
73295 }
73296 return -ENOMEM;
73297 }
73298 - if (!vma || addr + len <= vma->vm_start) {
73299 - /*
73300 - * Remember the place where we stopped the search:
73301 - */
73302 - mm->free_area_cache = addr + len;
73303 - return addr;
73304 - }
73305 + if (check_heap_stack_gap(vma, addr, len))
73306 + break;
73307 if (addr + mm->cached_hole_size < vma->vm_start)
73308 mm->cached_hole_size = vma->vm_start - addr;
73309 addr = vma->vm_end;
73310 }
73311 +
73312 + /*
73313 + * Remember the place where we stopped the search:
73314 + */
73315 + mm->free_area_cache = addr + len;
73316 + return addr;
73317 }
73318 #endif
73319
73320 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
73321 {
73322 +
73323 +#ifdef CONFIG_PAX_SEGMEXEC
73324 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73325 + return;
73326 +#endif
73327 +
73328 /*
73329 * Is this a new hole at the lowest possible address?
73330 */
73331 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
73332 + if (addr >= mm->mmap_base && addr < mm->free_area_cache)
73333 mm->free_area_cache = addr;
73334 }
73335
73336 @@ -1469,7 +1674,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73337 {
73338 struct vm_area_struct *vma;
73339 struct mm_struct *mm = current->mm;
73340 - unsigned long addr = addr0, start_addr;
73341 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
73342
73343 /* requested length too big for entire address space */
73344 if (len > TASK_SIZE)
73345 @@ -1478,13 +1683,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73346 if (flags & MAP_FIXED)
73347 return addr;
73348
73349 +#ifdef CONFIG_PAX_RANDMMAP
73350 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73351 +#endif
73352 +
73353 /* requesting a specific address */
73354 if (addr) {
73355 addr = PAGE_ALIGN(addr);
73356 - vma = find_vma(mm, addr);
73357 - if (TASK_SIZE - len >= addr &&
73358 - (!vma || addr + len <= vma->vm_start))
73359 - return addr;
73360 + if (TASK_SIZE - len >= addr) {
73361 + vma = find_vma(mm, addr);
73362 + if (check_heap_stack_gap(vma, addr, len))
73363 + return addr;
73364 + }
73365 }
73366
73367 /* check if free_area_cache is useful for us */
73368 @@ -1508,7 +1718,7 @@ try_again:
73369 * return with success:
73370 */
73371 vma = find_vma(mm, addr);
73372 - if (!vma || addr+len <= vma->vm_start)
73373 + if (check_heap_stack_gap(vma, addr, len))
73374 /* remember the address as a hint for next time */
73375 return (mm->free_area_cache = addr);
73376
73377 @@ -1517,8 +1727,8 @@ try_again:
73378 mm->cached_hole_size = vma->vm_start - addr;
73379
73380 /* try just below the current vma->vm_start */
73381 - addr = vma->vm_start-len;
73382 - } while (len < vma->vm_start);
73383 + addr = skip_heap_stack_gap(vma, len);
73384 + } while (!IS_ERR_VALUE(addr));
73385
73386 fail:
73387 /*
73388 @@ -1541,13 +1751,21 @@ fail:
73389 * can happen with large stack limits and large mmap()
73390 * allocations.
73391 */
73392 + mm->mmap_base = TASK_UNMAPPED_BASE;
73393 +
73394 +#ifdef CONFIG_PAX_RANDMMAP
73395 + if (mm->pax_flags & MF_PAX_RANDMMAP)
73396 + mm->mmap_base += mm->delta_mmap;
73397 +#endif
73398 +
73399 + mm->free_area_cache = mm->mmap_base;
73400 mm->cached_hole_size = ~0UL;
73401 - mm->free_area_cache = TASK_UNMAPPED_BASE;
73402 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
73403 /*
73404 * Restore the topdown base:
73405 */
73406 - mm->free_area_cache = mm->mmap_base;
73407 + mm->mmap_base = base;
73408 + mm->free_area_cache = base;
73409 mm->cached_hole_size = ~0UL;
73410
73411 return addr;
73412 @@ -1556,6 +1774,12 @@ fail:
73413
73414 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73415 {
73416 +
73417 +#ifdef CONFIG_PAX_SEGMEXEC
73418 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73419 + return;
73420 +#endif
73421 +
73422 /*
73423 * Is this a new hole at the highest possible address?
73424 */
73425 @@ -1563,8 +1787,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73426 mm->free_area_cache = addr;
73427
73428 /* dont allow allocations above current base */
73429 - if (mm->free_area_cache > mm->mmap_base)
73430 + if (mm->free_area_cache > mm->mmap_base) {
73431 mm->free_area_cache = mm->mmap_base;
73432 + mm->cached_hole_size = ~0UL;
73433 + }
73434 }
73435
73436 unsigned long
73437 @@ -1663,6 +1889,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
73438 return vma;
73439 }
73440
73441 +#ifdef CONFIG_PAX_SEGMEXEC
73442 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
73443 +{
73444 + struct vm_area_struct *vma_m;
73445 +
73446 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
73447 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
73448 + BUG_ON(vma->vm_mirror);
73449 + return NULL;
73450 + }
73451 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
73452 + vma_m = vma->vm_mirror;
73453 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
73454 + BUG_ON(vma->vm_file != vma_m->vm_file);
73455 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
73456 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
73457 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
73458 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
73459 + return vma_m;
73460 +}
73461 +#endif
73462 +
73463 /*
73464 * Verify that the stack growth is acceptable and
73465 * update accounting. This is shared with both the
73466 @@ -1679,6 +1927,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73467 return -ENOMEM;
73468
73469 /* Stack limit test */
73470 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
73471 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
73472 return -ENOMEM;
73473
73474 @@ -1689,6 +1938,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73475 locked = mm->locked_vm + grow;
73476 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
73477 limit >>= PAGE_SHIFT;
73478 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
73479 if (locked > limit && !capable(CAP_IPC_LOCK))
73480 return -ENOMEM;
73481 }
73482 @@ -1718,37 +1968,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73483 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
73484 * vma is the last one with address > vma->vm_end. Have to extend vma.
73485 */
73486 +#ifndef CONFIG_IA64
73487 +static
73488 +#endif
73489 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
73490 {
73491 int error;
73492 + bool locknext;
73493
73494 if (!(vma->vm_flags & VM_GROWSUP))
73495 return -EFAULT;
73496
73497 + /* Also guard against wrapping around to address 0. */
73498 + if (address < PAGE_ALIGN(address+1))
73499 + address = PAGE_ALIGN(address+1);
73500 + else
73501 + return -ENOMEM;
73502 +
73503 /*
73504 * We must make sure the anon_vma is allocated
73505 * so that the anon_vma locking is not a noop.
73506 */
73507 if (unlikely(anon_vma_prepare(vma)))
73508 return -ENOMEM;
73509 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
73510 + if (locknext && anon_vma_prepare(vma->vm_next))
73511 + return -ENOMEM;
73512 vma_lock_anon_vma(vma);
73513 + if (locknext)
73514 + vma_lock_anon_vma(vma->vm_next);
73515
73516 /*
73517 * vma->vm_start/vm_end cannot change under us because the caller
73518 * is required to hold the mmap_sem in read mode. We need the
73519 - * anon_vma lock to serialize against concurrent expand_stacks.
73520 - * Also guard against wrapping around to address 0.
73521 + * anon_vma locks to serialize against concurrent expand_stacks
73522 + * and expand_upwards.
73523 */
73524 - if (address < PAGE_ALIGN(address+4))
73525 - address = PAGE_ALIGN(address+4);
73526 - else {
73527 - vma_unlock_anon_vma(vma);
73528 - return -ENOMEM;
73529 - }
73530 error = 0;
73531
73532 /* Somebody else might have raced and expanded it already */
73533 - if (address > vma->vm_end) {
73534 + 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)
73535 + error = -ENOMEM;
73536 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
73537 unsigned long size, grow;
73538
73539 size = address - vma->vm_start;
73540 @@ -1763,6 +2024,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
73541 }
73542 }
73543 }
73544 + if (locknext)
73545 + vma_unlock_anon_vma(vma->vm_next);
73546 vma_unlock_anon_vma(vma);
73547 khugepaged_enter_vma_merge(vma);
73548 return error;
73549 @@ -1776,6 +2039,8 @@ int expand_downwards(struct vm_area_struct *vma,
73550 unsigned long address)
73551 {
73552 int error;
73553 + bool lockprev = false;
73554 + struct vm_area_struct *prev;
73555
73556 /*
73557 * We must make sure the anon_vma is allocated
73558 @@ -1789,6 +2054,15 @@ int expand_downwards(struct vm_area_struct *vma,
73559 if (error)
73560 return error;
73561
73562 + prev = vma->vm_prev;
73563 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
73564 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
73565 +#endif
73566 + if (lockprev && anon_vma_prepare(prev))
73567 + return -ENOMEM;
73568 + if (lockprev)
73569 + vma_lock_anon_vma(prev);
73570 +
73571 vma_lock_anon_vma(vma);
73572
73573 /*
73574 @@ -1798,9 +2072,17 @@ int expand_downwards(struct vm_area_struct *vma,
73575 */
73576
73577 /* Somebody else might have raced and expanded it already */
73578 - if (address < vma->vm_start) {
73579 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
73580 + error = -ENOMEM;
73581 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
73582 unsigned long size, grow;
73583
73584 +#ifdef CONFIG_PAX_SEGMEXEC
73585 + struct vm_area_struct *vma_m;
73586 +
73587 + vma_m = pax_find_mirror_vma(vma);
73588 +#endif
73589 +
73590 size = vma->vm_end - address;
73591 grow = (vma->vm_start - address) >> PAGE_SHIFT;
73592
73593 @@ -1810,11 +2092,22 @@ int expand_downwards(struct vm_area_struct *vma,
73594 if (!error) {
73595 vma->vm_start = address;
73596 vma->vm_pgoff -= grow;
73597 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
73598 +
73599 +#ifdef CONFIG_PAX_SEGMEXEC
73600 + if (vma_m) {
73601 + vma_m->vm_start -= grow << PAGE_SHIFT;
73602 + vma_m->vm_pgoff -= grow;
73603 + }
73604 +#endif
73605 +
73606 perf_event_mmap(vma);
73607 }
73608 }
73609 }
73610 vma_unlock_anon_vma(vma);
73611 + if (lockprev)
73612 + vma_unlock_anon_vma(prev);
73613 khugepaged_enter_vma_merge(vma);
73614 return error;
73615 }
73616 @@ -1886,6 +2179,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
73617 do {
73618 long nrpages = vma_pages(vma);
73619
73620 +#ifdef CONFIG_PAX_SEGMEXEC
73621 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
73622 + vma = remove_vma(vma);
73623 + continue;
73624 + }
73625 +#endif
73626 +
73627 if (vma->vm_flags & VM_ACCOUNT)
73628 nr_accounted += nrpages;
73629 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
73630 @@ -1931,6 +2231,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
73631 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
73632 vma->vm_prev = NULL;
73633 do {
73634 +
73635 +#ifdef CONFIG_PAX_SEGMEXEC
73636 + if (vma->vm_mirror) {
73637 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
73638 + vma->vm_mirror->vm_mirror = NULL;
73639 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
73640 + vma->vm_mirror = NULL;
73641 + }
73642 +#endif
73643 +
73644 rb_erase(&vma->vm_rb, &mm->mm_rb);
73645 mm->map_count--;
73646 tail_vma = vma;
73647 @@ -1959,14 +2269,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73648 struct vm_area_struct *new;
73649 int err = -ENOMEM;
73650
73651 +#ifdef CONFIG_PAX_SEGMEXEC
73652 + struct vm_area_struct *vma_m, *new_m = NULL;
73653 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
73654 +#endif
73655 +
73656 if (is_vm_hugetlb_page(vma) && (addr &
73657 ~(huge_page_mask(hstate_vma(vma)))))
73658 return -EINVAL;
73659
73660 +#ifdef CONFIG_PAX_SEGMEXEC
73661 + vma_m = pax_find_mirror_vma(vma);
73662 +#endif
73663 +
73664 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73665 if (!new)
73666 goto out_err;
73667
73668 +#ifdef CONFIG_PAX_SEGMEXEC
73669 + if (vma_m) {
73670 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73671 + if (!new_m) {
73672 + kmem_cache_free(vm_area_cachep, new);
73673 + goto out_err;
73674 + }
73675 + }
73676 +#endif
73677 +
73678 /* most fields are the same, copy all, and then fixup */
73679 *new = *vma;
73680
73681 @@ -1979,6 +2308,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73682 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
73683 }
73684
73685 +#ifdef CONFIG_PAX_SEGMEXEC
73686 + if (vma_m) {
73687 + *new_m = *vma_m;
73688 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
73689 + new_m->vm_mirror = new;
73690 + new->vm_mirror = new_m;
73691 +
73692 + if (new_below)
73693 + new_m->vm_end = addr_m;
73694 + else {
73695 + new_m->vm_start = addr_m;
73696 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
73697 + }
73698 + }
73699 +#endif
73700 +
73701 pol = mpol_dup(vma_policy(vma));
73702 if (IS_ERR(pol)) {
73703 err = PTR_ERR(pol);
73704 @@ -2004,6 +2349,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73705 else
73706 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
73707
73708 +#ifdef CONFIG_PAX_SEGMEXEC
73709 + if (!err && vma_m) {
73710 + if (anon_vma_clone(new_m, vma_m))
73711 + goto out_free_mpol;
73712 +
73713 + mpol_get(pol);
73714 + vma_set_policy(new_m, pol);
73715 +
73716 + if (new_m->vm_file) {
73717 + get_file(new_m->vm_file);
73718 + if (vma_m->vm_flags & VM_EXECUTABLE)
73719 + added_exe_file_vma(mm);
73720 + }
73721 +
73722 + if (new_m->vm_ops && new_m->vm_ops->open)
73723 + new_m->vm_ops->open(new_m);
73724 +
73725 + if (new_below)
73726 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
73727 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
73728 + else
73729 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
73730 +
73731 + if (err) {
73732 + if (new_m->vm_ops && new_m->vm_ops->close)
73733 + new_m->vm_ops->close(new_m);
73734 + if (new_m->vm_file) {
73735 + if (vma_m->vm_flags & VM_EXECUTABLE)
73736 + removed_exe_file_vma(mm);
73737 + fput(new_m->vm_file);
73738 + }
73739 + mpol_put(pol);
73740 + }
73741 + }
73742 +#endif
73743 +
73744 /* Success. */
73745 if (!err)
73746 return 0;
73747 @@ -2016,10 +2397,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73748 removed_exe_file_vma(mm);
73749 fput(new->vm_file);
73750 }
73751 - unlink_anon_vmas(new);
73752 out_free_mpol:
73753 mpol_put(pol);
73754 out_free_vma:
73755 +
73756 +#ifdef CONFIG_PAX_SEGMEXEC
73757 + if (new_m) {
73758 + unlink_anon_vmas(new_m);
73759 + kmem_cache_free(vm_area_cachep, new_m);
73760 + }
73761 +#endif
73762 +
73763 + unlink_anon_vmas(new);
73764 kmem_cache_free(vm_area_cachep, new);
73765 out_err:
73766 return err;
73767 @@ -2032,6 +2421,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73768 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73769 unsigned long addr, int new_below)
73770 {
73771 +
73772 +#ifdef CONFIG_PAX_SEGMEXEC
73773 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
73774 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
73775 + if (mm->map_count >= sysctl_max_map_count-1)
73776 + return -ENOMEM;
73777 + } else
73778 +#endif
73779 +
73780 if (mm->map_count >= sysctl_max_map_count)
73781 return -ENOMEM;
73782
73783 @@ -2043,11 +2441,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73784 * work. This now handles partial unmappings.
73785 * Jeremy Fitzhardinge <jeremy@goop.org>
73786 */
73787 +#ifdef CONFIG_PAX_SEGMEXEC
73788 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73789 {
73790 + int ret = __do_munmap(mm, start, len);
73791 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
73792 + return ret;
73793 +
73794 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
73795 +}
73796 +
73797 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73798 +#else
73799 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73800 +#endif
73801 +{
73802 unsigned long end;
73803 struct vm_area_struct *vma, *prev, *last;
73804
73805 + /*
73806 + * mm->mmap_sem is required to protect against another thread
73807 + * changing the mappings in case we sleep.
73808 + */
73809 + verify_mm_writelocked(mm);
73810 +
73811 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
73812 return -EINVAL;
73813
73814 @@ -2122,6 +2539,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73815 /* Fix up all other VM information */
73816 remove_vma_list(mm, vma);
73817
73818 + track_exec_limit(mm, start, end, 0UL);
73819 +
73820 return 0;
73821 }
73822
73823 @@ -2130,6 +2549,13 @@ int vm_munmap(unsigned long start, size_t len)
73824 int ret;
73825 struct mm_struct *mm = current->mm;
73826
73827 +
73828 +#ifdef CONFIG_PAX_SEGMEXEC
73829 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
73830 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
73831 + return -EINVAL;
73832 +#endif
73833 +
73834 down_write(&mm->mmap_sem);
73835 ret = do_munmap(mm, start, len);
73836 up_write(&mm->mmap_sem);
73837 @@ -2143,16 +2569,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
73838 return vm_munmap(addr, len);
73839 }
73840
73841 -static inline void verify_mm_writelocked(struct mm_struct *mm)
73842 -{
73843 -#ifdef CONFIG_DEBUG_VM
73844 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
73845 - WARN_ON(1);
73846 - up_read(&mm->mmap_sem);
73847 - }
73848 -#endif
73849 -}
73850 -
73851 /*
73852 * this is really a simplified "do_mmap". it only handles
73853 * anonymous maps. eventually we may be able to do some
73854 @@ -2166,6 +2582,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73855 struct rb_node ** rb_link, * rb_parent;
73856 pgoff_t pgoff = addr >> PAGE_SHIFT;
73857 int error;
73858 + unsigned long charged;
73859
73860 len = PAGE_ALIGN(len);
73861 if (!len)
73862 @@ -2173,16 +2590,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73863
73864 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
73865
73866 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
73867 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
73868 + flags &= ~VM_EXEC;
73869 +
73870 +#ifdef CONFIG_PAX_MPROTECT
73871 + if (mm->pax_flags & MF_PAX_MPROTECT)
73872 + flags &= ~VM_MAYEXEC;
73873 +#endif
73874 +
73875 + }
73876 +#endif
73877 +
73878 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
73879 if (error & ~PAGE_MASK)
73880 return error;
73881
73882 + charged = len >> PAGE_SHIFT;
73883 +
73884 /*
73885 * mlock MCL_FUTURE?
73886 */
73887 if (mm->def_flags & VM_LOCKED) {
73888 unsigned long locked, lock_limit;
73889 - locked = len >> PAGE_SHIFT;
73890 + locked = charged;
73891 locked += mm->locked_vm;
73892 lock_limit = rlimit(RLIMIT_MEMLOCK);
73893 lock_limit >>= PAGE_SHIFT;
73894 @@ -2199,22 +2630,22 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73895 /*
73896 * Clear old maps. this also does some error checking for us
73897 */
73898 - munmap_back:
73899 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73900 if (vma && vma->vm_start < addr + len) {
73901 if (do_munmap(mm, addr, len))
73902 return -ENOMEM;
73903 - goto munmap_back;
73904 - }
73905 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73906 + BUG_ON(vma && vma->vm_start < addr + len);
73907 + }
73908
73909 /* Check against address space limits *after* clearing old maps... */
73910 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
73911 + if (!may_expand_vm(mm, charged))
73912 return -ENOMEM;
73913
73914 if (mm->map_count > sysctl_max_map_count)
73915 return -ENOMEM;
73916
73917 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
73918 + if (security_vm_enough_memory_mm(mm, charged))
73919 return -ENOMEM;
73920
73921 /* Can we just expand an old private anonymous mapping? */
73922 @@ -2228,7 +2659,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73923 */
73924 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73925 if (!vma) {
73926 - vm_unacct_memory(len >> PAGE_SHIFT);
73927 + vm_unacct_memory(charged);
73928 return -ENOMEM;
73929 }
73930
73931 @@ -2242,11 +2673,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73932 vma_link(mm, vma, prev, rb_link, rb_parent);
73933 out:
73934 perf_event_mmap(vma);
73935 - mm->total_vm += len >> PAGE_SHIFT;
73936 + mm->total_vm += charged;
73937 if (flags & VM_LOCKED) {
73938 if (!mlock_vma_pages_range(vma, addr, addr + len))
73939 - mm->locked_vm += (len >> PAGE_SHIFT);
73940 + mm->locked_vm += charged;
73941 }
73942 + track_exec_limit(mm, addr, addr + len, flags);
73943 return addr;
73944 }
73945
73946 @@ -2304,6 +2736,7 @@ void exit_mmap(struct mm_struct *mm)
73947 while (vma) {
73948 if (vma->vm_flags & VM_ACCOUNT)
73949 nr_accounted += vma_pages(vma);
73950 + vma->vm_mirror = NULL;
73951 vma = remove_vma(vma);
73952 }
73953 vm_unacct_memory(nr_accounted);
73954 @@ -2320,6 +2753,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
73955 struct vm_area_struct * __vma, * prev;
73956 struct rb_node ** rb_link, * rb_parent;
73957
73958 +#ifdef CONFIG_PAX_SEGMEXEC
73959 + struct vm_area_struct *vma_m = NULL;
73960 +#endif
73961 +
73962 + if (security_mmap_addr(vma->vm_start))
73963 + return -EPERM;
73964 +
73965 /*
73966 * The vm_pgoff of a purely anonymous vma should be irrelevant
73967 * until its first write fault, when page's anon_vma and index
73968 @@ -2343,7 +2783,21 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
73969 security_vm_enough_memory_mm(mm, vma_pages(vma)))
73970 return -ENOMEM;
73971
73972 +#ifdef CONFIG_PAX_SEGMEXEC
73973 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
73974 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73975 + if (!vma_m)
73976 + return -ENOMEM;
73977 + }
73978 +#endif
73979 +
73980 vma_link(mm, vma, prev, rb_link, rb_parent);
73981 +
73982 +#ifdef CONFIG_PAX_SEGMEXEC
73983 + if (vma_m)
73984 + BUG_ON(pax_mirror_vma(vma_m, vma));
73985 +#endif
73986 +
73987 return 0;
73988 }
73989
73990 @@ -2362,6 +2816,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
73991 struct mempolicy *pol;
73992 bool faulted_in_anon_vma = true;
73993
73994 + BUG_ON(vma->vm_mirror);
73995 +
73996 /*
73997 * If anonymous vma has not yet been faulted, update new pgoff
73998 * to match new location, to increase its chance of merging.
73999 @@ -2430,6 +2886,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
74000 return NULL;
74001 }
74002
74003 +#ifdef CONFIG_PAX_SEGMEXEC
74004 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
74005 +{
74006 + struct vm_area_struct *prev_m;
74007 + struct rb_node **rb_link_m, *rb_parent_m;
74008 + struct mempolicy *pol_m;
74009 +
74010 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
74011 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
74012 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
74013 + *vma_m = *vma;
74014 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
74015 + if (anon_vma_clone(vma_m, vma))
74016 + return -ENOMEM;
74017 + pol_m = vma_policy(vma_m);
74018 + mpol_get(pol_m);
74019 + vma_set_policy(vma_m, pol_m);
74020 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
74021 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
74022 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
74023 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
74024 + if (vma_m->vm_file)
74025 + get_file(vma_m->vm_file);
74026 + if (vma_m->vm_ops && vma_m->vm_ops->open)
74027 + vma_m->vm_ops->open(vma_m);
74028 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
74029 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
74030 + vma_m->vm_mirror = vma;
74031 + vma->vm_mirror = vma_m;
74032 + return 0;
74033 +}
74034 +#endif
74035 +
74036 /*
74037 * Return true if the calling process may expand its vm space by the passed
74038 * number of pages
74039 @@ -2441,6 +2930,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
74040
74041 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
74042
74043 +#ifdef CONFIG_PAX_RANDMMAP
74044 + if (mm->pax_flags & MF_PAX_RANDMMAP)
74045 + cur -= mm->brk_gap;
74046 +#endif
74047 +
74048 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
74049 if (cur + npages > lim)
74050 return 0;
74051 return 1;
74052 @@ -2511,6 +3006,22 @@ int install_special_mapping(struct mm_struct *mm,
74053 vma->vm_start = addr;
74054 vma->vm_end = addr + len;
74055
74056 +#ifdef CONFIG_PAX_MPROTECT
74057 + if (mm->pax_flags & MF_PAX_MPROTECT) {
74058 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
74059 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
74060 + return -EPERM;
74061 + if (!(vm_flags & VM_EXEC))
74062 + vm_flags &= ~VM_MAYEXEC;
74063 +#else
74064 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
74065 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
74066 +#endif
74067 + else
74068 + vm_flags &= ~VM_MAYWRITE;
74069 + }
74070 +#endif
74071 +
74072 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
74073 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
74074
74075 diff --git a/mm/mprotect.c b/mm/mprotect.c
74076 index a409926..8b32e6d 100644
74077 --- a/mm/mprotect.c
74078 +++ b/mm/mprotect.c
74079 @@ -23,10 +23,17 @@
74080 #include <linux/mmu_notifier.h>
74081 #include <linux/migrate.h>
74082 #include <linux/perf_event.h>
74083 +
74084 +#ifdef CONFIG_PAX_MPROTECT
74085 +#include <linux/elf.h>
74086 +#include <linux/binfmts.h>
74087 +#endif
74088 +
74089 #include <asm/uaccess.h>
74090 #include <asm/pgtable.h>
74091 #include <asm/cacheflush.h>
74092 #include <asm/tlbflush.h>
74093 +#include <asm/mmu_context.h>
74094
74095 #ifndef pgprot_modify
74096 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
74097 @@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
74098 flush_tlb_range(vma, start, end);
74099 }
74100
74101 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
74102 +/* called while holding the mmap semaphor for writing except stack expansion */
74103 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
74104 +{
74105 + unsigned long oldlimit, newlimit = 0UL;
74106 +
74107 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
74108 + return;
74109 +
74110 + spin_lock(&mm->page_table_lock);
74111 + oldlimit = mm->context.user_cs_limit;
74112 + if ((prot & VM_EXEC) && oldlimit < end)
74113 + /* USER_CS limit moved up */
74114 + newlimit = end;
74115 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
74116 + /* USER_CS limit moved down */
74117 + newlimit = start;
74118 +
74119 + if (newlimit) {
74120 + mm->context.user_cs_limit = newlimit;
74121 +
74122 +#ifdef CONFIG_SMP
74123 + wmb();
74124 + cpus_clear(mm->context.cpu_user_cs_mask);
74125 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
74126 +#endif
74127 +
74128 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
74129 + }
74130 + spin_unlock(&mm->page_table_lock);
74131 + if (newlimit == end) {
74132 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
74133 +
74134 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
74135 + if (is_vm_hugetlb_page(vma))
74136 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
74137 + else
74138 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
74139 + }
74140 +}
74141 +#endif
74142 +
74143 int
74144 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74145 unsigned long start, unsigned long end, unsigned long newflags)
74146 @@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74147 int error;
74148 int dirty_accountable = 0;
74149
74150 +#ifdef CONFIG_PAX_SEGMEXEC
74151 + struct vm_area_struct *vma_m = NULL;
74152 + unsigned long start_m, end_m;
74153 +
74154 + start_m = start + SEGMEXEC_TASK_SIZE;
74155 + end_m = end + SEGMEXEC_TASK_SIZE;
74156 +#endif
74157 +
74158 if (newflags == oldflags) {
74159 *pprev = vma;
74160 return 0;
74161 }
74162
74163 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
74164 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
74165 +
74166 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
74167 + return -ENOMEM;
74168 +
74169 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
74170 + return -ENOMEM;
74171 + }
74172 +
74173 /*
74174 * If we make a private mapping writable we increase our commit;
74175 * but (without finer accounting) cannot reduce our commit if we
74176 @@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74177 }
74178 }
74179
74180 +#ifdef CONFIG_PAX_SEGMEXEC
74181 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
74182 + if (start != vma->vm_start) {
74183 + error = split_vma(mm, vma, start, 1);
74184 + if (error)
74185 + goto fail;
74186 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
74187 + *pprev = (*pprev)->vm_next;
74188 + }
74189 +
74190 + if (end != vma->vm_end) {
74191 + error = split_vma(mm, vma, end, 0);
74192 + if (error)
74193 + goto fail;
74194 + }
74195 +
74196 + if (pax_find_mirror_vma(vma)) {
74197 + error = __do_munmap(mm, start_m, end_m - start_m);
74198 + if (error)
74199 + goto fail;
74200 + } else {
74201 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
74202 + if (!vma_m) {
74203 + error = -ENOMEM;
74204 + goto fail;
74205 + }
74206 + vma->vm_flags = newflags;
74207 + error = pax_mirror_vma(vma_m, vma);
74208 + if (error) {
74209 + vma->vm_flags = oldflags;
74210 + goto fail;
74211 + }
74212 + }
74213 + }
74214 +#endif
74215 +
74216 /*
74217 * First try to merge with previous and/or next vma.
74218 */
74219 @@ -204,9 +307,21 @@ success:
74220 * vm_flags and vm_page_prot are protected by the mmap_sem
74221 * held in write mode.
74222 */
74223 +
74224 +#ifdef CONFIG_PAX_SEGMEXEC
74225 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
74226 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
74227 +#endif
74228 +
74229 vma->vm_flags = newflags;
74230 +
74231 +#ifdef CONFIG_PAX_MPROTECT
74232 + if (mm->binfmt && mm->binfmt->handle_mprotect)
74233 + mm->binfmt->handle_mprotect(vma, newflags);
74234 +#endif
74235 +
74236 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
74237 - vm_get_page_prot(newflags));
74238 + vm_get_page_prot(vma->vm_flags));
74239
74240 if (vma_wants_writenotify(vma)) {
74241 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
74242 @@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74243 end = start + len;
74244 if (end <= start)
74245 return -ENOMEM;
74246 +
74247 +#ifdef CONFIG_PAX_SEGMEXEC
74248 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
74249 + if (end > SEGMEXEC_TASK_SIZE)
74250 + return -EINVAL;
74251 + } else
74252 +#endif
74253 +
74254 + if (end > TASK_SIZE)
74255 + return -EINVAL;
74256 +
74257 if (!arch_validate_prot(prot))
74258 return -EINVAL;
74259
74260 @@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74261 /*
74262 * Does the application expect PROT_READ to imply PROT_EXEC:
74263 */
74264 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
74265 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
74266 prot |= PROT_EXEC;
74267
74268 vm_flags = calc_vm_prot_bits(prot);
74269 @@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74270 if (start > vma->vm_start)
74271 prev = vma;
74272
74273 +#ifdef CONFIG_PAX_MPROTECT
74274 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
74275 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
74276 +#endif
74277 +
74278 for (nstart = start ; ; ) {
74279 unsigned long newflags;
74280
74281 @@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74282
74283 /* newflags >> 4 shift VM_MAY% in place of VM_% */
74284 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
74285 + if (prot & (PROT_WRITE | PROT_EXEC))
74286 + gr_log_rwxmprotect(vma->vm_file);
74287 +
74288 + error = -EACCES;
74289 + goto out;
74290 + }
74291 +
74292 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
74293 error = -EACCES;
74294 goto out;
74295 }
74296 @@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74297 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
74298 if (error)
74299 goto out;
74300 +
74301 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
74302 +
74303 nstart = tmp;
74304
74305 if (nstart < prev->vm_end)
74306 diff --git a/mm/mremap.c b/mm/mremap.c
74307 index cc06d0e..40b5d18 100644
74308 --- a/mm/mremap.c
74309 +++ b/mm/mremap.c
74310 @@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
74311 continue;
74312 pte = ptep_get_and_clear(mm, old_addr, old_pte);
74313 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
74314 +
74315 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
74316 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
74317 + pte = pte_exprotect(pte);
74318 +#endif
74319 +
74320 set_pte_at(mm, new_addr, new_pte, pte);
74321 }
74322
74323 @@ -298,6 +304,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
74324 if (is_vm_hugetlb_page(vma))
74325 goto Einval;
74326
74327 +#ifdef CONFIG_PAX_SEGMEXEC
74328 + if (pax_find_mirror_vma(vma))
74329 + goto Einval;
74330 +#endif
74331 +
74332 /* We can't remap across vm area boundaries */
74333 if (old_len > vma->vm_end - addr)
74334 goto Efault;
74335 @@ -354,20 +365,25 @@ static unsigned long mremap_to(unsigned long addr,
74336 unsigned long ret = -EINVAL;
74337 unsigned long charged = 0;
74338 unsigned long map_flags;
74339 + unsigned long pax_task_size = TASK_SIZE;
74340
74341 if (new_addr & ~PAGE_MASK)
74342 goto out;
74343
74344 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
74345 +#ifdef CONFIG_PAX_SEGMEXEC
74346 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
74347 + pax_task_size = SEGMEXEC_TASK_SIZE;
74348 +#endif
74349 +
74350 + pax_task_size -= PAGE_SIZE;
74351 +
74352 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
74353 goto out;
74354
74355 /* Check if the location we're moving into overlaps the
74356 * old location at all, and fail if it does.
74357 */
74358 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
74359 - goto out;
74360 -
74361 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
74362 + if (addr + old_len > new_addr && new_addr + new_len > addr)
74363 goto out;
74364
74365 ret = do_munmap(mm, new_addr, new_len);
74366 @@ -435,6 +451,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74367 struct vm_area_struct *vma;
74368 unsigned long ret = -EINVAL;
74369 unsigned long charged = 0;
74370 + unsigned long pax_task_size = TASK_SIZE;
74371
74372 down_write(&current->mm->mmap_sem);
74373
74374 @@ -455,6 +472,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74375 if (!new_len)
74376 goto out;
74377
74378 +#ifdef CONFIG_PAX_SEGMEXEC
74379 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
74380 + pax_task_size = SEGMEXEC_TASK_SIZE;
74381 +#endif
74382 +
74383 + pax_task_size -= PAGE_SIZE;
74384 +
74385 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
74386 + old_len > pax_task_size || addr > pax_task_size-old_len)
74387 + goto out;
74388 +
74389 if (flags & MREMAP_FIXED) {
74390 if (flags & MREMAP_MAYMOVE)
74391 ret = mremap_to(addr, old_len, new_addr, new_len);
74392 @@ -503,6 +531,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74393 addr + new_len);
74394 }
74395 ret = addr;
74396 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
74397 goto out;
74398 }
74399 }
74400 @@ -526,7 +555,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74401 goto out;
74402 }
74403
74404 + map_flags = vma->vm_flags;
74405 ret = move_vma(vma, addr, old_len, new_len, new_addr);
74406 + if (!(ret & ~PAGE_MASK)) {
74407 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
74408 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
74409 + }
74410 }
74411 out:
74412 if (ret & ~PAGE_MASK)
74413 diff --git a/mm/nommu.c b/mm/nommu.c
74414 index d4b0c10..ed421b5 100644
74415 --- a/mm/nommu.c
74416 +++ b/mm/nommu.c
74417 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
74418 int sysctl_overcommit_ratio = 50; /* default is 50% */
74419 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
74420 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
74421 -int heap_stack_gap = 0;
74422
74423 atomic_long_t mmap_pages_allocated;
74424
74425 @@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
74426 EXPORT_SYMBOL(find_vma);
74427
74428 /*
74429 - * find a VMA
74430 - * - we don't extend stack VMAs under NOMMU conditions
74431 - */
74432 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
74433 -{
74434 - return find_vma(mm, addr);
74435 -}
74436 -
74437 -/*
74438 * expand a stack to a given address
74439 * - not supported under NOMMU conditions
74440 */
74441 @@ -1551,6 +1541,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
74442
74443 /* most fields are the same, copy all, and then fixup */
74444 *new = *vma;
74445 + INIT_LIST_HEAD(&new->anon_vma_chain);
74446 *region = *vma->vm_region;
74447 new->vm_region = region;
74448
74449 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
74450 index c13ea75..081ab2c 100644
74451 --- a/mm/page_alloc.c
74452 +++ b/mm/page_alloc.c
74453 @@ -340,7 +340,7 @@ out:
74454 * This usage means that zero-order pages may not be compound.
74455 */
74456
74457 -static void free_compound_page(struct page *page)
74458 +void free_compound_page(struct page *page)
74459 {
74460 __free_pages_ok(page, compound_order(page));
74461 }
74462 @@ -697,6 +697,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
74463 int i;
74464 int bad = 0;
74465
74466 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
74467 + unsigned long index = 1UL << order;
74468 +#endif
74469 +
74470 trace_mm_page_free(page, order);
74471 kmemcheck_free_shadow(page, order);
74472
74473 @@ -712,6 +716,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
74474 debug_check_no_obj_freed(page_address(page),
74475 PAGE_SIZE << order);
74476 }
74477 +
74478 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
74479 + for (; index; --index)
74480 + sanitize_highpage(page + index - 1);
74481 +#endif
74482 +
74483 arch_free_page(page, order);
74484 kernel_map_pages(page, 1 << order, 0);
74485
74486 @@ -853,8 +863,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
74487 arch_alloc_page(page, order);
74488 kernel_map_pages(page, 1 << order, 1);
74489
74490 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
74491 if (gfp_flags & __GFP_ZERO)
74492 prep_zero_page(page, order, gfp_flags);
74493 +#endif
74494
74495 if (order && (gfp_flags & __GFP_COMP))
74496 prep_compound_page(page, order);
74497 @@ -3648,7 +3660,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
74498 unsigned long pfn;
74499
74500 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
74501 +#ifdef CONFIG_X86_32
74502 + /* boot failures in VMware 8 on 32bit vanilla since
74503 + this change */
74504 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
74505 +#else
74506 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
74507 +#endif
74508 return 1;
74509 }
74510 return 0;
74511 diff --git a/mm/percpu.c b/mm/percpu.c
74512 index bb4be74..a43ea85 100644
74513 --- a/mm/percpu.c
74514 +++ b/mm/percpu.c
74515 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
74516 static unsigned int pcpu_high_unit_cpu __read_mostly;
74517
74518 /* the address of the first chunk which starts with the kernel static area */
74519 -void *pcpu_base_addr __read_mostly;
74520 +void *pcpu_base_addr __read_only;
74521 EXPORT_SYMBOL_GPL(pcpu_base_addr);
74522
74523 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
74524 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
74525 index 926b466..b23df53 100644
74526 --- a/mm/process_vm_access.c
74527 +++ b/mm/process_vm_access.c
74528 @@ -13,6 +13,7 @@
74529 #include <linux/uio.h>
74530 #include <linux/sched.h>
74531 #include <linux/highmem.h>
74532 +#include <linux/security.h>
74533 #include <linux/ptrace.h>
74534 #include <linux/slab.h>
74535 #include <linux/syscalls.h>
74536 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
74537 size_t iov_l_curr_offset = 0;
74538 ssize_t iov_len;
74539
74540 + return -ENOSYS; // PaX: until properly audited
74541 +
74542 /*
74543 * Work out how many pages of struct pages we're going to need
74544 * when eventually calling get_user_pages
74545 */
74546 for (i = 0; i < riovcnt; i++) {
74547 iov_len = rvec[i].iov_len;
74548 - if (iov_len > 0) {
74549 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
74550 - + iov_len)
74551 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
74552 - / PAGE_SIZE + 1;
74553 - nr_pages = max(nr_pages, nr_pages_iov);
74554 - }
74555 + if (iov_len <= 0)
74556 + continue;
74557 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
74558 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
74559 + nr_pages = max(nr_pages, nr_pages_iov);
74560 }
74561
74562 if (nr_pages == 0)
74563 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
74564 goto free_proc_pages;
74565 }
74566
74567 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
74568 + rc = -EPERM;
74569 + goto put_task_struct;
74570 + }
74571 +
74572 mm = mm_access(task, PTRACE_MODE_ATTACH);
74573 if (!mm || IS_ERR(mm)) {
74574 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
74575 diff --git a/mm/rmap.c b/mm/rmap.c
74576 index aa95e59..b681a63 100644
74577 --- a/mm/rmap.c
74578 +++ b/mm/rmap.c
74579 @@ -168,6 +168,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74580 struct anon_vma *anon_vma = vma->anon_vma;
74581 struct anon_vma_chain *avc;
74582
74583 +#ifdef CONFIG_PAX_SEGMEXEC
74584 + struct anon_vma_chain *avc_m = NULL;
74585 +#endif
74586 +
74587 might_sleep();
74588 if (unlikely(!anon_vma)) {
74589 struct mm_struct *mm = vma->vm_mm;
74590 @@ -177,6 +181,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74591 if (!avc)
74592 goto out_enomem;
74593
74594 +#ifdef CONFIG_PAX_SEGMEXEC
74595 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
74596 + if (!avc_m)
74597 + goto out_enomem_free_avc;
74598 +#endif
74599 +
74600 anon_vma = find_mergeable_anon_vma(vma);
74601 allocated = NULL;
74602 if (!anon_vma) {
74603 @@ -190,6 +200,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74604 /* page_table_lock to protect against threads */
74605 spin_lock(&mm->page_table_lock);
74606 if (likely(!vma->anon_vma)) {
74607 +
74608 +#ifdef CONFIG_PAX_SEGMEXEC
74609 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
74610 +
74611 + if (vma_m) {
74612 + BUG_ON(vma_m->anon_vma);
74613 + vma_m->anon_vma = anon_vma;
74614 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
74615 + avc_m = NULL;
74616 + }
74617 +#endif
74618 +
74619 vma->anon_vma = anon_vma;
74620 anon_vma_chain_link(vma, avc, anon_vma);
74621 allocated = NULL;
74622 @@ -200,12 +222,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74623
74624 if (unlikely(allocated))
74625 put_anon_vma(allocated);
74626 +
74627 +#ifdef CONFIG_PAX_SEGMEXEC
74628 + if (unlikely(avc_m))
74629 + anon_vma_chain_free(avc_m);
74630 +#endif
74631 +
74632 if (unlikely(avc))
74633 anon_vma_chain_free(avc);
74634 }
74635 return 0;
74636
74637 out_enomem_free_avc:
74638 +
74639 +#ifdef CONFIG_PAX_SEGMEXEC
74640 + if (avc_m)
74641 + anon_vma_chain_free(avc_m);
74642 +#endif
74643 +
74644 anon_vma_chain_free(avc);
74645 out_enomem:
74646 return -ENOMEM;
74647 @@ -241,7 +275,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
74648 * Attach the anon_vmas from src to dst.
74649 * Returns 0 on success, -ENOMEM on failure.
74650 */
74651 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
74652 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
74653 {
74654 struct anon_vma_chain *avc, *pavc;
74655 struct anon_vma *root = NULL;
74656 @@ -319,7 +353,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
74657 * the corresponding VMA in the parent process is attached to.
74658 * Returns 0 on success, non-zero on failure.
74659 */
74660 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
74661 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
74662 {
74663 struct anon_vma_chain *avc;
74664 struct anon_vma *anon_vma;
74665 diff --git a/mm/shmem.c b/mm/shmem.c
74666 index d2eeca1..3f160be 100644
74667 --- a/mm/shmem.c
74668 +++ b/mm/shmem.c
74669 @@ -31,7 +31,7 @@
74670 #include <linux/export.h>
74671 #include <linux/swap.h>
74672
74673 -static struct vfsmount *shm_mnt;
74674 +struct vfsmount *shm_mnt;
74675
74676 #ifdef CONFIG_SHMEM
74677 /*
74678 @@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
74679 #define BOGO_DIRENT_SIZE 20
74680
74681 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
74682 -#define SHORT_SYMLINK_LEN 128
74683 +#define SHORT_SYMLINK_LEN 64
74684
74685 struct shmem_xattr {
74686 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
74687 @@ -2594,8 +2594,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
74688 int err = -ENOMEM;
74689
74690 /* Round up to L1_CACHE_BYTES to resist false sharing */
74691 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
74692 - L1_CACHE_BYTES), GFP_KERNEL);
74693 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
74694 if (!sbinfo)
74695 return -ENOMEM;
74696
74697 diff --git a/mm/slab.c b/mm/slab.c
74698 index d066037..5bb78d9 100644
74699 --- a/mm/slab.c
74700 +++ b/mm/slab.c
74701 @@ -164,7 +164,7 @@ static bool pfmemalloc_active __read_mostly;
74702
74703 /* Legal flag mask for kmem_cache_create(). */
74704 #if DEBUG
74705 -# define CREATE_MASK (SLAB_RED_ZONE | \
74706 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
74707 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
74708 SLAB_CACHE_DMA | \
74709 SLAB_STORE_USER | \
74710 @@ -172,7 +172,7 @@ static bool pfmemalloc_active __read_mostly;
74711 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74712 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
74713 #else
74714 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
74715 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
74716 SLAB_CACHE_DMA | \
74717 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
74718 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74719 @@ -322,7 +322,7 @@ struct kmem_list3 {
74720 * Need this for bootstrapping a per node allocator.
74721 */
74722 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
74723 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
74724 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
74725 #define CACHE_CACHE 0
74726 #define SIZE_AC MAX_NUMNODES
74727 #define SIZE_L3 (2 * MAX_NUMNODES)
74728 @@ -423,10 +423,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
74729 if ((x)->max_freeable < i) \
74730 (x)->max_freeable = i; \
74731 } while (0)
74732 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
74733 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
74734 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
74735 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
74736 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
74737 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
74738 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
74739 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
74740 #else
74741 #define STATS_INC_ACTIVE(x) do { } while (0)
74742 #define STATS_DEC_ACTIVE(x) do { } while (0)
74743 @@ -549,7 +549,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
74744 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
74745 */
74746 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
74747 - const struct slab *slab, void *obj)
74748 + const struct slab *slab, const void *obj)
74749 {
74750 u32 offset = (obj - slab->s_mem);
74751 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
74752 @@ -570,12 +570,13 @@ EXPORT_SYMBOL(malloc_sizes);
74753 struct cache_names {
74754 char *name;
74755 char *name_dma;
74756 + char *name_usercopy;
74757 };
74758
74759 static struct cache_names __initdata cache_names[] = {
74760 -#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
74761 +#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
74762 #include <linux/kmalloc_sizes.h>
74763 - {NULL,}
74764 + {NULL}
74765 #undef CACHE
74766 };
74767
74768 @@ -736,6 +737,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
74769 if (unlikely(gfpflags & GFP_DMA))
74770 return csizep->cs_dmacachep;
74771 #endif
74772 +
74773 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74774 + if (unlikely(gfpflags & GFP_USERCOPY))
74775 + return csizep->cs_usercopycachep;
74776 +#endif
74777 +
74778 return csizep->cs_cachep;
74779 }
74780
74781 @@ -1684,7 +1691,7 @@ void __init kmem_cache_init(void)
74782 sizes[INDEX_AC].cs_cachep = __kmem_cache_create(names[INDEX_AC].name,
74783 sizes[INDEX_AC].cs_size,
74784 ARCH_KMALLOC_MINALIGN,
74785 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74786 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74787 NULL);
74788
74789 if (INDEX_AC != INDEX_L3) {
74790 @@ -1692,7 +1699,7 @@ void __init kmem_cache_init(void)
74791 __kmem_cache_create(names[INDEX_L3].name,
74792 sizes[INDEX_L3].cs_size,
74793 ARCH_KMALLOC_MINALIGN,
74794 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74795 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74796 NULL);
74797 }
74798
74799 @@ -1710,7 +1717,7 @@ void __init kmem_cache_init(void)
74800 sizes->cs_cachep = __kmem_cache_create(names->name,
74801 sizes->cs_size,
74802 ARCH_KMALLOC_MINALIGN,
74803 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74804 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74805 NULL);
74806 }
74807 #ifdef CONFIG_ZONE_DMA
74808 @@ -1722,6 +1729,16 @@ void __init kmem_cache_init(void)
74809 SLAB_PANIC,
74810 NULL);
74811 #endif
74812 +
74813 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74814 + sizes->cs_usercopycachep = kmem_cache_create(
74815 + names->name_usercopy,
74816 + sizes->cs_size,
74817 + ARCH_KMALLOC_MINALIGN,
74818 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74819 + NULL);
74820 +#endif
74821 +
74822 sizes++;
74823 names++;
74824 }
74825 @@ -4467,10 +4484,10 @@ static int s_show(struct seq_file *m, void *p)
74826 }
74827 /* cpu stats */
74828 {
74829 - unsigned long allochit = atomic_read(&cachep->allochit);
74830 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
74831 - unsigned long freehit = atomic_read(&cachep->freehit);
74832 - unsigned long freemiss = atomic_read(&cachep->freemiss);
74833 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
74834 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
74835 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
74836 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
74837
74838 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
74839 allochit, allocmiss, freehit, freemiss);
74840 @@ -4729,13 +4746,71 @@ static int __init slab_proc_init(void)
74841 {
74842 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
74843 #ifdef CONFIG_DEBUG_SLAB_LEAK
74844 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
74845 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
74846 #endif
74847 return 0;
74848 }
74849 module_init(slab_proc_init);
74850 #endif
74851
74852 +bool is_usercopy_object(const void *ptr)
74853 +{
74854 + struct page *page;
74855 + struct kmem_cache *cachep;
74856 +
74857 + if (ZERO_OR_NULL_PTR(ptr))
74858 + return false;
74859 +
74860 + if (!slab_is_available())
74861 + return false;
74862 +
74863 + if (!virt_addr_valid(ptr))
74864 + return false;
74865 +
74866 + page = virt_to_head_page(ptr);
74867 +
74868 + if (!PageSlab(page))
74869 + return false;
74870 +
74871 + cachep = page_get_cache(page);
74872 + return cachep->flags & SLAB_USERCOPY;
74873 +}
74874 +
74875 +#ifdef CONFIG_PAX_USERCOPY
74876 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74877 +{
74878 + struct page *page;
74879 + struct kmem_cache *cachep;
74880 + struct slab *slabp;
74881 + unsigned int objnr;
74882 + unsigned long offset;
74883 +
74884 + if (ZERO_OR_NULL_PTR(ptr))
74885 + return "<null>";
74886 +
74887 + if (!virt_addr_valid(ptr))
74888 + return NULL;
74889 +
74890 + page = virt_to_head_page(ptr);
74891 +
74892 + if (!PageSlab(page))
74893 + return NULL;
74894 +
74895 + cachep = page_get_cache(page);
74896 + if (!(cachep->flags & SLAB_USERCOPY))
74897 + return cachep->name;
74898 +
74899 + slabp = page->slab_page;
74900 + objnr = obj_to_index(cachep, slabp, ptr);
74901 + BUG_ON(objnr >= cachep->num);
74902 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
74903 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
74904 + return NULL;
74905 +
74906 + return cachep->name;
74907 +}
74908 +#endif
74909 +
74910 /**
74911 * ksize - get the actual amount of memory allocated for a given object
74912 * @objp: Pointer to the object
74913 diff --git a/mm/slob.c b/mm/slob.c
74914 index 45d4ca7..88943c1 100644
74915 --- a/mm/slob.c
74916 +++ b/mm/slob.c
74917 @@ -159,7 +159,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
74918 /*
74919 * Return the size of a slob block.
74920 */
74921 -static slobidx_t slob_units(slob_t *s)
74922 +static slobidx_t slob_units(const slob_t *s)
74923 {
74924 if (s->units > 0)
74925 return s->units;
74926 @@ -169,7 +169,7 @@ static slobidx_t slob_units(slob_t *s)
74927 /*
74928 * Return the next free slob block pointer after this one.
74929 */
74930 -static slob_t *slob_next(slob_t *s)
74931 +static slob_t *slob_next(const slob_t *s)
74932 {
74933 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
74934 slobidx_t next;
74935 @@ -184,14 +184,14 @@ static slob_t *slob_next(slob_t *s)
74936 /*
74937 * Returns true if s is the last free block in its page.
74938 */
74939 -static int slob_last(slob_t *s)
74940 +static int slob_last(const slob_t *s)
74941 {
74942 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
74943 }
74944
74945 -static void *slob_new_pages(gfp_t gfp, int order, int node)
74946 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
74947 {
74948 - void *page;
74949 + struct page *page;
74950
74951 #ifdef CONFIG_NUMA
74952 if (node != -1)
74953 @@ -203,14 +203,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
74954 if (!page)
74955 return NULL;
74956
74957 - return page_address(page);
74958 + __SetPageSlab(page);
74959 + return page;
74960 }
74961
74962 -static void slob_free_pages(void *b, int order)
74963 +static void slob_free_pages(struct page *sp, int order)
74964 {
74965 if (current->reclaim_state)
74966 current->reclaim_state->reclaimed_slab += 1 << order;
74967 - free_pages((unsigned long)b, order);
74968 + __ClearPageSlab(sp);
74969 + reset_page_mapcount(sp);
74970 + sp->private = 0;
74971 + __free_pages(sp, order);
74972 }
74973
74974 /*
74975 @@ -315,15 +319,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
74976
74977 /* Not enough space: must allocate a new page */
74978 if (!b) {
74979 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
74980 - if (!b)
74981 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
74982 + if (!sp)
74983 return NULL;
74984 - sp = virt_to_page(b);
74985 - __SetPageSlab(sp);
74986 + b = page_address(sp);
74987
74988 spin_lock_irqsave(&slob_lock, flags);
74989 sp->units = SLOB_UNITS(PAGE_SIZE);
74990 sp->freelist = b;
74991 + sp->private = 0;
74992 INIT_LIST_HEAD(&sp->list);
74993 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
74994 set_slob_page_free(sp, slob_list);
74995 @@ -361,9 +365,7 @@ static void slob_free(void *block, int size)
74996 if (slob_page_free(sp))
74997 clear_slob_page_free(sp);
74998 spin_unlock_irqrestore(&slob_lock, flags);
74999 - __ClearPageSlab(sp);
75000 - reset_page_mapcount(sp);
75001 - slob_free_pages(b, 0);
75002 + slob_free_pages(sp, 0);
75003 return;
75004 }
75005
75006 @@ -425,11 +427,10 @@ out:
75007 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
75008 */
75009
75010 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
75011 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
75012 {
75013 - unsigned int *m;
75014 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75015 - void *ret;
75016 + slob_t *m;
75017 + void *ret = NULL;
75018
75019 gfp &= gfp_allowed_mask;
75020
75021 @@ -443,20 +444,23 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
75022
75023 if (!m)
75024 return NULL;
75025 - *m = size;
75026 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
75027 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
75028 + m[0].units = size;
75029 + m[1].units = align;
75030 ret = (void *)m + align;
75031
75032 trace_kmalloc_node(_RET_IP_, ret,
75033 size, size + align, gfp, node);
75034 } else {
75035 unsigned int order = get_order(size);
75036 + struct page *page;
75037
75038 if (likely(order))
75039 gfp |= __GFP_COMP;
75040 - ret = slob_new_pages(gfp, order, node);
75041 - if (ret) {
75042 - struct page *page;
75043 - page = virt_to_page(ret);
75044 + page = slob_new_pages(gfp, order, node);
75045 + if (page) {
75046 + ret = page_address(page);
75047 page->private = size;
75048 }
75049
75050 @@ -464,7 +468,16 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
75051 size, PAGE_SIZE << order, gfp, node);
75052 }
75053
75054 - kmemleak_alloc(ret, size, 1, gfp);
75055 + return ret;
75056 +}
75057 +
75058 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
75059 +{
75060 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75061 + void *ret = __kmalloc_node_align(size, gfp, node, align);
75062 +
75063 + if (!ZERO_OR_NULL_PTR(ret))
75064 + kmemleak_alloc(ret, size, 1, gfp);
75065 return ret;
75066 }
75067 EXPORT_SYMBOL(__kmalloc_node);
75068 @@ -480,15 +493,91 @@ void kfree(const void *block)
75069 kmemleak_free(block);
75070
75071 sp = virt_to_page(block);
75072 - if (PageSlab(sp)) {
75073 + VM_BUG_ON(!PageSlab(sp));
75074 + if (!sp->private) {
75075 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75076 - unsigned int *m = (unsigned int *)(block - align);
75077 - slob_free(m, *m + align);
75078 - } else
75079 + slob_t *m = (slob_t *)(block - align);
75080 + slob_free(m, m[0].units + align);
75081 + } else {
75082 + __ClearPageSlab(sp);
75083 + reset_page_mapcount(sp);
75084 + sp->private = 0;
75085 put_page(sp);
75086 + }
75087 }
75088 EXPORT_SYMBOL(kfree);
75089
75090 +bool is_usercopy_object(const void *ptr)
75091 +{
75092 + if (!slab_is_available())
75093 + return false;
75094 +
75095 + // PAX: TODO
75096 +
75097 + return false;
75098 +}
75099 +
75100 +#ifdef CONFIG_PAX_USERCOPY
75101 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
75102 +{
75103 + struct page *page;
75104 + const slob_t *free;
75105 + const void *base;
75106 + unsigned long flags;
75107 +
75108 + if (ZERO_OR_NULL_PTR(ptr))
75109 + return "<null>";
75110 +
75111 + if (!virt_addr_valid(ptr))
75112 + return NULL;
75113 +
75114 + page = virt_to_head_page(ptr);
75115 + if (!PageSlab(page))
75116 + return NULL;
75117 +
75118 + if (page->private) {
75119 + base = page;
75120 + if (base <= ptr && n <= page->private - (ptr - base))
75121 + return NULL;
75122 + return "<slob>";
75123 + }
75124 +
75125 + /* some tricky double walking to find the chunk */
75126 + spin_lock_irqsave(&slob_lock, flags);
75127 + base = (void *)((unsigned long)ptr & PAGE_MASK);
75128 + free = page->freelist;
75129 +
75130 + while (!slob_last(free) && (void *)free <= ptr) {
75131 + base = free + slob_units(free);
75132 + free = slob_next(free);
75133 + }
75134 +
75135 + while (base < (void *)free) {
75136 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
75137 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
75138 + int offset;
75139 +
75140 + if (ptr < base + align)
75141 + break;
75142 +
75143 + offset = ptr - base - align;
75144 + if (offset >= m) {
75145 + base += size;
75146 + continue;
75147 + }
75148 +
75149 + if (n > m - offset)
75150 + break;
75151 +
75152 + spin_unlock_irqrestore(&slob_lock, flags);
75153 + return NULL;
75154 + }
75155 +
75156 + spin_unlock_irqrestore(&slob_lock, flags);
75157 + return "<slob>";
75158 +}
75159 +#endif
75160 +
75161 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
75162 size_t ksize(const void *block)
75163 {
75164 @@ -499,10 +588,11 @@ size_t ksize(const void *block)
75165 return 0;
75166
75167 sp = virt_to_page(block);
75168 - if (PageSlab(sp)) {
75169 + VM_BUG_ON(!PageSlab(sp));
75170 + if (!sp->private) {
75171 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75172 - unsigned int *m = (unsigned int *)(block - align);
75173 - return SLOB_UNITS(*m) * SLOB_UNIT;
75174 + slob_t *m = (slob_t *)(block - align);
75175 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
75176 } else
75177 return sp->private;
75178 }
75179 @@ -513,8 +603,13 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
75180 {
75181 struct kmem_cache *c;
75182
75183 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75184 + c = __kmalloc_node_align(sizeof(struct kmem_cache),
75185 + GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
75186 +#else
75187 c = slob_alloc(sizeof(struct kmem_cache),
75188 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
75189 +#endif
75190
75191 if (c) {
75192 c->name = name;
75193 @@ -549,23 +644,33 @@ EXPORT_SYMBOL(kmem_cache_destroy);
75194
75195 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
75196 {
75197 - void *b;
75198 + void *b = NULL;
75199
75200 flags &= gfp_allowed_mask;
75201
75202 lockdep_trace_alloc(flags);
75203
75204 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75205 + b = __kmalloc_node_align(c->size, flags, node, c->align);
75206 +#else
75207 if (c->size < PAGE_SIZE) {
75208 b = slob_alloc(c->size, flags, c->align, node);
75209 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
75210 SLOB_UNITS(c->size) * SLOB_UNIT,
75211 flags, node);
75212 } else {
75213 - b = slob_new_pages(flags, get_order(c->size), node);
75214 + struct page *sp;
75215 +
75216 + sp = slob_new_pages(flags, get_order(c->size), node);
75217 + if (sp) {
75218 + b = page_address(sp);
75219 + sp->private = c->size;
75220 + }
75221 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
75222 PAGE_SIZE << get_order(c->size),
75223 flags, node);
75224 }
75225 +#endif
75226
75227 if (c->ctor)
75228 c->ctor(b);
75229 @@ -577,10 +682,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
75230
75231 static void __kmem_cache_free(void *b, int size)
75232 {
75233 - if (size < PAGE_SIZE)
75234 + struct page *sp;
75235 +
75236 + sp = virt_to_page(b);
75237 + BUG_ON(!PageSlab(sp));
75238 + if (!sp->private)
75239 slob_free(b, size);
75240 else
75241 - slob_free_pages(b, get_order(size));
75242 + slob_free_pages(sp, get_order(size));
75243 }
75244
75245 static void kmem_rcu_free(struct rcu_head *head)
75246 @@ -593,17 +702,31 @@ static void kmem_rcu_free(struct rcu_head *head)
75247
75248 void kmem_cache_free(struct kmem_cache *c, void *b)
75249 {
75250 + int size = c->size;
75251 +
75252 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75253 + if (size + c->align < PAGE_SIZE) {
75254 + size += c->align;
75255 + b -= c->align;
75256 + }
75257 +#endif
75258 +
75259 kmemleak_free_recursive(b, c->flags);
75260 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
75261 struct slob_rcu *slob_rcu;
75262 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
75263 - slob_rcu->size = c->size;
75264 + slob_rcu = b + (size - sizeof(struct slob_rcu));
75265 + slob_rcu->size = size;
75266 call_rcu(&slob_rcu->head, kmem_rcu_free);
75267 } else {
75268 - __kmem_cache_free(b, c->size);
75269 + __kmem_cache_free(b, size);
75270 }
75271
75272 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75273 + trace_kfree(_RET_IP_, b);
75274 +#else
75275 trace_kmem_cache_free(_RET_IP_, b);
75276 +#endif
75277 +
75278 }
75279 EXPORT_SYMBOL(kmem_cache_free);
75280
75281 diff --git a/mm/slub.c b/mm/slub.c
75282 index 2fdd96f..1e2f893 100644
75283 --- a/mm/slub.c
75284 +++ b/mm/slub.c
75285 @@ -201,7 +201,7 @@ struct track {
75286
75287 enum track_item { TRACK_ALLOC, TRACK_FREE };
75288
75289 -#ifdef CONFIG_SYSFS
75290 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75291 static int sysfs_slab_add(struct kmem_cache *);
75292 static int sysfs_slab_alias(struct kmem_cache *, const char *);
75293 static void sysfs_slab_remove(struct kmem_cache *);
75294 @@ -525,7 +525,7 @@ static void print_track(const char *s, struct track *t)
75295 if (!t->addr)
75296 return;
75297
75298 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
75299 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
75300 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
75301 #ifdef CONFIG_STACKTRACE
75302 {
75303 @@ -2612,6 +2612,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
75304
75305 page = virt_to_head_page(x);
75306
75307 + BUG_ON(!PageSlab(page));
75308 +
75309 slab_free(s, page, x, _RET_IP_);
75310
75311 trace_kmem_cache_free(_RET_IP_, x);
75312 @@ -2645,7 +2647,7 @@ static int slub_min_objects;
75313 * Merge control. If this is set then no merging of slab caches will occur.
75314 * (Could be removed. This was introduced to pacify the merge skeptics.)
75315 */
75316 -static int slub_nomerge;
75317 +static int slub_nomerge = 1;
75318
75319 /*
75320 * Calculate the order of allocation given an slab object size.
75321 @@ -3098,7 +3100,7 @@ static int kmem_cache_open(struct kmem_cache *s,
75322 else
75323 s->cpu_partial = 30;
75324
75325 - s->refcount = 1;
75326 + atomic_set(&s->refcount, 1);
75327 #ifdef CONFIG_NUMA
75328 s->remote_node_defrag_ratio = 1000;
75329 #endif
75330 @@ -3202,8 +3204,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
75331 void kmem_cache_destroy(struct kmem_cache *s)
75332 {
75333 mutex_lock(&slab_mutex);
75334 - s->refcount--;
75335 - if (!s->refcount) {
75336 + if (atomic_dec_and_test(&s->refcount)) {
75337 list_del(&s->list);
75338 mutex_unlock(&slab_mutex);
75339 if (kmem_cache_close(s)) {
75340 @@ -3232,6 +3233,10 @@ static struct kmem_cache *kmem_cache;
75341 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
75342 #endif
75343
75344 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75345 +static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
75346 +#endif
75347 +
75348 static int __init setup_slub_min_order(char *str)
75349 {
75350 get_option(&str, &slub_min_order);
75351 @@ -3346,6 +3351,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
75352 return kmalloc_dma_caches[index];
75353
75354 #endif
75355 +
75356 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75357 + if (flags & SLAB_USERCOPY)
75358 + return kmalloc_usercopy_caches[index];
75359 +
75360 +#endif
75361 +
75362 return kmalloc_caches[index];
75363 }
75364
75365 @@ -3414,6 +3426,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
75366 EXPORT_SYMBOL(__kmalloc_node);
75367 #endif
75368
75369 +bool is_usercopy_object(const void *ptr)
75370 +{
75371 + struct page *page;
75372 + struct kmem_cache *s;
75373 +
75374 + if (ZERO_OR_NULL_PTR(ptr))
75375 + return false;
75376 +
75377 + if (!slab_is_available())
75378 + return false;
75379 +
75380 + if (!virt_addr_valid(ptr))
75381 + return false;
75382 +
75383 + page = virt_to_head_page(ptr);
75384 +
75385 + if (!PageSlab(page))
75386 + return false;
75387 +
75388 + s = page->slab;
75389 + return s->flags & SLAB_USERCOPY;
75390 +}
75391 +
75392 +#ifdef CONFIG_PAX_USERCOPY
75393 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
75394 +{
75395 + struct page *page;
75396 + struct kmem_cache *s;
75397 + unsigned long offset;
75398 +
75399 + if (ZERO_OR_NULL_PTR(ptr))
75400 + return "<null>";
75401 +
75402 + if (!virt_addr_valid(ptr))
75403 + return NULL;
75404 +
75405 + page = virt_to_head_page(ptr);
75406 +
75407 + if (!PageSlab(page))
75408 + return NULL;
75409 +
75410 + s = page->slab;
75411 + if (!(s->flags & SLAB_USERCOPY))
75412 + return s->name;
75413 +
75414 + offset = (ptr - page_address(page)) % s->size;
75415 + if (offset <= s->object_size && n <= s->object_size - offset)
75416 + return NULL;
75417 +
75418 + return s->name;
75419 +}
75420 +#endif
75421 +
75422 size_t ksize(const void *object)
75423 {
75424 struct page *page;
75425 @@ -3688,7 +3753,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
75426 int node;
75427
75428 list_add(&s->list, &slab_caches);
75429 - s->refcount = -1;
75430 + atomic_set(&s->refcount, -1);
75431
75432 for_each_node_state(node, N_NORMAL_MEMORY) {
75433 struct kmem_cache_node *n = get_node(s, node);
75434 @@ -3808,17 +3873,17 @@ void __init kmem_cache_init(void)
75435
75436 /* Caches that are not of the two-to-the-power-of size */
75437 if (KMALLOC_MIN_SIZE <= 32) {
75438 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
75439 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
75440 caches++;
75441 }
75442
75443 if (KMALLOC_MIN_SIZE <= 64) {
75444 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
75445 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
75446 caches++;
75447 }
75448
75449 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
75450 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
75451 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
75452 caches++;
75453 }
75454
75455 @@ -3860,6 +3925,22 @@ void __init kmem_cache_init(void)
75456 }
75457 }
75458 #endif
75459 +
75460 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75461 + for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
75462 + struct kmem_cache *s = kmalloc_caches[i];
75463 +
75464 + if (s && s->size) {
75465 + char *name = kasprintf(GFP_NOWAIT,
75466 + "usercopy-kmalloc-%d", s->object_size);
75467 +
75468 + BUG_ON(!name);
75469 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
75470 + s->object_size, SLAB_USERCOPY);
75471 + }
75472 + }
75473 +#endif
75474 +
75475 printk(KERN_INFO
75476 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
75477 " CPUs=%d, Nodes=%d\n",
75478 @@ -3886,7 +3967,7 @@ static int slab_unmergeable(struct kmem_cache *s)
75479 /*
75480 * We may have set a slab to be unmergeable during bootstrap.
75481 */
75482 - if (s->refcount < 0)
75483 + if (atomic_read(&s->refcount) < 0)
75484 return 1;
75485
75486 return 0;
75487 @@ -3941,7 +4022,7 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
75488
75489 s = find_mergeable(size, align, flags, name, ctor);
75490 if (s) {
75491 - s->refcount++;
75492 + atomic_inc(&s->refcount);
75493 /*
75494 * Adjust the object sizes so that we clear
75495 * the complete object on kzalloc.
75496 @@ -3950,7 +4031,7 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
75497 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
75498
75499 if (sysfs_slab_alias(s, name)) {
75500 - s->refcount--;
75501 + atomic_dec(&s->refcount);
75502 return NULL;
75503 }
75504 return s;
75505 @@ -4072,7 +4153,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
75506 }
75507 #endif
75508
75509 -#ifdef CONFIG_SYSFS
75510 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75511 static int count_inuse(struct page *page)
75512 {
75513 return page->inuse;
75514 @@ -4459,12 +4540,12 @@ static void resiliency_test(void)
75515 validate_slab_cache(kmalloc_caches[9]);
75516 }
75517 #else
75518 -#ifdef CONFIG_SYSFS
75519 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75520 static void resiliency_test(void) {};
75521 #endif
75522 #endif
75523
75524 -#ifdef CONFIG_SYSFS
75525 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75526 enum slab_stat_type {
75527 SL_ALL, /* All slabs */
75528 SL_PARTIAL, /* Only partially allocated slabs */
75529 @@ -4708,7 +4789,7 @@ SLAB_ATTR_RO(ctor);
75530
75531 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
75532 {
75533 - return sprintf(buf, "%d\n", s->refcount - 1);
75534 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
75535 }
75536 SLAB_ATTR_RO(aliases);
75537
75538 @@ -5279,6 +5360,7 @@ static char *create_unique_id(struct kmem_cache *s)
75539 return name;
75540 }
75541
75542 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75543 static int sysfs_slab_add(struct kmem_cache *s)
75544 {
75545 int err;
75546 @@ -5341,6 +5423,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
75547 kobject_del(&s->kobj);
75548 kobject_put(&s->kobj);
75549 }
75550 +#endif
75551
75552 /*
75553 * Need to buffer aliases during bootup until sysfs becomes
75554 @@ -5354,6 +5437,7 @@ struct saved_alias {
75555
75556 static struct saved_alias *alias_list;
75557
75558 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75559 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
75560 {
75561 struct saved_alias *al;
75562 @@ -5376,6 +5460,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
75563 alias_list = al;
75564 return 0;
75565 }
75566 +#endif
75567
75568 static int __init slab_sysfs_init(void)
75569 {
75570 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
75571 index 1b7e22a..3fcd4f3 100644
75572 --- a/mm/sparse-vmemmap.c
75573 +++ b/mm/sparse-vmemmap.c
75574 @@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
75575 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
75576 if (!p)
75577 return NULL;
75578 - pud_populate(&init_mm, pud, p);
75579 + pud_populate_kernel(&init_mm, pud, p);
75580 }
75581 return pud;
75582 }
75583 @@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
75584 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
75585 if (!p)
75586 return NULL;
75587 - pgd_populate(&init_mm, pgd, p);
75588 + pgd_populate_kernel(&init_mm, pgd, p);
75589 }
75590 return pgd;
75591 }
75592 diff --git a/mm/swap.c b/mm/swap.c
75593 index 7782588..228c784 100644
75594 --- a/mm/swap.c
75595 +++ b/mm/swap.c
75596 @@ -30,6 +30,7 @@
75597 #include <linux/backing-dev.h>
75598 #include <linux/memcontrol.h>
75599 #include <linux/gfp.h>
75600 +#include <linux/hugetlb.h>
75601
75602 #include "internal.h"
75603
75604 @@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
75605
75606 __page_cache_release(page);
75607 dtor = get_compound_page_dtor(page);
75608 + if (!PageHuge(page))
75609 + BUG_ON(dtor != free_compound_page);
75610 (*dtor)(page);
75611 }
75612
75613 diff --git a/mm/swapfile.c b/mm/swapfile.c
75614 index 14e254c..a6af32c 100644
75615 --- a/mm/swapfile.c
75616 +++ b/mm/swapfile.c
75617 @@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
75618
75619 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
75620 /* Activity counter to indicate that a swapon or swapoff has occurred */
75621 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
75622 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
75623
75624 static inline unsigned char swap_count(unsigned char ent)
75625 {
75626 @@ -1603,7 +1603,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
75627 }
75628 filp_close(swap_file, NULL);
75629 err = 0;
75630 - atomic_inc(&proc_poll_event);
75631 + atomic_inc_unchecked(&proc_poll_event);
75632 wake_up_interruptible(&proc_poll_wait);
75633
75634 out_dput:
75635 @@ -1619,8 +1619,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
75636
75637 poll_wait(file, &proc_poll_wait, wait);
75638
75639 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
75640 - seq->poll_event = atomic_read(&proc_poll_event);
75641 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
75642 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
75643 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
75644 }
75645
75646 @@ -1718,7 +1718,7 @@ static int swaps_open(struct inode *inode, struct file *file)
75647 return ret;
75648
75649 seq = file->private_data;
75650 - seq->poll_event = atomic_read(&proc_poll_event);
75651 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
75652 return 0;
75653 }
75654
75655 @@ -2060,7 +2060,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
75656 (frontswap_map) ? "FS" : "");
75657
75658 mutex_unlock(&swapon_mutex);
75659 - atomic_inc(&proc_poll_event);
75660 + atomic_inc_unchecked(&proc_poll_event);
75661 wake_up_interruptible(&proc_poll_wait);
75662
75663 if (S_ISREG(inode->i_mode))
75664 diff --git a/mm/util.c b/mm/util.c
75665 index 8c7265a..c96d884 100644
75666 --- a/mm/util.c
75667 +++ b/mm/util.c
75668 @@ -285,6 +285,12 @@ done:
75669 void arch_pick_mmap_layout(struct mm_struct *mm)
75670 {
75671 mm->mmap_base = TASK_UNMAPPED_BASE;
75672 +
75673 +#ifdef CONFIG_PAX_RANDMMAP
75674 + if (mm->pax_flags & MF_PAX_RANDMMAP)
75675 + mm->mmap_base += mm->delta_mmap;
75676 +#endif
75677 +
75678 mm->get_unmapped_area = arch_get_unmapped_area;
75679 mm->unmap_area = arch_unmap_area;
75680 }
75681 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
75682 index 2bb90b1..ed47e53 100644
75683 --- a/mm/vmalloc.c
75684 +++ b/mm/vmalloc.c
75685 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
75686
75687 pte = pte_offset_kernel(pmd, addr);
75688 do {
75689 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
75690 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
75691 +
75692 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75693 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
75694 + BUG_ON(!pte_exec(*pte));
75695 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
75696 + continue;
75697 + }
75698 +#endif
75699 +
75700 + {
75701 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
75702 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
75703 + }
75704 } while (pte++, addr += PAGE_SIZE, addr != end);
75705 }
75706
75707 @@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
75708 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
75709 {
75710 pte_t *pte;
75711 + int ret = -ENOMEM;
75712
75713 /*
75714 * nr is a running index into the array which helps higher level
75715 @@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
75716 pte = pte_alloc_kernel(pmd, addr);
75717 if (!pte)
75718 return -ENOMEM;
75719 +
75720 + pax_open_kernel();
75721 do {
75722 struct page *page = pages[*nr];
75723
75724 - if (WARN_ON(!pte_none(*pte)))
75725 - return -EBUSY;
75726 - if (WARN_ON(!page))
75727 - return -ENOMEM;
75728 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75729 + if (pgprot_val(prot) & _PAGE_NX)
75730 +#endif
75731 +
75732 + if (WARN_ON(!pte_none(*pte))) {
75733 + ret = -EBUSY;
75734 + goto out;
75735 + }
75736 + if (WARN_ON(!page)) {
75737 + ret = -ENOMEM;
75738 + goto out;
75739 + }
75740 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
75741 (*nr)++;
75742 } while (pte++, addr += PAGE_SIZE, addr != end);
75743 - return 0;
75744 + ret = 0;
75745 +out:
75746 + pax_close_kernel();
75747 + return ret;
75748 }
75749
75750 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
75751 @@ -119,7 +144,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
75752 pmd_t *pmd;
75753 unsigned long next;
75754
75755 - pmd = pmd_alloc(&init_mm, pud, addr);
75756 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
75757 if (!pmd)
75758 return -ENOMEM;
75759 do {
75760 @@ -136,7 +161,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
75761 pud_t *pud;
75762 unsigned long next;
75763
75764 - pud = pud_alloc(&init_mm, pgd, addr);
75765 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
75766 if (!pud)
75767 return -ENOMEM;
75768 do {
75769 @@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
75770 * and fall back on vmalloc() if that fails. Others
75771 * just put it in the vmalloc space.
75772 */
75773 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
75774 +#ifdef CONFIG_MODULES
75775 +#ifdef MODULES_VADDR
75776 unsigned long addr = (unsigned long)x;
75777 if (addr >= MODULES_VADDR && addr < MODULES_END)
75778 return 1;
75779 #endif
75780 +
75781 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75782 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
75783 + return 1;
75784 +#endif
75785 +
75786 +#endif
75787 +
75788 return is_vmalloc_addr(x);
75789 }
75790
75791 @@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
75792
75793 if (!pgd_none(*pgd)) {
75794 pud_t *pud = pud_offset(pgd, addr);
75795 +#ifdef CONFIG_X86
75796 + if (!pud_large(*pud))
75797 +#endif
75798 if (!pud_none(*pud)) {
75799 pmd_t *pmd = pmd_offset(pud, addr);
75800 +#ifdef CONFIG_X86
75801 + if (!pmd_large(*pmd))
75802 +#endif
75803 if (!pmd_none(*pmd)) {
75804 pte_t *ptep, pte;
75805
75806 @@ -329,7 +369,7 @@ static void purge_vmap_area_lazy(void);
75807 * Allocate a region of KVA of the specified size and alignment, within the
75808 * vstart and vend.
75809 */
75810 -static struct vmap_area *alloc_vmap_area(unsigned long size,
75811 +static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
75812 unsigned long align,
75813 unsigned long vstart, unsigned long vend,
75814 int node, gfp_t gfp_mask)
75815 @@ -1328,6 +1368,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
75816 struct vm_struct *area;
75817
75818 BUG_ON(in_interrupt());
75819 +
75820 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75821 + if (flags & VM_KERNEXEC) {
75822 + if (start != VMALLOC_START || end != VMALLOC_END)
75823 + return NULL;
75824 + start = (unsigned long)MODULES_EXEC_VADDR;
75825 + end = (unsigned long)MODULES_EXEC_END;
75826 + }
75827 +#endif
75828 +
75829 if (flags & VM_IOREMAP) {
75830 int bit = fls(size);
75831
75832 @@ -1568,6 +1618,11 @@ void *vmap(struct page **pages, unsigned int count,
75833 if (count > totalram_pages)
75834 return NULL;
75835
75836 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75837 + if (!(pgprot_val(prot) & _PAGE_NX))
75838 + flags |= VM_KERNEXEC;
75839 +#endif
75840 +
75841 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
75842 __builtin_return_address(0));
75843 if (!area)
75844 @@ -1669,6 +1724,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
75845 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
75846 goto fail;
75847
75848 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75849 + if (!(pgprot_val(prot) & _PAGE_NX))
75850 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
75851 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
75852 + else
75853 +#endif
75854 +
75855 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
75856 start, end, node, gfp_mask, caller);
75857 if (!area)
75858 @@ -1842,10 +1904,9 @@ EXPORT_SYMBOL(vzalloc_node);
75859 * For tight control over page level allocator and protection flags
75860 * use __vmalloc() instead.
75861 */
75862 -
75863 void *vmalloc_exec(unsigned long size)
75864 {
75865 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
75866 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
75867 -1, __builtin_return_address(0));
75868 }
75869
75870 @@ -2136,6 +2197,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
75871 unsigned long uaddr = vma->vm_start;
75872 unsigned long usize = vma->vm_end - vma->vm_start;
75873
75874 + BUG_ON(vma->vm_mirror);
75875 +
75876 if ((PAGE_SIZE-1) & (unsigned long)addr)
75877 return -EINVAL;
75878
75879 @@ -2572,7 +2635,7 @@ static int s_show(struct seq_file *m, void *p)
75880 {
75881 struct vm_struct *v = p;
75882
75883 - seq_printf(m, "0x%p-0x%p %7ld",
75884 + seq_printf(m, "0x%pK-0x%pK %7ld",
75885 v->addr, v->addr + v->size, v->size);
75886
75887 if (v->caller)
75888 diff --git a/mm/vmstat.c b/mm/vmstat.c
75889 index df7a674..8b4a4f3 100644
75890 --- a/mm/vmstat.c
75891 +++ b/mm/vmstat.c
75892 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
75893 *
75894 * vm_stat contains the global counters
75895 */
75896 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
75897 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
75898 EXPORT_SYMBOL(vm_stat);
75899
75900 #ifdef CONFIG_SMP
75901 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
75902 v = p->vm_stat_diff[i];
75903 p->vm_stat_diff[i] = 0;
75904 local_irq_restore(flags);
75905 - atomic_long_add(v, &zone->vm_stat[i]);
75906 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
75907 global_diff[i] += v;
75908 #ifdef CONFIG_NUMA
75909 /* 3 seconds idle till flush */
75910 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
75911
75912 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
75913 if (global_diff[i])
75914 - atomic_long_add(global_diff[i], &vm_stat[i]);
75915 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
75916 }
75917
75918 #endif
75919 @@ -1212,10 +1212,20 @@ static int __init setup_vmstat(void)
75920 start_cpu_timer(cpu);
75921 #endif
75922 #ifdef CONFIG_PROC_FS
75923 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
75924 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
75925 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
75926 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
75927 + {
75928 + mode_t gr_mode = S_IRUGO;
75929 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
75930 + gr_mode = S_IRUSR;
75931 +#endif
75932 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
75933 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
75934 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
75935 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
75936 +#else
75937 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
75938 +#endif
75939 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
75940 + }
75941 #endif
75942 return 0;
75943 }
75944 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
75945 index 9096bcb..43ed7bb 100644
75946 --- a/net/8021q/vlan.c
75947 +++ b/net/8021q/vlan.c
75948 @@ -557,8 +557,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
75949 err = -EPERM;
75950 if (!capable(CAP_NET_ADMIN))
75951 break;
75952 - if ((args.u.name_type >= 0) &&
75953 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
75954 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
75955 struct vlan_net *vn;
75956
75957 vn = net_generic(net, vlan_net_id);
75958 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
75959 index 6449bae..8c1f454 100644
75960 --- a/net/9p/trans_fd.c
75961 +++ b/net/9p/trans_fd.c
75962 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
75963 oldfs = get_fs();
75964 set_fs(get_ds());
75965 /* The cast to a user pointer is valid due to the set_fs() */
75966 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
75967 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
75968 set_fs(oldfs);
75969
75970 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
75971 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
75972 index 876fbe8..8bbea9f 100644
75973 --- a/net/atm/atm_misc.c
75974 +++ b/net/atm/atm_misc.c
75975 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
75976 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
75977 return 1;
75978 atm_return(vcc, truesize);
75979 - atomic_inc(&vcc->stats->rx_drop);
75980 + atomic_inc_unchecked(&vcc->stats->rx_drop);
75981 return 0;
75982 }
75983 EXPORT_SYMBOL(atm_charge);
75984 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
75985 }
75986 }
75987 atm_return(vcc, guess);
75988 - atomic_inc(&vcc->stats->rx_drop);
75989 + atomic_inc_unchecked(&vcc->stats->rx_drop);
75990 return NULL;
75991 }
75992 EXPORT_SYMBOL(atm_alloc_charge);
75993 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
75994
75995 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75996 {
75997 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75998 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75999 __SONET_ITEMS
76000 #undef __HANDLE_ITEM
76001 }
76002 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
76003
76004 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
76005 {
76006 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
76007 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
76008 __SONET_ITEMS
76009 #undef __HANDLE_ITEM
76010 }
76011 diff --git a/net/atm/lec.h b/net/atm/lec.h
76012 index a86aff9..3a0d6f6 100644
76013 --- a/net/atm/lec.h
76014 +++ b/net/atm/lec.h
76015 @@ -48,7 +48,7 @@ struct lane2_ops {
76016 const u8 *tlvs, u32 sizeoftlvs);
76017 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
76018 const u8 *tlvs, u32 sizeoftlvs);
76019 -};
76020 +} __no_const;
76021
76022 /*
76023 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
76024 diff --git a/net/atm/mpc.h b/net/atm/mpc.h
76025 index 0919a88..a23d54e 100644
76026 --- a/net/atm/mpc.h
76027 +++ b/net/atm/mpc.h
76028 @@ -33,7 +33,7 @@ struct mpoa_client {
76029 struct mpc_parameters parameters; /* parameters for this client */
76030
76031 const struct net_device_ops *old_ops;
76032 - struct net_device_ops new_ops;
76033 + net_device_ops_no_const new_ops;
76034 };
76035
76036
76037 diff --git a/net/atm/proc.c b/net/atm/proc.c
76038 index 0d020de..011c7bb 100644
76039 --- a/net/atm/proc.c
76040 +++ b/net/atm/proc.c
76041 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
76042 const struct k_atm_aal_stats *stats)
76043 {
76044 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
76045 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
76046 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
76047 - atomic_read(&stats->rx_drop));
76048 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
76049 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
76050 + atomic_read_unchecked(&stats->rx_drop));
76051 }
76052
76053 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
76054 diff --git a/net/atm/resources.c b/net/atm/resources.c
76055 index 23f45ce..c748f1a 100644
76056 --- a/net/atm/resources.c
76057 +++ b/net/atm/resources.c
76058 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
76059 static void copy_aal_stats(struct k_atm_aal_stats *from,
76060 struct atm_aal_stats *to)
76061 {
76062 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
76063 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
76064 __AAL_STAT_ITEMS
76065 #undef __HANDLE_ITEM
76066 }
76067 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
76068 static void subtract_aal_stats(struct k_atm_aal_stats *from,
76069 struct atm_aal_stats *to)
76070 {
76071 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
76072 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
76073 __AAL_STAT_ITEMS
76074 #undef __HANDLE_ITEM
76075 }
76076 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
76077 index 469daab..262851c 100644
76078 --- a/net/batman-adv/bat_iv_ogm.c
76079 +++ b/net/batman-adv/bat_iv_ogm.c
76080 @@ -62,7 +62,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
76081
76082 /* randomize initial seqno to avoid collision */
76083 get_random_bytes(&random_seqno, sizeof(random_seqno));
76084 - atomic_set(&hard_iface->seqno, random_seqno);
76085 + atomic_set_unchecked(&hard_iface->seqno, random_seqno);
76086
76087 hard_iface->packet_len = BATADV_OGM_HLEN;
76088 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
76089 @@ -600,8 +600,8 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
76090
76091 /* change sequence number to network order */
76092 batadv_ogm_packet->seqno =
76093 - htonl((uint32_t)atomic_read(&hard_iface->seqno));
76094 - atomic_inc(&hard_iface->seqno);
76095 + htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
76096 + atomic_inc_unchecked(&hard_iface->seqno);
76097
76098 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
76099 batadv_ogm_packet->tt_crc = htons(bat_priv->tt_crc);
76100 @@ -1001,7 +1001,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
76101 return;
76102
76103 /* could be changed by schedule_own_packet() */
76104 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
76105 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
76106
76107 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
76108 has_directlink_flag = 1;
76109 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
76110 index 282bf6e..4b2603d 100644
76111 --- a/net/batman-adv/hard-interface.c
76112 +++ b/net/batman-adv/hard-interface.c
76113 @@ -320,7 +320,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
76114 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
76115 dev_add_pack(&hard_iface->batman_adv_ptype);
76116
76117 - atomic_set(&hard_iface->frag_seqno, 1);
76118 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
76119 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
76120 hard_iface->net_dev->name);
76121
76122 @@ -443,7 +443,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
76123 /* This can't be called via a bat_priv callback because
76124 * we have no bat_priv yet.
76125 */
76126 - atomic_set(&hard_iface->seqno, 1);
76127 + atomic_set_unchecked(&hard_iface->seqno, 1);
76128 hard_iface->packet_buff = NULL;
76129
76130 return hard_iface;
76131 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
76132 index 21c5357..768be1a 100644
76133 --- a/net/batman-adv/soft-interface.c
76134 +++ b/net/batman-adv/soft-interface.c
76135 @@ -227,7 +227,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
76136
76137 /* set broadcast sequence number */
76138 bcast_packet->seqno =
76139 - htonl(atomic_inc_return(&bat_priv->bcast_seqno));
76140 + htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
76141
76142 batadv_add_bcast_packet_to_list(bat_priv, skb, 1);
76143
76144 @@ -407,7 +407,7 @@ struct net_device *batadv_softif_create(const char *name)
76145 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
76146
76147 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
76148 - atomic_set(&bat_priv->bcast_seqno, 1);
76149 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
76150 atomic_set(&bat_priv->ttvn, 0);
76151 atomic_set(&bat_priv->tt_local_changes, 0);
76152 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
76153 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
76154 index 12635fd..d99d837 100644
76155 --- a/net/batman-adv/types.h
76156 +++ b/net/batman-adv/types.h
76157 @@ -33,8 +33,8 @@ struct batadv_hard_iface {
76158 int16_t if_num;
76159 char if_status;
76160 struct net_device *net_dev;
76161 - atomic_t seqno;
76162 - atomic_t frag_seqno;
76163 + atomic_unchecked_t seqno;
76164 + atomic_unchecked_t frag_seqno;
76165 unsigned char *packet_buff;
76166 int packet_len;
76167 struct kobject *hardif_obj;
76168 @@ -176,7 +176,7 @@ struct batadv_priv {
76169 atomic_t orig_interval; /* uint */
76170 atomic_t hop_penalty; /* uint */
76171 atomic_t log_level; /* uint */
76172 - atomic_t bcast_seqno;
76173 + atomic_unchecked_t bcast_seqno;
76174 atomic_t bcast_queue_left;
76175 atomic_t batman_queue_left;
76176 atomic_t ttvn; /* translation table version number */
76177 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
76178 index 0016464..0ef3e53 100644
76179 --- a/net/batman-adv/unicast.c
76180 +++ b/net/batman-adv/unicast.c
76181 @@ -269,7 +269,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
76182 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
76183 frag2->flags = large_tail;
76184
76185 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
76186 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
76187 frag1->seqno = htons(seqno - 1);
76188 frag2->seqno = htons(seqno);
76189
76190 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
76191 index d5ace1e..231c4bf 100644
76192 --- a/net/bluetooth/hci_sock.c
76193 +++ b/net/bluetooth/hci_sock.c
76194 @@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
76195 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
76196 }
76197
76198 - len = min_t(unsigned int, len, sizeof(uf));
76199 + len = min((size_t)len, sizeof(uf));
76200 if (copy_from_user(&uf, optval, len)) {
76201 err = -EFAULT;
76202 break;
76203 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
76204 index 38c00f1..e9d566e 100644
76205 --- a/net/bluetooth/l2cap_core.c
76206 +++ b/net/bluetooth/l2cap_core.c
76207 @@ -3165,8 +3165,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
76208 break;
76209
76210 case L2CAP_CONF_RFC:
76211 - if (olen == sizeof(rfc))
76212 - memcpy(&rfc, (void *)val, olen);
76213 + if (olen != sizeof(rfc))
76214 + break;
76215 +
76216 + memcpy(&rfc, (void *)val, olen);
76217
76218 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
76219 rfc.mode != chan->mode)
76220 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
76221 index 34bbe1c..451c19b 100644
76222 --- a/net/bluetooth/l2cap_sock.c
76223 +++ b/net/bluetooth/l2cap_sock.c
76224 @@ -467,7 +467,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
76225 struct sock *sk = sock->sk;
76226 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
76227 struct l2cap_options opts;
76228 - int len, err = 0;
76229 + int err = 0;
76230 + size_t len = optlen;
76231 u32 opt;
76232
76233 BT_DBG("sk %p", sk);
76234 @@ -489,7 +490,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
76235 opts.max_tx = chan->max_tx;
76236 opts.txwin_size = chan->tx_win;
76237
76238 - len = min_t(unsigned int, sizeof(opts), optlen);
76239 + len = min(sizeof(opts), len);
76240 if (copy_from_user((char *) &opts, optval, len)) {
76241 err = -EFAULT;
76242 break;
76243 @@ -567,7 +568,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76244 struct bt_security sec;
76245 struct bt_power pwr;
76246 struct l2cap_conn *conn;
76247 - int len, err = 0;
76248 + int err = 0;
76249 + size_t len = optlen;
76250 u32 opt;
76251
76252 BT_DBG("sk %p", sk);
76253 @@ -590,7 +592,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76254
76255 sec.level = BT_SECURITY_LOW;
76256
76257 - len = min_t(unsigned int, sizeof(sec), optlen);
76258 + len = min(sizeof(sec), len);
76259 if (copy_from_user((char *) &sec, optval, len)) {
76260 err = -EFAULT;
76261 break;
76262 @@ -687,7 +689,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76263
76264 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
76265
76266 - len = min_t(unsigned int, sizeof(pwr), optlen);
76267 + len = min(sizeof(pwr), len);
76268 if (copy_from_user((char *) &pwr, optval, len)) {
76269 err = -EFAULT;
76270 break;
76271 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
76272 index 1a17850..65a3129 100644
76273 --- a/net/bluetooth/rfcomm/sock.c
76274 +++ b/net/bluetooth/rfcomm/sock.c
76275 @@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
76276 struct sock *sk = sock->sk;
76277 struct bt_security sec;
76278 int err = 0;
76279 - size_t len;
76280 + size_t len = optlen;
76281 u32 opt;
76282
76283 BT_DBG("sk %p", sk);
76284 @@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
76285
76286 sec.level = BT_SECURITY_LOW;
76287
76288 - len = min_t(unsigned int, sizeof(sec), optlen);
76289 + len = min(sizeof(sec), len);
76290 if (copy_from_user((char *) &sec, optval, len)) {
76291 err = -EFAULT;
76292 break;
76293 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
76294 index 56f1823..da44330 100644
76295 --- a/net/bluetooth/rfcomm/tty.c
76296 +++ b/net/bluetooth/rfcomm/tty.c
76297 @@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
76298 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
76299
76300 spin_lock_irqsave(&dev->port.lock, flags);
76301 - if (dev->port.count > 0) {
76302 + if (atomic_read(&dev->port.count) > 0) {
76303 spin_unlock_irqrestore(&dev->port.lock, flags);
76304 return;
76305 }
76306 @@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
76307 return -ENODEV;
76308
76309 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
76310 - dev->channel, dev->port.count);
76311 + dev->channel, atomic_read(&dev->port.count));
76312
76313 spin_lock_irqsave(&dev->port.lock, flags);
76314 - if (++dev->port.count > 1) {
76315 + if (atomic_inc_return(&dev->port.count) > 1) {
76316 spin_unlock_irqrestore(&dev->port.lock, flags);
76317 return 0;
76318 }
76319 @@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
76320 return;
76321
76322 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
76323 - dev->port.count);
76324 + atomic_read(&dev->port.count));
76325
76326 spin_lock_irqsave(&dev->port.lock, flags);
76327 - if (!--dev->port.count) {
76328 + if (!atomic_dec_return(&dev->port.count)) {
76329 spin_unlock_irqrestore(&dev->port.lock, flags);
76330 if (dev->tty_dev->parent)
76331 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
76332 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
76333 index 5fe2ff3..121d696 100644
76334 --- a/net/bridge/netfilter/ebtables.c
76335 +++ b/net/bridge/netfilter/ebtables.c
76336 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
76337 tmp.valid_hooks = t->table->valid_hooks;
76338 }
76339 mutex_unlock(&ebt_mutex);
76340 - if (copy_to_user(user, &tmp, *len) != 0){
76341 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
76342 BUGPRINT("c2u Didn't work\n");
76343 ret = -EFAULT;
76344 break;
76345 @@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
76346 goto out;
76347 tmp.valid_hooks = t->valid_hooks;
76348
76349 - if (copy_to_user(user, &tmp, *len) != 0) {
76350 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
76351 ret = -EFAULT;
76352 break;
76353 }
76354 @@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
76355 tmp.entries_size = t->table->entries_size;
76356 tmp.valid_hooks = t->table->valid_hooks;
76357
76358 - if (copy_to_user(user, &tmp, *len) != 0) {
76359 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
76360 ret = -EFAULT;
76361 break;
76362 }
76363 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
76364 index 44f270f..1f5602d 100644
76365 --- a/net/caif/cfctrl.c
76366 +++ b/net/caif/cfctrl.c
76367 @@ -10,6 +10,7 @@
76368 #include <linux/spinlock.h>
76369 #include <linux/slab.h>
76370 #include <linux/pkt_sched.h>
76371 +#include <linux/sched.h>
76372 #include <net/caif/caif_layer.h>
76373 #include <net/caif/cfpkt.h>
76374 #include <net/caif/cfctrl.h>
76375 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
76376 memset(&dev_info, 0, sizeof(dev_info));
76377 dev_info.id = 0xff;
76378 cfsrvl_init(&this->serv, 0, &dev_info, false);
76379 - atomic_set(&this->req_seq_no, 1);
76380 - atomic_set(&this->rsp_seq_no, 1);
76381 + atomic_set_unchecked(&this->req_seq_no, 1);
76382 + atomic_set_unchecked(&this->rsp_seq_no, 1);
76383 this->serv.layer.receive = cfctrl_recv;
76384 sprintf(this->serv.layer.name, "ctrl");
76385 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
76386 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
76387 struct cfctrl_request_info *req)
76388 {
76389 spin_lock_bh(&ctrl->info_list_lock);
76390 - atomic_inc(&ctrl->req_seq_no);
76391 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
76392 + atomic_inc_unchecked(&ctrl->req_seq_no);
76393 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
76394 list_add_tail(&req->list, &ctrl->list);
76395 spin_unlock_bh(&ctrl->info_list_lock);
76396 }
76397 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
76398 if (p != first)
76399 pr_warn("Requests are not received in order\n");
76400
76401 - atomic_set(&ctrl->rsp_seq_no,
76402 + atomic_set_unchecked(&ctrl->rsp_seq_no,
76403 p->sequence_no);
76404 list_del(&p->list);
76405 goto out;
76406 diff --git a/net/can/gw.c b/net/can/gw.c
76407 index b54d5e6..91c3b25 100644
76408 --- a/net/can/gw.c
76409 +++ b/net/can/gw.c
76410 @@ -96,7 +96,7 @@ struct cf_mod {
76411 struct {
76412 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
76413 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
76414 - } csumfunc;
76415 + } __no_const csumfunc;
76416 };
76417
76418
76419 diff --git a/net/compat.c b/net/compat.c
76420 index 74ed1d7..3695bd9 100644
76421 --- a/net/compat.c
76422 +++ b/net/compat.c
76423 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
76424 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
76425 __get_user(kmsg->msg_flags, &umsg->msg_flags))
76426 return -EFAULT;
76427 - kmsg->msg_name = compat_ptr(tmp1);
76428 - kmsg->msg_iov = compat_ptr(tmp2);
76429 - kmsg->msg_control = compat_ptr(tmp3);
76430 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
76431 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
76432 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
76433 return 0;
76434 }
76435
76436 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76437
76438 if (kern_msg->msg_namelen) {
76439 if (mode == VERIFY_READ) {
76440 - int err = move_addr_to_kernel(kern_msg->msg_name,
76441 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
76442 kern_msg->msg_namelen,
76443 kern_address);
76444 if (err < 0)
76445 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76446 kern_msg->msg_name = NULL;
76447
76448 tot_len = iov_from_user_compat_to_kern(kern_iov,
76449 - (struct compat_iovec __user *)kern_msg->msg_iov,
76450 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
76451 kern_msg->msg_iovlen);
76452 if (tot_len >= 0)
76453 kern_msg->msg_iov = kern_iov;
76454 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76455
76456 #define CMSG_COMPAT_FIRSTHDR(msg) \
76457 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
76458 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
76459 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
76460 (struct compat_cmsghdr __user *)NULL)
76461
76462 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
76463 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
76464 (ucmlen) <= (unsigned long) \
76465 ((mhdr)->msg_controllen - \
76466 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
76467 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
76468
76469 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
76470 struct compat_cmsghdr __user *cmsg, int cmsg_len)
76471 {
76472 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
76473 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
76474 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
76475 msg->msg_controllen)
76476 return NULL;
76477 return (struct compat_cmsghdr __user *)ptr;
76478 @@ -219,7 +219,7 @@ Efault:
76479
76480 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
76481 {
76482 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
76483 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
76484 struct compat_cmsghdr cmhdr;
76485 struct compat_timeval ctv;
76486 struct compat_timespec cts[3];
76487 @@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
76488
76489 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
76490 {
76491 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
76492 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
76493 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
76494 int fdnum = scm->fp->count;
76495 struct file **fp = scm->fp->fp;
76496 @@ -364,7 +364,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
76497 return -EFAULT;
76498 old_fs = get_fs();
76499 set_fs(KERNEL_DS);
76500 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
76501 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
76502 set_fs(old_fs);
76503
76504 return err;
76505 @@ -425,7 +425,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
76506 len = sizeof(ktime);
76507 old_fs = get_fs();
76508 set_fs(KERNEL_DS);
76509 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
76510 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
76511 set_fs(old_fs);
76512
76513 if (!err) {
76514 @@ -568,7 +568,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76515 case MCAST_JOIN_GROUP:
76516 case MCAST_LEAVE_GROUP:
76517 {
76518 - struct compat_group_req __user *gr32 = (void *)optval;
76519 + struct compat_group_req __user *gr32 = (void __user *)optval;
76520 struct group_req __user *kgr =
76521 compat_alloc_user_space(sizeof(struct group_req));
76522 u32 interface;
76523 @@ -589,7 +589,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76524 case MCAST_BLOCK_SOURCE:
76525 case MCAST_UNBLOCK_SOURCE:
76526 {
76527 - struct compat_group_source_req __user *gsr32 = (void *)optval;
76528 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
76529 struct group_source_req __user *kgsr = compat_alloc_user_space(
76530 sizeof(struct group_source_req));
76531 u32 interface;
76532 @@ -610,7 +610,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76533 }
76534 case MCAST_MSFILTER:
76535 {
76536 - struct compat_group_filter __user *gf32 = (void *)optval;
76537 + struct compat_group_filter __user *gf32 = (void __user *)optval;
76538 struct group_filter __user *kgf;
76539 u32 interface, fmode, numsrc;
76540
76541 @@ -648,7 +648,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
76542 char __user *optval, int __user *optlen,
76543 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
76544 {
76545 - struct compat_group_filter __user *gf32 = (void *)optval;
76546 + struct compat_group_filter __user *gf32 = (void __user *)optval;
76547 struct group_filter __user *kgf;
76548 int __user *koptlen;
76549 u32 interface, fmode, numsrc;
76550 @@ -797,7 +797,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
76551
76552 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
76553 return -EINVAL;
76554 - if (copy_from_user(a, args, nas[call]))
76555 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
76556 return -EFAULT;
76557 a0 = a[0];
76558 a1 = a[1];
76559 diff --git a/net/core/datagram.c b/net/core/datagram.c
76560 index 0337e2b..47914a0 100644
76561 --- a/net/core/datagram.c
76562 +++ b/net/core/datagram.c
76563 @@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
76564 }
76565
76566 kfree_skb(skb);
76567 - atomic_inc(&sk->sk_drops);
76568 + atomic_inc_unchecked(&sk->sk_drops);
76569 sk_mem_reclaim_partial(sk);
76570
76571 return err;
76572 diff --git a/net/core/dev.c b/net/core/dev.c
76573 index 2fb9f59..d9a07df 100644
76574 --- a/net/core/dev.c
76575 +++ b/net/core/dev.c
76576 @@ -1138,9 +1138,13 @@ void dev_load(struct net *net, const char *name)
76577 if (no_module && capable(CAP_NET_ADMIN))
76578 no_module = request_module("netdev-%s", name);
76579 if (no_module && capable(CAP_SYS_MODULE)) {
76580 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
76581 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
76582 +#else
76583 if (!request_module("%s", name))
76584 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
76585 name);
76586 +#endif
76587 }
76588 }
76589 EXPORT_SYMBOL(dev_load);
76590 @@ -1605,7 +1609,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
76591 {
76592 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
76593 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
76594 - atomic_long_inc(&dev->rx_dropped);
76595 + atomic_long_inc_unchecked(&dev->rx_dropped);
76596 kfree_skb(skb);
76597 return NET_RX_DROP;
76598 }
76599 @@ -1615,7 +1619,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
76600 nf_reset(skb);
76601
76602 if (unlikely(!is_skb_forwardable(dev, skb))) {
76603 - atomic_long_inc(&dev->rx_dropped);
76604 + atomic_long_inc_unchecked(&dev->rx_dropped);
76605 kfree_skb(skb);
76606 return NET_RX_DROP;
76607 }
76608 @@ -2071,7 +2075,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
76609
76610 struct dev_gso_cb {
76611 void (*destructor)(struct sk_buff *skb);
76612 -};
76613 +} __no_const;
76614
76615 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
76616
76617 @@ -2928,7 +2932,7 @@ enqueue:
76618
76619 local_irq_restore(flags);
76620
76621 - atomic_long_inc(&skb->dev->rx_dropped);
76622 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
76623 kfree_skb(skb);
76624 return NET_RX_DROP;
76625 }
76626 @@ -3000,7 +3004,7 @@ int netif_rx_ni(struct sk_buff *skb)
76627 }
76628 EXPORT_SYMBOL(netif_rx_ni);
76629
76630 -static void net_tx_action(struct softirq_action *h)
76631 +static void net_tx_action(void)
76632 {
76633 struct softnet_data *sd = &__get_cpu_var(softnet_data);
76634
76635 @@ -3331,7 +3335,7 @@ ncls:
76636 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
76637 } else {
76638 drop:
76639 - atomic_long_inc(&skb->dev->rx_dropped);
76640 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
76641 kfree_skb(skb);
76642 /* Jamal, now you will not able to escape explaining
76643 * me how you were going to use this. :-)
76644 @@ -3898,7 +3902,7 @@ void netif_napi_del(struct napi_struct *napi)
76645 }
76646 EXPORT_SYMBOL(netif_napi_del);
76647
76648 -static void net_rx_action(struct softirq_action *h)
76649 +static void net_rx_action(void)
76650 {
76651 struct softnet_data *sd = &__get_cpu_var(softnet_data);
76652 unsigned long time_limit = jiffies + 2;
76653 @@ -4368,8 +4372,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
76654 else
76655 seq_printf(seq, "%04x", ntohs(pt->type));
76656
76657 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76658 + seq_printf(seq, " %-8s %p\n",
76659 + pt->dev ? pt->dev->name : "", NULL);
76660 +#else
76661 seq_printf(seq, " %-8s %pF\n",
76662 pt->dev ? pt->dev->name : "", pt->func);
76663 +#endif
76664 }
76665
76666 return 0;
76667 @@ -5922,7 +5931,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
76668 } else {
76669 netdev_stats_to_stats64(storage, &dev->stats);
76670 }
76671 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
76672 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
76673 return storage;
76674 }
76675 EXPORT_SYMBOL(dev_get_stats);
76676 diff --git a/net/core/flow.c b/net/core/flow.c
76677 index e318c7e..168b1d0 100644
76678 --- a/net/core/flow.c
76679 +++ b/net/core/flow.c
76680 @@ -61,7 +61,7 @@ struct flow_cache {
76681 struct timer_list rnd_timer;
76682 };
76683
76684 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
76685 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
76686 EXPORT_SYMBOL(flow_cache_genid);
76687 static struct flow_cache flow_cache_global;
76688 static struct kmem_cache *flow_cachep __read_mostly;
76689 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
76690
76691 static int flow_entry_valid(struct flow_cache_entry *fle)
76692 {
76693 - if (atomic_read(&flow_cache_genid) != fle->genid)
76694 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
76695 return 0;
76696 if (fle->object && !fle->object->ops->check(fle->object))
76697 return 0;
76698 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
76699 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
76700 fcp->hash_count++;
76701 }
76702 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
76703 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
76704 flo = fle->object;
76705 if (!flo)
76706 goto ret_object;
76707 @@ -280,7 +280,7 @@ nocache:
76708 }
76709 flo = resolver(net, key, family, dir, flo, ctx);
76710 if (fle) {
76711 - fle->genid = atomic_read(&flow_cache_genid);
76712 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
76713 if (!IS_ERR(flo))
76714 fle->object = flo;
76715 else
76716 diff --git a/net/core/iovec.c b/net/core/iovec.c
76717 index 7e7aeb0..2a998cb 100644
76718 --- a/net/core/iovec.c
76719 +++ b/net/core/iovec.c
76720 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
76721 if (m->msg_namelen) {
76722 if (mode == VERIFY_READ) {
76723 void __user *namep;
76724 - namep = (void __user __force *) m->msg_name;
76725 + namep = (void __force_user *) m->msg_name;
76726 err = move_addr_to_kernel(namep, m->msg_namelen,
76727 address);
76728 if (err < 0)
76729 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
76730 }
76731
76732 size = m->msg_iovlen * sizeof(struct iovec);
76733 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
76734 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
76735 return -EFAULT;
76736
76737 m->msg_iov = iov;
76738 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
76739 index 2c5a0a0..a45f90c 100644
76740 --- a/net/core/rtnetlink.c
76741 +++ b/net/core/rtnetlink.c
76742 @@ -58,7 +58,7 @@ struct rtnl_link {
76743 rtnl_doit_func doit;
76744 rtnl_dumpit_func dumpit;
76745 rtnl_calcit_func calcit;
76746 -};
76747 +} __no_const;
76748
76749 static DEFINE_MUTEX(rtnl_mutex);
76750
76751 diff --git a/net/core/scm.c b/net/core/scm.c
76752 index 040cebe..5b1e312 100644
76753 --- a/net/core/scm.c
76754 +++ b/net/core/scm.c
76755 @@ -203,7 +203,7 @@ EXPORT_SYMBOL(__scm_send);
76756 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
76757 {
76758 struct cmsghdr __user *cm
76759 - = (__force struct cmsghdr __user *)msg->msg_control;
76760 + = (struct cmsghdr __force_user *)msg->msg_control;
76761 struct cmsghdr cmhdr;
76762 int cmlen = CMSG_LEN(len);
76763 int err;
76764 @@ -226,7 +226,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
76765 err = -EFAULT;
76766 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
76767 goto out;
76768 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
76769 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
76770 goto out;
76771 cmlen = CMSG_SPACE(len);
76772 if (msg->msg_controllen < cmlen)
76773 @@ -242,7 +242,7 @@ EXPORT_SYMBOL(put_cmsg);
76774 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
76775 {
76776 struct cmsghdr __user *cm
76777 - = (__force struct cmsghdr __user*)msg->msg_control;
76778 + = (struct cmsghdr __force_user *)msg->msg_control;
76779
76780 int fdmax = 0;
76781 int fdnum = scm->fp->count;
76782 @@ -262,7 +262,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
76783 if (fdnum < fdmax)
76784 fdmax = fdnum;
76785
76786 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
76787 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
76788 i++, cmfptr++)
76789 {
76790 struct socket *sock;
76791 diff --git a/net/core/sock.c b/net/core/sock.c
76792 index a6000fb..d4aee72 100644
76793 --- a/net/core/sock.c
76794 +++ b/net/core/sock.c
76795 @@ -399,7 +399,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76796 struct sk_buff_head *list = &sk->sk_receive_queue;
76797
76798 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
76799 - atomic_inc(&sk->sk_drops);
76800 + atomic_inc_unchecked(&sk->sk_drops);
76801 trace_sock_rcvqueue_full(sk, skb);
76802 return -ENOMEM;
76803 }
76804 @@ -409,7 +409,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76805 return err;
76806
76807 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
76808 - atomic_inc(&sk->sk_drops);
76809 + atomic_inc_unchecked(&sk->sk_drops);
76810 return -ENOBUFS;
76811 }
76812
76813 @@ -429,7 +429,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76814 skb_dst_force(skb);
76815
76816 spin_lock_irqsave(&list->lock, flags);
76817 - skb->dropcount = atomic_read(&sk->sk_drops);
76818 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
76819 __skb_queue_tail(list, skb);
76820 spin_unlock_irqrestore(&list->lock, flags);
76821
76822 @@ -449,7 +449,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
76823 skb->dev = NULL;
76824
76825 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
76826 - atomic_inc(&sk->sk_drops);
76827 + atomic_inc_unchecked(&sk->sk_drops);
76828 goto discard_and_relse;
76829 }
76830 if (nested)
76831 @@ -467,7 +467,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
76832 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
76833 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
76834 bh_unlock_sock(sk);
76835 - atomic_inc(&sk->sk_drops);
76836 + atomic_inc_unchecked(&sk->sk_drops);
76837 goto discard_and_relse;
76838 }
76839
76840 @@ -886,12 +886,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76841 struct timeval tm;
76842 } v;
76843
76844 - int lv = sizeof(int);
76845 - int len;
76846 + unsigned int lv = sizeof(int);
76847 + unsigned int len;
76848
76849 if (get_user(len, optlen))
76850 return -EFAULT;
76851 - if (len < 0)
76852 + if (len > INT_MAX)
76853 return -EINVAL;
76854
76855 memset(&v, 0, sizeof(v));
76856 @@ -1039,11 +1039,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76857
76858 case SO_PEERNAME:
76859 {
76860 - char address[128];
76861 + char address[_K_SS_MAXSIZE];
76862
76863 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
76864 return -ENOTCONN;
76865 - if (lv < len)
76866 + if (lv < len || sizeof address < len)
76867 return -EINVAL;
76868 if (copy_to_user(optval, address, len))
76869 return -EFAULT;
76870 @@ -1091,7 +1091,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76871
76872 if (len > lv)
76873 len = lv;
76874 - if (copy_to_user(optval, &v, len))
76875 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
76876 return -EFAULT;
76877 lenout:
76878 if (put_user(len, optlen))
76879 @@ -2193,7 +2193,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
76880 */
76881 smp_wmb();
76882 atomic_set(&sk->sk_refcnt, 1);
76883 - atomic_set(&sk->sk_drops, 0);
76884 + atomic_set_unchecked(&sk->sk_drops, 0);
76885 }
76886 EXPORT_SYMBOL(sock_init_data);
76887
76888 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
76889 index 9d8755e..26de8bc 100644
76890 --- a/net/core/sock_diag.c
76891 +++ b/net/core/sock_diag.c
76892 @@ -15,20 +15,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
76893
76894 int sock_diag_check_cookie(void *sk, __u32 *cookie)
76895 {
76896 +#ifndef CONFIG_GRKERNSEC_HIDESYM
76897 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
76898 cookie[1] != INET_DIAG_NOCOOKIE) &&
76899 ((u32)(unsigned long)sk != cookie[0] ||
76900 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
76901 return -ESTALE;
76902 else
76903 +#endif
76904 return 0;
76905 }
76906 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
76907
76908 void sock_diag_save_cookie(void *sk, __u32 *cookie)
76909 {
76910 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76911 + cookie[0] = 0;
76912 + cookie[1] = 0;
76913 +#else
76914 cookie[0] = (u32)(unsigned long)sk;
76915 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
76916 +#endif
76917 }
76918 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
76919
76920 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
76921 index a55eecc..dd8428c 100644
76922 --- a/net/decnet/sysctl_net_decnet.c
76923 +++ b/net/decnet/sysctl_net_decnet.c
76924 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
76925
76926 if (len > *lenp) len = *lenp;
76927
76928 - if (copy_to_user(buffer, addr, len))
76929 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
76930 return -EFAULT;
76931
76932 *lenp = len;
76933 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
76934
76935 if (len > *lenp) len = *lenp;
76936
76937 - if (copy_to_user(buffer, devname, len))
76938 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
76939 return -EFAULT;
76940
76941 *lenp = len;
76942 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
76943 index f444ac7..b7bdda9 100644
76944 --- a/net/ipv4/fib_frontend.c
76945 +++ b/net/ipv4/fib_frontend.c
76946 @@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
76947 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76948 fib_sync_up(dev);
76949 #endif
76950 - atomic_inc(&net->ipv4.dev_addr_genid);
76951 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76952 rt_cache_flush(dev_net(dev));
76953 break;
76954 case NETDEV_DOWN:
76955 fib_del_ifaddr(ifa, NULL);
76956 - atomic_inc(&net->ipv4.dev_addr_genid);
76957 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76958 if (ifa->ifa_dev->ifa_list == NULL) {
76959 /* Last address was deleted from this interface.
76960 * Disable IP.
76961 @@ -1062,7 +1062,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
76962 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76963 fib_sync_up(dev);
76964 #endif
76965 - atomic_inc(&net->ipv4.dev_addr_genid);
76966 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76967 rt_cache_flush(dev_net(dev));
76968 break;
76969 case NETDEV_DOWN:
76970 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
76971 index 9633661..4e0bc08 100644
76972 --- a/net/ipv4/fib_semantics.c
76973 +++ b/net/ipv4/fib_semantics.c
76974 @@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
76975 nh->nh_saddr = inet_select_addr(nh->nh_dev,
76976 nh->nh_gw,
76977 nh->nh_parent->fib_scope);
76978 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
76979 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
76980
76981 return nh->nh_saddr;
76982 }
76983 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
76984 index 7880af9..70f92a3 100644
76985 --- a/net/ipv4/inet_hashtables.c
76986 +++ b/net/ipv4/inet_hashtables.c
76987 @@ -18,12 +18,15 @@
76988 #include <linux/sched.h>
76989 #include <linux/slab.h>
76990 #include <linux/wait.h>
76991 +#include <linux/security.h>
76992
76993 #include <net/inet_connection_sock.h>
76994 #include <net/inet_hashtables.h>
76995 #include <net/secure_seq.h>
76996 #include <net/ip.h>
76997
76998 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
76999 +
77000 /*
77001 * Allocate and initialize a new local port bind bucket.
77002 * The bindhash mutex for snum's hash chain must be held here.
77003 @@ -530,6 +533,8 @@ ok:
77004 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
77005 spin_unlock(&head->lock);
77006
77007 + gr_update_task_in_ip_table(current, inet_sk(sk));
77008 +
77009 if (tw) {
77010 inet_twsk_deschedule(tw, death_row);
77011 while (twrefcnt) {
77012 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
77013 index c7527f6..d8bba61 100644
77014 --- a/net/ipv4/inetpeer.c
77015 +++ b/net/ipv4/inetpeer.c
77016 @@ -503,8 +503,8 @@ relookup:
77017 if (p) {
77018 p->daddr = *daddr;
77019 atomic_set(&p->refcnt, 1);
77020 - atomic_set(&p->rid, 0);
77021 - atomic_set(&p->ip_id_count,
77022 + atomic_set_unchecked(&p->rid, 0);
77023 + atomic_set_unchecked(&p->ip_id_count,
77024 (daddr->family == AF_INET) ?
77025 secure_ip_id(daddr->addr.a4) :
77026 secure_ipv6_id(daddr->addr.a6));
77027 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
77028 index 8d07c97..d0812ef 100644
77029 --- a/net/ipv4/ip_fragment.c
77030 +++ b/net/ipv4/ip_fragment.c
77031 @@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
77032 return 0;
77033
77034 start = qp->rid;
77035 - end = atomic_inc_return(&peer->rid);
77036 + end = atomic_inc_return_unchecked(&peer->rid);
77037 qp->rid = end;
77038
77039 rc = qp->q.fragments && (end - start) > max;
77040 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
77041 index 5eea4a8..49819c2 100644
77042 --- a/net/ipv4/ip_sockglue.c
77043 +++ b/net/ipv4/ip_sockglue.c
77044 @@ -1142,7 +1142,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
77045 len = min_t(unsigned int, len, opt->optlen);
77046 if (put_user(len, optlen))
77047 return -EFAULT;
77048 - if (copy_to_user(optval, opt->__data, len))
77049 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
77050 + copy_to_user(optval, opt->__data, len))
77051 return -EFAULT;
77052 return 0;
77053 }
77054 @@ -1273,7 +1274,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
77055 if (sk->sk_type != SOCK_STREAM)
77056 return -ENOPROTOOPT;
77057
77058 - msg.msg_control = optval;
77059 + msg.msg_control = (void __force_kernel *)optval;
77060 msg.msg_controllen = len;
77061 msg.msg_flags = flags;
77062
77063 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
77064 index 67e8a6b..386764d 100644
77065 --- a/net/ipv4/ipconfig.c
77066 +++ b/net/ipv4/ipconfig.c
77067 @@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
77068
77069 mm_segment_t oldfs = get_fs();
77070 set_fs(get_ds());
77071 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
77072 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
77073 set_fs(oldfs);
77074 return res;
77075 }
77076 @@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
77077
77078 mm_segment_t oldfs = get_fs();
77079 set_fs(get_ds());
77080 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
77081 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
77082 set_fs(oldfs);
77083 return res;
77084 }
77085 @@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
77086
77087 mm_segment_t oldfs = get_fs();
77088 set_fs(get_ds());
77089 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
77090 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
77091 set_fs(oldfs);
77092 return res;
77093 }
77094 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
77095 index 97e61ea..cac1bbb 100644
77096 --- a/net/ipv4/netfilter/arp_tables.c
77097 +++ b/net/ipv4/netfilter/arp_tables.c
77098 @@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
77099 #endif
77100
77101 static int get_info(struct net *net, void __user *user,
77102 - const int *len, int compat)
77103 + int len, int compat)
77104 {
77105 char name[XT_TABLE_MAXNAMELEN];
77106 struct xt_table *t;
77107 int ret;
77108
77109 - if (*len != sizeof(struct arpt_getinfo)) {
77110 - duprintf("length %u != %Zu\n", *len,
77111 + if (len != sizeof(struct arpt_getinfo)) {
77112 + duprintf("length %u != %Zu\n", len,
77113 sizeof(struct arpt_getinfo));
77114 return -EINVAL;
77115 }
77116 @@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
77117 info.size = private->size;
77118 strcpy(info.name, name);
77119
77120 - if (copy_to_user(user, &info, *len) != 0)
77121 + if (copy_to_user(user, &info, len) != 0)
77122 ret = -EFAULT;
77123 else
77124 ret = 0;
77125 @@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
77126
77127 switch (cmd) {
77128 case ARPT_SO_GET_INFO:
77129 - ret = get_info(sock_net(sk), user, len, 1);
77130 + ret = get_info(sock_net(sk), user, *len, 1);
77131 break;
77132 case ARPT_SO_GET_ENTRIES:
77133 ret = compat_get_entries(sock_net(sk), user, len);
77134 @@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
77135
77136 switch (cmd) {
77137 case ARPT_SO_GET_INFO:
77138 - ret = get_info(sock_net(sk), user, len, 0);
77139 + ret = get_info(sock_net(sk), user, *len, 0);
77140 break;
77141
77142 case ARPT_SO_GET_ENTRIES:
77143 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
77144 index 170b1fd..6105b91 100644
77145 --- a/net/ipv4/netfilter/ip_tables.c
77146 +++ b/net/ipv4/netfilter/ip_tables.c
77147 @@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
77148 #endif
77149
77150 static int get_info(struct net *net, void __user *user,
77151 - const int *len, int compat)
77152 + int len, int compat)
77153 {
77154 char name[XT_TABLE_MAXNAMELEN];
77155 struct xt_table *t;
77156 int ret;
77157
77158 - if (*len != sizeof(struct ipt_getinfo)) {
77159 - duprintf("length %u != %zu\n", *len,
77160 + if (len != sizeof(struct ipt_getinfo)) {
77161 + duprintf("length %u != %zu\n", len,
77162 sizeof(struct ipt_getinfo));
77163 return -EINVAL;
77164 }
77165 @@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
77166 info.size = private->size;
77167 strcpy(info.name, name);
77168
77169 - if (copy_to_user(user, &info, *len) != 0)
77170 + if (copy_to_user(user, &info, len) != 0)
77171 ret = -EFAULT;
77172 else
77173 ret = 0;
77174 @@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77175
77176 switch (cmd) {
77177 case IPT_SO_GET_INFO:
77178 - ret = get_info(sock_net(sk), user, len, 1);
77179 + ret = get_info(sock_net(sk), user, *len, 1);
77180 break;
77181 case IPT_SO_GET_ENTRIES:
77182 ret = compat_get_entries(sock_net(sk), user, len);
77183 @@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77184
77185 switch (cmd) {
77186 case IPT_SO_GET_INFO:
77187 - ret = get_info(sock_net(sk), user, len, 0);
77188 + ret = get_info(sock_net(sk), user, *len, 0);
77189 break;
77190
77191 case IPT_SO_GET_ENTRIES:
77192 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
77193 index 6232d47..6b88607 100644
77194 --- a/net/ipv4/ping.c
77195 +++ b/net/ipv4/ping.c
77196 @@ -847,7 +847,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
77197 sk_rmem_alloc_get(sp),
77198 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77199 atomic_read(&sp->sk_refcnt), sp,
77200 - atomic_read(&sp->sk_drops), len);
77201 + atomic_read_unchecked(&sp->sk_drops), len);
77202 }
77203
77204 static int ping_seq_show(struct seq_file *seq, void *v)
77205 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
77206 index d23c657..cb69cc2 100644
77207 --- a/net/ipv4/raw.c
77208 +++ b/net/ipv4/raw.c
77209 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
77210 int raw_rcv(struct sock *sk, struct sk_buff *skb)
77211 {
77212 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
77213 - atomic_inc(&sk->sk_drops);
77214 + atomic_inc_unchecked(&sk->sk_drops);
77215 kfree_skb(skb);
77216 return NET_RX_DROP;
77217 }
77218 @@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
77219
77220 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
77221 {
77222 + struct icmp_filter filter;
77223 +
77224 if (optlen > sizeof(struct icmp_filter))
77225 optlen = sizeof(struct icmp_filter);
77226 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
77227 + if (copy_from_user(&filter, optval, optlen))
77228 return -EFAULT;
77229 + raw_sk(sk)->filter = filter;
77230 return 0;
77231 }
77232
77233 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
77234 {
77235 int len, ret = -EFAULT;
77236 + struct icmp_filter filter;
77237
77238 if (get_user(len, optlen))
77239 goto out;
77240 @@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
77241 if (len > sizeof(struct icmp_filter))
77242 len = sizeof(struct icmp_filter);
77243 ret = -EFAULT;
77244 - if (put_user(len, optlen) ||
77245 - copy_to_user(optval, &raw_sk(sk)->filter, len))
77246 + filter = raw_sk(sk)->filter;
77247 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
77248 goto out;
77249 ret = 0;
77250 out: return ret;
77251 @@ -995,7 +999,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
77252 sk_wmem_alloc_get(sp),
77253 sk_rmem_alloc_get(sp),
77254 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77255 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
77256 + atomic_read(&sp->sk_refcnt),
77257 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77258 + NULL,
77259 +#else
77260 + sp,
77261 +#endif
77262 + atomic_read_unchecked(&sp->sk_drops));
77263 }
77264
77265 static int raw_seq_show(struct seq_file *seq, void *v)
77266 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
77267 index 2a1383c..ff99572 100644
77268 --- a/net/ipv4/route.c
77269 +++ b/net/ipv4/route.c
77270 @@ -2523,7 +2523,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
77271
77272 static __net_init int rt_genid_init(struct net *net)
77273 {
77274 - atomic_set(&net->rt_genid, 0);
77275 + atomic_set_unchecked(&net->rt_genid, 0);
77276 get_random_bytes(&net->ipv4.dev_addr_genid,
77277 sizeof(net->ipv4.dev_addr_genid));
77278 return 0;
77279 diff --git a/net/ipv4/tcp_illinois.c b/net/ipv4/tcp_illinois.c
77280 index 813b43a..834857f 100644
77281 --- a/net/ipv4/tcp_illinois.c
77282 +++ b/net/ipv4/tcp_illinois.c
77283 @@ -313,11 +313,13 @@ static void tcp_illinois_info(struct sock *sk, u32 ext,
77284 .tcpv_rttcnt = ca->cnt_rtt,
77285 .tcpv_minrtt = ca->base_rtt,
77286 };
77287 - u64 t = ca->sum_rtt;
77288
77289 - do_div(t, ca->cnt_rtt);
77290 - info.tcpv_rtt = t;
77291 + if (info.tcpv_rttcnt > 0) {
77292 + u64 t = ca->sum_rtt;
77293
77294 + do_div(t, info.tcpv_rttcnt);
77295 + info.tcpv_rtt = t;
77296 + }
77297 nla_put(skb, INET_DIAG_VEGASINFO, sizeof(info), &info);
77298 }
77299 }
77300 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
77301 index d377f48..f19e3ec 100644
77302 --- a/net/ipv4/tcp_input.c
77303 +++ b/net/ipv4/tcp_input.c
77304 @@ -4556,6 +4556,9 @@ int tcp_send_rcvq(struct sock *sk, struct msghdr *msg, size_t size)
77305 struct tcphdr *th;
77306 bool fragstolen;
77307
77308 + if (size == 0)
77309 + return 0;
77310 +
77311 skb = alloc_skb(size + sizeof(*th), sk->sk_allocation);
77312 if (!skb)
77313 goto err;
77314 @@ -4728,7 +4731,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
77315 * simplifies code)
77316 */
77317 static void
77318 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
77319 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
77320 struct sk_buff *head, struct sk_buff *tail,
77321 u32 start, u32 end)
77322 {
77323 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
77324 index db7bfad..bfea796 100644
77325 --- a/net/ipv4/tcp_ipv4.c
77326 +++ b/net/ipv4/tcp_ipv4.c
77327 @@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
77328 EXPORT_SYMBOL(sysctl_tcp_low_latency);
77329
77330
77331 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77332 +extern int grsec_enable_blackhole;
77333 +#endif
77334 +
77335 #ifdef CONFIG_TCP_MD5SIG
77336 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
77337 __be32 daddr, __be32 saddr, const struct tcphdr *th);
77338 @@ -1664,6 +1668,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
77339 return 0;
77340
77341 reset:
77342 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77343 + if (!grsec_enable_blackhole)
77344 +#endif
77345 tcp_v4_send_reset(rsk, skb);
77346 discard:
77347 kfree_skb(skb);
77348 @@ -1764,12 +1771,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
77349 TCP_SKB_CB(skb)->sacked = 0;
77350
77351 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
77352 - if (!sk)
77353 + if (!sk) {
77354 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77355 + ret = 1;
77356 +#endif
77357 goto no_tcp_socket;
77358 -
77359 + }
77360 process:
77361 - if (sk->sk_state == TCP_TIME_WAIT)
77362 + if (sk->sk_state == TCP_TIME_WAIT) {
77363 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77364 + ret = 2;
77365 +#endif
77366 goto do_time_wait;
77367 + }
77368
77369 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
77370 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
77371 @@ -1820,6 +1834,10 @@ no_tcp_socket:
77372 bad_packet:
77373 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
77374 } else {
77375 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77376 + if (!grsec_enable_blackhole || (ret == 1 &&
77377 + (skb->dev->flags & IFF_LOOPBACK)))
77378 +#endif
77379 tcp_v4_send_reset(NULL, skb);
77380 }
77381
77382 @@ -2415,7 +2433,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
77383 0, /* non standard timer */
77384 0, /* open_requests have no inode */
77385 atomic_read(&sk->sk_refcnt),
77386 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77387 + NULL,
77388 +#else
77389 req,
77390 +#endif
77391 len);
77392 }
77393
77394 @@ -2465,7 +2487,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
77395 sock_i_uid(sk),
77396 icsk->icsk_probes_out,
77397 sock_i_ino(sk),
77398 - atomic_read(&sk->sk_refcnt), sk,
77399 + atomic_read(&sk->sk_refcnt),
77400 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77401 + NULL,
77402 +#else
77403 + sk,
77404 +#endif
77405 jiffies_to_clock_t(icsk->icsk_rto),
77406 jiffies_to_clock_t(icsk->icsk_ack.ato),
77407 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
77408 @@ -2493,7 +2520,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
77409 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
77410 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
77411 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
77412 - atomic_read(&tw->tw_refcnt), tw, len);
77413 + atomic_read(&tw->tw_refcnt),
77414 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77415 + NULL,
77416 +#else
77417 + tw,
77418 +#endif
77419 + len);
77420 }
77421
77422 #define TMPSZ 150
77423 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
77424 index 6ff7f10..38de56e 100644
77425 --- a/net/ipv4/tcp_minisocks.c
77426 +++ b/net/ipv4/tcp_minisocks.c
77427 @@ -27,6 +27,10 @@
77428 #include <net/inet_common.h>
77429 #include <net/xfrm.h>
77430
77431 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77432 +extern int grsec_enable_blackhole;
77433 +#endif
77434 +
77435 int sysctl_tcp_syncookies __read_mostly = 1;
77436 EXPORT_SYMBOL(sysctl_tcp_syncookies);
77437
77438 @@ -707,6 +711,10 @@ listen_overflow:
77439
77440 embryonic_reset:
77441 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
77442 +
77443 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77444 + if (!grsec_enable_blackhole)
77445 +#endif
77446 if (!(flg & TCP_FLAG_RST))
77447 req->rsk_ops->send_reset(sk, skb);
77448
77449 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
77450 index 4526fe6..1a34e43 100644
77451 --- a/net/ipv4/tcp_probe.c
77452 +++ b/net/ipv4/tcp_probe.c
77453 @@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
77454 if (cnt + width >= len)
77455 break;
77456
77457 - if (copy_to_user(buf + cnt, tbuf, width))
77458 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
77459 return -EFAULT;
77460 cnt += width;
77461 }
77462 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
77463 index b774a03..3873efe 100644
77464 --- a/net/ipv4/tcp_timer.c
77465 +++ b/net/ipv4/tcp_timer.c
77466 @@ -22,6 +22,10 @@
77467 #include <linux/gfp.h>
77468 #include <net/tcp.h>
77469
77470 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77471 +extern int grsec_lastack_retries;
77472 +#endif
77473 +
77474 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
77475 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
77476 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
77477 @@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
77478 }
77479 }
77480
77481 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77482 + if ((sk->sk_state == TCP_LAST_ACK) &&
77483 + (grsec_lastack_retries > 0) &&
77484 + (grsec_lastack_retries < retry_until))
77485 + retry_until = grsec_lastack_retries;
77486 +#endif
77487 +
77488 if (retransmits_timed_out(sk, retry_until,
77489 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
77490 /* Has it gone just too far? */
77491 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
77492 index 2814f66..fa2b223 100644
77493 --- a/net/ipv4/udp.c
77494 +++ b/net/ipv4/udp.c
77495 @@ -87,6 +87,7 @@
77496 #include <linux/types.h>
77497 #include <linux/fcntl.h>
77498 #include <linux/module.h>
77499 +#include <linux/security.h>
77500 #include <linux/socket.h>
77501 #include <linux/sockios.h>
77502 #include <linux/igmp.h>
77503 @@ -111,6 +112,10 @@
77504 #include <trace/events/skb.h>
77505 #include "udp_impl.h"
77506
77507 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77508 +extern int grsec_enable_blackhole;
77509 +#endif
77510 +
77511 struct udp_table udp_table __read_mostly;
77512 EXPORT_SYMBOL(udp_table);
77513
77514 @@ -569,6 +574,9 @@ found:
77515 return s;
77516 }
77517
77518 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
77519 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
77520 +
77521 /*
77522 * This routine is called by the ICMP module when it gets some
77523 * sort of error condition. If err < 0 then the socket should
77524 @@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
77525 dport = usin->sin_port;
77526 if (dport == 0)
77527 return -EINVAL;
77528 +
77529 + err = gr_search_udp_sendmsg(sk, usin);
77530 + if (err)
77531 + return err;
77532 } else {
77533 if (sk->sk_state != TCP_ESTABLISHED)
77534 return -EDESTADDRREQ;
77535 +
77536 + err = gr_search_udp_sendmsg(sk, NULL);
77537 + if (err)
77538 + return err;
77539 +
77540 daddr = inet->inet_daddr;
77541 dport = inet->inet_dport;
77542 /* Open fast path for connected socket.
77543 @@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
77544 udp_lib_checksum_complete(skb)) {
77545 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77546 IS_UDPLITE(sk));
77547 - atomic_inc(&sk->sk_drops);
77548 + atomic_inc_unchecked(&sk->sk_drops);
77549 __skb_unlink(skb, rcvq);
77550 __skb_queue_tail(&list_kill, skb);
77551 }
77552 @@ -1194,6 +1211,10 @@ try_again:
77553 if (!skb)
77554 goto out;
77555
77556 + err = gr_search_udp_recvmsg(sk, skb);
77557 + if (err)
77558 + goto out_free;
77559 +
77560 ulen = skb->len - sizeof(struct udphdr);
77561 copied = len;
77562 if (copied > ulen)
77563 @@ -1227,7 +1248,7 @@ try_again:
77564 if (unlikely(err)) {
77565 trace_kfree_skb(skb, udp_recvmsg);
77566 if (!peeked) {
77567 - atomic_inc(&sk->sk_drops);
77568 + atomic_inc_unchecked(&sk->sk_drops);
77569 UDP_INC_STATS_USER(sock_net(sk),
77570 UDP_MIB_INERRORS, is_udplite);
77571 }
77572 @@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77573
77574 drop:
77575 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
77576 - atomic_inc(&sk->sk_drops);
77577 + atomic_inc_unchecked(&sk->sk_drops);
77578 kfree_skb(skb);
77579 return -1;
77580 }
77581 @@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
77582 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
77583
77584 if (!skb1) {
77585 - atomic_inc(&sk->sk_drops);
77586 + atomic_inc_unchecked(&sk->sk_drops);
77587 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
77588 IS_UDPLITE(sk));
77589 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77590 @@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
77591 goto csum_error;
77592
77593 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
77594 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77595 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
77596 +#endif
77597 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
77598
77599 /*
77600 @@ -2116,8 +2140,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
77601 sk_wmem_alloc_get(sp),
77602 sk_rmem_alloc_get(sp),
77603 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77604 - atomic_read(&sp->sk_refcnt), sp,
77605 - atomic_read(&sp->sk_drops), len);
77606 + atomic_read(&sp->sk_refcnt),
77607 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77608 + NULL,
77609 +#else
77610 + sp,
77611 +#endif
77612 + atomic_read_unchecked(&sp->sk_drops), len);
77613 }
77614
77615 int udp4_seq_show(struct seq_file *seq, void *v)
77616 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
77617 index b10374d..0baa1f9 100644
77618 --- a/net/ipv6/addrconf.c
77619 +++ b/net/ipv6/addrconf.c
77620 @@ -2144,7 +2144,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
77621 p.iph.ihl = 5;
77622 p.iph.protocol = IPPROTO_IPV6;
77623 p.iph.ttl = 64;
77624 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
77625 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
77626
77627 if (ops->ndo_do_ioctl) {
77628 mm_segment_t oldfs = get_fs();
77629 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
77630 index ba6d13d..6899122 100644
77631 --- a/net/ipv6/ipv6_sockglue.c
77632 +++ b/net/ipv6/ipv6_sockglue.c
77633 @@ -989,7 +989,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
77634 if (sk->sk_type != SOCK_STREAM)
77635 return -ENOPROTOOPT;
77636
77637 - msg.msg_control = optval;
77638 + msg.msg_control = (void __force_kernel *)optval;
77639 msg.msg_controllen = len;
77640 msg.msg_flags = flags;
77641
77642 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
77643 index d7cb045..8c0ded6 100644
77644 --- a/net/ipv6/netfilter/ip6_tables.c
77645 +++ b/net/ipv6/netfilter/ip6_tables.c
77646 @@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
77647 #endif
77648
77649 static int get_info(struct net *net, void __user *user,
77650 - const int *len, int compat)
77651 + int len, int compat)
77652 {
77653 char name[XT_TABLE_MAXNAMELEN];
77654 struct xt_table *t;
77655 int ret;
77656
77657 - if (*len != sizeof(struct ip6t_getinfo)) {
77658 - duprintf("length %u != %zu\n", *len,
77659 + if (len != sizeof(struct ip6t_getinfo)) {
77660 + duprintf("length %u != %zu\n", len,
77661 sizeof(struct ip6t_getinfo));
77662 return -EINVAL;
77663 }
77664 @@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
77665 info.size = private->size;
77666 strcpy(info.name, name);
77667
77668 - if (copy_to_user(user, &info, *len) != 0)
77669 + if (copy_to_user(user, &info, len) != 0)
77670 ret = -EFAULT;
77671 else
77672 ret = 0;
77673 @@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77674
77675 switch (cmd) {
77676 case IP6T_SO_GET_INFO:
77677 - ret = get_info(sock_net(sk), user, len, 1);
77678 + ret = get_info(sock_net(sk), user, *len, 1);
77679 break;
77680 case IP6T_SO_GET_ENTRIES:
77681 ret = compat_get_entries(sock_net(sk), user, len);
77682 @@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77683
77684 switch (cmd) {
77685 case IP6T_SO_GET_INFO:
77686 - ret = get_info(sock_net(sk), user, len, 0);
77687 + ret = get_info(sock_net(sk), user, *len, 0);
77688 break;
77689
77690 case IP6T_SO_GET_ENTRIES:
77691 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
77692 index 4a5f78b..3f22ebe 100644
77693 --- a/net/ipv6/raw.c
77694 +++ b/net/ipv6/raw.c
77695 @@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
77696 {
77697 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
77698 skb_checksum_complete(skb)) {
77699 - atomic_inc(&sk->sk_drops);
77700 + atomic_inc_unchecked(&sk->sk_drops);
77701 kfree_skb(skb);
77702 return NET_RX_DROP;
77703 }
77704 @@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
77705 struct raw6_sock *rp = raw6_sk(sk);
77706
77707 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
77708 - atomic_inc(&sk->sk_drops);
77709 + atomic_inc_unchecked(&sk->sk_drops);
77710 kfree_skb(skb);
77711 return NET_RX_DROP;
77712 }
77713 @@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
77714
77715 if (inet->hdrincl) {
77716 if (skb_checksum_complete(skb)) {
77717 - atomic_inc(&sk->sk_drops);
77718 + atomic_inc_unchecked(&sk->sk_drops);
77719 kfree_skb(skb);
77720 return NET_RX_DROP;
77721 }
77722 @@ -604,7 +604,7 @@ out:
77723 return err;
77724 }
77725
77726 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
77727 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
77728 struct flowi6 *fl6, struct dst_entry **dstp,
77729 unsigned int flags)
77730 {
77731 @@ -916,12 +916,15 @@ do_confirm:
77732 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
77733 char __user *optval, int optlen)
77734 {
77735 + struct icmp6_filter filter;
77736 +
77737 switch (optname) {
77738 case ICMPV6_FILTER:
77739 if (optlen > sizeof(struct icmp6_filter))
77740 optlen = sizeof(struct icmp6_filter);
77741 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
77742 + if (copy_from_user(&filter, optval, optlen))
77743 return -EFAULT;
77744 + raw6_sk(sk)->filter = filter;
77745 return 0;
77746 default:
77747 return -ENOPROTOOPT;
77748 @@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
77749 char __user *optval, int __user *optlen)
77750 {
77751 int len;
77752 + struct icmp6_filter filter;
77753
77754 switch (optname) {
77755 case ICMPV6_FILTER:
77756 @@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
77757 len = sizeof(struct icmp6_filter);
77758 if (put_user(len, optlen))
77759 return -EFAULT;
77760 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
77761 + filter = raw6_sk(sk)->filter;
77762 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
77763 return -EFAULT;
77764 return 0;
77765 default:
77766 @@ -1252,7 +1257,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
77767 0, 0L, 0,
77768 sock_i_uid(sp), 0,
77769 sock_i_ino(sp),
77770 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
77771 + atomic_read(&sp->sk_refcnt),
77772 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77773 + NULL,
77774 +#else
77775 + sp,
77776 +#endif
77777 + atomic_read_unchecked(&sp->sk_drops));
77778 }
77779
77780 static int raw6_seq_show(struct seq_file *seq, void *v)
77781 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
77782 index 7e32d42..5d975ba 100644
77783 --- a/net/ipv6/tcp_ipv6.c
77784 +++ b/net/ipv6/tcp_ipv6.c
77785 @@ -106,6 +106,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
77786 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
77787 }
77788
77789 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77790 +extern int grsec_enable_blackhole;
77791 +#endif
77792 +
77793 static void tcp_v6_hash(struct sock *sk)
77794 {
77795 if (sk->sk_state != TCP_CLOSE) {
77796 @@ -1511,6 +1515,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
77797 return 0;
77798
77799 reset:
77800 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77801 + if (!grsec_enable_blackhole)
77802 +#endif
77803 tcp_v6_send_reset(sk, skb);
77804 discard:
77805 if (opt_skb)
77806 @@ -1592,12 +1599,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
77807 TCP_SKB_CB(skb)->sacked = 0;
77808
77809 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
77810 - if (!sk)
77811 + if (!sk) {
77812 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77813 + ret = 1;
77814 +#endif
77815 goto no_tcp_socket;
77816 + }
77817
77818 process:
77819 - if (sk->sk_state == TCP_TIME_WAIT)
77820 + if (sk->sk_state == TCP_TIME_WAIT) {
77821 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77822 + ret = 2;
77823 +#endif
77824 goto do_time_wait;
77825 + }
77826
77827 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
77828 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
77829 @@ -1646,6 +1661,10 @@ no_tcp_socket:
77830 bad_packet:
77831 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
77832 } else {
77833 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77834 + if (!grsec_enable_blackhole || (ret == 1 &&
77835 + (skb->dev->flags & IFF_LOOPBACK)))
77836 +#endif
77837 tcp_v6_send_reset(NULL, skb);
77838 }
77839
77840 @@ -1857,7 +1876,13 @@ static void get_openreq6(struct seq_file *seq,
77841 uid,
77842 0, /* non standard timer */
77843 0, /* open_requests have no inode */
77844 - 0, req);
77845 + 0,
77846 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77847 + NULL
77848 +#else
77849 + req
77850 +#endif
77851 + );
77852 }
77853
77854 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
77855 @@ -1907,7 +1932,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
77856 sock_i_uid(sp),
77857 icsk->icsk_probes_out,
77858 sock_i_ino(sp),
77859 - atomic_read(&sp->sk_refcnt), sp,
77860 + atomic_read(&sp->sk_refcnt),
77861 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77862 + NULL,
77863 +#else
77864 + sp,
77865 +#endif
77866 jiffies_to_clock_t(icsk->icsk_rto),
77867 jiffies_to_clock_t(icsk->icsk_ack.ato),
77868 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
77869 @@ -1942,7 +1972,13 @@ static void get_timewait6_sock(struct seq_file *seq,
77870 dest->s6_addr32[2], dest->s6_addr32[3], destp,
77871 tw->tw_substate, 0, 0,
77872 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
77873 - atomic_read(&tw->tw_refcnt), tw);
77874 + atomic_read(&tw->tw_refcnt),
77875 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77876 + NULL
77877 +#else
77878 + tw
77879 +#endif
77880 + );
77881 }
77882
77883 static int tcp6_seq_show(struct seq_file *seq, void *v)
77884 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
77885 index 07e2bfe..328dae8 100644
77886 --- a/net/ipv6/udp.c
77887 +++ b/net/ipv6/udp.c
77888 @@ -51,6 +51,10 @@
77889 #include <trace/events/skb.h>
77890 #include "udp_impl.h"
77891
77892 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77893 +extern int grsec_enable_blackhole;
77894 +#endif
77895 +
77896 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
77897 {
77898 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
77899 @@ -395,7 +399,7 @@ try_again:
77900 if (unlikely(err)) {
77901 trace_kfree_skb(skb, udpv6_recvmsg);
77902 if (!peeked) {
77903 - atomic_inc(&sk->sk_drops);
77904 + atomic_inc_unchecked(&sk->sk_drops);
77905 if (is_udp4)
77906 UDP_INC_STATS_USER(sock_net(sk),
77907 UDP_MIB_INERRORS,
77908 @@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77909 return rc;
77910 drop:
77911 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
77912 - atomic_inc(&sk->sk_drops);
77913 + atomic_inc_unchecked(&sk->sk_drops);
77914 kfree_skb(skb);
77915 return -1;
77916 }
77917 @@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
77918 if (likely(skb1 == NULL))
77919 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
77920 if (!skb1) {
77921 - atomic_inc(&sk->sk_drops);
77922 + atomic_inc_unchecked(&sk->sk_drops);
77923 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
77924 IS_UDPLITE(sk));
77925 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77926 @@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
77927 goto discard;
77928
77929 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
77930 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77931 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
77932 +#endif
77933 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
77934
77935 kfree_skb(skb);
77936 @@ -1471,8 +1478,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
77937 0, 0L, 0,
77938 sock_i_uid(sp), 0,
77939 sock_i_ino(sp),
77940 - atomic_read(&sp->sk_refcnt), sp,
77941 - atomic_read(&sp->sk_drops));
77942 + atomic_read(&sp->sk_refcnt),
77943 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77944 + NULL,
77945 +#else
77946 + sp,
77947 +#endif
77948 + atomic_read_unchecked(&sp->sk_drops));
77949 }
77950
77951 int udp6_seq_show(struct seq_file *seq, void *v)
77952 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
77953 index 6b9d5a0..4dffaf1 100644
77954 --- a/net/irda/ircomm/ircomm_tty.c
77955 +++ b/net/irda/ircomm/ircomm_tty.c
77956 @@ -281,16 +281,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77957 add_wait_queue(&self->open_wait, &wait);
77958
77959 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
77960 - __FILE__,__LINE__, tty->driver->name, self->open_count );
77961 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
77962
77963 /* As far as I can see, we protect open_count - Jean II */
77964 spin_lock_irqsave(&self->spinlock, flags);
77965 if (!tty_hung_up_p(filp)) {
77966 extra_count = 1;
77967 - self->open_count--;
77968 + local_dec(&self->open_count);
77969 }
77970 spin_unlock_irqrestore(&self->spinlock, flags);
77971 - self->blocked_open++;
77972 + local_inc(&self->blocked_open);
77973
77974 while (1) {
77975 if (tty->termios->c_cflag & CBAUD) {
77976 @@ -330,7 +330,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77977 }
77978
77979 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
77980 - __FILE__,__LINE__, tty->driver->name, self->open_count );
77981 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
77982
77983 schedule();
77984 }
77985 @@ -341,13 +341,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77986 if (extra_count) {
77987 /* ++ is not atomic, so this should be protected - Jean II */
77988 spin_lock_irqsave(&self->spinlock, flags);
77989 - self->open_count++;
77990 + local_inc(&self->open_count);
77991 spin_unlock_irqrestore(&self->spinlock, flags);
77992 }
77993 - self->blocked_open--;
77994 + local_dec(&self->blocked_open);
77995
77996 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
77997 - __FILE__,__LINE__, tty->driver->name, self->open_count);
77998 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
77999
78000 if (!retval)
78001 self->flags |= ASYNC_NORMAL_ACTIVE;
78002 @@ -412,14 +412,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
78003 }
78004 /* ++ is not atomic, so this should be protected - Jean II */
78005 spin_lock_irqsave(&self->spinlock, flags);
78006 - self->open_count++;
78007 + local_inc(&self->open_count);
78008
78009 tty->driver_data = self;
78010 self->tty = tty;
78011 spin_unlock_irqrestore(&self->spinlock, flags);
78012
78013 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
78014 - self->line, self->open_count);
78015 + self->line, local_read(&self->open_count));
78016
78017 /* Not really used by us, but lets do it anyway */
78018 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
78019 @@ -505,7 +505,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
78020 return;
78021 }
78022
78023 - if ((tty->count == 1) && (self->open_count != 1)) {
78024 + if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
78025 /*
78026 * Uh, oh. tty->count is 1, which means that the tty
78027 * structure will be freed. state->count should always
78028 @@ -515,16 +515,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
78029 */
78030 IRDA_DEBUG(0, "%s(), bad serial port count; "
78031 "tty->count is 1, state->count is %d\n", __func__ ,
78032 - self->open_count);
78033 - self->open_count = 1;
78034 + local_read(&self->open_count));
78035 + local_set(&self->open_count, 1);
78036 }
78037
78038 - if (--self->open_count < 0) {
78039 + if (local_dec_return(&self->open_count) < 0) {
78040 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
78041 - __func__, self->line, self->open_count);
78042 - self->open_count = 0;
78043 + __func__, self->line, local_read(&self->open_count));
78044 + local_set(&self->open_count, 0);
78045 }
78046 - if (self->open_count) {
78047 + if (local_read(&self->open_count)) {
78048 spin_unlock_irqrestore(&self->spinlock, flags);
78049
78050 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
78051 @@ -556,7 +556,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
78052 tty->closing = 0;
78053 self->tty = NULL;
78054
78055 - if (self->blocked_open) {
78056 + if (local_read(&self->blocked_open)) {
78057 if (self->close_delay)
78058 schedule_timeout_interruptible(self->close_delay);
78059 wake_up_interruptible(&self->open_wait);
78060 @@ -1008,7 +1008,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
78061 spin_lock_irqsave(&self->spinlock, flags);
78062 self->flags &= ~ASYNC_NORMAL_ACTIVE;
78063 self->tty = NULL;
78064 - self->open_count = 0;
78065 + local_set(&self->open_count, 0);
78066 spin_unlock_irqrestore(&self->spinlock, flags);
78067
78068 wake_up_interruptible(&self->open_wait);
78069 @@ -1355,7 +1355,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
78070 seq_putc(m, '\n');
78071
78072 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
78073 - seq_printf(m, "Open count: %d\n", self->open_count);
78074 + seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
78075 seq_printf(m, "Max data size: %d\n", self->max_data_size);
78076 seq_printf(m, "Max header size: %d\n", self->max_header_size);
78077
78078 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
78079 index cd6f7a9..e63fe89 100644
78080 --- a/net/iucv/af_iucv.c
78081 +++ b/net/iucv/af_iucv.c
78082 @@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
78083
78084 write_lock_bh(&iucv_sk_list.lock);
78085
78086 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
78087 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
78088 while (__iucv_get_sock_by_name(name)) {
78089 sprintf(name, "%08x",
78090 - atomic_inc_return(&iucv_sk_list.autobind_name));
78091 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
78092 }
78093
78094 write_unlock_bh(&iucv_sk_list.lock);
78095 diff --git a/net/key/af_key.c b/net/key/af_key.c
78096 index 34e4185..8823368 100644
78097 --- a/net/key/af_key.c
78098 +++ b/net/key/af_key.c
78099 @@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
78100 static u32 get_acqseq(void)
78101 {
78102 u32 res;
78103 - static atomic_t acqseq;
78104 + static atomic_unchecked_t acqseq;
78105
78106 do {
78107 - res = atomic_inc_return(&acqseq);
78108 + res = atomic_inc_return_unchecked(&acqseq);
78109 } while (!res);
78110 return res;
78111 }
78112 diff --git a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c
78113 index 3bfb34a..69bf48d 100644
78114 --- a/net/l2tp/l2tp_eth.c
78115 +++ b/net/l2tp/l2tp_eth.c
78116 @@ -290,6 +290,7 @@ static int l2tp_eth_create(struct net *net, u32 tunnel_id, u32 session_id, u32 p
78117
78118 out_del_dev:
78119 free_netdev(dev);
78120 + spriv->dev = NULL;
78121 out_del_session:
78122 l2tp_session_delete(session);
78123 out:
78124 diff --git a/net/mac80211/ibss.c b/net/mac80211/ibss.c
78125 index 5746d62..327aa07 100644
78126 --- a/net/mac80211/ibss.c
78127 +++ b/net/mac80211/ibss.c
78128 @@ -1074,7 +1074,7 @@ int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata,
78129 sdata->u.ibss.state = IEEE80211_IBSS_MLME_SEARCH;
78130 sdata->u.ibss.ibss_join_req = jiffies;
78131
78132 - memcpy(sdata->u.ibss.ssid, params->ssid, IEEE80211_MAX_SSID_LEN);
78133 + memcpy(sdata->u.ibss.ssid, params->ssid, params->ssid_len);
78134 sdata->u.ibss.ssid_len = params->ssid_len;
78135
78136 mutex_unlock(&sdata->u.ibss.mtx);
78137 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
78138 index bb61f77..3788d63 100644
78139 --- a/net/mac80211/ieee80211_i.h
78140 +++ b/net/mac80211/ieee80211_i.h
78141 @@ -28,6 +28,7 @@
78142 #include <net/ieee80211_radiotap.h>
78143 #include <net/cfg80211.h>
78144 #include <net/mac80211.h>
78145 +#include <asm/local.h>
78146 #include "key.h"
78147 #include "sta_info.h"
78148 #include "debug.h"
78149 @@ -840,7 +841,7 @@ struct ieee80211_local {
78150 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
78151 spinlock_t queue_stop_reason_lock;
78152
78153 - int open_count;
78154 + local_t open_count;
78155 int monitors, cooked_mntrs;
78156 /* number of interfaces with corresponding FIF_ flags */
78157 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
78158 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
78159 index c93d395..a305570 100644
78160 --- a/net/mac80211/iface.c
78161 +++ b/net/mac80211/iface.c
78162 @@ -454,7 +454,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78163 break;
78164 }
78165
78166 - if (local->open_count == 0) {
78167 + if (local_read(&local->open_count) == 0) {
78168 res = drv_start(local);
78169 if (res)
78170 goto err_del_bss;
78171 @@ -497,7 +497,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78172 break;
78173 }
78174
78175 - if (local->monitors == 0 && local->open_count == 0) {
78176 + if (local->monitors == 0 && local_read(&local->open_count) == 0) {
78177 res = ieee80211_add_virtual_monitor(local);
78178 if (res)
78179 goto err_stop;
78180 @@ -594,7 +594,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78181 mutex_unlock(&local->mtx);
78182
78183 if (coming_up)
78184 - local->open_count++;
78185 + local_inc(&local->open_count);
78186
78187 if (hw_reconf_flags)
78188 ieee80211_hw_config(local, hw_reconf_flags);
78189 @@ -607,7 +607,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78190 err_del_interface:
78191 drv_remove_interface(local, sdata);
78192 err_stop:
78193 - if (!local->open_count)
78194 + if (!local_read(&local->open_count))
78195 drv_stop(local);
78196 err_del_bss:
78197 sdata->bss = NULL;
78198 @@ -736,7 +736,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78199 }
78200
78201 if (going_down)
78202 - local->open_count--;
78203 + local_dec(&local->open_count);
78204
78205 switch (sdata->vif.type) {
78206 case NL80211_IFTYPE_AP_VLAN:
78207 @@ -796,7 +796,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78208
78209 ieee80211_recalc_ps(local, -1);
78210
78211 - if (local->open_count == 0) {
78212 + if (local_read(&local->open_count) == 0) {
78213 if (local->ops->napi_poll)
78214 napi_disable(&local->napi);
78215 ieee80211_clear_tx_pending(local);
78216 @@ -828,7 +828,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78217 }
78218 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
78219
78220 - if (local->monitors == local->open_count && local->monitors > 0)
78221 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
78222 ieee80211_add_virtual_monitor(local);
78223 }
78224
78225 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
78226 index c26e231..8916637 100644
78227 --- a/net/mac80211/main.c
78228 +++ b/net/mac80211/main.c
78229 @@ -166,7 +166,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
78230 local->hw.conf.power_level = power;
78231 }
78232
78233 - if (changed && local->open_count) {
78234 + if (changed && local_read(&local->open_count)) {
78235 ret = drv_config(local, changed);
78236 /*
78237 * Goal:
78238 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
78239 index 5c572e7..ecf75ce 100644
78240 --- a/net/mac80211/pm.c
78241 +++ b/net/mac80211/pm.c
78242 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78243 struct ieee80211_sub_if_data *sdata;
78244 struct sta_info *sta;
78245
78246 - if (!local->open_count)
78247 + if (!local_read(&local->open_count))
78248 goto suspend;
78249
78250 ieee80211_scan_cancel(local);
78251 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78252 cancel_work_sync(&local->dynamic_ps_enable_work);
78253 del_timer_sync(&local->dynamic_ps_timer);
78254
78255 - local->wowlan = wowlan && local->open_count;
78256 + local->wowlan = wowlan && local_read(&local->open_count);
78257 if (local->wowlan) {
78258 int err = drv_suspend(local, wowlan);
78259 if (err < 0) {
78260 @@ -143,7 +143,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78261 drv_remove_interface(local, sdata);
78262
78263 /* stop hardware - this must stop RX */
78264 - if (local->open_count)
78265 + if (local_read(&local->open_count))
78266 ieee80211_stop_device(local);
78267
78268 suspend:
78269 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
78270 index 3313c11..bec9f17 100644
78271 --- a/net/mac80211/rate.c
78272 +++ b/net/mac80211/rate.c
78273 @@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
78274
78275 ASSERT_RTNL();
78276
78277 - if (local->open_count)
78278 + if (local_read(&local->open_count))
78279 return -EBUSY;
78280
78281 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
78282 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
78283 index c97a065..ff61928 100644
78284 --- a/net/mac80211/rc80211_pid_debugfs.c
78285 +++ b/net/mac80211/rc80211_pid_debugfs.c
78286 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
78287
78288 spin_unlock_irqrestore(&events->lock, status);
78289
78290 - if (copy_to_user(buf, pb, p))
78291 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
78292 return -EFAULT;
78293
78294 return p;
78295 diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
78296 index 0cb4ede..884155d 100644
78297 --- a/net/mac80211/rx.c
78298 +++ b/net/mac80211/rx.c
78299 @@ -491,6 +491,11 @@ ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
78300
78301 if (ieee80211_is_action(hdr->frame_control)) {
78302 u8 category;
78303 +
78304 + /* make sure category field is present */
78305 + if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE)
78306 + return RX_DROP_MONITOR;
78307 +
78308 mgmt = (struct ieee80211_mgmt *)hdr;
78309 category = mgmt->u.action.category;
78310 if (category != WLAN_CATEGORY_MESH_ACTION &&
78311 @@ -1426,7 +1431,6 @@ ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
78312 frag = sc & IEEE80211_SCTL_FRAG;
78313
78314 if (likely((!ieee80211_has_morefrags(fc) && frag == 0) ||
78315 - (rx->skb)->len < 24 ||
78316 is_multicast_ether_addr(hdr->addr1))) {
78317 /* not fragmented */
78318 goto out;
78319 @@ -1849,6 +1853,20 @@ ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
78320
78321 hdr = (struct ieee80211_hdr *) skb->data;
78322 hdrlen = ieee80211_hdrlen(hdr->frame_control);
78323 +
78324 + /* make sure fixed part of mesh header is there, also checks skb len */
78325 + if (!pskb_may_pull(rx->skb, hdrlen + 6))
78326 + return RX_DROP_MONITOR;
78327 +
78328 + mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
78329 +
78330 + /* make sure full mesh header is there, also checks skb len */
78331 + if (!pskb_may_pull(rx->skb,
78332 + hdrlen + ieee80211_get_mesh_hdrlen(mesh_hdr)))
78333 + return RX_DROP_MONITOR;
78334 +
78335 + /* reload pointers */
78336 + hdr = (struct ieee80211_hdr *) skb->data;
78337 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
78338
78339 /* frame is in RMC, don't forward */
78340 @@ -1871,9 +1889,12 @@ ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
78341 if (is_multicast_ether_addr(hdr->addr1)) {
78342 mpp_addr = hdr->addr3;
78343 proxied_addr = mesh_hdr->eaddr1;
78344 - } else {
78345 + } else if (mesh_hdr->flags & MESH_FLAGS_AE_A5_A6) {
78346 + /* has_a4 already checked in ieee80211_rx_mesh_check */
78347 mpp_addr = hdr->addr4;
78348 proxied_addr = mesh_hdr->eaddr2;
78349 + } else {
78350 + return RX_DROP_MONITOR;
78351 }
78352
78353 rcu_read_lock();
78354 @@ -2313,6 +2334,10 @@ ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
78355 }
78356 break;
78357 case WLAN_CATEGORY_SELF_PROTECTED:
78358 + if (len < (IEEE80211_MIN_ACTION_SIZE +
78359 + sizeof(mgmt->u.action.u.self_prot.action_code)))
78360 + break;
78361 +
78362 switch (mgmt->u.action.u.self_prot.action_code) {
78363 case WLAN_SP_MESH_PEERING_OPEN:
78364 case WLAN_SP_MESH_PEERING_CLOSE:
78365 @@ -2331,6 +2356,10 @@ ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
78366 }
78367 break;
78368 case WLAN_CATEGORY_MESH_ACTION:
78369 + if (len < (IEEE80211_MIN_ACTION_SIZE +
78370 + sizeof(mgmt->u.action.u.mesh_action.action_code)))
78371 + break;
78372 +
78373 if (!ieee80211_vif_is_mesh(&sdata->vif))
78374 break;
78375 if (mesh_action_is_path_sel(mgmt) &&
78376 @@ -2865,10 +2894,15 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
78377 if (ieee80211_is_data(fc) || ieee80211_is_mgmt(fc))
78378 local->dot11ReceivedFragmentCount++;
78379
78380 - if (ieee80211_is_mgmt(fc))
78381 - err = skb_linearize(skb);
78382 - else
78383 + if (ieee80211_is_mgmt(fc)) {
78384 + /* drop frame if too short for header */
78385 + if (skb->len < ieee80211_hdrlen(fc))
78386 + err = -ENOBUFS;
78387 + else
78388 + err = skb_linearize(skb);
78389 + } else {
78390 err = !pskb_may_pull(skb, ieee80211_hdrlen(fc));
78391 + }
78392
78393 if (err) {
78394 dev_kfree_skb(skb);
78395 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
78396 index c9b52f7..4da1014 100644
78397 --- a/net/mac80211/util.c
78398 +++ b/net/mac80211/util.c
78399 @@ -1251,7 +1251,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
78400 }
78401 #endif
78402 /* everything else happens only if HW was up & running */
78403 - if (!local->open_count)
78404 + if (!local_read(&local->open_count))
78405 goto wake_up;
78406
78407 /*
78408 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
78409 index c19b214..471fad1 100644
78410 --- a/net/netfilter/Kconfig
78411 +++ b/net/netfilter/Kconfig
78412 @@ -872,6 +872,16 @@ config NETFILTER_XT_MATCH_ESP
78413
78414 To compile it as a module, choose M here. If unsure, say N.
78415
78416 +config NETFILTER_XT_MATCH_GRADM
78417 + tristate '"gradm" match support'
78418 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
78419 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
78420 + ---help---
78421 + The gradm match allows to match on grsecurity RBAC being enabled.
78422 + It is useful when iptables rules are applied early on bootup to
78423 + prevent connections to the machine (except from a trusted host)
78424 + while the RBAC system is disabled.
78425 +
78426 config NETFILTER_XT_MATCH_HASHLIMIT
78427 tristate '"hashlimit" match support'
78428 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
78429 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
78430 index 1c5160f..145ae21 100644
78431 --- a/net/netfilter/Makefile
78432 +++ b/net/netfilter/Makefile
78433 @@ -90,6 +90,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
78434 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
78435 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
78436 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
78437 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
78438 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
78439 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
78440 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
78441 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
78442 index 1548df9..98ad9b4 100644
78443 --- a/net/netfilter/ipvs/ip_vs_conn.c
78444 +++ b/net/netfilter/ipvs/ip_vs_conn.c
78445 @@ -557,7 +557,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
78446 /* Increase the refcnt counter of the dest */
78447 atomic_inc(&dest->refcnt);
78448
78449 - conn_flags = atomic_read(&dest->conn_flags);
78450 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
78451 if (cp->protocol != IPPROTO_UDP)
78452 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
78453 flags = cp->flags;
78454 @@ -902,7 +902,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
78455 atomic_set(&cp->refcnt, 1);
78456
78457 atomic_set(&cp->n_control, 0);
78458 - atomic_set(&cp->in_pkts, 0);
78459 + atomic_set_unchecked(&cp->in_pkts, 0);
78460
78461 atomic_inc(&ipvs->conn_count);
78462 if (flags & IP_VS_CONN_F_NO_CPORT)
78463 @@ -1183,7 +1183,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
78464
78465 /* Don't drop the entry if its number of incoming packets is not
78466 located in [0, 8] */
78467 - i = atomic_read(&cp->in_pkts);
78468 + i = atomic_read_unchecked(&cp->in_pkts);
78469 if (i > 8 || i < 0) return 0;
78470
78471 if (!todrop_rate[i]) return 0;
78472 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
78473 index b54ecce..fc5f6cf 100644
78474 --- a/net/netfilter/ipvs/ip_vs_core.c
78475 +++ b/net/netfilter/ipvs/ip_vs_core.c
78476 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
78477 ret = cp->packet_xmit(skb, cp, pd->pp);
78478 /* do not touch skb anymore */
78479
78480 - atomic_inc(&cp->in_pkts);
78481 + atomic_inc_unchecked(&cp->in_pkts);
78482 ip_vs_conn_put(cp);
78483 return ret;
78484 }
78485 @@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
78486 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
78487 pkts = sysctl_sync_threshold(ipvs);
78488 else
78489 - pkts = atomic_add_return(1, &cp->in_pkts);
78490 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78491
78492 if (ipvs->sync_state & IP_VS_STATE_MASTER)
78493 ip_vs_sync_conn(net, cp, pkts);
78494 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
78495 index f51013c..c99ee52 100644
78496 --- a/net/netfilter/ipvs/ip_vs_ctl.c
78497 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
78498 @@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
78499 ip_vs_rs_hash(ipvs, dest);
78500 write_unlock_bh(&ipvs->rs_lock);
78501 }
78502 - atomic_set(&dest->conn_flags, conn_flags);
78503 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
78504
78505 /* bind the service */
78506 if (!dest->svc) {
78507 @@ -2076,7 +2076,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
78508 " %-7s %-6d %-10d %-10d\n",
78509 &dest->addr.in6,
78510 ntohs(dest->port),
78511 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
78512 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
78513 atomic_read(&dest->weight),
78514 atomic_read(&dest->activeconns),
78515 atomic_read(&dest->inactconns));
78516 @@ -2087,7 +2087,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
78517 "%-7s %-6d %-10d %-10d\n",
78518 ntohl(dest->addr.ip),
78519 ntohs(dest->port),
78520 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
78521 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
78522 atomic_read(&dest->weight),
78523 atomic_read(&dest->activeconns),
78524 atomic_read(&dest->inactconns));
78525 @@ -2557,7 +2557,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
78526
78527 entry.addr = dest->addr.ip;
78528 entry.port = dest->port;
78529 - entry.conn_flags = atomic_read(&dest->conn_flags);
78530 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
78531 entry.weight = atomic_read(&dest->weight);
78532 entry.u_threshold = dest->u_threshold;
78533 entry.l_threshold = dest->l_threshold;
78534 @@ -3092,7 +3092,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
78535 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
78536 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
78537 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
78538 - (atomic_read(&dest->conn_flags) &
78539 + (atomic_read_unchecked(&dest->conn_flags) &
78540 IP_VS_CONN_F_FWD_MASK)) ||
78541 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
78542 atomic_read(&dest->weight)) ||
78543 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
78544 index effa10c..9058928 100644
78545 --- a/net/netfilter/ipvs/ip_vs_sync.c
78546 +++ b/net/netfilter/ipvs/ip_vs_sync.c
78547 @@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
78548 cp = cp->control;
78549 if (cp) {
78550 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
78551 - pkts = atomic_add_return(1, &cp->in_pkts);
78552 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78553 else
78554 pkts = sysctl_sync_threshold(ipvs);
78555 ip_vs_sync_conn(net, cp->control, pkts);
78556 @@ -758,7 +758,7 @@ control:
78557 if (!cp)
78558 return;
78559 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
78560 - pkts = atomic_add_return(1, &cp->in_pkts);
78561 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78562 else
78563 pkts = sysctl_sync_threshold(ipvs);
78564 goto sloop;
78565 @@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
78566
78567 if (opt)
78568 memcpy(&cp->in_seq, opt, sizeof(*opt));
78569 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
78570 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
78571 cp->state = state;
78572 cp->old_state = cp->state;
78573 /*
78574 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
78575 index c3c6291..3376d73 100644
78576 --- a/net/netfilter/ipvs/ip_vs_xmit.c
78577 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
78578 @@ -1157,7 +1157,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
78579 else
78580 rc = NF_ACCEPT;
78581 /* do not touch skb anymore */
78582 - atomic_inc(&cp->in_pkts);
78583 + atomic_inc_unchecked(&cp->in_pkts);
78584 goto out;
78585 }
78586
78587 @@ -1278,7 +1278,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
78588 else
78589 rc = NF_ACCEPT;
78590 /* do not touch skb anymore */
78591 - atomic_inc(&cp->in_pkts);
78592 + atomic_inc_unchecked(&cp->in_pkts);
78593 goto out;
78594 }
78595
78596 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
78597 index 2ceec64..a5b8a61 100644
78598 --- a/net/netfilter/nf_conntrack_core.c
78599 +++ b/net/netfilter/nf_conntrack_core.c
78600 @@ -1529,6 +1529,10 @@ err_extend:
78601 #define UNCONFIRMED_NULLS_VAL ((1<<30)+0)
78602 #define DYING_NULLS_VAL ((1<<30)+1)
78603
78604 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78605 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
78606 +#endif
78607 +
78608 static int nf_conntrack_init_net(struct net *net)
78609 {
78610 int ret;
78611 @@ -1542,7 +1546,11 @@ static int nf_conntrack_init_net(struct net *net)
78612 goto err_stat;
78613 }
78614
78615 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78616 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
78617 +#else
78618 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
78619 +#endif
78620 if (!net->ct.slabname) {
78621 ret = -ENOMEM;
78622 goto err_slabname;
78623 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
78624 index 5cfb5be..217c6d8 100644
78625 --- a/net/netfilter/nfnetlink_log.c
78626 +++ b/net/netfilter/nfnetlink_log.c
78627 @@ -70,7 +70,7 @@ struct nfulnl_instance {
78628 };
78629
78630 static DEFINE_SPINLOCK(instances_lock);
78631 -static atomic_t global_seq;
78632 +static atomic_unchecked_t global_seq;
78633
78634 #define INSTANCE_BUCKETS 16
78635 static struct hlist_head instance_table[INSTANCE_BUCKETS];
78636 @@ -523,7 +523,7 @@ __build_packet_message(struct nfulnl_instance *inst,
78637 /* global sequence number */
78638 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
78639 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
78640 - htonl(atomic_inc_return(&global_seq))))
78641 + htonl(atomic_inc_return_unchecked(&global_seq))))
78642 goto nla_put_failure;
78643
78644 if (data_len) {
78645 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
78646 new file mode 100644
78647 index 0000000..6905327
78648 --- /dev/null
78649 +++ b/net/netfilter/xt_gradm.c
78650 @@ -0,0 +1,51 @@
78651 +/*
78652 + * gradm match for netfilter
78653 + * Copyright © Zbigniew Krzystolik, 2010
78654 + *
78655 + * This program is free software; you can redistribute it and/or modify
78656 + * it under the terms of the GNU General Public License; either version
78657 + * 2 or 3 as published by the Free Software Foundation.
78658 + */
78659 +#include <linux/module.h>
78660 +#include <linux/moduleparam.h>
78661 +#include <linux/skbuff.h>
78662 +#include <linux/netfilter/x_tables.h>
78663 +#include <linux/grsecurity.h>
78664 +#include <linux/netfilter/xt_gradm.h>
78665 +
78666 +static bool
78667 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
78668 +{
78669 + const struct xt_gradm_mtinfo *info = par->matchinfo;
78670 + bool retval = false;
78671 + if (gr_acl_is_enabled())
78672 + retval = true;
78673 + return retval ^ info->invflags;
78674 +}
78675 +
78676 +static struct xt_match gradm_mt_reg __read_mostly = {
78677 + .name = "gradm",
78678 + .revision = 0,
78679 + .family = NFPROTO_UNSPEC,
78680 + .match = gradm_mt,
78681 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
78682 + .me = THIS_MODULE,
78683 +};
78684 +
78685 +static int __init gradm_mt_init(void)
78686 +{
78687 + return xt_register_match(&gradm_mt_reg);
78688 +}
78689 +
78690 +static void __exit gradm_mt_exit(void)
78691 +{
78692 + xt_unregister_match(&gradm_mt_reg);
78693 +}
78694 +
78695 +module_init(gradm_mt_init);
78696 +module_exit(gradm_mt_exit);
78697 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
78698 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
78699 +MODULE_LICENSE("GPL");
78700 +MODULE_ALIAS("ipt_gradm");
78701 +MODULE_ALIAS("ip6t_gradm");
78702 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
78703 index 4fe4fb4..87a89e5 100644
78704 --- a/net/netfilter/xt_statistic.c
78705 +++ b/net/netfilter/xt_statistic.c
78706 @@ -19,7 +19,7 @@
78707 #include <linux/module.h>
78708
78709 struct xt_statistic_priv {
78710 - atomic_t count;
78711 + atomic_unchecked_t count;
78712 } ____cacheline_aligned_in_smp;
78713
78714 MODULE_LICENSE("GPL");
78715 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
78716 break;
78717 case XT_STATISTIC_MODE_NTH:
78718 do {
78719 - oval = atomic_read(&info->master->count);
78720 + oval = atomic_read_unchecked(&info->master->count);
78721 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
78722 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
78723 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
78724 if (nval == 0)
78725 ret = !ret;
78726 break;
78727 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
78728 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
78729 if (info->master == NULL)
78730 return -ENOMEM;
78731 - atomic_set(&info->master->count, info->u.nth.count);
78732 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
78733
78734 return 0;
78735 }
78736 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
78737 index 9172179..a4035c4 100644
78738 --- a/net/netlink/af_netlink.c
78739 +++ b/net/netlink/af_netlink.c
78740 @@ -769,7 +769,7 @@ static void netlink_overrun(struct sock *sk)
78741 sk->sk_error_report(sk);
78742 }
78743 }
78744 - atomic_inc(&sk->sk_drops);
78745 + atomic_inc_unchecked(&sk->sk_drops);
78746 }
78747
78748 static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
78749 @@ -2059,7 +2059,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
78750 sk_wmem_alloc_get(s),
78751 nlk->cb,
78752 atomic_read(&s->sk_refcnt),
78753 - atomic_read(&s->sk_drops),
78754 + atomic_read_unchecked(&s->sk_drops),
78755 sock_i_ino(s)
78756 );
78757
78758 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
78759 index 7261eb8..44e8ac6 100644
78760 --- a/net/netrom/af_netrom.c
78761 +++ b/net/netrom/af_netrom.c
78762 @@ -838,6 +838,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
78763 struct sock *sk = sock->sk;
78764 struct nr_sock *nr = nr_sk(sk);
78765
78766 + memset(sax, 0, sizeof(*sax));
78767 lock_sock(sk);
78768 if (peer != 0) {
78769 if (sk->sk_state != TCP_ESTABLISHED) {
78770 @@ -852,7 +853,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
78771 *uaddr_len = sizeof(struct full_sockaddr_ax25);
78772 } else {
78773 sax->fsa_ax25.sax25_family = AF_NETROM;
78774 - sax->fsa_ax25.sax25_ndigis = 0;
78775 sax->fsa_ax25.sax25_call = nr->source_addr;
78776 *uaddr_len = sizeof(struct sockaddr_ax25);
78777 }
78778 diff --git a/net/nfc/llcp/sock.c b/net/nfc/llcp/sock.c
78779 index ddeb9aa..e18fffd 100644
78780 --- a/net/nfc/llcp/sock.c
78781 +++ b/net/nfc/llcp/sock.c
78782 @@ -443,15 +443,11 @@ static int llcp_sock_connect(struct socket *sock, struct sockaddr *_addr,
78783 pr_debug("sock %p sk %p flags 0x%x\n", sock, sk, flags);
78784
78785 if (!addr || len < sizeof(struct sockaddr_nfc) ||
78786 - addr->sa_family != AF_NFC) {
78787 - pr_err("Invalid socket\n");
78788 + addr->sa_family != AF_NFC)
78789 return -EINVAL;
78790 - }
78791
78792 - if (addr->service_name_len == 0 && addr->dsap == 0) {
78793 - pr_err("Missing service name or dsap\n");
78794 + if (addr->service_name_len == 0 && addr->dsap == 0)
78795 return -EINVAL;
78796 - }
78797
78798 pr_debug("addr dev_idx=%u target_idx=%u protocol=%u\n", addr->dev_idx,
78799 addr->target_idx, addr->nfc_protocol);
78800 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
78801 index c5c9e2a..4814ab1 100644
78802 --- a/net/packet/af_packet.c
78803 +++ b/net/packet/af_packet.c
78804 @@ -1689,7 +1689,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
78805
78806 spin_lock(&sk->sk_receive_queue.lock);
78807 po->stats.tp_packets++;
78808 - skb->dropcount = atomic_read(&sk->sk_drops);
78809 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
78810 __skb_queue_tail(&sk->sk_receive_queue, skb);
78811 spin_unlock(&sk->sk_receive_queue.lock);
78812 sk->sk_data_ready(sk, skb->len);
78813 @@ -1698,7 +1698,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
78814 drop_n_acct:
78815 spin_lock(&sk->sk_receive_queue.lock);
78816 po->stats.tp_drops++;
78817 - atomic_inc(&sk->sk_drops);
78818 + atomic_inc_unchecked(&sk->sk_drops);
78819 spin_unlock(&sk->sk_receive_queue.lock);
78820
78821 drop_n_restore:
78822 @@ -2642,6 +2642,7 @@ out:
78823
78824 static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
78825 {
78826 + struct sock_extended_err ee;
78827 struct sock_exterr_skb *serr;
78828 struct sk_buff *skb, *skb2;
78829 int copied, err;
78830 @@ -2663,8 +2664,9 @@ static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
78831 sock_recv_timestamp(msg, sk, skb);
78832
78833 serr = SKB_EXT_ERR(skb);
78834 + ee = serr->ee;
78835 put_cmsg(msg, SOL_PACKET, PACKET_TX_TIMESTAMP,
78836 - sizeof(serr->ee), &serr->ee);
78837 + sizeof ee, &ee);
78838
78839 msg->msg_flags |= MSG_ERRQUEUE;
78840 err = copied;
78841 @@ -3276,7 +3278,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
78842 case PACKET_HDRLEN:
78843 if (len > sizeof(int))
78844 len = sizeof(int);
78845 - if (copy_from_user(&val, optval, len))
78846 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
78847 return -EFAULT;
78848 switch (val) {
78849 case TPACKET_V1:
78850 @@ -3315,7 +3317,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
78851 len = lv;
78852 if (put_user(len, optlen))
78853 return -EFAULT;
78854 - if (copy_to_user(optval, data, len))
78855 + if (len > sizeof(st) || copy_to_user(optval, data, len))
78856 return -EFAULT;
78857 return 0;
78858 }
78859 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
78860 index 5a940db..f0b9c12 100644
78861 --- a/net/phonet/af_phonet.c
78862 +++ b/net/phonet/af_phonet.c
78863 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
78864 {
78865 struct phonet_protocol *pp;
78866
78867 - if (protocol >= PHONET_NPROTO)
78868 + if (protocol < 0 || protocol >= PHONET_NPROTO)
78869 return NULL;
78870
78871 rcu_read_lock();
78872 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
78873 {
78874 int err = 0;
78875
78876 - if (protocol >= PHONET_NPROTO)
78877 + if (protocol < 0 || protocol >= PHONET_NPROTO)
78878 return -EINVAL;
78879
78880 err = proto_register(pp->prot, 1);
78881 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
78882 index 576f22c..bc7a71b 100644
78883 --- a/net/phonet/pep.c
78884 +++ b/net/phonet/pep.c
78885 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
78886
78887 case PNS_PEP_CTRL_REQ:
78888 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
78889 - atomic_inc(&sk->sk_drops);
78890 + atomic_inc_unchecked(&sk->sk_drops);
78891 break;
78892 }
78893 __skb_pull(skb, 4);
78894 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
78895 }
78896
78897 if (pn->rx_credits == 0) {
78898 - atomic_inc(&sk->sk_drops);
78899 + atomic_inc_unchecked(&sk->sk_drops);
78900 err = -ENOBUFS;
78901 break;
78902 }
78903 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
78904 }
78905
78906 if (pn->rx_credits == 0) {
78907 - atomic_inc(&sk->sk_drops);
78908 + atomic_inc_unchecked(&sk->sk_drops);
78909 err = NET_RX_DROP;
78910 break;
78911 }
78912 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
78913 index 0acc943..c727611 100644
78914 --- a/net/phonet/socket.c
78915 +++ b/net/phonet/socket.c
78916 @@ -613,8 +613,13 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
78917 pn->resource, sk->sk_state,
78918 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
78919 sock_i_uid(sk), sock_i_ino(sk),
78920 - atomic_read(&sk->sk_refcnt), sk,
78921 - atomic_read(&sk->sk_drops), &len);
78922 + atomic_read(&sk->sk_refcnt),
78923 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78924 + NULL,
78925 +#else
78926 + sk,
78927 +#endif
78928 + atomic_read_unchecked(&sk->sk_drops), &len);
78929 }
78930 seq_printf(seq, "%*s\n", 127 - len, "");
78931 return 0;
78932 diff --git a/net/rds/cong.c b/net/rds/cong.c
78933 index e5b65ac..f3b6fb7 100644
78934 --- a/net/rds/cong.c
78935 +++ b/net/rds/cong.c
78936 @@ -78,7 +78,7 @@
78937 * finds that the saved generation number is smaller than the global generation
78938 * number, it wakes up the process.
78939 */
78940 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
78941 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
78942
78943 /*
78944 * Congestion monitoring
78945 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
78946 rdsdebug("waking map %p for %pI4\n",
78947 map, &map->m_addr);
78948 rds_stats_inc(s_cong_update_received);
78949 - atomic_inc(&rds_cong_generation);
78950 + atomic_inc_unchecked(&rds_cong_generation);
78951 if (waitqueue_active(&map->m_waitq))
78952 wake_up(&map->m_waitq);
78953 if (waitqueue_active(&rds_poll_waitq))
78954 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
78955
78956 int rds_cong_updated_since(unsigned long *recent)
78957 {
78958 - unsigned long gen = atomic_read(&rds_cong_generation);
78959 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
78960
78961 if (likely(*recent == gen))
78962 return 0;
78963 diff --git a/net/rds/ib.h b/net/rds/ib.h
78964 index 8d2b3d5..227ec5b 100644
78965 --- a/net/rds/ib.h
78966 +++ b/net/rds/ib.h
78967 @@ -128,7 +128,7 @@ struct rds_ib_connection {
78968 /* sending acks */
78969 unsigned long i_ack_flags;
78970 #ifdef KERNEL_HAS_ATOMIC64
78971 - atomic64_t i_ack_next; /* next ACK to send */
78972 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
78973 #else
78974 spinlock_t i_ack_lock; /* protect i_ack_next */
78975 u64 i_ack_next; /* next ACK to send */
78976 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
78977 index a1e1162..265e129 100644
78978 --- a/net/rds/ib_cm.c
78979 +++ b/net/rds/ib_cm.c
78980 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
78981 /* Clear the ACK state */
78982 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
78983 #ifdef KERNEL_HAS_ATOMIC64
78984 - atomic64_set(&ic->i_ack_next, 0);
78985 + atomic64_set_unchecked(&ic->i_ack_next, 0);
78986 #else
78987 ic->i_ack_next = 0;
78988 #endif
78989 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
78990 index 8d19491..05a3e65 100644
78991 --- a/net/rds/ib_recv.c
78992 +++ b/net/rds/ib_recv.c
78993 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
78994 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
78995 int ack_required)
78996 {
78997 - atomic64_set(&ic->i_ack_next, seq);
78998 + atomic64_set_unchecked(&ic->i_ack_next, seq);
78999 if (ack_required) {
79000 smp_mb__before_clear_bit();
79001 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
79002 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
79003 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
79004 smp_mb__after_clear_bit();
79005
79006 - return atomic64_read(&ic->i_ack_next);
79007 + return atomic64_read_unchecked(&ic->i_ack_next);
79008 }
79009 #endif
79010
79011 diff --git a/net/rds/iw.h b/net/rds/iw.h
79012 index 04ce3b1..48119a6 100644
79013 --- a/net/rds/iw.h
79014 +++ b/net/rds/iw.h
79015 @@ -134,7 +134,7 @@ struct rds_iw_connection {
79016 /* sending acks */
79017 unsigned long i_ack_flags;
79018 #ifdef KERNEL_HAS_ATOMIC64
79019 - atomic64_t i_ack_next; /* next ACK to send */
79020 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
79021 #else
79022 spinlock_t i_ack_lock; /* protect i_ack_next */
79023 u64 i_ack_next; /* next ACK to send */
79024 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
79025 index a91e1db..cf3053f 100644
79026 --- a/net/rds/iw_cm.c
79027 +++ b/net/rds/iw_cm.c
79028 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
79029 /* Clear the ACK state */
79030 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
79031 #ifdef KERNEL_HAS_ATOMIC64
79032 - atomic64_set(&ic->i_ack_next, 0);
79033 + atomic64_set_unchecked(&ic->i_ack_next, 0);
79034 #else
79035 ic->i_ack_next = 0;
79036 #endif
79037 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
79038 index 4503335..db566b4 100644
79039 --- a/net/rds/iw_recv.c
79040 +++ b/net/rds/iw_recv.c
79041 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
79042 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
79043 int ack_required)
79044 {
79045 - atomic64_set(&ic->i_ack_next, seq);
79046 + atomic64_set_unchecked(&ic->i_ack_next, seq);
79047 if (ack_required) {
79048 smp_mb__before_clear_bit();
79049 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
79050 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
79051 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
79052 smp_mb__after_clear_bit();
79053
79054 - return atomic64_read(&ic->i_ack_next);
79055 + return atomic64_read_unchecked(&ic->i_ack_next);
79056 }
79057 #endif
79058
79059 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
79060 index edac9ef..16bcb98 100644
79061 --- a/net/rds/tcp.c
79062 +++ b/net/rds/tcp.c
79063 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
79064 int val = 1;
79065
79066 set_fs(KERNEL_DS);
79067 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
79068 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
79069 sizeof(val));
79070 set_fs(oldfs);
79071 }
79072 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
79073 index 1b4fd68..2234175 100644
79074 --- a/net/rds/tcp_send.c
79075 +++ b/net/rds/tcp_send.c
79076 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
79077
79078 oldfs = get_fs();
79079 set_fs(KERNEL_DS);
79080 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
79081 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
79082 sizeof(val));
79083 set_fs(oldfs);
79084 }
79085 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
79086 index 05996d0..5a1dfe0 100644
79087 --- a/net/rxrpc/af_rxrpc.c
79088 +++ b/net/rxrpc/af_rxrpc.c
79089 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
79090 __be32 rxrpc_epoch;
79091
79092 /* current debugging ID */
79093 -atomic_t rxrpc_debug_id;
79094 +atomic_unchecked_t rxrpc_debug_id;
79095
79096 /* count of skbs currently in use */
79097 atomic_t rxrpc_n_skbs;
79098 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
79099 index e4d9cbc..b229649 100644
79100 --- a/net/rxrpc/ar-ack.c
79101 +++ b/net/rxrpc/ar-ack.c
79102 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
79103
79104 _enter("{%d,%d,%d,%d},",
79105 call->acks_hard, call->acks_unacked,
79106 - atomic_read(&call->sequence),
79107 + atomic_read_unchecked(&call->sequence),
79108 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
79109
79110 stop = 0;
79111 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
79112
79113 /* each Tx packet has a new serial number */
79114 sp->hdr.serial =
79115 - htonl(atomic_inc_return(&call->conn->serial));
79116 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
79117
79118 hdr = (struct rxrpc_header *) txb->head;
79119 hdr->serial = sp->hdr.serial;
79120 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
79121 */
79122 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
79123 {
79124 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
79125 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
79126 }
79127
79128 /*
79129 @@ -629,7 +629,7 @@ process_further:
79130
79131 latest = ntohl(sp->hdr.serial);
79132 hard = ntohl(ack.firstPacket);
79133 - tx = atomic_read(&call->sequence);
79134 + tx = atomic_read_unchecked(&call->sequence);
79135
79136 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
79137 latest,
79138 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
79139 goto maybe_reschedule;
79140
79141 send_ACK_with_skew:
79142 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
79143 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
79144 ntohl(ack.serial));
79145 send_ACK:
79146 mtu = call->conn->trans->peer->if_mtu;
79147 @@ -1173,7 +1173,7 @@ send_ACK:
79148 ackinfo.rxMTU = htonl(5692);
79149 ackinfo.jumbo_max = htonl(4);
79150
79151 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
79152 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
79153 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
79154 ntohl(hdr.serial),
79155 ntohs(ack.maxSkew),
79156 @@ -1191,7 +1191,7 @@ send_ACK:
79157 send_message:
79158 _debug("send message");
79159
79160 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
79161 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
79162 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
79163 send_message_2:
79164
79165 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
79166 index a3bbb36..3341fb9 100644
79167 --- a/net/rxrpc/ar-call.c
79168 +++ b/net/rxrpc/ar-call.c
79169 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
79170 spin_lock_init(&call->lock);
79171 rwlock_init(&call->state_lock);
79172 atomic_set(&call->usage, 1);
79173 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
79174 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79175 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
79176
79177 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
79178 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
79179 index 4106ca9..a338d7a 100644
79180 --- a/net/rxrpc/ar-connection.c
79181 +++ b/net/rxrpc/ar-connection.c
79182 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
79183 rwlock_init(&conn->lock);
79184 spin_lock_init(&conn->state_lock);
79185 atomic_set(&conn->usage, 1);
79186 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
79187 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79188 conn->avail_calls = RXRPC_MAXCALLS;
79189 conn->size_align = 4;
79190 conn->header_size = sizeof(struct rxrpc_header);
79191 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
79192 index e7ed43a..6afa140 100644
79193 --- a/net/rxrpc/ar-connevent.c
79194 +++ b/net/rxrpc/ar-connevent.c
79195 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
79196
79197 len = iov[0].iov_len + iov[1].iov_len;
79198
79199 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
79200 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
79201 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
79202
79203 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
79204 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
79205 index 529572f..c758ca7 100644
79206 --- a/net/rxrpc/ar-input.c
79207 +++ b/net/rxrpc/ar-input.c
79208 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
79209 /* track the latest serial number on this connection for ACK packet
79210 * information */
79211 serial = ntohl(sp->hdr.serial);
79212 - hi_serial = atomic_read(&call->conn->hi_serial);
79213 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
79214 while (serial > hi_serial)
79215 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
79216 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
79217 serial);
79218
79219 /* request ACK generation for any ACK or DATA packet that requests
79220 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
79221 index a693aca..81e7293 100644
79222 --- a/net/rxrpc/ar-internal.h
79223 +++ b/net/rxrpc/ar-internal.h
79224 @@ -272,8 +272,8 @@ struct rxrpc_connection {
79225 int error; /* error code for local abort */
79226 int debug_id; /* debug ID for printks */
79227 unsigned int call_counter; /* call ID counter */
79228 - atomic_t serial; /* packet serial number counter */
79229 - atomic_t hi_serial; /* highest serial number received */
79230 + atomic_unchecked_t serial; /* packet serial number counter */
79231 + atomic_unchecked_t hi_serial; /* highest serial number received */
79232 u8 avail_calls; /* number of calls available */
79233 u8 size_align; /* data size alignment (for security) */
79234 u8 header_size; /* rxrpc + security header size */
79235 @@ -346,7 +346,7 @@ struct rxrpc_call {
79236 spinlock_t lock;
79237 rwlock_t state_lock; /* lock for state transition */
79238 atomic_t usage;
79239 - atomic_t sequence; /* Tx data packet sequence counter */
79240 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
79241 u32 abort_code; /* local/remote abort code */
79242 enum { /* current state of call */
79243 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
79244 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
79245 */
79246 extern atomic_t rxrpc_n_skbs;
79247 extern __be32 rxrpc_epoch;
79248 -extern atomic_t rxrpc_debug_id;
79249 +extern atomic_unchecked_t rxrpc_debug_id;
79250 extern struct workqueue_struct *rxrpc_workqueue;
79251
79252 /*
79253 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
79254 index 87f7135..74d3703 100644
79255 --- a/net/rxrpc/ar-local.c
79256 +++ b/net/rxrpc/ar-local.c
79257 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
79258 spin_lock_init(&local->lock);
79259 rwlock_init(&local->services_lock);
79260 atomic_set(&local->usage, 1);
79261 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
79262 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79263 memcpy(&local->srx, srx, sizeof(*srx));
79264 }
79265
79266 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
79267 index e1ac183..b43e10e 100644
79268 --- a/net/rxrpc/ar-output.c
79269 +++ b/net/rxrpc/ar-output.c
79270 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
79271 sp->hdr.cid = call->cid;
79272 sp->hdr.callNumber = call->call_id;
79273 sp->hdr.seq =
79274 - htonl(atomic_inc_return(&call->sequence));
79275 + htonl(atomic_inc_return_unchecked(&call->sequence));
79276 sp->hdr.serial =
79277 - htonl(atomic_inc_return(&conn->serial));
79278 + htonl(atomic_inc_return_unchecked(&conn->serial));
79279 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
79280 sp->hdr.userStatus = 0;
79281 sp->hdr.securityIndex = conn->security_ix;
79282 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
79283 index bebaa43..2644591 100644
79284 --- a/net/rxrpc/ar-peer.c
79285 +++ b/net/rxrpc/ar-peer.c
79286 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
79287 INIT_LIST_HEAD(&peer->error_targets);
79288 spin_lock_init(&peer->lock);
79289 atomic_set(&peer->usage, 1);
79290 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
79291 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79292 memcpy(&peer->srx, srx, sizeof(*srx));
79293
79294 rxrpc_assess_MTU_size(peer);
79295 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
79296 index 38047f7..9f48511 100644
79297 --- a/net/rxrpc/ar-proc.c
79298 +++ b/net/rxrpc/ar-proc.c
79299 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
79300 atomic_read(&conn->usage),
79301 rxrpc_conn_states[conn->state],
79302 key_serial(conn->key),
79303 - atomic_read(&conn->serial),
79304 - atomic_read(&conn->hi_serial));
79305 + atomic_read_unchecked(&conn->serial),
79306 + atomic_read_unchecked(&conn->hi_serial));
79307
79308 return 0;
79309 }
79310 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
79311 index 92df566..87ec1bf 100644
79312 --- a/net/rxrpc/ar-transport.c
79313 +++ b/net/rxrpc/ar-transport.c
79314 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
79315 spin_lock_init(&trans->client_lock);
79316 rwlock_init(&trans->conn_lock);
79317 atomic_set(&trans->usage, 1);
79318 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
79319 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79320
79321 if (peer->srx.transport.family == AF_INET) {
79322 switch (peer->srx.transport_type) {
79323 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
79324 index f226709..0e735a8 100644
79325 --- a/net/rxrpc/rxkad.c
79326 +++ b/net/rxrpc/rxkad.c
79327 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
79328
79329 len = iov[0].iov_len + iov[1].iov_len;
79330
79331 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
79332 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
79333 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
79334
79335 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
79336 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
79337
79338 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
79339
79340 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
79341 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
79342 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
79343
79344 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
79345 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
79346 index 1e2eee8..ce3967e 100644
79347 --- a/net/sctp/proc.c
79348 +++ b/net/sctp/proc.c
79349 @@ -319,7 +319,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
79350 seq_printf(seq,
79351 "%8pK %8pK %-3d %-3d %-2d %-4d "
79352 "%4d %8d %8d %7d %5lu %-5d %5d ",
79353 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
79354 + assoc, sk,
79355 + sctp_sk(sk)->type, sk->sk_state,
79356 assoc->state, hash,
79357 assoc->assoc_id,
79358 assoc->sndbuf_used,
79359 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
79360 index 5e25981..dbda919 100644
79361 --- a/net/sctp/socket.c
79362 +++ b/net/sctp/socket.c
79363 @@ -4630,6 +4630,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
79364 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
79365 if (space_left < addrlen)
79366 return -ENOMEM;
79367 + if (addrlen > sizeof(temp) || addrlen < 0)
79368 + return -EFAULT;
79369 if (copy_to_user(to, &temp, addrlen))
79370 return -EFAULT;
79371 to += addrlen;
79372 diff --git a/net/socket.c b/net/socket.c
79373 index edc3c4a..4b4e4a8 100644
79374 --- a/net/socket.c
79375 +++ b/net/socket.c
79376 @@ -88,6 +88,7 @@
79377 #include <linux/nsproxy.h>
79378 #include <linux/magic.h>
79379 #include <linux/slab.h>
79380 +#include <linux/in.h>
79381
79382 #include <asm/uaccess.h>
79383 #include <asm/unistd.h>
79384 @@ -105,6 +106,8 @@
79385 #include <linux/sockios.h>
79386 #include <linux/atalk.h>
79387
79388 +#include <linux/grsock.h>
79389 +
79390 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
79391 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
79392 unsigned long nr_segs, loff_t pos);
79393 @@ -321,7 +324,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
79394 &sockfs_dentry_operations, SOCKFS_MAGIC);
79395 }
79396
79397 -static struct vfsmount *sock_mnt __read_mostly;
79398 +struct vfsmount *sock_mnt __read_mostly;
79399
79400 static struct file_system_type sock_fs_type = {
79401 .name = "sockfs",
79402 @@ -1209,6 +1212,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
79403 return -EAFNOSUPPORT;
79404 if (type < 0 || type >= SOCK_MAX)
79405 return -EINVAL;
79406 + if (protocol < 0)
79407 + return -EINVAL;
79408
79409 /* Compatibility.
79410
79411 @@ -1340,6 +1345,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
79412 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
79413 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
79414
79415 + if(!gr_search_socket(family, type, protocol)) {
79416 + retval = -EACCES;
79417 + goto out;
79418 + }
79419 +
79420 + if (gr_handle_sock_all(family, type, protocol)) {
79421 + retval = -EACCES;
79422 + goto out;
79423 + }
79424 +
79425 retval = sock_create(family, type, protocol, &sock);
79426 if (retval < 0)
79427 goto out;
79428 @@ -1452,6 +1467,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
79429 if (sock) {
79430 err = move_addr_to_kernel(umyaddr, addrlen, &address);
79431 if (err >= 0) {
79432 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
79433 + err = -EACCES;
79434 + goto error;
79435 + }
79436 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
79437 + if (err)
79438 + goto error;
79439 +
79440 err = security_socket_bind(sock,
79441 (struct sockaddr *)&address,
79442 addrlen);
79443 @@ -1460,6 +1483,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
79444 (struct sockaddr *)
79445 &address, addrlen);
79446 }
79447 +error:
79448 fput_light(sock->file, fput_needed);
79449 }
79450 return err;
79451 @@ -1483,10 +1507,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
79452 if ((unsigned int)backlog > somaxconn)
79453 backlog = somaxconn;
79454
79455 + if (gr_handle_sock_server_other(sock->sk)) {
79456 + err = -EPERM;
79457 + goto error;
79458 + }
79459 +
79460 + err = gr_search_listen(sock);
79461 + if (err)
79462 + goto error;
79463 +
79464 err = security_socket_listen(sock, backlog);
79465 if (!err)
79466 err = sock->ops->listen(sock, backlog);
79467
79468 +error:
79469 fput_light(sock->file, fput_needed);
79470 }
79471 return err;
79472 @@ -1530,6 +1564,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
79473 newsock->type = sock->type;
79474 newsock->ops = sock->ops;
79475
79476 + if (gr_handle_sock_server_other(sock->sk)) {
79477 + err = -EPERM;
79478 + sock_release(newsock);
79479 + goto out_put;
79480 + }
79481 +
79482 + err = gr_search_accept(sock);
79483 + if (err) {
79484 + sock_release(newsock);
79485 + goto out_put;
79486 + }
79487 +
79488 /*
79489 * We don't need try_module_get here, as the listening socket (sock)
79490 * has the protocol module (sock->ops->owner) held.
79491 @@ -1568,6 +1614,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
79492 fd_install(newfd, newfile);
79493 err = newfd;
79494
79495 + gr_attach_curr_ip(newsock->sk);
79496 +
79497 out_put:
79498 fput_light(sock->file, fput_needed);
79499 out:
79500 @@ -1600,6 +1648,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
79501 int, addrlen)
79502 {
79503 struct socket *sock;
79504 + struct sockaddr *sck;
79505 struct sockaddr_storage address;
79506 int err, fput_needed;
79507
79508 @@ -1610,6 +1659,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
79509 if (err < 0)
79510 goto out_put;
79511
79512 + sck = (struct sockaddr *)&address;
79513 +
79514 + if (gr_handle_sock_client(sck)) {
79515 + err = -EACCES;
79516 + goto out_put;
79517 + }
79518 +
79519 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
79520 + if (err)
79521 + goto out_put;
79522 +
79523 err =
79524 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
79525 if (err)
79526 @@ -1964,7 +2024,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
79527 * checking falls down on this.
79528 */
79529 if (copy_from_user(ctl_buf,
79530 - (void __user __force *)msg_sys->msg_control,
79531 + (void __force_user *)msg_sys->msg_control,
79532 ctl_len))
79533 goto out_freectl;
79534 msg_sys->msg_control = ctl_buf;
79535 @@ -2132,7 +2192,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
79536 * kernel msghdr to use the kernel address space)
79537 */
79538
79539 - uaddr = (__force void __user *)msg_sys->msg_name;
79540 + uaddr = (void __force_user *)msg_sys->msg_name;
79541 uaddr_len = COMPAT_NAMELEN(msg);
79542 if (MSG_CMSG_COMPAT & flags) {
79543 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
79544 @@ -2761,7 +2821,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79545 }
79546
79547 ifr = compat_alloc_user_space(buf_size);
79548 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
79549 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
79550
79551 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
79552 return -EFAULT;
79553 @@ -2785,12 +2845,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79554 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
79555
79556 if (copy_in_user(rxnfc, compat_rxnfc,
79557 - (void *)(&rxnfc->fs.m_ext + 1) -
79558 - (void *)rxnfc) ||
79559 + (void __user *)(&rxnfc->fs.m_ext + 1) -
79560 + (void __user *)rxnfc) ||
79561 copy_in_user(&rxnfc->fs.ring_cookie,
79562 &compat_rxnfc->fs.ring_cookie,
79563 - (void *)(&rxnfc->fs.location + 1) -
79564 - (void *)&rxnfc->fs.ring_cookie) ||
79565 + (void __user *)(&rxnfc->fs.location + 1) -
79566 + (void __user *)&rxnfc->fs.ring_cookie) ||
79567 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
79568 sizeof(rxnfc->rule_cnt)))
79569 return -EFAULT;
79570 @@ -2802,12 +2862,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79571
79572 if (convert_out) {
79573 if (copy_in_user(compat_rxnfc, rxnfc,
79574 - (const void *)(&rxnfc->fs.m_ext + 1) -
79575 - (const void *)rxnfc) ||
79576 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
79577 + (const void __user *)rxnfc) ||
79578 copy_in_user(&compat_rxnfc->fs.ring_cookie,
79579 &rxnfc->fs.ring_cookie,
79580 - (const void *)(&rxnfc->fs.location + 1) -
79581 - (const void *)&rxnfc->fs.ring_cookie) ||
79582 + (const void __user *)(&rxnfc->fs.location + 1) -
79583 + (const void __user *)&rxnfc->fs.ring_cookie) ||
79584 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
79585 sizeof(rxnfc->rule_cnt)))
79586 return -EFAULT;
79587 @@ -2877,7 +2937,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
79588 old_fs = get_fs();
79589 set_fs(KERNEL_DS);
79590 err = dev_ioctl(net, cmd,
79591 - (struct ifreq __user __force *) &kifr);
79592 + (struct ifreq __force_user *) &kifr);
79593 set_fs(old_fs);
79594
79595 return err;
79596 @@ -2986,7 +3046,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
79597
79598 old_fs = get_fs();
79599 set_fs(KERNEL_DS);
79600 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
79601 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
79602 set_fs(old_fs);
79603
79604 if (cmd == SIOCGIFMAP && !err) {
79605 @@ -3091,7 +3151,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
79606 ret |= __get_user(rtdev, &(ur4->rt_dev));
79607 if (rtdev) {
79608 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
79609 - r4.rt_dev = (char __user __force *)devname;
79610 + r4.rt_dev = (char __force_user *)devname;
79611 devname[15] = 0;
79612 } else
79613 r4.rt_dev = NULL;
79614 @@ -3317,8 +3377,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
79615 int __user *uoptlen;
79616 int err;
79617
79618 - uoptval = (char __user __force *) optval;
79619 - uoptlen = (int __user __force *) optlen;
79620 + uoptval = (char __force_user *) optval;
79621 + uoptlen = (int __force_user *) optlen;
79622
79623 set_fs(KERNEL_DS);
79624 if (level == SOL_SOCKET)
79625 @@ -3338,7 +3398,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
79626 char __user *uoptval;
79627 int err;
79628
79629 - uoptval = (char __user __force *) optval;
79630 + uoptval = (char __force_user *) optval;
79631
79632 set_fs(KERNEL_DS);
79633 if (level == SOL_SOCKET)
79634 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
79635 index 128494e..775d0e0 100644
79636 --- a/net/sunrpc/sched.c
79637 +++ b/net/sunrpc/sched.c
79638 @@ -240,9 +240,9 @@ static int rpc_wait_bit_killable(void *word)
79639 #ifdef RPC_DEBUG
79640 static void rpc_task_set_debuginfo(struct rpc_task *task)
79641 {
79642 - static atomic_t rpc_pid;
79643 + static atomic_unchecked_t rpc_pid;
79644
79645 - task->tk_pid = atomic_inc_return(&rpc_pid);
79646 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
79647 }
79648 #else
79649 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
79650 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
79651 index 8343737..677025e 100644
79652 --- a/net/sunrpc/xprtrdma/svc_rdma.c
79653 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
79654 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
79655 static unsigned int min_max_inline = 4096;
79656 static unsigned int max_max_inline = 65536;
79657
79658 -atomic_t rdma_stat_recv;
79659 -atomic_t rdma_stat_read;
79660 -atomic_t rdma_stat_write;
79661 -atomic_t rdma_stat_sq_starve;
79662 -atomic_t rdma_stat_rq_starve;
79663 -atomic_t rdma_stat_rq_poll;
79664 -atomic_t rdma_stat_rq_prod;
79665 -atomic_t rdma_stat_sq_poll;
79666 -atomic_t rdma_stat_sq_prod;
79667 +atomic_unchecked_t rdma_stat_recv;
79668 +atomic_unchecked_t rdma_stat_read;
79669 +atomic_unchecked_t rdma_stat_write;
79670 +atomic_unchecked_t rdma_stat_sq_starve;
79671 +atomic_unchecked_t rdma_stat_rq_starve;
79672 +atomic_unchecked_t rdma_stat_rq_poll;
79673 +atomic_unchecked_t rdma_stat_rq_prod;
79674 +atomic_unchecked_t rdma_stat_sq_poll;
79675 +atomic_unchecked_t rdma_stat_sq_prod;
79676
79677 /* Temporary NFS request map and context caches */
79678 struct kmem_cache *svc_rdma_map_cachep;
79679 @@ -110,7 +110,7 @@ static int read_reset_stat(ctl_table *table, int write,
79680 len -= *ppos;
79681 if (len > *lenp)
79682 len = *lenp;
79683 - if (len && copy_to_user(buffer, str_buf, len))
79684 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
79685 return -EFAULT;
79686 *lenp = len;
79687 *ppos += len;
79688 @@ -151,63 +151,63 @@ static ctl_table svcrdma_parm_table[] = {
79689 {
79690 .procname = "rdma_stat_read",
79691 .data = &rdma_stat_read,
79692 - .maxlen = sizeof(atomic_t),
79693 + .maxlen = sizeof(atomic_unchecked_t),
79694 .mode = 0644,
79695 .proc_handler = read_reset_stat,
79696 },
79697 {
79698 .procname = "rdma_stat_recv",
79699 .data = &rdma_stat_recv,
79700 - .maxlen = sizeof(atomic_t),
79701 + .maxlen = sizeof(atomic_unchecked_t),
79702 .mode = 0644,
79703 .proc_handler = read_reset_stat,
79704 },
79705 {
79706 .procname = "rdma_stat_write",
79707 .data = &rdma_stat_write,
79708 - .maxlen = sizeof(atomic_t),
79709 + .maxlen = sizeof(atomic_unchecked_t),
79710 .mode = 0644,
79711 .proc_handler = read_reset_stat,
79712 },
79713 {
79714 .procname = "rdma_stat_sq_starve",
79715 .data = &rdma_stat_sq_starve,
79716 - .maxlen = sizeof(atomic_t),
79717 + .maxlen = sizeof(atomic_unchecked_t),
79718 .mode = 0644,
79719 .proc_handler = read_reset_stat,
79720 },
79721 {
79722 .procname = "rdma_stat_rq_starve",
79723 .data = &rdma_stat_rq_starve,
79724 - .maxlen = sizeof(atomic_t),
79725 + .maxlen = sizeof(atomic_unchecked_t),
79726 .mode = 0644,
79727 .proc_handler = read_reset_stat,
79728 },
79729 {
79730 .procname = "rdma_stat_rq_poll",
79731 .data = &rdma_stat_rq_poll,
79732 - .maxlen = sizeof(atomic_t),
79733 + .maxlen = sizeof(atomic_unchecked_t),
79734 .mode = 0644,
79735 .proc_handler = read_reset_stat,
79736 },
79737 {
79738 .procname = "rdma_stat_rq_prod",
79739 .data = &rdma_stat_rq_prod,
79740 - .maxlen = sizeof(atomic_t),
79741 + .maxlen = sizeof(atomic_unchecked_t),
79742 .mode = 0644,
79743 .proc_handler = read_reset_stat,
79744 },
79745 {
79746 .procname = "rdma_stat_sq_poll",
79747 .data = &rdma_stat_sq_poll,
79748 - .maxlen = sizeof(atomic_t),
79749 + .maxlen = sizeof(atomic_unchecked_t),
79750 .mode = 0644,
79751 .proc_handler = read_reset_stat,
79752 },
79753 {
79754 .procname = "rdma_stat_sq_prod",
79755 .data = &rdma_stat_sq_prod,
79756 - .maxlen = sizeof(atomic_t),
79757 + .maxlen = sizeof(atomic_unchecked_t),
79758 .mode = 0644,
79759 .proc_handler = read_reset_stat,
79760 },
79761 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
79762 index 41cb63b..c4a1489 100644
79763 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
79764 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
79765 @@ -501,7 +501,7 @@ next_sge:
79766 svc_rdma_put_context(ctxt, 0);
79767 goto out;
79768 }
79769 - atomic_inc(&rdma_stat_read);
79770 + atomic_inc_unchecked(&rdma_stat_read);
79771
79772 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
79773 chl_map->ch[ch_no].count -= read_wr.num_sge;
79774 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
79775 dto_q);
79776 list_del_init(&ctxt->dto_q);
79777 } else {
79778 - atomic_inc(&rdma_stat_rq_starve);
79779 + atomic_inc_unchecked(&rdma_stat_rq_starve);
79780 clear_bit(XPT_DATA, &xprt->xpt_flags);
79781 ctxt = NULL;
79782 }
79783 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
79784 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
79785 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
79786 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
79787 - atomic_inc(&rdma_stat_recv);
79788 + atomic_inc_unchecked(&rdma_stat_recv);
79789
79790 /* Build up the XDR from the receive buffers. */
79791 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
79792 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
79793 index 42eb7ba..c887c45 100644
79794 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
79795 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
79796 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
79797 write_wr.wr.rdma.remote_addr = to;
79798
79799 /* Post It */
79800 - atomic_inc(&rdma_stat_write);
79801 + atomic_inc_unchecked(&rdma_stat_write);
79802 if (svc_rdma_send(xprt, &write_wr))
79803 goto err;
79804 return 0;
79805 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
79806 index 73b428b..5f3f8f3 100644
79807 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
79808 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
79809 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
79810 return;
79811
79812 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
79813 - atomic_inc(&rdma_stat_rq_poll);
79814 + atomic_inc_unchecked(&rdma_stat_rq_poll);
79815
79816 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
79817 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
79818 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
79819 }
79820
79821 if (ctxt)
79822 - atomic_inc(&rdma_stat_rq_prod);
79823 + atomic_inc_unchecked(&rdma_stat_rq_prod);
79824
79825 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
79826 /*
79827 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
79828 return;
79829
79830 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
79831 - atomic_inc(&rdma_stat_sq_poll);
79832 + atomic_inc_unchecked(&rdma_stat_sq_poll);
79833 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
79834 if (wc.status != IB_WC_SUCCESS)
79835 /* Close the transport */
79836 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
79837 }
79838
79839 if (ctxt)
79840 - atomic_inc(&rdma_stat_sq_prod);
79841 + atomic_inc_unchecked(&rdma_stat_sq_prod);
79842 }
79843
79844 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
79845 @@ -1266,7 +1266,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
79846 spin_lock_bh(&xprt->sc_lock);
79847 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
79848 spin_unlock_bh(&xprt->sc_lock);
79849 - atomic_inc(&rdma_stat_sq_starve);
79850 + atomic_inc_unchecked(&rdma_stat_sq_starve);
79851
79852 /* See if we can opportunistically reap SQ WR to make room */
79853 sq_cq_reap(xprt);
79854 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
79855 index e3a6e37..be2ea77 100644
79856 --- a/net/sysctl_net.c
79857 +++ b/net/sysctl_net.c
79858 @@ -43,7 +43,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
79859 struct ctl_table *table)
79860 {
79861 /* Allow network administrator to have same access as root. */
79862 - if (capable(CAP_NET_ADMIN)) {
79863 + if (capable_nolog(CAP_NET_ADMIN)) {
79864 int mode = (table->mode >> 6) & 7;
79865 return (mode << 6) | (mode << 3) | mode;
79866 }
79867 diff --git a/net/tipc/link.c b/net/tipc/link.c
79868 index 1c1e615..113e0ae 100644
79869 --- a/net/tipc/link.c
79870 +++ b/net/tipc/link.c
79871 @@ -1171,7 +1171,7 @@ static int link_send_sections_long(struct tipc_port *sender,
79872 struct tipc_msg fragm_hdr;
79873 struct sk_buff *buf, *buf_chain, *prev;
79874 u32 fragm_crs, fragm_rest, hsz, sect_rest;
79875 - const unchar *sect_crs;
79876 + const unchar __user *sect_crs;
79877 int curr_sect;
79878 u32 fragm_no;
79879
79880 @@ -1212,7 +1212,7 @@ again:
79881
79882 if (!sect_rest) {
79883 sect_rest = msg_sect[++curr_sect].iov_len;
79884 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
79885 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
79886 }
79887
79888 if (sect_rest < fragm_rest)
79889 @@ -1231,7 +1231,7 @@ error:
79890 }
79891 } else
79892 skb_copy_to_linear_data_offset(buf, fragm_crs,
79893 - sect_crs, sz);
79894 + (const void __force_kernel *)sect_crs, sz);
79895 sect_crs += sz;
79896 sect_rest -= sz;
79897 fragm_crs += sz;
79898 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
79899 index f2db8a8..9245aa4 100644
79900 --- a/net/tipc/msg.c
79901 +++ b/net/tipc/msg.c
79902 @@ -98,7 +98,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
79903 msg_sect[cnt].iov_len);
79904 else
79905 skb_copy_to_linear_data_offset(*buf, pos,
79906 - msg_sect[cnt].iov_base,
79907 + (const void __force_kernel *)msg_sect[cnt].iov_base,
79908 msg_sect[cnt].iov_len);
79909 pos += msg_sect[cnt].iov_len;
79910 }
79911 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
79912 index 5ed5965..90abe34 100644
79913 --- a/net/tipc/subscr.c
79914 +++ b/net/tipc/subscr.c
79915 @@ -96,7 +96,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
79916 {
79917 struct iovec msg_sect;
79918
79919 - msg_sect.iov_base = (void *)&sub->evt;
79920 + msg_sect.iov_base = (void __force_user *)&sub->evt;
79921 msg_sect.iov_len = sizeof(struct tipc_event);
79922
79923 sub->evt.event = htohl(event, sub->swap);
79924 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
79925 index c5ee4ff..e905948 100644
79926 --- a/net/unix/af_unix.c
79927 +++ b/net/unix/af_unix.c
79928 @@ -789,6 +789,12 @@ static struct sock *unix_find_other(struct net *net,
79929 err = -ECONNREFUSED;
79930 if (!S_ISSOCK(inode->i_mode))
79931 goto put_fail;
79932 +
79933 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
79934 + err = -EACCES;
79935 + goto put_fail;
79936 + }
79937 +
79938 u = unix_find_socket_byinode(inode);
79939 if (!u)
79940 goto put_fail;
79941 @@ -809,6 +815,13 @@ static struct sock *unix_find_other(struct net *net,
79942 if (u) {
79943 struct dentry *dentry;
79944 dentry = unix_sk(u)->path.dentry;
79945 +
79946 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
79947 + err = -EPERM;
79948 + sock_put(u);
79949 + goto fail;
79950 + }
79951 +
79952 if (dentry)
79953 touch_atime(&unix_sk(u)->path);
79954 } else
79955 @@ -842,12 +855,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
79956 */
79957 err = security_path_mknod(&path, dentry, mode, 0);
79958 if (!err) {
79959 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
79960 + err = -EACCES;
79961 + goto out;
79962 + }
79963 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
79964 if (!err) {
79965 res->mnt = mntget(path.mnt);
79966 res->dentry = dget(dentry);
79967 + gr_handle_create(dentry, path.mnt);
79968 }
79969 }
79970 +out:
79971 done_path_create(&path, dentry);
79972 return err;
79973 }
79974 diff --git a/net/wireless/core.h b/net/wireless/core.h
79975 index bc7430b..35349de 100644
79976 --- a/net/wireless/core.h
79977 +++ b/net/wireless/core.h
79978 @@ -28,7 +28,7 @@ struct cfg80211_registered_device {
79979 struct mutex mtx;
79980
79981 /* rfkill support */
79982 - struct rfkill_ops rfkill_ops;
79983 + rfkill_ops_no_const rfkill_ops;
79984 struct rfkill *rfkill;
79985 struct work_struct rfkill_sync;
79986
79987 diff --git a/net/wireless/util.c b/net/wireless/util.c
79988 index 994e2f0..f67aeb1 100644
79989 --- a/net/wireless/util.c
79990 +++ b/net/wireless/util.c
79991 @@ -309,7 +309,7 @@ unsigned int ieee80211_get_hdrlen_from_skb(const struct sk_buff *skb)
79992 }
79993 EXPORT_SYMBOL(ieee80211_get_hdrlen_from_skb);
79994
79995 -static int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr)
79996 +unsigned int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr)
79997 {
79998 int ae = meshhdr->flags & MESH_FLAGS_AE;
79999 /* 7.1.3.5a.2 */
80000 @@ -326,6 +326,7 @@ static int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr)
80001 return 6;
80002 }
80003 }
80004 +EXPORT_SYMBOL(ieee80211_get_mesh_hdrlen);
80005
80006 int ieee80211_data_to_8023(struct sk_buff *skb, const u8 *addr,
80007 enum nl80211_iftype iftype)
80008 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
80009 index b0eb7aa..7d73e82 100644
80010 --- a/net/wireless/wext-core.c
80011 +++ b/net/wireless/wext-core.c
80012 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
80013 */
80014
80015 /* Support for very large requests */
80016 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
80017 - (user_length > descr->max_tokens)) {
80018 + if (user_length > descr->max_tokens) {
80019 /* Allow userspace to GET more than max so
80020 * we can support any size GET requests.
80021 * There is still a limit : -ENOMEM.
80022 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
80023 }
80024 }
80025
80026 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
80027 - /*
80028 - * If this is a GET, but not NOMAX, it means that the extra
80029 - * data is not bounded by userspace, but by max_tokens. Thus
80030 - * set the length to max_tokens. This matches the extra data
80031 - * allocation.
80032 - * The driver should fill it with the number of tokens it
80033 - * provided, and it may check iwp->length rather than having
80034 - * knowledge of max_tokens. If the driver doesn't change the
80035 - * iwp->length, this ioctl just copies back max_token tokens
80036 - * filled with zeroes. Hopefully the driver isn't claiming
80037 - * them to be valid data.
80038 - */
80039 - iwp->length = descr->max_tokens;
80040 - }
80041 -
80042 err = handler(dev, info, (union iwreq_data *) iwp, extra);
80043
80044 iwp->length += essid_compat;
80045 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
80046 index 387848e..a6667a2 100644
80047 --- a/net/xfrm/xfrm_policy.c
80048 +++ b/net/xfrm/xfrm_policy.c
80049 @@ -300,7 +300,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
80050 {
80051 policy->walk.dead = 1;
80052
80053 - atomic_inc(&policy->genid);
80054 + atomic_inc_unchecked(&policy->genid);
80055
80056 if (del_timer(&policy->timer))
80057 xfrm_pol_put(policy);
80058 @@ -584,7 +584,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
80059 hlist_add_head(&policy->bydst, chain);
80060 xfrm_pol_hold(policy);
80061 net->xfrm.policy_count[dir]++;
80062 - atomic_inc(&flow_cache_genid);
80063 + atomic_inc_unchecked(&flow_cache_genid);
80064 rt_genid_bump(net);
80065 if (delpol)
80066 __xfrm_policy_unlink(delpol, dir);
80067 @@ -1533,7 +1533,7 @@ free_dst:
80068 goto out;
80069 }
80070
80071 -static int inline
80072 +static inline int
80073 xfrm_dst_alloc_copy(void **target, const void *src, int size)
80074 {
80075 if (!*target) {
80076 @@ -1545,7 +1545,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
80077 return 0;
80078 }
80079
80080 -static int inline
80081 +static inline int
80082 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
80083 {
80084 #ifdef CONFIG_XFRM_SUB_POLICY
80085 @@ -1557,7 +1557,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
80086 #endif
80087 }
80088
80089 -static int inline
80090 +static inline int
80091 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
80092 {
80093 #ifdef CONFIG_XFRM_SUB_POLICY
80094 @@ -1651,7 +1651,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
80095
80096 xdst->num_pols = num_pols;
80097 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
80098 - xdst->policy_genid = atomic_read(&pols[0]->genid);
80099 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
80100
80101 return xdst;
80102 }
80103 @@ -2352,7 +2352,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
80104 if (xdst->xfrm_genid != dst->xfrm->genid)
80105 return 0;
80106 if (xdst->num_pols > 0 &&
80107 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
80108 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
80109 return 0;
80110
80111 mtu = dst_mtu(dst->child);
80112 @@ -2891,7 +2891,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
80113 sizeof(pol->xfrm_vec[i].saddr));
80114 pol->xfrm_vec[i].encap_family = mp->new_family;
80115 /* flush bundles */
80116 - atomic_inc(&pol->genid);
80117 + atomic_inc_unchecked(&pol->genid);
80118 }
80119 }
80120
80121 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
80122 index ff1720d..ed8475e 100644
80123 --- a/scripts/Makefile.build
80124 +++ b/scripts/Makefile.build
80125 @@ -111,7 +111,7 @@ endif
80126 endif
80127
80128 # Do not include host rules unless needed
80129 -ifneq ($(hostprogs-y)$(hostprogs-m),)
80130 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
80131 include scripts/Makefile.host
80132 endif
80133
80134 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
80135 index 686cb0d..9d653bf 100644
80136 --- a/scripts/Makefile.clean
80137 +++ b/scripts/Makefile.clean
80138 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
80139 __clean-files := $(extra-y) $(always) \
80140 $(targets) $(clean-files) \
80141 $(host-progs) \
80142 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
80143 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
80144 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
80145
80146 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
80147
80148 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
80149 index 1ac414f..38575f7 100644
80150 --- a/scripts/Makefile.host
80151 +++ b/scripts/Makefile.host
80152 @@ -31,6 +31,8 @@
80153 # Note: Shared libraries consisting of C++ files are not supported
80154
80155 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
80156 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
80157 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
80158
80159 # C code
80160 # Executables compiled from a single .c file
80161 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
80162 # Shared libaries (only .c supported)
80163 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
80164 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
80165 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
80166 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
80167 # Remove .so files from "xxx-objs"
80168 host-cobjs := $(filter-out %.so,$(host-cobjs))
80169 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
80170
80171 -#Object (.o) files used by the shared libaries
80172 +# Object (.o) files used by the shared libaries
80173 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
80174 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
80175
80176 # output directory for programs/.o files
80177 # hostprogs-y := tools/build may have been specified. Retrieve directory
80178 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
80179 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
80180 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
80181 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
80182 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
80183 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
80184 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
80185 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
80186
80187 obj-dirs += $(host-objdirs)
80188 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
80189 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
80190 $(call if_changed_dep,host-cshobjs)
80191
80192 +# Compile .c file, create position independent .o file
80193 +# host-cxxshobjs -> .o
80194 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
80195 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
80196 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
80197 + $(call if_changed_dep,host-cxxshobjs)
80198 +
80199 # Link a shared library, based on position independent .o files
80200 # *.o -> .so shared library (host-cshlib)
80201 quiet_cmd_host-cshlib = HOSTLLD -shared $@
80202 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
80203 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
80204 $(call if_changed,host-cshlib)
80205
80206 +# Link a shared library, based on position independent .o files
80207 +# *.o -> .so shared library (host-cxxshlib)
80208 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
80209 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
80210 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
80211 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
80212 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
80213 + $(call if_changed,host-cxxshlib)
80214 +
80215 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
80216 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
80217 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
80218
80219 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
80220 index cb1f50c..cef2a7c 100644
80221 --- a/scripts/basic/fixdep.c
80222 +++ b/scripts/basic/fixdep.c
80223 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
80224 /*
80225 * Lookup a value in the configuration string.
80226 */
80227 -static int is_defined_config(const char *name, int len, unsigned int hash)
80228 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
80229 {
80230 struct item *aux;
80231
80232 @@ -211,10 +211,10 @@ static void clear_config(void)
80233 /*
80234 * Record the use of a CONFIG_* word.
80235 */
80236 -static void use_config(const char *m, int slen)
80237 +static void use_config(const char *m, unsigned int slen)
80238 {
80239 unsigned int hash = strhash(m, slen);
80240 - int c, i;
80241 + unsigned int c, i;
80242
80243 if (is_defined_config(m, slen, hash))
80244 return;
80245 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
80246
80247 static void parse_config_file(const char *map, size_t len)
80248 {
80249 - const int *end = (const int *) (map + len);
80250 + const unsigned int *end = (const unsigned int *) (map + len);
80251 /* start at +1, so that p can never be < map */
80252 - const int *m = (const int *) map + 1;
80253 + const unsigned int *m = (const unsigned int *) map + 1;
80254 const char *p, *q;
80255
80256 for (; m < end; m++) {
80257 @@ -406,7 +406,7 @@ static void print_deps(void)
80258 static void traps(void)
80259 {
80260 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
80261 - int *p = (int *)test;
80262 + unsigned int *p = (unsigned int *)test;
80263
80264 if (*p != INT_CONF) {
80265 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
80266 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
80267 new file mode 100644
80268 index 0000000..008ac1a
80269 --- /dev/null
80270 +++ b/scripts/gcc-plugin.sh
80271 @@ -0,0 +1,17 @@
80272 +#!/bin/bash
80273 +plugincc=`$1 -x c -shared - -o /dev/null -I\`$3 -print-file-name=plugin\`/include 2>&1 <<EOF
80274 +#include "gcc-plugin.h"
80275 +#include "tree.h"
80276 +#include "tm.h"
80277 +#include "rtl.h"
80278 +#ifdef ENABLE_BUILD_WITH_CXX
80279 +#warning $2
80280 +#else
80281 +#warning $1
80282 +#endif
80283 +EOF`
80284 +if [ $? -eq 0 ]
80285 +then
80286 + [[ "$plugincc" =~ "$1" ]] && echo "$1"
80287 + [[ "$plugincc" =~ "$2" ]] && echo "$2"
80288 +fi
80289 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
80290 index b3d907e..a4782ab 100644
80291 --- a/scripts/link-vmlinux.sh
80292 +++ b/scripts/link-vmlinux.sh
80293 @@ -152,7 +152,7 @@ else
80294 fi;
80295
80296 # final build of init/
80297 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
80298 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
80299
80300 kallsymso=""
80301 kallsyms_vmlinux=""
80302 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
80303 index 7ed6864..b6e90e6 100644
80304 --- a/scripts/mod/file2alias.c
80305 +++ b/scripts/mod/file2alias.c
80306 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
80307 unsigned long size, unsigned long id_size,
80308 void *symval)
80309 {
80310 - int i;
80311 + unsigned int i;
80312
80313 if (size % id_size || size < id_size) {
80314 if (cross_build != 0)
80315 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
80316 /* USB is special because the bcdDevice can be matched against a numeric range */
80317 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
80318 static void do_usb_entry(struct usb_device_id *id,
80319 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
80320 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
80321 unsigned char range_lo, unsigned char range_hi,
80322 unsigned char max, struct module *mod)
80323 {
80324 @@ -262,7 +262,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
80325 {
80326 unsigned int devlo, devhi;
80327 unsigned char chi, clo, max;
80328 - int ndigits;
80329 + unsigned int ndigits;
80330
80331 id->match_flags = TO_NATIVE(id->match_flags);
80332 id->idVendor = TO_NATIVE(id->idVendor);
80333 @@ -507,7 +507,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
80334 for (i = 0; i < count; i++) {
80335 const char *id = (char *)devs[i].id;
80336 char acpi_id[sizeof(devs[0].id)];
80337 - int j;
80338 + unsigned int j;
80339
80340 buf_printf(&mod->dev_table_buf,
80341 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
80342 @@ -537,7 +537,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
80343
80344 for (j = 0; j < PNP_MAX_DEVICES; j++) {
80345 const char *id = (char *)card->devs[j].id;
80346 - int i2, j2;
80347 + unsigned int i2, j2;
80348 int dup = 0;
80349
80350 if (!id[0])
80351 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
80352 /* add an individual alias for every device entry */
80353 if (!dup) {
80354 char acpi_id[sizeof(card->devs[0].id)];
80355 - int k;
80356 + unsigned int k;
80357
80358 buf_printf(&mod->dev_table_buf,
80359 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
80360 @@ -888,7 +888,7 @@ static void dmi_ascii_filter(char *d, const char *s)
80361 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
80362 char *alias)
80363 {
80364 - int i, j;
80365 + unsigned int i, j;
80366
80367 sprintf(alias, "dmi*");
80368
80369 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
80370 index 68e9f5e..ac7759b 100644
80371 --- a/scripts/mod/modpost.c
80372 +++ b/scripts/mod/modpost.c
80373 @@ -930,6 +930,7 @@ enum mismatch {
80374 ANY_INIT_TO_ANY_EXIT,
80375 ANY_EXIT_TO_ANY_INIT,
80376 EXPORT_TO_INIT_EXIT,
80377 + DATA_TO_TEXT
80378 };
80379
80380 struct sectioncheck {
80381 @@ -1044,6 +1045,12 @@ const struct sectioncheck sectioncheck[] = {
80382 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
80383 .mismatch = EXPORT_TO_INIT_EXIT,
80384 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
80385 +},
80386 +/* Do not reference code from writable data */
80387 +{
80388 + .fromsec = { DATA_SECTIONS, NULL },
80389 + .tosec = { TEXT_SECTIONS, NULL },
80390 + .mismatch = DATA_TO_TEXT
80391 }
80392 };
80393
80394 @@ -1166,10 +1173,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
80395 continue;
80396 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
80397 continue;
80398 - if (sym->st_value == addr)
80399 - return sym;
80400 /* Find a symbol nearby - addr are maybe negative */
80401 d = sym->st_value - addr;
80402 + if (d == 0)
80403 + return sym;
80404 if (d < 0)
80405 d = addr - sym->st_value;
80406 if (d < distance) {
80407 @@ -1448,6 +1455,14 @@ static void report_sec_mismatch(const char *modname,
80408 tosym, prl_to, prl_to, tosym);
80409 free(prl_to);
80410 break;
80411 + case DATA_TO_TEXT:
80412 +#if 0
80413 + fprintf(stderr,
80414 + "The %s %s:%s references\n"
80415 + "the %s %s:%s%s\n",
80416 + from, fromsec, fromsym, to, tosec, tosym, to_p);
80417 +#endif
80418 + break;
80419 }
80420 fprintf(stderr, "\n");
80421 }
80422 @@ -1682,7 +1697,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
80423 static void check_sec_ref(struct module *mod, const char *modname,
80424 struct elf_info *elf)
80425 {
80426 - int i;
80427 + unsigned int i;
80428 Elf_Shdr *sechdrs = elf->sechdrs;
80429
80430 /* Walk through all sections */
80431 @@ -1780,7 +1795,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
80432 va_end(ap);
80433 }
80434
80435 -void buf_write(struct buffer *buf, const char *s, int len)
80436 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
80437 {
80438 if (buf->size - buf->pos < len) {
80439 buf->size += len + SZ;
80440 @@ -1998,7 +2013,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
80441 if (fstat(fileno(file), &st) < 0)
80442 goto close_write;
80443
80444 - if (st.st_size != b->pos)
80445 + if (st.st_size != (off_t)b->pos)
80446 goto close_write;
80447
80448 tmp = NOFAIL(malloc(b->pos));
80449 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
80450 index 51207e4..f7d603d 100644
80451 --- a/scripts/mod/modpost.h
80452 +++ b/scripts/mod/modpost.h
80453 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
80454
80455 struct buffer {
80456 char *p;
80457 - int pos;
80458 - int size;
80459 + unsigned int pos;
80460 + unsigned int size;
80461 };
80462
80463 void __attribute__((format(printf, 2, 3)))
80464 buf_printf(struct buffer *buf, const char *fmt, ...);
80465
80466 void
80467 -buf_write(struct buffer *buf, const char *s, int len);
80468 +buf_write(struct buffer *buf, const char *s, unsigned int len);
80469
80470 struct module {
80471 struct module *next;
80472 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
80473 index 9dfcd6d..099068e 100644
80474 --- a/scripts/mod/sumversion.c
80475 +++ b/scripts/mod/sumversion.c
80476 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
80477 goto out;
80478 }
80479
80480 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
80481 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
80482 warn("writing sum in %s failed: %s\n",
80483 filename, strerror(errno));
80484 goto out;
80485 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
80486 index 5c11312..72742b5 100644
80487 --- a/scripts/pnmtologo.c
80488 +++ b/scripts/pnmtologo.c
80489 @@ -237,14 +237,14 @@ static void write_header(void)
80490 fprintf(out, " * Linux logo %s\n", logoname);
80491 fputs(" */\n\n", out);
80492 fputs("#include <linux/linux_logo.h>\n\n", out);
80493 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
80494 + fprintf(out, "static unsigned char %s_data[] = {\n",
80495 logoname);
80496 }
80497
80498 static void write_footer(void)
80499 {
80500 fputs("\n};\n\n", out);
80501 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
80502 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
80503 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
80504 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
80505 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
80506 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
80507 fputs("\n};\n\n", out);
80508
80509 /* write logo clut */
80510 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
80511 + fprintf(out, "static unsigned char %s_clut[] = {\n",
80512 logoname);
80513 write_hex_cnt = 0;
80514 for (i = 0; i < logo_clutsize; i++) {
80515 diff --git a/security/Kconfig b/security/Kconfig
80516 index e9c6ac7..e7feb0d 100644
80517 --- a/security/Kconfig
80518 +++ b/security/Kconfig
80519 @@ -4,6 +4,896 @@
80520
80521 menu "Security options"
80522
80523 +menu "Grsecurity"
80524 +
80525 + config ARCH_TRACK_EXEC_LIMIT
80526 + bool
80527 +
80528 + config PAX_KERNEXEC_PLUGIN
80529 + bool
80530 +
80531 + config PAX_PER_CPU_PGD
80532 + bool
80533 +
80534 + config TASK_SIZE_MAX_SHIFT
80535 + int
80536 + depends on X86_64
80537 + default 47 if !PAX_PER_CPU_PGD
80538 + default 42 if PAX_PER_CPU_PGD
80539 +
80540 + config PAX_ENABLE_PAE
80541 + bool
80542 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
80543 +
80544 + config PAX_USERCOPY_SLABS
80545 + bool
80546 +
80547 +config GRKERNSEC
80548 + bool "Grsecurity"
80549 + select CRYPTO
80550 + select CRYPTO_SHA256
80551 + select PROC_FS
80552 + select STOP_MACHINE
80553 + help
80554 + If you say Y here, you will be able to configure many features
80555 + that will enhance the security of your system. It is highly
80556 + recommended that you say Y here and read through the help
80557 + for each option so that you fully understand the features and
80558 + can evaluate their usefulness for your machine.
80559 +
80560 +choice
80561 + prompt "Configuration Method"
80562 + depends on GRKERNSEC
80563 + default GRKERNSEC_CONFIG_CUSTOM
80564 + help
80565 +
80566 +config GRKERNSEC_CONFIG_AUTO
80567 + bool "Automatic"
80568 + help
80569 + If you choose this configuration method, you'll be able to answer a small
80570 + number of simple questions about how you plan to use this kernel.
80571 + The settings of grsecurity and PaX will be automatically configured for
80572 + the highest commonly-used settings within the provided constraints.
80573 +
80574 + If you require additional configuration, custom changes can still be made
80575 + from the "custom configuration" menu.
80576 +
80577 +config GRKERNSEC_CONFIG_CUSTOM
80578 + bool "Custom"
80579 + help
80580 + If you choose this configuration method, you'll be able to configure all
80581 + grsecurity and PaX settings manually. Via this method, no options are
80582 + automatically enabled.
80583 +
80584 +endchoice
80585 +
80586 +choice
80587 + prompt "Usage Type"
80588 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
80589 + default GRKERNSEC_CONFIG_SERVER
80590 + help
80591 +
80592 +config GRKERNSEC_CONFIG_SERVER
80593 + bool "Server"
80594 + help
80595 + Choose this option if you plan to use this kernel on a server.
80596 +
80597 +config GRKERNSEC_CONFIG_DESKTOP
80598 + bool "Desktop"
80599 + help
80600 + Choose this option if you plan to use this kernel on a desktop.
80601 +
80602 +endchoice
80603 +
80604 +choice
80605 + prompt "Virtualization Type"
80606 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
80607 + default GRKERNSEC_CONFIG_VIRT_NONE
80608 + help
80609 +
80610 +config GRKERNSEC_CONFIG_VIRT_NONE
80611 + bool "None"
80612 + help
80613 + Choose this option if this kernel will be run on bare metal.
80614 +
80615 +config GRKERNSEC_CONFIG_VIRT_GUEST
80616 + bool "Guest"
80617 + help
80618 + Choose this option if this kernel will be run as a VM guest.
80619 +
80620 +config GRKERNSEC_CONFIG_VIRT_HOST
80621 + bool "Host"
80622 + help
80623 + Choose this option if this kernel will be run as a VM host.
80624 +
80625 +endchoice
80626 +
80627 +choice
80628 + prompt "Virtualization Hardware"
80629 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
80630 + help
80631 +
80632 +config GRKERNSEC_CONFIG_VIRT_EPT
80633 + bool "EPT/RVI Processor Support"
80634 + depends on X86
80635 + help
80636 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
80637 + hardware virtualization. This allows for additional kernel hardening protections
80638 + to operate without additional performance impact.
80639 +
80640 + To see if your Intel processor supports EPT, see:
80641 + http://ark.intel.com/Products/VirtualizationTechnology
80642 + (Most Core i3/5/7 support EPT)
80643 +
80644 + To see if your AMD processor supports RVI, see:
80645 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
80646 +
80647 +config GRKERNSEC_CONFIG_VIRT_SOFT
80648 + bool "First-gen/No Hardware Virtualization"
80649 + help
80650 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
80651 + support hardware virtualization or doesn't support the EPT/RVI extensions.
80652 +
80653 +endchoice
80654 +
80655 +choice
80656 + prompt "Virtualization Software"
80657 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
80658 + help
80659 +
80660 +config GRKERNSEC_CONFIG_VIRT_XEN
80661 + bool "Xen"
80662 + help
80663 + Choose this option if this kernel is running as a Xen guest or host.
80664 +
80665 +config GRKERNSEC_CONFIG_VIRT_VMWARE
80666 + bool "VMWare"
80667 + help
80668 + Choose this option if this kernel is running as a VMWare guest or host.
80669 +
80670 +config GRKERNSEC_CONFIG_VIRT_KVM
80671 + bool "KVM"
80672 + help
80673 + Choose this option if this kernel is running as a KVM guest or host.
80674 +
80675 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
80676 + bool "VirtualBox"
80677 + help
80678 + Choose this option if this kernel is running as a VirtualBox guest or host.
80679 +
80680 +endchoice
80681 +
80682 +choice
80683 + prompt "Required Priorities"
80684 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
80685 + default GRKERNSEC_CONFIG_PRIORITY_PERF
80686 + help
80687 +
80688 +config GRKERNSEC_CONFIG_PRIORITY_PERF
80689 + bool "Performance"
80690 + help
80691 + Choose this option if performance is of highest priority for this deployment
80692 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
80693 + and freed memory sanitizing will be disabled.
80694 +
80695 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
80696 + bool "Security"
80697 + help
80698 + Choose this option if security is of highest priority for this deployment of
80699 + grsecurity. UDEREF, kernel stack clearing, and freed memory sanitizing will
80700 + be enabled for this kernel. In a worst-case scenario, these features can
80701 + introduce a 20% performance hit (UDEREF on x64 contributing half of this hit).
80702 +
80703 +endchoice
80704 +
80705 +menu "Default Special Groups"
80706 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
80707 +
80708 +config GRKERNSEC_PROC_GID
80709 + int "GID exempted from /proc restrictions"
80710 + default 1001
80711 + help
80712 + Setting this GID determines which group will be exempted from
80713 + grsecurity's /proc restrictions, allowing users of the specified
80714 + group to view network statistics and the existence of other users'
80715 + processes on the system. This GID may also be chosen at boot time
80716 + via "grsec_proc_gid=" on the kernel commandline.
80717 +
80718 +config GRKERNSEC_TPE_UNTRUSTED_GID
80719 + int "GID for TPE-untrusted users"
80720 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
80721 + default 1005
80722 + help
80723 + Setting this GID determines which group untrusted users should
80724 + be added to. These users will be placed under grsecurity's Trusted Path
80725 + Execution mechanism, preventing them from executing their own binaries.
80726 + The users will only be able to execute binaries in directories owned and
80727 + writable only by the root user. If the sysctl option is enabled, a sysctl
80728 + option with name "tpe_gid" is created.
80729 +
80730 +config GRKERNSEC_TPE_TRUSTED_GID
80731 + int "GID for TPE-trusted users"
80732 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
80733 + default 1005
80734 + help
80735 + Setting this GID determines what group TPE restrictions will be
80736 + *disabled* for. If the sysctl option is enabled, a sysctl option
80737 + with name "tpe_gid" is created.
80738 +
80739 +config GRKERNSEC_SYMLINKOWN_GID
80740 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
80741 + depends on GRKERNSEC_CONFIG_SERVER
80742 + default 1006
80743 + help
80744 + Setting this GID determines what group kernel-enforced
80745 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
80746 + is enabled, a sysctl option with name "symlinkown_gid" is created.
80747 +
80748 +
80749 +endmenu
80750 +
80751 +menu "Customize Configuration"
80752 +depends on GRKERNSEC
80753 +
80754 +menu "PaX"
80755 +
80756 +config PAX
80757 + bool "Enable various PaX features"
80758 + default y if GRKERNSEC_CONFIG_AUTO
80759 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
80760 + help
80761 + This allows you to enable various PaX features. PaX adds
80762 + intrusion prevention mechanisms to the kernel that reduce
80763 + the risks posed by exploitable memory corruption bugs.
80764 +
80765 +menu "PaX Control"
80766 + depends on PAX
80767 +
80768 +config PAX_SOFTMODE
80769 + bool 'Support soft mode'
80770 + help
80771 + Enabling this option will allow you to run PaX in soft mode, that
80772 + is, PaX features will not be enforced by default, only on executables
80773 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
80774 + support as they are the only way to mark executables for soft mode use.
80775 +
80776 + Soft mode can be activated by using the "pax_softmode=1" kernel command
80777 + line option on boot. Furthermore you can control various PaX features
80778 + at runtime via the entries in /proc/sys/kernel/pax.
80779 +
80780 +config PAX_EI_PAX
80781 + bool 'Use legacy ELF header marking'
80782 + default y if GRKERNSEC_CONFIG_AUTO
80783 + help
80784 + Enabling this option will allow you to control PaX features on
80785 + a per executable basis via the 'chpax' utility available at
80786 + http://pax.grsecurity.net/. The control flags will be read from
80787 + an otherwise reserved part of the ELF header. This marking has
80788 + numerous drawbacks (no support for soft-mode, toolchain does not
80789 + know about the non-standard use of the ELF header) therefore it
80790 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
80791 + support.
80792 +
80793 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
80794 + support as well, they will override the legacy EI_PAX marks.
80795 +
80796 + If you enable none of the marking options then all applications
80797 + will run with PaX enabled on them by default.
80798 +
80799 +config PAX_PT_PAX_FLAGS
80800 + bool 'Use ELF program header marking'
80801 + default y if GRKERNSEC_CONFIG_AUTO
80802 + help
80803 + Enabling this option will allow you to control PaX features on
80804 + a per executable basis via the 'paxctl' utility available at
80805 + http://pax.grsecurity.net/. The control flags will be read from
80806 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
80807 + has the benefits of supporting both soft mode and being fully
80808 + integrated into the toolchain (the binutils patch is available
80809 + from http://pax.grsecurity.net).
80810 +
80811 + Note that if you enable the legacy EI_PAX marking support as well,
80812 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
80813 +
80814 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
80815 + must make sure that the marks are the same if a binary has both marks.
80816 +
80817 + If you enable none of the marking options then all applications
80818 + will run with PaX enabled on them by default.
80819 +
80820 +config PAX_XATTR_PAX_FLAGS
80821 + bool 'Use filesystem extended attributes marking'
80822 + default y if GRKERNSEC_CONFIG_AUTO
80823 + select CIFS_XATTR if CIFS
80824 + select EXT2_FS_XATTR if EXT2_FS
80825 + select EXT3_FS_XATTR if EXT3_FS
80826 + select EXT4_FS_XATTR if EXT4_FS
80827 + select JFFS2_FS_XATTR if JFFS2_FS
80828 + select REISERFS_FS_XATTR if REISERFS_FS
80829 + select SQUASHFS_XATTR if SQUASHFS
80830 + select TMPFS_XATTR if TMPFS
80831 + select UBIFS_FS_XATTR if UBIFS_FS
80832 + help
80833 + Enabling this option will allow you to control PaX features on
80834 + a per executable basis via the 'setfattr' utility. The control
80835 + flags will be read from the user.pax.flags extended attribute of
80836 + the file. This marking has the benefit of supporting binary-only
80837 + applications that self-check themselves (e.g., skype) and would
80838 + not tolerate chpax/paxctl changes. The main drawback is that
80839 + extended attributes are not supported by some filesystems (e.g.,
80840 + isofs, udf, vfat) so copying files through such filesystems will
80841 + lose the extended attributes and these PaX markings.
80842 +
80843 + Note that if you enable the legacy EI_PAX marking support as well,
80844 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
80845 +
80846 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
80847 + must make sure that the marks are the same if a binary has both marks.
80848 +
80849 + If you enable none of the marking options then all applications
80850 + will run with PaX enabled on them by default.
80851 +
80852 +choice
80853 + prompt 'MAC system integration'
80854 + default PAX_HAVE_ACL_FLAGS
80855 + help
80856 + Mandatory Access Control systems have the option of controlling
80857 + PaX flags on a per executable basis, choose the method supported
80858 + by your particular system.
80859 +
80860 + - "none": if your MAC system does not interact with PaX,
80861 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
80862 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
80863 +
80864 + NOTE: this option is for developers/integrators only.
80865 +
80866 + config PAX_NO_ACL_FLAGS
80867 + bool 'none'
80868 +
80869 + config PAX_HAVE_ACL_FLAGS
80870 + bool 'direct'
80871 +
80872 + config PAX_HOOK_ACL_FLAGS
80873 + bool 'hook'
80874 +endchoice
80875 +
80876 +endmenu
80877 +
80878 +menu "Non-executable pages"
80879 + depends on PAX
80880 +
80881 +config PAX_NOEXEC
80882 + bool "Enforce non-executable pages"
80883 + default y if GRKERNSEC_CONFIG_AUTO
80884 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
80885 + help
80886 + By design some architectures do not allow for protecting memory
80887 + pages against execution or even if they do, Linux does not make
80888 + use of this feature. In practice this means that if a page is
80889 + readable (such as the stack or heap) it is also executable.
80890 +
80891 + There is a well known exploit technique that makes use of this
80892 + fact and a common programming mistake where an attacker can
80893 + introduce code of his choice somewhere in the attacked program's
80894 + memory (typically the stack or the heap) and then execute it.
80895 +
80896 + If the attacked program was running with different (typically
80897 + higher) privileges than that of the attacker, then he can elevate
80898 + his own privilege level (e.g. get a root shell, write to files for
80899 + which he does not have write access to, etc).
80900 +
80901 + Enabling this option will let you choose from various features
80902 + that prevent the injection and execution of 'foreign' code in
80903 + a program.
80904 +
80905 + This will also break programs that rely on the old behaviour and
80906 + expect that dynamically allocated memory via the malloc() family
80907 + of functions is executable (which it is not). Notable examples
80908 + are the XFree86 4.x server, the java runtime and wine.
80909 +
80910 +config PAX_PAGEEXEC
80911 + bool "Paging based non-executable pages"
80912 + default y if GRKERNSEC_CONFIG_AUTO
80913 + 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)
80914 + select S390_SWITCH_AMODE if S390
80915 + select S390_EXEC_PROTECT if S390
80916 + select ARCH_TRACK_EXEC_LIMIT if X86_32
80917 + help
80918 + This implementation is based on the paging feature of the CPU.
80919 + On i386 without hardware non-executable bit support there is a
80920 + variable but usually low performance impact, however on Intel's
80921 + P4 core based CPUs it is very high so you should not enable this
80922 + for kernels meant to be used on such CPUs.
80923 +
80924 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
80925 + with hardware non-executable bit support there is no performance
80926 + impact, on ppc the impact is negligible.
80927 +
80928 + Note that several architectures require various emulations due to
80929 + badly designed userland ABIs, this will cause a performance impact
80930 + but will disappear as soon as userland is fixed. For example, ppc
80931 + userland MUST have been built with secure-plt by a recent toolchain.
80932 +
80933 +config PAX_SEGMEXEC
80934 + bool "Segmentation based non-executable pages"
80935 + default y if GRKERNSEC_CONFIG_AUTO
80936 + depends on PAX_NOEXEC && X86_32
80937 + help
80938 + This implementation is based on the segmentation feature of the
80939 + CPU and has a very small performance impact, however applications
80940 + will be limited to a 1.5 GB address space instead of the normal
80941 + 3 GB.
80942 +
80943 +config PAX_EMUTRAMP
80944 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
80945 + default y if PARISC
80946 + help
80947 + There are some programs and libraries that for one reason or
80948 + another attempt to execute special small code snippets from
80949 + non-executable memory pages. Most notable examples are the
80950 + signal handler return code generated by the kernel itself and
80951 + the GCC trampolines.
80952 +
80953 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
80954 + such programs will no longer work under your kernel.
80955 +
80956 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
80957 + utilities to enable trampoline emulation for the affected programs
80958 + yet still have the protection provided by the non-executable pages.
80959 +
80960 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
80961 + your system will not even boot.
80962 +
80963 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
80964 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
80965 + for the affected files.
80966 +
80967 + NOTE: enabling this feature *may* open up a loophole in the
80968 + protection provided by non-executable pages that an attacker
80969 + could abuse. Therefore the best solution is to not have any
80970 + files on your system that would require this option. This can
80971 + be achieved by not using libc5 (which relies on the kernel
80972 + signal handler return code) and not using or rewriting programs
80973 + that make use of the nested function implementation of GCC.
80974 + Skilled users can just fix GCC itself so that it implements
80975 + nested function calls in a way that does not interfere with PaX.
80976 +
80977 +config PAX_EMUSIGRT
80978 + bool "Automatically emulate sigreturn trampolines"
80979 + depends on PAX_EMUTRAMP && PARISC
80980 + default y
80981 + help
80982 + Enabling this option will have the kernel automatically detect
80983 + and emulate signal return trampolines executing on the stack
80984 + that would otherwise lead to task termination.
80985 +
80986 + This solution is intended as a temporary one for users with
80987 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
80988 + Modula-3 runtime, etc) or executables linked to such, basically
80989 + everything that does not specify its own SA_RESTORER function in
80990 + normal executable memory like glibc 2.1+ does.
80991 +
80992 + On parisc you MUST enable this option, otherwise your system will
80993 + not even boot.
80994 +
80995 + NOTE: this feature cannot be disabled on a per executable basis
80996 + and since it *does* open up a loophole in the protection provided
80997 + by non-executable pages, the best solution is to not have any
80998 + files on your system that would require this option.
80999 +
81000 +config PAX_MPROTECT
81001 + bool "Restrict mprotect()"
81002 + default y if GRKERNSEC_CONFIG_AUTO
81003 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
81004 + help
81005 + Enabling this option will prevent programs from
81006 + - changing the executable status of memory pages that were
81007 + not originally created as executable,
81008 + - making read-only executable pages writable again,
81009 + - creating executable pages from anonymous memory,
81010 + - making read-only-after-relocations (RELRO) data pages writable again.
81011 +
81012 + You should say Y here to complete the protection provided by
81013 + the enforcement of non-executable pages.
81014 +
81015 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
81016 + this feature on a per file basis.
81017 +
81018 +config PAX_MPROTECT_COMPAT
81019 + bool "Use legacy/compat protection demoting (read help)"
81020 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
81021 + depends on PAX_MPROTECT
81022 + help
81023 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
81024 + by sending the proper error code to the application. For some broken
81025 + userland, this can cause problems with Python or other applications. The
81026 + current implementation however allows for applications like clamav to
81027 + detect if JIT compilation/execution is allowed and to fall back gracefully
81028 + to an interpreter-based mode if it does not. While we encourage everyone
81029 + to use the current implementation as-is and push upstream to fix broken
81030 + userland (note that the RWX logging option can assist with this), in some
81031 + environments this may not be possible. Having to disable MPROTECT
81032 + completely on certain binaries reduces the security benefit of PaX,
81033 + so this option is provided for those environments to revert to the old
81034 + behavior.
81035 +
81036 +config PAX_ELFRELOCS
81037 + bool "Allow ELF text relocations (read help)"
81038 + depends on PAX_MPROTECT
81039 + default n
81040 + help
81041 + Non-executable pages and mprotect() restrictions are effective
81042 + in preventing the introduction of new executable code into an
81043 + attacked task's address space. There remain only two venues
81044 + for this kind of attack: if the attacker can execute already
81045 + existing code in the attacked task then he can either have it
81046 + create and mmap() a file containing his code or have it mmap()
81047 + an already existing ELF library that does not have position
81048 + independent code in it and use mprotect() on it to make it
81049 + writable and copy his code there. While protecting against
81050 + the former approach is beyond PaX, the latter can be prevented
81051 + by having only PIC ELF libraries on one's system (which do not
81052 + need to relocate their code). If you are sure this is your case,
81053 + as is the case with all modern Linux distributions, then leave
81054 + this option disabled. You should say 'n' here.
81055 +
81056 +config PAX_ETEXECRELOCS
81057 + bool "Allow ELF ET_EXEC text relocations"
81058 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
81059 + select PAX_ELFRELOCS
81060 + default y
81061 + help
81062 + On some architectures there are incorrectly created applications
81063 + that require text relocations and would not work without enabling
81064 + this option. If you are an alpha, ia64 or parisc user, you should
81065 + enable this option and disable it once you have made sure that
81066 + none of your applications need it.
81067 +
81068 +config PAX_EMUPLT
81069 + bool "Automatically emulate ELF PLT"
81070 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
81071 + default y
81072 + help
81073 + Enabling this option will have the kernel automatically detect
81074 + and emulate the Procedure Linkage Table entries in ELF files.
81075 + On some architectures such entries are in writable memory, and
81076 + become non-executable leading to task termination. Therefore
81077 + it is mandatory that you enable this option on alpha, parisc,
81078 + sparc and sparc64, otherwise your system would not even boot.
81079 +
81080 + NOTE: this feature *does* open up a loophole in the protection
81081 + provided by the non-executable pages, therefore the proper
81082 + solution is to modify the toolchain to produce a PLT that does
81083 + not need to be writable.
81084 +
81085 +config PAX_DLRESOLVE
81086 + bool 'Emulate old glibc resolver stub'
81087 + depends on PAX_EMUPLT && SPARC
81088 + default n
81089 + help
81090 + This option is needed if userland has an old glibc (before 2.4)
81091 + that puts a 'save' instruction into the runtime generated resolver
81092 + stub that needs special emulation.
81093 +
81094 +config PAX_KERNEXEC
81095 + bool "Enforce non-executable kernel pages"
81096 + 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))
81097 + depends on (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
81098 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
81099 + select PAX_KERNEXEC_PLUGIN if X86_64
81100 + help
81101 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
81102 + that is, enabling this option will make it harder to inject
81103 + and execute 'foreign' code in kernel memory itself.
81104 +
81105 +choice
81106 + prompt "Return Address Instrumentation Method"
81107 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
81108 + depends on PAX_KERNEXEC_PLUGIN
81109 + help
81110 + Select the method used to instrument function pointer dereferences.
81111 + Note that binary modules cannot be instrumented by this approach.
81112 +
81113 + Note that the implementation requires a gcc with plugin support,
81114 + i.e., gcc 4.5 or newer. You may need to install the supporting
81115 + headers explicitly in addition to the normal gcc package.
81116 +
81117 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
81118 + bool "bts"
81119 + help
81120 + This method is compatible with binary only modules but has
81121 + a higher runtime overhead.
81122 +
81123 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
81124 + bool "or"
81125 + depends on !PARAVIRT
81126 + help
81127 + This method is incompatible with binary only modules but has
81128 + a lower runtime overhead.
81129 +endchoice
81130 +
81131 +config PAX_KERNEXEC_PLUGIN_METHOD
81132 + string
81133 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
81134 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
81135 + default ""
81136 +
81137 +config PAX_KERNEXEC_MODULE_TEXT
81138 + int "Minimum amount of memory reserved for module code"
81139 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
81140 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
81141 + depends on PAX_KERNEXEC && X86_32 && MODULES
81142 + help
81143 + Due to implementation details the kernel must reserve a fixed
81144 + amount of memory for module code at compile time that cannot be
81145 + changed at runtime. Here you can specify the minimum amount
81146 + in MB that will be reserved. Due to the same implementation
81147 + details this size will always be rounded up to the next 2/4 MB
81148 + boundary (depends on PAE) so the actually available memory for
81149 + module code will usually be more than this minimum.
81150 +
81151 + The default 4 MB should be enough for most users but if you have
81152 + an excessive number of modules (e.g., most distribution configs
81153 + compile many drivers as modules) or use huge modules such as
81154 + nvidia's kernel driver, you will need to adjust this amount.
81155 + A good rule of thumb is to look at your currently loaded kernel
81156 + modules and add up their sizes.
81157 +
81158 +endmenu
81159 +
81160 +menu "Address Space Layout Randomization"
81161 + depends on PAX
81162 +
81163 +config PAX_ASLR
81164 + bool "Address Space Layout Randomization"
81165 + default y if GRKERNSEC_CONFIG_AUTO
81166 + help
81167 + Many if not most exploit techniques rely on the knowledge of
81168 + certain addresses in the attacked program. The following options
81169 + will allow the kernel to apply a certain amount of randomization
81170 + to specific parts of the program thereby forcing an attacker to
81171 + guess them in most cases. Any failed guess will most likely crash
81172 + the attacked program which allows the kernel to detect such attempts
81173 + and react on them. PaX itself provides no reaction mechanisms,
81174 + instead it is strongly encouraged that you make use of Nergal's
81175 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
81176 + (http://www.grsecurity.net/) built-in crash detection features or
81177 + develop one yourself.
81178 +
81179 + By saying Y here you can choose to randomize the following areas:
81180 + - top of the task's kernel stack
81181 + - top of the task's userland stack
81182 + - base address for mmap() requests that do not specify one
81183 + (this includes all libraries)
81184 + - base address of the main executable
81185 +
81186 + It is strongly recommended to say Y here as address space layout
81187 + randomization has negligible impact on performance yet it provides
81188 + a very effective protection.
81189 +
81190 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
81191 + this feature on a per file basis.
81192 +
81193 +config PAX_RANDKSTACK
81194 + bool "Randomize kernel stack base"
81195 + default y if GRKERNSEC_CONFIG_AUTO
81196 + depends on X86_TSC && X86
81197 + help
81198 + By saying Y here the kernel will randomize every task's kernel
81199 + stack on every system call. This will not only force an attacker
81200 + to guess it but also prevent him from making use of possible
81201 + leaked information about it.
81202 +
81203 + Since the kernel stack is a rather scarce resource, randomization
81204 + may cause unexpected stack overflows, therefore you should very
81205 + carefully test your system. Note that once enabled in the kernel
81206 + configuration, this feature cannot be disabled on a per file basis.
81207 +
81208 +config PAX_RANDUSTACK
81209 + bool "Randomize user stack base"
81210 + default y if GRKERNSEC_CONFIG_AUTO
81211 + depends on PAX_ASLR
81212 + help
81213 + By saying Y here the kernel will randomize every task's userland
81214 + stack. The randomization is done in two steps where the second
81215 + one may apply a big amount of shift to the top of the stack and
81216 + cause problems for programs that want to use lots of memory (more
81217 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
81218 + For this reason the second step can be controlled by 'chpax' or
81219 + 'paxctl' on a per file basis.
81220 +
81221 +config PAX_RANDMMAP
81222 + bool "Randomize mmap() base"
81223 + default y if GRKERNSEC_CONFIG_AUTO
81224 + depends on PAX_ASLR
81225 + help
81226 + By saying Y here the kernel will use a randomized base address for
81227 + mmap() requests that do not specify one themselves. As a result
81228 + all dynamically loaded libraries will appear at random addresses
81229 + and therefore be harder to exploit by a technique where an attacker
81230 + attempts to execute library code for his purposes (e.g. spawn a
81231 + shell from an exploited program that is running at an elevated
81232 + privilege level).
81233 +
81234 + Furthermore, if a program is relinked as a dynamic ELF file, its
81235 + base address will be randomized as well, completing the full
81236 + randomization of the address space layout. Attacking such programs
81237 + becomes a guess game. You can find an example of doing this at
81238 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
81239 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
81240 +
81241 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
81242 + feature on a per file basis.
81243 +
81244 +endmenu
81245 +
81246 +menu "Miscellaneous hardening features"
81247 +
81248 +config PAX_MEMORY_SANITIZE
81249 + bool "Sanitize all freed memory"
81250 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
81251 + depends on !HIBERNATION
81252 + help
81253 + By saying Y here the kernel will erase memory pages as soon as they
81254 + are freed. This in turn reduces the lifetime of data stored in the
81255 + pages, making it less likely that sensitive information such as
81256 + passwords, cryptographic secrets, etc stay in memory for too long.
81257 +
81258 + This is especially useful for programs whose runtime is short, long
81259 + lived processes and the kernel itself benefit from this as long as
81260 + they operate on whole memory pages and ensure timely freeing of pages
81261 + that may hold sensitive information.
81262 +
81263 + The tradeoff is performance impact, on a single CPU system kernel
81264 + compilation sees a 3% slowdown, other systems and workloads may vary
81265 + and you are advised to test this feature on your expected workload
81266 + before deploying it.
81267 +
81268 + Note that this feature does not protect data stored in live pages,
81269 + e.g., process memory swapped to disk may stay there for a long time.
81270 +
81271 +config PAX_MEMORY_STACKLEAK
81272 + bool "Sanitize kernel stack"
81273 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
81274 + depends on X86
81275 + help
81276 + By saying Y here the kernel will erase the kernel stack before it
81277 + returns from a system call. This in turn reduces the information
81278 + that a kernel stack leak bug can reveal.
81279 +
81280 + Note that such a bug can still leak information that was put on
81281 + the stack by the current system call (the one eventually triggering
81282 + the bug) but traces of earlier system calls on the kernel stack
81283 + cannot leak anymore.
81284 +
81285 + The tradeoff is performance impact: on a single CPU system kernel
81286 + compilation sees a 1% slowdown, other systems and workloads may vary
81287 + and you are advised to test this feature on your expected workload
81288 + before deploying it.
81289 +
81290 + Note that the full feature requires a gcc with plugin support,
81291 + i.e., gcc 4.5 or newer. You may need to install the supporting
81292 + headers explicitly in addition to the normal gcc package. Using
81293 + older gcc versions means that functions with large enough stack
81294 + frames may leave uninitialized memory behind that may be exposed
81295 + to a later syscall leaking the stack.
81296 +
81297 +config PAX_MEMORY_UDEREF
81298 + bool "Prevent invalid userland pointer dereference"
81299 + default y if GRKERNSEC_CONFIG_AUTO && (X86_32 || (X86_64 && GRKERNSEC_CONFIG_PRIORITY_SECURITY)) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
81300 + depends on X86 && !UML_X86 && !XEN
81301 + select PAX_PER_CPU_PGD if X86_64
81302 + help
81303 + By saying Y here the kernel will be prevented from dereferencing
81304 + userland pointers in contexts where the kernel expects only kernel
81305 + pointers. This is both a useful runtime debugging feature and a
81306 + security measure that prevents exploiting a class of kernel bugs.
81307 +
81308 + The tradeoff is that some virtualization solutions may experience
81309 + a huge slowdown and therefore you should not enable this feature
81310 + for kernels meant to run in such environments. Whether a given VM
81311 + solution is affected or not is best determined by simply trying it
81312 + out, the performance impact will be obvious right on boot as this
81313 + mechanism engages from very early on. A good rule of thumb is that
81314 + VMs running on CPUs without hardware virtualization support (i.e.,
81315 + the majority of IA-32 CPUs) will likely experience the slowdown.
81316 +
81317 +config PAX_REFCOUNT
81318 + bool "Prevent various kernel object reference counter overflows"
81319 + default y if GRKERNSEC_CONFIG_AUTO
81320 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
81321 + help
81322 + By saying Y here the kernel will detect and prevent overflowing
81323 + various (but not all) kinds of object reference counters. Such
81324 + overflows can normally occur due to bugs only and are often, if
81325 + not always, exploitable.
81326 +
81327 + The tradeoff is that data structures protected by an overflowed
81328 + refcount will never be freed and therefore will leak memory. Note
81329 + that this leak also happens even without this protection but in
81330 + that case the overflow can eventually trigger the freeing of the
81331 + data structure while it is still being used elsewhere, resulting
81332 + in the exploitable situation that this feature prevents.
81333 +
81334 + Since this has a negligible performance impact, you should enable
81335 + this feature.
81336 +
81337 +config PAX_USERCOPY
81338 + bool "Harden heap object copies between kernel and userland"
81339 + default y if GRKERNSEC_CONFIG_AUTO
81340 + depends on X86 || PPC || SPARC || ARM
81341 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
81342 + select PAX_USERCOPY_SLABS
81343 + help
81344 + By saying Y here the kernel will enforce the size of heap objects
81345 + when they are copied in either direction between the kernel and
81346 + userland, even if only a part of the heap object is copied.
81347 +
81348 + Specifically, this checking prevents information leaking from the
81349 + kernel heap during kernel to userland copies (if the kernel heap
81350 + object is otherwise fully initialized) and prevents kernel heap
81351 + overflows during userland to kernel copies.
81352 +
81353 + Note that the current implementation provides the strictest bounds
81354 + checks for the SLUB allocator.
81355 +
81356 + Enabling this option also enables per-slab cache protection against
81357 + data in a given cache being copied into/out of via userland
81358 + accessors. Though the whitelist of regions will be reduced over
81359 + time, it notably protects important data structures like task structs.
81360 +
81361 + If frame pointers are enabled on x86, this option will also restrict
81362 + copies into and out of the kernel stack to local variables within a
81363 + single frame.
81364 +
81365 + Since this has a negligible performance impact, you should enable
81366 + this feature.
81367 +
81368 +config PAX_SIZE_OVERFLOW
81369 + bool "Prevent various integer overflows in function size parameters"
81370 + default y if GRKERNSEC_CONFIG_AUTO
81371 + depends on X86
81372 + help
81373 + By saying Y here the kernel recomputes expressions of function
81374 + arguments marked by a size_overflow attribute with double integer
81375 + precision (DImode/TImode for 32/64 bit integer types).
81376 +
81377 + The recomputed argument is checked against TYPE_MAX and an event
81378 + is logged on overflow and the triggering process is killed.
81379 +
81380 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
81381 +
81382 + Note that the implementation requires a gcc with plugin support,
81383 + i.e., gcc 4.5 or newer. You may need to install the supporting
81384 + headers explicitly in addition to the normal gcc package.
81385 +
81386 +config PAX_LATENT_ENTROPY
81387 + bool "Generate some entropy during boot"
81388 + default y if GRKERNSEC_CONFIG_AUTO
81389 + help
81390 + By saying Y here the kernel will instrument early boot code to
81391 + extract some entropy from both original and artificially created
81392 + program state. This will help especially embedded systems where
81393 + there is little 'natural' source of entropy normally. The cost
81394 + is some slowdown of the boot process.
81395 +
81396 + Note that the implementation requires a gcc with plugin support,
81397 + i.e., gcc 4.5 or newer. You may need to install the supporting
81398 + headers explicitly in addition to the normal gcc package.
81399 +
81400 + Note that entropy extracted this way is not cryptographically
81401 + secure!
81402 +
81403 +endmenu
81404 +
81405 +endmenu
81406 +
81407 +source grsecurity/Kconfig
81408 +
81409 +endmenu
81410 +
81411 +endmenu
81412 +
81413 source security/keys/Kconfig
81414
81415 config SECURITY_DMESG_RESTRICT
81416 @@ -103,7 +993,7 @@ config INTEL_TXT
81417 config LSM_MMAP_MIN_ADDR
81418 int "Low address space for LSM to protect from user allocation"
81419 depends on SECURITY && SECURITY_SELINUX
81420 - default 32768 if ARM
81421 + default 32768 if ALPHA || ARM || PARISC || SPARC32
81422 default 65536
81423 help
81424 This is the portion of low virtual memory which should be protected
81425 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
81426 index 8ea39aa..8569ac5 100644
81427 --- a/security/apparmor/lsm.c
81428 +++ b/security/apparmor/lsm.c
81429 @@ -614,7 +614,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
81430 return error;
81431 }
81432
81433 -static struct security_operations apparmor_ops = {
81434 +static struct security_operations apparmor_ops __read_only = {
81435 .name = "apparmor",
81436
81437 .ptrace_access_check = apparmor_ptrace_access_check,
81438 diff --git a/security/commoncap.c b/security/commoncap.c
81439 index 6dbae46..d5611fd 100644
81440 --- a/security/commoncap.c
81441 +++ b/security/commoncap.c
81442 @@ -415,6 +415,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
81443 return 0;
81444 }
81445
81446 +/* returns:
81447 + 1 for suid privilege
81448 + 2 for sgid privilege
81449 + 3 for fscap privilege
81450 +*/
81451 +int is_privileged_binary(const struct dentry *dentry)
81452 +{
81453 + struct cpu_vfs_cap_data capdata;
81454 + struct inode *inode = dentry->d_inode;
81455 +
81456 + if (!inode || S_ISDIR(inode->i_mode))
81457 + return 0;
81458 +
81459 + if (inode->i_mode & S_ISUID)
81460 + return 1;
81461 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
81462 + return 2;
81463 +
81464 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
81465 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
81466 + return 3;
81467 + }
81468 +
81469 + return 0;
81470 +}
81471 +
81472 /*
81473 * Attempt to get the on-exec apply capability sets for an executable file from
81474 * its xattrs and, if present, apply them to the proposed credentials being
81475 @@ -583,6 +609,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
81476 const struct cred *cred = current_cred();
81477 kuid_t root_uid = make_kuid(cred->user_ns, 0);
81478
81479 + if (gr_acl_enable_at_secure())
81480 + return 1;
81481 +
81482 if (!uid_eq(cred->uid, root_uid)) {
81483 if (bprm->cap_effective)
81484 return 1;
81485 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
81486 index e7c99fd..5b2fa24 100644
81487 --- a/security/integrity/ima/ima.h
81488 +++ b/security/integrity/ima/ima.h
81489 @@ -95,8 +95,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
81490 extern spinlock_t ima_queue_lock;
81491
81492 struct ima_h_table {
81493 - atomic_long_t len; /* number of stored measurements in the list */
81494 - atomic_long_t violations;
81495 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
81496 + atomic_long_unchecked_t violations;
81497 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
81498 };
81499 extern struct ima_h_table ima_htable;
81500 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
81501 index 032ff03..c428a74 100644
81502 --- a/security/integrity/ima/ima_api.c
81503 +++ b/security/integrity/ima/ima_api.c
81504 @@ -75,7 +75,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
81505 int result;
81506
81507 /* can overflow, only indicator */
81508 - atomic_long_inc(&ima_htable.violations);
81509 + atomic_long_inc_unchecked(&ima_htable.violations);
81510
81511 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
81512 if (!entry) {
81513 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
81514 index 38477c9..87a60c7 100644
81515 --- a/security/integrity/ima/ima_fs.c
81516 +++ b/security/integrity/ima/ima_fs.c
81517 @@ -28,12 +28,12 @@
81518 static int valid_policy = 1;
81519 #define TMPBUFLEN 12
81520 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
81521 - loff_t *ppos, atomic_long_t *val)
81522 + loff_t *ppos, atomic_long_unchecked_t *val)
81523 {
81524 char tmpbuf[TMPBUFLEN];
81525 ssize_t len;
81526
81527 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
81528 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
81529 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
81530 }
81531
81532 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
81533 index 55a6271..ad829c3 100644
81534 --- a/security/integrity/ima/ima_queue.c
81535 +++ b/security/integrity/ima/ima_queue.c
81536 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
81537 INIT_LIST_HEAD(&qe->later);
81538 list_add_tail_rcu(&qe->later, &ima_measurements);
81539
81540 - atomic_long_inc(&ima_htable.len);
81541 + atomic_long_inc_unchecked(&ima_htable.len);
81542 key = ima_hash_key(entry->digest);
81543 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
81544 return 0;
81545 diff --git a/security/keys/compat.c b/security/keys/compat.c
81546 index 1c26176..64a1ba2 100644
81547 --- a/security/keys/compat.c
81548 +++ b/security/keys/compat.c
81549 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
81550 if (ret == 0)
81551 goto no_payload_free;
81552
81553 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
81554 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
81555
81556 if (iov != iovstack)
81557 kfree(iov);
81558 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
81559 index 3364fbf..1f10f31 100644
81560 --- a/security/keys/keyctl.c
81561 +++ b/security/keys/keyctl.c
81562 @@ -966,7 +966,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
81563 /*
81564 * Copy the iovec data from userspace
81565 */
81566 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
81567 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
81568 unsigned ioc)
81569 {
81570 for (; ioc > 0; ioc--) {
81571 @@ -988,7 +988,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
81572 * If successful, 0 will be returned.
81573 */
81574 long keyctl_instantiate_key_common(key_serial_t id,
81575 - const struct iovec *payload_iov,
81576 + const struct iovec __user *payload_iov,
81577 unsigned ioc,
81578 size_t plen,
81579 key_serial_t ringid)
81580 @@ -1083,7 +1083,7 @@ long keyctl_instantiate_key(key_serial_t id,
81581 [0].iov_len = plen
81582 };
81583
81584 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
81585 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
81586 }
81587
81588 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
81589 @@ -1116,7 +1116,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
81590 if (ret == 0)
81591 goto no_payload_free;
81592
81593 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
81594 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
81595
81596 if (iov != iovstack)
81597 kfree(iov);
81598 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
81599 index 81e7852..2b2ecc3 100644
81600 --- a/security/keys/keyring.c
81601 +++ b/security/keys/keyring.c
81602 @@ -227,16 +227,16 @@ static long keyring_read(const struct key *keyring,
81603 ret = -EFAULT;
81604
81605 for (loop = 0; loop < klist->nkeys; loop++) {
81606 + key_serial_t serial;
81607 key = rcu_deref_link_locked(klist, loop,
81608 keyring);
81609 + serial = key->serial;
81610
81611 tmp = sizeof(key_serial_t);
81612 if (tmp > buflen)
81613 tmp = buflen;
81614
81615 - if (copy_to_user(buffer,
81616 - &key->serial,
81617 - tmp) != 0)
81618 + if (copy_to_user(buffer, &serial, tmp))
81619 goto error;
81620
81621 buflen -= tmp;
81622 diff --git a/security/min_addr.c b/security/min_addr.c
81623 index f728728..6457a0c 100644
81624 --- a/security/min_addr.c
81625 +++ b/security/min_addr.c
81626 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
81627 */
81628 static void update_mmap_min_addr(void)
81629 {
81630 +#ifndef SPARC
81631 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
81632 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
81633 mmap_min_addr = dac_mmap_min_addr;
81634 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
81635 #else
81636 mmap_min_addr = dac_mmap_min_addr;
81637 #endif
81638 +#endif
81639 }
81640
81641 /*
81642 diff --git a/security/security.c b/security/security.c
81643 index 860aeb3..45765c0 100644
81644 --- a/security/security.c
81645 +++ b/security/security.c
81646 @@ -20,6 +20,7 @@
81647 #include <linux/ima.h>
81648 #include <linux/evm.h>
81649 #include <linux/fsnotify.h>
81650 +#include <linux/mm.h>
81651 #include <linux/mman.h>
81652 #include <linux/mount.h>
81653 #include <linux/personality.h>
81654 @@ -32,8 +33,8 @@
81655 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
81656 CONFIG_DEFAULT_SECURITY;
81657
81658 -static struct security_operations *security_ops;
81659 -static struct security_operations default_security_ops = {
81660 +static struct security_operations *security_ops __read_only;
81661 +static struct security_operations default_security_ops __read_only = {
81662 .name = "default",
81663 };
81664
81665 @@ -74,7 +75,9 @@ int __init security_init(void)
81666
81667 void reset_security_ops(void)
81668 {
81669 + pax_open_kernel();
81670 security_ops = &default_security_ops;
81671 + pax_close_kernel();
81672 }
81673
81674 /* Save user chosen LSM */
81675 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
81676 index 6c77f63..7496c76 100644
81677 --- a/security/selinux/hooks.c
81678 +++ b/security/selinux/hooks.c
81679 @@ -95,8 +95,6 @@
81680
81681 #define NUM_SEL_MNT_OPTS 5
81682
81683 -extern struct security_operations *security_ops;
81684 -
81685 /* SECMARK reference count */
81686 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
81687
81688 @@ -5511,7 +5509,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
81689
81690 #endif
81691
81692 -static struct security_operations selinux_ops = {
81693 +static struct security_operations selinux_ops __read_only = {
81694 .name = "selinux",
81695
81696 .ptrace_access_check = selinux_ptrace_access_check,
81697 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
81698 index 65f67cb..3f141ef 100644
81699 --- a/security/selinux/include/xfrm.h
81700 +++ b/security/selinux/include/xfrm.h
81701 @@ -50,7 +50,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
81702
81703 static inline void selinux_xfrm_notify_policyload(void)
81704 {
81705 - atomic_inc(&flow_cache_genid);
81706 + atomic_inc_unchecked(&flow_cache_genid);
81707 rt_genid_bump(&init_net);
81708 }
81709 #else
81710 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
81711 index 8221514..5c4775f 100644
81712 --- a/security/smack/smack_lsm.c
81713 +++ b/security/smack/smack_lsm.c
81714 @@ -3429,7 +3429,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
81715 return 0;
81716 }
81717
81718 -struct security_operations smack_ops = {
81719 +struct security_operations smack_ops __read_only = {
81720 .name = "smack",
81721
81722 .ptrace_access_check = smack_ptrace_access_check,
81723 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
81724 index c2d04a5..e6a1aeb 100644
81725 --- a/security/tomoyo/tomoyo.c
81726 +++ b/security/tomoyo/tomoyo.c
81727 @@ -501,7 +501,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
81728 * tomoyo_security_ops is a "struct security_operations" which is used for
81729 * registering TOMOYO.
81730 */
81731 -static struct security_operations tomoyo_security_ops = {
81732 +static struct security_operations tomoyo_security_ops __read_only = {
81733 .name = "tomoyo",
81734 .cred_alloc_blank = tomoyo_cred_alloc_blank,
81735 .cred_prepare = tomoyo_cred_prepare,
81736 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
81737 index 51d6709..1f3dbe2 100644
81738 --- a/security/yama/Kconfig
81739 +++ b/security/yama/Kconfig
81740 @@ -1,6 +1,6 @@
81741 config SECURITY_YAMA
81742 bool "Yama support"
81743 - depends on SECURITY
81744 + depends on SECURITY && !GRKERNSEC
81745 select SECURITYFS
81746 select SECURITY_PATH
81747 default n
81748 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
81749 index 4cedc69..e59d8a3 100644
81750 --- a/sound/aoa/codecs/onyx.c
81751 +++ b/sound/aoa/codecs/onyx.c
81752 @@ -54,7 +54,7 @@ struct onyx {
81753 spdif_locked:1,
81754 analog_locked:1,
81755 original_mute:2;
81756 - int open_count;
81757 + local_t open_count;
81758 struct codec_info *codec_info;
81759
81760 /* mutex serializes concurrent access to the device
81761 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
81762 struct onyx *onyx = cii->codec_data;
81763
81764 mutex_lock(&onyx->mutex);
81765 - onyx->open_count++;
81766 + local_inc(&onyx->open_count);
81767 mutex_unlock(&onyx->mutex);
81768
81769 return 0;
81770 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
81771 struct onyx *onyx = cii->codec_data;
81772
81773 mutex_lock(&onyx->mutex);
81774 - onyx->open_count--;
81775 - if (!onyx->open_count)
81776 + if (local_dec_and_test(&onyx->open_count))
81777 onyx->spdif_locked = onyx->analog_locked = 0;
81778 mutex_unlock(&onyx->mutex);
81779
81780 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
81781 index ffd2025..df062c9 100644
81782 --- a/sound/aoa/codecs/onyx.h
81783 +++ b/sound/aoa/codecs/onyx.h
81784 @@ -11,6 +11,7 @@
81785 #include <linux/i2c.h>
81786 #include <asm/pmac_low_i2c.h>
81787 #include <asm/prom.h>
81788 +#include <asm/local.h>
81789
81790 /* PCM3052 register definitions */
81791
81792 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
81793 index 08fde00..0bf641a 100644
81794 --- a/sound/core/oss/pcm_oss.c
81795 +++ b/sound/core/oss/pcm_oss.c
81796 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
81797 if (in_kernel) {
81798 mm_segment_t fs;
81799 fs = snd_enter_user();
81800 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
81801 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
81802 snd_leave_user(fs);
81803 } else {
81804 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
81805 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
81806 }
81807 if (ret != -EPIPE && ret != -ESTRPIPE)
81808 break;
81809 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
81810 if (in_kernel) {
81811 mm_segment_t fs;
81812 fs = snd_enter_user();
81813 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
81814 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
81815 snd_leave_user(fs);
81816 } else {
81817 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
81818 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
81819 }
81820 if (ret == -EPIPE) {
81821 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
81822 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
81823 struct snd_pcm_plugin_channel *channels;
81824 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
81825 if (!in_kernel) {
81826 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
81827 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
81828 return -EFAULT;
81829 buf = runtime->oss.buffer;
81830 }
81831 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
81832 }
81833 } else {
81834 tmp = snd_pcm_oss_write2(substream,
81835 - (const char __force *)buf,
81836 + (const char __force_kernel *)buf,
81837 runtime->oss.period_bytes, 0);
81838 if (tmp <= 0)
81839 goto err;
81840 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
81841 struct snd_pcm_runtime *runtime = substream->runtime;
81842 snd_pcm_sframes_t frames, frames1;
81843 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
81844 - char __user *final_dst = (char __force __user *)buf;
81845 + char __user *final_dst = (char __force_user *)buf;
81846 if (runtime->oss.plugin_first) {
81847 struct snd_pcm_plugin_channel *channels;
81848 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
81849 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
81850 xfer += tmp;
81851 runtime->oss.buffer_used -= tmp;
81852 } else {
81853 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
81854 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
81855 runtime->oss.period_bytes, 0);
81856 if (tmp <= 0)
81857 goto err;
81858 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
81859 size1);
81860 size1 /= runtime->channels; /* frames */
81861 fs = snd_enter_user();
81862 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
81863 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
81864 snd_leave_user(fs);
81865 }
81866 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
81867 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
81868 index 91cdf94..4085161 100644
81869 --- a/sound/core/pcm_compat.c
81870 +++ b/sound/core/pcm_compat.c
81871 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
81872 int err;
81873
81874 fs = snd_enter_user();
81875 - err = snd_pcm_delay(substream, &delay);
81876 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
81877 snd_leave_user(fs);
81878 if (err < 0)
81879 return err;
81880 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
81881 index 53b5ada..2db94c8 100644
81882 --- a/sound/core/pcm_native.c
81883 +++ b/sound/core/pcm_native.c
81884 @@ -2780,11 +2780,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
81885 switch (substream->stream) {
81886 case SNDRV_PCM_STREAM_PLAYBACK:
81887 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
81888 - (void __user *)arg);
81889 + (void __force_user *)arg);
81890 break;
81891 case SNDRV_PCM_STREAM_CAPTURE:
81892 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
81893 - (void __user *)arg);
81894 + (void __force_user *)arg);
81895 break;
81896 default:
81897 result = -EINVAL;
81898 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
81899 index 5cf8d65..912a79c 100644
81900 --- a/sound/core/seq/seq_device.c
81901 +++ b/sound/core/seq/seq_device.c
81902 @@ -64,7 +64,7 @@ struct ops_list {
81903 int argsize; /* argument size */
81904
81905 /* operators */
81906 - struct snd_seq_dev_ops ops;
81907 + struct snd_seq_dev_ops *ops;
81908
81909 /* registred devices */
81910 struct list_head dev_list; /* list of devices */
81911 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
81912
81913 mutex_lock(&ops->reg_mutex);
81914 /* copy driver operators */
81915 - ops->ops = *entry;
81916 + ops->ops = entry;
81917 ops->driver |= DRIVER_LOADED;
81918 ops->argsize = argsize;
81919
81920 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
81921 dev->name, ops->id, ops->argsize, dev->argsize);
81922 return -EINVAL;
81923 }
81924 - if (ops->ops.init_device(dev) >= 0) {
81925 + if (ops->ops->init_device(dev) >= 0) {
81926 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
81927 ops->num_init_devices++;
81928 } else {
81929 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
81930 dev->name, ops->id, ops->argsize, dev->argsize);
81931 return -EINVAL;
81932 }
81933 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
81934 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
81935 dev->status = SNDRV_SEQ_DEVICE_FREE;
81936 dev->driver_data = NULL;
81937 ops->num_init_devices--;
81938 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
81939 index 2d5514b..3afae9c 100644
81940 --- a/sound/drivers/mts64.c
81941 +++ b/sound/drivers/mts64.c
81942 @@ -29,6 +29,7 @@
81943 #include <sound/initval.h>
81944 #include <sound/rawmidi.h>
81945 #include <sound/control.h>
81946 +#include <asm/local.h>
81947
81948 #define CARD_NAME "Miditerminal 4140"
81949 #define DRIVER_NAME "MTS64"
81950 @@ -67,7 +68,7 @@ struct mts64 {
81951 struct pardevice *pardev;
81952 int pardev_claimed;
81953
81954 - int open_count;
81955 + local_t open_count;
81956 int current_midi_output_port;
81957 int current_midi_input_port;
81958 u8 mode[MTS64_NUM_INPUT_PORTS];
81959 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
81960 {
81961 struct mts64 *mts = substream->rmidi->private_data;
81962
81963 - if (mts->open_count == 0) {
81964 + if (local_read(&mts->open_count) == 0) {
81965 /* We don't need a spinlock here, because this is just called
81966 if the device has not been opened before.
81967 So there aren't any IRQs from the device */
81968 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
81969
81970 msleep(50);
81971 }
81972 - ++(mts->open_count);
81973 + local_inc(&mts->open_count);
81974
81975 return 0;
81976 }
81977 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
81978 struct mts64 *mts = substream->rmidi->private_data;
81979 unsigned long flags;
81980
81981 - --(mts->open_count);
81982 - if (mts->open_count == 0) {
81983 + if (local_dec_return(&mts->open_count) == 0) {
81984 /* We need the spinlock_irqsave here because we can still
81985 have IRQs at this point */
81986 spin_lock_irqsave(&mts->lock, flags);
81987 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
81988
81989 msleep(500);
81990
81991 - } else if (mts->open_count < 0)
81992 - mts->open_count = 0;
81993 + } else if (local_read(&mts->open_count) < 0)
81994 + local_set(&mts->open_count, 0);
81995
81996 return 0;
81997 }
81998 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
81999 index b953fb4..1999c01 100644
82000 --- a/sound/drivers/opl4/opl4_lib.c
82001 +++ b/sound/drivers/opl4/opl4_lib.c
82002 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
82003 MODULE_DESCRIPTION("OPL4 driver");
82004 MODULE_LICENSE("GPL");
82005
82006 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
82007 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
82008 {
82009 int timeout = 10;
82010 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
82011 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
82012 index 8364855..59f2e2b 100644
82013 --- a/sound/drivers/portman2x4.c
82014 +++ b/sound/drivers/portman2x4.c
82015 @@ -48,6 +48,7 @@
82016 #include <sound/initval.h>
82017 #include <sound/rawmidi.h>
82018 #include <sound/control.h>
82019 +#include <asm/local.h>
82020
82021 #define CARD_NAME "Portman 2x4"
82022 #define DRIVER_NAME "portman"
82023 @@ -85,7 +86,7 @@ struct portman {
82024 struct pardevice *pardev;
82025 int pardev_claimed;
82026
82027 - int open_count;
82028 + local_t open_count;
82029 int mode[PORTMAN_NUM_INPUT_PORTS];
82030 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
82031 };
82032 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
82033 index ea995af..f1bfa37 100644
82034 --- a/sound/firewire/amdtp.c
82035 +++ b/sound/firewire/amdtp.c
82036 @@ -389,7 +389,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
82037 ptr = s->pcm_buffer_pointer + data_blocks;
82038 if (ptr >= pcm->runtime->buffer_size)
82039 ptr -= pcm->runtime->buffer_size;
82040 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
82041 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
82042
82043 s->pcm_period_pointer += data_blocks;
82044 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
82045 @@ -557,7 +557,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
82046 */
82047 void amdtp_out_stream_update(struct amdtp_out_stream *s)
82048 {
82049 - ACCESS_ONCE(s->source_node_id_field) =
82050 + ACCESS_ONCE_RW(s->source_node_id_field) =
82051 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
82052 }
82053 EXPORT_SYMBOL(amdtp_out_stream_update);
82054 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
82055 index b680c5e..061b7a0 100644
82056 --- a/sound/firewire/amdtp.h
82057 +++ b/sound/firewire/amdtp.h
82058 @@ -139,7 +139,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
82059 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
82060 struct snd_pcm_substream *pcm)
82061 {
82062 - ACCESS_ONCE(s->pcm) = pcm;
82063 + ACCESS_ONCE_RW(s->pcm) = pcm;
82064 }
82065
82066 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
82067 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
82068 index d428ffe..751ef78 100644
82069 --- a/sound/firewire/isight.c
82070 +++ b/sound/firewire/isight.c
82071 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
82072 ptr += count;
82073 if (ptr >= runtime->buffer_size)
82074 ptr -= runtime->buffer_size;
82075 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
82076 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
82077
82078 isight->period_counter += count;
82079 if (isight->period_counter >= runtime->period_size) {
82080 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
82081 if (err < 0)
82082 return err;
82083
82084 - ACCESS_ONCE(isight->pcm_active) = true;
82085 + ACCESS_ONCE_RW(isight->pcm_active) = true;
82086
82087 return 0;
82088 }
82089 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
82090 {
82091 struct isight *isight = substream->private_data;
82092
82093 - ACCESS_ONCE(isight->pcm_active) = false;
82094 + ACCESS_ONCE_RW(isight->pcm_active) = false;
82095
82096 mutex_lock(&isight->mutex);
82097 isight_stop_streaming(isight);
82098 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
82099
82100 switch (cmd) {
82101 case SNDRV_PCM_TRIGGER_START:
82102 - ACCESS_ONCE(isight->pcm_running) = true;
82103 + ACCESS_ONCE_RW(isight->pcm_running) = true;
82104 break;
82105 case SNDRV_PCM_TRIGGER_STOP:
82106 - ACCESS_ONCE(isight->pcm_running) = false;
82107 + ACCESS_ONCE_RW(isight->pcm_running) = false;
82108 break;
82109 default:
82110 return -EINVAL;
82111 diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
82112 index 7bd5e33..1fcab12 100644
82113 --- a/sound/isa/cmi8330.c
82114 +++ b/sound/isa/cmi8330.c
82115 @@ -172,7 +172,7 @@ struct snd_cmi8330 {
82116
82117 struct snd_pcm *pcm;
82118 struct snd_cmi8330_stream {
82119 - struct snd_pcm_ops ops;
82120 + snd_pcm_ops_no_const ops;
82121 snd_pcm_open_callback_t open;
82122 void *private_data; /* sb or wss */
82123 } streams[2];
82124 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
82125 index b2b3c01..e1c1e1f 100644
82126 --- a/sound/oss/sb_audio.c
82127 +++ b/sound/oss/sb_audio.c
82128 @@ -903,7 +903,7 @@ sb16_copy_from_user(int dev,
82129 buf16 = (signed short *)(localbuf + localoffs);
82130 while (c)
82131 {
82132 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
82133 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
82134 if (copy_from_user(lbuf8,
82135 userbuf+useroffs + p,
82136 locallen))
82137 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
82138 index 7d8803a..559f8d0 100644
82139 --- a/sound/oss/swarm_cs4297a.c
82140 +++ b/sound/oss/swarm_cs4297a.c
82141 @@ -2621,7 +2621,6 @@ static int __init cs4297a_init(void)
82142 {
82143 struct cs4297a_state *s;
82144 u32 pwr, id;
82145 - mm_segment_t fs;
82146 int rval;
82147 #ifndef CONFIG_BCM_CS4297A_CSWARM
82148 u64 cfg;
82149 @@ -2711,22 +2710,23 @@ static int __init cs4297a_init(void)
82150 if (!rval) {
82151 char *sb1250_duart_present;
82152
82153 +#if 0
82154 + mm_segment_t fs;
82155 fs = get_fs();
82156 set_fs(KERNEL_DS);
82157 -#if 0
82158 val = SOUND_MASK_LINE;
82159 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
82160 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
82161 val = initvol[i].vol;
82162 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
82163 }
82164 + set_fs(fs);
82165 // cs4297a_write_ac97(s, 0x18, 0x0808);
82166 #else
82167 // cs4297a_write_ac97(s, 0x5e, 0x180);
82168 cs4297a_write_ac97(s, 0x02, 0x0808);
82169 cs4297a_write_ac97(s, 0x18, 0x0808);
82170 #endif
82171 - set_fs(fs);
82172
82173 list_add(&s->list, &cs4297a_devs);
82174
82175 diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
82176 index e5a7e19..4049063 100644
82177 --- a/sound/pci/hda/hda_codec.h
82178 +++ b/sound/pci/hda/hda_codec.h
82179 @@ -614,7 +614,7 @@ struct hda_bus_ops {
82180 /* notify power-up/down from codec to controller */
82181 void (*pm_notify)(struct hda_bus *bus);
82182 #endif
82183 -};
82184 +} __no_const;
82185
82186 /* template to pass to the bus constructor */
82187 struct hda_bus_template {
82188 @@ -714,6 +714,7 @@ struct hda_codec_ops {
82189 #endif
82190 void (*reboot_notify)(struct hda_codec *codec);
82191 };
82192 +typedef struct hda_codec_ops __no_const hda_codec_ops_no_const;
82193
82194 /* record for amp information cache */
82195 struct hda_cache_head {
82196 @@ -744,7 +745,7 @@ struct hda_pcm_ops {
82197 struct snd_pcm_substream *substream);
82198 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
82199 struct snd_pcm_substream *substream);
82200 -};
82201 +} __no_const;
82202
82203 /* PCM information for each substream */
82204 struct hda_pcm_stream {
82205 @@ -802,7 +803,7 @@ struct hda_codec {
82206 const char *modelname; /* model name for preset */
82207
82208 /* set by patch */
82209 - struct hda_codec_ops patch_ops;
82210 + hda_codec_ops_no_const patch_ops;
82211
82212 /* PCM to create, set by patch_ops.build_pcms callback */
82213 unsigned int num_pcms;
82214 diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
82215 index 0da778a..bc38b84 100644
82216 --- a/sound/pci/ice1712/ice1712.h
82217 +++ b/sound/pci/ice1712/ice1712.h
82218 @@ -269,7 +269,7 @@ struct snd_ak4xxx_private {
82219 unsigned int mask_flags; /* total mask bits */
82220 struct snd_akm4xxx_ops {
82221 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
82222 - } ops;
82223 + } __no_const ops;
82224 };
82225
82226 struct snd_ice1712_spdif {
82227 @@ -285,7 +285,7 @@ struct snd_ice1712_spdif {
82228 int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
82229 void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
82230 int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
82231 - } ops;
82232 + } __no_const ops;
82233 };
82234
82235
82236 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
82237 index bddc405..2c0733c 100644
82238 --- a/sound/pci/ymfpci/ymfpci.h
82239 +++ b/sound/pci/ymfpci/ymfpci.h
82240 @@ -358,7 +358,7 @@ struct snd_ymfpci {
82241 spinlock_t reg_lock;
82242 spinlock_t voice_lock;
82243 wait_queue_head_t interrupt_sleep;
82244 - atomic_t interrupt_sleep_count;
82245 + atomic_unchecked_t interrupt_sleep_count;
82246 struct snd_info_entry *proc_entry;
82247 const struct firmware *dsp_microcode;
82248 const struct firmware *controller_microcode;
82249 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
82250 index 62b2363..ee77972 100644
82251 --- a/sound/pci/ymfpci/ymfpci_main.c
82252 +++ b/sound/pci/ymfpci/ymfpci_main.c
82253 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
82254 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
82255 break;
82256 }
82257 - if (atomic_read(&chip->interrupt_sleep_count)) {
82258 - atomic_set(&chip->interrupt_sleep_count, 0);
82259 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
82260 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
82261 wake_up(&chip->interrupt_sleep);
82262 }
82263 __end:
82264 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
82265 continue;
82266 init_waitqueue_entry(&wait, current);
82267 add_wait_queue(&chip->interrupt_sleep, &wait);
82268 - atomic_inc(&chip->interrupt_sleep_count);
82269 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
82270 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
82271 remove_wait_queue(&chip->interrupt_sleep, &wait);
82272 }
82273 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
82274 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
82275 spin_unlock(&chip->reg_lock);
82276
82277 - if (atomic_read(&chip->interrupt_sleep_count)) {
82278 - atomic_set(&chip->interrupt_sleep_count, 0);
82279 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
82280 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
82281 wake_up(&chip->interrupt_sleep);
82282 }
82283 }
82284 @@ -2402,7 +2402,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
82285 spin_lock_init(&chip->reg_lock);
82286 spin_lock_init(&chip->voice_lock);
82287 init_waitqueue_head(&chip->interrupt_sleep);
82288 - atomic_set(&chip->interrupt_sleep_count, 0);
82289 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
82290 chip->card = card;
82291 chip->pci = pci;
82292 chip->irq = -1;
82293 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
82294 new file mode 100644
82295 index 0000000..50f2f2f
82296 --- /dev/null
82297 +++ b/tools/gcc/.gitignore
82298 @@ -0,0 +1 @@
82299 +size_overflow_hash.h
82300 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
82301 new file mode 100644
82302 index 0000000..1d09b7e
82303 --- /dev/null
82304 +++ b/tools/gcc/Makefile
82305 @@ -0,0 +1,43 @@
82306 +#CC := gcc
82307 +#PLUGIN_SOURCE_FILES := pax_plugin.c
82308 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
82309 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
82310 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
82311 +
82312 +ifeq ($(PLUGINCC),$(HOSTCC))
82313 +HOSTLIBS := hostlibs
82314 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
82315 +else
82316 +HOSTLIBS := hostcxxlibs
82317 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu++98 -ggdb -Wno-unused-parameter
82318 +endif
82319 +
82320 +$(HOSTLIBS)-y := constify_plugin.so
82321 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
82322 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
82323 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
82324 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
82325 +$(HOSTLIBS)-y += colorize_plugin.so
82326 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
82327 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
82328 +
82329 +always := $($(HOSTLIBS)-y)
82330 +
82331 +constify_plugin-objs := constify_plugin.o
82332 +stackleak_plugin-objs := stackleak_plugin.o
82333 +kallocstat_plugin-objs := kallocstat_plugin.o
82334 +kernexec_plugin-objs := kernexec_plugin.o
82335 +checker_plugin-objs := checker_plugin.o
82336 +colorize_plugin-objs := colorize_plugin.o
82337 +size_overflow_plugin-objs := size_overflow_plugin.o
82338 +latent_entropy_plugin-objs := latent_entropy_plugin.o
82339 +
82340 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
82341 +
82342 +quiet_cmd_build_size_overflow_hash = GENHASH $@
82343 + cmd_build_size_overflow_hash = \
82344 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -d $< -o $@
82345 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
82346 + $(call if_changed,build_size_overflow_hash)
82347 +
82348 +targets += size_overflow_hash.h
82349 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
82350 new file mode 100644
82351 index 0000000..d41b5af
82352 --- /dev/null
82353 +++ b/tools/gcc/checker_plugin.c
82354 @@ -0,0 +1,171 @@
82355 +/*
82356 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
82357 + * Licensed under the GPL v2
82358 + *
82359 + * Note: the choice of the license means that the compilation process is
82360 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82361 + * but for the kernel it doesn't matter since it doesn't link against
82362 + * any of the gcc libraries
82363 + *
82364 + * gcc plugin to implement various sparse (source code checker) features
82365 + *
82366 + * TODO:
82367 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
82368 + *
82369 + * BUGS:
82370 + * - none known
82371 + */
82372 +#include "gcc-plugin.h"
82373 +#include "config.h"
82374 +#include "system.h"
82375 +#include "coretypes.h"
82376 +#include "tree.h"
82377 +#include "tree-pass.h"
82378 +#include "flags.h"
82379 +#include "intl.h"
82380 +#include "toplev.h"
82381 +#include "plugin.h"
82382 +//#include "expr.h" where are you...
82383 +#include "diagnostic.h"
82384 +#include "plugin-version.h"
82385 +#include "tm.h"
82386 +#include "function.h"
82387 +#include "basic-block.h"
82388 +#include "gimple.h"
82389 +#include "rtl.h"
82390 +#include "emit-rtl.h"
82391 +#include "tree-flow.h"
82392 +#include "target.h"
82393 +
82394 +extern void c_register_addr_space (const char *str, addr_space_t as);
82395 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
82396 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
82397 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
82398 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
82399 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
82400 +
82401 +extern void print_gimple_stmt(FILE *, gimple, int, int);
82402 +extern rtx emit_move_insn(rtx x, rtx y);
82403 +
82404 +int plugin_is_GPL_compatible;
82405 +
82406 +static struct plugin_info checker_plugin_info = {
82407 + .version = "201111150100",
82408 +};
82409 +
82410 +#define ADDR_SPACE_KERNEL 0
82411 +#define ADDR_SPACE_FORCE_KERNEL 1
82412 +#define ADDR_SPACE_USER 2
82413 +#define ADDR_SPACE_FORCE_USER 3
82414 +#define ADDR_SPACE_IOMEM 0
82415 +#define ADDR_SPACE_FORCE_IOMEM 0
82416 +#define ADDR_SPACE_PERCPU 0
82417 +#define ADDR_SPACE_FORCE_PERCPU 0
82418 +#define ADDR_SPACE_RCU 0
82419 +#define ADDR_SPACE_FORCE_RCU 0
82420 +
82421 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
82422 +{
82423 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
82424 +}
82425 +
82426 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
82427 +{
82428 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
82429 +}
82430 +
82431 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
82432 +{
82433 + return default_addr_space_valid_pointer_mode(mode, as);
82434 +}
82435 +
82436 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
82437 +{
82438 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
82439 +}
82440 +
82441 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
82442 +{
82443 + return default_addr_space_legitimize_address(x, oldx, mode, as);
82444 +}
82445 +
82446 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
82447 +{
82448 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
82449 + return true;
82450 +
82451 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
82452 + return true;
82453 +
82454 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
82455 + return true;
82456 +
82457 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
82458 + return true;
82459 +
82460 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
82461 + return true;
82462 +
82463 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
82464 + return true;
82465 +
82466 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
82467 + return true;
82468 +
82469 + return subset == superset;
82470 +}
82471 +
82472 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
82473 +{
82474 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
82475 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
82476 +
82477 + return op;
82478 +}
82479 +
82480 +static void register_checker_address_spaces(void *event_data, void *data)
82481 +{
82482 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
82483 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
82484 + c_register_addr_space("__user", ADDR_SPACE_USER);
82485 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
82486 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
82487 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
82488 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
82489 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
82490 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
82491 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
82492 +
82493 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
82494 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
82495 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
82496 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
82497 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
82498 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
82499 + targetm.addr_space.convert = checker_addr_space_convert;
82500 +}
82501 +
82502 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82503 +{
82504 + const char * const plugin_name = plugin_info->base_name;
82505 + const int argc = plugin_info->argc;
82506 + const struct plugin_argument * const argv = plugin_info->argv;
82507 + int i;
82508 +
82509 + if (!plugin_default_version_check(version, &gcc_version)) {
82510 + error(G_("incompatible gcc/plugin versions"));
82511 + return 1;
82512 + }
82513 +
82514 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
82515 +
82516 + for (i = 0; i < argc; ++i)
82517 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
82518 +
82519 + if (TARGET_64BIT == 0)
82520 + return 0;
82521 +
82522 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
82523 +
82524 + return 0;
82525 +}
82526 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
82527 new file mode 100644
82528 index 0000000..846aeb0
82529 --- /dev/null
82530 +++ b/tools/gcc/colorize_plugin.c
82531 @@ -0,0 +1,148 @@
82532 +/*
82533 + * Copyright 2012 by PaX Team <pageexec@freemail.hu>
82534 + * Licensed under the GPL v2
82535 + *
82536 + * Note: the choice of the license means that the compilation process is
82537 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82538 + * but for the kernel it doesn't matter since it doesn't link against
82539 + * any of the gcc libraries
82540 + *
82541 + * gcc plugin to colorize diagnostic output
82542 + *
82543 + */
82544 +
82545 +#include "gcc-plugin.h"
82546 +#include "config.h"
82547 +#include "system.h"
82548 +#include "coretypes.h"
82549 +#include "tree.h"
82550 +#include "tree-pass.h"
82551 +#include "flags.h"
82552 +#include "intl.h"
82553 +#include "toplev.h"
82554 +#include "plugin.h"
82555 +#include "diagnostic.h"
82556 +#include "plugin-version.h"
82557 +#include "tm.h"
82558 +
82559 +int plugin_is_GPL_compatible;
82560 +
82561 +static struct plugin_info colorize_plugin_info = {
82562 + .version = "201203092200",
82563 + .help = NULL,
82564 +};
82565 +
82566 +#define GREEN "\033[32m\033[2m"
82567 +#define LIGHTGREEN "\033[32m\033[1m"
82568 +#define YELLOW "\033[33m\033[2m"
82569 +#define LIGHTYELLOW "\033[33m\033[1m"
82570 +#define RED "\033[31m\033[2m"
82571 +#define LIGHTRED "\033[31m\033[1m"
82572 +#define BLUE "\033[34m\033[2m"
82573 +#define LIGHTBLUE "\033[34m\033[1m"
82574 +#define BRIGHT "\033[m\033[1m"
82575 +#define NORMAL "\033[m"
82576 +
82577 +static diagnostic_starter_fn old_starter;
82578 +static diagnostic_finalizer_fn old_finalizer;
82579 +
82580 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
82581 +{
82582 + const char *color;
82583 + char *newprefix;
82584 +
82585 + switch (diagnostic->kind) {
82586 + case DK_NOTE:
82587 + color = LIGHTBLUE;
82588 + break;
82589 +
82590 + case DK_PEDWARN:
82591 + case DK_WARNING:
82592 + color = LIGHTYELLOW;
82593 + break;
82594 +
82595 + case DK_ERROR:
82596 + case DK_FATAL:
82597 + case DK_ICE:
82598 + case DK_PERMERROR:
82599 + case DK_SORRY:
82600 + color = LIGHTRED;
82601 + break;
82602 +
82603 + default:
82604 + color = NORMAL;
82605 + }
82606 +
82607 + old_starter(context, diagnostic);
82608 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
82609 + return;
82610 + pp_destroy_prefix(context->printer);
82611 + pp_set_prefix(context->printer, newprefix);
82612 +}
82613 +
82614 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
82615 +{
82616 + old_finalizer(context, diagnostic);
82617 +}
82618 +
82619 +static void colorize_arm(void)
82620 +{
82621 + old_starter = diagnostic_starter(global_dc);
82622 + old_finalizer = diagnostic_finalizer(global_dc);
82623 +
82624 + diagnostic_starter(global_dc) = start_colorize;
82625 + diagnostic_finalizer(global_dc) = finalize_colorize;
82626 +}
82627 +
82628 +static unsigned int execute_colorize_rearm(void)
82629 +{
82630 + if (diagnostic_starter(global_dc) == start_colorize)
82631 + return 0;
82632 +
82633 + colorize_arm();
82634 + return 0;
82635 +}
82636 +
82637 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
82638 + .pass = {
82639 + .type = SIMPLE_IPA_PASS,
82640 + .name = "colorize_rearm",
82641 + .gate = NULL,
82642 + .execute = execute_colorize_rearm,
82643 + .sub = NULL,
82644 + .next = NULL,
82645 + .static_pass_number = 0,
82646 + .tv_id = TV_NONE,
82647 + .properties_required = 0,
82648 + .properties_provided = 0,
82649 + .properties_destroyed = 0,
82650 + .todo_flags_start = 0,
82651 + .todo_flags_finish = 0
82652 + }
82653 +};
82654 +
82655 +static void colorize_start_unit(void *gcc_data, void *user_data)
82656 +{
82657 + colorize_arm();
82658 +}
82659 +
82660 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82661 +{
82662 + const char * const plugin_name = plugin_info->base_name;
82663 + struct register_pass_info colorize_rearm_pass_info = {
82664 + .pass = &pass_ipa_colorize_rearm.pass,
82665 + .reference_pass_name = "*free_lang_data",
82666 + .ref_pass_instance_number = 1,
82667 + .pos_op = PASS_POS_INSERT_AFTER
82668 + };
82669 +
82670 + if (!plugin_default_version_check(version, &gcc_version)) {
82671 + error(G_("incompatible gcc/plugin versions"));
82672 + return 1;
82673 + }
82674 +
82675 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
82676 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
82677 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
82678 + return 0;
82679 +}
82680 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
82681 new file mode 100644
82682 index 0000000..92ed719
82683 --- /dev/null
82684 +++ b/tools/gcc/constify_plugin.c
82685 @@ -0,0 +1,331 @@
82686 +/*
82687 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
82688 + * Copyright 2011 by PaX Team <pageexec@freemail.hu>
82689 + * Licensed under the GPL v2, or (at your option) v3
82690 + *
82691 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
82692 + *
82693 + * Homepage:
82694 + * http://www.grsecurity.net/~ephox/const_plugin/
82695 + *
82696 + * Usage:
82697 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
82698 + * $ gcc -fplugin=constify_plugin.so test.c -O2
82699 + */
82700 +
82701 +#include "gcc-plugin.h"
82702 +#include "config.h"
82703 +#include "system.h"
82704 +#include "coretypes.h"
82705 +#include "tree.h"
82706 +#include "tree-pass.h"
82707 +#include "flags.h"
82708 +#include "intl.h"
82709 +#include "toplev.h"
82710 +#include "plugin.h"
82711 +#include "diagnostic.h"
82712 +#include "plugin-version.h"
82713 +#include "tm.h"
82714 +#include "function.h"
82715 +#include "basic-block.h"
82716 +#include "gimple.h"
82717 +#include "rtl.h"
82718 +#include "emit-rtl.h"
82719 +#include "tree-flow.h"
82720 +
82721 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
82722 +
82723 +int plugin_is_GPL_compatible;
82724 +
82725 +static struct plugin_info const_plugin_info = {
82726 + .version = "201205300030",
82727 + .help = "no-constify\tturn off constification\n",
82728 +};
82729 +
82730 +static void deconstify_tree(tree node);
82731 +
82732 +static void deconstify_type(tree type)
82733 +{
82734 + tree field;
82735 +
82736 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
82737 + tree type = TREE_TYPE(field);
82738 +
82739 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
82740 + continue;
82741 + if (!TYPE_READONLY(type))
82742 + continue;
82743 +
82744 + deconstify_tree(field);
82745 + }
82746 + TYPE_READONLY(type) = 0;
82747 + C_TYPE_FIELDS_READONLY(type) = 0;
82748 +}
82749 +
82750 +static void deconstify_tree(tree node)
82751 +{
82752 + tree old_type, new_type, field;
82753 +
82754 + old_type = TREE_TYPE(node);
82755 +
82756 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
82757 +
82758 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
82759 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
82760 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
82761 + DECL_FIELD_CONTEXT(field) = new_type;
82762 +
82763 + deconstify_type(new_type);
82764 +
82765 + TREE_READONLY(node) = 0;
82766 + TREE_TYPE(node) = new_type;
82767 +}
82768 +
82769 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
82770 +{
82771 + tree type;
82772 +
82773 + *no_add_attrs = true;
82774 + if (TREE_CODE(*node) == FUNCTION_DECL) {
82775 + error("%qE attribute does not apply to functions", name);
82776 + return NULL_TREE;
82777 + }
82778 +
82779 + if (TREE_CODE(*node) == VAR_DECL) {
82780 + error("%qE attribute does not apply to variables", name);
82781 + return NULL_TREE;
82782 + }
82783 +
82784 + if (TYPE_P(*node)) {
82785 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
82786 + *no_add_attrs = false;
82787 + else
82788 + error("%qE attribute applies to struct and union types only", name);
82789 + return NULL_TREE;
82790 + }
82791 +
82792 + type = TREE_TYPE(*node);
82793 +
82794 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
82795 + error("%qE attribute applies to struct and union types only", name);
82796 + return NULL_TREE;
82797 + }
82798 +
82799 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
82800 + error("%qE attribute is already applied to the type", name);
82801 + return NULL_TREE;
82802 + }
82803 +
82804 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
82805 + error("%qE attribute used on type that is not constified", name);
82806 + return NULL_TREE;
82807 + }
82808 +
82809 + if (TREE_CODE(*node) == TYPE_DECL) {
82810 + deconstify_tree(*node);
82811 + return NULL_TREE;
82812 + }
82813 +
82814 + return NULL_TREE;
82815 +}
82816 +
82817 +static void constify_type(tree type)
82818 +{
82819 + TYPE_READONLY(type) = 1;
82820 + C_TYPE_FIELDS_READONLY(type) = 1;
82821 +}
82822 +
82823 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
82824 +{
82825 + *no_add_attrs = true;
82826 + if (!TYPE_P(*node)) {
82827 + error("%qE attribute applies to types only", name);
82828 + return NULL_TREE;
82829 + }
82830 +
82831 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
82832 + error("%qE attribute applies to struct and union types only", name);
82833 + return NULL_TREE;
82834 + }
82835 +
82836 + *no_add_attrs = false;
82837 + constify_type(*node);
82838 + return NULL_TREE;
82839 +}
82840 +
82841 +static struct attribute_spec no_const_attr = {
82842 + .name = "no_const",
82843 + .min_length = 0,
82844 + .max_length = 0,
82845 + .decl_required = false,
82846 + .type_required = false,
82847 + .function_type_required = false,
82848 + .handler = handle_no_const_attribute,
82849 +#if BUILDING_GCC_VERSION >= 4007
82850 + .affects_type_identity = true
82851 +#endif
82852 +};
82853 +
82854 +static struct attribute_spec do_const_attr = {
82855 + .name = "do_const",
82856 + .min_length = 0,
82857 + .max_length = 0,
82858 + .decl_required = false,
82859 + .type_required = false,
82860 + .function_type_required = false,
82861 + .handler = handle_do_const_attribute,
82862 +#if BUILDING_GCC_VERSION >= 4007
82863 + .affects_type_identity = true
82864 +#endif
82865 +};
82866 +
82867 +static void register_attributes(void *event_data, void *data)
82868 +{
82869 + register_attribute(&no_const_attr);
82870 + register_attribute(&do_const_attr);
82871 +}
82872 +
82873 +static bool is_fptr(tree field)
82874 +{
82875 + tree ptr = TREE_TYPE(field);
82876 +
82877 + if (TREE_CODE(ptr) != POINTER_TYPE)
82878 + return false;
82879 +
82880 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
82881 +}
82882 +
82883 +static bool walk_struct(tree node)
82884 +{
82885 + tree field;
82886 +
82887 + if (TYPE_FIELDS(node) == NULL_TREE)
82888 + return false;
82889 +
82890 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
82891 + gcc_assert(!TYPE_READONLY(node));
82892 + deconstify_type(node);
82893 + return false;
82894 + }
82895 +
82896 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
82897 + tree type = TREE_TYPE(field);
82898 + enum tree_code code = TREE_CODE(type);
82899 +
82900 + if (node == type)
82901 + return false;
82902 + if (code == RECORD_TYPE || code == UNION_TYPE) {
82903 + if (!(walk_struct(type)))
82904 + return false;
82905 + } else if (!is_fptr(field) && !TREE_READONLY(field))
82906 + return false;
82907 + }
82908 + return true;
82909 +}
82910 +
82911 +static void finish_type(void *event_data, void *data)
82912 +{
82913 + tree type = (tree)event_data;
82914 +
82915 + if (type == NULL_TREE || type == error_mark_node)
82916 + return;
82917 +
82918 + if (TYPE_READONLY(type))
82919 + return;
82920 +
82921 + if (walk_struct(type))
82922 + constify_type(type);
82923 +}
82924 +
82925 +static unsigned int check_local_variables(void);
82926 +
82927 +struct gimple_opt_pass pass_local_variable = {
82928 + {
82929 + .type = GIMPLE_PASS,
82930 + .name = "check_local_variables",
82931 + .gate = NULL,
82932 + .execute = check_local_variables,
82933 + .sub = NULL,
82934 + .next = NULL,
82935 + .static_pass_number = 0,
82936 + .tv_id = TV_NONE,
82937 + .properties_required = 0,
82938 + .properties_provided = 0,
82939 + .properties_destroyed = 0,
82940 + .todo_flags_start = 0,
82941 + .todo_flags_finish = 0
82942 + }
82943 +};
82944 +
82945 +static unsigned int check_local_variables(void)
82946 +{
82947 + tree var;
82948 + referenced_var_iterator rvi;
82949 +
82950 +#if BUILDING_GCC_VERSION == 4005
82951 + FOR_EACH_REFERENCED_VAR(var, rvi) {
82952 +#else
82953 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
82954 +#endif
82955 + tree type = TREE_TYPE(var);
82956 +
82957 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
82958 + continue;
82959 +
82960 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
82961 + continue;
82962 +
82963 + if (!TYPE_READONLY(type))
82964 + continue;
82965 +
82966 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
82967 +// continue;
82968 +
82969 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
82970 +// continue;
82971 +
82972 + if (walk_struct(type)) {
82973 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
82974 + return 1;
82975 + }
82976 + }
82977 + return 0;
82978 +}
82979 +
82980 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82981 +{
82982 + const char * const plugin_name = plugin_info->base_name;
82983 + const int argc = plugin_info->argc;
82984 + const struct plugin_argument * const argv = plugin_info->argv;
82985 + int i;
82986 + bool constify = true;
82987 +
82988 + struct register_pass_info local_variable_pass_info = {
82989 + .pass = &pass_local_variable.pass,
82990 + .reference_pass_name = "*referenced_vars",
82991 + .ref_pass_instance_number = 1,
82992 + .pos_op = PASS_POS_INSERT_AFTER
82993 + };
82994 +
82995 + if (!plugin_default_version_check(version, &gcc_version)) {
82996 + error(G_("incompatible gcc/plugin versions"));
82997 + return 1;
82998 + }
82999 +
83000 + for (i = 0; i < argc; ++i) {
83001 + if (!(strcmp(argv[i].key, "no-constify"))) {
83002 + constify = false;
83003 + continue;
83004 + }
83005 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
83006 + }
83007 +
83008 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
83009 + if (constify) {
83010 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
83011 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
83012 + }
83013 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
83014 +
83015 + return 0;
83016 +}
83017 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
83018 new file mode 100644
83019 index 0000000..02c6bec
83020 --- /dev/null
83021 +++ b/tools/gcc/generate_size_overflow_hash.sh
83022 @@ -0,0 +1,94 @@
83023 +#!/bin/bash
83024 +
83025 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
83026 +
83027 +header1="size_overflow_hash.h"
83028 +database="size_overflow_hash.data"
83029 +n=65536
83030 +
83031 +usage() {
83032 +cat <<EOF
83033 +usage: $0 options
83034 +OPTIONS:
83035 + -h|--help help
83036 + -o header file
83037 + -d database file
83038 + -n hash array size
83039 +EOF
83040 + return 0
83041 +}
83042 +
83043 +while true
83044 +do
83045 + case "$1" in
83046 + -h|--help) usage && exit 0;;
83047 + -n) n=$2; shift 2;;
83048 + -o) header1="$2"; shift 2;;
83049 + -d) database="$2"; shift 2;;
83050 + --) shift 1; break ;;
83051 + *) break ;;
83052 + esac
83053 +done
83054 +
83055 +create_defines() {
83056 + for i in `seq 1 32`
83057 + do
83058 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
83059 + done
83060 + echo >> "$header1"
83061 +}
83062 +
83063 +create_structs () {
83064 + rm -f "$header1"
83065 +
83066 + create_defines
83067 +
83068 + cat "$database" | while read data
83069 + do
83070 + data_array=($data)
83071 + struct_hash_name="${data_array[0]}"
83072 + funcn="${data_array[1]}"
83073 + params="${data_array[2]}"
83074 + next="${data_array[5]}"
83075 +
83076 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
83077 +
83078 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
83079 + echo -en "\t.param\t= " >> "$header1"
83080 + line=
83081 + for param_num in ${params//-/ };
83082 + do
83083 + line="${line}PARAM"$param_num"|"
83084 + done
83085 +
83086 + echo -e "${line%?},\n};\n" >> "$header1"
83087 + done
83088 +}
83089 +
83090 +create_headers () {
83091 + echo "const struct size_overflow_hash * const size_overflow_hash[$n] = {" >> "$header1"
83092 +}
83093 +
83094 +create_array_elements () {
83095 + index=0
83096 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
83097 + do
83098 + data_array=($data)
83099 + i="${data_array[3]}"
83100 + hash="${data_array[4]}"
83101 + while [[ $index -lt $i ]]
83102 + do
83103 + echo -e "\t["$index"]\t= NULL," >> "$header1"
83104 + index=$(($index + 1))
83105 + done
83106 + index=$(($index + 1))
83107 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
83108 + done
83109 + echo '};' >> $header1
83110 +}
83111 +
83112 +create_structs
83113 +create_headers
83114 +create_array_elements
83115 +
83116 +exit 0
83117 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
83118 new file mode 100644
83119 index 0000000..a86e422
83120 --- /dev/null
83121 +++ b/tools/gcc/kallocstat_plugin.c
83122 @@ -0,0 +1,167 @@
83123 +/*
83124 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
83125 + * Licensed under the GPL v2
83126 + *
83127 + * Note: the choice of the license means that the compilation process is
83128 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
83129 + * but for the kernel it doesn't matter since it doesn't link against
83130 + * any of the gcc libraries
83131 + *
83132 + * gcc plugin to find the distribution of k*alloc sizes
83133 + *
83134 + * TODO:
83135 + *
83136 + * BUGS:
83137 + * - none known
83138 + */
83139 +#include "gcc-plugin.h"
83140 +#include "config.h"
83141 +#include "system.h"
83142 +#include "coretypes.h"
83143 +#include "tree.h"
83144 +#include "tree-pass.h"
83145 +#include "flags.h"
83146 +#include "intl.h"
83147 +#include "toplev.h"
83148 +#include "plugin.h"
83149 +//#include "expr.h" where are you...
83150 +#include "diagnostic.h"
83151 +#include "plugin-version.h"
83152 +#include "tm.h"
83153 +#include "function.h"
83154 +#include "basic-block.h"
83155 +#include "gimple.h"
83156 +#include "rtl.h"
83157 +#include "emit-rtl.h"
83158 +
83159 +extern void print_gimple_stmt(FILE *, gimple, int, int);
83160 +
83161 +int plugin_is_GPL_compatible;
83162 +
83163 +static const char * const kalloc_functions[] = {
83164 + "__kmalloc",
83165 + "kmalloc",
83166 + "kmalloc_large",
83167 + "kmalloc_node",
83168 + "kmalloc_order",
83169 + "kmalloc_order_trace",
83170 + "kmalloc_slab",
83171 + "kzalloc",
83172 + "kzalloc_node",
83173 +};
83174 +
83175 +static struct plugin_info kallocstat_plugin_info = {
83176 + .version = "201111150100",
83177 +};
83178 +
83179 +static unsigned int execute_kallocstat(void);
83180 +
83181 +static struct gimple_opt_pass kallocstat_pass = {
83182 + .pass = {
83183 + .type = GIMPLE_PASS,
83184 + .name = "kallocstat",
83185 + .gate = NULL,
83186 + .execute = execute_kallocstat,
83187 + .sub = NULL,
83188 + .next = NULL,
83189 + .static_pass_number = 0,
83190 + .tv_id = TV_NONE,
83191 + .properties_required = 0,
83192 + .properties_provided = 0,
83193 + .properties_destroyed = 0,
83194 + .todo_flags_start = 0,
83195 + .todo_flags_finish = 0
83196 + }
83197 +};
83198 +
83199 +static bool is_kalloc(const char *fnname)
83200 +{
83201 + size_t i;
83202 +
83203 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
83204 + if (!strcmp(fnname, kalloc_functions[i]))
83205 + return true;
83206 + return false;
83207 +}
83208 +
83209 +static unsigned int execute_kallocstat(void)
83210 +{
83211 + basic_block bb;
83212 +
83213 + // 1. loop through BBs and GIMPLE statements
83214 + FOR_EACH_BB(bb) {
83215 + gimple_stmt_iterator gsi;
83216 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
83217 + // gimple match:
83218 + tree fndecl, size;
83219 + gimple call_stmt;
83220 + const char *fnname;
83221 +
83222 + // is it a call
83223 + call_stmt = gsi_stmt(gsi);
83224 + if (!is_gimple_call(call_stmt))
83225 + continue;
83226 + fndecl = gimple_call_fndecl(call_stmt);
83227 + if (fndecl == NULL_TREE)
83228 + continue;
83229 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
83230 + continue;
83231 +
83232 + // is it a call to k*alloc
83233 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
83234 + if (!is_kalloc(fnname))
83235 + continue;
83236 +
83237 + // is the size arg the result of a simple const assignment
83238 + size = gimple_call_arg(call_stmt, 0);
83239 + while (true) {
83240 + gimple def_stmt;
83241 + expanded_location xloc;
83242 + size_t size_val;
83243 +
83244 + if (TREE_CODE(size) != SSA_NAME)
83245 + break;
83246 + def_stmt = SSA_NAME_DEF_STMT(size);
83247 + if (!def_stmt || !is_gimple_assign(def_stmt))
83248 + break;
83249 + if (gimple_num_ops(def_stmt) != 2)
83250 + break;
83251 + size = gimple_assign_rhs1(def_stmt);
83252 + if (!TREE_CONSTANT(size))
83253 + continue;
83254 + xloc = expand_location(gimple_location(def_stmt));
83255 + if (!xloc.file)
83256 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
83257 + size_val = TREE_INT_CST_LOW(size);
83258 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
83259 + break;
83260 + }
83261 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
83262 +//debug_tree(gimple_call_fn(call_stmt));
83263 +//print_node(stderr, "pax", fndecl, 4);
83264 + }
83265 + }
83266 +
83267 + return 0;
83268 +}
83269 +
83270 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83271 +{
83272 + const char * const plugin_name = plugin_info->base_name;
83273 + struct register_pass_info kallocstat_pass_info = {
83274 + .pass = &kallocstat_pass.pass,
83275 + .reference_pass_name = "ssa",
83276 + .ref_pass_instance_number = 1,
83277 + .pos_op = PASS_POS_INSERT_AFTER
83278 + };
83279 +
83280 + if (!plugin_default_version_check(version, &gcc_version)) {
83281 + error(G_("incompatible gcc/plugin versions"));
83282 + return 1;
83283 + }
83284 +
83285 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
83286 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
83287 +
83288 + return 0;
83289 +}
83290 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
83291 new file mode 100644
83292 index 0000000..98011fa
83293 --- /dev/null
83294 +++ b/tools/gcc/kernexec_plugin.c
83295 @@ -0,0 +1,427 @@
83296 +/*
83297 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
83298 + * Licensed under the GPL v2
83299 + *
83300 + * Note: the choice of the license means that the compilation process is
83301 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
83302 + * but for the kernel it doesn't matter since it doesn't link against
83303 + * any of the gcc libraries
83304 + *
83305 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
83306 + *
83307 + * TODO:
83308 + *
83309 + * BUGS:
83310 + * - none known
83311 + */
83312 +#include "gcc-plugin.h"
83313 +#include "config.h"
83314 +#include "system.h"
83315 +#include "coretypes.h"
83316 +#include "tree.h"
83317 +#include "tree-pass.h"
83318 +#include "flags.h"
83319 +#include "intl.h"
83320 +#include "toplev.h"
83321 +#include "plugin.h"
83322 +//#include "expr.h" where are you...
83323 +#include "diagnostic.h"
83324 +#include "plugin-version.h"
83325 +#include "tm.h"
83326 +#include "function.h"
83327 +#include "basic-block.h"
83328 +#include "gimple.h"
83329 +#include "rtl.h"
83330 +#include "emit-rtl.h"
83331 +#include "tree-flow.h"
83332 +
83333 +extern void print_gimple_stmt(FILE *, gimple, int, int);
83334 +extern rtx emit_move_insn(rtx x, rtx y);
83335 +
83336 +int plugin_is_GPL_compatible;
83337 +
83338 +static struct plugin_info kernexec_plugin_info = {
83339 + .version = "201111291120",
83340 + .help = "method=[bts|or]\tinstrumentation method\n"
83341 +};
83342 +
83343 +static unsigned int execute_kernexec_reload(void);
83344 +static unsigned int execute_kernexec_fptr(void);
83345 +static unsigned int execute_kernexec_retaddr(void);
83346 +static bool kernexec_cmodel_check(void);
83347 +
83348 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
83349 +static void (*kernexec_instrument_retaddr)(rtx);
83350 +
83351 +static struct gimple_opt_pass kernexec_reload_pass = {
83352 + .pass = {
83353 + .type = GIMPLE_PASS,
83354 + .name = "kernexec_reload",
83355 + .gate = kernexec_cmodel_check,
83356 + .execute = execute_kernexec_reload,
83357 + .sub = NULL,
83358 + .next = NULL,
83359 + .static_pass_number = 0,
83360 + .tv_id = TV_NONE,
83361 + .properties_required = 0,
83362 + .properties_provided = 0,
83363 + .properties_destroyed = 0,
83364 + .todo_flags_start = 0,
83365 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
83366 + }
83367 +};
83368 +
83369 +static struct gimple_opt_pass kernexec_fptr_pass = {
83370 + .pass = {
83371 + .type = GIMPLE_PASS,
83372 + .name = "kernexec_fptr",
83373 + .gate = kernexec_cmodel_check,
83374 + .execute = execute_kernexec_fptr,
83375 + .sub = NULL,
83376 + .next = NULL,
83377 + .static_pass_number = 0,
83378 + .tv_id = TV_NONE,
83379 + .properties_required = 0,
83380 + .properties_provided = 0,
83381 + .properties_destroyed = 0,
83382 + .todo_flags_start = 0,
83383 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
83384 + }
83385 +};
83386 +
83387 +static struct rtl_opt_pass kernexec_retaddr_pass = {
83388 + .pass = {
83389 + .type = RTL_PASS,
83390 + .name = "kernexec_retaddr",
83391 + .gate = kernexec_cmodel_check,
83392 + .execute = execute_kernexec_retaddr,
83393 + .sub = NULL,
83394 + .next = NULL,
83395 + .static_pass_number = 0,
83396 + .tv_id = TV_NONE,
83397 + .properties_required = 0,
83398 + .properties_provided = 0,
83399 + .properties_destroyed = 0,
83400 + .todo_flags_start = 0,
83401 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
83402 + }
83403 +};
83404 +
83405 +static bool kernexec_cmodel_check(void)
83406 +{
83407 + tree section;
83408 +
83409 + if (ix86_cmodel != CM_KERNEL)
83410 + return false;
83411 +
83412 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
83413 + if (!section || !TREE_VALUE(section))
83414 + return true;
83415 +
83416 + section = TREE_VALUE(TREE_VALUE(section));
83417 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
83418 + return true;
83419 +
83420 + return false;
83421 +}
83422 +
83423 +/*
83424 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
83425 + */
83426 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
83427 +{
83428 + gimple asm_movabs_stmt;
83429 +
83430 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
83431 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
83432 + gimple_asm_set_volatile(asm_movabs_stmt, true);
83433 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
83434 + update_stmt(asm_movabs_stmt);
83435 +}
83436 +
83437 +/*
83438 + * find all asm() stmts that clobber r10 and add a reload of r10
83439 + */
83440 +static unsigned int execute_kernexec_reload(void)
83441 +{
83442 + basic_block bb;
83443 +
83444 + // 1. loop through BBs and GIMPLE statements
83445 + FOR_EACH_BB(bb) {
83446 + gimple_stmt_iterator gsi;
83447 +
83448 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
83449 + // gimple match: __asm__ ("" : : : "r10");
83450 + gimple asm_stmt;
83451 + size_t nclobbers;
83452 +
83453 + // is it an asm ...
83454 + asm_stmt = gsi_stmt(gsi);
83455 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
83456 + continue;
83457 +
83458 + // ... clobbering r10
83459 + nclobbers = gimple_asm_nclobbers(asm_stmt);
83460 + while (nclobbers--) {
83461 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
83462 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
83463 + continue;
83464 + kernexec_reload_fptr_mask(&gsi);
83465 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
83466 + break;
83467 + }
83468 + }
83469 + }
83470 +
83471 + return 0;
83472 +}
83473 +
83474 +/*
83475 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
83476 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
83477 + */
83478 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
83479 +{
83480 + gimple assign_intptr, assign_new_fptr, call_stmt;
83481 + tree intptr, old_fptr, new_fptr, kernexec_mask;
83482 +
83483 + call_stmt = gsi_stmt(*gsi);
83484 + old_fptr = gimple_call_fn(call_stmt);
83485 +
83486 + // create temporary unsigned long variable used for bitops and cast fptr to it
83487 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
83488 + add_referenced_var(intptr);
83489 + mark_sym_for_renaming(intptr);
83490 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
83491 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
83492 + update_stmt(assign_intptr);
83493 +
83494 + // apply logical or to temporary unsigned long and bitmask
83495 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
83496 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
83497 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
83498 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
83499 + update_stmt(assign_intptr);
83500 +
83501 + // cast temporary unsigned long back to a temporary fptr variable
83502 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
83503 + add_referenced_var(new_fptr);
83504 + mark_sym_for_renaming(new_fptr);
83505 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
83506 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
83507 + update_stmt(assign_new_fptr);
83508 +
83509 + // replace call stmt fn with the new fptr
83510 + gimple_call_set_fn(call_stmt, new_fptr);
83511 + update_stmt(call_stmt);
83512 +}
83513 +
83514 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
83515 +{
83516 + gimple asm_or_stmt, call_stmt;
83517 + tree old_fptr, new_fptr, input, output;
83518 + VEC(tree, gc) *inputs = NULL;
83519 + VEC(tree, gc) *outputs = NULL;
83520 +
83521 + call_stmt = gsi_stmt(*gsi);
83522 + old_fptr = gimple_call_fn(call_stmt);
83523 +
83524 + // create temporary fptr variable
83525 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
83526 + add_referenced_var(new_fptr);
83527 + mark_sym_for_renaming(new_fptr);
83528 +
83529 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
83530 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
83531 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
83532 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
83533 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
83534 + VEC_safe_push(tree, gc, inputs, input);
83535 + VEC_safe_push(tree, gc, outputs, output);
83536 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
83537 + gimple_asm_set_volatile(asm_or_stmt, true);
83538 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
83539 + update_stmt(asm_or_stmt);
83540 +
83541 + // replace call stmt fn with the new fptr
83542 + gimple_call_set_fn(call_stmt, new_fptr);
83543 + update_stmt(call_stmt);
83544 +}
83545 +
83546 +/*
83547 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
83548 + */
83549 +static unsigned int execute_kernexec_fptr(void)
83550 +{
83551 + basic_block bb;
83552 +
83553 + // 1. loop through BBs and GIMPLE statements
83554 + FOR_EACH_BB(bb) {
83555 + gimple_stmt_iterator gsi;
83556 +
83557 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
83558 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
83559 + tree fn;
83560 + gimple call_stmt;
83561 +
83562 + // is it a call ...
83563 + call_stmt = gsi_stmt(gsi);
83564 + if (!is_gimple_call(call_stmt))
83565 + continue;
83566 + fn = gimple_call_fn(call_stmt);
83567 + if (TREE_CODE(fn) == ADDR_EXPR)
83568 + continue;
83569 + if (TREE_CODE(fn) != SSA_NAME)
83570 + gcc_unreachable();
83571 +
83572 + // ... through a function pointer
83573 + fn = SSA_NAME_VAR(fn);
83574 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
83575 + continue;
83576 + fn = TREE_TYPE(fn);
83577 + if (TREE_CODE(fn) != POINTER_TYPE)
83578 + continue;
83579 + fn = TREE_TYPE(fn);
83580 + if (TREE_CODE(fn) != FUNCTION_TYPE)
83581 + continue;
83582 +
83583 + kernexec_instrument_fptr(&gsi);
83584 +
83585 +//debug_tree(gimple_call_fn(call_stmt));
83586 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
83587 + }
83588 + }
83589 +
83590 + return 0;
83591 +}
83592 +
83593 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
83594 +static void kernexec_instrument_retaddr_bts(rtx insn)
83595 +{
83596 + rtx btsq;
83597 + rtvec argvec, constraintvec, labelvec;
83598 + int line;
83599 +
83600 + // create asm volatile("btsq $63,(%%rsp)":::)
83601 + argvec = rtvec_alloc(0);
83602 + constraintvec = rtvec_alloc(0);
83603 + labelvec = rtvec_alloc(0);
83604 + line = expand_location(RTL_LOCATION(insn)).line;
83605 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
83606 + MEM_VOLATILE_P(btsq) = 1;
83607 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
83608 + emit_insn_before(btsq, insn);
83609 +}
83610 +
83611 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
83612 +static void kernexec_instrument_retaddr_or(rtx insn)
83613 +{
83614 + rtx orq;
83615 + rtvec argvec, constraintvec, labelvec;
83616 + int line;
83617 +
83618 + // create asm volatile("orq %%r10,(%%rsp)":::)
83619 + argvec = rtvec_alloc(0);
83620 + constraintvec = rtvec_alloc(0);
83621 + labelvec = rtvec_alloc(0);
83622 + line = expand_location(RTL_LOCATION(insn)).line;
83623 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
83624 + MEM_VOLATILE_P(orq) = 1;
83625 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
83626 + emit_insn_before(orq, insn);
83627 +}
83628 +
83629 +/*
83630 + * find all asm level function returns and forcibly set the highest bit of the return address
83631 + */
83632 +static unsigned int execute_kernexec_retaddr(void)
83633 +{
83634 + rtx insn;
83635 +
83636 + // 1. find function returns
83637 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
83638 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
83639 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
83640 + rtx body;
83641 +
83642 + // is it a retn
83643 + if (!JUMP_P(insn))
83644 + continue;
83645 + body = PATTERN(insn);
83646 + if (GET_CODE(body) == PARALLEL)
83647 + body = XVECEXP(body, 0, 0);
83648 + if (GET_CODE(body) != RETURN)
83649 + continue;
83650 + kernexec_instrument_retaddr(insn);
83651 + }
83652 +
83653 +// print_simple_rtl(stderr, get_insns());
83654 +// print_rtl(stderr, get_insns());
83655 +
83656 + return 0;
83657 +}
83658 +
83659 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83660 +{
83661 + const char * const plugin_name = plugin_info->base_name;
83662 + const int argc = plugin_info->argc;
83663 + const struct plugin_argument * const argv = plugin_info->argv;
83664 + int i;
83665 + struct register_pass_info kernexec_reload_pass_info = {
83666 + .pass = &kernexec_reload_pass.pass,
83667 + .reference_pass_name = "ssa",
83668 + .ref_pass_instance_number = 1,
83669 + .pos_op = PASS_POS_INSERT_AFTER
83670 + };
83671 + struct register_pass_info kernexec_fptr_pass_info = {
83672 + .pass = &kernexec_fptr_pass.pass,
83673 + .reference_pass_name = "ssa",
83674 + .ref_pass_instance_number = 1,
83675 + .pos_op = PASS_POS_INSERT_AFTER
83676 + };
83677 + struct register_pass_info kernexec_retaddr_pass_info = {
83678 + .pass = &kernexec_retaddr_pass.pass,
83679 + .reference_pass_name = "pro_and_epilogue",
83680 + .ref_pass_instance_number = 1,
83681 + .pos_op = PASS_POS_INSERT_AFTER
83682 + };
83683 +
83684 + if (!plugin_default_version_check(version, &gcc_version)) {
83685 + error(G_("incompatible gcc/plugin versions"));
83686 + return 1;
83687 + }
83688 +
83689 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
83690 +
83691 + if (TARGET_64BIT == 0)
83692 + return 0;
83693 +
83694 + for (i = 0; i < argc; ++i) {
83695 + if (!strcmp(argv[i].key, "method")) {
83696 + if (!argv[i].value) {
83697 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
83698 + continue;
83699 + }
83700 + if (!strcmp(argv[i].value, "bts")) {
83701 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
83702 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
83703 + } else if (!strcmp(argv[i].value, "or")) {
83704 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
83705 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
83706 + fix_register("r10", 1, 1);
83707 + } else
83708 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
83709 + continue;
83710 + }
83711 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
83712 + }
83713 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
83714 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
83715 +
83716 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
83717 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
83718 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
83719 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
83720 +
83721 + return 0;
83722 +}
83723 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
83724 new file mode 100644
83725 index 0000000..b8008f7
83726 --- /dev/null
83727 +++ b/tools/gcc/latent_entropy_plugin.c
83728 @@ -0,0 +1,295 @@
83729 +/*
83730 + * Copyright 2012 by the PaX Team <pageexec@freemail.hu>
83731 + * Licensed under the GPL v2
83732 + *
83733 + * Note: the choice of the license means that the compilation process is
83734 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
83735 + * but for the kernel it doesn't matter since it doesn't link against
83736 + * any of the gcc libraries
83737 + *
83738 + * gcc plugin to help generate a little bit of entropy from program state,
83739 + * used during boot in the kernel
83740 + *
83741 + * TODO:
83742 + * - add ipa pass to identify not explicitly marked candidate functions
83743 + * - mix in more program state (function arguments/return values, loop variables, etc)
83744 + * - more instrumentation control via attribute parameters
83745 + *
83746 + * BUGS:
83747 + * - LTO needs -flto-partition=none for now
83748 + */
83749 +#include "gcc-plugin.h"
83750 +#include "config.h"
83751 +#include "system.h"
83752 +#include "coretypes.h"
83753 +#include "tree.h"
83754 +#include "tree-pass.h"
83755 +#include "flags.h"
83756 +#include "intl.h"
83757 +#include "toplev.h"
83758 +#include "plugin.h"
83759 +//#include "expr.h" where are you...
83760 +#include "diagnostic.h"
83761 +#include "plugin-version.h"
83762 +#include "tm.h"
83763 +#include "function.h"
83764 +#include "basic-block.h"
83765 +#include "gimple.h"
83766 +#include "rtl.h"
83767 +#include "emit-rtl.h"
83768 +#include "tree-flow.h"
83769 +
83770 +int plugin_is_GPL_compatible;
83771 +
83772 +static tree latent_entropy_decl;
83773 +
83774 +static struct plugin_info latent_entropy_plugin_info = {
83775 + .version = "201207271820",
83776 + .help = NULL
83777 +};
83778 +
83779 +static unsigned int execute_latent_entropy(void);
83780 +static bool gate_latent_entropy(void);
83781 +
83782 +static struct gimple_opt_pass latent_entropy_pass = {
83783 + .pass = {
83784 + .type = GIMPLE_PASS,
83785 + .name = "latent_entropy",
83786 + .gate = gate_latent_entropy,
83787 + .execute = execute_latent_entropy,
83788 + .sub = NULL,
83789 + .next = NULL,
83790 + .static_pass_number = 0,
83791 + .tv_id = TV_NONE,
83792 + .properties_required = PROP_gimple_leh | PROP_cfg,
83793 + .properties_provided = 0,
83794 + .properties_destroyed = 0,
83795 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
83796 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
83797 + }
83798 +};
83799 +
83800 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
83801 +{
83802 + if (TREE_CODE(*node) != FUNCTION_DECL) {
83803 + *no_add_attrs = true;
83804 + error("%qE attribute only applies to functions", name);
83805 + }
83806 + return NULL_TREE;
83807 +}
83808 +
83809 +static struct attribute_spec latent_entropy_attr = {
83810 + .name = "latent_entropy",
83811 + .min_length = 0,
83812 + .max_length = 0,
83813 + .decl_required = true,
83814 + .type_required = false,
83815 + .function_type_required = false,
83816 + .handler = handle_latent_entropy_attribute,
83817 +#if BUILDING_GCC_VERSION >= 4007
83818 + .affects_type_identity = false
83819 +#endif
83820 +};
83821 +
83822 +static void register_attributes(void *event_data, void *data)
83823 +{
83824 + register_attribute(&latent_entropy_attr);
83825 +}
83826 +
83827 +static bool gate_latent_entropy(void)
83828 +{
83829 + tree latent_entropy_attr;
83830 +
83831 + latent_entropy_attr = lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl));
83832 + return latent_entropy_attr != NULL_TREE;
83833 +}
83834 +
83835 +static unsigned HOST_WIDE_INT seed;
83836 +static unsigned HOST_WIDE_INT get_random_const(void)
83837 +{
83838 + seed = (seed >> 1U) ^ (-(seed & 1ULL) & 0xD800000000000000ULL);
83839 + return seed;
83840 +}
83841 +
83842 +static enum tree_code get_op(tree *rhs)
83843 +{
83844 + static enum tree_code op;
83845 + unsigned HOST_WIDE_INT random_const;
83846 +
83847 + random_const = get_random_const();
83848 +
83849 + switch (op) {
83850 + case BIT_XOR_EXPR:
83851 + op = PLUS_EXPR;
83852 + break;
83853 +
83854 + case PLUS_EXPR:
83855 + if (rhs) {
83856 + op = LROTATE_EXPR;
83857 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
83858 + break;
83859 + }
83860 +
83861 + case LROTATE_EXPR:
83862 + default:
83863 + op = BIT_XOR_EXPR;
83864 + break;
83865 + }
83866 + if (rhs)
83867 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
83868 + return op;
83869 +}
83870 +
83871 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
83872 +{
83873 + gimple_stmt_iterator gsi;
83874 + gimple assign;
83875 + tree addxorrol, rhs;
83876 + enum tree_code op;
83877 +
83878 + op = get_op(&rhs);
83879 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
83880 + assign = gimple_build_assign(local_entropy, addxorrol);
83881 + find_referenced_vars_in(assign);
83882 +//debug_bb(bb);
83883 + gsi = gsi_after_labels(bb);
83884 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
83885 + update_stmt(assign);
83886 +}
83887 +
83888 +static void perturb_latent_entropy(basic_block bb, tree rhs)
83889 +{
83890 + gimple_stmt_iterator gsi;
83891 + gimple assign;
83892 + tree addxorrol, temp;
83893 +
83894 + // 1. create temporary copy of latent_entropy
83895 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
83896 + add_referenced_var(temp);
83897 + mark_sym_for_renaming(temp);
83898 +
83899 + // 2. read...
83900 + assign = gimple_build_assign(temp, latent_entropy_decl);
83901 + find_referenced_vars_in(assign);
83902 + gsi = gsi_after_labels(bb);
83903 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83904 + update_stmt(assign);
83905 +
83906 + // 3. ...modify...
83907 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
83908 + assign = gimple_build_assign(temp, addxorrol);
83909 + find_referenced_vars_in(assign);
83910 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83911 + update_stmt(assign);
83912 +
83913 + // 4. ...write latent_entropy
83914 + assign = gimple_build_assign(latent_entropy_decl, temp);
83915 + find_referenced_vars_in(assign);
83916 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83917 + update_stmt(assign);
83918 +}
83919 +
83920 +static unsigned int execute_latent_entropy(void)
83921 +{
83922 + basic_block bb;
83923 + gimple assign;
83924 + gimple_stmt_iterator gsi;
83925 + tree local_entropy;
83926 +
83927 + if (!latent_entropy_decl) {
83928 + struct varpool_node *node;
83929 +
83930 + for (node = varpool_nodes; node; node = node->next) {
83931 + tree var = node->decl;
83932 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
83933 + continue;
83934 + latent_entropy_decl = var;
83935 +// debug_tree(var);
83936 + break;
83937 + }
83938 + if (!latent_entropy_decl) {
83939 +// debug_tree(current_function_decl);
83940 + return 0;
83941 + }
83942 + }
83943 +
83944 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
83945 +
83946 + // 1. create local entropy variable
83947 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
83948 + add_referenced_var(local_entropy);
83949 + mark_sym_for_renaming(local_entropy);
83950 +
83951 + // 2. initialize local entropy variable
83952 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
83953 + if (dom_info_available_p(CDI_DOMINATORS))
83954 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
83955 + gsi = gsi_start_bb(bb);
83956 +
83957 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
83958 +// gimple_set_location(assign, loc);
83959 + find_referenced_vars_in(assign);
83960 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83961 + update_stmt(assign);
83962 + bb = bb->next_bb;
83963 +
83964 + // 3. instrument each BB with an operation on the local entropy variable
83965 + while (bb != EXIT_BLOCK_PTR) {
83966 + perturb_local_entropy(bb, local_entropy);
83967 + bb = bb->next_bb;
83968 + };
83969 +
83970 + // 4. mix local entropy into the global entropy variable
83971 + perturb_latent_entropy(EXIT_BLOCK_PTR->prev_bb, local_entropy);
83972 + return 0;
83973 +}
83974 +
83975 +static void start_unit_callback(void *gcc_data, void *user_data)
83976 +{
83977 +#if BUILDING_GCC_VERSION >= 4007
83978 + seed = get_random_seed(false);
83979 +#else
83980 + sscanf(get_random_seed(false), "%" HOST_WIDE_INT_PRINT "x", &seed);
83981 + seed *= seed;
83982 +#endif
83983 +
83984 + if (in_lto_p)
83985 + return;
83986 +
83987 + // extern u64 latent_entropy
83988 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), unsigned_intDI_type_node);
83989 +
83990 + TREE_STATIC(latent_entropy_decl) = 1;
83991 + TREE_PUBLIC(latent_entropy_decl) = 1;
83992 + TREE_USED(latent_entropy_decl) = 1;
83993 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
83994 + DECL_EXTERNAL(latent_entropy_decl) = 1;
83995 + DECL_ARTIFICIAL(latent_entropy_decl) = 0;
83996 + DECL_INITIAL(latent_entropy_decl) = NULL;
83997 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
83998 +// varpool_finalize_decl(latent_entropy_decl);
83999 +// varpool_mark_needed_node(latent_entropy_decl);
84000 +}
84001 +
84002 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
84003 +{
84004 + const char * const plugin_name = plugin_info->base_name;
84005 + struct register_pass_info latent_entropy_pass_info = {
84006 + .pass = &latent_entropy_pass.pass,
84007 + .reference_pass_name = "optimized",
84008 + .ref_pass_instance_number = 1,
84009 + .pos_op = PASS_POS_INSERT_BEFORE
84010 + };
84011 +
84012 + if (!plugin_default_version_check(version, &gcc_version)) {
84013 + error(G_("incompatible gcc/plugin versions"));
84014 + return 1;
84015 + }
84016 +
84017 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
84018 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
84019 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
84020 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
84021 +
84022 + return 0;
84023 +}
84024 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
84025 new file mode 100644
84026 index 0000000..9332f17
84027 --- /dev/null
84028 +++ b/tools/gcc/size_overflow_hash.data
84029 @@ -0,0 +1,3597 @@
84030 +_000001_hash alloc_dr 2 65495 _000001_hash NULL
84031 +_000002_hash __copy_from_user 3 10918 _000002_hash NULL
84032 +_000003_hash copy_from_user 3 17559 _000003_hash NULL
84033 +_000004_hash __copy_from_user_inatomic 3 4365 _000004_hash NULL
84034 +_000005_hash __copy_from_user_nocache 3 39351 _000005_hash NULL
84035 +_000006_hash __copy_to_user_inatomic 3 19214 _000006_hash NULL
84036 +_000007_hash do_xip_mapping_read 5 60297 _000007_hash NULL
84037 +_000008_hash hugetlbfs_read 3 11268 _000008_hash NULL
84038 +_000009_hash kmalloc 1 60432 _003302_hash NULL nohasharray
84039 +_000010_hash kmalloc_array 1-2 9444 _000010_hash NULL
84040 +_000012_hash __kmalloc_reserve 1 17080 _000012_hash NULL
84041 +_000013_hash kmalloc_slab 1 11917 _000013_hash NULL
84042 +_000014_hash kmemdup 2 64015 _000014_hash NULL
84043 +_000015_hash __krealloc 2 14857 _000340_hash NULL nohasharray
84044 +_000016_hash memdup_user 2 59590 _000016_hash NULL
84045 +_000017_hash module_alloc 1 63630 _000017_hash NULL
84046 +_000018_hash read_default_ldt 2 14302 _000018_hash NULL
84047 +_000019_hash read_kcore 3 63488 _000019_hash NULL
84048 +_000020_hash read_ldt 2 47570 _000020_hash NULL
84049 +_000021_hash read_zero 3 19366 _000021_hash NULL
84050 +_000022_hash __vmalloc_node 1 39308 _000022_hash NULL
84051 +_000023_hash aac_convert_sgraw2 4 51598 _000023_hash NULL
84052 +_000024_hash aa_simple_write_to_buffer 4-3 49683 _000024_hash NULL
84053 +_000025_hash ablkcipher_copy_iv 3 64140 _000025_hash NULL
84054 +_000026_hash ablkcipher_next_slow 3-4 47274 _000026_hash NULL
84055 +_000028_hash acpi_battery_write_alarm 3 1240 _000028_hash NULL
84056 +_000029_hash acpi_os_allocate 1 14892 _000029_hash NULL
84057 +_000030_hash acpi_system_write_wakeup_device 3 34853 _000030_hash NULL
84058 +_000031_hash adu_write 3 30487 _000031_hash NULL
84059 +_000032_hash aer_inject_write 3 52399 _000032_hash NULL
84060 +_000033_hash afs_alloc_flat_call 2-3 36399 _000033_hash NULL
84061 +_000035_hash afs_proc_cells_write 3 61139 _000035_hash NULL
84062 +_000036_hash afs_proc_rootcell_write 3 15822 _000036_hash NULL
84063 +_000037_hash agp_3_5_isochronous_node_enable 3 49465 _000037_hash NULL
84064 +_000038_hash agp_alloc_page_array 1 22554 _000038_hash NULL
84065 +_000039_hash ah_alloc_tmp 2-3 54378 _000039_hash NULL
84066 +_000041_hash ahash_setkey_unaligned 3 33521 _000041_hash NULL
84067 +_000042_hash alg_setkey 3 31485 _000042_hash NULL
84068 +_000043_hash aligned_kmalloc 1 3628 _000043_hash NULL
84069 +_000044_hash alloc_context 1 3194 _000044_hash NULL
84070 +_000045_hash alloc_ep_req 2 54860 _000045_hash NULL
84071 +_000046_hash alloc_fdmem 1 27083 _000046_hash NULL
84072 +_000047_hash alloc_flex_gd 1 57259 _000047_hash NULL
84073 +_000048_hash alloc_sglist 1-3-2 22960 _000048_hash NULL
84074 +_000049_hash __alloc_skb 1 23940 _000049_hash NULL
84075 +_000050_hash aoedev_flush 2 44398 _000050_hash NULL
84076 +_000051_hash append_to_buffer 3 63550 _000051_hash NULL
84077 +_000052_hash asix_read_cmd 5 13245 _000052_hash NULL
84078 +_000053_hash asix_write_cmd 5 58192 _000053_hash NULL
84079 +_000054_hash at76_set_card_command 4 4471 _000054_hash NULL
84080 +_000055_hash ath6kl_add_bss_if_needed 6 24317 _000055_hash NULL
84081 +_000056_hash ath6kl_debug_roam_tbl_event 3 5224 _000056_hash NULL
84082 +_000057_hash ath6kl_mgmt_powersave_ap 6 13791 _000057_hash NULL
84083 +_000058_hash ath6kl_send_go_probe_resp 3 21113 _000058_hash NULL
84084 +_000059_hash ath6kl_set_ap_probe_resp_ies 3 50539 _000059_hash NULL
84085 +_000060_hash ath6kl_set_assoc_req_ies 3 43185 _000060_hash NULL
84086 +_000061_hash ath6kl_wmi_bssinfo_event_rx 3 2275 _000061_hash NULL
84087 +_000062_hash ath6kl_wmi_send_action_cmd 7 58860 _000062_hash NULL
84088 +_000063_hash __ath6kl_wmi_send_mgmt_cmd 7 38971 _000063_hash NULL
84089 +_000064_hash attach_hdlc_protocol 3 19986 _000064_hash NULL
84090 +_000065_hash audio_write 4 54261 _001782_hash NULL nohasharray
84091 +_000066_hash audit_unpack_string 3 13748 _000066_hash NULL
84092 +_000067_hash ax25_setsockopt 5 42740 _000067_hash NULL
84093 +_000068_hash b43_debugfs_write 3 34838 _000068_hash NULL
84094 +_000069_hash b43legacy_debugfs_write 3 28556 _000069_hash NULL
84095 +_000070_hash batadv_hash_new 1 40491 _000070_hash NULL
84096 +_000071_hash batadv_orig_node_add_if 2 18433 _000071_hash NULL
84097 +_000072_hash batadv_orig_node_del_if 2 4 _000072_hash NULL
84098 +_000073_hash batadv_tt_changes_fill_buff 4 40323 _000073_hash NULL
84099 +_000074_hash batadv_tt_realloc_packet_buff 4 49960 _000074_hash NULL
84100 +_000075_hash bch_alloc 1 4593 _000075_hash NULL
84101 +_000076_hash befs_nls2utf 3 17163 _000076_hash NULL
84102 +_000077_hash befs_utf2nls 3 25628 _000077_hash NULL
84103 +_000078_hash bfad_debugfs_write_regrd 3 15218 _000078_hash NULL
84104 +_000079_hash bfad_debugfs_write_regwr 3 61841 _000079_hash NULL
84105 +_000080_hash bio_alloc_map_data 1-2 50782 _000080_hash NULL
84106 +_000082_hash bio_kmalloc 2 54672 _000082_hash NULL
84107 +_000083_hash bitmap_storage_alloc 2 55077 _000083_hash NULL
84108 +_000084_hash blkcipher_copy_iv 3 24075 _000084_hash NULL
84109 +_000085_hash blkcipher_next_slow 3-4 52733 _000085_hash NULL
84110 +_000087_hash bl_pipe_downcall 3 34264 _000087_hash NULL
84111 +_000088_hash bnad_debugfs_write_regrd 3 6706 _000088_hash NULL
84112 +_000089_hash bnad_debugfs_write_regwr 3 57500 _000089_hash NULL
84113 +_000090_hash bnx2fc_cmd_mgr_alloc 2-3 24873 _000090_hash NULL
84114 +_000092_hash bnx2fc_process_unsol_compl 2 15576 _000092_hash NULL
84115 +_000093_hash bnx2_nvram_write 2-4 7790 _000093_hash NULL
84116 +_000095_hash btmrvl_gpiogap_write 3 35053 _000095_hash NULL
84117 +_000096_hash btmrvl_hscfgcmd_write 3 27143 _000096_hash NULL
84118 +_000097_hash btmrvl_hscmd_write 3 27089 _000097_hash NULL
84119 +_000098_hash btmrvl_hsmode_write 3 42252 _000098_hash NULL
84120 +_000099_hash btmrvl_pscmd_write 3 29504 _000099_hash NULL
84121 +_000100_hash btmrvl_psmode_write 3 3703 _000100_hash NULL
84122 +_000101_hash btrfs_alloc_delayed_item 1 11678 _000101_hash NULL
84123 +_000102_hash c4iw_id_table_alloc 3 48163 _000102_hash NULL
84124 +_000103_hash cache_do_downcall 3 6926 _000103_hash NULL
84125 +_000104_hash cachefiles_cook_key 2 33274 _000104_hash NULL
84126 +_000105_hash cachefiles_daemon_write 3 43535 _000105_hash NULL
84127 +_000106_hash capi_write 3 35104 _003607_hash NULL nohasharray
84128 +_000107_hash carl9170_debugfs_write 3 50857 _000107_hash NULL
84129 +_000108_hash cciss_allocate_sg_chain_blocks 2-3 5368 _000108_hash NULL
84130 +_000110_hash cciss_proc_write 3 10259 _000110_hash NULL
84131 +_000111_hash cdrom_read_cdda_old 4 27664 _000111_hash NULL
84132 +_000112_hash ceph_alloc_page_vector 1 18710 _000112_hash NULL
84133 +_000113_hash ceph_buffer_new 1 35974 _000113_hash NULL
84134 +_000114_hash ceph_copy_user_to_page_vector 3-4 656 _000114_hash NULL
84135 +_000116_hash ceph_get_direct_page_vector 2 41917 _000116_hash NULL
84136 +_000117_hash ceph_msg_new 2 5846 _000117_hash NULL
84137 +_000118_hash ceph_setxattr 4 18913 _000118_hash NULL
84138 +_000119_hash cfi_read_pri 3 24366 _000119_hash NULL
84139 +_000120_hash cgroup_write_string 5 10900 _000120_hash NULL
84140 +_000121_hash cgroup_write_X64 5 54514 _000121_hash NULL
84141 +_000122_hash change_xattr 5 61390 _000122_hash NULL
84142 +_000123_hash check_load_and_stores 2 2143 _000123_hash NULL
84143 +_000124_hash cifs_idmap_key_instantiate 3 54503 _000124_hash NULL
84144 +_000125_hash cifs_security_flags_proc_write 3 5484 _000125_hash NULL
84145 +_000126_hash cifs_setxattr 4 23957 _000126_hash NULL
84146 +_000127_hash cifs_spnego_key_instantiate 3 23588 _000127_hash NULL
84147 +_000128_hash cld_pipe_downcall 3 15058 _000128_hash NULL
84148 +_000129_hash clear_refs_write 3 61904 _000129_hash NULL
84149 +_000130_hash clusterip_proc_write 3 44729 _000130_hash NULL
84150 +_000131_hash cm4040_write 3 58079 _000131_hash NULL
84151 +_000132_hash cm_copy_private_data 2 3649 _000132_hash NULL
84152 +_000133_hash cmm_write 3 2896 _000133_hash NULL
84153 +_000134_hash cm_write 3 36858 _000134_hash NULL
84154 +_000135_hash coda_psdev_write 3 1711 _000135_hash NULL
84155 +_000136_hash codec_reg_read_file 3 36280 _000136_hash NULL
84156 +_000137_hash command_file_write 3 31318 _000137_hash NULL
84157 +_000138_hash command_write 3 58841 _000138_hash NULL
84158 +_000139_hash comm_write 3 44537 _001714_hash NULL nohasharray
84159 +_000140_hash concat_writev 3 21451 _000140_hash NULL
84160 +_000141_hash copy_and_check 3 19089 _000141_hash NULL
84161 +_000142_hash copy_from_user_toio 3 31966 _000142_hash NULL
84162 +_000143_hash copy_items 6 50140 _000143_hash NULL
84163 +_000144_hash copy_macs 4 45534 _000144_hash NULL
84164 +_000145_hash __copy_to_user 3 17551 _000145_hash NULL
84165 +_000146_hash copy_vm86_regs_from_user 3 45340 _000146_hash NULL
84166 +_000147_hash core_sys_select 1 47494 _000147_hash NULL
84167 +_000148_hash cosa_write 3 1774 _000148_hash NULL
84168 +_000149_hash cp210x_set_config 4 46447 _000149_hash NULL
84169 +_000150_hash create_entry 2 33479 _000150_hash NULL
84170 +_000151_hash create_queues 2-3 9088 _000151_hash NULL
84171 +_000153_hash create_xattr 5 54106 _000153_hash NULL
84172 +_000154_hash create_xattr_datum 5 33356 _003443_hash NULL nohasharray
84173 +_000155_hash csum_partial_copy_fromiovecend 3-4 9957 _000155_hash NULL
84174 +_000157_hash ctrl_out 3-5 8712 _000157_hash NULL
84175 +_000159_hash cxacru_cm_get_array 4 4412 _000159_hash NULL
84176 +_000160_hash cxgbi_alloc_big_mem 1 4707 _000160_hash NULL
84177 +_000161_hash dac960_user_command_proc_write 3 3071 _000161_hash NULL
84178 +_000162_hash datablob_format 2 39571 _002490_hash NULL nohasharray
84179 +_000163_hash dccp_feat_clone_sp_val 3 11942 _000163_hash NULL
84180 +_000164_hash dccp_setsockopt_ccid 4 30701 _000164_hash NULL
84181 +_000165_hash dccp_setsockopt_cscov 2 37766 _000165_hash NULL
84182 +_000166_hash dccp_setsockopt_service 4 65336 _000166_hash NULL
84183 +_000167_hash ddebug_proc_write 3 18055 _000167_hash NULL
84184 +_000168_hash dev_config 3 8506 _000168_hash NULL
84185 +_000169_hash device_write 3 45156 _000169_hash NULL
84186 +_000170_hash devm_kzalloc 2 4966 _000170_hash NULL
84187 +_000171_hash devres_alloc 2 551 _000171_hash NULL
84188 +_000172_hash dfs_file_write 3 41196 _000172_hash NULL
84189 +_000173_hash direct_entry 3 38836 _000173_hash NULL
84190 +_000174_hash dispatch_ioctl 2 32357 _000174_hash NULL
84191 +_000175_hash dispatch_proc_write 3 44320 _000175_hash NULL
84192 +_000176_hash diva_os_copy_from_user 4 7792 _000176_hash NULL
84193 +_000177_hash dlm_alloc_pagevec 1 54296 _000177_hash NULL
84194 +_000178_hash dlmfs_file_read 3 28385 _000178_hash NULL
84195 +_000179_hash dlmfs_file_write 3 6892 _000179_hash NULL
84196 +_000180_hash dm_read 3 15674 _000180_hash NULL
84197 +_000181_hash dm_write 3 2513 _000181_hash NULL
84198 +_000182_hash __dn_setsockopt 5 13060 _000182_hash NULL
84199 +_000183_hash dns_query 3 9676 _000183_hash NULL
84200 +_000184_hash dns_resolver_instantiate 3 63314 _000184_hash NULL
84201 +_000185_hash do_add_counters 3 3992 _000185_hash NULL
84202 +_000186_hash __do_config_autodelink 3 58763 _000186_hash NULL
84203 +_000187_hash do_ip_setsockopt 5 41852 _000187_hash NULL
84204 +_000188_hash do_ipv6_setsockopt 5 18215 _000188_hash NULL
84205 +_000189_hash do_ip_vs_set_ctl 4 48641 _000189_hash NULL
84206 +_000190_hash do_kimage_alloc 3 64827 _000190_hash NULL
84207 +_000191_hash do_register_entry 4 29478 _000191_hash NULL
84208 +_000192_hash do_tty_write 5 44896 _000192_hash NULL
84209 +_000193_hash do_update_counters 4 2259 _000193_hash NULL
84210 +_000194_hash dsp_write 2 46218 _000194_hash NULL
84211 +_000195_hash dup_to_netobj 3 26363 _000195_hash NULL
84212 +_000196_hash dwc3_link_state_write 3 12641 _000196_hash NULL
84213 +_000197_hash dwc3_mode_write 3 51997 _000197_hash NULL
84214 +_000198_hash dwc3_testmode_write 3 30516 _000198_hash NULL
84215 +_000199_hash ecryptfs_copy_filename 4 11868 _000199_hash NULL
84216 +_000200_hash ecryptfs_miscdev_write 3 26847 _000200_hash NULL
84217 +_000201_hash ecryptfs_send_miscdev 2 64816 _000201_hash NULL
84218 +_000202_hash efx_tsoh_heap_alloc 2 58545 _000202_hash NULL
84219 +_000203_hash emi26_writememory 4 57908 _000203_hash NULL
84220 +_000204_hash emi62_writememory 4 29731 _000204_hash NULL
84221 +_000205_hash encrypted_instantiate 3 3168 _000205_hash NULL
84222 +_000206_hash encrypted_update 3 13414 _000206_hash NULL
84223 +_000207_hash ep0_write 3 14536 _001422_hash NULL nohasharray
84224 +_000208_hash ep_read 3 58813 _000208_hash NULL
84225 +_000209_hash ep_write 3 59008 _000209_hash NULL
84226 +_000210_hash erst_dbg_write 3 46715 _000210_hash NULL
84227 +_000211_hash esp_alloc_tmp 2-3 40558 _000211_hash NULL
84228 +_000213_hash evdev_do_ioctl 2 24459 _000213_hash NULL
84229 +_000214_hash exofs_read_lookup_dev_table 3 17733 _000214_hash NULL
84230 +_000215_hash ext4_kvmalloc 1 14796 _000215_hash NULL
84231 +_000216_hash ezusb_writememory 4 45976 _000216_hash NULL
84232 +_000217_hash fanotify_write 3 64623 _000217_hash NULL
84233 +_000218_hash fd_copyin 3 56247 _000218_hash NULL
84234 +_000219_hash ffs_epfile_io 3 64886 _000219_hash NULL
84235 +_000220_hash ffs_prepare_buffer 2 59892 _000220_hash NULL
84236 +_000221_hash f_hidg_write 3 7932 _000221_hash NULL
84237 +_000222_hash file_read_actor 4 1401 _000222_hash NULL
84238 +_000223_hash fill_write_buffer 3 3142 _000223_hash NULL
84239 +_000224_hash __find_xattr 6 2117 _002425_hash NULL nohasharray
84240 +_000225_hash fl_create 5 56435 _000225_hash NULL
84241 +_000226_hash fs_path_ensure_buf 2 59445 _000226_hash NULL
84242 +_000227_hash ftdi_elan_write 3 57309 _000227_hash NULL
84243 +_000228_hash fw_iso_buffer_alloc 2 13704 _000228_hash NULL
84244 +_000229_hash garmin_write_bulk 3 58191 _000229_hash NULL
84245 +_000230_hash garp_attr_create 3 3883 _000230_hash NULL
84246 +_000231_hash get_arg 3 5694 _000231_hash NULL
84247 +_000232_hash getdqbuf 1 62908 _000232_hash NULL
84248 +_000233_hash get_fdb_entries 3 41916 _000233_hash NULL
84249 +_000234_hash get_fd_set 1 3866 _000234_hash NULL
84250 +_000235_hash get_indirect_ea 4 51869 _000235_hash NULL
84251 +_000236_hash get_registers 3 26187 _000236_hash NULL
84252 +_000237_hash get_scq 2 10897 _000237_hash NULL
84253 +_000238_hash get_server_iovec 2 16804 _000238_hash NULL
84254 +_000239_hash get_ucode_user 3 38202 _000239_hash NULL
84255 +_000240_hash get_user_cpu_mask 2 14861 _000240_hash NULL
84256 +_000241_hash gfs2_alloc_sort_buffer 1 18275 _000241_hash NULL
84257 +_000242_hash gfs2_glock_nq_m 1 20347 _000242_hash NULL
84258 +_000243_hash gigaset_initcs 2 43753 _000243_hash NULL
84259 +_000244_hash gigaset_initdriver 2 1060 _000244_hash NULL
84260 +_000245_hash groups_alloc 1 7614 _000245_hash NULL
84261 +_000246_hash gs_alloc_req 2 58883 _000246_hash NULL
84262 +_000247_hash gs_buf_alloc 2 25067 _000247_hash NULL
84263 +_000248_hash gsm_data_alloc 3 42437 _000248_hash NULL
84264 +_000249_hash gss_pipe_downcall 3 23182 _000249_hash NULL
84265 +_000250_hash handle_request 9 10024 _000250_hash NULL
84266 +_000251_hash hashtab_create 3 33769 _000251_hash NULL
84267 +_000252_hash hcd_buffer_alloc 2 27495 _000252_hash NULL
84268 +_000253_hash hci_sock_setsockopt 5 28993 _000253_hash NULL
84269 +_000254_hash heap_init 2 49617 _000254_hash NULL
84270 +_000255_hash hest_ghes_dev_register 1 46766 _000255_hash NULL
84271 +_000256_hash hidg_alloc_ep_req 2 10159 _000256_hash NULL
84272 +_000257_hash hid_parse_report 3 51737 _000257_hash NULL
84273 +_000258_hash hidraw_get_report 3 45609 _000258_hash NULL
84274 +_000259_hash hidraw_report_event 3 20503 _000259_hash NULL
84275 +_000260_hash hidraw_send_report 3 23449 _000260_hash NULL
84276 +_000261_hash hpfs_translate_name 3 41497 _000261_hash NULL
84277 +_000262_hash hysdn_conf_write 3 52145 _000262_hash NULL
84278 +_000263_hash __i2400mu_send_barker 3 23652 _000263_hash NULL
84279 +_000264_hash i2cdev_read 3 1206 _000264_hash NULL
84280 +_000265_hash i2cdev_write 3 23310 _000265_hash NULL
84281 +_000266_hash i2o_parm_field_get 5 34477 _000266_hash NULL
84282 +_000267_hash i2o_parm_table_get 6 61635 _000267_hash NULL
84283 +_000268_hash ib_copy_from_udata 3 59502 _000268_hash NULL
84284 +_000269_hash ib_ucm_alloc_data 3 36885 _000269_hash NULL
84285 +_000270_hash ib_umad_write 3 47993 _000270_hash NULL
84286 +_000271_hash ib_uverbs_unmarshall_recv 5 12251 _000271_hash NULL
84287 +_000272_hash icn_writecmd 2 38629 _000272_hash NULL
84288 +_000273_hash ide_driver_proc_write 3 32493 _000273_hash NULL
84289 +_000274_hash ide_settings_proc_write 3 35110 _000274_hash NULL
84290 +_000275_hash idetape_chrdev_write 3 53976 _000275_hash NULL
84291 +_000276_hash idmap_pipe_downcall 3 14591 _000276_hash NULL
84292 +_000277_hash ieee80211_build_probe_req 7-5 27660 _000277_hash NULL
84293 +_000278_hash ieee80211_if_write 3 34894 _000278_hash NULL
84294 +_000279_hash if_write 3 51756 _000279_hash NULL
84295 +_000280_hash ilo_write 3 64378 _000280_hash NULL
84296 +_000281_hash ima_write_policy 3 40548 _000281_hash NULL
84297 +_000282_hash init_data_container 1 60709 _000282_hash NULL
84298 +_000283_hash init_send_hfcd 1 34586 _000283_hash NULL
84299 +_000284_hash insert_dent 7 65034 _000284_hash NULL
84300 +_000285_hash interpret_user_input 2 19393 _000285_hash NULL
84301 +_000286_hash int_proc_write 3 39542 _000286_hash NULL
84302 +_000287_hash ioctl_private_iw_point 7 1273 _000287_hash NULL
84303 +_000288_hash iov_iter_copy_from_user 4 31942 _000288_hash NULL
84304 +_000289_hash iov_iter_copy_from_user_atomic 4 56368 _000289_hash NULL
84305 +_000290_hash iowarrior_write 3 18604 _000290_hash NULL
84306 +_000291_hash ipc_alloc 1 1192 _000291_hash NULL
84307 +_000292_hash ipc_rcu_alloc 1 21208 _000292_hash NULL
84308 +_000293_hash ip_options_get_from_user 4 64958 _000293_hash NULL
84309 +_000294_hash ipv6_renew_option 3 38813 _000294_hash NULL
84310 +_000295_hash ip_vs_conn_fill_param_sync 6 29771 _001898_hash NULL nohasharray
84311 +_000296_hash ip_vs_create_timeout_table 2 64478 _000296_hash NULL
84312 +_000297_hash ipw_queue_tx_init 3 49161 _000297_hash NULL
84313 +_000298_hash irda_setsockopt 5 19824 _000298_hash NULL
84314 +_000299_hash irias_new_octseq_value 2 13596 _003821_hash NULL nohasharray
84315 +_000300_hash irnet_ctrl_write 3 24139 _000300_hash NULL
84316 +_000301_hash isdn_add_channels 3 40905 _000301_hash NULL
84317 +_000302_hash isdn_ppp_fill_rq 2 41428 _000302_hash NULL
84318 +_000303_hash isdn_ppp_write 4 29109 _000303_hash NULL
84319 +_000304_hash isdn_read 3 50021 _000304_hash NULL
84320 +_000305_hash isdn_v110_open 3 2418 _000305_hash NULL
84321 +_000306_hash isdn_writebuf_stub 4 52383 _000306_hash NULL
84322 +_000307_hash islpci_mgt_transmit 5 34133 _000307_hash NULL
84323 +_000308_hash iso_callback 3 43208 _000308_hash NULL
84324 +_000309_hash iso_packets_buffer_init 3-4 29061 _000309_hash NULL
84325 +_000310_hash it821x_firmware_command 3 8628 _000310_hash NULL
84326 +_000311_hash iwch_alloc_fastreg_pbl 2 40153 _000311_hash NULL
84327 +_000312_hash iwl_calib_set 3 34400 _003754_hash NULL nohasharray
84328 +_000313_hash jbd2_journal_init_revoke_table 1 36336 _000313_hash NULL
84329 +_000314_hash jffs2_alloc_full_dirent 1 60179 _001158_hash NULL nohasharray
84330 +_000315_hash journal_init_revoke_table 1 56331 _000315_hash NULL
84331 +_000316_hash kcalloc 1-2 27770 _000316_hash NULL
84332 +_000318_hash keyctl_instantiate_key_common 4 47889 _000318_hash NULL
84333 +_000319_hash keyctl_update_key 3 26061 _000319_hash NULL
84334 +_000320_hash __kfifo_alloc 2-3 22173 _000320_hash NULL
84335 +_000322_hash kfifo_copy_from_user 3 5091 _000322_hash NULL
84336 +_000323_hash kmalloc_node 1 50163 _003818_hash NULL nohasharray
84337 +_000324_hash kmalloc_parameter 1 65279 _000324_hash NULL
84338 +_000325_hash kmem_alloc 1 31920 _000325_hash NULL
84339 +_000326_hash kobj_map 2-3 9566 _000326_hash NULL
84340 +_000328_hash kone_receive 4 4690 _000328_hash NULL
84341 +_000329_hash kone_send 4 63435 _000329_hash NULL
84342 +_000330_hash krealloc 2 14908 _000330_hash NULL
84343 +_000331_hash kvmalloc 1 32646 _000331_hash NULL
84344 +_000332_hash kvm_read_guest_atomic 4 10765 _000332_hash NULL
84345 +_000333_hash kvm_read_guest_cached 4 39666 _000333_hash NULL
84346 +_000334_hash kvm_read_guest_page 5 18074 _000334_hash NULL
84347 +_000335_hash kzalloc 1 54740 _000335_hash NULL
84348 +_000336_hash l2cap_sock_setsockopt 5 50207 _000336_hash NULL
84349 +_000337_hash l2cap_sock_setsockopt_old 4 29346 _000337_hash NULL
84350 +_000338_hash lane2_associate_req 4 45398 _000338_hash NULL
84351 +_000339_hash lbs_debugfs_write 3 48413 _000339_hash NULL
84352 +_000340_hash lcd_write 3 14857 _000340_hash &_000015_hash
84353 +_000341_hash ldm_frag_add 2 5611 _000341_hash NULL
84354 +_000342_hash __lgread 4 31668 _000342_hash NULL
84355 +_000343_hash libipw_alloc_txb 1-3-2 27579 _000343_hash NULL
84356 +_000344_hash link_send_sections_long 4 46556 _000344_hash NULL
84357 +_000345_hash listxattr 3 12769 _000345_hash NULL
84358 +_000346_hash load_msg 2 95 _000346_hash NULL
84359 +_000347_hash lpfc_debugfs_dif_err_write 3 17424 _000347_hash NULL
84360 +_000348_hash lp_write 3 9511 _000348_hash NULL
84361 +_000349_hash mb_cache_create 2 17307 _000349_hash NULL
84362 +_000350_hash mce_write 3 26201 _000350_hash NULL
84363 +_000351_hash mcs7830_get_reg 3 33308 _000351_hash NULL
84364 +_000352_hash mcs7830_set_reg 3 31413 _000352_hash NULL
84365 +_000353_hash memcpy_fromiovec 3 55247 _000353_hash NULL
84366 +_000354_hash memcpy_fromiovecend 3-4 2707 _000354_hash NULL
84367 +_000356_hash mempool_resize 2 47983 _002039_hash NULL nohasharray
84368 +_000357_hash mem_rw 3 22085 _000357_hash NULL
84369 +_000358_hash mgmt_control 3 7349 _000358_hash NULL
84370 +_000359_hash mgmt_pending_add 5 46976 _000359_hash NULL
84371 +_000360_hash mlx4_ib_alloc_fast_reg_page_list 2 46119 _000360_hash NULL
84372 +_000361_hash mmc_alloc_sg 1 21504 _000361_hash NULL
84373 +_000362_hash mmc_send_bus_test 4 18285 _000362_hash NULL
84374 +_000363_hash mmc_send_cxd_data 5 38655 _000363_hash NULL
84375 +_000364_hash module_alloc_update_bounds 1 47205 _000364_hash NULL
84376 +_000365_hash move_addr_to_kernel 2 32673 _000365_hash NULL
84377 +_000366_hash mpi_alloc_limb_space 1 23190 _000366_hash NULL
84378 +_000367_hash mpi_resize 2 44674 _000367_hash NULL
84379 +_000368_hash mptctl_getiocinfo 2 28545 _000368_hash NULL
84380 +_000369_hash mtdchar_readoob 4 31200 _000369_hash NULL
84381 +_000370_hash mtdchar_write 3 56831 _002122_hash NULL nohasharray
84382 +_000371_hash mtdchar_writeoob 4 3393 _000371_hash NULL
84383 +_000372_hash mtd_device_parse_register 5 5024 _000372_hash NULL
84384 +_000373_hash mtf_test_write 3 18844 _000373_hash NULL
84385 +_000374_hash mthca_alloc_icm_table 3-4 38268 _002459_hash NULL nohasharray
84386 +_000376_hash mthca_alloc_init 2 21754 _000376_hash NULL
84387 +_000377_hash mthca_array_init 2 39987 _000377_hash NULL
84388 +_000378_hash mthca_buf_alloc 2 35861 _000378_hash NULL
84389 +_000379_hash mtrr_write 3 59622 _000379_hash NULL
84390 +_000380_hash musb_test_mode_write 3 33518 _000380_hash NULL
84391 +_000381_hash mwifiex_get_common_rates 3 17131 _000381_hash NULL
84392 +_000382_hash __mxt_write_reg 3 57326 _000382_hash NULL
84393 +_000383_hash nand_bch_init 2-3 16280 _001439_hash NULL nohasharray
84394 +_000385_hash ncp_file_write 3 3813 _000385_hash NULL
84395 +_000386_hash ncp__vol2io 5 4804 _000386_hash NULL
84396 +_000387_hash nes_alloc_fast_reg_page_list 2 33523 _000387_hash NULL
84397 +_000388_hash nfc_targets_found 3 29886 _000388_hash NULL
84398 +_000389_hash __nf_ct_ext_add_length 3 12364 _000389_hash NULL
84399 +_000390_hash nfs4_acl_new 1 49806 _000390_hash NULL
84400 +_000391_hash nfs4_write_cached_acl 4 15070 _000391_hash NULL
84401 +_000392_hash nfsd_symlink 6 63442 _000392_hash NULL
84402 +_000393_hash nfs_idmap_get_desc 2-4 42990 _000393_hash NULL
84403 +_000395_hash nfs_readdir_make_qstr 3 12509 _000395_hash NULL
84404 +_000396_hash note_last_dentry 3 12285 _000396_hash NULL
84405 +_000397_hash ntfs_copy_from_user 3-5 15072 _000397_hash NULL
84406 +_000399_hash __ntfs_copy_from_user_iovec_inatomic 3-4 38153 _000399_hash NULL
84407 +_000401_hash ntfs_ucstonls 3-5 23097 _000401_hash NULL
84408 +_000403_hash nvme_alloc_iod 1 56027 _000403_hash NULL
84409 +_000404_hash nvram_write 3 3894 _000404_hash NULL
84410 +_000405_hash o2hb_debug_create 4 18744 _000405_hash NULL
84411 +_000406_hash o2net_send_message_vec 4 879 _002013_hash NULL nohasharray
84412 +_000407_hash ocfs2_control_cfu 2 37750 _000407_hash NULL
84413 +_000408_hash oom_adjust_write 3 41116 _000408_hash NULL
84414 +_000409_hash oom_score_adj_write 3 42594 _000409_hash NULL
84415 +_000410_hash oprofilefs_ulong_from_user 3 57251 _000410_hash NULL
84416 +_000411_hash opticon_write 4 60775 _000411_hash NULL
84417 +_000412_hash p9_check_zc_errors 4 15534 _000412_hash NULL
84418 +_000413_hash packet_buffer_init 2 1607 _000413_hash NULL
84419 +_000414_hash packet_setsockopt 5 17662 _000414_hash NULL
84420 +_000415_hash parse_command 2 37079 _000415_hash NULL
84421 +_000416_hash pcbit_writecmd 2 12332 _000416_hash NULL
84422 +_000417_hash pcmcia_replace_cis 3 57066 _000417_hash NULL
84423 +_000418_hash pgctrl_write 3 50453 _000418_hash NULL
84424 +_000419_hash pg_write 3 40766 _000419_hash NULL
84425 +_000420_hash pidlist_allocate 1 64404 _000420_hash NULL
84426 +_000421_hash pipe_iov_copy_from_user 3 23102 _000421_hash NULL
84427 +_000422_hash pipe_iov_copy_to_user 3 3447 _000422_hash NULL
84428 +_000423_hash pkt_add 3 39897 _000423_hash NULL
84429 +_000424_hash pktgen_if_write 3 55628 _000424_hash NULL
84430 +_000425_hash platform_device_add_data 3 310 _000425_hash NULL
84431 +_000426_hash platform_device_add_resources 3 13289 _000426_hash NULL
84432 +_000427_hash pmcraid_copy_sglist 3 38431 _000427_hash NULL
84433 +_000428_hash pm_qos_power_write 3 52513 _000428_hash NULL
84434 +_000429_hash pnpbios_proc_write 3 19758 _000429_hash NULL
84435 +_000430_hash pool_allocate 3 42012 _000430_hash NULL
84436 +_000431_hash posix_acl_alloc 1 48063 _000431_hash NULL
84437 +_000432_hash ppp_cp_parse_cr 4 5214 _000432_hash NULL
84438 +_000433_hash ppp_write 3 34034 _000433_hash NULL
84439 +_000434_hash pp_read 3 33210 _000434_hash NULL
84440 +_000435_hash pp_write 3 39554 _000435_hash NULL
84441 +_000436_hash printer_req_alloc 2 62687 _000436_hash NULL
84442 +_000437_hash printer_write 3 60276 _000437_hash NULL
84443 +_000438_hash prism2_info_scanresults 3 59729 _000438_hash NULL
84444 +_000439_hash prism2_set_genericelement 3 29277 _000439_hash NULL
84445 +_000440_hash __probe_kernel_read 3 61119 _000440_hash NULL
84446 +_000441_hash __probe_kernel_write 3 29842 _000441_hash NULL
84447 +_000442_hash proc_coredump_filter_write 3 25625 _000442_hash NULL
84448 +_000443_hash _proc_do_string 2 6376 _000443_hash NULL
84449 +_000444_hash process_vm_rw_pages 5-6 15954 _000444_hash NULL
84450 +_000446_hash proc_loginuid_write 3 63648 _000446_hash NULL
84451 +_000447_hash proc_pid_attr_write 3 63845 _000447_hash NULL
84452 +_000448_hash proc_scsi_devinfo_write 3 32064 _000448_hash NULL
84453 +_000449_hash proc_scsi_write 3 29142 _000449_hash NULL
84454 +_000450_hash proc_scsi_write_proc 3 267 _000450_hash NULL
84455 +_000451_hash pskb_expand_head 2-3 42881 _000451_hash NULL
84456 +_000453_hash pstore_mkfile 5 50830 _000453_hash NULL
84457 +_000454_hash pti_char_write 3 60960 _000454_hash NULL
84458 +_000455_hash ptrace_writedata 4 45021 _000455_hash NULL
84459 +_000456_hash pt_write 3 40159 _000456_hash NULL
84460 +_000457_hash qdisc_class_hash_alloc 1 18262 _000457_hash NULL
84461 +_000458_hash r3964_write 4 57662 _000458_hash NULL
84462 +_000459_hash raw_seticmpfilter 3 6888 _000459_hash NULL
84463 +_000460_hash raw_setsockopt 5 45800 _000460_hash NULL
84464 +_000461_hash rawv6_seticmpfilter 5 12137 _000461_hash NULL
84465 +_000462_hash ray_cs_essid_proc_write 3 17875 _000462_hash NULL
84466 +_000463_hash rbd_add 3 16366 _000463_hash NULL
84467 +_000464_hash rbd_snap_add 4 19678 _000464_hash NULL
84468 +_000465_hash rdma_set_ib_paths 3 45592 _000465_hash NULL
84469 +_000466_hash rds_page_copy_user 4 35691 _000466_hash NULL
84470 +_000467_hash read 3 9397 _000467_hash NULL
84471 +_000468_hash read_buf 2 20469 _000468_hash NULL
84472 +_000469_hash read_cis_cache 4 29735 _000469_hash NULL
84473 +_000470_hash realloc_buffer 2 25816 _000470_hash NULL
84474 +_000471_hash receive_DataRequest 3 9904 _000471_hash NULL
84475 +_000472_hash recent_mt_proc_write 3 8206 _000472_hash NULL
84476 +_000473_hash regmap_access_read_file 3 37223 _000473_hash NULL
84477 +_000474_hash regmap_bulk_write 4 59049 _000474_hash NULL
84478 +_000475_hash regmap_map_read_file 3 37685 _000475_hash NULL
84479 +_000476_hash regset_tls_set 4 18459 _000476_hash NULL
84480 +_000477_hash reiserfs_add_entry 4 23062 _002792_hash NULL nohasharray
84481 +_000478_hash remote_settings_file_write 3 22987 _000478_hash NULL
84482 +_000479_hash request_key_auth_new 3 38092 _000479_hash NULL
84483 +_000480_hash restore_i387_fxsave 2 17528 _000480_hash NULL
84484 +_000481_hash revalidate 2 19043 _000481_hash NULL
84485 +_000482_hash rfcomm_sock_setsockopt 5 18254 _000482_hash NULL
84486 +_000483_hash rndis_add_response 2 58544 _000483_hash NULL
84487 +_000484_hash rndis_set_oid 4 6547 _000484_hash NULL
84488 +_000485_hash rngapi_reset 3 34366 _002137_hash NULL nohasharray
84489 +_000486_hash roccat_common2_receive 4 50369 _000486_hash NULL
84490 +_000487_hash roccat_common2_send 4 2422 _000487_hash NULL
84491 +_000488_hash rpc_malloc 2 43573 _000488_hash NULL
84492 +_000489_hash rt2x00debug_write_bbp 3 8212 _000489_hash NULL
84493 +_000490_hash rt2x00debug_write_csr 3 64753 _000490_hash NULL
84494 +_000491_hash rt2x00debug_write_eeprom 3 23091 _000491_hash NULL
84495 +_000492_hash rt2x00debug_write_rf 3 38195 _000492_hash NULL
84496 +_000493_hash rt2x00debug_write_rfcsr 3 41473 _000493_hash NULL
84497 +_000494_hash rts51x_read_mem 4 26577 _002730_hash NULL nohasharray
84498 +_000495_hash rts51x_read_status 4 11830 _000495_hash NULL
84499 +_000496_hash rts51x_write_mem 4 17598 _000496_hash NULL
84500 +_000497_hash rw_copy_check_uvector 3 45748 _003716_hash NULL nohasharray
84501 +_000498_hash rxrpc_request_key 3 27235 _000498_hash NULL
84502 +_000499_hash rxrpc_server_keyring 3 16431 _000499_hash NULL
84503 +_000500_hash savemem 3 58129 _000500_hash NULL
84504 +_000501_hash sb16_copy_from_user 10-7-6 55836 _000501_hash NULL
84505 +_000504_hash sched_autogroup_write 3 10984 _000504_hash NULL
84506 +_000505_hash scsi_mode_select 6 37330 _000505_hash NULL
84507 +_000506_hash scsi_tgt_copy_sense 3 26933 _000506_hash NULL
84508 +_000507_hash sctp_auth_create_key 1 51641 _000507_hash NULL
84509 +_000508_hash sctp_getsockopt_delayed_ack 2 9232 _000508_hash NULL
84510 +_000509_hash sctp_getsockopt_local_addrs 2 25178 _000509_hash NULL
84511 +_000510_hash sctp_make_abort_user 3 29654 _000510_hash NULL
84512 +_000511_hash sctp_setsockopt_active_key 3 43755 _000511_hash NULL
84513 +_000512_hash sctp_setsockopt_adaptation_layer 3 26935 _003246_hash NULL nohasharray
84514 +_000513_hash sctp_setsockopt_associnfo 3 51684 _000513_hash NULL
84515 +_000514_hash sctp_setsockopt_auth_chunk 3 30843 _000514_hash NULL
84516 +_000515_hash sctp_setsockopt_auth_key 3 3793 _000515_hash NULL
84517 +_000516_hash sctp_setsockopt_autoclose 3 5775 _000516_hash NULL
84518 +_000517_hash sctp_setsockopt_bindx 3 49870 _000517_hash NULL
84519 +_000518_hash __sctp_setsockopt_connectx 3 46949 _000518_hash NULL
84520 +_000519_hash sctp_setsockopt_context 3 31091 _000519_hash NULL
84521 +_000520_hash sctp_setsockopt_default_send_param 3 49578 _000520_hash NULL
84522 +_000521_hash sctp_setsockopt_delayed_ack 3 40129 _000521_hash NULL
84523 +_000522_hash sctp_setsockopt_del_key 3 42304 _002709_hash NULL nohasharray
84524 +_000523_hash sctp_setsockopt_events 3 18862 _000523_hash NULL
84525 +_000524_hash sctp_setsockopt_hmac_ident 3 11687 _000524_hash NULL
84526 +_000525_hash sctp_setsockopt_initmsg 3 1383 _000525_hash NULL
84527 +_000526_hash sctp_setsockopt_maxburst 3 28041 _000526_hash NULL
84528 +_000527_hash sctp_setsockopt_maxseg 3 11829 _000527_hash NULL
84529 +_000528_hash sctp_setsockopt_peer_addr_params 3 734 _000528_hash NULL
84530 +_000529_hash sctp_setsockopt_peer_primary_addr 3 13440 _000529_hash NULL
84531 +_000530_hash sctp_setsockopt_rtoinfo 3 30941 _000530_hash NULL
84532 +_000531_hash security_context_to_sid_core 2 29248 _000531_hash NULL
84533 +_000532_hash sel_commit_bools_write 3 46077 _000532_hash NULL
84534 +_000533_hash sel_write_avc_cache_threshold 3 2256 _000533_hash NULL
84535 +_000534_hash sel_write_bool 3 46996 _000534_hash NULL
84536 +_000535_hash sel_write_checkreqprot 3 60774 _000535_hash NULL
84537 +_000536_hash sel_write_disable 3 10511 _000536_hash NULL
84538 +_000537_hash sel_write_enforce 3 48998 _000537_hash NULL
84539 +_000538_hash sel_write_load 3 63830 _000538_hash NULL
84540 +_000539_hash send_bulk_static_data 3 61932 _000539_hash NULL
84541 +_000540_hash set_aoe_iflist 2 42737 _000540_hash NULL
84542 +_000541_hash setkey_unaligned 3 39474 _000541_hash NULL
84543 +_000542_hash set_registers 3 53582 _000542_hash NULL
84544 +_000543_hash setsockopt 5 54539 _000543_hash NULL
84545 +_000544_hash setup_req 3 5848 _000544_hash NULL
84546 +_000545_hash setxattr 4 37006 _000545_hash NULL
84547 +_000546_hash sfq_alloc 1 2861 _000546_hash NULL
84548 +_000547_hash sg_kmalloc 1 50240 _000547_hash NULL
84549 +_000548_hash sgl_map_user_pages 2 30610 _000548_hash NULL
84550 +_000549_hash shash_setkey_unaligned 3 8620 _000549_hash NULL
84551 +_000550_hash shmem_xattr_alloc 2 61190 _000550_hash NULL
84552 +_000551_hash sierra_setup_urb 5 46029 _000551_hash NULL
84553 +_000552_hash simple_transaction_get 3 50633 _000552_hash NULL
84554 +_000553_hash simple_write_to_buffer 2-5 3122 _000553_hash NULL
84555 +_000555_hash sisusb_send_bulk_msg 3 17864 _000555_hash NULL
84556 +_000556_hash skb_add_data 3 48363 _000556_hash NULL
84557 +_000557_hash skb_do_copy_data_nocache 5 12465 _000557_hash NULL
84558 +_000558_hash sl_alloc_bufs 2 50380 _000558_hash NULL
84559 +_000559_hash sl_realloc_bufs 2 64086 _000559_hash NULL
84560 +_000560_hash smk_set_cipso 3 20379 _000560_hash NULL
84561 +_000561_hash smk_write_ambient 3 45691 _000561_hash NULL
84562 +_000562_hash smk_write_direct 3 46363 _000562_hash NULL
84563 +_000563_hash smk_write_doi 3 49621 _000563_hash NULL
84564 +_000564_hash smk_write_logging 3 2618 _000564_hash NULL
84565 +_000565_hash smk_write_mapped 3 13519 _000565_hash NULL
84566 +_000566_hash smk_write_netlbladdr 3 42525 _000566_hash NULL
84567 +_000567_hash smk_write_onlycap 3 14400 _000567_hash NULL
84568 +_000568_hash smk_write_rules_list 3 18565 _000568_hash NULL
84569 +_000569_hash snd_ctl_elem_user_tlv 3 11695 _000569_hash NULL
84570 +_000570_hash snd_emu10k1_fx8010_read 5 9605 _000570_hash NULL
84571 +_000571_hash snd_emu10k1_synth_copy_from_user 3-5 9061 _000571_hash NULL
84572 +_000573_hash snd_gus_dram_poke 4 18525 _000573_hash NULL
84573 +_000574_hash snd_hdsp_playback_copy 5 20676 _000574_hash NULL
84574 +_000575_hash snd_info_entry_write 3 63474 _000575_hash NULL
84575 +_000576_hash snd_korg1212_copy_from 6 36169 _000576_hash NULL
84576 +_000577_hash snd_mem_proc_write 3 9786 _000577_hash NULL
84577 +_000578_hash snd_midi_channel_init_set 1 30092 _000578_hash NULL
84578 +_000579_hash snd_midi_event_new 1 9893 _000764_hash NULL nohasharray
84579 +_000580_hash snd_opl4_mem_proc_write 5 9670 _000580_hash NULL
84580 +_000581_hash snd_pcm_aio_read 3 13900 _000581_hash NULL
84581 +_000582_hash snd_pcm_aio_write 3 28738 _000582_hash NULL
84582 +_000583_hash snd_pcm_oss_write1 3 10872 _000583_hash NULL
84583 +_000584_hash snd_pcm_oss_write2 3 27332 _000584_hash NULL
84584 +_000585_hash snd_rawmidi_kernel_write1 4 56847 _000585_hash NULL
84585 +_000586_hash snd_rme9652_playback_copy 5 20970 _000586_hash NULL
84586 +_000587_hash snd_sb_csp_load_user 3 45190 _000587_hash NULL
84587 +_000588_hash snd_usb_ctl_msg 8 8436 _000588_hash NULL
84588 +_000589_hash sock_bindtodevice 3 50942 _000589_hash NULL
84589 +_000590_hash sock_kmalloc 2 62205 _000590_hash NULL
84590 +_000591_hash spidev_ioctl 2 12846 _000591_hash NULL
84591 +_000592_hash spidev_write 3 44510 _000592_hash NULL
84592 +_000593_hash squashfs_read_table 3 16945 _000593_hash NULL
84593 +_000594_hash srpt_alloc_ioctx 2-3 51042 _000594_hash NULL
84594 +_000596_hash srpt_alloc_ioctx_ring 2-4-3 49330 _000596_hash NULL
84595 +_000597_hash st5481_setup_isocpipes 6-4 61340 _000597_hash NULL
84596 +_000598_hash sta_agg_status_write 3 45164 _000598_hash NULL
84597 +_000599_hash svc_setsockopt 5 36876 _000599_hash NULL
84598 +_000600_hash sys_add_key 4 61288 _000600_hash NULL
84599 +_000601_hash sys_modify_ldt 3 18824 _000601_hash NULL
84600 +_000602_hash sys_semtimedop 3 4486 _000602_hash NULL
84601 +_000603_hash sys_setdomainname 2 4373 _000603_hash NULL
84602 +_000604_hash sys_sethostname 2 42962 _000604_hash NULL
84603 +_000605_hash tomoyo_write_self 3 45161 _000605_hash NULL
84604 +_000606_hash tower_write 3 8580 _000606_hash NULL
84605 +_000607_hash tpm_write 3 50798 _000607_hash NULL
84606 +_000608_hash trusted_instantiate 3 4710 _000608_hash NULL
84607 +_000609_hash trusted_update 3 12664 _000609_hash NULL
84608 +_000610_hash tty_buffer_alloc 2 45437 _000610_hash NULL
84609 +_000611_hash __tun_chr_ioctl 4 22300 _000611_hash NULL
84610 +_000612_hash ubi_more_leb_change_data 4 63534 _000612_hash NULL
84611 +_000613_hash ubi_more_update_data 4 39189 _000613_hash NULL
84612 +_000614_hash ubi_resize_volume 2 50172 _000614_hash NULL
84613 +_000615_hash udf_alloc_i_data 2 35786 _000615_hash NULL
84614 +_000616_hash uea_idma_write 3 64139 _000616_hash NULL
84615 +_000617_hash uea_request 4 47613 _000617_hash NULL
84616 +_000618_hash uea_send_modem_cmd 3 3888 _000618_hash NULL
84617 +_000619_hash uio_write 3 43202 _000619_hash NULL
84618 +_000620_hash um_idi_write 3 18293 _000620_hash NULL
84619 +_000621_hash us122l_ctl_msg 8 13330 _000621_hash NULL
84620 +_000622_hash usb_alloc_urb 1 43436 _000622_hash NULL
84621 +_000623_hash usblp_new_writeurb 2 22894 _000623_hash NULL
84622 +_000624_hash usblp_write 3 23178 _000624_hash NULL
84623 +_000625_hash usbtest_alloc_urb 3-5 34446 _000625_hash NULL
84624 +_000627_hash usbtmc_write 3 64340 _000627_hash NULL
84625 +_000628_hash user_instantiate 3 26131 _000628_hash NULL
84626 +_000629_hash user_update 3 41332 _000629_hash NULL
84627 +_000630_hash uwb_rc_cmd_done 4 35892 _000630_hash NULL
84628 +_000631_hash uwb_rc_neh_grok_event 3 55799 _000631_hash NULL
84629 +_000632_hash v9fs_alloc_rdir_buf 2 42150 _000632_hash NULL
84630 +_000633_hash vc_do_resize 3-4 48842 _000633_hash NULL
84631 +_000635_hash vcs_write 3 3910 _000635_hash NULL
84632 +_000636_hash vga_arb_write 3 36112 _000636_hash NULL
84633 +_000637_hash vga_switcheroo_debugfs_write 3 33984 _000637_hash NULL
84634 +_000638_hash vhci_get_user 3 45039 _000638_hash NULL
84635 +_000639_hash video_proc_write 3 6724 _000639_hash NULL
84636 +_000640_hash vlsi_alloc_ring 3-4 57003 _000640_hash NULL
84637 +_000642_hash __vmalloc 1 61168 _000642_hash NULL
84638 +_000643_hash vmalloc_32 1 1135 _000643_hash NULL
84639 +_000644_hash vmalloc_32_user 1 37519 _000644_hash NULL
84640 +_000645_hash vmalloc_exec 1 36132 _000645_hash NULL
84641 +_000646_hash vmalloc_node 1 58700 _000646_hash NULL
84642 +_000647_hash __vmalloc_node_flags 1 30352 _000647_hash NULL
84643 +_000648_hash vmalloc_user 1 32308 _000648_hash NULL
84644 +_000649_hash vol_cdev_direct_write 3 20751 _000649_hash NULL
84645 +_000650_hash vp_request_msix_vectors 2 28849 _000650_hash NULL
84646 +_000651_hash vring_add_indirect 3-4 20737 _000651_hash NULL
84647 +_000653_hash vring_new_virtqueue 1 9671 _000653_hash NULL
84648 +_000654_hash vxge_os_dma_malloc 2 46184 _000654_hash NULL
84649 +_000655_hash vxge_os_dma_malloc_async 3 56348 _000655_hash NULL
84650 +_000656_hash wdm_write 3 53735 _000656_hash NULL
84651 +_000657_hash wiimote_hid_send 3 48528 _000657_hash NULL
84652 +_000658_hash wlc_phy_loadsampletable_nphy 3 64367 _000658_hash NULL
84653 +_000659_hash write 3 62671 _000659_hash NULL
84654 +_000660_hash write_flush 3 50803 _000660_hash NULL
84655 +_000661_hash write_rio 3 54837 _000661_hash NULL
84656 +_000662_hash x25_asy_change_mtu 2 26928 _000662_hash NULL
84657 +_000663_hash xdi_copy_from_user 4 8395 _000663_hash NULL
84658 +_000664_hash xfrm_dst_alloc_copy 3 3034 _000664_hash NULL
84659 +_000665_hash xfrm_user_policy 4 62573 _000665_hash NULL
84660 +_000666_hash xfs_attrmulti_attr_set 4 59346 _000666_hash NULL
84661 +_000667_hash xfs_handle_to_dentry 3 12135 _000667_hash NULL
84662 +_000668_hash xip_file_read 3 58592 _000668_hash NULL
84663 +_000669_hash __xip_file_write 3-4 2733 _000669_hash NULL
84664 +_000671_hash xprt_rdma_allocate 2 31372 _000671_hash NULL
84665 +_000672_hash zd_usb_iowrite16v_async 3 23984 _000672_hash NULL
84666 +_000673_hash zd_usb_read_fw 4 22049 _000673_hash NULL
84667 +_000674_hash zerocopy_sg_from_iovec 3 11828 _000674_hash NULL
84668 +_000675_hash __a2mp_build 3 60987 _000675_hash NULL
84669 +_000677_hash acpi_ex_allocate_name_string 2-1 7685 _001169_hash NULL nohasharray
84670 +_000678_hash acpi_os_allocate_zeroed 1 37422 _000678_hash NULL
84671 +_000679_hash acpi_ut_initialize_buffer 2 47143 _002830_hash NULL nohasharray
84672 +_000680_hash ad7879_spi_xfer 3 36311 _000680_hash NULL
84673 +_000681_hash add_new_gdb 3 27643 _000681_hash NULL
84674 +_000682_hash add_numbered_child 5 14273 _000682_hash NULL
84675 +_000683_hash add_res_range 4 21310 _000683_hash NULL
84676 +_000684_hash addtgt 3 54703 _000684_hash NULL
84677 +_000685_hash add_uuid 4 49831 _000685_hash NULL
84678 +_000686_hash afs_cell_alloc 2 24052 _000686_hash NULL
84679 +_000687_hash aggr_recv_addba_req_evt 4 38037 _000687_hash NULL
84680 +_000688_hash agp_create_memory 1 1075 _000688_hash NULL
84681 +_000689_hash agp_create_user_memory 1 62955 _000689_hash NULL
84682 +_000690_hash alg_setsockopt 5 20985 _000690_hash NULL
84683 +_000691_hash alloc_async 1 14208 _000691_hash NULL
84684 +_000692_hash ___alloc_bootmem_nopanic 1 53626 _000692_hash NULL
84685 +_000693_hash alloc_buf 1 34532 _000693_hash NULL
84686 +_000694_hash alloc_chunk 1 49575 _000694_hash NULL
84687 +_000695_hash alloc_context 1 41283 _000695_hash NULL
84688 +_000696_hash alloc_ctrl_packet 1 44667 _000696_hash NULL
84689 +_000697_hash alloc_data_packet 1 46698 _000697_hash NULL
84690 +_000698_hash alloc_dca_provider 2 59670 _000698_hash NULL
84691 +_000699_hash __alloc_dev_table 2 54343 _000699_hash NULL
84692 +_000700_hash alloc_ep 1 17269 _000700_hash NULL
84693 +_000701_hash __alloc_extent_buffer 3 15093 _000701_hash NULL
84694 +_000702_hash alloc_group_attrs 2 9194 _000727_hash NULL nohasharray
84695 +_000703_hash alloc_large_system_hash 2 22391 _000703_hash NULL
84696 +_000704_hash alloc_netdev_mqs 1 30030 _000704_hash NULL
84697 +_000705_hash __alloc_objio_seg 1 7203 _000705_hash NULL
84698 +_000706_hash alloc_ring 2-4 15345 _000706_hash NULL
84699 +_000707_hash alloc_ring 2-4 39151 _000707_hash NULL
84700 +_000710_hash alloc_session 1-2 64171 _000710_hash NULL
84701 +_000714_hash alloc_skb 1 55439 _000714_hash NULL
84702 +_000715_hash alloc_skb_fclone 1 3467 _000715_hash NULL
84703 +_000716_hash alloc_smp_req 1 51337 _000716_hash NULL
84704 +_000717_hash alloc_smp_resp 1 3566 _000717_hash NULL
84705 +_000718_hash alloc_ts_config 1 45775 _000718_hash NULL
84706 +_000719_hash alloc_upcall 2 62186 _000719_hash NULL
84707 +_000720_hash altera_drscan 2 48698 _000720_hash NULL
84708 +_000721_hash altera_irscan 2 62396 _000721_hash NULL
84709 +_000722_hash altera_set_dr_post 2 54291 _000722_hash NULL
84710 +_000723_hash altera_set_dr_pre 2 64862 _000723_hash NULL
84711 +_000724_hash altera_set_ir_post 2 20948 _000724_hash NULL
84712 +_000725_hash altera_set_ir_pre 2 54103 _000725_hash NULL
84713 +_000726_hash altera_swap_dr 2 50090 _000726_hash NULL
84714 +_000727_hash altera_swap_ir 2 9194 _000727_hash &_000702_hash
84715 +_000728_hash amd_create_gatt_pages 1 20537 _000728_hash NULL
84716 +_000729_hash aoechr_write 3 62883 _003674_hash NULL nohasharray
84717 +_000730_hash applesmc_create_nodes 2 49392 _000730_hash NULL
84718 +_000731_hash array_zalloc 1-2 7519 _000731_hash NULL
84719 +_000733_hash arvo_sysfs_read 6 31617 _000733_hash NULL
84720 +_000734_hash arvo_sysfs_write 6 3311 _000734_hash NULL
84721 +_000735_hash asd_store_update_bios 4 10165 _000735_hash NULL
84722 +_000736_hash ata_host_alloc 2 46094 _000736_hash NULL
84723 +_000737_hash atalk_sendmsg 4 21677 _000737_hash NULL
84724 +_000738_hash ath6kl_cfg80211_connect_event 7-9-8 13443 _000738_hash NULL
84725 +_000739_hash ath6kl_mgmt_tx 9 21153 _000739_hash NULL
84726 +_000740_hash ath6kl_wmi_proc_events_vif 5 42549 _003190_hash NULL nohasharray
84727 +_000741_hash ath6kl_wmi_roam_tbl_event_rx 3 43440 _000741_hash NULL
84728 +_000742_hash ath6kl_wmi_send_mgmt_cmd 7 17347 _000742_hash NULL
84729 +_000743_hash ath_descdma_setup 5 12257 _000743_hash NULL
84730 +_000744_hash ath_rx_edma_init 2 65483 _000744_hash NULL
84731 +_000745_hash ati_create_gatt_pages 1 4722 _003275_hash NULL nohasharray
84732 +_000746_hash audit_expand 2 2098 _000746_hash NULL
84733 +_000747_hash audit_init_entry 1 38644 _000747_hash NULL
84734 +_000748_hash ax25_sendmsg 4 62770 _000748_hash NULL
84735 +_000749_hash b1_alloc_card 1 36155 _000749_hash NULL
84736 +_000750_hash b43_nphy_load_samples 3 36481 _000750_hash NULL
84737 +_000751_hash batadv_orig_hash_add_if 2 10033 _000751_hash NULL
84738 +_000752_hash batadv_orig_hash_del_if 2 48972 _000752_hash NULL
84739 +_000753_hash batadv_tt_append_diff 4 20588 _000753_hash NULL
84740 +_000754_hash batadv_tt_commit_changes 4 2008 _000754_hash NULL
84741 +_000755_hash batadv_tt_prepare_packet_buff 4 1280 _000755_hash NULL
84742 +_000756_hash bio_copy_user_iov 4 37660 _000756_hash NULL
84743 +_000757_hash __bio_map_kern 3 47379 _000757_hash NULL
84744 +_000758_hash bitmap_resize 2 33054 _000758_hash NULL
84745 +_000759_hash blk_check_plugged 3 50736 _000759_hash NULL
84746 +_000760_hash blk_register_region 1-2 51424 _000760_hash NULL
84747 +_000762_hash bm_entry_write 3 28338 _000762_hash NULL
84748 +_000763_hash bm_realloc_pages 2 9431 _000763_hash NULL
84749 +_000764_hash bm_register_write 3 9893 _000764_hash &_000579_hash
84750 +_000765_hash bm_status_write 3 12964 _000765_hash NULL
84751 +_000766_hash br_mdb_rehash 2 42643 _000766_hash NULL
84752 +_000767_hash btmrvl_sdio_host_to_card 3 12152 _000767_hash NULL
84753 +_000768_hash btrfs_copy_from_user 1-3 43806 _000768_hash NULL
84754 +_000770_hash btrfs_insert_delayed_dir_index 4 63720 _000770_hash NULL
84755 +_000771_hash __btrfs_map_block 3 49839 _000771_hash NULL
84756 +_000772_hash c4iw_init_resource 2-3 30393 _000772_hash NULL
84757 +_000774_hash cache_downcall 3 13666 _000774_hash NULL
84758 +_000775_hash cache_slow_downcall 2 8570 _000775_hash NULL
84759 +_000776_hash caif_seqpkt_sendmsg 4 22961 _000776_hash NULL
84760 +_000777_hash caif_stream_sendmsg 4 9110 _000777_hash NULL
84761 +_000778_hash carl9170_cmd_buf 3 950 _000778_hash NULL
84762 +_000779_hash cdev_add 2-3 38176 _000779_hash NULL
84763 +_000781_hash cdrom_read_cdda 4 50478 _000781_hash NULL
84764 +_000782_hash ceph_dns_resolve_name 2 62488 _000782_hash NULL
84765 +_000783_hash ceph_msgpool_get 2 54258 _000783_hash NULL
84766 +_000784_hash cfg80211_connect_result 4-6 56515 _000784_hash NULL
84767 +_000786_hash cfg80211_disconnected 4 57 _000786_hash NULL
84768 +_000787_hash cfg80211_inform_bss 8 19332 _000787_hash NULL
84769 +_000788_hash cfg80211_inform_bss_frame 4 41078 _000788_hash NULL
84770 +_000789_hash cfg80211_mlme_register_mgmt 5 19852 _000789_hash NULL
84771 +_000790_hash cfg80211_roamed_bss 4-6 50198 _000790_hash NULL
84772 +_000792_hash cgroup_file_write 3 52417 _000792_hash NULL
84773 +_000793_hash cifs_readdata_alloc 1 26360 _000793_hash NULL
84774 +_000794_hash cifs_readv_from_socket 3 19109 _000794_hash NULL
84775 +_000795_hash cifs_writedata_alloc 1 32880 _003097_hash NULL nohasharray
84776 +_000796_hash cnic_alloc_dma 3 34641 _000796_hash NULL
84777 +_000797_hash cnic_init_id_tbl 2 41354 _000797_hash NULL
84778 +_000798_hash configfs_write_file 3 61621 _000798_hash NULL
84779 +_000799_hash construct_key 3 11329 _000799_hash NULL
84780 +_000800_hash context_alloc 3 24645 _000800_hash NULL
84781 +_000801_hash copy_to_user 3 57835 _000801_hash NULL
84782 +_000802_hash cp210x_get_config 4 56229 _000802_hash NULL
84783 +_000803_hash create_attr_set 1 22861 _000803_hash NULL
84784 +_000804_hash create_bounce_buffer 3 39155 _000804_hash NULL
84785 +_000805_hash create_gpadl_header 2 19064 _000805_hash NULL
84786 +_000806_hash _create_sg_bios 4 31244 _000806_hash NULL
84787 +_000807_hash cryptd_alloc_instance 2-3 18048 _000807_hash NULL
84788 +_000809_hash crypto_ahash_setkey 3 55134 _000809_hash NULL
84789 +_000810_hash crypto_alloc_instance2 3 25277 _000810_hash NULL
84790 +_000811_hash crypto_shash_setkey 3 60483 _000811_hash NULL
84791 +_000812_hash cxgb_alloc_mem 1 24007 _000812_hash NULL
84792 +_000813_hash cxgbi_device_portmap_create 3 25747 _000813_hash NULL
84793 +_000814_hash cxgbi_device_register 1-2 36746 _000814_hash NULL
84794 +_000816_hash __cxio_init_resource_fifo 3 23447 _000816_hash NULL
84795 +_000817_hash dccp_sendmsg 4 56058 _000817_hash NULL
84796 +_000818_hash ddp_make_gl 1 12179 _000818_hash NULL
84797 +_000819_hash depth_write 3 3021 _000819_hash NULL
84798 +_000820_hash dev_irnet_write 3 11398 _000820_hash NULL
84799 +_000821_hash dev_set_alias 3 50084 _000821_hash NULL
84800 +_000822_hash dev_write 3 7708 _000822_hash NULL
84801 +_000823_hash dfs_global_file_write 3 6112 _000823_hash NULL
84802 +_000824_hash dgram_sendmsg 4 45679 _000824_hash NULL
84803 +_000825_hash disconnect 4 32521 _000825_hash NULL
84804 +_000826_hash dma_attach 6-7 50831 _000826_hash NULL
84805 +_000828_hash dma_declare_coherent_memory 4-2 14244 _000828_hash NULL
84806 +_000829_hash dn_sendmsg 4 38390 _000829_hash NULL
84807 +_000830_hash dn_setsockopt 5 314 _000830_hash NULL
84808 +_000831_hash do_arpt_set_ctl 4 51053 _000831_hash NULL
84809 +_000832_hash do_dccp_setsockopt 5 54377 _003195_hash NULL nohasharray
84810 +_000833_hash do_ip6t_set_ctl 4 60040 _000833_hash NULL
84811 +_000834_hash do_ipt_set_ctl 4 56238 _000834_hash NULL
84812 +_000835_hash do_jffs2_setxattr 5 25910 _000835_hash NULL
84813 +_000836_hash do_msgsnd 4 1387 _000836_hash NULL
84814 +_000837_hash do_pselect 1 62061 _000837_hash NULL
84815 +_000838_hash do_raw_setsockopt 5 55215 _000838_hash NULL
84816 +_000839_hash do_readv_writev 4 51849 _000839_hash NULL
84817 +_000840_hash do_sync 1 9604 _000840_hash NULL
84818 +_000841_hash dup_array 3 33551 _000841_hash NULL
84819 +_000842_hash ecryptfs_decode_and_decrypt_filename 5 10379 _000842_hash NULL
84820 +_000843_hash ecryptfs_encrypt_and_encode_filename 6 2109 _000843_hash NULL
84821 +_000844_hash ecryptfs_send_message_locked 2 31801 _000844_hash NULL
84822 +_000845_hash edac_device_alloc_ctl_info 1 5941 _000845_hash NULL
84823 +_000846_hash edac_mc_alloc 4 3611 _000846_hash NULL
84824 +_000847_hash edac_pci_alloc_ctl_info 1 63388 _000847_hash NULL
84825 +_000848_hash efivar_create_sysfs_entry 2 19485 _000848_hash NULL
84826 +_000849_hash enable_write 3 30456 _000849_hash NULL
84827 +_000850_hash enclosure_register 3 57412 _000850_hash NULL
84828 +_000851_hash enlarge_skb 2 44248 _002839_hash NULL nohasharray
84829 +_000852_hash evdev_ioctl_handler 2 21705 _000852_hash NULL
84830 +_000853_hash ext4_kvzalloc 1 47605 _000853_hash NULL
84831 +_000854_hash extend_netdev_table 2 21453 _000854_hash NULL
84832 +_000855_hash fcoe_ctlr_device_add 3 1793 _000855_hash NULL
84833 +_000856_hash fd_do_readv 3 51297 _000856_hash NULL
84834 +_000857_hash fd_do_writev 3 29329 _000857_hash NULL
84835 +_000858_hash __feat_register_sp 6 64712 _000858_hash NULL
84836 +_000859_hash __ffs_ep0_read_events 3 48868 _000859_hash NULL
84837 +_000860_hash ffs_ep0_write 3 9438 _000860_hash NULL
84838 +_000861_hash ffs_epfile_read 3 18775 _000861_hash NULL
84839 +_000862_hash ffs_epfile_write 3 48014 _000862_hash NULL
84840 +_000863_hash fib_info_hash_alloc 1 9075 _000863_hash NULL
84841 +_000864_hash fillonedir 3 41746 _000864_hash NULL
84842 +_000865_hash fs_devrw_entry 3 11924 _000865_hash NULL
84843 +_000866_hash fs_path_prepare_for_add 2 61854 _000866_hash NULL
84844 +_000867_hash fuse_fill_write_pages 4 53682 _000867_hash NULL
84845 +_000868_hash fw_device_op_ioctl 2 11595 _000868_hash NULL
84846 +_000869_hash fw_iso_buffer_init 3 54582 _000869_hash NULL
84847 +_000870_hash fw_node_create 2 9559 _000870_hash NULL
84848 +_000871_hash garmin_read_process 3 27509 _000871_hash NULL
84849 +_000872_hash garp_request_join 4 7471 _000872_hash NULL
84850 +_000873_hash generic_perform_write 3 54832 _000873_hash NULL
84851 +_000874_hash gen_pool_add_virt 4 39913 _000874_hash NULL
84852 +_000875_hash get_derived_key 4 61100 _000875_hash NULL
84853 +_000876_hash get_new_cssid 2 51665 _000876_hash NULL
84854 +_000877_hash getxattr 4 24398 _003758_hash NULL nohasharray
84855 +_000878_hash gsm_control_reply 4 53333 _000878_hash NULL
84856 +_000879_hash hcd_alloc_coherent 5 55862 _000879_hash NULL
84857 +_000880_hash hci_sock_sendmsg 4 37420 _000880_hash NULL
84858 +_000881_hash hidraw_ioctl 2 63658 _000881_hash NULL
84859 +_000882_hash hidraw_write 3 31536 _000882_hash NULL
84860 +_000883_hash hid_register_field 2-3 4874 _000883_hash NULL
84861 +_000885_hash hid_report_raw_event 4 2762 _000885_hash NULL
84862 +_000886_hash hpi_alloc_control_cache 1 35351 _000886_hash NULL
84863 +_000887_hash hugetlbfs_read_actor 2-5-4 34547 _000887_hash NULL
84864 +_000890_hash hvc_alloc 4 12579 _000890_hash NULL
84865 +_000891_hash __hwahc_dev_set_key 5 46328 _000891_hash NULL
84866 +_000892_hash i2400m_zrealloc_2x 3 54166 _001549_hash NULL nohasharray
84867 +_000893_hash ib_alloc_device 1 26483 _000893_hash NULL
84868 +_000894_hash ib_create_send_mad 5 1196 _000894_hash NULL
84869 +_000895_hash ibmasm_new_command 2 25714 _000895_hash NULL
84870 +_000896_hash ib_send_cm_drep 3 50186 _000896_hash NULL
84871 +_000897_hash ib_send_cm_mra 4 60202 _003063_hash NULL nohasharray
84872 +_000898_hash ib_send_cm_rtu 3 63138 _000898_hash NULL
84873 +_000899_hash ide_core_cp_entry 3 22636 _000899_hash NULL
84874 +_000900_hash ieee80211_if_write_smps 3 35550 _000900_hash NULL
84875 +_000901_hash ieee80211_if_write_tkip_mic_test 3 58748 _000901_hash NULL
84876 +_000902_hash ieee80211_if_write_tsf 3 36077 _000902_hash NULL
84877 +_000903_hash ieee80211_if_write_uapsd_max_sp_len 3 14233 _000903_hash NULL
84878 +_000904_hash ieee80211_if_write_uapsd_queues 3 51526 _000904_hash NULL
84879 +_000905_hash ieee80211_key_alloc 3 19065 _000905_hash NULL
84880 +_000906_hash ieee80211_send_probe_req 6-4 6924 _000906_hash NULL
84881 +_000907_hash ieee80211_skb_resize 3 50211 _000907_hash NULL
84882 +_000908_hash if_spi_host_to_card 4 62890 _000908_hash NULL
84883 +_000909_hash if_writecmd 2 815 _000909_hash NULL
84884 +_000910_hash init_bch 1-2 64130 _000910_hash NULL
84885 +_000912_hash init_ipath 1 48187 _000912_hash NULL
84886 +_000913_hash init_list_set 2-3 39188 _000913_hash NULL
84887 +_000915_hash init_q 4 132 _000915_hash NULL
84888 +_000916_hash init_state 2 60165 _000916_hash NULL
84889 +_000917_hash init_tag_map 3 57515 _000917_hash NULL
84890 +_000918_hash input_ff_create 2 21240 _000918_hash NULL
84891 +_000919_hash input_mt_init_slots 2 31183 _000919_hash NULL
84892 +_000920_hash interfaces 2 38859 _000920_hash NULL
84893 +_000921_hash int_hardware_entry 3 36833 _000921_hash NULL
84894 +_000922_hash int_hw_irq_en 3 46776 _000922_hash NULL
84895 +_000923_hash int_tasklet_entry 3 52500 _000923_hash NULL
84896 +_000924_hash ioat2_alloc_ring 2 11172 _000924_hash NULL
84897 +_000925_hash ip_generic_getfrag 3-4 12187 _000925_hash NULL
84898 +_000927_hash ip_options_get_alloc 1 7448 _000927_hash NULL
84899 +_000928_hash ipr_alloc_ucode_buffer 1 40199 _000928_hash NULL
84900 +_000929_hash ip_set_alloc 1 57953 _000929_hash NULL
84901 +_000930_hash ip_setsockopt 5 33487 _000930_hash NULL
84902 +_000931_hash ipv6_flowlabel_opt 3 58135 _001179_hash NULL nohasharray
84903 +_000932_hash ipv6_renew_options 5 28867 _000932_hash NULL
84904 +_000933_hash ipv6_setsockopt 5 29871 _000933_hash NULL
84905 +_000934_hash ipxrtr_route_packet 4 54036 _000934_hash NULL
84906 +_000935_hash irda_sendmsg 4 4388 _000935_hash NULL
84907 +_000936_hash irda_sendmsg_dgram 4 38563 _000936_hash NULL
84908 +_000937_hash irda_sendmsg_ultra 4 42047 _000937_hash NULL
84909 +_000938_hash irias_add_octseq_attrib 4 29983 _000938_hash NULL
84910 +_000939_hash irq_alloc_generic_chip 2 26650 _000939_hash NULL
84911 +_000940_hash iscsi_alloc_session 3 49390 _000940_hash NULL
84912 +_000941_hash iscsi_create_conn 2 50425 _000941_hash NULL
84913 +_000942_hash iscsi_create_endpoint 1 15193 _000942_hash NULL
84914 +_000943_hash iscsi_create_iface 5 38510 _000943_hash NULL
84915 +_000944_hash iscsi_decode_text_input 4 58292 _000944_hash NULL
84916 +_000945_hash iscsi_pool_init 2-4 54913 _000945_hash NULL
84917 +_000947_hash iscsit_dump_data_payload 2 38683 _000947_hash NULL
84918 +_000948_hash isdn_write 3 45863 _000948_hash NULL
84919 +_000949_hash isku_receive 4 54130 _000949_hash NULL
84920 +_000950_hash islpci_mgt_transaction 5 23610 _000950_hash NULL
84921 +_000951_hash iso_alloc_urb 4-5 45206 _000951_hash NULL
84922 +_000952_hash iso_sched_alloc 1 13377 _003325_hash NULL nohasharray
84923 +_000953_hash iwl_trans_txq_alloc 3 36147 _000953_hash NULL
84924 +_000954_hash ixgbe_alloc_q_vector 4-6 24439 _000954_hash NULL
84925 +_000956_hash jbd2_journal_init_revoke 2 51088 _000956_hash NULL
84926 +_000957_hash jffs2_write_dirent 5 37311 _000957_hash NULL
84927 +_000958_hash journal_init_revoke 2 56933 _000958_hash NULL
84928 +_000959_hash keyctl_instantiate_key 3 41855 _000959_hash NULL
84929 +_000960_hash keyctl_instantiate_key_iov 3 16969 _000960_hash NULL
84930 +_000961_hash __kfifo_from_user 3 20399 _000961_hash NULL
84931 +_000962_hash kimage_crash_alloc 3 3233 _000962_hash NULL
84932 +_000963_hash kimage_normal_alloc 3 31140 _000963_hash NULL
84933 +_000964_hash kmem_realloc 2 37489 _000964_hash NULL
84934 +_000965_hash kmem_zalloc 1 11510 _000965_hash NULL
84935 +_000966_hash koneplus_sysfs_read 6 42792 _000966_hash NULL
84936 +_000967_hash kvm_kvzalloc 1 52894 _000967_hash NULL
84937 +_000968_hash kvm_read_guest_page_mmu 6 37611 _000968_hash NULL
84938 +_000969_hash kvm_set_irq_routing 3 48704 _000969_hash NULL
84939 +_000970_hash kvm_write_guest_cached 4 11106 _000970_hash NULL
84940 +_000971_hash kvm_write_guest_page 5 63555 _002812_hash NULL nohasharray
84941 +_000972_hash kzalloc_node 1 24352 _000972_hash NULL
84942 +_000973_hash l2cap_skbuff_fromiovec 3-4 35003 _000973_hash NULL
84943 +_000975_hash l2tp_ip_sendmsg 4 50411 _000975_hash NULL
84944 +_000976_hash l2tp_session_create 1 25286 _000976_hash NULL
84945 +_000977_hash lc_create 3 48662 _000977_hash NULL
84946 +_000978_hash leaf_dealloc 3 29566 _000978_hash NULL
84947 +_000979_hash linear_conf 2 23485 _003837_hash NULL nohasharray
84948 +_000980_hash llc_ui_sendmsg 4 24987 _000980_hash NULL
84949 +_000981_hash load_module 2 60056 _003010_hash NULL nohasharray
84950 +_000982_hash lpfc_sli4_queue_alloc 3 62646 _000982_hash NULL
84951 +_000983_hash mdiobus_alloc_size 1 52259 _000983_hash NULL
84952 +_000984_hash mempool_create_node 1 3191 _000984_hash NULL
84953 +_000985_hash mem_read 3 57631 _000985_hash NULL
84954 +_000986_hash memstick_alloc_host 1 142 _000986_hash NULL
84955 +_000987_hash mem_swapout_entry 3 32586 _000987_hash NULL
84956 +_000988_hash mem_write 3 22232 _000988_hash NULL
84957 +_000989_hash mesh_table_alloc 1 22305 _000989_hash NULL
84958 +_000990_hash mfd_add_devices 4 16668 _000990_hash NULL
84959 +_000991_hash mISDN_sock_sendmsg 4 41035 _000991_hash NULL
84960 +_000992_hash mlx4_init_icm_table 4-5 2151 _000992_hash NULL
84961 +_000994_hash mmc_alloc_host 1 48097 _000994_hash NULL
84962 +_000995_hash mmc_test_alloc_mem 2-3 28102 _000995_hash NULL
84963 +_000997_hash mon_bin_ioctl 3 2771 _000997_hash NULL
84964 +_000998_hash mpi_alloc 1 18094 _000998_hash NULL
84965 +_000999_hash mpihelp_mul_karatsuba_case 5-3 23918 _003061_hash NULL nohasharray
84966 +_001000_hash __mptctl_ioctl 2 15875 _001000_hash NULL
84967 +_001001_hash mtd_concat_create 2 14416 _001001_hash NULL
84968 +_001002_hash mthca_alloc_cq_buf 3 46512 _001002_hash NULL
84969 +_001003_hash mvumi_alloc_mem_resource 3 47750 _001003_hash NULL
84970 +_001004_hash mwifiex_11n_create_rx_reorder_tbl 4 63806 _001004_hash NULL
84971 +_001005_hash mwifiex_alloc_sdio_mpa_buffers 2-3 60961 _001005_hash NULL
84972 +_001007_hash mwl8k_cmd_set_beacon 4 23110 _001007_hash NULL
84973 +_001008_hash neigh_hash_alloc 1 17595 _001008_hash NULL
84974 +_001009_hash __netdev_alloc_skb 2 18595 _001009_hash NULL
84975 +_001010_hash __netlink_change_ngroups 2 46156 _001010_hash NULL
84976 +_001011_hash netlink_sendmsg 4 33708 _001236_hash NULL nohasharray
84977 +_001012_hash netxen_alloc_sds_rings 2 13417 _001012_hash NULL
84978 +_001013_hash new_bind_ctl 2 35324 _001013_hash NULL
84979 +_001014_hash new_dir 3 31919 _001014_hash NULL
84980 +_001015_hash new_tape_buffer 2 32866 _001015_hash NULL
84981 +_001016_hash nfc_llcp_build_tlv 3 19536 _001016_hash NULL
84982 +_001017_hash nfc_llcp_send_i_frame 3 59130 _001017_hash NULL
84983 +_001018_hash nf_ct_ext_create 3 51232 _001018_hash NULL
84984 +_001019_hash nfs4_alloc_pages 1 48426 _001019_hash NULL
84985 +_001020_hash nfs4_alloc_slots 1 2454 _003345_hash NULL nohasharray
84986 +_001021_hash nfsctl_transaction_write 3 64800 _001021_hash NULL
84987 +_001022_hash nfs_fscache_get_super_cookie 3 44355 _001850_hash NULL nohasharray
84988 +_001023_hash nfs_idmap_request_key 3 30208 _001023_hash NULL
84989 +_001024_hash nfs_pgarray_set 2 1085 _001024_hash NULL
84990 +_001025_hash nl_pid_hash_zalloc 1 23314 _001025_hash NULL
84991 +_001026_hash nr_sendmsg 4 53656 _001026_hash NULL
84992 +_001027_hash nsm_create_handle 4 38060 _001027_hash NULL
84993 +_001028_hash ntfs_copy_from_user_iovec 3-6 49829 _001028_hash NULL
84994 +_001030_hash ntfs_file_buffered_write 4-6 41442 _001030_hash NULL
84995 +_001032_hash __ntfs_malloc 1 34022 _001032_hash NULL
84996 +_001033_hash nvme_alloc_queue 3 46865 _001033_hash NULL
84997 +_001034_hash nvme_map_user_pages 3-4 41093 _001639_hash NULL nohasharray
84998 +_001036_hash ocfs2_acl_from_xattr 2 21604 _001036_hash NULL
84999 +_001037_hash ocfs2_control_message 3 19564 _001037_hash NULL
85000 +_001038_hash _ore_get_io_state 3-5-4 2166 _001038_hash NULL
85001 +_001041_hash orinoco_set_key 5-7 17878 _001041_hash NULL
85002 +_001043_hash osdmap_set_max_osd 2 57630 _002267_hash NULL nohasharray
85003 +_001044_hash _osd_realloc_seg 3 54352 _001044_hash NULL
85004 +_001045_hash osst_execute 7-6 17607 _001045_hash NULL
85005 +_001046_hash osst_write 3 31581 _001046_hash NULL
85006 +_001047_hash otp_read 2-5-4 10594 _001047_hash NULL
85007 +_001050_hash ovs_vport_alloc 1 33475 _001050_hash NULL
85008 +_001051_hash p54_parse_rssical 3 64493 _001051_hash NULL
85009 +_001052_hash p9_client_zc_rpc 7 14345 _001052_hash NULL
85010 +_001053_hash packet_sendmsg_spkt 4 28885 _001053_hash NULL
85011 +_001054_hash pair_device 4 61175 _003161_hash NULL nohasharray
85012 +_001055_hash pccard_store_cis 6 18176 _001055_hash NULL
85013 +_001056_hash pci_add_cap_save_buffer 3 3426 _001056_hash NULL
85014 +_001057_hash pcnet32_realloc_rx_ring 3 36598 _001057_hash NULL
85015 +_001058_hash pcnet32_realloc_tx_ring 3 38428 _001058_hash NULL
85016 +_001059_hash pcpu_mem_zalloc 1 22948 _001059_hash NULL
85017 +_001060_hash pep_sendmsg 4 62524 _001060_hash NULL
85018 +_001061_hash pfkey_sendmsg 4 47394 _001061_hash NULL
85019 +_001062_hash pidlist_resize 2 496 _001062_hash NULL
85020 +_001063_hash pin_code_reply 4 46510 _001063_hash NULL
85021 +_001064_hash ping_getfrag 3-4 8360 _001064_hash NULL
85022 +_001066_hash pipe_set_size 2 5204 _001066_hash NULL
85023 +_001067_hash pkt_bio_alloc 1 48284 _001067_hash NULL
85024 +_001068_hash platform_create_bundle 4-6 12785 _001068_hash NULL
85025 +_001070_hash pm8001_store_update_fw 4 55716 _001070_hash NULL
85026 +_001071_hash pmcraid_alloc_sglist 1 9864 _001071_hash NULL
85027 +_001072_hash pn533_dep_link_up 5 22154 _001072_hash NULL
85028 +_001073_hash pn533_init_target_frame 3 65438 _001073_hash NULL
85029 +_001074_hash pnp_alloc 1 24869 _001538_hash NULL nohasharray
85030 +_001075_hash pn_sendmsg 4 12640 _001075_hash NULL
85031 +_001076_hash pppoe_sendmsg 4 48039 _001076_hash NULL
85032 +_001077_hash pppol2tp_sendmsg 4 56420 _001077_hash NULL
85033 +_001078_hash prism2_info_hostscanresults 3 39657 _001078_hash NULL
85034 +_001079_hash process_vm_rw 3-5 47533 _001079_hash NULL
85035 +_001081_hash process_vm_rw_single_vec 1-2 26213 _001081_hash NULL
85036 +_001083_hash proc_write 3 51003 _001083_hash NULL
85037 +_001084_hash profile_load 3 58267 _001084_hash NULL
85038 +_001085_hash profile_remove 3 8556 _001085_hash NULL
85039 +_001086_hash profile_replace 3 14652 _001086_hash NULL
85040 +_001087_hash pscsi_get_bio 1 56103 _001087_hash NULL
85041 +_001088_hash __pskb_copy 2 9038 _001088_hash NULL
85042 +_001089_hash __pskb_pull_tail 2 60287 _001089_hash NULL
85043 +_001090_hash qla4xxx_alloc_work 2 44813 _001090_hash NULL
85044 +_001091_hash qlcnic_alloc_msix_entries 2 46160 _001091_hash NULL
85045 +_001092_hash qlcnic_alloc_sds_rings 2 26795 _001092_hash NULL
85046 +_001093_hash queue_received_packet 5 9657 _001093_hash NULL
85047 +_001094_hash raw_send_hdrinc 4 58803 _001094_hash NULL
85048 +_001095_hash raw_sendmsg 4 23078 _003316_hash NULL nohasharray
85049 +_001096_hash rawsock_sendmsg 4 60010 _001096_hash NULL
85050 +_001097_hash rawv6_send_hdrinc 3 35425 _001097_hash NULL
85051 +_001098_hash rawv6_setsockopt 5 56165 _001098_hash NULL
85052 +_001099_hash rb_alloc 1 3102 _001099_hash NULL
85053 +_001100_hash rbd_alloc_coll 1 33678 _001100_hash NULL
85054 +_001101_hash rbd_create_rw_ops 1 55297 _001101_hash NULL
85055 +_001102_hash rds_ib_inc_copy_to_user 3 55007 _001102_hash NULL
85056 +_001103_hash rds_iw_inc_copy_to_user 3 29214 _001103_hash NULL
85057 +_001104_hash rds_message_alloc 1 10517 _001104_hash NULL
85058 +_001105_hash rds_message_copy_from_user 3 45510 _001105_hash NULL
85059 +_001106_hash rds_message_inc_copy_to_user 3 26540 _001106_hash NULL
85060 +_001107_hash regcache_rbtree_insert_to_block 5 58009 _001107_hash NULL
85061 +_001108_hash _regmap_raw_write 4 42652 _001108_hash NULL
85062 +_001109_hash regmap_register_patch 3 21681 _001109_hash NULL
85063 +_001110_hash relay_alloc_page_array 1 52735 _001110_hash NULL
85064 +_001111_hash remove_uuid 4 64505 _001111_hash NULL
85065 +_001112_hash reshape_ring 2 29147 _001112_hash NULL
85066 +_001113_hash RESIZE_IF_NEEDED 2 56286 _001113_hash NULL
85067 +_001114_hash resize_info_buffer 2 62889 _001114_hash NULL
85068 +_001115_hash resize_stripes 2 61650 _001115_hash NULL
85069 +_001116_hash rfcomm_sock_sendmsg 4 37661 _003661_hash NULL nohasharray
85070 +_001117_hash roccat_common2_send_with_status 4 50343 _001117_hash NULL
85071 +_001118_hash rose_sendmsg 4 20249 _001118_hash NULL
85072 +_001119_hash rsc_mgr_init 3 16299 _001119_hash NULL
85073 +_001120_hash rxrpc_send_data 5 21553 _001120_hash NULL
85074 +_001121_hash rxrpc_setsockopt 5 50286 _001121_hash NULL
85075 +_001122_hash savu_sysfs_read 6 49473 _001122_hash NULL
85076 +_001124_hash sco_send_frame 3 41815 _001124_hash NULL
85077 +_001125_hash scsi_dispatch_cmd_entry 3 49848 _001125_hash NULL
85078 +_001126_hash scsi_host_alloc 2 63041 _001126_hash NULL
85079 +_001127_hash scsi_tgt_kspace_exec 8 9522 _001127_hash NULL
85080 +_001128_hash sctp_sendmsg 4 61919 _001128_hash NULL
85081 +_001129_hash sctp_setsockopt 5 44788 _001129_hash NULL
85082 +_001130_hash sctp_setsockopt_connectx 3 6073 _001130_hash NULL
85083 +_001131_hash sctp_setsockopt_connectx_old 3 22631 _001131_hash NULL
85084 +_001132_hash sctp_tsnmap_grow 2 32784 _001132_hash NULL
85085 +_001133_hash sctp_tsnmap_init 2 36446 _001133_hash NULL
85086 +_001134_hash sctp_user_addto_chunk 2-3 62047 _001134_hash NULL
85087 +_001136_hash security_context_to_sid 2 19839 _001136_hash NULL
85088 +_001137_hash security_context_to_sid_default 2 3492 _003841_hash NULL nohasharray
85089 +_001138_hash security_context_to_sid_force 2 20724 _001138_hash NULL
85090 +_001139_hash self_check_write 5 50856 _001139_hash NULL
85091 +_001140_hash selinux_transaction_write 3 59038 _001140_hash NULL
85092 +_001141_hash sel_write_access 3 51704 _001141_hash NULL
85093 +_001142_hash sel_write_create 3 11353 _001142_hash NULL
85094 +_001143_hash sel_write_member 3 28800 _001143_hash NULL
85095 +_001144_hash sel_write_relabel 3 55195 _001144_hash NULL
85096 +_001145_hash sel_write_user 3 45060 _001145_hash NULL
85097 +_001146_hash __seq_open_private 3 40715 _001146_hash NULL
85098 +_001147_hash serverworks_create_gatt_pages 1 46582 _001147_hash NULL
85099 +_001148_hash set_connectable 4 56458 _001148_hash NULL
85100 +_001149_hash set_dev_class 4 39645 _001921_hash NULL nohasharray
85101 +_001150_hash set_discoverable 4 48141 _001150_hash NULL
85102 +_001151_hash set_fd_set 1 35249 _001151_hash NULL
85103 +_001152_hash setkey 3 14987 _001152_hash NULL
85104 +_001153_hash set_le 4 30581 _001153_hash NULL
85105 +_001154_hash set_link_security 4 4502 _001154_hash NULL
85106 +_001155_hash set_local_name 4 55757 _001155_hash NULL
85107 +_001156_hash set_powered 4 12129 _001156_hash NULL
85108 +_001157_hash set_ssp 4 62411 _001157_hash NULL
85109 +_001158_hash sg_build_sgat 3 60179 _001158_hash &_000314_hash
85110 +_001159_hash sg_read_oxfer 3 51724 _001159_hash NULL
85111 +_001160_hash shmem_xattr_set 4 11843 _001160_hash NULL
85112 +_001161_hash simple_alloc_urb 3 60420 _001161_hash NULL
85113 +_001162_hash sisusb_send_bridge_packet 2 11649 _001162_hash NULL
85114 +_001163_hash sisusb_send_packet 2 20891 _001163_hash NULL
85115 +_001164_hash sisusb_write_mem_bulk 4 29678 _001164_hash NULL
85116 +_001165_hash skb_add_data_nocache 4 4682 _001165_hash NULL
85117 +_001166_hash skb_copy_datagram_from_iovec 2-5-4 52014 _001166_hash NULL
85118 +_001169_hash skb_copy_expand 2-3 7685 _001169_hash &_000677_hash
85119 +_001171_hash skb_copy_to_page_nocache 6 58624 _001171_hash NULL
85120 +_001172_hash __skb_cow 2 39254 _001172_hash NULL
85121 +_001173_hash skb_cow_data 2 11565 _001173_hash NULL
85122 +_001174_hash skb_pad 2 17302 _001174_hash NULL
85123 +_001175_hash skb_realloc_headroom 2 19516 _001175_hash NULL
85124 +_001176_hash sk_chk_filter 2 42095 _001176_hash NULL
85125 +_001177_hash skcipher_sendmsg 4 30290 _001177_hash NULL
85126 +_001178_hash sl_change_mtu 2 7396 _001178_hash NULL
85127 +_001179_hash slhc_init 1-2 58135 _001179_hash &_000931_hash
85128 +_001181_hash sm501_create_subdev 3-4 48668 _001245_hash NULL nohasharray
85129 +_001183_hash smk_user_access 3 24440 _001183_hash NULL
85130 +_001184_hash smk_write_cipso2 3 1021 _001184_hash NULL
85131 +_001185_hash smk_write_cipso 3 17989 _001185_hash NULL
85132 +_001186_hash smk_write_load2 3 52155 _001186_hash NULL
85133 +_001187_hash smk_write_load 3 26829 _001187_hash NULL
85134 +_001188_hash smk_write_load_self2 3 591 _001188_hash NULL
85135 +_001189_hash smk_write_load_self 3 7958 _001189_hash NULL
85136 +_001190_hash snapshot_write 3 28351 _001190_hash NULL
85137 +_001191_hash snd_ac97_pcm_assign 2 30218 _001191_hash NULL
85138 +_001192_hash snd_card_create 4 64418 _001529_hash NULL nohasharray
85139 +_001193_hash snd_emux_create_port 3 42533 _001193_hash NULL
85140 +_001194_hash snd_gus_dram_write 4 38784 _001194_hash NULL
85141 +_001195_hash snd_midi_channel_alloc_set 1 28153 _001195_hash NULL
85142 +_001196_hash _snd_pcm_lib_alloc_vmalloc_buffer 2 17820 _001196_hash NULL
85143 +_001197_hash snd_pcm_oss_sync1 2 45298 _001197_hash NULL
85144 +_001198_hash snd_pcm_oss_write 3 38108 _001198_hash NULL
85145 +_001199_hash snd_pcm_plugin_build 5 25505 _001199_hash NULL
85146 +_001200_hash snd_rawmidi_kernel_write 3 25106 _001200_hash NULL
85147 +_001201_hash snd_rawmidi_write 3 28008 _001201_hash NULL
85148 +_001202_hash snd_rme32_playback_copy 5 43732 _001202_hash NULL
85149 +_001203_hash snd_rme96_playback_copy 5 13111 _001203_hash NULL
85150 +_001204_hash snd_seq_device_new 4 31753 _001204_hash NULL
85151 +_001205_hash snd_seq_oss_readq_new 2 14283 _001205_hash NULL
85152 +_001206_hash snd_vx_create 4 40948 _001206_hash NULL
85153 +_001207_hash sock_setsockopt 5 50088 _001207_hash NULL
85154 +_001208_hash sound_write 3 5102 _001208_hash NULL
85155 +_001209_hash _sp2d_alloc 1-3-2 16944 _001209_hash NULL
85156 +_001212_hash spi_alloc_master 2 45223 _001212_hash NULL
85157 +_001213_hash spidev_message 3 5518 _001213_hash NULL
85158 +_001214_hash spi_register_board_info 2 35651 _001214_hash NULL
85159 +_001215_hash squashfs_cache_init 2 41656 _001215_hash NULL
85160 +_001216_hash squashfs_read_data 6 59440 _001216_hash NULL
85161 +_001217_hash squashfs_read_fragment_index_table 4 2506 _001217_hash NULL
85162 +_001218_hash squashfs_read_id_index_table 4 61961 _001218_hash NULL
85163 +_001219_hash squashfs_read_inode_lookup_table 4 64739 _001219_hash NULL
85164 +_001220_hash srp_alloc_iu 2 44227 _001220_hash NULL
85165 +_001221_hash srp_iu_pool_alloc 2 17920 _001221_hash NULL
85166 +_001222_hash srp_ring_alloc 2 26760 _001222_hash NULL
85167 +_001226_hash start_isoc_chain 2 565 _001226_hash NULL
85168 +_001227_hash st_write 3 16874 _001227_hash NULL
85169 +_001228_hash svc_pool_map_alloc_arrays 2 47181 _001228_hash NULL
85170 +_001229_hash symtab_init 2 61050 _001229_hash NULL
85171 +_001230_hash sys_bind 3 10799 _001230_hash NULL
85172 +_001231_hash sys_connect 3 15291 _003816_hash NULL nohasharray
85173 +_001232_hash sys_flistxattr 3 41407 _001232_hash NULL
85174 +_001233_hash sys_fsetxattr 4 49736 _001233_hash NULL
85175 +_001234_hash sysfs_write_file 3 57116 _001234_hash NULL
85176 +_001235_hash sys_ipc 3 4889 _001235_hash NULL
85177 +_001236_hash sys_keyctl 4 33708 _001236_hash &_001011_hash
85178 +_001237_hash sys_listxattr 3 27833 _001237_hash NULL
85179 +_001238_hash sys_llistxattr 3 4532 _001238_hash NULL
85180 +_001239_hash sys_lsetxattr 4 61177 _001239_hash NULL
85181 +_001240_hash sys_mq_timedsend 3 57661 _001240_hash NULL
85182 +_001241_hash sys_sched_setaffinity 2 32046 _001241_hash NULL
85183 +_001242_hash sys_select 1 38827 _001242_hash NULL
85184 +_001243_hash sys_semop 3 39457 _001243_hash NULL
85185 +_001244_hash sys_sendto 6 20809 _001244_hash NULL
85186 +_001245_hash sys_setgroups 1 48668 _001245_hash &_001181_hash
85187 +_001246_hash sys_setgroups16 1 48882 _001246_hash NULL
85188 +_001247_hash sys_setxattr 4 37880 _001247_hash NULL
85189 +_001248_hash t4_alloc_mem 1 32342 _001248_hash NULL
85190 +_001249_hash tcf_hash_create 4 54360 _001249_hash NULL
85191 +_001250_hash tcp_send_rcvq 3 11316 _001250_hash NULL
85192 +_001251_hash __team_options_register 3 63941 _001251_hash NULL
85193 +_001252_hash test_unaligned_bulk 3 52333 _001252_hash NULL
85194 +_001253_hash tifm_alloc_adapter 1 10903 _001253_hash NULL
85195 +_001254_hash timeout_write 3 50991 _001254_hash NULL
85196 +_001255_hash timeradd_entry 3 49850 _001255_hash NULL
85197 +_001256_hash tipc_link_send_sections_fast 4 37920 _001256_hash NULL
85198 +_001257_hash tipc_subseq_alloc 1 5957 _001257_hash NULL
85199 +_001258_hash tnode_alloc 1 49407 _001258_hash NULL
85200 +_001259_hash tomoyo_commit_ok 2 20167 _001259_hash NULL
85201 +_001260_hash tomoyo_scan_bprm 2-4 15642 _003488_hash NULL nohasharray
85202 +_001262_hash tps6586x_writes 3 58689 _001262_hash NULL
85203 +_001263_hash tty_buffer_find 2 2443 _001263_hash NULL
85204 +_001264_hash tty_write 3 5494 _001264_hash NULL
85205 +_001265_hash ubifs_setxattr 4 59650 _001477_hash NULL nohasharray
85206 +_001266_hash ubi_self_check_all_ff 4 41959 _001266_hash NULL
85207 +_001267_hash udf_sb_alloc_partition_maps 2 62313 _001267_hash NULL
85208 +_001268_hash udplite_getfrag 3-4 14479 _001268_hash NULL
85209 +_001270_hash ulong_write_file 3 26485 _001270_hash NULL
85210 +_001271_hash unix_stream_sendmsg 4 61455 _001271_hash NULL
85211 +_001272_hash unlink_queued 3-4 645 _001272_hash NULL
85212 +_001273_hash update_pmkid 4 2481 _001273_hash NULL
85213 +_001274_hash usb_alloc_coherent 2 65444 _001274_hash NULL
85214 +_001275_hash vc_resize 2-3 3585 _001275_hash NULL
85215 +_001277_hash vhci_write 3 2224 _001277_hash NULL
85216 +_001278_hash __vhost_add_used_n 3 26554 _001278_hash NULL
85217 +_001279_hash virtqueue_add_buf 3-4 59470 _001279_hash NULL
85218 +_001281_hash vmalloc 1 15464 _001281_hash NULL
85219 +_001282_hash vol_cdev_write 3 40915 _001282_hash NULL
85220 +_001283_hash vxge_device_register 4 7752 _001283_hash NULL
85221 +_001284_hash __vxge_hw_blockpool_malloc 2 5786 _001284_hash NULL
85222 +_001285_hash __vxge_hw_channel_allocate 3 55462 _001285_hash NULL
85223 +_001286_hash vzalloc 1 47421 _001286_hash NULL
85224 +_001287_hash vzalloc_node 1 23424 _001287_hash NULL
85225 +_001288_hash wa_nep_queue 2 8858 _001288_hash NULL
85226 +_001289_hash __wa_xfer_setup_segs 2 56725 _001289_hash NULL
85227 +_001290_hash wiphy_new 2 2482 _001290_hash NULL
85228 +_001291_hash wm8350_block_write 3 19727 _001291_hash NULL
85229 +_001292_hash wpan_phy_alloc 1 48056 _001292_hash NULL
85230 +_001293_hash write_flush_pipefs 3 2021 _001293_hash NULL
85231 +_001294_hash write_flush_procfs 3 44011 _001294_hash NULL
85232 +_001295_hash wusb_ccm_mac 7 32199 _001295_hash NULL
85233 +_001296_hash x25_sendmsg 4 12487 _001296_hash NULL
85234 +_001297_hash xfrm_hash_alloc 1 10997 _001297_hash NULL
85235 +_001298_hash _xfs_buf_get_pages 2 46811 _001298_hash NULL
85236 +_001299_hash xfs_da_grow_inode_int 3 21785 _001299_hash NULL
85237 +_001300_hash xfs_dir_cilookup_result 3 64288 _003160_hash NULL nohasharray
85238 +_001301_hash xfs_idata_realloc 2 26199 _001301_hash NULL
85239 +_001302_hash xfs_iext_add_indirect_multi 3 32400 _001302_hash NULL
85240 +_001303_hash xfs_iext_inline_to_direct 2 12384 _001303_hash NULL
85241 +_001304_hash xfs_iformat_local 4 49472 _001304_hash NULL
85242 +_001305_hash xfs_iroot_realloc 2 46826 _001305_hash NULL
85243 +_001306_hash xhci_alloc_stream_info 3 63902 _001306_hash NULL
85244 +_001307_hash xlog_recover_add_to_trans 4 62839 _001307_hash NULL
85245 +_001308_hash xprt_alloc 2 1475 _001308_hash NULL
85246 +_001309_hash xt_alloc_table_info 1 57903 _001309_hash NULL
85247 +_001310_hash _zd_iowrite32v_async_locked 3 39034 _001310_hash NULL
85248 +_001311_hash zd_usb_iowrite16v 3 49744 _001311_hash NULL
85249 +_001312_hash a2mp_send 4 41615 _001312_hash NULL
85250 +_001313_hash acpi_ds_build_internal_package_obj 3 58271 _001313_hash NULL
85251 +_001314_hash acpi_system_read_event 3 55362 _001314_hash NULL
85252 +_001315_hash acpi_ut_create_buffer_object 1 42030 _001315_hash NULL
85253 +_001316_hash acpi_ut_create_package_object 1 17594 _001316_hash NULL
85254 +_001317_hash acpi_ut_create_string_object 1 15360 _001317_hash NULL
85255 +_001318_hash ad7879_spi_multi_read 3 8218 _001318_hash NULL
85256 +_001319_hash add_child 4 45201 _001319_hash NULL
85257 +_001320_hash add_port 2 54941 _001320_hash NULL
85258 +_001321_hash adu_read 3 24177 _001321_hash NULL
85259 +_001322_hash afs_cell_create 2 27346 _001322_hash NULL
85260 +_001323_hash agp_allocate_memory 2 58761 _001323_hash NULL
85261 +_001324_hash agp_generic_alloc_user 1 9470 _001324_hash NULL
85262 +_001325_hash alc_auto_create_extra_outs 2 18975 _001325_hash NULL
85263 +_001326_hash alloc_agpphysmem_i8xx 1 39427 _001326_hash NULL
85264 +_001327_hash allocate_cnodes 1 5329 _001327_hash NULL
85265 +_001328_hash ___alloc_bootmem 1 11410 _001328_hash NULL
85266 +_001329_hash __alloc_bootmem_low_node 2 25726 _001662_hash NULL nohasharray
85267 +_001330_hash __alloc_bootmem_node 2 1992 _001330_hash NULL
85268 +_001331_hash __alloc_bootmem_node_nopanic 2 6432 _001331_hash NULL
85269 +_001332_hash __alloc_bootmem_nopanic 1 65397 _001332_hash NULL
85270 +_001333_hash alloc_candev 1-2 7776 _001333_hash NULL
85271 +_001335_hash _alloc_cdb_cont 2 23609 _001335_hash NULL
85272 +_001336_hash alloc_dummy_extent_buffer 2 56374 _001336_hash NULL
85273 +_001337_hash ____alloc_ei_netdev 1 51475 _001337_hash NULL
85274 +_001338_hash alloc_etherdev_mqs 1 36450 _001338_hash NULL
85275 +_001339_hash alloc_extent_buffer 3 52824 _001339_hash NULL
85276 +_001340_hash alloc_fcdev 1 18780 _001340_hash NULL
85277 +_001341_hash alloc_fddidev 1 15382 _001341_hash NULL
85278 +_001342_hash _alloc_get_attr_desc 2 470 _001342_hash NULL
85279 +_001343_hash alloc_hippi_dev 1 51320 _001343_hash NULL
85280 +_001344_hash alloc_irdadev 1 19140 _001344_hash NULL
85281 +_001345_hash alloc_ldt 2 21972 _001345_hash NULL
85282 +_001346_hash alloc_ltalkdev 1 38071 _001346_hash NULL
85283 +_001347_hash alloc_one_pg_vec_page 1 10747 _001347_hash NULL
85284 +_001348_hash alloc_orinocodev 1 21371 _001348_hash NULL
85285 +_001349_hash alloc_ring 2-4 18278 _001349_hash NULL
85286 +_001351_hash _alloc_set_attr_list 4 48991 _001351_hash NULL
85287 +_001353_hash alloc_tx 2 32143 _001353_hash NULL
85288 +_001354_hash alloc_wr 1-2 24635 _001354_hash NULL
85289 +_001356_hash async_setkey 3 35521 _001356_hash NULL
85290 +_001357_hash ata_host_alloc_pinfo 3 17325 _001357_hash NULL
85291 +_001360_hash ath6kl_connect_event 7-9-8 14267 _001360_hash NULL
85292 +_001361_hash ath6kl_fwlog_block_read 3 49836 _001361_hash NULL
85293 +_001362_hash ath6kl_fwlog_read 3 32101 _001362_hash NULL
85294 +_001363_hash ath9k_wmi_cmd 4 327 _001363_hash NULL
85295 +_001364_hash ath_rx_init 2 43564 _001364_hash NULL
85296 +_001365_hash ath_tx_init 2 60515 _001365_hash NULL
85297 +_001366_hash atm_alloc_charge 2 19517 _001914_hash NULL nohasharray
85298 +_001367_hash atm_get_addr 3 31221 _001367_hash NULL
85299 +_001368_hash audit_log_n_hex 3 45617 _001368_hash NULL
85300 +_001369_hash audit_log_n_string 3 31705 _001369_hash NULL
85301 +_001370_hash ax25_output 2 22736 _001370_hash NULL
85302 +_001371_hash bcsp_prepare_pkt 3 12961 _001371_hash NULL
85303 +_001372_hash bdx_rxdb_create 1 46525 _001372_hash NULL
85304 +_001373_hash bdx_tx_db_init 2 41719 _001373_hash NULL
85305 +_001374_hash bio_map_kern 3 64751 _001374_hash NULL
85306 +_001375_hash bits_to_user 2-3 47733 _001375_hash NULL
85307 +_001377_hash __blk_queue_init_tags 2 9778 _001377_hash NULL
85308 +_001378_hash blk_queue_resize_tags 2 28670 _001378_hash NULL
85309 +_001379_hash blk_rq_map_user_iov 5 16772 _001379_hash NULL
85310 +_001380_hash bm_init 2 13529 _001380_hash NULL
85311 +_001381_hash brcmf_alloc_wdev 1 60347 _001381_hash NULL
85312 +_001382_hash __btrfs_buffered_write 3 35311 _002735_hash NULL nohasharray
85313 +_001383_hash btrfs_insert_dir_item 4 59304 _001383_hash NULL
85314 +_001384_hash btrfs_map_block 3 64379 _001384_hash NULL
85315 +_001385_hash bt_skb_alloc 1 6404 _001385_hash NULL
85316 +_001386_hash c4_add_card 3 54968 _001386_hash NULL
85317 +_001387_hash cache_read 3 24790 _001387_hash NULL
85318 +_001388_hash cache_write 3 13589 _001388_hash NULL
85319 +_001389_hash calc_hmac 3 32010 _001389_hash NULL
85320 +_001390_hash capinc_tty_write 3 28539 _001390_hash NULL
85321 +_001391_hash ccid_getsockopt_builtin_ccids 2 53634 _001391_hash NULL
85322 +_001392_hash ceph_copy_page_vector_to_user 3-4 31270 _001392_hash NULL
85323 +_001394_hash ceph_parse_server_name 2 60318 _001394_hash NULL
85324 +_001395_hash ceph_read_dir 3 17005 _001395_hash NULL
85325 +_001396_hash cfg80211_roamed 5-7 32632 _001396_hash NULL
85326 +_001398_hash cfpkt_add_body 3 44630 _001398_hash NULL
85327 +_001399_hash cfpkt_create_pfx 1-2 23594 _001399_hash NULL
85328 +_001401_hash cmd_complete 6 51629 _001401_hash NULL
85329 +_001402_hash cmtp_add_msgpart 4 9252 _001402_hash NULL
85330 +_001403_hash cmtp_send_interopmsg 7 376 _001403_hash NULL
85331 +_001404_hash coda_psdev_read 3 35029 _001404_hash NULL
85332 +_001405_hash construct_key_and_link 4 8321 _001405_hash NULL
85333 +_001406_hash copy_counters_to_user 5 17027 _001406_hash NULL
85334 +_001407_hash copy_entries_to_user 1 52367 _001407_hash NULL
85335 +_001408_hash copy_from_buf 2-4 27308 _001408_hash NULL
85336 +_001410_hash copy_oldmem_page 3-1 26164 _001410_hash NULL
85337 +_001411_hash copy_to_user_fromio 3 57432 _001411_hash NULL
85338 +_001412_hash cryptd_hash_setkey 3 42781 _001412_hash NULL
85339 +_001413_hash crypto_authenc_esn_setkey 3 6985 _001413_hash NULL
85340 +_001414_hash crypto_authenc_setkey 3 80 _001414_hash NULL
85341 +_001415_hash cxgb3_get_cpl_reply_skb 2 10620 _001415_hash NULL
85342 +_001416_hash cxgbi_ddp_reserve 4 30091 _001416_hash NULL
85343 +_001417_hash cxio_init_resource_fifo 3 28764 _001417_hash NULL
85344 +_001418_hash cxio_init_resource_fifo_random 3 47151 _001418_hash NULL
85345 +_001419_hash datablob_hmac_append 3 40038 _001419_hash NULL
85346 +_001420_hash datablob_hmac_verify 4 24786 _001420_hash NULL
85347 +_001421_hash dataflash_read_fact_otp 3-2 33204 _001421_hash NULL
85348 +_001422_hash dataflash_read_user_otp 3-2 14536 _001422_hash &_000207_hash
85349 +_001423_hash dccp_feat_register_sp 5 17914 _001423_hash NULL
85350 +_001424_hash dccp_setsockopt 5 60367 _001424_hash NULL
85351 +_001425_hash __dev_alloc_skb 1 28681 _001425_hash NULL
85352 +_001426_hash disk_expand_part_tbl 2 30561 _001426_hash NULL
85353 +_001427_hash diva_os_alloc_message_buffer 1 64568 _001427_hash NULL
85354 +_001428_hash diva_os_copy_to_user 4 48508 _001428_hash NULL
85355 +_001429_hash diva_os_malloc 2 16406 _001429_hash NULL
85356 +_001430_hash dmam_declare_coherent_memory 4-2 43679 _001430_hash NULL
85357 +_001431_hash dm_vcalloc 1-2 16814 _001431_hash NULL
85358 +_001433_hash dn_alloc_skb 2 6631 _001433_hash NULL
85359 +_001434_hash do_proc_readlink 3 14096 _001434_hash NULL
85360 +_001435_hash do_readlink 2 43518 _001435_hash NULL
85361 +_001436_hash __do_replace 5 37227 _001436_hash NULL
85362 +_001437_hash do_sigpending 2 9766 _001437_hash NULL
85363 +_001438_hash drbd_bm_resize 2 20522 _001438_hash NULL
85364 +_001439_hash drbd_setsockopt 5 16280 _001439_hash &_000383_hash
85365 +_001440_hash dump_midi 3 51040 _001440_hash NULL
85366 +_001441_hash ecryptfs_filldir 3 6622 _001441_hash NULL
85367 +_001442_hash ecryptfs_send_message 2 18322 _001442_hash NULL
85368 +_001443_hash ep0_read 3 38095 _001443_hash NULL
85369 +_001444_hash evdev_ioctl 2 22371 _001444_hash NULL
85370 +_001445_hash ext4_add_new_descs 3 19509 _001445_hash NULL
85371 +_001446_hash fat_ioctl_filldir 3 36621 _001446_hash NULL
85372 +_001447_hash _fc_frame_alloc 1 43568 _001447_hash NULL
85373 +_001448_hash fc_host_post_vendor_event 3 30903 _001448_hash NULL
85374 +_001449_hash fd_copyout 3 59323 _001449_hash NULL
85375 +_001450_hash f_hidg_read 3 6238 _001450_hash NULL
85376 +_001451_hash filldir 3 55137 _001451_hash NULL
85377 +_001452_hash filldir64 3 46469 _001452_hash NULL
85378 +_001453_hash find_skb 2 20431 _001453_hash NULL
85379 +_001454_hash from_buffer 3 18625 _001454_hash NULL
85380 +_001455_hash fsm_init 2 16134 _001455_hash NULL
85381 +_001456_hash fs_path_add 3 15648 _001456_hash NULL
85382 +_001457_hash fs_path_add_from_extent_buffer 4 27702 _001457_hash NULL
85383 +_001458_hash fuse_perform_write 4 18457 _001458_hash NULL
85384 +_001459_hash gem_alloc_skb 2 51715 _001459_hash NULL
85385 +_001460_hash generic_file_buffered_write 4 25464 _001460_hash NULL
85386 +_001461_hash gen_pool_add 3 21776 _001461_hash NULL
85387 +_001462_hash get_packet 3 41914 _001462_hash NULL
85388 +_001463_hash get_packet 3 5747 _001463_hash NULL
85389 +_001464_hash get_packet_pg 4 28023 _001464_hash NULL
85390 +_001465_hash get_skb 2 63008 _001465_hash NULL
85391 +_001466_hash get_subdir 3 62581 _001466_hash NULL
85392 +_001467_hash gsm_control_message 4 18209 _001467_hash NULL
85393 +_001468_hash gsm_control_modem 3 55303 _001468_hash NULL
85394 +_001469_hash gsm_control_rls 3 3353 _001469_hash NULL
85395 +_001470_hash handle_received_packet 3 22457 _001470_hash NULL
85396 +_001471_hash hash_setkey 3 48310 _001471_hash NULL
85397 +_001472_hash hdlcdrv_register 2 6792 _001472_hash NULL
85398 +_001473_hash hiddev_ioctl 2 36816 _001473_hash NULL
85399 +_001474_hash hid_input_report 4 32458 _001474_hash NULL
85400 +_001475_hash hidp_queue_report 3 1881 _001475_hash NULL
85401 +_001476_hash __hidp_send_ctrl_message 4 28303 _001476_hash NULL
85402 +_001477_hash hidraw_read 3 59650 _001477_hash &_001265_hash
85403 +_001478_hash HiSax_readstatus 2 15752 _001478_hash NULL
85404 +_001480_hash __hwahc_op_set_gtk 4 42038 _001480_hash NULL
85405 +_001481_hash __hwahc_op_set_ptk 5 36510 _001481_hash NULL
85406 +_001482_hash hycapi_rx_capipkt 3 11602 _001482_hash NULL
85407 +_001483_hash i2400m_net_rx 5 27170 _001483_hash NULL
85408 +_001484_hash ib_copy_to_udata 3 27525 _001484_hash NULL
85409 +_001485_hash idetape_chrdev_read 3 2097 _001485_hash NULL
85410 +_001486_hash ieee80211_alloc_hw 1 43829 _001486_hash NULL
85411 +_001487_hash ieee80211_bss_info_update 4 13991 _001487_hash NULL
85412 +_001488_hash igmpv3_newpack 2 35912 _001488_hash NULL
85413 +_001489_hash ilo_read 3 32531 _001489_hash NULL
85414 +_001490_hash init_map_ipmac 3-4 63896 _001490_hash NULL
85415 +_001492_hash init_tid_tabs 2-4-3 13252 _001492_hash NULL
85416 +_001495_hash iowarrior_read 3 53483 _001495_hash NULL
85417 +_001496_hash ip_options_get 4 56538 _001496_hash NULL
85418 +_001497_hash ipv6_getsockopt_sticky 5 56711 _001497_hash NULL
85419 +_001498_hash ipwireless_send_packet 4 8328 _001498_hash NULL
85420 +_001499_hash ipx_sendmsg 4 1362 _001499_hash NULL
85421 +_001500_hash irq_domain_add_linear 2 29236 _001500_hash NULL
85422 +_001501_hash iscsi_conn_setup 2 35159 _001501_hash NULL
85423 +_001502_hash iscsi_create_session 3 51647 _001502_hash NULL
85424 +_001503_hash iscsi_host_alloc 2 36671 _001503_hash NULL
85425 +_001504_hash iscsi_if_send_reply 7 52219 _001504_hash NULL
85426 +_001505_hash iscsi_offload_mesg 5 58425 _001505_hash NULL
85427 +_001506_hash iscsi_ping_comp_event 5 38263 _001506_hash NULL
85428 +_001507_hash iscsi_post_host_event 4 13473 _001507_hash NULL
85429 +_001508_hash iscsi_recv_pdu 4 16755 _001508_hash NULL
85430 +_001509_hash iscsi_session_setup 4-5 196 _001509_hash NULL
85431 +_001511_hash iscsit_find_cmd_from_itt_or_dump 3 17194 _003122_hash NULL nohasharray
85432 +_001512_hash isdn_net_ciscohdlck_alloc_skb 2 55209 _001951_hash NULL nohasharray
85433 +_001513_hash isdn_ppp_ccp_xmit_reset 6 63297 _001513_hash NULL
85434 +_001514_hash isdn_ppp_read 4 50356 _001514_hash NULL
85435 +_001515_hash isdn_ppp_skb_push 2 5236 _001515_hash NULL
85436 +_001516_hash isku_sysfs_read 6 58806 _001516_hash NULL
85437 +_001517_hash isku_sysfs_write 6 49767 _001517_hash NULL
85438 +_001520_hash jbd2_alloc 1 41359 _001520_hash NULL
85439 +_001521_hash jffs2_do_link 6 42048 _001521_hash NULL
85440 +_001522_hash jffs2_do_unlink 4 62020 _001522_hash NULL
85441 +_001523_hash jffs2_security_setxattr 4 62107 _001523_hash NULL
85442 +_001524_hash jffs2_trusted_setxattr 4 17048 _001524_hash NULL
85443 +_001525_hash jffs2_user_setxattr 4 10182 _001525_hash NULL
85444 +_001526_hash joydev_ioctl_common 2 49359 _001526_hash NULL
85445 +_001527_hash kernel_setsockopt 5 35913 _001527_hash NULL
85446 +_001528_hash keyctl_describe_key 3 36853 _001528_hash NULL
85447 +_001529_hash keyctl_get_security 3 64418 _001529_hash &_001192_hash
85448 +_001530_hash keyring_read 3 13438 _001530_hash NULL
85449 +_001531_hash kfifo_copy_to_user 3 20646 _001531_hash NULL
85450 +_001532_hash kmem_zalloc_large 1 56128 _001532_hash NULL
85451 +_001533_hash kmp_init 2 41373 _001533_hash NULL
85452 +_001534_hash koneplus_sysfs_write 6 35993 _001534_hash NULL
85453 +_001535_hash kvm_clear_guest_page 4 2308 _001535_hash NULL
85454 +_001536_hash kvm_read_nested_guest_page 5 13337 _001536_hash NULL
85455 +_001537_hash _l2_alloc_skb 1 11883 _001537_hash NULL
85456 +_001538_hash l2cap_create_basic_pdu 3 24869 _001538_hash &_001074_hash
85457 +_001539_hash l2cap_create_connless_pdu 3 37327 _001539_hash NULL
85458 +_001540_hash l2cap_create_iframe_pdu 3 40055 _001540_hash NULL
85459 +_001541_hash l3_alloc_skb 1 32289 _001541_hash NULL
85460 +_001542_hash __lgwrite 4 57669 _001542_hash NULL
85461 +_001543_hash libfc_host_alloc 2 7917 _001543_hash NULL
85462 +_001544_hash llc_alloc_frame 4 64366 _001544_hash NULL
85463 +_001545_hash llcp_sock_sendmsg 4 1092 _001545_hash NULL
85464 +_001546_hash mac_drv_rx_init 2 48898 _001546_hash NULL
85465 +_001547_hash macvtap_get_user 4 28185 _001547_hash NULL
85466 +_001548_hash mdc800_device_read 3 22896 _001548_hash NULL
85467 +_001549_hash memcpy_toiovec 3 54166 _001549_hash &_000892_hash
85468 +_001550_hash memcpy_toiovecend 3-4 19736 _001550_hash NULL
85469 +_001552_hash mempool_create 1 29437 _001552_hash NULL
85470 +_001553_hash mgmt_event 4 12810 _001553_hash NULL
85471 +_001554_hash mgt_set_varlen 4 60916 _001554_hash NULL
85472 +_001555_hash mI_alloc_skb 1 24770 _001555_hash NULL
85473 +_001556_hash mlx4_en_create_rx_ring 3 62498 _001556_hash NULL
85474 +_001557_hash mlx4_en_create_tx_ring 4 48501 _001557_hash NULL
85475 +_001558_hash mlx4_init_cmpt_table 3 11569 _001558_hash NULL
85476 +_001559_hash mon_bin_get_event 4 52863 _001559_hash NULL
85477 +_001560_hash mousedev_read 3 47123 _001560_hash NULL
85478 +_001561_hash move_addr_to_user 2 2868 _001561_hash NULL
85479 +_001562_hash mpihelp_mul 5-3 27805 _001562_hash NULL
85480 +_001564_hash mpi_set_buffer 3 65294 _001564_hash NULL
85481 +_001565_hash mptctl_ioctl 2 12355 _001565_hash NULL
85482 +_001566_hash msnd_fifo_alloc 2 23179 _001566_hash NULL
85483 +_001567_hash mtdswap_init 2 55719 _001567_hash NULL
85484 +_001568_hash mthca_alloc_resize_buf 3 60394 _001568_hash NULL
85485 +_001569_hash mthca_init_cq 2 60011 _001569_hash NULL
85486 +_001570_hash nci_skb_alloc 2 49757 _001570_hash NULL
85487 +_001571_hash neigh_hash_grow 2 17283 _001571_hash NULL
85488 +_001572_hash netdev_alloc_skb 2 62437 _001572_hash NULL
85489 +_001573_hash __netdev_alloc_skb_ip_align 2 55067 _001573_hash NULL
85490 +_001574_hash netlink_change_ngroups 2 16457 _001574_hash NULL
85491 +_001575_hash new_skb 1 21148 _001575_hash NULL
85492 +_001576_hash nfc_alloc_recv_skb 1 10244 _001576_hash NULL
85493 +_001577_hash nfcwilink_skb_alloc 1 16167 _001577_hash NULL
85494 +_001578_hash __nf_nat_mangle_tcp_packet 5-7 8190 _001578_hash NULL
85495 +_001580_hash nf_nat_mangle_udp_packet 5-7 13321 _001580_hash NULL
85496 +_001582_hash nfqnl_mangle 4-2 36226 _001582_hash NULL
85497 +_001583_hash nfs4_realloc_slot_table 2 22859 _001583_hash NULL
85498 +_001584_hash nfs_idmap_get_key 2 39616 _001584_hash NULL
85499 +_001585_hash nfs_readdata_alloc 2 65015 _001585_hash NULL
85500 +_001586_hash nfs_writedata_alloc 2 12133 _001586_hash NULL
85501 +_001587_hash nfulnl_alloc_skb 2 65207 _001587_hash NULL
85502 +_001588_hash ni65_alloc_mem 3 10664 _001588_hash NULL
85503 +_001589_hash nsm_get_handle 4 52089 _001589_hash NULL
85504 +_001590_hash ntfs_malloc_nofs 1 49572 _001590_hash NULL
85505 +_001591_hash ntfs_malloc_nofs_nofail 1 63631 _001591_hash NULL
85506 +_001592_hash nvme_create_queue 3 170 _001592_hash NULL
85507 +_001593_hash ocfs2_control_write 3 54737 _001593_hash NULL
85508 +_001595_hash orinoco_add_extscan_result 3 18207 _001595_hash NULL
85509 +_001596_hash osd_req_read_sg_kern 5 6378 _001596_hash NULL
85510 +_001597_hash osd_req_write_sg_kern 5 10514 _001597_hash NULL
85511 +_001599_hash override_release 2 52032 _001599_hash NULL
85512 +_001600_hash p9_client_read 5 19750 _001600_hash NULL
85513 +_001601_hash packet_snd 3 13634 _001601_hash NULL
85514 +_001602_hash pcbit_stat 2 27364 _001602_hash NULL
85515 +_001603_hash pcpu_extend_area_map 2 12589 _001603_hash NULL
85516 +_001604_hash pep_alloc_skb 3 46303 _001604_hash NULL
85517 +_001605_hash pg_read 3 17276 _001605_hash NULL
85518 +_001606_hash picolcd_debug_eeprom_read 3 14549 _001606_hash NULL
85519 +_001607_hash pkt_alloc_packet_data 1 37928 _001607_hash NULL
85520 +_001608_hash pmcraid_build_passthrough_ioadls 2 62034 _001608_hash NULL
85521 +_001609_hash pn_raw_send 2 54330 _001609_hash NULL
85522 +_001610_hash posix_clock_register 2 5662 _001610_hash NULL
85523 +_001611_hash printer_read 3 54851 _001611_hash NULL
85524 +_001612_hash __proc_file_read 3 54978 _001612_hash NULL
85525 +_001613_hash pskb_may_pull 2 22546 _001613_hash NULL
85526 +_001614_hash __pskb_pull 2 42602 _001614_hash NULL
85527 +_001615_hash ptp_read 4 63251 _001615_hash NULL
85528 +_001616_hash pt_read 3 49136 _001616_hash NULL
85529 +_001617_hash put_cmsg 4 36589 _001617_hash NULL
85530 +_001618_hash px_raw_event 4 49371 _001618_hash NULL
85531 +_001619_hash qla4xxx_post_aen_work 3 46953 _001619_hash NULL
85532 +_001620_hash qla4xxx_post_ping_evt_work 4 8074 _001819_hash NULL nohasharray
85533 +_001621_hash raid5_resize 2 63306 _001621_hash NULL
85534 +_001622_hash rawv6_sendmsg 4 20080 _001622_hash NULL
85535 +_001623_hash rds_message_map_pages 2 31487 _001623_hash NULL
85536 +_001624_hash rds_sendmsg 4 40976 _001624_hash NULL
85537 +_001625_hash read_flush 3 43851 _001625_hash NULL
85538 +_001626_hash read_profile 3 27859 _001626_hash NULL
85539 +_001627_hash read_vmcore 3 26501 _001627_hash NULL
85540 +_001628_hash redirected_tty_write 3 65297 _001628_hash NULL
85541 +_001629_hash refill_pool 2 19477 _001629_hash NULL
85542 +_001630_hash __register_chrdev 2-3 54223 _001630_hash NULL
85543 +_001632_hash regmap_raw_write 4 53803 _001632_hash NULL
85544 +_001633_hash reiserfs_allocate_list_bitmaps 3 21732 _001633_hash NULL
85545 +_001634_hash reiserfs_resize 2 34377 _001634_hash NULL
85546 +_001635_hash request_key_auth_read 3 24109 _001635_hash NULL
85547 +_001636_hash rfcomm_wmalloc 2 58090 _001636_hash NULL
85548 +_001637_hash rfkill_fop_read 3 54711 _001637_hash NULL
85549 +_001638_hash rng_dev_read 3 41581 _001638_hash NULL
85550 +_001639_hash roccat_read 3 41093 _001639_hash &_001034_hash
85551 +_001640_hash rx 4 57944 _001640_hash NULL
85552 +_001641_hash rxrpc_client_sendmsg 5 23236 _001641_hash NULL
85553 +_001642_hash rxrpc_kernel_send_data 3 60083 _001642_hash NULL
85554 +_001643_hash rxrpc_server_sendmsg 4 37331 _001643_hash NULL
85555 +_001644_hash savu_sysfs_write 6 42273 _001644_hash NULL
85556 +_001645_hash sco_sock_sendmsg 4 62542 _001645_hash NULL
85557 +_001646_hash scsi_nl_send_vendor_msg 5 16394 _001646_hash NULL
85558 +_001647_hash scsi_register 2 49094 _001647_hash NULL
85559 +_001648_hash sctp_datamsg_from_user 4 55342 _001648_hash NULL
85560 +_001649_hash sctp_getsockopt_events 2 3607 _001649_hash NULL
85561 +_001650_hash sctp_getsockopt_maxburst 2 42941 _001650_hash NULL
85562 +_001651_hash sctp_getsockopt_maxseg 2 10737 _001651_hash NULL
85563 +_001652_hash sctp_make_chunk 4 12986 _001652_hash NULL
85564 +_001653_hash sctpprobe_read 3 17741 _001653_hash NULL
85565 +_001654_hash sctp_tsnmap_mark 2 35929 _001654_hash NULL
85566 +_001655_hash sctp_ulpevent_new 1 33377 _001655_hash NULL
85567 +_001656_hash sdhci_alloc_host 2 7509 _001656_hash NULL
85568 +_001657_hash selinux_inode_post_setxattr 4 26037 _001657_hash NULL
85569 +_001658_hash selinux_inode_setsecurity 4 18148 _001658_hash NULL
85570 +_001659_hash selinux_inode_setxattr 4 10708 _001659_hash NULL
85571 +_001660_hash selinux_secctx_to_secid 2 63744 _001660_hash NULL
85572 +_001661_hash selinux_setprocattr 4 55611 _001661_hash NULL
85573 +_001662_hash sel_write_context 3 25726 _001662_hash &_001329_hash
85574 +_001663_hash send_command 4 10832 _001663_hash NULL
85575 +_001664_hash seq_copy_in_user 3 18543 _001664_hash NULL
85576 +_001665_hash seq_open_net 4 8968 _001779_hash NULL nohasharray
85577 +_001666_hash seq_open_private 3 61589 _001666_hash NULL
85578 +_001667_hash set_arg 3 42824 _001667_hash NULL
85579 +_001668_hash sg_read 3 25799 _001668_hash NULL
85580 +_001669_hash shash_async_setkey 3 10720 _003506_hash NULL nohasharray
85581 +_001670_hash shash_compat_setkey 3 12267 _001670_hash NULL
85582 +_001671_hash shmem_setxattr 4 55867 _001671_hash NULL
85583 +_001672_hash simple_read_from_buffer 2-5 55957 _001672_hash NULL
85584 +_001674_hash sisusb_clear_vram 2-3 57466 _001674_hash NULL
85585 +_001676_hash sisusbcon_do_font_op 9 52271 _001676_hash NULL
85586 +_001677_hash sisusb_copy_memory 4 35016 _001677_hash NULL
85587 +_001678_hash sisusb_write 3 44834 _001678_hash NULL
85588 +_001680_hash skb_cow 2 26138 _001680_hash NULL
85589 +_001681_hash skb_cow_head 2 52495 _001681_hash NULL
85590 +_001682_hash skb_make_writable 2 24783 _001682_hash NULL
85591 +_001683_hash skb_padto 2 50759 _001683_hash NULL
85592 +_001684_hash sk_stream_alloc_skb 2 57622 _001684_hash NULL
85593 +_001685_hash smk_write_access2 3 19170 _001685_hash NULL
85594 +_001686_hash smk_write_access 3 49561 _001686_hash NULL
85595 +_001687_hash snd_es1938_capture_copy 5 25930 _001687_hash NULL
85596 +_001688_hash snd_gus_dram_peek 4 9062 _001688_hash NULL
85597 +_001689_hash snd_hdsp_capture_copy 5 4011 _001689_hash NULL
85598 +_001690_hash snd_korg1212_copy_to 6 92 _001690_hash NULL
85599 +_001691_hash snd_opl4_mem_proc_read 5 63774 _001691_hash NULL
85600 +_001692_hash snd_pcm_oss_read1 3 63771 _001692_hash NULL
85601 +_001693_hash snd_pcm_plugin_alloc 2 12580 _001693_hash NULL
85602 +_001694_hash snd_rawmidi_kernel_read1 4 36740 _001694_hash NULL
85603 +_001695_hash snd_rme9652_capture_copy 5 10287 _001695_hash NULL
85604 +_001696_hash sock_alloc_send_pskb 2 21246 _001696_hash NULL
85605 +_001697_hash sock_rmalloc 2 59740 _002491_hash NULL nohasharray
85606 +_001698_hash sock_wmalloc 2 16472 _001698_hash NULL
85607 +_001699_hash solos_param_store 4 34755 _001699_hash NULL
85608 +_001702_hash srp_target_alloc 3 37288 _001702_hash NULL
85609 +_001703_hash store_ifalias 4 35088 _001703_hash NULL
85610 +_001704_hash store_msg 3 56417 _001704_hash NULL
85611 +_001705_hash str_to_user 2 11411 _001705_hash NULL
85612 +_001706_hash subbuf_read_actor 3 2071 _001706_hash NULL
85613 +_001707_hash sys_fgetxattr 4 25166 _001707_hash NULL
85614 +_001708_hash sys_gethostname 2 49698 _001708_hash NULL
85615 +_001709_hash sys_getxattr 4 37418 _001709_hash NULL
85616 +_001710_hash sys_init_module 2 36047 _001710_hash NULL
85617 +_001711_hash sys_kexec_load 2 14222 _001711_hash NULL
85618 +_001712_hash sys_lgetxattr 4 45531 _001712_hash NULL
85619 +_001713_hash syslog_print 2 307 _001713_hash NULL
85620 +_001714_hash sys_msgsnd 3 44537 _001714_hash &_000139_hash
85621 +_001715_hash sys_process_vm_readv 3-5 19090 _003104_hash NULL nohasharray
85622 +_001717_hash sys_process_vm_writev 3-5 4928 _001717_hash NULL
85623 +_001719_hash sys_pselect6 1 57449 _001719_hash NULL
85624 +_001720_hash sys_sched_getaffinity 2 60033 _001720_hash NULL
85625 +_001721_hash sys_setsockopt 5 35320 _001721_hash NULL
85626 +_001722_hash t3_init_l2t 1 8261 _001722_hash NULL
85627 +_001723_hash t4vf_pktgl_to_skb 2 39005 _001723_hash NULL
85628 +_001724_hash tcp_collapse 5-6 63294 _001724_hash NULL
85629 +_001726_hash tcp_sendmsg 4 30296 _001726_hash NULL
85630 +_001727_hash team_options_register 3 20091 _001727_hash NULL
85631 +_001728_hash tipc_buf_acquire 1 60437 _001728_hash NULL
85632 +_001729_hash tipc_cfg_reply_alloc 1 27606 _001729_hash NULL
85633 +_001730_hash tipc_send2name 6 16809 _001730_hash NULL
85634 +_001731_hash tipc_send2port 5 63935 _001731_hash NULL
85635 +_001732_hash tipc_send 4 51238 _001732_hash NULL
85636 +_001733_hash tnode_new 3 44757 _002769_hash NULL nohasharray
85637 +_001734_hash tomoyo_read_self 3 33539 _001734_hash NULL
85638 +_001735_hash tomoyo_update_domain 2 5498 _001735_hash NULL
85639 +_001736_hash tomoyo_update_policy 2 40458 _001736_hash NULL
85640 +_001737_hash tpm_read 3 50344 _001737_hash NULL
85641 +_001738_hash TSS_rawhmac 3 17486 _001738_hash NULL
85642 +_001739_hash __tty_buffer_request_room 2 27700 _001739_hash NULL
85643 +_001740_hash tun_get_user 4 39099 _001740_hash NULL
85644 +_001741_hash ubi_dump_flash 4 46381 _001741_hash NULL
85645 +_001742_hash ubi_io_write 4-5 15870 _003453_hash NULL nohasharray
85646 +_001744_hash udp_setsockopt 5 25985 _001744_hash NULL
85647 +_001745_hash udpv6_setsockopt 5 18487 _001745_hash NULL
85648 +_001746_hash uio_read 3 49300 _001746_hash NULL
85649 +_001747_hash ulog_alloc_skb 1 23427 _001747_hash NULL
85650 +_001748_hash unix_dgram_sendmsg 4 45699 _001748_hash NULL
85651 +_001749_hash unlink1 3 63059 _001749_hash NULL
85652 +_001751_hash usbdev_read 3 45114 _001751_hash NULL
85653 +_001752_hash usblp_ioctl 2 30203 _001752_hash NULL
85654 +_001753_hash usblp_read 3 57342 _003832_hash NULL nohasharray
85655 +_001754_hash usbtmc_read 3 32377 _001754_hash NULL
85656 +_001755_hash _usb_writeN_sync 4 31682 _001755_hash NULL
85657 +_001756_hash user_read 3 51881 _001756_hash NULL
85658 +_001757_hash vcs_read 3 8017 _001757_hash NULL
85659 +_001758_hash vdma_mem_alloc 1 6171 _001758_hash NULL
85660 +_001759_hash venus_create 4 20555 _001759_hash NULL
85661 +_001760_hash venus_link 5 32165 _001760_hash NULL
85662 +_001761_hash venus_lookup 4 8121 _001761_hash NULL
85663 +_001762_hash venus_mkdir 4 8967 _001762_hash NULL
85664 +_001763_hash venus_remove 4 59781 _001763_hash NULL
85665 +_001764_hash venus_rename 4-5 17707 _003784_hash NULL nohasharray
85666 +_001766_hash venus_rmdir 4 45564 _001766_hash NULL
85667 +_001767_hash venus_symlink 4-6 23570 _001767_hash NULL
85668 +_001769_hash vfs_readlink 3 54368 _001769_hash NULL
85669 +_001770_hash vfs_readv 3 38011 _001770_hash NULL
85670 +_001771_hash vfs_writev 3 25278 _001771_hash NULL
85671 +_001772_hash vga_arb_read 3 4886 _001772_hash NULL
85672 +_001773_hash vgacon_adjust_height 2 28124 _001773_hash NULL
85673 +_001774_hash vhci_put_user 4 12604 _001774_hash NULL
85674 +_001775_hash vhost_add_used_n 3 10760 _001775_hash NULL
85675 +_001776_hash virtnet_send_command 5-6 61993 _001776_hash NULL
85676 +_001778_hash vmbus_establish_gpadl 3 4495 _001778_hash NULL
85677 +_001779_hash vol_cdev_read 3 8968 _001779_hash &_001665_hash
85678 +_001780_hash wdm_read 3 6549 _001780_hash NULL
85679 +_001781_hash write_adapter_mem 3 3234 _001781_hash NULL
85680 +_001782_hash wusb_prf 7 54261 _001782_hash &_000065_hash
85681 +_001783_hash xdi_copy_to_user 4 48900 _001783_hash NULL
85682 +_001784_hash xfs_buf_associate_memory 3 17915 _001784_hash NULL
85683 +_001785_hash xfs_buf_get_maps 2 4581 _001785_hash NULL
85684 +_001786_hash xfs_buf_get_uncached 2 51477 _001786_hash NULL
85685 +_001787_hash xfs_buf_item_get_format 2 189 _001787_hash NULL
85686 +_001788_hash xfs_buf_map_from_irec 5 2368 _002641_hash NULL nohasharray
85687 +_001789_hash xfs_dir2_block_to_sf 3 37868 _001789_hash NULL
85688 +_001790_hash xfs_dir2_leaf_getdents 3 23841 _001790_hash NULL
85689 +_001791_hash xfs_dir2_sf_addname_hard 3 54254 _001791_hash NULL
85690 +_001792_hash xfs_efd_init 3 5463 _001792_hash NULL
85691 +_001793_hash xfs_efi_init 2 5476 _001793_hash NULL
85692 +_001794_hash xfs_iext_realloc_direct 2 20521 _001794_hash NULL
85693 +_001795_hash xfs_iext_realloc_indirect 2 59211 _001795_hash NULL
85694 +_001796_hash xfs_inumbers_fmt 3 12817 _001796_hash NULL
85695 +_001797_hash xhci_alloc_streams 5 37586 _001797_hash NULL
85696 +_001798_hash xlog_recover_add_to_cont_trans 4 44102 _001798_hash NULL
85697 +_001799_hash xz_dec_lzma2_create 2 36353 _002713_hash NULL nohasharray
85698 +_001800_hash _zd_iowrite32v_locked 3 44725 _001800_hash NULL
85699 +_001801_hash a2mp_chan_alloc_skb_cb 2 27159 _001801_hash NULL
85700 +_001802_hash aat2870_reg_read_file 3 12221 _001802_hash NULL
85701 +_001803_hash add_partition 2 55588 _001803_hash NULL
85702 +_001804_hash add_sctp_bind_addr 3 12269 _001804_hash NULL
85703 +_001805_hash _add_sg_continuation_descriptor 3 54721 _001805_hash NULL
85704 +_001806_hash afs_cell_lookup 2 8482 _001806_hash NULL
85705 +_001807_hash afs_send_simple_reply 3 63940 _001807_hash NULL
85706 +_001808_hash agp_allocate_memory_wrap 1 16576 _001808_hash NULL
85707 +_001809_hash __alloc_bootmem 1 31498 _001809_hash NULL
85708 +_001810_hash __alloc_bootmem_low 1 43423 _003425_hash NULL nohasharray
85709 +_001811_hash __alloc_bootmem_node_high 2 65076 _001811_hash NULL
85710 +_001812_hash alloc_cc770dev 1 48186 _001812_hash NULL
85711 +_001813_hash __alloc_ei_netdev 1 29338 _001813_hash NULL
85712 +_001814_hash __alloc_eip_netdev 1 51549 _001814_hash NULL
85713 +_001815_hash alloc_libipw 1 22708 _001815_hash NULL
85714 +_001816_hash _alloc_mISDN_skb 3 52232 _001816_hash NULL
85715 +_001817_hash alloc_pg_vec 2 8533 _001817_hash NULL
85716 +_001818_hash alloc_sja1000dev 1 17868 _001818_hash NULL
85717 +_001819_hash alloc_targets 2 8074 _001819_hash &_001620_hash
85718 +_001822_hash ath6kl_disconnect_timeout_read 3 3650 _001822_hash NULL
85719 +_001823_hash ath6kl_endpoint_stats_read 3 41554 _001823_hash NULL
85720 +_001824_hash ath6kl_fwlog_mask_read 3 2050 _001824_hash NULL
85721 +_001825_hash ath6kl_keepalive_read 3 44303 _001825_hash NULL
85722 +_001826_hash ath6kl_listen_int_read 3 10355 _001826_hash NULL
85723 +_001827_hash ath6kl_lrssi_roam_read 3 61022 _001827_hash NULL
85724 +_001828_hash ath6kl_regdump_read 3 14393 _001828_hash NULL
85725 +_001829_hash ath6kl_regread_read 3 25884 _001829_hash NULL
85726 +_001830_hash ath6kl_regwrite_read 3 48747 _001830_hash NULL
85727 +_001831_hash ath6kl_roam_table_read 3 26166 _001831_hash NULL
85728 +_001832_hash ath9k_debugfs_read_buf 3 25316 _001832_hash NULL
85729 +_001833_hash ath9k_multi_regread 4 65056 _001833_hash NULL
85730 +_001834_hash ath_rxbuf_alloc 2 24745 _001834_hash NULL
85731 +_001835_hash atk_debugfs_ggrp_read 3 29522 _001835_hash NULL
85732 +_001836_hash audit_log_n_untrustedstring 3 9548 _001836_hash NULL
85733 +_001837_hash ax25_send_frame 2 19964 _001837_hash NULL
85734 +_001838_hash b43_debugfs_read 3 24425 _001838_hash NULL
85735 +_001839_hash b43legacy_debugfs_read 3 2473 _001839_hash NULL
85736 +_001840_hash batadv_bla_is_backbone_gw 3 58488 _001840_hash NULL
85737 +_001841_hash batadv_check_management_packet 3 52993 _001841_hash NULL
85738 +_001842_hash batadv_check_unicast_packet 2 10866 _001842_hash NULL
85739 +_001843_hash batadv_interface_rx 4 8568 _001843_hash NULL
85740 +_001844_hash batadv_skb_head_push 2 11360 _001844_hash NULL
85741 +_001845_hash bchannel_get_rxbuf 2 37213 _001845_hash NULL
85742 +_001846_hash bcm_recvmsg 4 43992 _001846_hash NULL
85743 +_001847_hash bfad_debugfs_read 3 13119 _001847_hash NULL
85744 +_001848_hash bfad_debugfs_read_regrd 3 57830 _001848_hash NULL
85745 +_001849_hash blk_init_tags 1 30592 _001849_hash NULL
85746 +_001850_hash blk_queue_init_tags 2 44355 _001850_hash &_001022_hash
85747 +_001851_hash blk_rq_map_kern 4 47004 _001851_hash NULL
85748 +_001852_hash bm_entry_read 3 10976 _001852_hash NULL
85749 +_001853_hash bm_status_read 3 19583 _001853_hash NULL
85750 +_001854_hash bnad_debugfs_read 3 50665 _001854_hash NULL
85751 +_001855_hash bnad_debugfs_read_regrd 3 51308 _001855_hash NULL
85752 +_001856_hash bnx2i_send_nl_mesg 4 53353 _001856_hash NULL
85753 +_001857_hash brcmf_debugfs_sdio_counter_read 3 58369 _001857_hash NULL
85754 +_001858_hash brcmf_sdio_assert_info 4 52653 _001858_hash NULL
85755 +_001859_hash brcmf_sdio_dump_console 4 37455 _001859_hash NULL
85756 +_001860_hash brcmf_sdio_trap_info 4 48510 _001860_hash NULL
85757 +_001861_hash btmrvl_curpsmode_read 3 46939 _001861_hash NULL
85758 +_001862_hash btmrvl_gpiogap_read 3 4718 _001862_hash NULL
85759 +_001863_hash btmrvl_hscfgcmd_read 3 56303 _001863_hash NULL
85760 +_001864_hash btmrvl_hscmd_read 3 1614 _001864_hash NULL
85761 +_001865_hash btmrvl_hsmode_read 3 1647 _001865_hash NULL
85762 +_001866_hash btmrvl_hsstate_read 3 920 _001866_hash NULL
85763 +_001867_hash btmrvl_pscmd_read 3 24308 _001867_hash NULL
85764 +_001868_hash btmrvl_psmode_read 3 22395 _001868_hash NULL
85765 +_001869_hash btmrvl_psstate_read 3 50683 _001869_hash NULL
85766 +_001870_hash btmrvl_txdnldready_read 3 413 _001870_hash NULL
85767 +_001871_hash btrfs_add_link 5 9973 _001871_hash NULL
85768 +_001872_hash __btrfs_direct_write 4 22273 _001872_hash NULL
85769 +_001873_hash btrfs_discard_extent 2 38547 _001873_hash NULL
85770 +_001874_hash btrfs_file_aio_write 4 21520 _001874_hash NULL
85771 +_001875_hash btrfs_find_create_tree_block 3 55812 _001875_hash NULL
85772 +_001876_hash btrfsic_map_block 2 56751 _001876_hash NULL
85773 +_001877_hash cache_read_pipefs 3 47615 _001877_hash NULL
85774 +_001878_hash cache_read_procfs 3 52882 _001878_hash NULL
85775 +_001879_hash cache_write_pipefs 3 48270 _001879_hash NULL
85776 +_001880_hash cache_write_procfs 3 22491 _001880_hash NULL
85777 +_001881_hash caif_stream_recvmsg 4 13173 _001881_hash NULL
85778 +_001882_hash carl9170_alloc 1 27 _001882_hash NULL
85779 +_001883_hash carl9170_debugfs_read 3 47738 _001883_hash NULL
85780 +_001884_hash ceph_msgpool_init 4 34599 _001884_hash NULL
85781 +_001885_hash cfpkt_add_trail 3 27260 _001885_hash NULL
85782 +_001886_hash cfpkt_create 1 18197 _001886_hash NULL
85783 +_001887_hash cfpkt_pad_trail 2 55511 _003606_hash NULL nohasharray
85784 +_001888_hash cfpkt_split 2 47541 _001888_hash NULL
85785 +_001889_hash cgroup_read_s64 5 19570 _001889_hash NULL
85786 +_001890_hash cgroup_read_u64 5 45532 _001890_hash NULL
85787 +_001891_hash channel_type_read 3 47308 _001891_hash NULL
85788 +_001892_hash check_header 2 56930 _001892_hash NULL
85789 +_001893_hash codec_list_read_file 3 24910 _001893_hash NULL
85790 +_001894_hash configfs_read_file 3 1683 _001894_hash NULL
85791 +_001895_hash console_store 4 36007 _001895_hash NULL
85792 +_001896_hash cpuset_common_file_read 5 8800 _001896_hash NULL
85793 +_001897_hash create_subvol 4 30836 _001897_hash NULL
85794 +_001898_hash cxio_hal_init_resource 2-7-6 29771 _001898_hash &_000295_hash
85795 +_001901_hash cxio_hal_init_rhdl_resource 1 25104 _001901_hash NULL
85796 +_001902_hash dai_list_read_file 3 25421 _001902_hash NULL
85797 +_001903_hash dapm_bias_read_file 3 64715 _001903_hash NULL
85798 +_001904_hash dapm_widget_power_read_file 3 59950 _001983_hash NULL nohasharray
85799 +_001907_hash dbgfs_frame 3 45917 _001907_hash NULL
85800 +_001908_hash dbgfs_state 3 38894 _001908_hash NULL
85801 +_001909_hash dccp_manip_pkt 2 30229 _001909_hash NULL
85802 +_001910_hash ddp_ppod_write_idata 5 25610 _001910_hash NULL
85803 +_001911_hash debugfs_read 3 62535 _001911_hash NULL
85804 +_001912_hash debug_output 3 18575 _001912_hash NULL
85805 +_001913_hash debug_read 3 19322 _001913_hash NULL
85806 +_001914_hash dev_alloc_skb 1 19517 _001914_hash &_001366_hash
85807 +_001915_hash dfs_file_read 3 18116 _001915_hash NULL
85808 +_001916_hash diva_alloc_dma_map 2 23798 _001916_hash NULL
85809 +_001917_hash diva_xdi_write 4 63975 _001917_hash NULL
85810 +_001918_hash dma_memcpy_pg_to_iovec 6 1725 _001918_hash NULL
85811 +_001919_hash dma_memcpy_to_iovec 5 12173 _001919_hash NULL
85812 +_001920_hash dma_show_regs 3 35266 _001920_hash NULL
85813 +_001921_hash dm_exception_table_init 2 39645 _001921_hash &_001149_hash
85814 +_001922_hash dn_nsp_do_disc 2-6 49474 _001922_hash NULL
85815 +_001924_hash dn_recvmsg 4 17213 _001924_hash NULL
85816 +_001925_hash dns_resolver_read 3 54658 _001925_hash NULL
85817 +_001926_hash do_msgrcv 4 5590 _001926_hash NULL
85818 +_001927_hash do_syslog 3 56807 _001927_hash NULL
85819 +_001928_hash dpcm_state_read_file 3 65489 _001928_hash NULL
85820 +_001929_hash dsp_cmx_send_member 2 15625 _001929_hash NULL
85821 +_001930_hash fallback_on_nodma_alloc 2 35332 _001930_hash NULL
85822 +_001931_hash fc_frame_alloc 2 1596 _001931_hash NULL
85823 +_001932_hash fc_frame_alloc_fill 2 59394 _001932_hash NULL
85824 +_001933_hash filter_read 3 61692 _001933_hash NULL
85825 +_001934_hash __finish_unordered_dir 4 33198 _001934_hash NULL
85826 +_001935_hash format_devstat_counter 3 32550 _001935_hash NULL
85827 +_001936_hash fragmentation_threshold_read 3 61718 _001936_hash NULL
85828 +_001937_hash fuse_conn_limit_read 3 20084 _001937_hash NULL
85829 +_001938_hash fuse_conn_waiting_read 3 49762 _001938_hash NULL
85830 +_001939_hash fuse_file_aio_write 4 46399 _001939_hash NULL
85831 +_001940_hash generic_readlink 3 32654 _001940_hash NULL
85832 +_001941_hash gre_manip_pkt 2 38785 _001941_hash NULL
85833 +_001942_hash handle_eviocgbit 3 44193 _001942_hash NULL
85834 +_001943_hash handle_response 5 55951 _001943_hash NULL
85835 +_001944_hash handle_response_icmp 7 39574 _001944_hash NULL
85836 +_001945_hash hash_recvmsg 4 50924 _001945_hash NULL
85837 +_001946_hash hci_send_cmd 3 43810 _001946_hash NULL
85838 +_001947_hash hci_si_event 3 1404 _001947_hash NULL
85839 +_001948_hash help 4 14971 _001948_hash NULL
85840 +_001949_hash hfcpci_empty_bfifo 4 62323 _001949_hash NULL
85841 +_001950_hash hidp_send_ctrl_message 4 43702 _001950_hash NULL
85842 +_001951_hash ht40allow_map_read 3 55209 _001951_hash &_001512_hash
85843 +_001952_hash hwflags_read 3 52318 _001952_hash NULL
85844 +_001953_hash hysdn_conf_read 3 42324 _001953_hash NULL
85845 +_001954_hash hysdn_sched_rx 3 60533 _001954_hash NULL
85846 +_001955_hash i2400m_rx_stats_read 3 57706 _001955_hash NULL
85847 +_001956_hash i2400m_tx_stats_read 3 28527 _001956_hash NULL
85848 +_001957_hash icmp_manip_pkt 2 48801 _001957_hash NULL
85849 +_001958_hash idmouse_read 3 63374 _001958_hash NULL
85850 +_001959_hash ieee80211_if_read 3 6785 _001959_hash NULL
85851 +_001960_hash ieee80211_rx_bss_info 3 61630 _001960_hash NULL
85852 +_001961_hash ikconfig_read_current 3 1658 _001961_hash NULL
85853 +_001962_hash il3945_sta_dbgfs_stats_table_read 3 48802 _001962_hash NULL
85854 +_001963_hash il3945_ucode_general_stats_read 3 46111 _001963_hash NULL
85855 +_001964_hash il3945_ucode_rx_stats_read 3 3048 _001964_hash NULL
85856 +_001965_hash il3945_ucode_tx_stats_read 3 36016 _001965_hash NULL
85857 +_001966_hash il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 _001966_hash NULL
85858 +_001967_hash il4965_rs_sta_dbgfs_scale_table_read 3 38564 _001967_hash NULL
85859 +_001968_hash il4965_rs_sta_dbgfs_stats_table_read 3 49206 _001968_hash NULL
85860 +_001969_hash il4965_ucode_general_stats_read 3 56277 _001969_hash NULL
85861 +_001970_hash il4965_ucode_rx_stats_read 3 61948 _001970_hash NULL
85862 +_001971_hash il4965_ucode_tx_stats_read 3 12064 _001971_hash NULL
85863 +_001972_hash il_dbgfs_chain_noise_read 3 38044 _001972_hash NULL
85864 +_001973_hash il_dbgfs_channels_read 3 25005 _001973_hash NULL
85865 +_001974_hash il_dbgfs_disable_ht40_read 3 42386 _001974_hash NULL
85866 +_001975_hash il_dbgfs_fh_reg_read 3 40993 _001975_hash NULL
85867 +_001976_hash il_dbgfs_force_reset_read 3 57517 _001976_hash NULL
85868 +_001977_hash il_dbgfs_interrupt_read 3 3351 _001977_hash NULL
85869 +_001978_hash il_dbgfs_missed_beacon_read 3 59956 _001978_hash NULL
85870 +_001979_hash il_dbgfs_nvm_read 3 12288 _001979_hash NULL
85871 +_001980_hash il_dbgfs_power_save_status_read 3 43165 _001980_hash NULL
85872 +_001981_hash il_dbgfs_qos_read 3 33615 _001981_hash NULL
85873 +_001982_hash il_dbgfs_rxon_filter_flags_read 3 19281 _001982_hash NULL
85874 +_001983_hash il_dbgfs_rxon_flags_read 3 59950 _001983_hash &_001904_hash
85875 +_001984_hash il_dbgfs_rx_queue_read 3 11221 _001984_hash NULL
85876 +_001985_hash il_dbgfs_rx_stats_read 3 15243 _001985_hash NULL
85877 +_001986_hash il_dbgfs_sensitivity_read 3 2370 _001986_hash NULL
85878 +_001987_hash il_dbgfs_sram_read 3 62296 _001987_hash NULL
85879 +_001988_hash il_dbgfs_stations_read 3 21532 _001988_hash NULL
85880 +_001989_hash il_dbgfs_status_read 3 58388 _001989_hash NULL
85881 +_001990_hash il_dbgfs_tx_queue_read 3 55668 _001990_hash NULL
85882 +_001991_hash il_dbgfs_tx_stats_read 3 32913 _001991_hash NULL
85883 +_001992_hash ima_show_htable_value 2 57136 _001992_hash NULL
85884 +_001994_hash intel_fake_agp_alloc_by_type 1 1 _001994_hash NULL
85885 +_001995_hash ip4ip6_err 5 36772 _001995_hash NULL
85886 +_001996_hash ip6_append_data 4-5 36490 _003601_hash NULL nohasharray
85887 +_001997_hash ip6ip6_err 5 18308 _001997_hash NULL
85888 +_001998_hash __ip_append_data 7-8 36191 _001998_hash NULL
85889 +_001999_hash ip_vs_icmp_xmit 4 59624 _001999_hash NULL
85890 +_002000_hash ip_vs_icmp_xmit_v6 4 20464 _002000_hash NULL
85891 +_002001_hash ipw_write 3 59807 _002001_hash NULL
85892 +_002002_hash irda_recvmsg_stream 4 35280 _002002_hash NULL
85893 +_002003_hash irq_domain_add_simple 2 46734 _002003_hash NULL
85894 +_002004_hash __iscsi_complete_pdu 4 10726 _002004_hash NULL
85895 +_002005_hash iscsi_nop_out_rsp 4 51117 _002005_hash NULL
85896 +_002006_hash iscsi_tcp_conn_setup 2 16376 _002006_hash NULL
85897 +_002007_hash iwl_dbgfs_bt_traffic_read 3 35534 _002007_hash NULL
85898 +_002008_hash iwl_dbgfs_calib_disabled_read 3 22649 _002008_hash NULL
85899 +_002009_hash iwl_dbgfs_chain_noise_read 3 46355 _002009_hash NULL
85900 +_002010_hash iwl_dbgfs_channels_read 3 6784 _002010_hash NULL
85901 +_002011_hash iwl_dbgfs_current_sleep_command_read 3 2081 _002011_hash NULL
85902 +_002012_hash iwl_dbgfs_disable_ht40_read 3 35761 _002012_hash NULL
85903 +_002013_hash iwl_dbgfs_fh_reg_read 3 879 _002013_hash &_000406_hash
85904 +_002014_hash iwl_dbgfs_interrupt_read 3 23574 _002014_hash NULL
85905 +_002015_hash iwl_dbgfs_log_event_read 3 2107 _002015_hash NULL
85906 +_002016_hash iwl_dbgfs_missed_beacon_read 3 50584 _002016_hash NULL
85907 +_002017_hash iwl_dbgfs_nvm_read 3 23845 _002017_hash NULL
85908 +_002018_hash iwl_dbgfs_plcp_delta_read 3 55407 _002018_hash NULL
85909 +_002019_hash iwl_dbgfs_power_save_status_read 3 54392 _002019_hash NULL
85910 +_002020_hash iwl_dbgfs_protection_mode_read 3 13943 _002020_hash NULL
85911 +_002021_hash iwl_dbgfs_qos_read 3 11753 _002021_hash NULL
85912 +_002022_hash iwl_dbgfs_reply_tx_error_read 3 19205 _002022_hash NULL
85913 +_002023_hash iwl_dbgfs_rf_reset_read 3 26512 _002023_hash NULL
85914 +_002024_hash iwl_dbgfs_rx_handlers_read 3 18708 _002024_hash NULL
85915 +_002025_hash iwl_dbgfs_rxon_filter_flags_read 3 28832 _002025_hash NULL
85916 +_002026_hash iwl_dbgfs_rxon_flags_read 3 20795 _002026_hash NULL
85917 +_002027_hash iwl_dbgfs_rx_queue_read 3 19943 _002027_hash NULL
85918 +_002028_hash iwl_dbgfs_sensitivity_read 3 63116 _002731_hash NULL nohasharray
85919 +_002029_hash iwl_dbgfs_sleep_level_override_read 3 3038 _002029_hash NULL
85920 +_002030_hash iwl_dbgfs_sram_read 3 44505 _002030_hash NULL
85921 +_002031_hash iwl_dbgfs_stations_read 3 9309 _002031_hash NULL
85922 +_002032_hash iwl_dbgfs_status_read 3 5171 _002032_hash NULL
85923 +_002033_hash iwl_dbgfs_temperature_read 3 29224 _002033_hash NULL
85924 +_002034_hash iwl_dbgfs_thermal_throttling_read 3 38779 _002034_hash NULL
85925 +_002035_hash iwl_dbgfs_tx_queue_read 3 4635 _002035_hash NULL
85926 +_002036_hash iwl_dbgfs_ucode_bt_stats_read 3 42820 _002036_hash NULL
85927 +_002037_hash iwl_dbgfs_ucode_general_stats_read 3 49199 _002037_hash NULL
85928 +_002038_hash iwl_dbgfs_ucode_rx_stats_read 3 58023 _002038_hash NULL
85929 +_002039_hash iwl_dbgfs_ucode_tracing_read 3 47983 _002039_hash &_000356_hash
85930 +_002040_hash iwl_dbgfs_ucode_tx_stats_read 3 31611 _002040_hash NULL
85931 +_002041_hash iwl_dbgfs_wowlan_sram_read 3 540 _002041_hash NULL
85932 +_002042_hash joydev_ioctl 2 33343 _002042_hash NULL
85933 +_002043_hash kernel_readv 3 35617 _002043_hash NULL
85934 +_002044_hash key_algorithm_read 3 57946 _002044_hash NULL
85935 +_002045_hash key_icverrors_read 3 20895 _002045_hash NULL
85936 +_002046_hash key_key_read 3 3241 _002046_hash NULL
85937 +_002047_hash key_replays_read 3 62746 _002047_hash NULL
85938 +_002048_hash key_rx_spec_read 3 12736 _002048_hash NULL
85939 +_002049_hash key_tx_spec_read 3 4862 _002049_hash NULL
85940 +_002050_hash __kfifo_to_user 3 36555 _002568_hash NULL nohasharray
85941 +_002051_hash __kfifo_to_user_r 3 39123 _002051_hash NULL
85942 +_002052_hash kmem_zalloc_greedy 2-3 65268 _002052_hash NULL
85943 +_002054_hash l1oip_socket_recv 6 56537 _002054_hash NULL
85944 +_002055_hash l2cap_build_cmd 4 48676 _002055_hash NULL
85945 +_002056_hash l2cap_chan_send 3 49995 _002056_hash NULL
85946 +_002057_hash l2cap_segment_sdu 4 48772 _002057_hash NULL
85947 +_002058_hash l2down_create 4 21755 _002058_hash NULL
85948 +_002059_hash l2tp_xmit_skb 3 42672 _002059_hash NULL
85949 +_002060_hash l2up_create 3 6430 _002060_hash NULL
85950 +_002061_hash lbs_debugfs_read 3 30721 _002061_hash NULL
85951 +_002062_hash lbs_dev_info 3 51023 _002062_hash NULL
85952 +_002063_hash lbs_host_sleep_read 3 31013 _002063_hash NULL
85953 +_002064_hash lbs_rdbbp_read 3 45805 _002064_hash NULL
85954 +_002065_hash lbs_rdmac_read 3 418 _002065_hash NULL
85955 +_002066_hash lbs_rdrf_read 3 41431 _002066_hash NULL
85956 +_002067_hash lbs_sleepparams_read 3 10840 _002067_hash NULL
85957 +_002068_hash lbs_threshold_read 5 21046 _002068_hash NULL
85958 +_002069_hash ldisc_receive 4 41516 _002069_hash NULL
85959 +_002070_hash libfc_vport_create 2 4415 _002070_hash NULL
85960 +_002073_hash lkdtm_debugfs_read 3 45752 _002073_hash NULL
85961 +_002074_hash llcp_sock_recvmsg 4 13556 _002074_hash NULL
85962 +_002075_hash long_retry_limit_read 3 59766 _002075_hash NULL
85963 +_002076_hash lpfc_debugfs_dif_err_read 3 36303 _002076_hash NULL
85964 +_002077_hash lpfc_debugfs_read 3 16566 _002077_hash NULL
85965 +_002078_hash lpfc_idiag_baracc_read 3 58466 _002972_hash NULL nohasharray
85966 +_002079_hash lpfc_idiag_ctlacc_read 3 33943 _002079_hash NULL
85967 +_002080_hash lpfc_idiag_drbacc_read 3 15948 _002080_hash NULL
85968 +_002081_hash lpfc_idiag_extacc_read 3 48301 _002081_hash NULL
85969 +_002082_hash lpfc_idiag_mbxacc_read 3 28061 _002082_hash NULL
85970 +_002083_hash lpfc_idiag_pcicfg_read 3 50334 _002083_hash NULL
85971 +_002084_hash lpfc_idiag_queacc_read 3 13950 _002084_hash NULL
85972 +_002085_hash lpfc_idiag_queinfo_read 3 55662 _002085_hash NULL
85973 +_002086_hash lro_gen_skb 6 2644 _002086_hash NULL
85974 +_002087_hash mac80211_format_buffer 2 41010 _002087_hash NULL
85975 +_002088_hash macvtap_alloc_skb 2-4-3 50629 _002088_hash NULL
85976 +_002091_hash macvtap_put_user 4 55609 _002091_hash NULL
85977 +_002092_hash macvtap_sendmsg 4 30629 _002092_hash NULL
85978 +_002093_hash mangle_packet 6-8 27864 _002093_hash NULL
85979 +_002095_hash manip_pkt 3 7741 _002095_hash NULL
85980 +_002096_hash mempool_create_kmalloc_pool 1 41650 _002096_hash NULL
85981 +_002097_hash mempool_create_page_pool 1 30189 _002097_hash NULL
85982 +_002098_hash mempool_create_slab_pool 1 62907 _002098_hash NULL
85983 +_002099_hash mgmt_device_found 10 14146 _002099_hash NULL
85984 +_002100_hash minstrel_stats_read 3 17290 _002100_hash NULL
85985 +_002101_hash mmc_ext_csd_read 3 13205 _002101_hash NULL
85986 +_002102_hash mon_bin_read 3 6841 _002102_hash NULL
85987 +_002103_hash mon_stat_read 3 25238 _002103_hash NULL
85988 +_002105_hash mqueue_read_file 3 6228 _002105_hash NULL
85989 +_002106_hash mwifiex_debug_read 3 53074 _002106_hash NULL
85990 +_002107_hash mwifiex_getlog_read 3 54269 _002107_hash NULL
85991 +_002108_hash mwifiex_info_read 3 53447 _002108_hash NULL
85992 +_002109_hash mwifiex_rdeeprom_read 3 51429 _002109_hash NULL
85993 +_002110_hash mwifiex_regrdwr_read 3 34472 _002110_hash NULL
85994 +_002111_hash named_prepare_buf 2 24532 _002111_hash NULL
85995 +_002112_hash nci_send_cmd 3 58206 _002112_hash NULL
85996 +_002113_hash netdev_alloc_skb_ip_align 2 40811 _002113_hash NULL
85997 +_002114_hash netpoll_send_udp 3 58955 _002114_hash NULL
85998 +_002115_hash nfcwilink_send_bts_cmd 3 10802 _002115_hash NULL
85999 +_002116_hash nf_nat_mangle_tcp_packet 5-7 8643 _002116_hash NULL
86000 +_002119_hash nfsd_vfs_read 6 62605 _002616_hash NULL nohasharray
86001 +_002120_hash nfsd_vfs_write 6 54577 _002120_hash NULL
86002 +_002121_hash nfs_idmap_lookup_id 2 10660 _002121_hash NULL
86003 +_002122_hash ntfs_rl_realloc 3 56831 _002122_hash &_000370_hash
86004 +_002123_hash ntfs_rl_realloc_nofail 3 32173 _002123_hash NULL
86005 +_002124_hash o2hb_debug_read 3 37851 _002124_hash NULL
86006 +_002125_hash o2net_debug_read 3 52105 _002125_hash NULL
86007 +_002126_hash ocfs2_control_read 3 56405 _002126_hash NULL
86008 +_002127_hash ocfs2_debug_read 3 14507 _002127_hash NULL
86009 +_002128_hash oom_adjust_read 3 25127 _002128_hash NULL
86010 +_002129_hash oom_score_adj_read 3 39921 _002426_hash NULL nohasharray
86011 +_002130_hash oprofilefs_str_to_user 3 42182 _002130_hash NULL
86012 +_002131_hash oprofilefs_ulong_to_user 3 11582 _002131_hash NULL
86013 +_002132_hash osd_req_add_get_attr_list 3 49278 _002132_hash NULL
86014 +_002133_hash _osd_req_list_objects 6 4204 _002133_hash NULL
86015 +_002134_hash osd_req_read_kern 5 59990 _002134_hash NULL
86016 +_002135_hash osd_req_write_kern 5 53486 _002135_hash NULL
86017 +_002136_hash osst_read 3 40237 _002136_hash NULL
86018 +_002137_hash p54_alloc_skb 3 34366 _002137_hash &_000485_hash
86019 +_002138_hash p54_init_common 1 23850 _002138_hash NULL
86020 +_002139_hash packet_alloc_skb 2-5-4 62602 _002139_hash NULL
86021 +_002142_hash packet_sendmsg 4 24954 _002142_hash NULL
86022 +_002143_hash page_readlink 3 23346 _002143_hash NULL
86023 +_002144_hash pcf50633_write_block 3 2124 _002144_hash NULL
86024 +_002145_hash pcpu_alloc_alloc_info 1-2 45813 _002145_hash NULL
86025 +_002147_hash pep_indicate 5 38611 _002147_hash NULL
86026 +_002148_hash pep_reply 5 50582 _002148_hash NULL
86027 +_002149_hash pipe_handler_request 5 50774 _003582_hash NULL nohasharray
86028 +_002150_hash platform_list_read_file 3 34734 _002150_hash NULL
86029 +_002151_hash pm860x_bulk_write 3 43875 _002151_hash NULL
86030 +_002152_hash pm_qos_power_read 3 55891 _002152_hash NULL
86031 +_002153_hash port_show_regs 3 5904 _002153_hash NULL
86032 +_002154_hash proc_coredump_filter_read 3 39153 _002154_hash NULL
86033 +_002155_hash proc_fdinfo_read 3 62043 _002155_hash NULL
86034 +_002156_hash proc_file_read 3 53905 _002156_hash NULL
86035 +_002157_hash proc_info_read 3 63344 _002157_hash NULL
86036 +_002158_hash proc_loginuid_read 3 15631 _002158_hash NULL
86037 +_002159_hash proc_pid_attr_read 3 10173 _002159_hash NULL
86038 +_002160_hash proc_pid_readlink 3 52186 _002160_hash NULL
86039 +_002161_hash proc_read 3 43614 _002161_hash NULL
86040 +_002162_hash proc_self_readlink 3 38094 _002162_hash NULL
86041 +_002163_hash proc_sessionid_read 3 6911 _002299_hash NULL nohasharray
86042 +_002164_hash provide_user_output 3 41105 _002164_hash NULL
86043 +_002165_hash pskb_network_may_pull 2 35336 _002165_hash NULL
86044 +_002166_hash pskb_pull 2 65005 _002166_hash NULL
86045 +_002167_hash pstore_file_read 3 57288 _002167_hash NULL
86046 +_002168_hash ql_process_mac_rx_page 4 15543 _002168_hash NULL
86047 +_002169_hash ql_process_mac_rx_skb 4 6689 _002169_hash NULL
86048 +_002170_hash queues_read 3 24877 _002170_hash NULL
86049 +_002171_hash raw_recvmsg 4 17277 _002171_hash NULL
86050 +_002172_hash rcname_read 3 25919 _002172_hash NULL
86051 +_002173_hash read_4k_modal_eeprom 3 30212 _002173_hash NULL
86052 +_002174_hash read_9287_modal_eeprom 3 59327 _002174_hash NULL
86053 +_002175_hash reada_find_extent 2 63486 _002175_hash NULL
86054 +_002176_hash read_def_modal_eeprom 3 14041 _002176_hash NULL
86055 +_002177_hash read_enabled_file_bool 3 37744 _002177_hash NULL
86056 +_002178_hash read_file_ani 3 23161 _002178_hash NULL
86057 +_002179_hash read_file_antenna 3 13574 _002179_hash NULL
86058 +_002180_hash read_file_base_eeprom 3 42168 _002180_hash NULL
86059 +_002181_hash read_file_beacon 3 32595 _002181_hash NULL
86060 +_002182_hash read_file_blob 3 57406 _002182_hash NULL
86061 +_002183_hash read_file_bool 3 4180 _002183_hash NULL
86062 +_002184_hash read_file_credit_dist_stats 3 54367 _002184_hash NULL
86063 +_002185_hash read_file_debug 3 58256 _002185_hash NULL
86064 +_002186_hash read_file_disable_ani 3 6536 _002186_hash NULL
86065 +_002187_hash read_file_dma 3 9530 _002187_hash NULL
86066 +_002188_hash read_file_dump_nfcal 3 18766 _002188_hash NULL
86067 +_002189_hash read_file_frameerrors 3 64001 _002189_hash NULL
86068 +_002190_hash read_file_interrupt 3 61742 _002197_hash NULL nohasharray
86069 +_002191_hash read_file_misc 3 9948 _002191_hash NULL
86070 +_002192_hash read_file_modal_eeprom 3 39909 _002192_hash NULL
86071 +_002193_hash read_file_queue 3 40895 _002193_hash NULL
86072 +_002194_hash read_file_rcstat 3 22854 _002194_hash NULL
86073 +_002195_hash read_file_recv 3 48232 _002195_hash NULL
86074 +_002196_hash read_file_regidx 3 33370 _002196_hash NULL
86075 +_002197_hash read_file_regval 3 61742 _002197_hash &_002190_hash
86076 +_002198_hash read_file_reset 3 52310 _002198_hash NULL
86077 +_002199_hash read_file_rx_chainmask 3 41605 _002199_hash NULL
86078 +_002200_hash read_file_slot 3 50111 _002200_hash NULL
86079 +_002201_hash read_file_stations 3 35795 _002201_hash NULL
86080 +_002202_hash read_file_tgt_int_stats 3 20697 _002202_hash NULL
86081 +_002203_hash read_file_tgt_rx_stats 3 33944 _002203_hash NULL
86082 +_002204_hash read_file_tgt_stats 3 8959 _002204_hash NULL
86083 +_002205_hash read_file_tgt_tx_stats 3 51847 _002205_hash NULL
86084 +_002206_hash read_file_tx_chainmask 3 3829 _002206_hash NULL
86085 +_002207_hash read_file_war_stats 3 292 _002207_hash NULL
86086 +_002208_hash read_file_xmit 3 21487 _002208_hash NULL
86087 +_002209_hash read_flush_pipefs 3 20171 _002209_hash NULL
86088 +_002210_hash read_flush_procfs 3 27642 _002210_hash NULL
86089 +_002211_hash read_from_oldmem 2 3337 _002211_hash NULL
86090 +_002212_hash read_oldmem 3 55658 _002212_hash NULL
86091 +_002213_hash receive_packet 2 12367 _002213_hash NULL
86092 +_002214_hash regmap_name_read_file 3 39379 _002214_hash NULL
86093 +_002215_hash repair_io_failure 4 4815 _002215_hash NULL
86094 +_002216_hash request_key_and_link 4 42693 _002216_hash NULL
86095 +_002217_hash res_counter_read 4 33499 _002217_hash NULL
86096 +_002218_hash rfcomm_tty_write 3 51603 _002218_hash NULL
86097 +_002219_hash rs_sta_dbgfs_rate_scale_data_read 3 47165 _002219_hash NULL
86098 +_002220_hash rs_sta_dbgfs_scale_table_read 3 40262 _002220_hash NULL
86099 +_002221_hash rs_sta_dbgfs_stats_table_read 3 56573 _002221_hash NULL
86100 +_002222_hash rts_threshold_read 3 44384 _002222_hash NULL
86101 +_002223_hash rxrpc_sendmsg 4 29049 _002223_hash NULL
86102 +_002224_hash scrub_setup_recheck_block 3-4 56245 _002224_hash NULL
86103 +_002226_hash scsi_adjust_queue_depth 3 12802 _002226_hash NULL
86104 +_002227_hash sctp_make_abort 3 34459 _002227_hash NULL
86105 +_002228_hash sctp_make_asconf 3 4078 _002228_hash NULL
86106 +_002229_hash sctp_make_asconf_ack 3 31726 _002229_hash NULL
86107 +_002230_hash sctp_make_datafrag_empty 3 34737 _002230_hash NULL
86108 +_002231_hash sctp_make_fwdtsn 3 53265 _002231_hash NULL
86109 +_002232_hash sctp_make_heartbeat_ack 4 34411 _002232_hash NULL
86110 +_002233_hash sctp_make_init 4 58401 _002233_hash NULL
86111 +_002234_hash sctp_make_init_ack 4 3335 _002234_hash NULL
86112 +_002235_hash sctp_make_op_error_space 3 5528 _002235_hash NULL
86113 +_002236_hash sctp_manip_pkt 2 40620 _002236_hash NULL
86114 +_002237_hash selinux_inode_notifysecctx 3 36896 _002237_hash NULL
86115 +_002238_hash sel_read_avc_cache_threshold 3 33942 _002238_hash NULL
86116 +_002239_hash sel_read_avc_hash_stats 3 1984 _002239_hash NULL
86117 +_002240_hash sel_read_bool 3 24236 _002240_hash NULL
86118 +_002241_hash sel_read_checkreqprot 3 33068 _002241_hash NULL
86119 +_002242_hash sel_read_class 3 12669 _002960_hash NULL nohasharray
86120 +_002243_hash sel_read_enforce 3 2828 _002243_hash NULL
86121 +_002244_hash sel_read_handle_status 3 56139 _002244_hash NULL
86122 +_002245_hash sel_read_handle_unknown 3 57933 _002245_hash NULL
86123 +_002246_hash sel_read_initcon 3 32362 _002246_hash NULL
86124 +_002247_hash sel_read_mls 3 25369 _002247_hash NULL
86125 +_002248_hash sel_read_perm 3 42302 _002248_hash NULL
86126 +_002249_hash sel_read_policy 3 55947 _002249_hash NULL
86127 +_002250_hash sel_read_policycap 3 28544 _002250_hash NULL
86128 +_002251_hash sel_read_policyvers 3 55 _002827_hash NULL nohasharray
86129 +_002252_hash send_mpa_reject 3 7135 _002252_hash NULL
86130 +_002253_hash send_mpa_reply 3 32372 _002253_hash NULL
86131 +_002254_hash send_msg 4 37323 _002254_hash NULL
86132 +_002255_hash send_packet 4 52960 _002255_hash NULL
86133 +_002256_hash set_rxd_buffer_pointer 8 9950 _002256_hash NULL
86134 +_002257_hash sge_rx 3 50594 _002257_hash NULL
86135 +_002258_hash short_retry_limit_read 3 4687 _002258_hash NULL
86136 +_002259_hash simple_attr_read 3 24738 _002259_hash NULL
86137 +_002260_hash simple_transaction_read 3 17076 _002260_hash NULL
86138 +_002261_hash sisusbcon_bmove 5-7-6 21873 _002261_hash NULL
86139 +_002264_hash sisusbcon_clear 3-5-4 64329 _002264_hash NULL
86140 +_002267_hash sisusbcon_putcs 3 57630 _002267_hash &_001043_hash
86141 +_002268_hash sisusbcon_scroll 5-3-2 31315 _002268_hash NULL
86142 +_002269_hash sisusbcon_scroll_area 3-4 25899 _002269_hash NULL
86143 +_002271_hash skb_copy_datagram_const_iovec 2-5-4 48102 _002271_hash NULL
86144 +_002274_hash skb_copy_datagram_iovec 2-4 5806 _002274_hash NULL
86145 +_002276_hash skb_gro_header_slow 2 34958 _002276_hash NULL
86146 +_002277_hash smk_read_ambient 3 61220 _002277_hash NULL
86147 +_002278_hash smk_read_direct 3 15803 _002278_hash NULL
86148 +_002279_hash smk_read_doi 3 30813 _002279_hash NULL
86149 +_002280_hash smk_read_logging 3 37804 _002280_hash NULL
86150 +_002281_hash smk_read_mapped 3 7562 _002281_hash NULL
86151 +_002282_hash smk_read_onlycap 3 3855 _002282_hash NULL
86152 +_002283_hash smp_build_cmd 3 45853 _002283_hash NULL
86153 +_002284_hash snapshot_read 3 22601 _002284_hash NULL
86154 +_002285_hash snd_cs4281_BA0_read 5 6847 _002285_hash NULL
86155 +_002286_hash snd_cs4281_BA1_read 5 20323 _002286_hash NULL
86156 +_002287_hash snd_cs46xx_io_read 5 45734 _002287_hash NULL
86157 +_002288_hash snd_gus_dram_read 4 56686 _002288_hash NULL
86158 +_002289_hash snd_mixart_BA0_read 5 45069 _002289_hash NULL
86159 +_002290_hash snd_mixart_BA1_read 5 5082 _002290_hash NULL
86160 +_002291_hash snd_pcm_oss_read 3 28317 _002291_hash NULL
86161 +_002292_hash snd_pcm_plug_alloc 2 42339 _002292_hash NULL
86162 +_002293_hash snd_rawmidi_kernel_read 3 4328 _002293_hash NULL
86163 +_002294_hash snd_rawmidi_read 3 56337 _002294_hash NULL
86164 +_002295_hash snd_rme32_capture_copy 5 39653 _002295_hash NULL
86165 +_002296_hash snd_rme96_capture_copy 5 58484 _002296_hash NULL
86166 +_002297_hash snd_soc_hw_bulk_write_raw 4 14245 _002297_hash NULL
86167 +_002298_hash sock_alloc_send_skb 2 23720 _002298_hash NULL
86168 +_002299_hash spi_show_regs 3 6911 _002299_hash &_002163_hash
86169 +_002300_hash sta_agg_status_read 3 14058 _002300_hash NULL
86170 +_002301_hash sta_connected_time_read 3 17435 _002301_hash NULL
86171 +_002302_hash sta_flags_read 3 56710 _002302_hash NULL
86172 +_002303_hash sta_ht_capa_read 3 10366 _002303_hash NULL
86173 +_002304_hash sta_last_seq_ctrl_read 3 19106 _002304_hash NULL
86174 +_002305_hash sta_num_ps_buf_frames_read 3 1488 _002305_hash NULL
86175 +_002306_hash st_read 3 51251 _002306_hash NULL
86176 +_002307_hash supply_map_read_file 3 10608 _002307_hash NULL
86177 +_002308_hash sysfs_read_file 3 42113 _002308_hash NULL
86178 +_002309_hash sys_preadv 3 17100 _002309_hash NULL
86179 +_002310_hash sys_pwritev 3 41722 _002310_hash NULL
86180 +_002311_hash sys_readv 3 50664 _002311_hash NULL
86181 +_002312_hash sys_rt_sigpending 2 24961 _002312_hash NULL
86182 +_002313_hash sys_writev 3 28384 _002313_hash NULL
86183 +_002314_hash tcf_csum_skb_nextlayer 3 64025 _002314_hash NULL
86184 +_002315_hash tcp_fragment 3 20436 _002315_hash NULL
86185 +_002316_hash tcp_manip_pkt 2 14202 _002316_hash NULL
86186 +_002317_hash teiup_create 3 43201 _002317_hash NULL
86187 +_002318_hash test_iso_queue 5 62534 _002318_hash NULL
86188 +_002319_hash tg3_run_loopback 2 30093 _002319_hash NULL
86189 +_002320_hash tipc_msg_build 4 12326 _002320_hash NULL
86190 +_002321_hash TSS_authhmac 3 12839 _002321_hash NULL
86191 +_002322_hash TSS_checkhmac1 5 31429 _002322_hash NULL
86192 +_002323_hash TSS_checkhmac2 5-7 40520 _002323_hash NULL
86193 +_002325_hash tty_audit_log 8 47280 _002325_hash NULL
86194 +_002326_hash tty_buffer_request_room 2 23228 _002326_hash NULL
86195 +_002327_hash tty_insert_flip_string_fixed_flag 4 37428 _002327_hash NULL
86196 +_002328_hash tty_insert_flip_string_flags 4 30969 _002328_hash NULL
86197 +_002329_hash tty_prepare_flip_string 3 39955 _002329_hash NULL
86198 +_002330_hash tty_prepare_flip_string_flags 4 59240 _002330_hash NULL
86199 +_002331_hash tun_alloc_skb 2-4-3 41216 _002331_hash NULL
86200 +_002334_hash tun_sendmsg 4 10337 _002334_hash NULL
86201 +_002335_hash u32_array_read 3 2219 _002335_hash NULL
86202 +_002336_hash ubi_io_write_data 4-5 40305 _002336_hash NULL
86203 +_002338_hash udplite_manip_pkt 2 62433 _002338_hash NULL
86204 +_002339_hash udp_manip_pkt 2 50770 _002339_hash NULL
86205 +_002340_hash uhci_debug_read 3 5911 _002340_hash NULL
86206 +_002341_hash um_idi_read 3 850 _002341_hash NULL
86207 +_002342_hash unix_seqpacket_sendmsg 4 27893 _002342_hash NULL
86208 +_002343_hash unix_stream_recvmsg 4 35210 _002343_hash NULL
86209 +_002344_hash unlink_simple 3 47506 _002344_hash NULL
86210 +_002345_hash use_pool 2 64607 _002345_hash NULL
86211 +_002346_hash v9fs_fid_readn 4 60544 _002346_hash NULL
86212 +_002347_hash v9fs_file_read 3 40858 _002347_hash NULL
86213 +_002348_hash vhci_read 3 47878 _002348_hash NULL
86214 +_002349_hash vhost_add_used_and_signal_n 4 8038 _002349_hash NULL
86215 +_002350_hash vmbus_open 2-3 12154 _002350_hash NULL
86216 +_002352_hash vxge_rx_alloc 3 52024 _002352_hash NULL
86217 +_002353_hash waiters_read 3 40902 _002353_hash NULL
86218 +_002354_hash wm8994_bulk_write 3 13615 _002354_hash NULL
86219 +_002355_hash write_pbl 4 59583 _002355_hash NULL
86220 +_002356_hash wusb_prf_256 7 29203 _002356_hash NULL
86221 +_002357_hash wusb_prf_64 7 51065 _002357_hash NULL
86222 +_002358_hash _xfs_buf_alloc 3 38058 _002358_hash NULL
86223 +_002359_hash xfs_buf_read_uncached 3 42844 _002359_hash NULL
86224 +_002360_hash xfs_file_buffered_aio_write 4 11492 _002360_hash NULL
86225 +_002361_hash xfs_iext_add 3 41422 _002361_hash NULL
86226 +_002362_hash xfs_iext_remove_direct 3 40744 _002362_hash NULL
86227 +_002363_hash xfs_readdir 3 41200 _002363_hash NULL
86228 +_002364_hash xfs_trans_get_efd 3 51148 _002364_hash NULL
86229 +_002365_hash xfs_trans_get_efi 2 7898 _002365_hash NULL
86230 +_002366_hash xlog_bread_offset 3 60030 _002366_hash NULL
86231 +_002367_hash xlog_get_bp 2 23229 _002367_hash NULL
86232 +_002368_hash xz_dec_init 2 29029 _002368_hash NULL
86233 +_002369_hash aac_change_queue_depth 2 825 _002369_hash NULL
86234 +_002370_hash add_rx_skb 3 8257 _002370_hash NULL
86235 +_002371_hash afs_extract_data 5 50261 _002371_hash NULL
86236 +_002372_hash arcmsr_adjust_disk_queue_depth 2 16756 _002372_hash NULL
86237 +_002373_hash atalk_recvmsg 4 22053 _002373_hash NULL
86238 +_002374_hash ath6kl_buf_alloc 1 57304 _002374_hash NULL
86239 +_002376_hash atomic_read_file 3 16227 _002376_hash NULL
86240 +_002377_hash ax25_recvmsg 4 64441 _002377_hash NULL
86241 +_002378_hash batadv_add_packet 3 12136 _002378_hash NULL
86242 +_002379_hash batadv_iv_ogm_aggregate_new 2 54761 _002379_hash NULL
86243 +_002380_hash batadv_tt_response_fill_table 1 39236 _002380_hash NULL
86244 +_002381_hash beiscsi_process_async_pdu 7 39834 _002381_hash NULL
86245 +_002382_hash bioset_create 1 5580 _002382_hash NULL
86246 +_002383_hash bioset_integrity_create 2 62708 _002383_hash NULL
86247 +_002384_hash biovec_create_pools 2 9575 _002384_hash NULL
86248 +_002385_hash bnx2fc_process_l2_frame_compl 3 65072 _002385_hash NULL
86249 +_002386_hash brcmf_sdbrcm_died_dump 3 15841 _002386_hash NULL
86250 +_002387_hash brcmu_pkt_buf_get_skb 1 5556 _002387_hash NULL
86251 +_002388_hash br_send_bpdu 3 29669 _002388_hash NULL
86252 +_002389_hash btrfs_error_discard_extent 2 50444 _002389_hash NULL
86253 +_002390_hash __btrfs_free_reserved_extent 2 31207 _002390_hash NULL
86254 +_002391_hash btrfsic_cmp_log_and_dev_bytenr 2 49628 _002391_hash NULL
86255 +_002392_hash btrfsic_create_link_to_next_block 4 58246 _002392_hash NULL
86256 +_002393_hash btrfs_init_new_buffer 4 55761 _002393_hash NULL
86257 +_002394_hash btrfs_mksubvol 3 58240 _002394_hash NULL
86258 +_002395_hash bt_skb_send_alloc 2 6581 _002395_hash NULL
86259 +_002396_hash bt_sock_recvmsg 4 12316 _002396_hash NULL
86260 +_002397_hash bt_sock_stream_recvmsg 4 52518 _002397_hash NULL
86261 +_002398_hash c4iw_reject_cr 3 28174 _002398_hash NULL
86262 +_002399_hash caif_seqpkt_recvmsg 4 32241 _002399_hash NULL
86263 +_002400_hash carl9170_rx_copy_data 2 21656 _002400_hash NULL
86264 +_002401_hash cfpkt_append 3 61206 _002401_hash NULL
86265 +_002402_hash cfpkt_setlen 2 49343 _002402_hash NULL
86266 +_002403_hash cgroup_file_read 3 28804 _002403_hash NULL
86267 +_002404_hash cosa_net_setup_rx 2 38594 _002404_hash NULL
86268 +_002405_hash cpu_type_read 3 36540 _002405_hash NULL
86269 +_002406_hash cxgb4_pktgl_to_skb 2 61899 _002406_hash NULL
86270 +_002408_hash dccp_recvmsg 4 16056 _002408_hash NULL
86271 +_002409_hash ddp_clear_map 4 46152 _002409_hash NULL
86272 +_002410_hash ddp_set_map 4 751 _002410_hash NULL
86273 +_002411_hash depth_read 3 31112 _002411_hash NULL
86274 +_002412_hash dfs_global_file_read 3 7787 _002412_hash NULL
86275 +_002413_hash dgram_recvmsg 4 23104 _002413_hash NULL
86276 +_002414_hash diva_init_dma_map 3 58336 _002414_hash NULL
86277 +_002415_hash divas_write 3 63901 _002415_hash NULL
86278 +_002416_hash dma_push_rx 2 39973 _002416_hash NULL
86279 +_002417_hash dma_skb_copy_datagram_iovec 3-5 21516 _002417_hash NULL
86280 +_002419_hash dm_table_create 3 35687 _002419_hash NULL
86281 +_002420_hash dn_alloc_send_pskb 2 4465 _002420_hash NULL
86282 +_002421_hash dn_nsp_return_disc 2 60296 _002421_hash NULL
86283 +_002422_hash dn_nsp_send_disc 2 23469 _002422_hash NULL
86284 +_002423_hash dsp_tone_hw_message 3 17678 _002423_hash NULL
86285 +_002424_hash e1000_check_copybreak 3 62448 _002424_hash NULL
86286 +_002425_hash enable_read 3 2117 _002425_hash &_000224_hash
86287 +_002426_hash exofs_read_kern 6 39921 _002426_hash &_002129_hash
86288 +_002427_hash fast_rx_path 3 59214 _002427_hash NULL
86289 +_002428_hash fc_change_queue_depth 2 36841 _002428_hash NULL
86290 +_002429_hash fc_fcp_frame_alloc 2 12624 _002429_hash NULL
86291 +_002430_hash fcoe_ctlr_send_keep_alive 3 15308 _002430_hash NULL
86292 +_002431_hash frequency_read 3 64031 _003698_hash NULL nohasharray
86293 +_002432_hash ftdi_process_packet 5 45005 _002432_hash NULL
86294 +_002433_hash fuse_conn_congestion_threshold_read 3 51028 _002433_hash NULL
86295 +_002434_hash fuse_conn_max_background_read 3 10855 _002434_hash NULL
86296 +_002435_hash fwnet_incoming_packet 3 40380 _002435_hash NULL
86297 +_002436_hash fwnet_pd_new 4 39947 _003402_hash NULL nohasharray
86298 +_002437_hash get_alua_req 3 4166 _002437_hash NULL
86299 +_002438_hash get_rdac_req 3 45882 _002438_hash NULL
86300 +_002439_hash got_frame 2 16028 _002439_hash NULL
86301 +_002440_hash gsm_mux_rx_netchar 3 33336 _002440_hash NULL
86302 +_002441_hash hci_sock_recvmsg 4 7072 _002441_hash NULL
86303 +_002442_hash hdlcdev_rx 3 997 _002442_hash NULL
86304 +_002443_hash hdlc_empty_fifo 2 18397 _002443_hash NULL
86305 +_002444_hash hfc_empty_fifo 2 57972 _002444_hash NULL
86306 +_002445_hash hfcpci_empty_fifo 4 2427 _002445_hash NULL
86307 +_002446_hash hfcsusb_rx_frame 3 52745 _002446_hash NULL
86308 +_002447_hash hidp_output_raw_report 3 5629 _002447_hash NULL
86309 +_002448_hash hpsa_change_queue_depth 2 15449 _002448_hash NULL
86310 +_002449_hash hptiop_adjust_disk_queue_depth 2 20122 _002449_hash NULL
86311 +_002450_hash hscx_empty_fifo 2 13360 _002450_hash NULL
86312 +_002451_hash hysdn_rx_netpkt 3 16136 _002451_hash NULL
86313 +_002452_hash i2o_pool_alloc 4 55485 _002452_hash NULL
86314 +_002453_hash ide_queue_pc_tail 5 11673 _002453_hash NULL
86315 +_002454_hash ide_raw_taskfile 4 42355 _002454_hash NULL
86316 +_002455_hash idetape_queue_rw_tail 3 29562 _002455_hash NULL
86317 +_002456_hash ieee80211_amsdu_to_8023s 5 15561 _002456_hash NULL
86318 +_002457_hash ieee80211_fragment 4 33112 _002457_hash NULL
86319 +_002458_hash ieee80211_if_read_aid 3 9705 _002458_hash NULL
86320 +_002459_hash ieee80211_if_read_auto_open_plinks 3 38268 _002459_hash &_000374_hash
86321 +_002460_hash ieee80211_if_read_ave_beacon 3 64924 _002460_hash NULL
86322 +_002461_hash ieee80211_if_read_bssid 3 35161 _002461_hash NULL
86323 +_002462_hash ieee80211_if_read_channel_type 3 23884 _002462_hash NULL
86324 +_002463_hash ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 _002463_hash NULL
86325 +_002464_hash ieee80211_if_read_dot11MeshForwarding 3 13940 _002464_hash NULL
86326 +_002465_hash ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 _002465_hash NULL
86327 +_002466_hash ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 _002466_hash NULL
86328 +_002467_hash ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 _002467_hash NULL
86329 +_002468_hash ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 _002468_hash NULL
86330 +_002469_hash ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 _002469_hash NULL
86331 +_002470_hash ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 _002470_hash NULL
86332 +_002471_hash ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 _002471_hash NULL
86333 +_002472_hash ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 _002472_hash NULL
86334 +_002473_hash ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 _002473_hash NULL
86335 +_002474_hash ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 _002474_hash NULL
86336 +_002475_hash ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 _002475_hash NULL
86337 +_002476_hash ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 _002476_hash NULL
86338 +_002477_hash ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 _002477_hash NULL
86339 +_002478_hash ieee80211_if_read_dot11MeshMaxRetries 3 12756 _002478_hash NULL
86340 +_002479_hash ieee80211_if_read_dot11MeshRetryTimeout 3 52168 _002479_hash NULL
86341 +_002480_hash ieee80211_if_read_dot11MeshTTL 3 58307 _002480_hash NULL
86342 +_002481_hash ieee80211_if_read_dropped_frames_congestion 3 32603 _002481_hash NULL
86343 +_002482_hash ieee80211_if_read_dropped_frames_no_route 3 33383 _002482_hash NULL
86344 +_002483_hash ieee80211_if_read_dropped_frames_ttl 3 44500 _002483_hash NULL
86345 +_002484_hash ieee80211_if_read_drop_unencrypted 3 37053 _002484_hash NULL
86346 +_002485_hash ieee80211_if_read_dtim_count 3 38419 _002485_hash NULL
86347 +_002486_hash ieee80211_if_read_element_ttl 3 18869 _002486_hash NULL
86348 +_002487_hash ieee80211_if_read_estab_plinks 3 32533 _002487_hash NULL
86349 +_002488_hash ieee80211_if_read_flags 3 57470 _002919_hash NULL nohasharray
86350 +_002489_hash ieee80211_if_read_fwded_frames 3 36520 _002489_hash NULL
86351 +_002490_hash ieee80211_if_read_fwded_mcast 3 39571 _002490_hash &_000162_hash
86352 +_002491_hash ieee80211_if_read_fwded_unicast 3 59740 _002491_hash &_001697_hash
86353 +_002492_hash ieee80211_if_read_ht_opmode 3 29044 _002492_hash NULL
86354 +_002493_hash ieee80211_if_read_last_beacon 3 31257 _002493_hash NULL
86355 +_002494_hash ieee80211_if_read_min_discovery_timeout 3 13946 _002494_hash NULL
86356 +_002495_hash ieee80211_if_read_num_buffered_multicast 3 12716 _002495_hash NULL
86357 +_002496_hash ieee80211_if_read_num_mcast_sta 3 12419 _002496_hash NULL
86358 +_002497_hash ieee80211_if_read_num_sta_ps 3 34722 _002497_hash NULL
86359 +_002498_hash ieee80211_if_read_path_refresh_time 3 25545 _002498_hash NULL
86360 +_002499_hash ieee80211_if_read_peer 3 45233 _002499_hash NULL
86361 +_002500_hash ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 _002500_hash NULL
86362 +_002501_hash ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 _002501_hash NULL
86363 +_002502_hash ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 _002502_hash NULL
86364 +_002503_hash ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 _002503_hash NULL
86365 +_002504_hash ieee80211_if_read_rssi_threshold 3 49260 _002504_hash NULL
86366 +_002505_hash ieee80211_if_read_smps 3 27416 _002505_hash NULL
86367 +_002506_hash ieee80211_if_read_state 3 9813 _002707_hash NULL nohasharray
86368 +_002507_hash ieee80211_if_read_tkip_mic_test 3 19565 _002507_hash NULL
86369 +_002508_hash ieee80211_if_read_tsf 3 16420 _002508_hash NULL
86370 +_002509_hash ieee80211_if_read_uapsd_max_sp_len 3 15067 _002509_hash NULL
86371 +_002510_hash ieee80211_if_read_uapsd_queues 3 55150 _002510_hash NULL
86372 +_002511_hash ieee80211_mgmt_tx 9 46860 _002511_hash NULL
86373 +_002512_hash ieee80211_probereq_get 4-6 29069 _002512_hash NULL
86374 +_002514_hash ieee80211_rx_mgmt_beacon 3 24430 _002514_hash NULL
86375 +_002515_hash ieee80211_rx_mgmt_probe_resp 3 6918 _002515_hash NULL
86376 +_002516_hash ieee80211_send_auth 5 24121 _002516_hash NULL
86377 +_002517_hash ieee80211_set_probe_resp 3 10077 _002517_hash NULL
86378 +_002518_hash ieee80211_tdls_mgmt 8 9581 _002518_hash NULL
86379 +_002519_hash ima_show_htable_violations 3 10619 _002519_hash NULL
86380 +_002520_hash ima_show_measurements_count 3 23536 _002520_hash NULL
86381 +_002521_hash insert_one_name 7 61668 _002521_hash NULL
86382 +_002522_hash ip6_ufo_append_data 5-7-6 4780 _002522_hash NULL
86383 +_002525_hash ip_append_data 5-6 16942 _002525_hash NULL
86384 +_002526_hash ip_make_skb 5-6 13129 _002526_hash NULL
86385 +_002527_hash ip_nat_sdp_port 6 52938 _002527_hash NULL
86386 +_002528_hash ip_nat_sip_expect 7 45693 _002528_hash NULL
86387 +_002529_hash ipr_change_queue_depth 2 6431 _002529_hash NULL
86388 +_002530_hash ip_recv_error 3 23109 _002530_hash NULL
86389 +_002531_hash ip_ufo_append_data 6-8-7 12775 _002531_hash NULL
86390 +_002534_hash ipv6_recv_error 3 56347 _002534_hash NULL
86391 +_002535_hash ipv6_recv_rxpmtu 3 7142 _002535_hash NULL
86392 +_002536_hash ipw_packet_received_skb 2 1230 _002536_hash NULL
86393 +_002537_hash ipx_recvmsg 4 44366 _002537_hash NULL
86394 +_002538_hash irda_recvmsg_dgram 4 32631 _002538_hash NULL
86395 +_002539_hash iscsi_change_queue_depth 2 23416 _002539_hash NULL
86396 +_002540_hash iscsi_complete_pdu 4 48372 _002540_hash NULL
86397 +_002541_hash iwch_reject_cr 3 23901 _002541_hash NULL
86398 +_002542_hash ixgb_check_copybreak 3 5847 _002542_hash NULL
86399 +_002543_hash key_conf_hw_key_idx_read 3 25003 _002543_hash NULL
86400 +_002544_hash key_conf_keyidx_read 3 42443 _002544_hash NULL
86401 +_002545_hash key_conf_keylen_read 3 49758 _002545_hash NULL
86402 +_002546_hash key_flags_read 3 25931 _002546_hash NULL
86403 +_002547_hash key_ifindex_read 3 31411 _002547_hash NULL
86404 +_002548_hash key_tx_rx_count_read 3 44742 _002548_hash NULL
86405 +_002549_hash kmsg_read 3 46514 _002549_hash NULL
86406 +_002550_hash l1oip_socket_parse 4 4507 _002550_hash NULL
86407 +_002551_hash l2cap_send_cmd 4 14548 _002551_hash NULL
86408 +_002552_hash l2cap_sock_sendmsg 4 63427 _002552_hash NULL
86409 +_002553_hash l2tp_ip6_recvmsg 4 62874 _002553_hash NULL
86410 +_002554_hash l2tp_ip6_sendmsg 4 7461 _002554_hash NULL
86411 +_002555_hash l2tp_ip_recvmsg 4 22681 _002555_hash NULL
86412 +_002556_hash lbs_bcnmiss_read 3 8678 _002556_hash NULL
86413 +_002557_hash lbs_failcount_read 3 31063 _002557_hash NULL
86414 +_002558_hash lbs_highrssi_read 3 64089 _002558_hash NULL
86415 +_002559_hash lbs_highsnr_read 3 5931 _002559_hash NULL
86416 +_002560_hash lbs_lowrssi_read 3 32242 _002560_hash NULL
86417 +_002561_hash lbs_lowsnr_read 3 29571 _002561_hash NULL
86418 +_002563_hash llc_ui_recvmsg 4 3826 _002563_hash NULL
86419 +_002564_hash lowpan_fragment_xmit 3-4 22095 _002564_hash NULL
86420 +_002566_hash lpfc_change_queue_depth 2 25905 _002566_hash NULL
86421 +_002568_hash macvtap_do_read 4 36555 _002568_hash &_002050_hash
86422 +_002569_hash mangle_sdp_packet 9 36279 _002569_hash NULL
86423 +_002570_hash map_addr 6 4666 _002570_hash NULL
86424 +_002571_hash mcs_unwrap_fir 3 25733 _002571_hash NULL
86425 +_002572_hash mcs_unwrap_mir 3 9455 _002572_hash NULL
86426 +_002573_hash megaraid_change_queue_depth 2 64815 _002573_hash NULL
86427 +_002574_hash megasas_change_queue_depth 2 32747 _002574_hash NULL
86428 +_002575_hash mld_newpack 2 50950 _002575_hash NULL
86429 +_002576_hash mptscsih_change_queue_depth 2 26036 _002576_hash NULL
86430 +_002577_hash named_distribute 4 48544 _002577_hash NULL
86431 +_002578_hash NCR_700_change_queue_depth 2 31742 _002578_hash NULL
86432 +_002579_hash netlink_recvmsg 4 61600 _002579_hash NULL
86433 +_002580_hash nfc_alloc_send_skb 4 3167 _002580_hash NULL
86434 +_002581_hash nf_nat_ftp 5 47948 _002581_hash NULL
86435 +_002582_hash nfsctl_transaction_read 3 48250 _002582_hash NULL
86436 +_002583_hash nfsd_read 5 19568 _002583_hash NULL
86437 +_002584_hash nfsd_read_file 6 62241 _002584_hash NULL
86438 +_002585_hash nfsd_write 6 54809 _002585_hash NULL
86439 +_002586_hash nfs_map_group_to_gid 3 15892 _002586_hash NULL
86440 +_002587_hash nfs_map_name_to_uid 3 51132 _002587_hash NULL
86441 +_002588_hash nr_recvmsg 4 12649 _002588_hash NULL
86442 +_002589_hash ntfs_rl_append 2-4 6037 _002589_hash NULL
86443 +_002591_hash ntfs_rl_insert 2-4 4931 _002591_hash NULL
86444 +_002593_hash ntfs_rl_replace 2-4 14136 _002593_hash NULL
86445 +_002595_hash ntfs_rl_split 2-4 52328 _002595_hash NULL
86446 +_002597_hash osd_req_list_collection_objects 5 36664 _002597_hash NULL
86447 +_002598_hash osd_req_list_partition_objects 5 56464 _002598_hash NULL
86448 +_002599_hash osd_req_read_sg 5 47905 _002599_hash NULL
86449 +_002600_hash osd_req_write_sg 5 50908 _002600_hash NULL
86450 +_002602_hash p54_download_eeprom 4 43842 _002602_hash NULL
86451 +_002604_hash packet_recv_error 3 16669 _002604_hash NULL
86452 +_002605_hash packet_recvmsg 4 47700 _002605_hash NULL
86453 +_002606_hash pep_recvmsg 4 19402 _002606_hash NULL
86454 +_002607_hash pfkey_recvmsg 4 53604 _002607_hash NULL
86455 +_002608_hash ping_recvmsg 4 25597 _002608_hash NULL
86456 +_002609_hash pmcraid_change_queue_depth 2 9116 _002609_hash NULL
86457 +_002610_hash pn_recvmsg 4 30887 _002610_hash NULL
86458 +_002611_hash pointer_size_read 3 51863 _002611_hash NULL
86459 +_002612_hash power_read 3 15939 _002612_hash NULL
86460 +_002613_hash pppoe_recvmsg 4 15073 _002613_hash NULL
86461 +_002614_hash pppol2tp_recvmsg 4 57742 _002993_hash NULL nohasharray
86462 +_002615_hash ppp_tx_cp 5 62044 _002615_hash NULL
86463 +_002616_hash prism2_send_mgmt 4 62605 _002616_hash &_002119_hash
86464 +_002617_hash prism2_sta_send_mgmt 5 43916 _002617_hash NULL
86465 +_002618_hash prison_create 1 43623 _002618_hash NULL
86466 +_002619_hash qla2x00_adjust_sdev_qdepth_up 2 20097 _002619_hash NULL
86467 +_002620_hash qla2x00_change_queue_depth 2 24742 _002620_hash NULL
86468 +_002621_hash _queue_data 4 54983 _002621_hash NULL
86469 +_002622_hash raw_recvmsg 4 52529 _002622_hash NULL
86470 +_002623_hash rawsock_recvmsg 4 12144 _002623_hash NULL
86471 +_002624_hash rawv6_recvmsg 4 30265 _002624_hash NULL
86472 +_002625_hash rds_tcp_data_recv 3 53476 _002625_hash NULL
86473 +_002626_hash reada_add_block 2 54247 _002626_hash NULL
86474 +_002627_hash readahead_tree_block 3 36285 _002627_hash NULL
86475 +_002628_hash reada_tree_block_flagged 3 18402 _002628_hash NULL
86476 +_002629_hash read_dma 3 55086 _002629_hash NULL
86477 +_002630_hash read_fifo 3 826 _002630_hash NULL
86478 +_002631_hash read_tree_block 3 841 _002631_hash NULL
86479 +_002632_hash receive_copy 3 12216 _002632_hash NULL
86480 +_002633_hash recover_peb 6-7 29238 _002633_hash NULL
86481 +_002635_hash recv_msg 4 48709 _002635_hash NULL
86482 +_002636_hash recv_stream 4 30138 _002636_hash NULL
86483 +_002637_hash _req_append_segment 2 41031 _002637_hash NULL
86484 +_002638_hash request_key_async 4 6990 _002638_hash NULL
86485 +_002639_hash request_key_async_with_auxdata 4 46624 _002639_hash NULL
86486 +_002640_hash request_key_with_auxdata 4 24515 _002640_hash NULL
86487 +_002641_hash rose_recvmsg 4 2368 _002641_hash &_001788_hash
86488 +_002642_hash rtl8169_try_rx_copy 3 705 _002642_hash NULL
86489 +_002643_hash _rtl92s_firmware_downloadcode 3 14021 _002643_hash NULL
86490 +_002644_hash rx_data 4 60442 _002644_hash NULL
86491 +_002645_hash rxrpc_recvmsg 4 26233 _002645_hash NULL
86492 +_002646_hash sas_change_queue_depth 2 18555 _002646_hash NULL
86493 +_002647_hash scsi_activate_tcq 2 42640 _002647_hash NULL
86494 +_002648_hash scsi_deactivate_tcq 2 47086 _002648_hash NULL
86495 +_002649_hash scsi_execute 5 33596 _002649_hash NULL
86496 +_002650_hash _scsih_adjust_queue_depth 2 1083 _002650_hash NULL
86497 +_002651_hash scsi_init_shared_tag_map 2 59812 _002651_hash NULL
86498 +_002652_hash scsi_track_queue_full 2 44239 _002652_hash NULL
86499 +_002653_hash sctp_abort_pkt_new 5 55218 _002653_hash NULL
86500 +_002654_hash sctp_make_abort_violation 4 27959 _002654_hash NULL
86501 +_002655_hash sctp_make_op_error 5-6 7057 _002655_hash NULL
86502 +_002657_hash sctp_recvmsg 4 23265 _002657_hash NULL
86503 +_002658_hash send_stream 4 3397 _002658_hash NULL
86504 +_002659_hash sis190_try_rx_copy 3 57069 _002659_hash NULL
86505 +_002664_hash skb_copy_and_csum_datagram_iovec 2 24466 _002664_hash NULL
86506 +_002666_hash skge_rx_get 3 40598 _002666_hash NULL
86507 +_002667_hash smp_send_cmd 3 512 _002667_hash NULL
86508 +_002668_hash snd_gf1_mem_proc_dump 5 16926 _003499_hash NULL nohasharray
86509 +_002669_hash sta_dev_read 3 14782 _002669_hash NULL
86510 +_002670_hash sta_inactive_ms_read 3 25690 _002670_hash NULL
86511 +_002671_hash sta_last_signal_read 3 31818 _002671_hash NULL
86512 +_002672_hash stats_dot11ACKFailureCount_read 3 45558 _002672_hash NULL
86513 +_002673_hash stats_dot11FCSErrorCount_read 3 28154 _002673_hash NULL
86514 +_002674_hash stats_dot11RTSFailureCount_read 3 43948 _002674_hash NULL
86515 +_002675_hash stats_dot11RTSSuccessCount_read 3 33065 _002675_hash NULL
86516 +_002676_hash storvsc_connect_to_vsp 2 22 _002676_hash NULL
86517 +_002677_hash sys_msgrcv 3 959 _002677_hash NULL
86518 +_002678_hash sys_syslog 3 10746 _002678_hash NULL
86519 +_002679_hash tcf_csum_ipv4_icmp 3 9258 _002679_hash NULL
86520 +_002680_hash tcf_csum_ipv4_igmp 3 60446 _002680_hash NULL
86521 +_002681_hash tcf_csum_ipv4_tcp 4 39713 _002681_hash NULL
86522 +_002682_hash tcf_csum_ipv4_udp 4 30777 _002682_hash NULL
86523 +_002683_hash tcf_csum_ipv6_icmp 4 11738 _002683_hash NULL
86524 +_002684_hash tcf_csum_ipv6_tcp 4 54877 _002684_hash NULL
86525 +_002685_hash tcf_csum_ipv6_udp 4 25241 _002685_hash NULL
86526 +_002686_hash tcm_loop_change_queue_depth 2 42454 _002686_hash NULL
86527 +_002687_hash tcp_copy_to_iovec 3 28344 _002687_hash NULL
86528 +_002688_hash tcp_mark_head_lost 2 35895 _002688_hash NULL
86529 +_002689_hash tcp_match_skb_to_sack 4 23568 _002689_hash NULL
86530 +_002690_hash timeout_read 3 47915 _002690_hash NULL
86531 +_002691_hash tipc_multicast 5 49144 _002691_hash NULL
86532 +_002692_hash tipc_port_recv_sections 4 42890 _002692_hash NULL
86533 +_002693_hash tipc_port_reject_sections 5 55229 _002693_hash NULL
86534 +_002694_hash total_ps_buffered_read 3 16365 _002694_hash NULL
86535 +_002695_hash tso_fragment 3 29050 _002695_hash NULL
86536 +_002696_hash tty_insert_flip_string 3 34042 _002696_hash NULL
86537 +_002698_hash tun_put_user 4 59849 _002698_hash NULL
86538 +_002699_hash twa_change_queue_depth 2 48808 _002699_hash NULL
86539 +_002700_hash tw_change_queue_depth 2 11116 _002700_hash NULL
86540 +_002701_hash twl_change_queue_depth 2 41342 _002701_hash NULL
86541 +_002702_hash ubi_eba_atomic_leb_change 5 60379 _002702_hash NULL
86542 +_002703_hash ubi_eba_write_leb 5-6 36029 _002703_hash NULL
86543 +_002705_hash ubi_eba_write_leb_st 5 44343 _002705_hash NULL
86544 +_002706_hash udp_recvmsg 4 42558 _002706_hash NULL
86545 +_002707_hash udpv6_recvmsg 4 9813 _002707_hash &_002506_hash
86546 +_002708_hash udpv6_sendmsg 4 22316 _002708_hash NULL
86547 +_002709_hash ulong_read_file 3 42304 _002709_hash &_000522_hash
86548 +_002710_hash unix_dgram_recvmsg 4 14952 _002710_hash NULL
86549 +_002711_hash user_power_read 3 39414 _002711_hash NULL
86550 +_002712_hash v9fs_direct_read 3 45546 _002712_hash NULL
86551 +_002713_hash v9fs_file_readn 4 36353 _002713_hash &_001799_hash
86552 +_002714_hash vcc_recvmsg 4 37198 _002714_hash NULL
86553 +_002715_hash velocity_rx_copy 2 34583 _002715_hash NULL
86554 +_002716_hash W6692_empty_Bfifo 2 47804 _002716_hash NULL
86555 +_002717_hash wep_iv_read 3 54744 _002717_hash NULL
86556 +_002718_hash x25_recvmsg 4 42777 _002718_hash NULL
86557 +_002719_hash xfs_buf_get_map 3 24522 _002719_hash NULL
86558 +_002720_hash xfs_file_aio_write 4 33234 _002720_hash NULL
86559 +_002721_hash xfs_iext_insert 3 18667 _002741_hash NULL nohasharray
86560 +_002722_hash xfs_iext_remove 3 50909 _002722_hash NULL
86561 +_002723_hash xlog_do_recovery_pass 3 21618 _002723_hash NULL
86562 +_002724_hash xlog_find_verify_log_record 2 18870 _002724_hash NULL
86563 +_002725_hash zd_mac_rx 3 38296 _002725_hash NULL
86564 +_002726_hash aircable_process_packet 5 46639 _002726_hash NULL
86565 +_002727_hash ath6kl_wmi_get_new_buf 1 52304 _002727_hash NULL
86566 +_002728_hash batadv_iv_ogm_queue_add 3 46319 _002728_hash NULL
86567 +_002729_hash batadv_receive_client_update_packet 3 41578 _002729_hash NULL
86568 +_002730_hash batadv_receive_server_sync_packet 3 26577 _002730_hash &_000494_hash
86569 +_002731_hash brcmf_alloc_pkt_and_read 2 63116 _002731_hash &_002028_hash
86570 +_002732_hash brcmf_sdcard_recv_buf 6 38179 _002732_hash NULL
86571 +_002733_hash brcmf_sdcard_rwdata 5 65041 _002733_hash NULL
86572 +_002734_hash brcmf_sdcard_send_buf 6 7713 _002734_hash NULL
86573 +_002735_hash brcmf_sdio_forensic_read 3 35311 _002735_hash &_001382_hash
86574 +_002736_hash btrfs_alloc_free_block 3 8986 _002736_hash NULL
86575 +_002737_hash btrfs_free_and_pin_reserved_extent 2 53016 _002737_hash NULL
86576 +_002738_hash btrfs_free_reserved_extent 2 9867 _002738_hash NULL
86577 +_002739_hash carl9170_handle_mpdu 3 11056 _002739_hash NULL
86578 +_002740_hash do_trimming 3 26952 _002740_hash NULL
86579 +_002741_hash edge_tty_recv 4 18667 _002741_hash &_002721_hash
86580 +_002742_hash fwnet_receive_packet 9 50537 _002742_hash NULL
86581 +_002743_hash gigaset_if_receive 3 4861 _002743_hash NULL
86582 +_002744_hash gsm_dlci_data 3 14155 _002744_hash NULL
86583 +_002745_hash handle_rx_packet 3 58993 _002745_hash NULL
86584 +_002746_hash HDLC_irq 2 8709 _002746_hash NULL
86585 +_002747_hash hdlc_rpr_irq 2 10240 _002747_hash NULL
86586 +_002749_hash ifx_spi_insert_flip_string 3 51752 _002749_hash NULL
86587 +_002753_hash ip_nat_sdp_media 8 23386 _002753_hash NULL
86588 +_002754_hash ip_send_unicast_reply 6 38714 _002754_hash NULL
86589 +_002756_hash ipwireless_network_packet_received 4 51277 _002756_hash NULL
86590 +_002757_hash ipwireless_tty_received 3 49154 _002757_hash NULL
86591 +_002758_hash iscsi_iser_recv 4 41948 _002758_hash NULL
86592 +_002759_hash l2cap_bredr_sig_cmd 3 49065 _002759_hash NULL
86593 +_002760_hash l2cap_sock_alloc_skb_cb 2 33532 _002760_hash NULL
86594 +_002761_hash l2cap_sock_recvmsg 4 59886 _002761_hash NULL
86595 +_002762_hash llcp_allocate_pdu 3 19866 _002762_hash NULL
86596 +_002763_hash macvtap_recvmsg 4 63949 _002763_hash NULL
86597 +_002764_hash osd_req_list_dev_partitions 4 60027 _002764_hash NULL
86598 +_002765_hash osd_req_list_partition_collections 5 38223 _002765_hash NULL
86599 +_002766_hash osst_do_scsi 4 44410 _002766_hash NULL
86600 +_002767_hash ping_sendmsg 4 3782 _002767_hash NULL
86601 +_002768_hash ppp_cp_event 6 2965 _002768_hash NULL
86602 +_002769_hash pty_write 3 44757 _002769_hash &_001733_hash
86603 +_002770_hash push_rx 3 28939 _002770_hash NULL
86604 +_002772_hash qla2x00_handle_queue_full 2 24365 _002772_hash NULL
86605 +_002773_hash qla4xxx_change_queue_depth 2 1268 _002773_hash NULL
86606 +_002774_hash rfcomm_sock_recvmsg 4 22227 _002774_hash NULL
86607 +_002775_hash scsi_execute_req 5 42088 _002775_hash NULL
86608 +_002776_hash _scsih_change_queue_depth 2 26230 _002776_hash NULL
86609 +_002777_hash sctp_sf_abort_violation 6 38380 _002777_hash NULL
86610 +_002778_hash send_to_tty 3 45141 _002778_hash NULL
86611 +_002780_hash sky2_receive 2 13407 _002780_hash NULL
86612 +_002781_hash spi_execute 5 28736 _002781_hash NULL
86613 +_002782_hash submit_inquiry 3 42108 _002782_hash NULL
86614 +_002783_hash tcp_dma_try_early_copy 3 4457 _002783_hash NULL
86615 +_002784_hash tcp_sacktag_walk 6 49703 _002784_hash NULL
86616 +_002785_hash tcp_write_xmit 2 64602 _002785_hash NULL
86617 +_002786_hash ti_recv 4 22027 _002786_hash NULL
86618 +_002787_hash tun_do_read 4 50800 _002787_hash NULL
86619 +_002788_hash ubi_leb_change 4 10289 _002788_hash NULL
86620 +_002789_hash ubi_leb_write 4-5 5478 _002789_hash NULL
86621 +_002791_hash udp_sendmsg 4 4492 _002791_hash NULL
86622 +_002792_hash unix_seqpacket_recvmsg 4 23062 _002792_hash &_000477_hash
86623 +_002793_hash v9fs_cached_file_read 3 2514 _002793_hash NULL
86624 +_002794_hash write_leb 5 36957 _002794_hash NULL
86625 +_002795_hash xfs_buf_read_map 3 40226 _002795_hash NULL
86626 +_002796_hash xfs_trans_get_buf_map 4 2927 _002796_hash NULL
86627 +_002797_hash xlog_do_log_recovery 3 17550 _002797_hash NULL
86628 +_002798_hash ath6kl_wmi_add_wow_pattern_cmd 4 12842 _002798_hash NULL
86629 +_002799_hash ath6kl_wmi_beginscan_cmd 8 25462 _002799_hash NULL
86630 +_002800_hash ath6kl_wmi_send_probe_response_cmd 6 31728 _002800_hash NULL
86631 +_002801_hash ath6kl_wmi_set_appie_cmd 5 39266 _002801_hash NULL
86632 +_002802_hash ath6kl_wmi_set_ie_cmd 6 37260 _002802_hash NULL
86633 +_002803_hash ath6kl_wmi_startscan_cmd 8 33674 _002803_hash NULL
86634 +_002804_hash ath6kl_wmi_test_cmd 3 27312 _002804_hash NULL
86635 +_002805_hash brcmf_sdbrcm_membytes 3-5 37324 _002805_hash NULL
86636 +_002807_hash brcmf_sdbrcm_read_control 3 22721 _002807_hash NULL
86637 +_002808_hash brcmf_tx_frame 3 20978 _002808_hash NULL
86638 +_002809_hash __carl9170_rx 3 56784 _002809_hash NULL
86639 +_002810_hash ch_do_scsi 4 31171 _002810_hash NULL
86640 +_002811_hash dbg_leb_change 4 23555 _002811_hash NULL
86641 +_002812_hash dbg_leb_write 4-5 63555 _002812_hash &_000971_hash
86642 +_002814_hash gluebi_write 3 27905 _002814_hash NULL
86643 +_002815_hash hdlc_irq_one 2 3944 _002815_hash NULL
86644 +_002819_hash iser_rcv_completion 2 8048 _002819_hash NULL
86645 +_002820_hash lock_loop 1 61681 _002820_hash NULL
86646 +_002821_hash process_rcvd_data 3 6679 _002821_hash NULL
86647 +_002822_hash brcmf_sdbrcm_bus_txctl 3 42492 _002822_hash NULL
86648 +_002823_hash carl9170_rx 3 13272 _002823_hash NULL
86649 +_002824_hash carl9170_rx_stream 3 1334 _002824_hash NULL
86650 +_002826_hash mpt_lan_receive_post_turbo 2 13592 _002826_hash NULL
86651 +_002827_hash padzero 1 55 _002827_hash &_002251_hash
86652 +_002828_hash scsi_mode_sense 5 16835 _002828_hash NULL
86653 +_002829_hash scsi_vpd_inquiry 4 30040 _002829_hash NULL
86654 +_002830_hash ses_recv_diag 4 47143 _002830_hash &_000679_hash
86655 +_002831_hash ses_send_diag 4 64527 _002831_hash NULL
86656 +_002832_hash tcp_push_one 2 48816 _002832_hash NULL
86657 +_002833_hash __tcp_push_pending_frames 2 48148 _002833_hash NULL
86658 +_002834_hash trim_bitmaps 3 24158 _002834_hash NULL
86659 +_002835_hash tun_recvmsg 4 48463 _002835_hash NULL
86660 +_002836_hash ubifs_leb_change 4 17789 _002836_hash NULL
86661 +_002837_hash ubifs_leb_write 4-5 22679 _002837_hash NULL
86662 +_002839_hash xfs_buf_readahead_map 3 44248 _002839_hash &_000851_hash
86663 +_002840_hash xfs_trans_read_buf_map 5 37487 _002840_hash NULL
86664 +_002841_hash xlog_do_recover 3 59789 _002841_hash NULL
86665 +_002842_hash btrfs_trim_block_group 3 28963 _002842_hash NULL
86666 +_002843_hash do_write_orph_node 2 64343 _002843_hash NULL
86667 +_002844_hash fix_unclean_leb 3 23188 _002844_hash NULL
86668 +_002845_hash fixup_leb 3 43256 _002845_hash NULL
86669 +_002846_hash recover_head 3 17904 _002846_hash NULL
86670 +_002847_hash scsi_get_vpd_page 4 51951 _002847_hash NULL
86671 +_002848_hash sd_do_mode_sense 5 11507 _002848_hash NULL
86672 +_002849_hash tcp_push 3 10680 _002849_hash NULL
86673 +_002850_hash ubifs_wbuf_write_nolock 3 64946 _002850_hash NULL
86674 +_002851_hash ubifs_write_node 3-5 11258 _002851_hash NULL
86675 +_002852_hash ubifs_recover_leb 3 60639 _002852_hash NULL
86676 +_002853_hash write_head 4 30481 _002853_hash NULL
86677 +_002854_hash write_node 4 33121 _002854_hash NULL
86678 +_002855_hash ubifs_recover_log_leb 3 12079 _002855_hash NULL
86679 +_002856_hash replay_log_leb 3 18704 _002856_hash NULL
86680 +_002857_hash alloc_cpu_rmap 1 65363 _002857_hash NULL
86681 +_002858_hash alloc_ebda_hpc 1-2 50046 _002858_hash NULL
86682 +_002860_hash alloc_sched_domains 1 28972 _002860_hash NULL
86683 +_002861_hash amthi_read 4 45831 _002861_hash NULL
86684 +_002862_hash bcm_char_read 3 31750 _002862_hash NULL
86685 +_002863_hash BcmCopySection 5 2035 _002863_hash NULL
86686 +_002864_hash buffer_from_user 3 51826 _002864_hash NULL
86687 +_002865_hash buffer_to_user 3 35439 _002865_hash NULL
86688 +_002866_hash card_send_command 3 40757 _002866_hash NULL
86689 +_002867_hash chd_dec_fetch_cdata 3 50926 _002867_hash NULL
86690 +_002868_hash copy_nodes_to_user 2 63807 _002868_hash NULL
86691 +_002869_hash create_log 2 8225 _002869_hash NULL
86692 +_002870_hash crystalhd_create_dio_pool 2 3427 _002870_hash NULL
86693 +_002871_hash crystalhd_user_data 3 18407 _002871_hash NULL
86694 +_002872_hash do_pages_stat 2 4437 _002872_hash NULL
86695 +_002873_hash do_read_log_to_user 4 3236 _002873_hash NULL
86696 +_002874_hash do_write_log_from_user 3 39362 _002874_hash NULL
86697 +_002875_hash evm_read_key 3 54674 _002875_hash NULL
86698 +_002876_hash evm_write_key 3 27715 _002876_hash NULL
86699 +_002877_hash fir16_create 3 5574 _002877_hash NULL
86700 +_002878_hash get_nodes 3 39012 _002878_hash NULL
86701 +_002879_hash __iio_allocate_kfifo 2-3 55738 _002879_hash NULL
86702 +_002881_hash __iio_allocate_sw_ring_buffer 3 4843 _002881_hash NULL
86703 +_002882_hash iio_debugfs_read_reg 3 60908 _002882_hash NULL
86704 +_002883_hash iio_debugfs_write_reg 3 22742 _002883_hash NULL
86705 +_002884_hash iio_device_alloc 1 41440 _002884_hash NULL
86706 +_002885_hash iio_event_chrdev_read 3 54757 _002885_hash NULL
86707 +_002886_hash iio_read_first_n_kfifo 2 57910 _002886_hash NULL
86708 +_002887_hash iio_read_first_n_sw_rb 2 51911 _002887_hash NULL
86709 +_002888_hash ioapic_setup_resources 1 35255 _002888_hash NULL
86710 +_002889_hash keymap_store 4 45406 _002889_hash NULL
86711 +_002890_hash line6_alloc_sysex_buffer 4 28225 _002890_hash NULL
86712 +_002891_hash line6_dumpreq_initbuf 3 53123 _002891_hash NULL
86713 +_002892_hash line6_midibuf_init 2 52425 _002892_hash NULL
86714 +_002893_hash _malloc 1 54077 _002893_hash NULL
86715 +_002894_hash mei_read 3 6507 _002894_hash NULL
86716 +_002895_hash mei_write 3 4005 _002895_hash NULL
86717 +_002896_hash msg_set 3 51725 _002896_hash NULL
86718 +_002897_hash newpart 6 47485 _002897_hash NULL
86719 +_002898_hash OS_kmalloc 1 36909 _002898_hash NULL
86720 +_002899_hash OS_mem_token_alloc 1 14276 _002899_hash NULL
86721 +_002900_hash packet_came 3 18072 _002900_hash NULL
86722 +_002901_hash pcpu_alloc_bootmem 2 62074 _002901_hash NULL
86723 +_002902_hash pcpu_build_alloc_info 1-3-2 41443 _002902_hash NULL
86724 +_002905_hash pcpu_get_vm_areas 3 50085 _002905_hash NULL
86725 +_002906_hash resource_from_user 3 30341 _002906_hash NULL
86726 +_002907_hash rtsx_read_cfg_seq 3-5 48139 _002907_hash NULL
86727 +_002909_hash rtsx_write_cfg_seq 3-5 27485 _002909_hash NULL
86728 +_002911_hash sca3000_read_data 4 57064 _002911_hash NULL
86729 +_002912_hash sca3000_read_first_n_hw_rb 2 11479 _002912_hash NULL
86730 +_002913_hash send_midi_async 3 57463 _002913_hash NULL
86731 +_002914_hash sep_create_dcb_dmatables_context 6 37551 _002914_hash NULL
86732 +_002915_hash sep_create_dcb_dmatables_context_kernel 6 49728 _002915_hash NULL
86733 +_002916_hash sep_create_msgarea_context 4 33829 _002916_hash NULL
86734 +_002917_hash sep_lli_table_secure_dma 2-3 64042 _002917_hash NULL
86735 +_002919_hash sep_lock_user_pages 2-3 57470 _002919_hash &_002488_hash
86736 +_002921_hash sep_prepare_input_output_dma_table_in_dcb 4-5-2-3 63087 _002921_hash NULL
86737 +_002923_hash sep_read 3 17161 _002923_hash NULL
86738 +_002924_hash TransmitTcb 4 12989 _002924_hash NULL
86739 +_002925_hash ValidateDSDParamsChecksum 3 63654 _002925_hash NULL
86740 +_002926_hash Wb35Reg_BurstWrite 4 62327 _002926_hash NULL
86741 +_002927_hash alloc_irq_cpu_rmap 1 28459 _002927_hash NULL
86742 +_002928_hash InterfaceTransmitPacket 3 42058 _002928_hash NULL
86743 +_002929_hash line6_dumpreq_init 3 34473 _002929_hash NULL
86744 +_002931_hash pcpu_embed_first_chunk 1-3-2 24224 _002931_hash NULL
86745 +_002933_hash pcpu_fc_alloc 2 11818 _002933_hash NULL
86746 +_002934_hash pcpu_page_first_chunk 1 20712 _002934_hash NULL
86747 +_002935_hash pod_alloc_sysex_buffer 3 31651 _002935_hash NULL
86748 +_002936_hash r8712_usbctrl_vendorreq 6 48489 _002936_hash NULL
86749 +_002937_hash r871x_set_wpa_ie 3 7000 _002937_hash NULL
86750 +_002938_hash sep_prepare_input_dma_table 2-3 2009 _002938_hash NULL
86751 +_002940_hash sep_prepare_input_output_dma_table 2-4-3 63429 _002940_hash NULL
86752 +_002943_hash sys_get_mempolicy 3 30379 _002943_hash NULL
86753 +_002944_hash sys_mbind 5 7990 _002944_hash NULL
86754 +_002945_hash sys_migrate_pages 2 39825 _002945_hash NULL
86755 +_002946_hash sys_move_pages 2 42626 _002946_hash NULL
86756 +_002947_hash sys_set_mempolicy 3 32608 _002947_hash NULL
86757 +_002948_hash variax_alloc_sysex_buffer 3 15237 _002948_hash NULL
86758 +_002949_hash vme_user_read 3 55338 _002949_hash NULL
86759 +_002950_hash vme_user_write 3 15587 _002950_hash NULL
86760 +_002954_hash variax_set_raw2 4 32374 _002954_hash NULL
86761 +_002955_hash copy_in_user 3 57502 _002955_hash NULL
86762 +_002956_hash __earlyonly_bootmem_alloc 2 23824 _002956_hash NULL
86763 +_002957_hash rfc4106_set_key 3 54519 _002957_hash NULL
86764 +_002958_hash sparse_early_usemaps_alloc_pgdat_section 2 62304 _002958_hash NULL
86765 +_002959_hash sparse_early_usemaps_alloc_node 4 9269 _002959_hash NULL
86766 +_002960_hash sparse_mem_maps_populate_node 4 12669 _002960_hash &_002242_hash
86767 +_002961_hash vmemmap_alloc_block 1 43245 _002961_hash NULL
86768 +_002962_hash sparse_early_mem_maps_alloc_node 4 36971 _002962_hash NULL
86769 +_002963_hash vmemmap_alloc_block_buf 1 61126 _002963_hash NULL
86770 +_002964_hash alloc_mr 1 45935 _002964_hash NULL
86771 +_002965_hash atomic_counters_read 3 48827 _002965_hash NULL
86772 +_002966_hash atomic_stats_read 3 36228 _002966_hash NULL
86773 +_002967_hash capabilities_read 3 58457 _002967_hash NULL
86774 +_002968_hash compat_core_sys_select 1 65285 _002968_hash NULL
86775 +_002969_hash compat_dccp_setsockopt 5 51263 _002969_hash NULL
86776 +_002970_hash compat_do_arpt_set_ctl 4 12184 _002970_hash NULL
86777 +_002971_hash compat_do_ip6t_set_ctl 4 3184 _002971_hash NULL
86778 +_002972_hash compat_do_ipt_set_ctl 4 58466 _002972_hash &_002078_hash
86779 +_002973_hash compat_filldir 3 32999 _002973_hash NULL
86780 +_002974_hash compat_filldir64 3 35354 _002974_hash NULL
86781 +_002975_hash compat_fillonedir 3 15620 _002975_hash NULL
86782 +_002976_hash compat_ip_setsockopt 5 13870 _003094_hash NULL nohasharray
86783 +_002977_hash compat_ipv6_setsockopt 5 20468 _002977_hash NULL
86784 +_002978_hash compat_mpctl_ioctl 2 45671 _002978_hash NULL
86785 +_002979_hash compat_raw_setsockopt 5 30634 _002979_hash NULL
86786 +_002980_hash compat_rawv6_setsockopt 5 4967 _002980_hash NULL
86787 +_002981_hash compat_rw_copy_check_uvector 3 22001 _003263_hash NULL nohasharray
86788 +_002982_hash compat_sock_setsockopt 5 23 _002982_hash NULL
86789 +_002983_hash compat_sys_get_mempolicy 3 31109 _002983_hash NULL
86790 +_002984_hash compat_sys_kexec_load 2 35674 _002984_hash NULL
86791 +_002985_hash compat_sys_keyctl 4 9639 _002985_hash NULL
86792 +_002986_hash compat_sys_mbind 5 36256 _002986_hash NULL
86793 +_002987_hash compat_sys_migrate_pages 2 3157 _002987_hash NULL
86794 +_002988_hash compat_sys_move_pages 2 5861 _002988_hash NULL
86795 +_002989_hash compat_sys_mq_timedsend 3 31060 _002989_hash NULL
86796 +_002990_hash compat_sys_msgrcv 2 7482 _002990_hash NULL
86797 +_002991_hash compat_sys_msgsnd 2 10738 _002991_hash NULL
86798 +_002992_hash compat_sys_semtimedop 3 3606 _002992_hash NULL
86799 +_002993_hash compat_sys_set_mempolicy 3 57742 _002993_hash &_002614_hash
86800 +_002994_hash __copy_in_user 3 34790 _002994_hash NULL
86801 +_002995_hash dev_counters_read 3 19216 _002995_hash NULL
86802 +_002996_hash dev_names_read 3 38509 _002996_hash NULL
86803 +_002997_hash driver_names_read 3 60399 _002997_hash NULL
86804 +_002998_hash driver_stats_read 3 8944 _002998_hash NULL
86805 +_002999_hash evdev_ioctl_compat 2 13851 _002999_hash NULL
86806 +_003000_hash evtchn_read 3 3569 _003000_hash NULL
86807 +_003001_hash evtchn_write 3 43278 _003001_hash NULL
86808 +_003002_hash fat_compat_ioctl_filldir 3 36328 _003002_hash NULL
86809 +_003003_hash flash_read 3 57843 _003003_hash NULL
86810 +_003004_hash flash_write 3 62354 _003004_hash NULL
86811 +_003005_hash fw_device_op_compat_ioctl 2 42804 _003005_hash NULL
86812 +_003006_hash gather_array 3 56641 _003006_hash NULL
86813 +_003007_hash ghash_async_setkey 3 60001 _003007_hash NULL
86814 +_003008_hash gntdev_alloc_map 2 35145 _003008_hash NULL
86815 +_003009_hash gnttab_map 2 56439 _003009_hash NULL
86816 +_003010_hash gru_alloc_gts 2-3 60056 _003010_hash &_000981_hash
86817 +_003012_hash hiddev_compat_ioctl 2 41255 _003012_hash NULL
86818 +_003013_hash init_cdev 1 8274 _003013_hash NULL
86819 +_003014_hash init_per_cpu 1 17880 _003014_hash NULL
86820 +_003015_hash ipath_create_cq 2 45586 _003015_hash NULL
86821 +_003016_hash ipath_get_base_info 3 7043 _003016_hash NULL
86822 +_003017_hash ipath_init_qp_table 2 25167 _003017_hash NULL
86823 +_003018_hash ipath_resize_cq 2 712 _003018_hash NULL
86824 +_003019_hash joydev_compat_ioctl 2 8765 _003019_hash NULL
86825 +_003020_hash mon_bin_compat_ioctl 3 50234 _003020_hash NULL
86826 +_003021_hash options_write 3 47243 _003021_hash NULL
86827 +_003022_hash portcntrs_1_read 3 47253 _003022_hash NULL
86828 +_003023_hash portcntrs_2_read 3 56586 _003023_hash NULL
86829 +_003024_hash portnames_read 3 41958 _003024_hash NULL
86830 +_003025_hash ptc_proc_write 3 12076 _003025_hash NULL
86831 +_003026_hash put_cmsg_compat 4 35937 _003026_hash NULL
86832 +_003027_hash qib_alloc_devdata 2 51819 _003027_hash NULL
86833 +_003028_hash qib_alloc_fast_reg_page_list 2 10507 _003028_hash NULL
86834 +_003029_hash qib_cdev_init 1 34778 _003029_hash NULL
86835 +_003030_hash qib_create_cq 2 27497 _003030_hash NULL
86836 +_003031_hash qib_diag_write 3 62133 _003031_hash NULL
86837 +_003032_hash qib_get_base_info 3 11369 _003032_hash NULL
86838 +_003033_hash qib_resize_cq 2 53090 _003033_hash NULL
86839 +_003034_hash qsfp_1_read 3 21915 _003034_hash NULL
86840 +_003035_hash qsfp_2_read 3 31491 _003035_hash NULL
86841 +_003036_hash queue_reply 3 22416 _003036_hash NULL
86842 +_003037_hash spidev_compat_ioctl 2 63778 _003037_hash NULL
86843 +_003038_hash split 2 11691 _003038_hash NULL
86844 +_003039_hash stats_read_ul 3 32751 _003039_hash NULL
86845 +_003040_hash sys32_ipc 3 7238 _003040_hash NULL
86846 +_003041_hash sys32_rt_sigpending 2 25814 _003041_hash NULL
86847 +_003042_hash tunables_read 3 36385 _003042_hash NULL
86848 +_003043_hash tunables_write 3 59563 _003043_hash NULL
86849 +_003044_hash xenbus_file_write 3 6282 _003044_hash NULL
86850 +_003045_hash xlbd_reserve_minors 1-2 18365 _003045_hash NULL
86851 +_003047_hash xpc_kmalloc_cacheline_aligned 1 42895 _003047_hash NULL
86852 +_003048_hash xpc_kzalloc_cacheline_aligned 1 65433 _003048_hash NULL
86853 +_003049_hash xsd_read 3 15653 _003049_hash NULL
86854 +_003050_hash compat_do_readv_writev 4 49102 _003050_hash NULL
86855 +_003051_hash compat_keyctl_instantiate_key_iov 3 57431 _003088_hash NULL nohasharray
86856 +_003052_hash compat_process_vm_rw 3-5 22254 _003052_hash NULL
86857 +_003054_hash compat_sys_select 1 16131 _003054_hash NULL
86858 +_003055_hash compat_sys_setsockopt 5 3326 _003055_hash NULL
86859 +_003056_hash compat_udp_setsockopt 5 38840 _003056_hash NULL
86860 +_003057_hash compat_udpv6_setsockopt 5 42981 _003057_hash NULL
86861 +_003058_hash do_compat_pselect 1 10398 _003058_hash NULL
86862 +_003059_hash gnttab_expand 1 15817 _003059_hash NULL
86863 +_003060_hash ipath_cdev_init 1 37752 _003060_hash NULL
86864 +_003061_hash ipath_reg_phys_mr 3 23918 _003061_hash &_000999_hash
86865 +_003062_hash qib_alloc_fast_reg_mr 2 12526 _003062_hash NULL
86866 +_003063_hash qib_reg_phys_mr 3 60202 _003063_hash &_000897_hash
86867 +_003064_hash compat_readv 3 30273 _003064_hash NULL
86868 +_003065_hash compat_sys_process_vm_readv 3-5 15374 _003065_hash NULL
86869 +_003067_hash compat_sys_process_vm_writev 3-5 41194 _003067_hash NULL
86870 +_003069_hash compat_sys_pselect6 1 14105 _003069_hash NULL
86871 +_003070_hash compat_writev 3 60063 _003070_hash NULL
86872 +_003071_hash get_free_entries 1 46030 _003071_hash NULL
86873 +_003072_hash compat_sys_preadv64 3 24283 _003072_hash NULL
86874 +_003073_hash compat_sys_pwritev64 3 51151 _003073_hash NULL
86875 +_003074_hash compat_sys_readv 3 20911 _003074_hash NULL
86876 +_003075_hash compat_sys_writev 3 5784 _003075_hash NULL
86877 +_003076_hash gnttab_alloc_grant_references 1 18240 _003076_hash NULL
86878 +_003077_hash compat_sys_preadv 3 583 _003077_hash NULL
86879 +_003078_hash compat_sys_pwritev 3 17886 _003078_hash NULL
86880 +_003079_hash aes_decrypt_fail_read 3 54815 _003079_hash NULL
86881 +_003080_hash aes_decrypt_interrupt_read 3 19910 _003080_hash NULL
86882 +_003081_hash aes_decrypt_packets_read 3 10155 _003081_hash NULL
86883 +_003082_hash aes_encrypt_fail_read 3 32562 _003082_hash NULL
86884 +_003083_hash aes_encrypt_interrupt_read 3 39919 _003083_hash NULL
86885 +_003084_hash aes_encrypt_packets_read 3 48666 _003084_hash NULL
86886 +_003085_hash agp_remap 2 30665 _003085_hash NULL
86887 +_003086_hash alloc_apertures 1 56561 _003086_hash NULL
86888 +_003087_hash allocate_probes 1 40204 _003087_hash NULL
86889 +_003088_hash alloc_ftrace_hash 1 57431 _003088_hash &_003051_hash
86890 +_003089_hash alloc_page_cgroup 1 2919 _003089_hash NULL
86891 +_003090_hash __alloc_preds 2 9492 _003090_hash NULL
86892 +_003091_hash __alloc_pred_stack 2 26687 _003091_hash NULL
86893 +_003092_hash alloc_sched_domains 1 47756 _003092_hash NULL
86894 +_003093_hash alloc_trace_probe 6 38720 _003093_hash NULL
86895 +_003094_hash alloc_trace_uprobe 3 13870 _003094_hash &_002976_hash
86896 +_003095_hash ath6kl_sdio_alloc_prep_scat_req 2 51986 _003095_hash NULL
86897 +_003096_hash ath6kl_usb_post_recv_transfers 2 32892 _003096_hash NULL
86898 +_003097_hash ath6kl_usb_submit_ctrl_in 6 32880 _003097_hash &_000795_hash
86899 +_003098_hash ath6kl_usb_submit_ctrl_out 6 9978 _003098_hash NULL
86900 +_003099_hash av7110_ipack_init 2 46655 _003099_hash NULL
86901 +_003100_hash av7110_vbi_write 3 34384 _003100_hash NULL
86902 +_003101_hash bin_uuid 3 28999 _003101_hash NULL
86903 +_003102_hash blk_dropped_read 3 4168 _003102_hash NULL
86904 +_003103_hash blk_msg_write 3 13655 _003103_hash NULL
86905 +_003104_hash brcmf_usbdev_qinit 2 19090 _003104_hash &_001715_hash
86906 +_003105_hash brcmf_usb_dl_cmd 4 53130 _003105_hash NULL
86907 +_003106_hash ci_ll_init 3 12930 _003106_hash NULL
86908 +_003107_hash ci_ll_write 4 3740 _003107_hash NULL
86909 +_003108_hash conf_read 3 55786 _003108_hash NULL
86910 +_003109_hash __copy_from_user_inatomic_nocache 3 49921 _003109_hash NULL
86911 +_003110_hash cx24116_writeregN 4 41975 _003110_hash NULL
86912 +_003111_hash cyttsp_probe 4 1940 _003111_hash NULL
86913 +_003112_hash dccpprobe_read 3 52549 _003112_hash NULL
86914 +_003113_hash ddb_input_read 3 9743 _003113_hash NULL
86915 +_003114_hash ddb_output_write 3 31902 _003114_hash NULL
86916 +_003115_hash __devres_alloc 2 25598 _003115_hash NULL
86917 +_003116_hash dma_rx_errors_read 3 52045 _003116_hash NULL
86918 +_003117_hash dma_rx_requested_read 3 65354 _003117_hash NULL
86919 +_003118_hash dma_tx_errors_read 3 46060 _003118_hash NULL
86920 +_003119_hash dma_tx_requested_read 3 16110 _003203_hash NULL nohasharray
86921 +_003120_hash do_dmabuf_dirty_sou 7 3017 _003120_hash NULL
86922 +_003121_hash do_surface_dirty_sou 7 39678 _003121_hash NULL
86923 +_003122_hash driver_state_read 3 17194 _003122_hash &_001511_hash
86924 +_003123_hash drm_agp_bind_pages 3 56748 _003123_hash NULL
86925 +_003124_hash drm_buffer_alloc 2 44405 _003124_hash NULL
86926 +_003125_hash drm_calloc_large 1-2 65421 _003125_hash NULL
86927 +_003127_hash drm_fb_helper_init 3-4 19044 _003127_hash NULL
86928 +_003129_hash drm_ht_create 2 18853 _003129_hash NULL
86929 +_003130_hash drm_ioctl 2 42813 _003130_hash NULL
86930 +_003131_hash drm_malloc_ab 1-2 16831 _003131_hash NULL
86931 +_003133_hash drm_mode_crtc_set_gamma_size 2 31881 _003133_hash NULL
86932 +_003134_hash drm_plane_init 6 28731 _003134_hash NULL
86933 +_003135_hash drm_property_create 4 51239 _003135_hash NULL
86934 +_003136_hash drm_property_create_blob 2 7414 _003136_hash NULL
86935 +_003137_hash drm_vblank_init 2 11362 _003137_hash NULL
86936 +_003138_hash drm_vmalloc_dma 1 14550 _003138_hash NULL
86937 +_003139_hash dvb_aplay 3 56296 _003139_hash NULL
86938 +_003140_hash dvb_ca_en50221_init 4 45718 _003140_hash NULL
86939 +_003141_hash dvb_ca_en50221_io_write 3 43533 _003141_hash NULL
86940 +_003142_hash dvb_dmxdev_set_buffer_size 2 55643 _003142_hash NULL
86941 +_003143_hash dvbdmx_write 3 19423 _003143_hash NULL
86942 +_003144_hash dvb_dvr_set_buffer_size 2 9840 _003144_hash NULL
86943 +_003145_hash dvb_net_sec 3 37884 _003145_hash NULL
86944 +_003146_hash dvb_play 3 50814 _003146_hash NULL
86945 +_003147_hash dvb_ringbuffer_pkt_read_user 2-5-3 4303 _003147_hash NULL
86946 +_003150_hash dvb_ringbuffer_read_user 3 56702 _003150_hash NULL
86947 +_003151_hash dvb_usercopy 2 14036 _003151_hash NULL
86948 +_003152_hash dw210x_op_rw 6 39915 _003152_hash NULL
86949 +_003153_hash edt_ft5x06_debugfs_raw_data_read 3 28002 _003153_hash NULL
86950 +_003154_hash em_canid_change 3 14150 _003154_hash NULL
86951 +_003155_hash event_calibration_read 3 21083 _003155_hash NULL
86952 +_003156_hash event_enable_read 3 7074 _003156_hash NULL
86953 +_003157_hash event_filter_read 3 23494 _003157_hash NULL
86954 +_003158_hash event_filter_write 3 56609 _003158_hash NULL
86955 +_003159_hash event_heart_beat_read 3 48961 _003159_hash NULL
86956 +_003160_hash event_id_read 3 64288 _003160_hash &_001300_hash
86957 +_003161_hash event_oom_late_read 3 61175 _003161_hash &_001054_hash
86958 +_003162_hash event_phy_transmit_error_read 3 10471 _003162_hash NULL
86959 +_003163_hash event_rx_mem_empty_read 3 40363 _003163_hash NULL
86960 +_003164_hash event_rx_mismatch_read 3 38518 _003164_hash NULL
86961 +_003165_hash event_rx_pool_read 3 25792 _003165_hash NULL
86962 +_003166_hash event_tx_stuck_read 3 19305 _003166_hash NULL
86963 +_003167_hash excessive_retries_read 3 60425 _003167_hash NULL
86964 +_003168_hash flexcop_device_kmalloc 1 54793 _003168_hash NULL
86965 +_003169_hash fm_send_cmd 5 39639 _003169_hash NULL
86966 +_003170_hash __fprog_create 2 41263 _003170_hash NULL
86967 +_003171_hash fq_codel_zalloc 1 15378 _003171_hash NULL
86968 +_003172_hash ftrace_pid_write 3 39710 _003172_hash NULL
86969 +_003173_hash ftrace_profile_read 3 21327 _003173_hash NULL
86970 +_003174_hash fw_stats_raw_read 3 1369 _003174_hash NULL
86971 +_003175_hash get_info 3 55681 _003175_hash NULL
86972 +_003176_hash __get_vm_area_node 1 55305 _003176_hash NULL
86973 +_003177_hash gpio_power_read 3 36059 _003177_hash NULL
86974 +_003178_hash h5_prepare_pkt 4 12085 _003178_hash NULL
86975 +_003179_hash hsc_msg_alloc 1 60990 _003179_hash NULL
86976 +_003180_hash hsc_write 3 55875 _003180_hash NULL
86977 +_003181_hash hsi_alloc_controller 1 41802 _003181_hash NULL
86978 +_003182_hash hsi_register_board_info 2 13820 _003182_hash NULL
86979 +_003183_hash hugetlb_cgroup_read 5 49259 _003183_hash NULL
86980 +_003184_hash i915_cache_sharing_read 3 24775 _003184_hash NULL
86981 +_003185_hash i915_cache_sharing_write 3 57961 _003185_hash NULL
86982 +_003186_hash i915_max_freq_read 3 20581 _003186_hash NULL
86983 +_003187_hash i915_max_freq_write 3 11350 _003187_hash NULL
86984 +_003188_hash i915_min_freq_read 3 38470 _003188_hash NULL
86985 +_003189_hash i915_min_freq_write 3 10981 _003189_hash NULL
86986 +_003190_hash i915_ring_stop_read 3 42549 _003190_hash &_000740_hash
86987 +_003191_hash i915_ring_stop_write 3 59010 _003191_hash NULL
86988 +_003192_hash i915_wedged_read 3 35474 _003192_hash NULL
86989 +_003193_hash i915_wedged_write 3 47771 _003193_hash NULL
86990 +_003194_hash ieee802154_alloc_device 1 13767 _003194_hash NULL
86991 +_003195_hash intel_sdvo_write_cmd 4 54377 _003195_hash &_000832_hash
86992 +_003196_hash isr_cmd_cmplt_read 3 53439 _003196_hash NULL
86993 +_003197_hash isr_commands_read 3 41398 _003197_hash NULL
86994 +_003198_hash isr_decrypt_done_read 3 49490 _003198_hash NULL
86995 +_003199_hash isr_dma0_done_read 3 8574 _003199_hash NULL
86996 +_003200_hash isr_dma1_done_read 3 48159 _003200_hash NULL
86997 +_003201_hash isr_fiqs_read 3 34687 _003201_hash NULL
86998 +_003202_hash isr_host_acknowledges_read 3 54136 _003202_hash NULL
86999 +_003203_hash isr_hw_pm_mode_changes_read 3 16110 _003203_hash &_003119_hash
87000 +_003204_hash isr_irqs_read 3 9181 _003204_hash NULL
87001 +_003205_hash isr_low_rssi_read 3 64789 _003205_hash NULL
87002 +_003206_hash isr_pci_pm_read 3 30271 _003206_hash NULL
87003 +_003207_hash isr_rx_headers_read 3 38325 _003207_hash NULL
87004 +_003208_hash isr_rx_mem_overflow_read 3 43025 _003208_hash NULL
87005 +_003209_hash isr_rx_procs_read 3 31804 _003209_hash NULL
87006 +_003210_hash isr_rx_rdys_read 3 35283 _003210_hash NULL
87007 +_003211_hash isr_tx_exch_complete_read 3 16103 _003211_hash NULL
87008 +_003212_hash isr_tx_procs_read 3 23084 _003212_hash NULL
87009 +_003213_hash isr_wakeups_read 3 49607 _003213_hash NULL
87010 +_003214_hash LoadBitmap 2 19658 _003214_hash NULL
87011 +_003215_hash mem_cgroup_read 5 22461 _003215_hash NULL
87012 +_003216_hash mic_calc_failure_read 3 59700 _003216_hash NULL
87013 +_003217_hash mic_rx_pkts_read 3 27972 _003217_hash NULL
87014 +_003218_hash __module_alloc 1 50004 _003218_hash NULL
87015 +_003219_hash module_alloc_update_bounds_rw 1 63233 _003219_hash NULL
87016 +_003220_hash module_alloc_update_bounds_rx 1 58634 _003220_hash NULL
87017 +_003221_hash mwifiex_usb_submit_rx_urb 2 54558 _003221_hash NULL
87018 +_003222_hash nfc_hci_hcp_message_tx 6 14534 _003222_hash NULL
87019 +_003223_hash nfc_hci_set_param 5 40697 _003223_hash NULL
87020 +_003224_hash nfc_shdlc_alloc_skb 2 12741 _003224_hash NULL
87021 +_003225_hash opera1_xilinx_rw 5 31453 _003225_hash NULL
87022 +_003226_hash persistent_ram_vmap 1-2 709 _003226_hash NULL
87023 +_003228_hash prctl_set_mm 3 64538 _003228_hash NULL
87024 +_003229_hash probe_kernel_write 3 17481 _003229_hash NULL
87025 +_003230_hash proc_fault_inject_read 3 36802 _003230_hash NULL
87026 +_003231_hash proc_fault_inject_write 3 21058 _003231_hash NULL
87027 +_003232_hash ps_pspoll_max_apturn_read 3 6699 _003232_hash NULL
87028 +_003233_hash ps_pspoll_timeouts_read 3 11776 _003233_hash NULL
87029 +_003234_hash ps_pspoll_utilization_read 3 5361 _003234_hash NULL
87030 +_003235_hash ps_upsd_max_apturn_read 3 19918 _003235_hash NULL
87031 +_003236_hash ps_upsd_max_sptime_read 3 63362 _003236_hash NULL
87032 +_003237_hash ps_upsd_timeouts_read 3 28924 _003237_hash NULL
87033 +_003238_hash ps_upsd_utilization_read 3 51669 _003238_hash NULL
87034 +_003239_hash ptp_filter_init 2 36780 _003239_hash NULL
87035 +_003240_hash pwr_disable_ps_read 3 13176 _003240_hash NULL
87036 +_003241_hash pwr_elp_enter_read 3 5324 _003241_hash NULL
87037 +_003242_hash pwr_enable_ps_read 3 17686 _003242_hash NULL
87038 +_003243_hash pwr_fix_tsf_ps_read 3 26627 _003243_hash NULL
87039 +_003244_hash pwr_missing_bcns_read 3 25824 _003244_hash NULL
87040 +_003245_hash pwr_power_save_off_read 3 18355 _003245_hash NULL
87041 +_003246_hash pwr_ps_enter_read 3 26935 _003246_hash &_000512_hash
87042 +_003247_hash pwr_rcvd_awake_beacons_read 3 50505 _003247_hash NULL
87043 +_003248_hash pwr_rcvd_beacons_read 3 52836 _003248_hash NULL
87044 +_003249_hash pwr_tx_without_ps_read 3 48423 _003249_hash NULL
87045 +_003250_hash pwr_tx_with_ps_read 3 60851 _003250_hash NULL
87046 +_003251_hash pwr_wake_on_host_read 3 26321 _003251_hash NULL
87047 +_003252_hash pwr_wake_on_timer_exp_read 3 22640 _003252_hash NULL
87048 +_003253_hash rb_simple_read 3 45972 _003253_hash NULL
87049 +_003254_hash read_file_dfs 3 43145 _003254_hash NULL
87050 +_003255_hash retry_count_read 3 52129 _003255_hash NULL
87051 +_003256_hash rx_dropped_read 3 44799 _003256_hash NULL
87052 +_003257_hash rx_fcs_err_read 3 62844 _003257_hash NULL
87053 +_003258_hash rx_hdr_overflow_read 3 64407 _003258_hash NULL
87054 +_003259_hash rx_hw_stuck_read 3 57179 _003259_hash NULL
87055 +_003260_hash rx_out_of_mem_read 3 10157 _003260_hash NULL
87056 +_003261_hash rx_path_reset_read 3 23801 _003261_hash NULL
87057 +_003262_hash rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 _003262_hash NULL
87058 +_003263_hash rxpipe_descr_host_int_trig_rx_data_read 3 22001 _003263_hash &_002981_hash
87059 +_003264_hash rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 _003264_hash NULL
87060 +_003265_hash rxpipe_rx_prep_beacon_drop_read 3 2403 _003265_hash NULL
87061 +_003266_hash rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 _003266_hash NULL
87062 +_003267_hash rx_reset_counter_read 3 58001 _003267_hash NULL
87063 +_003268_hash rx_xfr_hint_trig_read 3 40283 _003268_hash NULL
87064 +_003269_hash saa7146_vmalloc_build_pgtable 2 19780 _003269_hash NULL
87065 +_003270_hash sched_feat_write 3 55202 _003270_hash NULL
87066 +_003271_hash sd_alloc_ctl_entry 1 29708 _003271_hash NULL
87067 +_003272_hash shmem_pread_fast 3 34147 _003272_hash NULL
87068 +_003273_hash shmem_pread_slow 3 3198 _003273_hash NULL
87069 +_003274_hash shmem_pwrite_slow 3 31741 _003274_hash NULL
87070 +_003275_hash show_header 3 4722 _003275_hash &_000745_hash
87071 +_003276_hash stack_max_size_read 3 1445 _003276_hash NULL
87072 +_003277_hash subsystem_filter_read 3 62310 _003277_hash NULL
87073 +_003278_hash subsystem_filter_write 3 13022 _003278_hash NULL
87074 +_003279_hash swap_cgroup_swapon 2 13614 _003279_hash NULL
87075 +_003280_hash system_enable_read 3 25815 _003280_hash NULL
87076 +_003281_hash tda10048_writeregbulk 4 11050 _003281_hash NULL
87077 +_003282_hash tlbflush_read_file 3 64661 _003282_hash NULL
87078 +_003283_hash trace_options_core_read 3 47390 _003283_hash NULL
87079 +_003284_hash trace_options_read 3 11419 _003284_hash NULL
87080 +_003285_hash trace_parser_get_init 2 31379 _003285_hash NULL
87081 +_003286_hash traceprobe_probes_write 3 64969 _003286_hash NULL
87082 +_003287_hash trace_seq_to_user 3 65398 _003287_hash NULL
87083 +_003288_hash tracing_buffers_read 3 11124 _003288_hash NULL
87084 +_003289_hash tracing_clock_write 3 27961 _003289_hash NULL
87085 +_003290_hash tracing_cpumask_read 3 7010 _003290_hash NULL
87086 +_003291_hash tracing_ctrl_read 3 46922 _003291_hash NULL
87087 +_003292_hash tracing_entries_read 3 8345 _003292_hash NULL
87088 +_003293_hash tracing_max_lat_read 3 8890 _003293_hash NULL
87089 +_003294_hash tracing_read_dyn_info 3 45468 _003294_hash NULL
87090 +_003295_hash tracing_readme_read 3 16493 _003295_hash NULL
87091 +_003296_hash tracing_saved_cmdlines_read 3 21434 _003296_hash NULL
87092 +_003297_hash tracing_set_trace_read 3 44122 _003297_hash NULL
87093 +_003298_hash tracing_set_trace_write 3 57096 _003298_hash NULL
87094 +_003299_hash tracing_stats_read 3 34537 _003299_hash NULL
87095 +_003300_hash tracing_total_entries_read 3 62817 _003300_hash NULL
87096 +_003301_hash tracing_trace_options_write 3 153 _003301_hash NULL
87097 +_003302_hash tstats_write 3 60432 _003302_hash &_000009_hash
87098 +_003303_hash ttm_bo_fbdev_io 4 9805 _003303_hash NULL
87099 +_003304_hash ttm_bo_io 5 47000 _003304_hash NULL
87100 +_003305_hash ttm_dma_page_pool_free 2 34135 _003305_hash NULL
87101 +_003306_hash ttm_page_pool_free 2 61661 _003306_hash NULL
87102 +_003307_hash ttusb2_msg 4 3100 _003307_hash NULL
87103 +_003308_hash tx_internal_desc_overflow_read 3 47300 _003308_hash NULL
87104 +_003309_hash tx_queue_len_read 3 1463 _003309_hash NULL
87105 +_003310_hash tx_queue_status_read 3 44978 _003310_hash NULL
87106 +_003311_hash u_memcpya 2-3 30139 _003311_hash NULL
87107 +_003313_hash usb_allocate_stream_buffers 3 8964 _003313_hash NULL
87108 +_003314_hash vifs_state_read 3 33762 _003314_hash NULL
87109 +_003315_hash vmalloc_to_sg 2 58354 _003315_hash NULL
87110 +_003316_hash vm_map_ram 2 23078 _003316_hash &_001095_hash
87111 +_003317_hash vmw_execbuf_process 5 22885 _003317_hash NULL
87112 +_003318_hash vmw_fifo_reserve 2 12141 _003318_hash NULL
87113 +_003319_hash vmw_kms_present 9 38130 _003319_hash NULL
87114 +_003320_hash vmw_kms_readback 6 5727 _003320_hash NULL
87115 +_003321_hash wep_addr_key_count_read 3 20174 _003321_hash NULL
87116 +_003322_hash wep_decrypt_fail_read 3 58567 _003322_hash NULL
87117 +_003323_hash wep_default_key_count_read 3 43035 _003323_hash NULL
87118 +_003324_hash wep_interrupt_read 3 41492 _003324_hash NULL
87119 +_003325_hash wep_key_not_found_read 3 13377 _003325_hash &_000952_hash
87120 +_003326_hash wep_packets_read 3 18751 _003326_hash NULL
87121 +_003327_hash wl1251_cmd_template_set 4 6172 _003327_hash NULL
87122 +_003328_hash wl1271_format_buffer 2 20834 _003328_hash NULL
87123 +_003329_hash wl1271_rx_filter_alloc_field 5 46721 _003329_hash NULL
87124 +_003330_hash wl12xx_cmd_build_probe_req 6-8 54946 _003330_hash NULL
87125 +_003332_hash wlcore_alloc_hw 1 7785 _003332_hash NULL
87126 +_003333_hash aggr_size_rx_size_read 3 33526 _003333_hash NULL
87127 +_003334_hash aggr_size_tx_agg_vs_rate_read 3 21438 _003334_hash NULL
87128 +_003335_hash alloc_and_copy_ftrace_hash 1 29368 _003335_hash NULL
87129 +_003336_hash alloc_bulk_urbs_generic 5 12127 _003336_hash NULL
87130 +_003337_hash alloc_ieee80211 1 20063 _003337_hash NULL
87131 +_003338_hash alloc_ieee80211_rsl 1 34564 _003338_hash NULL
87132 +_003339_hash alloc_perm_bits 2 1532 _003339_hash NULL
87133 +_003340_hash alloc_private 2 22399 _003340_hash NULL
87134 +_003341_hash alloc_rtllib 1 51136 _003341_hash NULL
87135 +_003342_hash alloc_rx_desc_ring 2 18016 _003342_hash NULL
87136 +_003343_hash arcfb_write 3 8702 _003343_hash NULL
87137 +_003344_hash ath6kl_usb_bmi_read 3 48745 _003344_hash NULL
87138 +_003345_hash ath6kl_usb_bmi_write 3 2454 _003345_hash &_001020_hash
87139 +_003346_hash ath6kl_usb_ctrl_msg_exchange 4 33327 _003346_hash NULL
87140 +_003347_hash au0828_init_isoc 2-3 61917 _003347_hash NULL
87141 +_003349_hash auok190xfb_write 3 37001 _003349_hash NULL
87142 +_003350_hash beacon_interval_read 3 7091 _003350_hash NULL
87143 +_003351_hash brcmf_usb_attach 1-2 44656 _003351_hash NULL
87144 +_003353_hash broadsheetfb_write 3 39976 _003353_hash NULL
87145 +_003354_hash broadsheet_spiflash_rewrite_sector 2 54864 _003354_hash NULL
87146 +_003355_hash ci13xxx_add_device 3 14456 _003355_hash NULL
87147 +_003356_hash cmpk_message_handle_tx 4 54024 _003356_hash NULL
87148 +_003357_hash comedi_alloc_subdevices 2 29207 _003357_hash NULL
87149 +_003358_hash comedi_buf_alloc 3 24822 _003358_hash NULL
87150 +_003359_hash comedi_read 3 13199 _003359_hash NULL
87151 +_003360_hash comedi_write 3 47926 _003360_hash NULL
87152 +_003361_hash create_trace_probe 1 20175 _003361_hash NULL
87153 +_003362_hash create_trace_uprobe 1 13184 _003362_hash NULL
87154 +_003363_hash cx18_copy_buf_to_user 4 22735 _003363_hash NULL
87155 +_003364_hash cx231xx_init_bulk 2-3 47024 _003364_hash NULL
87156 +_003366_hash cx231xx_init_isoc 2-3 56453 _003366_hash NULL
87157 +_003368_hash cx231xx_init_vbi_isoc 2-3 28053 _003368_hash NULL
87158 +_003370_hash da9052_group_write 3 4534 _003370_hash NULL
87159 +_003371_hash debug_debug1_read 3 8856 _003371_hash NULL
87160 +_003372_hash debug_debug2_read 3 30526 _003372_hash NULL
87161 +_003373_hash debug_debug3_read 3 56894 _003373_hash NULL
87162 +_003374_hash debug_debug4_read 3 61367 _003374_hash NULL
87163 +_003375_hash debug_debug5_read 3 2291 _003375_hash NULL
87164 +_003376_hash debug_debug6_read 3 33168 _003376_hash NULL
87165 +_003377_hash dev_read 3 56369 _003377_hash NULL
87166 +_003378_hash do_dmabuf_dirty_ldu 6 52241 _003378_hash NULL
87167 +_003379_hash drm_compat_ioctl 2 51717 _003379_hash NULL
87168 +_003380_hash drm_mode_create_tv_properties 2 23122 _003380_hash NULL
87169 +_003381_hash drm_property_create_bitmask 5 30195 _003381_hash NULL
87170 +_003382_hash drm_property_create_enum 5 29201 _003382_hash NULL
87171 +_003383_hash dsp_buffer_alloc 2 11684 _003383_hash NULL
87172 +_003384_hash dt3155_alloc_coherent 2 58073 _003384_hash NULL
87173 +_003385_hash dtim_interval_read 3 654 _003385_hash NULL
87174 +_003386_hash dvb_audio_write 3 51275 _003386_hash NULL
87175 +_003387_hash dvb_ca_en50221_io_ioctl 2 26490 _003387_hash NULL
87176 +_003388_hash dvb_ca_write 3 41171 _003388_hash NULL
87177 +_003389_hash dvb_demux_ioctl 2 42733 _003389_hash NULL
87178 +_003390_hash dvb_dmxdev_buffer_read 4 20682 _003390_hash NULL
87179 +_003391_hash dvb_dvr_ioctl 2 49182 _003391_hash NULL
87180 +_003392_hash dvb_generic_ioctl 2 21810 _003392_hash NULL
87181 +_003393_hash dvb_net_ioctl 2 61559 _003393_hash NULL
87182 +_003394_hash dvb_net_sec_callback 2 28786 _003394_hash NULL
87183 +_003396_hash dvb_video_write 3 754 _003396_hash NULL
87184 +_003397_hash dynamic_ps_timeout_read 3 10110 _003397_hash NULL
87185 +_003398_hash easycap_alsa_vmalloc 2 14426 _003398_hash NULL
87186 +_003399_hash em28xx_alloc_isoc 4 46892 _003399_hash NULL
87187 +_003400_hash error_error_bar_retry_read 3 64305 _003400_hash NULL
87188 +_003401_hash error_error_frame_cts_nul_flid_read 3 17262 _003401_hash NULL
87189 +_003402_hash error_error_frame_read 3 39947 _003402_hash &_002436_hash
87190 +_003403_hash error_error_null_Frame_tx_start_read 3 55024 _003403_hash NULL
87191 +_003404_hash error_error_numll_frame_cts_start_read 3 47781 _003404_hash NULL
87192 +_003405_hash ext_sd_execute_read_data 9 48589 _003405_hash NULL
87193 +_003406_hash ext_sd_execute_write_data 9 8175 _003406_hash NULL
87194 +_003407_hash fast_user_write 5 20494 _003407_hash NULL
87195 +_003408_hash f_audio_buffer_alloc 1 41110 _003408_hash NULL
87196 +_003409_hash fb_alloc_cmap_gfp 2 20792 _003409_hash NULL
87197 +_003410_hash fbcon_do_set_font 2-3 4079 _003410_hash NULL
87198 +_003412_hash fb_read 3 33506 _003412_hash NULL
87199 +_003413_hash fb_sys_read 3 13778 _003413_hash NULL
87200 +_003414_hash fb_sys_write 3 33130 _003414_hash NULL
87201 +_003415_hash fb_write 3 46924 _003415_hash NULL
87202 +_003416_hash firmwareUpload 3 32794 _003416_hash NULL
87203 +_003417_hash fmc_send_cmd 5 20435 _003417_hash NULL
87204 +_003418_hash fops_read 3 40672 _003418_hash NULL
87205 +_003419_hash forced_ps_read 3 31685 _003419_hash NULL
87206 +_003420_hash frame_alloc 4 15981 _003420_hash NULL
87207 +_003421_hash framebuffer_alloc 1 59145 _003421_hash NULL
87208 +_003422_hash ftrace_write 3 29551 _003422_hash NULL
87209 +_003423_hash fw_download_code 3 13249 _003423_hash NULL
87210 +_003424_hash fwSendNullPacket 2 54618 _003424_hash NULL
87211 +_003425_hash gdm_wimax_netif_rx 3 43423 _003425_hash &_001810_hash
87212 +_003426_hash get_vm_area 1 18080 _003426_hash NULL
87213 +_003427_hash __get_vm_area 1 61599 _003427_hash NULL
87214 +_003428_hash get_vm_area_caller 1 10527 _003428_hash NULL
87215 +_003429_hash __get_vm_area_caller 1 56416 _003828_hash NULL nohasharray
87216 +_003430_hash gspca_dev_probe2 4 59833 _003430_hash NULL
87217 +_003431_hash hdpvr_read 3 9273 _003431_hash NULL
87218 +_003432_hash hecubafb_write 3 26942 _003432_hash NULL
87219 +_003433_hash i915_compat_ioctl 2 3656 _003433_hash NULL
87220 +_003434_hash i915_gem_execbuffer_relocate_slow 7 25355 _003434_hash NULL
87221 +_003435_hash ieee80211_alloc_txb 1-2 52477 _003435_hash NULL
87222 +_003437_hash ieee80211_authentication_req 3 63973 _003437_hash NULL
87223 +_003438_hash ieee80211_wx_set_gen_ie 3 51399 _003438_hash NULL
87224 +_003439_hash ieee80211_wx_set_gen_ie_rsl 3 3521 _003458_hash NULL nohasharray
87225 +_003440_hash intel_sdvo_set_value 4 2311 _003440_hash NULL
87226 +_003441_hash ir_lirc_transmit_ir 3 64403 _003441_hash NULL
87227 +_003442_hash irq_blk_threshold_read 3 33666 _003442_hash NULL
87228 +_003443_hash irq_pkt_threshold_read 3 33356 _003443_hash &_000154_hash
87229 +_003444_hash irq_timeout_read 3 54653 _003444_hash NULL
87230 +_003445_hash ivtv_buf_copy_from_user 4 25502 _003445_hash NULL
87231 +_003446_hash ivtv_copy_buf_to_user 4 6159 _003446_hash NULL
87232 +_003447_hash ivtvfb_write 3 40023 _003447_hash NULL
87233 +_003448_hash kgdb_hex2mem 3 24755 _003448_hash NULL
87234 +_003449_hash lirc_buffer_init 2-3 53282 _003449_hash NULL
87235 +_003451_hash lirc_write 3 20604 _003451_hash NULL
87236 +_003452_hash mce_request_packet 3 1073 _003452_hash NULL
87237 +_003453_hash media_entity_init 2-4 15870 _003453_hash &_001742_hash
87238 +_003455_hash mem_fw_gen_free_mem_blks_read 3 11413 _003455_hash NULL
87239 +_003456_hash mem_fwlog_free_mem_blks_read 3 59616 _003456_hash NULL
87240 +_003457_hash mem_rx_free_mem_blks_read 3 675 _003457_hash NULL
87241 +_003458_hash mem_tx_free_mem_blks_read 3 3521 _003458_hash &_003439_hash
87242 +_003459_hash metronomefb_write 3 8823 _003459_hash NULL
87243 +_003460_hash mga_compat_ioctl 2 52170 _003460_hash NULL
87244 +_003461_hash mmio_read 4 40348 _003461_hash NULL
87245 +_003462_hash netlink_send 5 38434 _003462_hash NULL
87246 +_003463_hash nfc_hci_execute_cmd 5 43882 _003463_hash NULL
87247 +_003464_hash nfc_hci_send_event 5 21452 _003464_hash NULL
87248 +_003465_hash nfc_hci_send_response 5 56462 _003465_hash NULL
87249 +_003466_hash ni_gpct_device_construct 5 610 _003466_hash NULL
87250 +_003467_hash nouveau_compat_ioctl 2 28305 _003467_hash NULL
87251 +_003468_hash odev_update 2 50169 _003468_hash NULL
87252 +_003469_hash opera1_usb_i2c_msgxfer 4 64521 _003469_hash NULL
87253 +_003470_hash OSDSetBlock 2-4 38986 _003470_hash NULL
87254 +_003472_hash oz_add_farewell 5 20652 _003472_hash NULL
87255 +_003473_hash oz_cdev_read 3 20659 _003473_hash NULL
87256 +_003474_hash oz_cdev_write 3 33852 _003474_hash NULL
87257 +_003475_hash oz_ep_alloc 2 5587 _003475_hash NULL
87258 +_003476_hash oz_events_read 3 47535 _003476_hash NULL
87259 +_003477_hash persistent_ram_buffer_map 1-2 11332 _003477_hash NULL
87260 +_003479_hash pipeline_cs_rx_packet_in_read 3 37089 _003479_hash NULL
87261 +_003480_hash pipeline_cs_rx_packet_out_read 3 58926 _003480_hash NULL
87262 +_003481_hash pipeline_csum_to_rx_xfer_swi_read 3 15403 _003481_hash NULL
87263 +_003482_hash pipeline_dec_packet_in_fifo_full_read 3 33052 _003482_hash NULL
87264 +_003483_hash pipeline_dec_packet_in_read 3 47076 _003483_hash NULL
87265 +_003484_hash pipeline_dec_packet_out_read 3 54052 _003484_hash NULL
87266 +_003485_hash pipeline_defrag_to_csum_swi_read 3 63037 _003485_hash NULL
87267 +_003486_hash pipeline_enc_rx_stat_fifo_int_read 3 7107 _003486_hash NULL
87268 +_003487_hash pipeline_enc_tx_stat_fifo_int_read 3 14680 _003487_hash NULL
87269 +_003488_hash pipeline_hs_tx_stat_fifo_int_read 3 15642 _003488_hash &_001260_hash
87270 +_003489_hash pipeline_pipeline_fifo_full_read 3 34095 _003489_hash NULL
87271 +_003490_hash pipeline_post_proc_swi_read 3 24108 _003490_hash NULL
87272 +_003491_hash pipeline_pre_proc_swi_read 3 3898 _003491_hash NULL
87273 +_003492_hash pipeline_pre_to_defrag_swi_read 3 56321 _003492_hash NULL
87274 +_003493_hash pipeline_rx_complete_stat_fifo_int_read 3 40671 _003493_hash NULL
87275 +_003494_hash pipeline_sec_frag_swi_read 3 30294 _003494_hash NULL
87276 +_003495_hash pipeline_tcp_rx_stat_fifo_int_read 3 26745 _003495_hash NULL
87277 +_003496_hash pipeline_tcp_tx_stat_fifo_int_read 3 32589 _003496_hash NULL
87278 +_003497_hash play_iframe 3 8219 _003497_hash NULL
87279 +_003498_hash probes_write 3 29711 _003498_hash NULL
87280 +_003499_hash psb_unlocked_ioctl 2 16926 _003499_hash &_002668_hash
87281 +_003500_hash ps_poll_ps_poll_max_ap_turn_read 3 53140 _003500_hash NULL
87282 +_003501_hash ps_poll_ps_poll_timeouts_read 3 5934 _003501_hash NULL
87283 +_003502_hash ps_poll_ps_poll_utilization_read 3 39383 _003502_hash NULL
87284 +_003503_hash ps_poll_upsd_max_ap_turn_read 3 42050 _003503_hash NULL
87285 +_003504_hash ps_poll_upsd_timeouts_read 3 36755 _003504_hash NULL
87286 +_003505_hash ps_poll_upsd_utilization_read 3 28519 _003505_hash NULL
87287 +_003506_hash pvr2_ioread_read 3 10720 _003506_hash &_001669_hash
87288 +_003507_hash pvr2_ioread_set_sync_key 3 59882 _003507_hash NULL
87289 +_003508_hash pvr2_stream_buffer_count 2 33719 _003508_hash NULL
87290 +_003509_hash pwr_connection_out_of_sync_read 3 35061 _003509_hash NULL
87291 +_003510_hash pwr_cont_miss_bcns_spread_read 3 39250 _003515_hash NULL nohasharray
87292 +_003511_hash pwr_missing_bcns_cnt_read 3 45113 _003511_hash NULL
87293 +_003512_hash pwr_rcvd_awake_bcns_cnt_read 3 12632 _003512_hash NULL
87294 +_003513_hash pwr_rcvd_bcns_cnt_read 3 4774 _003513_hash NULL
87295 +_003514_hash qc_capture 3 19298 _003514_hash NULL
87296 +_003515_hash r128_compat_ioctl 2 39250 _003515_hash &_003510_hash
87297 +_003516_hash radeon_compat_ioctl 2 59150 _003516_hash NULL
87298 +_003517_hash radeon_kms_compat_ioctl 2 51371 _003517_hash NULL
87299 +_003518_hash Realloc 2 34961 _003518_hash NULL
87300 +_003519_hash redrat3_transmit_ir 3 64244 _003519_hash NULL
87301 +_003520_hash reg_w_buf 3 27724 _003520_hash NULL
87302 +_003521_hash reg_w_ixbuf 4 34736 _003521_hash NULL
87303 +_003522_hash rtllib_alloc_txb 1-2 21687 _003522_hash NULL
87304 +_003524_hash rtllib_authentication_req 3 26713 _003524_hash NULL
87305 +_003525_hash rtllib_wx_set_gen_ie 3 59808 _003525_hash NULL
87306 +_003526_hash rts51x_transfer_data_partial 6 5735 _003526_hash NULL
87307 +_003527_hash rvmalloc 1 46873 _003527_hash NULL
87308 +_003528_hash rx_decrypt_key_not_found_read 3 37820 _003528_hash NULL
87309 +_003529_hash rx_defrag_called_read 3 1897 _003529_hash NULL
87310 +_003530_hash rx_defrag_decrypt_failed_read 3 41411 _003530_hash NULL
87311 +_003531_hash rx_defrag_init_called_read 3 35935 _003531_hash NULL
87312 +_003532_hash rx_defrag_in_process_called_read 3 59338 _003532_hash NULL
87313 +_003533_hash rx_defrag_need_decrypt_read 3 42253 _003533_hash NULL
87314 +_003534_hash rx_defrag_need_defrag_read 3 28117 _003534_hash NULL
87315 +_003535_hash rx_defrag_tkip_called_read 3 21031 _003535_hash NULL
87316 +_003536_hash rx_filter_accum_arp_pend_requests_read 3 11003 _003536_hash NULL
87317 +_003537_hash rx_filter_arp_filter_read 3 61914 _003537_hash NULL
87318 +_003538_hash rx_filter_beacon_filter_read 3 49279 _003538_hash NULL
87319 +_003539_hash rx_filter_data_filter_read 3 30098 _003539_hash NULL
87320 +_003540_hash rx_filter_dup_filter_read 3 37238 _003540_hash NULL
87321 +_003541_hash rx_filter_ibss_filter_read 3 50167 _003541_hash NULL
87322 +_003542_hash rx_filter_max_arp_queue_dep_read 3 5851 _003542_hash NULL
87323 +_003543_hash rx_filter_mc_filter_read 3 25712 _003543_hash NULL
87324 +_003544_hash rx_filter_protection_filter_read 3 39282 _003544_hash NULL
87325 +_003545_hash rx_rate_rx_frames_per_rates_read 3 7282 _003545_hash NULL
87326 +_003546_hash rx_rx_beacon_early_term_read 3 21559 _003546_hash NULL
87327 +_003547_hash rx_rx_checksum_result_read 3 50617 _003547_hash NULL
87328 +_003548_hash rx_rx_cmplt_read 3 14753 _003548_hash NULL
87329 +_003549_hash rx_rx_cmplt_task_read 3 35226 _003549_hash NULL
87330 +_003550_hash rx_rx_defrag_end_read 3 505 _003550_hash NULL
87331 +_003551_hash rx_rx_defrag_read 3 2010 _003551_hash NULL
87332 +_003552_hash rx_rx_done_read 3 65217 _003552_hash NULL
87333 +_003553_hash rx_rx_dropped_frame_read 3 23748 _003553_hash NULL
87334 +_003554_hash rx_rx_frame_checksum_read 3 40140 _003554_hash NULL
87335 +_003555_hash rx_rx_hdr_overflow_read 3 35002 _003555_hash NULL
87336 +_003556_hash rx_rx_out_of_mpdu_nodes_read 3 64668 _003556_hash NULL
87337 +_003557_hash rx_rx_phy_hdr_read 3 20950 _003557_hash NULL
87338 +_003558_hash rx_rx_pre_complt_read 3 41653 _003558_hash NULL
87339 +_003559_hash rx_rx_timeout_read 3 62389 _003559_hash NULL
87340 +_003560_hash rx_rx_timeout_wa_read 3 50204 _003560_hash NULL
87341 +_003561_hash rx_rx_tkip_replays_read 3 60193 _003561_hash NULL
87342 +_003562_hash rx_rx_wa_ba_not_expected_read 3 61341 _003562_hash NULL
87343 +_003563_hash rx_rx_wa_density_dropped_frame_read 3 26095 _003563_hash NULL
87344 +_003564_hash rx_streaming_always_read 3 49401 _003564_hash NULL
87345 +_003565_hash rx_streaming_interval_read 3 55291 _003565_hash NULL
87346 +_003566_hash saa7164_buffer_alloc_user 2 9627 _003566_hash NULL
87347 +_003567_hash send_control_msg 6 48498 _003567_hash NULL
87348 +_003568_hash SendTxCommandPacket 3 42901 _003568_hash NULL
87349 +_003569_hash setup_window 2-7-5-4 59178 _003569_hash NULL
87350 +_003573_hash shmem_pwrite_fast 3 46842 _003573_hash NULL
87351 +_003574_hash sleep_auth_read 3 19159 _003574_hash NULL
87352 +_003575_hash sn9c102_read 3 29305 _003575_hash NULL
87353 +_003576_hash snd_pcm_alloc_vmalloc_buffer 2 44595 _003576_hash NULL
87354 +_003577_hash split_scan_timeout_read 3 20029 _003577_hash NULL
87355 +_003578_hash stk_prepare_sio_buffers 2 57168 _003578_hash NULL
87356 +_003579_hash store_debug_level 3 35652 _003579_hash NULL
87357 +_003580_hash suspend_dtim_interval_read 3 64971 _003580_hash NULL
87358 +_003581_hash sys_prctl 4 8766 _003581_hash NULL
87359 +_003582_hash tm6000_read_write_usb 7 50774 _003582_hash &_002149_hash
87360 +_003583_hash tracing_read_pipe 3 35312 _003583_hash NULL
87361 +_003584_hash ts_read 3 44687 _003584_hash NULL
87362 +_003585_hash ts_write 3 64336 _003585_hash NULL
87363 +_003586_hash tt3650_ci_msg 4 57219 _003586_hash NULL
87364 +_003587_hash ttm_object_device_init 2 10321 _003587_hash NULL
87365 +_003588_hash ttm_object_file_init 2 27804 _003588_hash NULL
87366 +_003589_hash tx_frag_bad_mblk_num_read 3 28064 _003589_hash NULL
87367 +_003590_hash tx_frag_cache_hit_read 3 29639 _003590_hash NULL
87368 +_003591_hash tx_frag_cache_miss_read 3 28394 _003591_hash NULL
87369 +_003592_hash tx_frag_called_read 3 1748 _003592_hash NULL
87370 +_003593_hash tx_frag_failed_read 3 43540 _003593_hash NULL
87371 +_003594_hash tx_frag_init_called_read 3 48377 _003594_hash NULL
87372 +_003595_hash tx_frag_in_process_called_read 3 1290 _003595_hash NULL
87373 +_003596_hash tx_frag_key_not_found_read 3 22971 _003596_hash NULL
87374 +_003597_hash tx_frag_mpdu_alloc_failed_read 3 41167 _003597_hash NULL
87375 +_003598_hash tx_frag_need_fragmentation_read 3 50153 _003598_hash NULL
87376 +_003599_hash tx_frag_tkip_called_read 3 31575 _003599_hash NULL
87377 +_003600_hash tx_tx_burst_programmed_read 3 20320 _003600_hash NULL
87378 +_003601_hash tx_tx_checksum_result_read 3 36490 _003601_hash &_001996_hash
87379 +_003602_hash tx_tx_cmplt_read 3 35854 _003602_hash NULL
87380 +_003603_hash tx_tx_data_prepared_read 3 43497 _003603_hash NULL
87381 +_003604_hash tx_tx_data_programmed_read 3 36871 _003604_hash NULL
87382 +_003605_hash tx_tx_done_data_read 3 6799 _003605_hash NULL
87383 +_003606_hash tx_tx_done_int_template_read 3 55511 _003606_hash &_001887_hash
87384 +_003607_hash tx_tx_done_template_read 3 35104 _003607_hash &_000106_hash
87385 +_003608_hash tx_tx_exch_expiry_read 3 8749 _003608_hash NULL
87386 +_003609_hash tx_tx_exch_pending_read 3 53018 _003609_hash NULL
87387 +_003610_hash tx_tx_exch_read 3 52986 _003610_hash NULL
87388 +_003611_hash tx_tx_frame_checksum_read 3 41553 _003611_hash NULL
87389 +_003612_hash tx_tx_imm_resp_read 3 55964 _003612_hash NULL
87390 +_003613_hash tx_tx_prepared_descs_read 3 9221 _003613_hash NULL
87391 +_003614_hash tx_tx_retry_data_read 3 1926 _003614_hash NULL
87392 +_003615_hash tx_tx_retry_template_read 3 57623 _003615_hash NULL
87393 +_003616_hash tx_tx_start_data_read 3 53219 _003616_hash NULL
87394 +_003617_hash tx_tx_start_fw_gen_read 3 58648 _003617_hash NULL
87395 +_003618_hash tx_tx_start_int_templates_read 3 58324 _003618_hash NULL
87396 +_003619_hash tx_tx_start_null_frame_read 3 6281 _003619_hash NULL
87397 +_003620_hash tx_tx_starts_read 3 3617 _003620_hash NULL
87398 +_003621_hash tx_tx_start_templates_read 3 17164 _003621_hash NULL
87399 +_003622_hash tx_tx_template_prepared_read 3 30424 _003622_hash NULL
87400 +_003623_hash tx_tx_template_programmed_read 3 30461 _003623_hash NULL
87401 +_003624_hash udi_log_event 3 58105 _003624_hash NULL
87402 +_003625_hash udl_prime_create 2 57159 _003625_hash NULL
87403 +_003626_hash uf_create_device_nodes 2 24948 _003626_hash NULL
87404 +_003627_hash uf_sme_queue_message 3 15697 _003627_hash NULL
87405 +_003628_hash ufx_alloc_urb_list 3 10349 _003628_hash NULL
87406 +_003629_hash unifi_net_data_malloc 3 24716 _003629_hash NULL
87407 +_003630_hash unifi_read 3 14899 _003630_hash NULL
87408 +_003631_hash unifi_write 3 65012 _003631_hash NULL
87409 +_003632_hash usb_buffer_alloc 2 36276 _003632_hash NULL
87410 +_003633_hash usbvision_rvmalloc 1 19655 _003633_hash NULL
87411 +_003634_hash usbvision_v4l2_read 3 34386 _003634_hash NULL
87412 +_003635_hash uvc_alloc_buffers 2-3 9656 _003635_hash NULL
87413 +_003637_hash uvc_alloc_entity 3-4 20836 _003637_hash NULL
87414 +_003639_hash uvc_debugfs_stats_read 3 56651 _003639_hash NULL
87415 +_003640_hash uvc_simplify_fraction 3 31303 _003640_hash NULL
87416 +_003641_hash v4l2_ctrl_new 7 24927 _003641_hash NULL
87417 +_003642_hash v4l2_event_subscribe 3 53687 _003642_hash NULL
87418 +_003643_hash v4l_stk_read 3 39672 _003643_hash NULL
87419 +_003644_hash __vb2_perform_fileio 3 63033 _003644_hash NULL
87420 +_003645_hash vfd_write 3 14717 _003645_hash NULL
87421 +_003646_hash vfio_config_do_rw 3 46091 _003646_hash NULL
87422 +_003647_hash vfio_msi_enable 2 20906 _003647_hash NULL
87423 +_003648_hash viafb_dvp0_proc_write 3 23023 _003648_hash NULL
87424 +_003649_hash viafb_dvp1_proc_write 3 48864 _003649_hash NULL
87425 +_003650_hash viafb_vt1636_proc_write 3 16018 _003650_hash NULL
87426 +_003651_hash __videobuf_alloc_vb 1 27062 _003651_hash NULL
87427 +_003652_hash __videobuf_alloc_vb 1 5665 _003652_hash NULL
87428 +_003653_hash __videobuf_copy_to_user 4 15423 _003653_hash NULL
87429 +_003654_hash videobuf_dma_init_kernel 3 6963 _003654_hash NULL
87430 +_003655_hash videobuf_pages_to_sg 2 3708 _003655_hash NULL
87431 +_003656_hash videobuf_vmalloc_to_sg 2 4548 _003656_hash NULL
87432 +_003657_hash video_usercopy 2 62151 _003657_hash NULL
87433 +_003658_hash virtscsi_alloc_tgt 2 6643 _003658_hash NULL
87434 +_003659_hash vmw_cursor_update_image 3-4 16332 _003659_hash NULL
87435 +_003661_hash vmw_framebuffer_dmabuf_dirty 6 37661 _003661_hash &_001116_hash
87436 +_003662_hash vmw_framebuffer_surface_dirty 6 48132 _003662_hash NULL
87437 +_003663_hash vmw_gmr2_bind 3 21305 _003663_hash NULL
87438 +_003664_hash vmw_unlocked_ioctl 2 19212 _003664_hash NULL
87439 +_003665_hash w9966_v4l_read 3 31148 _003665_hash NULL
87440 +_003666_hash wl1273_fm_fops_write 3 60621 _003666_hash NULL
87441 +_003667_hash zoran_write 3 22404 _003667_hash NULL
87442 +_003668_hash alloc_vm_area 1 15989 _003668_hash NULL
87443 +_003669_hash cx18_copy_mdl_to_user 4 45549 _003669_hash NULL
87444 +_003670_hash dlfb_ops_write 3 64150 _003670_hash NULL
87445 +_003671_hash dvb_demux_read 3 13981 _003671_hash NULL
87446 +_003672_hash dvb_dmxdev_read_sec 4 7892 _003672_hash NULL
87447 +_003673_hash dvb_dvr_read 3 17073 _003673_hash NULL
87448 +_003674_hash em28xx_init_isoc 4 62883 _003674_hash &_000729_hash
87449 +_003675_hash fb_alloc_cmap 2 6554 _003675_hash NULL
87450 +_003676_hash gspca_dev_probe 4 2570 _003676_hash NULL
87451 +_003677_hash ieee80211_auth_challenge 3 18810 _003677_hash NULL
87452 +_003678_hash ieee80211_rtl_auth_challenge 3 61897 _003678_hash NULL
87453 +_003679_hash init_pci_cap_msi_perm 2 59033 _003679_hash NULL
87454 +_003680_hash __ioremap_caller 1-2 21800 _003680_hash NULL
87455 +_003682_hash ivtv_read 3 57796 _003682_hash NULL
87456 +_003683_hash ivtv_v4l2_write 3 39226 _003683_hash NULL
87457 +_003684_hash mce_async_out 3 58056 _003684_hash NULL
87458 +_003685_hash mce_flush_rx_buffer 2 14976 _003685_hash NULL
87459 +_003686_hash ms_read_multiple_pages 4-5 8052 _003686_hash NULL
87460 +_003688_hash ms_write_multiple_pages 5-6 10362 _003688_hash NULL
87461 +_003690_hash nfc_hci_send_cmd 5 55714 _003690_hash NULL
87462 +_003691_hash persistent_ram_new 1-2 40501 _003691_hash NULL
87463 +_003693_hash picolcd_fb_write 3 2318 _003693_hash NULL
87464 +_003694_hash process_bulk_data_command 4 38906 _003694_hash NULL
87465 +_003695_hash pvr2_v4l2_read 3 18006 _003695_hash NULL
87466 +_003696_hash qcam_read 3 13977 _003696_hash NULL
87467 +_003697_hash register_unifi_sdio 2 55239 _003697_hash NULL
87468 +_003698_hash resize_async_buffer 4 64031 _003698_hash &_002431_hash
87469 +_003699_hash rtllib_auth_challenge 3 12493 _003699_hash NULL
87470 +_003702_hash stk_allocate_buffers 2 16291 _003702_hash NULL
87471 +_003703_hash subdev_ioctl 2 28417 _003703_hash NULL
87472 +_003704_hash _sys_packet_req 4 46793 _003704_hash NULL
87473 +_003705_hash tm6000_i2c_recv_regs16 5 2949 _003705_hash NULL
87474 +_003706_hash tm6000_i2c_recv_regs 5 46215 _003706_hash NULL
87475 +_003707_hash tm6000_i2c_send_regs 5 20250 _003707_hash NULL
87476 +_003708_hash tt3650_ci_msg_locked 4 8013 _003708_hash NULL
87477 +_003709_hash ufx_ops_write 3 54848 _003709_hash NULL
87478 +_003710_hash update_macheader 7 1775 _003710_hash NULL
87479 +_003711_hash usbdux_attach_common 4 51764 _003750_hash NULL nohasharray
87480 +_003712_hash usbduxfast_attach_common 4 52538 _003712_hash NULL
87481 +_003713_hash usbduxsigma_attach_common 4 40847 _003713_hash NULL
87482 +_003714_hash uvc_v4l2_ioctl 2 8411 _003714_hash NULL
87483 +_003715_hash v4l2_ctrl_new_int_menu 4 41151 _003715_hash NULL
87484 +_003716_hash v4l2_ctrl_new_std 5 45748 _003716_hash &_000497_hash
87485 +_003717_hash v4l2_ctrl_new_std_menu 4 6221 _003717_hash NULL
87486 +_003718_hash vb2_read 3 42703 _003718_hash NULL
87487 +_003719_hash vb2_write 3 31948 _003719_hash NULL
87488 +_003720_hash vfio_pci_set_msi_trigger 3-4 26507 _003720_hash NULL
87489 +_003722_hash viafb_iga1_odev_proc_write 3 36241 _003722_hash NULL
87490 +_003723_hash viafb_iga2_odev_proc_write 3 2363 _003723_hash NULL
87491 +_003724_hash __videobuf_alloc_cached 1 12740 _003724_hash NULL
87492 +_003725_hash __videobuf_alloc_uncached 1 55711 _003725_hash NULL
87493 +_003726_hash __videobuf_copy_stream 4 44769 _003726_hash NULL
87494 +_003727_hash videobuf_read_one 3 31637 _003727_hash NULL
87495 +_003728_hash video_ioctl2 2 21380 _003728_hash NULL
87496 +_003729_hash vmap 2 15025 _003729_hash NULL
87497 +_003730_hash vmw_cursor_update_dmabuf 3-4 32045 _003730_hash NULL
87498 +_003732_hash vmw_gmr_bind 3 44130 _003732_hash NULL
87499 +_003733_hash xd_read_multiple_pages 4-5 11422 _003733_hash NULL
87500 +_003735_hash xd_write_multiple_pages 5-6 53633 _003735_hash NULL
87501 +_003737_hash xenfb_write 3 43412 _003737_hash NULL
87502 +_003738_hash arch_gnttab_map_shared 3 41306 _003738_hash NULL
87503 +_003739_hash arch_gnttab_map_status 3 49812 _003739_hash NULL
87504 +_003740_hash bttv_read 3 11432 _003740_hash NULL
87505 +_003741_hash cx18_read 3 23699 _003741_hash NULL
87506 +_003742_hash cx2341x_ctrl_new_menu 3 49700 _003742_hash NULL
87507 +_003743_hash cx2341x_ctrl_new_std 4 57061 _003743_hash NULL
87508 +_003744_hash cx25821_video_ioctl 2 30188 _003744_hash NULL
87509 +_003745_hash dt3155_read 3 59226 _003745_hash NULL
87510 +_003746_hash ioremap_cache 1-2 47189 _003746_hash NULL
87511 +_003748_hash ioremap_nocache 1-2 2439 _003748_hash NULL
87512 +_003750_hash ioremap_prot 1-2 51764 _003750_hash &_003711_hash
87513 +_003752_hash ioremap_wc 1-2 62695 _003752_hash NULL
87514 +_003754_hash ivtv_read_pos 3 34400 _003754_hash &_000312_hash
87515 +_003755_hash mcam_v4l_read 3 36513 _003755_hash NULL
87516 +_003756_hash ms_rw_multi_sector 3-4 7459 _003756_hash NULL
87517 +_003758_hash pvr2_v4l2_ioctl 2 24398 _003758_hash &_000877_hash
87518 +_003759_hash ramoops_init_prz 5 12134 _003759_hash NULL
87519 +_003761_hash ttm_bo_kmap_ttm 3 5922 _003761_hash NULL
87520 +_003762_hash uf_ap_process_data_pdu 7 25860 _003762_hash NULL
87521 +_003763_hash vb2_fop_read 3 24080 _003763_hash NULL
87522 +_003764_hash vb2_fop_write 3 30420 _003764_hash NULL
87523 +_003765_hash videobuf_read_stream 3 14956 _003765_hash NULL
87524 +_003766_hash video_read 3 28148 _003766_hash NULL
87525 +_003767_hash vmw_du_crtc_cursor_set 4-5 28479 _003767_hash NULL
87526 +_003769_hash xd_rw 3-4 49020 _003769_hash NULL
87527 +_003771_hash zoran_ioctl 2 30465 _003771_hash NULL
87528 +_003772_hash zr364xx_read 3 2354 _003772_hash NULL
87529 +_003773_hash acpi_os_ioremap 1-2 49523 _003773_hash NULL
87530 +_003775_hash au0828_v4l2_read 3 40220 _003775_hash NULL
87531 +_003776_hash ca91cx42_alloc_resource 2 10502 _003776_hash NULL
87532 +_003778_hash cx18_read_pos 3 4683 _003778_hash NULL
87533 +_003779_hash cx18_v4l2_read 3 21196 _003779_hash NULL
87534 +_003780_hash cx231xx_v4l2_read 3 55014 _003780_hash NULL
87535 +_003781_hash devm_ioremap_nocache 2-3 2036 _003781_hash NULL
87536 +_003783_hash do_test 1 15766 _003783_hash NULL
87537 +_003784_hash __einj_error_trigger 1 17707 _003784_hash &_001764_hash
87538 +_003785_hash em28xx_v4l2_read 3 16701 _003785_hash NULL
87539 +_003786_hash init_chip_wc_pat 2 62768 _003786_hash NULL
87540 +_003787_hash intel_render_ring_init_dri 2-3 45446 _003787_hash NULL
87541 +_003789_hash io_mapping_create_wc 1-2 1354 _003789_hash NULL
87542 +_003791_hash iommu_map_mmio_space 1 30919 _003791_hash NULL
87543 +_003792_hash ioremap 1-2 23172 _003792_hash NULL
87544 +_003794_hash ivtv_v4l2_read 3 1964 _003794_hash NULL
87545 +_003795_hash mga_ioremap 1-2 8571 _003795_hash NULL
87546 +_003797_hash mpeg_read 3 6708 _003797_hash NULL
87547 +_003798_hash msix_map_region 3 3411 _003798_hash NULL
87548 +_003799_hash ms_rw 3-4 17220 _003799_hash NULL
87549 +_003801_hash pci_iomap 3 47575 _003801_hash NULL
87550 +_003802_hash pd_video_read 3 24510 _003802_hash NULL
87551 +_003803_hash sfi_map_memory 1-2 5183 _003803_hash NULL
87552 +_003805_hash solo_enc_read 3 33553 _003805_hash NULL
87553 +_003806_hash solo_v4l2_read 3 59247 _003806_hash NULL
87554 +_003807_hash timblogiw_read 3 48305 _003807_hash NULL
87555 +_003808_hash tm6000_read 3 4151 _003808_hash NULL
87556 +_003809_hash tsi148_alloc_resource 2 24563 _003809_hash NULL
87557 +_003810_hash ttm_bo_ioremap 2-3 31082 _003810_hash NULL
87558 +_003812_hash ttm_bo_kmap 3-2 60118 _003812_hash NULL
87559 +_003813_hash vb2_vmalloc_get_userptr 3 31374 _003813_hash NULL
87560 +_003814_hash vbi_read 3 63673 _003814_hash NULL
87561 +_003815_hash viacam_read 3 54526 _003815_hash NULL
87562 +_003816_hash xlate_dev_mem_ptr 1 15291 _003816_hash &_001231_hash
87563 +_003817_hash a4t_cs_init 3 27734 _003817_hash NULL
87564 +_003818_hash aac_nark_ioremap 2 50163 _003818_hash &_000323_hash
87565 +_003819_hash aac_rkt_ioremap 2 3333 _003819_hash NULL
87566 +_003820_hash aac_rx_ioremap 2 52410 _003820_hash NULL
87567 +_003821_hash aac_sa_ioremap 2 13596 _003821_hash &_000299_hash
87568 +_003822_hash aac_src_ioremap 2 41688 _003822_hash NULL
87569 +_003823_hash aac_srcv_ioremap 2 6659 _003823_hash NULL
87570 +_003824_hash acpi_map 1-2 58725 _003824_hash NULL
87571 +_003826_hash acpi_os_read_memory 1-3 54186 _003826_hash NULL
87572 +_003828_hash acpi_os_write_memory 1-3 56416 _003828_hash &_003429_hash
87573 +_003830_hash atyfb_setup_generic 3 49151 _003830_hash NULL
87574 +_003831_hash ca91cx42_master_set 4 23146 _003831_hash NULL
87575 +_003832_hash check_mirror 1-2 57342 _003832_hash &_001753_hash
87576 +_003834_hash cycx_setup 4 47562 _003834_hash NULL
87577 +_003835_hash devm_ioremap 2-3 29235 _003835_hash NULL
87578 +_003837_hash divasa_remap_pci_bar 3-4 23485 _003837_hash &_000979_hash
87579 +_003839_hash doc_probe 1 23285 _003839_hash NULL
87580 +_003840_hash DoC_Probe 1 57534 _003840_hash NULL
87581 +_003841_hash efi_ioremap 1-2 3492 _003841_hash &_001137_hash
87582 +_003843_hash ems_pcmcia_add_card 2 62627 _003843_hash NULL
87583 +_003844_hash isp1760_register 1-2 628 _003844_hash NULL
87584 +_003846_hash mid_get_vbt_data_r0 2 10876 _003846_hash NULL
87585 +_003847_hash mid_get_vbt_data_r10 2 6308 _003847_hash NULL
87586 +_003848_hash mid_get_vbt_data_r1 2 26170 _003848_hash NULL
87587 +_003849_hash mthca_map_reg 2-3 5664 _003849_hash NULL
87588 +_003851_hash mthca_setup_cmd_doorbells 2 53954 _003851_hash NULL
87589 +_003852_hash netxen_nic_map_indirect_address_128M 2 42257 _003852_hash NULL
87590 +_003853_hash pcim_iomap 3 58334 _003853_hash NULL
87591 +_003854_hash persistent_ram_iomap 1-2 47156 _003854_hash NULL
87592 +_003856_hash read_vbt_r0 1 503 _003856_hash NULL
87593 +_003857_hash read_vbt_r10 1 60679 _003857_hash NULL
87594 +_003858_hash register_device 2-3 60015 _003858_hash NULL
87595 +_003860_hash remap_pci_mem 1-2 15966 _003860_hash NULL
87596 +_003862_hash rtl_port_map 1-2 2385 _003862_hash NULL
87597 +_003864_hash sfi_map_table 1 5462 _003864_hash NULL
87598 +_003865_hash sriov_enable_migration 2 14889 _003865_hash NULL
87599 +_003866_hash ssb_bus_scan 2 36578 _003866_hash NULL
87600 +_003867_hash ssb_ioremap 2 5228 _003867_hash NULL
87601 +_003868_hash tpci200_slot_map_space 2 3848 _003868_hash NULL
87602 +_003869_hash tpm_tis_init 2-3 15304 _003869_hash NULL
87603 +_003871_hash tsi148_master_set 4 14685 _003871_hash NULL
87604 +_003872_hash acpi_os_map_memory 1-2 11161 _003872_hash NULL
87605 +_003874_hash com90xx_found 3 13974 _003874_hash NULL
87606 +_003875_hash netxen_nic_hw_read_wx_128M 2 26858 _003875_hash NULL
87607 +_003876_hash netxen_nic_hw_write_wx_128M 2 33488 _003876_hash NULL
87608 +_003877_hash sfi_check_table 1 6772 _003877_hash NULL
87609 +_003878_hash sfi_sysfs_install_table 1 51688 _003878_hash NULL
87610 +_003879_hash sriov_enable 2 59689 _003879_hash NULL
87611 +_003880_hash ssb_bus_register 3 65183 _003880_hash NULL
87612 +_003881_hash acpi_ex_system_memory_space_handler 2 31192 _003881_hash NULL
87613 +_003882_hash acpi_tb_check_xsdt 1 21862 _003882_hash NULL
87614 +_003883_hash acpi_tb_install_table 1 12988 _003883_hash NULL
87615 +_003884_hash acpi_tb_parse_root_table 1 53455 _003884_hash NULL
87616 +_003885_hash check_vendor_extension 1 3254 _003885_hash NULL
87617 +_003886_hash pci_enable_sriov 2 35745 _003886_hash NULL
87618 +_003887_hash ssb_bus_pcmciabus_register 3 56020 _003887_hash NULL
87619 +_003888_hash ssb_bus_ssbbus_register 2 2217 _003888_hash NULL
87620 +_003889_hash lpfc_sli_probe_sriov_nr_virtfn 2 26004 _003889_hash NULL
87621 +_003890_hash alloc_vm_area 1 36149 _003890_hash NULL
87622 +_003891_hash cma_create_area 2 38642 _003891_hash NULL
87623 +_003893_hash fbcon_prepare_logo 5 6246 _003893_hash NULL
87624 +_003894_hash io_mapping_map_wc 2 19284 _003894_hash NULL
87625 +_003895_hash nfs_dns_resolve_name 3 25036 _003895_hash NULL
87626 +_003896_hash nfs_parse_server_name 2 1899 _003896_hash NULL
87627 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
87628 new file mode 100644
87629 index 0000000..244559e
87630 --- /dev/null
87631 +++ b/tools/gcc/size_overflow_plugin.c
87632 @@ -0,0 +1,1879 @@
87633 +/*
87634 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
87635 + * Licensed under the GPL v2, or (at your option) v3
87636 + *
87637 + * Homepage:
87638 + * http://www.grsecurity.net/~ephox/overflow_plugin/
87639 + *
87640 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
87641 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
87642 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
87643 + *
87644 + * Usage:
87645 + * $ 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
87646 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
87647 + */
87648 +
87649 +#include "gcc-plugin.h"
87650 +#include "config.h"
87651 +#include "system.h"
87652 +#include "coretypes.h"
87653 +#include "tree.h"
87654 +#include "tree-pass.h"
87655 +#include "intl.h"
87656 +#include "plugin-version.h"
87657 +#include "tm.h"
87658 +#include "toplev.h"
87659 +#include "function.h"
87660 +#include "tree-flow.h"
87661 +#include "plugin.h"
87662 +#include "gimple.h"
87663 +#include "c-common.h"
87664 +#include "diagnostic.h"
87665 +#include "cfgloop.h"
87666 +
87667 +#if BUILDING_GCC_VERSION >= 4007
87668 +#include "c-tree.h"
87669 +#else
87670 +#define C_DECL_IMPLICIT(EXP) DECL_LANG_FLAG_2 (EXP)
87671 +#endif
87672 +
87673 +struct size_overflow_hash {
87674 + const struct size_overflow_hash * const next;
87675 + const char * const name;
87676 + const unsigned int param;
87677 +};
87678 +
87679 +#include "size_overflow_hash.h"
87680 +
87681 +enum marked {
87682 + MARKED_NO, MARKED_YES, MARKED_NOT_INTENTIONAL
87683 +};
87684 +
87685 +#define __unused __attribute__((__unused__))
87686 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
87687 +#define NAME_LEN(node) IDENTIFIER_LENGTH(DECL_NAME(node))
87688 +#define BEFORE_STMT true
87689 +#define AFTER_STMT false
87690 +#define CREATE_NEW_VAR NULL_TREE
87691 +#define CODES_LIMIT 32
87692 +#define MAX_PARAM 32
87693 +#define MY_STMT GF_PLF_1
87694 +#define NO_CAST_CHECK GF_PLF_2
87695 +
87696 +#if BUILDING_GCC_VERSION == 4005
87697 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
87698 +#endif
87699 +
87700 +int plugin_is_GPL_compatible;
87701 +void debug_gimple_stmt(gimple gs);
87702 +
87703 +static tree expand(struct pointer_set_t *visited, tree lhs);
87704 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs);
87705 +static tree report_size_overflow_decl;
87706 +static const_tree const_char_ptr_type_node;
87707 +static unsigned int handle_function(void);
87708 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
87709 +static tree get_size_overflow_type(gimple stmt, const_tree node);
87710 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, tree size_overflow_type, tree rhs1, tree rhs2, tree __unused rhs3);
87711 +
87712 +static struct plugin_info size_overflow_plugin_info = {
87713 + .version = "20120930beta",
87714 + .help = "no-size-overflow\tturn off size overflow checking\n",
87715 +};
87716 +
87717 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
87718 +{
87719 + unsigned int arg_count;
87720 + enum tree_code code = TREE_CODE(*node);
87721 +
87722 + switch (code) {
87723 + case FUNCTION_DECL:
87724 + arg_count = type_num_arguments(TREE_TYPE(*node));
87725 + break;
87726 + case FUNCTION_TYPE:
87727 + case METHOD_TYPE:
87728 + arg_count = type_num_arguments(*node);
87729 + break;
87730 + default:
87731 + *no_add_attrs = true;
87732 + error("%s: %qE attribute only applies to functions", __func__, name);
87733 + return NULL_TREE;
87734 + }
87735 +
87736 + for (; args; args = TREE_CHAIN(args)) {
87737 + tree position = TREE_VALUE(args);
87738 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
87739 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
87740 + *no_add_attrs = true;
87741 + }
87742 + }
87743 + return NULL_TREE;
87744 +}
87745 +
87746 +static const char* get_asm_name(tree node)
87747 +{
87748 + return IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME(node));
87749 +}
87750 +
87751 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
87752 +{
87753 + unsigned int arg_count, arg_num;
87754 + enum tree_code code = TREE_CODE(*node);
87755 +
87756 + switch (code) {
87757 + case FUNCTION_DECL:
87758 + arg_count = type_num_arguments(TREE_TYPE(*node));
87759 + break;
87760 + case FUNCTION_TYPE:
87761 + case METHOD_TYPE:
87762 + arg_count = type_num_arguments(*node);
87763 + break;
87764 + case FIELD_DECL:
87765 + arg_num = TREE_INT_CST_LOW(TREE_VALUE(args));
87766 + if (arg_num != 0) {
87767 + *no_add_attrs = true;
87768 + error("%s: %qE attribute parameter can only be 0 in structure fields", __func__, name);
87769 + }
87770 + return NULL_TREE;
87771 + default:
87772 + *no_add_attrs = true;
87773 + error("%qE attribute only applies to functions", name);
87774 + return NULL_TREE;
87775 + }
87776 +
87777 + for (; args; args = TREE_CHAIN(args)) {
87778 + tree position = TREE_VALUE(args);
87779 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) > arg_count ) {
87780 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
87781 + *no_add_attrs = true;
87782 + }
87783 + }
87784 + return NULL_TREE;
87785 +}
87786 +
87787 +static struct attribute_spec size_overflow_attr = {
87788 + .name = "size_overflow",
87789 + .min_length = 1,
87790 + .max_length = -1,
87791 + .decl_required = true,
87792 + .type_required = false,
87793 + .function_type_required = false,
87794 + .handler = handle_size_overflow_attribute,
87795 +#if BUILDING_GCC_VERSION >= 4007
87796 + .affects_type_identity = false
87797 +#endif
87798 +};
87799 +
87800 +static struct attribute_spec intentional_overflow_attr = {
87801 + .name = "intentional_overflow",
87802 + .min_length = 1,
87803 + .max_length = -1,
87804 + .decl_required = true,
87805 + .type_required = false,
87806 + .function_type_required = false,
87807 + .handler = handle_intentional_overflow_attribute,
87808 +#if BUILDING_GCC_VERSION >= 4007
87809 + .affects_type_identity = false
87810 +#endif
87811 +};
87812 +
87813 +static void register_attributes(void __unused *event_data, void __unused *data)
87814 +{
87815 + register_attribute(&size_overflow_attr);
87816 + register_attribute(&intentional_overflow_attr);
87817 +}
87818 +
87819 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
87820 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
87821 +{
87822 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
87823 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
87824 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
87825 +
87826 + unsigned int m = 0x57559429;
87827 + unsigned int n = 0x5052acdb;
87828 + const unsigned int *key4 = (const unsigned int *)key;
87829 + unsigned int h = len;
87830 + unsigned int k = len + seed + n;
87831 + unsigned long long p;
87832 +
87833 + while (len >= 8) {
87834 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
87835 + len -= 8;
87836 + }
87837 + if (len >= 4) {
87838 + cwmixb(key4[0]) key4 += 1;
87839 + len -= 4;
87840 + }
87841 + if (len)
87842 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
87843 + cwmixb(h ^ (k + n));
87844 + return k ^ h;
87845 +
87846 +#undef cwfold
87847 +#undef cwmixa
87848 +#undef cwmixb
87849 +}
87850 +
87851 +static inline unsigned int get_hash_num(const char *fndecl, const char *tree_codes, unsigned int len, unsigned int seed)
87852 +{
87853 + unsigned int fn = CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
87854 + unsigned int codes = CrapWow(tree_codes, len, seed) & 0xffff;
87855 + return fn ^ codes;
87856 +}
87857 +
87858 +static inline tree get_original_function_decl(tree fndecl)
87859 +{
87860 + if (DECL_ABSTRACT_ORIGIN(fndecl))
87861 + return DECL_ABSTRACT_ORIGIN(fndecl);
87862 + return fndecl;
87863 +}
87864 +
87865 +static inline gimple get_def_stmt(const_tree node)
87866 +{
87867 + gcc_assert(node != NULL_TREE);
87868 + gcc_assert(TREE_CODE(node) == SSA_NAME);
87869 + return SSA_NAME_DEF_STMT(node);
87870 +}
87871 +
87872 +static unsigned char get_tree_code(const_tree type)
87873 +{
87874 + switch (TREE_CODE(type)) {
87875 + case ARRAY_TYPE:
87876 + return 0;
87877 + case BOOLEAN_TYPE:
87878 + return 1;
87879 + case ENUMERAL_TYPE:
87880 + return 2;
87881 + case FUNCTION_TYPE:
87882 + return 3;
87883 + case INTEGER_TYPE:
87884 + return 4;
87885 + case POINTER_TYPE:
87886 + return 5;
87887 + case RECORD_TYPE:
87888 + return 6;
87889 + case UNION_TYPE:
87890 + return 7;
87891 + case VOID_TYPE:
87892 + return 8;
87893 + case REAL_TYPE:
87894 + return 9;
87895 + case VECTOR_TYPE:
87896 + return 10;
87897 + case REFERENCE_TYPE:
87898 + return 11;
87899 + case OFFSET_TYPE:
87900 + return 12;
87901 + case COMPLEX_TYPE:
87902 + return 13;
87903 + default:
87904 + debug_tree((tree)type);
87905 + gcc_unreachable();
87906 + }
87907 +}
87908 +
87909 +static size_t add_type_codes(const_tree type, unsigned char *tree_codes, size_t len)
87910 +{
87911 + gcc_assert(type != NULL_TREE);
87912 +
87913 + while (type && len < CODES_LIMIT) {
87914 + tree_codes[len] = get_tree_code(type);
87915 + len++;
87916 + type = TREE_TYPE(type);
87917 + }
87918 + return len;
87919 +}
87920 +
87921 +static unsigned int get_function_decl(const_tree fndecl, unsigned char *tree_codes)
87922 +{
87923 + const_tree arg, result, arg_field, type = TREE_TYPE(fndecl);
87924 + enum tree_code code = TREE_CODE(type);
87925 + size_t len = 0;
87926 +
87927 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
87928 +
87929 + arg = TYPE_ARG_TYPES(type);
87930 + // skip builtins __builtin_constant_p
87931 + if (!arg && DECL_BUILT_IN(fndecl))
87932 + return 0;
87933 +
87934 + if (TREE_CODE_CLASS(code) == tcc_type)
87935 + result = type;
87936 + else
87937 + result = DECL_RESULT(fndecl);
87938 +
87939 + gcc_assert(result != NULL_TREE);
87940 + len = add_type_codes(TREE_TYPE(result), tree_codes, len);
87941 +
87942 + if (arg == NULL_TREE) {
87943 + gcc_assert(CODE_CONTAINS_STRUCT(TREE_CODE(fndecl), TS_DECL_NON_COMMON));
87944 + arg_field = DECL_ARGUMENT_FLD(fndecl);
87945 + if (arg_field == NULL_TREE)
87946 + return 0;
87947 + arg = TREE_TYPE(arg_field);
87948 + len = add_type_codes(arg, tree_codes, len);
87949 + gcc_assert(len != 0);
87950 + return len;
87951 + }
87952 +
87953 + gcc_assert(arg != NULL_TREE && TREE_CODE(arg) == TREE_LIST);
87954 + while (arg && len < CODES_LIMIT) {
87955 + len = add_type_codes(TREE_VALUE(arg), tree_codes, len);
87956 + arg = TREE_CHAIN(arg);
87957 + }
87958 +
87959 + gcc_assert(len != 0);
87960 + return len;
87961 +}
87962 +
87963 +static const struct size_overflow_hash *get_function_hash(tree fndecl)
87964 +{
87965 + unsigned int hash;
87966 + const struct size_overflow_hash *entry;
87967 + unsigned char tree_codes[CODES_LIMIT];
87968 + size_t len;
87969 + const char *func_name = get_asm_name(fndecl);
87970 +
87971 + len = get_function_decl(fndecl, tree_codes);
87972 + if (len == 0)
87973 + return NULL;
87974 +
87975 + hash = get_hash_num(func_name, (const char*) tree_codes, len, 0);
87976 +
87977 + entry = size_overflow_hash[hash];
87978 + while (entry) {
87979 + if (!strcmp(entry->name, func_name))
87980 + return entry;
87981 + entry = entry->next;
87982 + }
87983 +
87984 + return NULL;
87985 +}
87986 +
87987 +static void check_arg_type(const_tree arg)
87988 +{
87989 + const_tree type = TREE_TYPE(arg);
87990 + enum tree_code code = TREE_CODE(type);
87991 +
87992 + gcc_assert(code == INTEGER_TYPE || code == ENUMERAL_TYPE ||
87993 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
87994 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
87995 +}
87996 +
87997 +static int find_arg_number(const_tree arg, tree func)
87998 +{
87999 + tree var;
88000 + unsigned int argnum = 1;
88001 +
88002 + if (TREE_CODE(arg) == SSA_NAME)
88003 + arg = SSA_NAME_VAR(arg);
88004 +
88005 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
88006 + if (strcmp(NAME(arg), NAME(var))) {
88007 + argnum++;
88008 + continue;
88009 + }
88010 + check_arg_type(var);
88011 + return argnum;
88012 + }
88013 + gcc_unreachable();
88014 +}
88015 +
88016 +static tree create_new_var(tree type)
88017 +{
88018 + tree new_var = create_tmp_var(type, "cicus");
88019 +
88020 + add_referenced_var(new_var);
88021 + mark_sym_for_renaming(new_var);
88022 + return new_var;
88023 +}
88024 +
88025 +static gimple create_binary_assign(enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
88026 +{
88027 + gimple assign;
88028 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
88029 + tree type = TREE_TYPE(rhs1);
88030 + tree lhs = create_new_var(type);
88031 +
88032 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
88033 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
88034 +
88035 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
88036 + update_stmt(assign);
88037 + gimple_set_plf(assign, MY_STMT, true);
88038 + return assign;
88039 +}
88040 +
88041 +static bool is_bool(const_tree node)
88042 +{
88043 + const_tree type;
88044 +
88045 + if (node == NULL_TREE)
88046 + return false;
88047 +
88048 + type = TREE_TYPE(node);
88049 + if (!INTEGRAL_TYPE_P(type))
88050 + return false;
88051 + if (TREE_CODE(type) == BOOLEAN_TYPE)
88052 + return true;
88053 + if (TYPE_PRECISION(type) == 1)
88054 + return true;
88055 + return false;
88056 +}
88057 +
88058 +static tree cast_a_tree(tree type, tree var)
88059 +{
88060 + gcc_assert(type != NULL_TREE);
88061 + gcc_assert(var != NULL_TREE);
88062 + gcc_assert(fold_convertible_p(type, var));
88063 +
88064 + return fold_convert(type, var);
88065 +}
88066 +
88067 +static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before)
88068 +{
88069 + gimple assign;
88070 +
88071 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
88072 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
88073 + gcc_unreachable();
88074 +
88075 + if (lhs == CREATE_NEW_VAR)
88076 + lhs = create_new_var(dst_type);
88077 +
88078 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
88079 +
88080 + if (!gsi_end_p(*gsi)) {
88081 + location_t loc = gimple_location(gsi_stmt(*gsi));
88082 + gimple_set_location(assign, loc);
88083 + }
88084 +
88085 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
88086 +
88087 + if (before)
88088 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
88089 + else
88090 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
88091 + update_stmt(assign);
88092 + gimple_set_plf(assign, MY_STMT, true);
88093 +
88094 + return assign;
88095 +}
88096 +
88097 +static tree cast_to_new_size_overflow_type(gimple stmt, tree new_rhs1, tree size_overflow_type, bool before)
88098 +{
88099 + const_gimple assign;
88100 + gimple_stmt_iterator gsi;
88101 +
88102 + if (new_rhs1 == NULL_TREE)
88103 + return NULL_TREE;
88104 +
88105 + if (!useless_type_conversion_p(TREE_TYPE(new_rhs1), size_overflow_type)) {
88106 + gsi = gsi_for_stmt(stmt);
88107 + assign = build_cast_stmt(size_overflow_type, new_rhs1, CREATE_NEW_VAR, &gsi, before);
88108 + return gimple_get_lhs(assign);
88109 + }
88110 + return new_rhs1;
88111 +}
88112 +
88113 +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)
88114 +{
88115 + tree size_overflow_type = get_size_overflow_type(stmt, node);
88116 +
88117 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88118 +
88119 + if (new_rhs2 != NULL_TREE)
88120 + new_rhs2 = cast_to_new_size_overflow_type(stmt, new_rhs2, size_overflow_type, BEFORE_STMT);
88121 +
88122 + if (new_rhs3 != NULL_TREE)
88123 + new_rhs3 = cast_to_new_size_overflow_type(stmt, new_rhs3, size_overflow_type, BEFORE_STMT);
88124 +
88125 + return dup_assign(visited, stmt, size_overflow_type, new_rhs1, new_rhs2, new_rhs3);
88126 +}
88127 +
88128 +
88129 +static tree create_assign(struct pointer_set_t *visited, gimple oldstmt, tree rhs1, bool before)
88130 +{
88131 + tree size_overflow_type, lhs;
88132 + gimple stmt;
88133 + gimple_stmt_iterator gsi;
88134 +
88135 + if (rhs1 == NULL_TREE) {
88136 + debug_gimple_stmt(oldstmt);
88137 + error("%s: rhs1 is NULL_TREE", __func__);
88138 + gcc_unreachable();
88139 + }
88140 +
88141 + if (gimple_code(oldstmt) == GIMPLE_ASM)
88142 + lhs = rhs1;
88143 + else
88144 + lhs = gimple_get_lhs(oldstmt);
88145 +
88146 + gsi = gsi_for_stmt(oldstmt);
88147 + pointer_set_insert(visited, oldstmt);
88148 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
88149 + basic_block next_bb, cur_bb;
88150 + const_edge e;
88151 +
88152 + gcc_assert(before == false);
88153 + gcc_assert(stmt_can_throw_internal(oldstmt));
88154 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
88155 + gcc_assert(!gsi_end_p(gsi));
88156 +
88157 + cur_bb = gimple_bb(oldstmt);
88158 + next_bb = cur_bb->next_bb;
88159 + e = find_edge(cur_bb, next_bb);
88160 + gcc_assert(e != NULL);
88161 + gcc_assert(e->flags & EDGE_FALLTHRU);
88162 +
88163 + gsi = gsi_after_labels(next_bb);
88164 + gcc_assert(!gsi_end_p(gsi));
88165 +
88166 + before = true;
88167 + oldstmt = gsi_stmt(gsi);
88168 + }
88169 +
88170 + size_overflow_type = get_size_overflow_type(oldstmt, lhs);
88171 +
88172 + stmt = build_cast_stmt(size_overflow_type, rhs1, CREATE_NEW_VAR, &gsi, before);
88173 + gimple_set_plf(stmt, MY_STMT, true);
88174 + return gimple_get_lhs(stmt);
88175 +}
88176 +
88177 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, tree size_overflow_type, tree rhs1, tree rhs2, tree __unused rhs3)
88178 +{
88179 + gimple stmt;
88180 + gimple_stmt_iterator gsi;
88181 + tree new_var, lhs = gimple_get_lhs(oldstmt);
88182 +
88183 + if (gimple_plf(oldstmt, MY_STMT))
88184 + return lhs;
88185 +
88186 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
88187 + rhs1 = gimple_assign_rhs1(oldstmt);
88188 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
88189 + }
88190 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
88191 + rhs2 = gimple_assign_rhs2(oldstmt);
88192 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
88193 + }
88194 +
88195 + stmt = gimple_copy(oldstmt);
88196 + gimple_set_location(stmt, gimple_location(oldstmt));
88197 + gimple_set_plf(stmt, MY_STMT, true);
88198 +
88199 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
88200 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
88201 +
88202 + if (is_bool(lhs))
88203 + new_var = SSA_NAME_VAR(lhs);
88204 + else
88205 + new_var = create_new_var(size_overflow_type);
88206 + new_var = make_ssa_name(new_var, stmt);
88207 + gimple_set_lhs(stmt, new_var);
88208 +
88209 + if (rhs1 != NULL_TREE) {
88210 + if (!gimple_assign_cast_p(oldstmt))
88211 + rhs1 = cast_a_tree(size_overflow_type, rhs1);
88212 + gimple_assign_set_rhs1(stmt, rhs1);
88213 + }
88214 +
88215 + if (rhs2 != NULL_TREE)
88216 + gimple_assign_set_rhs2(stmt, rhs2);
88217 +#if BUILDING_GCC_VERSION >= 4007
88218 + if (rhs3 != NULL_TREE)
88219 + gimple_assign_set_rhs3(stmt, rhs3);
88220 +#endif
88221 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
88222 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
88223 +
88224 + gsi = gsi_for_stmt(oldstmt);
88225 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
88226 + update_stmt(stmt);
88227 + pointer_set_insert(visited, oldstmt);
88228 + return gimple_get_lhs(stmt);
88229 +}
88230 +
88231 +static gimple overflow_create_phi_node(gimple oldstmt, tree result)
88232 +{
88233 + basic_block bb;
88234 + gimple phi;
88235 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
88236 +
88237 + bb = gsi_bb(gsi);
88238 +
88239 + phi = create_phi_node(result, bb);
88240 + gsi = gsi_last(phi_nodes(bb));
88241 + gsi_remove(&gsi, false);
88242 +
88243 + gsi = gsi_for_stmt(oldstmt);
88244 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
88245 + gimple_set_bb(phi, bb);
88246 + gimple_set_plf(phi, MY_STMT, true);
88247 + return phi;
88248 +}
88249 +
88250 +static basic_block create_a_first_bb(void)
88251 +{
88252 + basic_block first_bb;
88253 +
88254 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
88255 + if (dom_info_available_p(CDI_DOMINATORS))
88256 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR);
88257 + return first_bb;
88258 +}
88259 +
88260 +static tree cast_old_phi_arg(gimple oldstmt, tree size_overflow_type, tree arg, tree new_var, unsigned int i)
88261 +{
88262 + basic_block bb;
88263 + const_gimple newstmt;
88264 + gimple_stmt_iterator gsi;
88265 + bool before = BEFORE_STMT;
88266 +
88267 + if (TREE_CODE(arg) == SSA_NAME && gimple_code(get_def_stmt(arg)) != GIMPLE_NOP) {
88268 + gsi = gsi_for_stmt(get_def_stmt(arg));
88269 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, AFTER_STMT);
88270 + return gimple_get_lhs(newstmt);
88271 + }
88272 +
88273 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
88274 + gsi = gsi_after_labels(bb);
88275 + if (bb->index == 0) {
88276 + bb = create_a_first_bb();
88277 + gsi = gsi_start_bb(bb);
88278 + }
88279 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, before);
88280 + return gimple_get_lhs(newstmt);
88281 +}
88282 +
88283 +static const_gimple handle_new_phi_arg(const_tree arg, tree new_var, tree new_rhs)
88284 +{
88285 + gimple newstmt;
88286 + gimple_stmt_iterator gsi;
88287 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
88288 + gimple def_newstmt = get_def_stmt(new_rhs);
88289 +
88290 + gsi_insert = gsi_insert_after;
88291 + gsi = gsi_for_stmt(def_newstmt);
88292 +
88293 + switch (gimple_code(get_def_stmt(arg))) {
88294 + case GIMPLE_PHI:
88295 + newstmt = gimple_build_assign(new_var, new_rhs);
88296 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
88297 + gsi_insert = gsi_insert_before;
88298 + break;
88299 + case GIMPLE_ASM:
88300 + case GIMPLE_CALL:
88301 + newstmt = gimple_build_assign(new_var, new_rhs);
88302 + break;
88303 + case GIMPLE_ASSIGN:
88304 + newstmt = gimple_build_assign(new_var, gimple_get_lhs(def_newstmt));
88305 + break;
88306 + default:
88307 + /* unknown gimple_code (handle_build_new_phi_arg) */
88308 + gcc_unreachable();
88309 + }
88310 +
88311 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
88312 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
88313 + gimple_set_plf(newstmt, MY_STMT, true);
88314 + update_stmt(newstmt);
88315 + return newstmt;
88316 +}
88317 +
88318 +static tree build_new_phi_arg(struct pointer_set_t *visited, tree size_overflow_type, tree arg, tree new_var)
88319 +{
88320 + const_gimple newstmt;
88321 + gimple def_stmt;
88322 + tree new_rhs;
88323 +
88324 + new_rhs = expand(visited, arg);
88325 + if (new_rhs == NULL_TREE)
88326 + return NULL_TREE;
88327 +
88328 + def_stmt = get_def_stmt(new_rhs);
88329 + if (gimple_code(def_stmt) == GIMPLE_NOP)
88330 + return NULL_TREE;
88331 + new_rhs = cast_to_new_size_overflow_type(def_stmt, new_rhs, size_overflow_type, AFTER_STMT);
88332 +
88333 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
88334 + return gimple_get_lhs(newstmt);
88335 +}
88336 +
88337 +static tree build_new_phi(struct pointer_set_t *visited, tree orig_result)
88338 +{
88339 + gimple phi, oldstmt = get_def_stmt(orig_result);
88340 + tree new_result, size_overflow_type;
88341 + unsigned int i;
88342 + unsigned int n = gimple_phi_num_args(oldstmt);
88343 +
88344 + size_overflow_type = get_size_overflow_type(oldstmt, orig_result);
88345 +
88346 + new_result = create_new_var(size_overflow_type);
88347 +
88348 + pointer_set_insert(visited, oldstmt);
88349 + phi = overflow_create_phi_node(oldstmt, new_result);
88350 + for (i = 0; i < n; i++) {
88351 + tree arg, lhs;
88352 +
88353 + arg = gimple_phi_arg_def(oldstmt, i);
88354 + if (is_gimple_constant(arg))
88355 + arg = cast_a_tree(size_overflow_type, arg);
88356 + lhs = build_new_phi_arg(visited, size_overflow_type, arg, new_result);
88357 + if (lhs == NULL_TREE)
88358 + lhs = cast_old_phi_arg(oldstmt, size_overflow_type, arg, new_result, i);
88359 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
88360 + }
88361 +
88362 + update_stmt(phi);
88363 + return gimple_phi_result(phi);
88364 +}
88365 +
88366 +static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
88367 +{
88368 + const_gimple assign;
88369 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
88370 + tree origtype = TREE_TYPE(orig_rhs);
88371 +
88372 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
88373 +
88374 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
88375 + return gimple_get_lhs(assign);
88376 +}
88377 +
88378 +static void change_rhs1(gimple stmt, tree new_rhs1)
88379 +{
88380 + tree assign_rhs;
88381 + const_tree rhs = gimple_assign_rhs1(stmt);
88382 +
88383 + assign_rhs = change_assign_rhs(stmt, rhs, new_rhs1);
88384 + gimple_assign_set_rhs1(stmt, assign_rhs);
88385 + update_stmt(stmt);
88386 +}
88387 +
88388 +static bool check_mode_type(const_gimple stmt)
88389 +{
88390 + const_tree lhs = gimple_get_lhs(stmt);
88391 + const_tree lhs_type = TREE_TYPE(lhs);
88392 + const_tree rhs_type = TREE_TYPE(gimple_assign_rhs1(stmt));
88393 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
88394 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
88395 +
88396 + if (rhs_mode == lhs_mode && TYPE_UNSIGNED(rhs_type) == TYPE_UNSIGNED(lhs_type))
88397 + return false;
88398 +
88399 + if (rhs_mode == SImode && lhs_mode == DImode && (TYPE_UNSIGNED(rhs_type) || !TYPE_UNSIGNED(lhs_type)))
88400 + return false;
88401 +
88402 + return true;
88403 +}
88404 +
88405 +static bool check_undefined_integer_operation(const_gimple stmt)
88406 +{
88407 + const_gimple def_stmt;
88408 + const_tree lhs = gimple_get_lhs(stmt);
88409 + const_tree rhs1 = gimple_assign_rhs1(stmt);
88410 + const_tree rhs1_type = TREE_TYPE(rhs1);
88411 + const_tree lhs_type = TREE_TYPE(lhs);
88412 +
88413 + if (TYPE_MODE(rhs1_type) != TYPE_MODE(lhs_type) || TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
88414 + return false;
88415 +
88416 + def_stmt = get_def_stmt(rhs1);
88417 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN)
88418 + return false;
88419 +
88420 + if (gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
88421 + return false;
88422 + return true;
88423 +}
88424 +
88425 +static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
88426 +{
88427 + const_tree rhs1, lhs, rhs1_type, lhs_type;
88428 + enum machine_mode lhs_mode, rhs_mode;
88429 + gimple def_stmt = get_def_stmt(no_const_rhs);
88430 +
88431 + if (!gimple_assign_cast_p(def_stmt))
88432 + return false;
88433 +
88434 + rhs1 = gimple_assign_rhs1(def_stmt);
88435 + lhs = gimple_get_lhs(def_stmt);
88436 + rhs1_type = TREE_TYPE(rhs1);
88437 + lhs_type = TREE_TYPE(lhs);
88438 + rhs_mode = TYPE_MODE(rhs1_type);
88439 + lhs_mode = TYPE_MODE(lhs_type);
88440 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
88441 + return false;
88442 +
88443 + return true;
88444 +}
88445 +
88446 +static tree handle_unary_rhs(struct pointer_set_t *visited, gimple stmt)
88447 +{
88448 + tree size_overflow_type, lhs = gimple_get_lhs(stmt);
88449 + tree new_rhs1, rhs1 = gimple_assign_rhs1(stmt);
88450 + const_tree rhs1_type = TREE_TYPE(rhs1);
88451 + const_tree lhs_type = TREE_TYPE(lhs);
88452 +
88453 + new_rhs1 = expand(visited, rhs1);
88454 +
88455 + if (new_rhs1 == NULL_TREE || TREE_CODE(rhs1_type) == POINTER_TYPE)
88456 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88457 +
88458 + if (gimple_plf(stmt, MY_STMT))
88459 + return lhs;
88460 +
88461 + if (gimple_plf(stmt, NO_CAST_CHECK))
88462 + return follow_overflow_type_and_dup(visited, stmt, rhs1, new_rhs1, NULL_TREE, NULL_TREE);
88463 +
88464 + if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
88465 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
88466 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88467 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
88468 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88469 + }
88470 +
88471 + if (!gimple_assign_cast_p(stmt) || check_undefined_integer_operation(stmt))
88472 + return follow_overflow_type_and_dup(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
88473 +
88474 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
88475 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88476 +
88477 + change_rhs1(stmt, new_rhs1);
88478 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
88479 +
88480 + rhs1 = gimple_assign_rhs1(stmt);
88481 + rhs1_type = TREE_TYPE(rhs1);
88482 + if (TYPE_UNSIGNED(rhs1_type) != TYPE_UNSIGNED(lhs_type))
88483 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
88484 +
88485 + if (!check_mode_type(stmt))
88486 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88487 +
88488 + size_overflow_type = get_size_overflow_type(stmt, lhs);
88489 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88490 +
88491 + check_size_overflow(stmt, size_overflow_type, new_rhs1, lhs, BEFORE_STMT);
88492 +
88493 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88494 +}
88495 +
88496 +static tree handle_unary_ops(struct pointer_set_t *visited, tree lhs)
88497 +{
88498 + gimple def_stmt = get_def_stmt(lhs);
88499 + tree rhs1 = gimple_assign_rhs1(def_stmt);
88500 +
88501 + if (is_gimple_constant(rhs1))
88502 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88503 +
88504 + gcc_assert(TREE_CODE(rhs1) != COND_EXPR);
88505 + switch (TREE_CODE(rhs1)) {
88506 + case SSA_NAME:
88507 + return handle_unary_rhs(visited, def_stmt);
88508 + case ARRAY_REF:
88509 + case BIT_FIELD_REF:
88510 + case ADDR_EXPR:
88511 + case COMPONENT_REF:
88512 + case INDIRECT_REF:
88513 +#if BUILDING_GCC_VERSION >= 4006
88514 + case MEM_REF:
88515 +#endif
88516 + case PARM_DECL:
88517 + case TARGET_MEM_REF:
88518 + case VAR_DECL:
88519 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88520 +
88521 + default:
88522 + debug_gimple_stmt(def_stmt);
88523 + debug_tree(rhs1);
88524 + gcc_unreachable();
88525 + }
88526 +}
88527 +
88528 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
88529 +{
88530 + gimple cond_stmt;
88531 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
88532 +
88533 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
88534 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
88535 + update_stmt(cond_stmt);
88536 +}
88537 +
88538 +static tree create_string_param(tree string)
88539 +{
88540 + tree i_type, a_type;
88541 + const int length = TREE_STRING_LENGTH(string);
88542 +
88543 + gcc_assert(length > 0);
88544 +
88545 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
88546 + a_type = build_array_type(char_type_node, i_type);
88547 +
88548 + TREE_TYPE(string) = a_type;
88549 + TREE_CONSTANT(string) = 1;
88550 + TREE_READONLY(string) = 1;
88551 +
88552 + return build1(ADDR_EXPR, ptr_type_node, string);
88553 +}
88554 +
88555 +static void insert_cond_result(basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
88556 +{
88557 + gimple func_stmt;
88558 + const_gimple def_stmt;
88559 + const_tree loc_line;
88560 + tree loc_file, ssa_name, current_func;
88561 + expanded_location xloc;
88562 + char ssa_name_buf[256];
88563 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
88564 +
88565 + def_stmt = get_def_stmt(arg);
88566 + xloc = expand_location(gimple_location(def_stmt));
88567 +
88568 + if (!gimple_has_location(def_stmt)) {
88569 + xloc = expand_location(gimple_location(stmt));
88570 + if (!gimple_has_location(stmt))
88571 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
88572 + }
88573 +
88574 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
88575 +
88576 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
88577 + loc_file = create_string_param(loc_file);
88578 +
88579 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
88580 + current_func = create_string_param(current_func);
88581 +
88582 + snprintf(ssa_name_buf, 256, "%s_%u (%s)\n", NAME(SSA_NAME_VAR(arg)), SSA_NAME_VERSION(arg), min ? "min" : "max");
88583 + ssa_name = build_string(256, ssa_name_buf);
88584 + ssa_name = create_string_param(ssa_name);
88585 +
88586 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
88587 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
88588 +
88589 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
88590 +}
88591 +
88592 +static void __unused print_the_code_insertions(const_gimple stmt)
88593 +{
88594 + location_t loc = gimple_location(stmt);
88595 +
88596 + inform(loc, "Integer size_overflow check applied here.");
88597 +}
88598 +
88599 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value, bool before, bool min)
88600 +{
88601 + basic_block cond_bb, join_bb, bb_true;
88602 + edge e;
88603 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
88604 +
88605 + cond_bb = gimple_bb(stmt);
88606 + if (before)
88607 + gsi_prev(&gsi);
88608 + if (gsi_end_p(gsi))
88609 + e = split_block_after_labels(cond_bb);
88610 + else
88611 + e = split_block(cond_bb, gsi_stmt(gsi));
88612 + cond_bb = e->src;
88613 + join_bb = e->dest;
88614 + e->flags = EDGE_FALSE_VALUE;
88615 + e->probability = REG_BR_PROB_BASE;
88616 +
88617 + bb_true = create_empty_bb(cond_bb);
88618 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
88619 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
88620 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
88621 +
88622 + if (dom_info_available_p(CDI_DOMINATORS)) {
88623 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
88624 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
88625 + }
88626 +
88627 + if (current_loops != NULL) {
88628 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
88629 + add_bb_to_loop(bb_true, cond_bb->loop_father);
88630 + }
88631 +
88632 + insert_cond(cond_bb, arg, cond_code, type_value);
88633 + insert_cond_result(bb_true, stmt, arg, min);
88634 +
88635 +// print_the_code_insertions(stmt);
88636 +}
88637 +
88638 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
88639 +{
88640 + const_tree rhs_type = TREE_TYPE(rhs);
88641 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
88642 +
88643 + gcc_assert(rhs_type != NULL_TREE);
88644 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
88645 + return;
88646 +
88647 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == BOOLEAN_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
88648 +
88649 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
88650 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
88651 +
88652 + gcc_assert(!TREE_OVERFLOW(type_max));
88653 +
88654 + cast_rhs_type = TREE_TYPE(cast_rhs);
88655 + type_max_type = TREE_TYPE(type_max);
88656 + type_min_type = TREE_TYPE(type_min);
88657 + gcc_assert(useless_type_conversion_p(cast_rhs_type, type_max_type));
88658 + gcc_assert(useless_type_conversion_p(type_max_type, type_min_type));
88659 +
88660 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max, before, false);
88661 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min, before, true);
88662 +}
88663 +
88664 +static tree get_size_overflow_type_for_intentional_overflow(gimple def_stmt, tree change_rhs)
88665 +{
88666 + gimple change_rhs_def_stmt;
88667 + tree lhs = gimple_get_lhs(def_stmt);
88668 + tree lhs_type = TREE_TYPE(lhs);
88669 + tree rhs1_type = TREE_TYPE(gimple_assign_rhs1(def_stmt));
88670 + tree rhs2_type = TREE_TYPE(gimple_assign_rhs2(def_stmt));
88671 +
88672 + if (change_rhs == NULL_TREE)
88673 + return get_size_overflow_type(def_stmt, lhs);
88674 +
88675 + change_rhs_def_stmt = get_def_stmt(change_rhs);
88676 +
88677 + if (TREE_CODE_CLASS(gimple_assign_rhs_code(def_stmt)) == tcc_comparison)
88678 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
88679 +
88680 + if (gimple_assign_rhs_code(def_stmt) == LSHIFT_EXPR)
88681 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
88682 +
88683 + if (gimple_assign_rhs_code(def_stmt) == RSHIFT_EXPR)
88684 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
88685 +
88686 + if (!useless_type_conversion_p(lhs_type, rhs1_type) || !useless_type_conversion_p(rhs1_type, rhs2_type)) {
88687 + debug_gimple_stmt(def_stmt);
88688 + gcc_unreachable();
88689 + }
88690 +
88691 + return get_size_overflow_type(def_stmt, lhs);
88692 +}
88693 +
88694 +static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
88695 +{
88696 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
88697 + return false;
88698 + if (!is_gimple_constant(rhs))
88699 + return false;
88700 + return true;
88701 +}
88702 +
88703 +static tree get_cast_def_stmt_rhs(const_tree new_rhs)
88704 +{
88705 + gimple def_stmt;
88706 +
88707 + def_stmt = get_def_stmt(new_rhs);
88708 + // get_size_overflow_type
88709 + if (LONG_TYPE_SIZE != GET_MODE_BITSIZE(SImode))
88710 + gcc_assert(gimple_assign_cast_p(def_stmt));
88711 + return gimple_assign_rhs1(def_stmt);
88712 +}
88713 +
88714 +static tree cast_to_int_TI_type_and_check(gimple stmt, tree new_rhs)
88715 +{
88716 + gimple_stmt_iterator gsi;
88717 + const_gimple cast_stmt;
88718 + gimple def_stmt;
88719 + enum machine_mode mode = TYPE_MODE(TREE_TYPE(new_rhs));
88720 +
88721 + if (mode != TImode && mode != DImode) {
88722 + def_stmt = get_def_stmt(new_rhs);
88723 + gcc_assert(gimple_assign_cast_p(def_stmt));
88724 + new_rhs = gimple_assign_rhs1(def_stmt);
88725 + mode = TYPE_MODE(TREE_TYPE(new_rhs));
88726 + }
88727 +
88728 + gcc_assert(mode == TImode || mode == DImode);
88729 +
88730 + if (mode == TYPE_MODE(intTI_type_node) && useless_type_conversion_p(TREE_TYPE(new_rhs), intTI_type_node))
88731 + return new_rhs;
88732 +
88733 + gsi = gsi_for_stmt(stmt);
88734 + cast_stmt = build_cast_stmt(intTI_type_node, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
88735 + new_rhs = gimple_get_lhs(cast_stmt);
88736 +
88737 + if (mode == DImode)
88738 + return new_rhs;
88739 +
88740 + check_size_overflow(stmt, intTI_type_node, new_rhs, new_rhs, BEFORE_STMT);
88741 +
88742 + return new_rhs;
88743 +}
88744 +
88745 +static bool is_an_integer_trunction(const_gimple stmt)
88746 +{
88747 + gimple rhs1_def_stmt, rhs2_def_stmt;
88748 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1;
88749 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode;
88750 + const_tree rhs1 = gimple_assign_rhs1(stmt);
88751 + const_tree rhs2 = gimple_assign_rhs2(stmt);
88752 + enum machine_mode rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1));
88753 + enum machine_mode rhs2_mode = TYPE_MODE(TREE_TYPE(rhs2));
88754 +
88755 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
88756 + return false;
88757 +
88758 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
88759 +
88760 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR || rhs1_mode != SImode || rhs2_mode != SImode)
88761 + return false;
88762 +
88763 + rhs1_def_stmt = get_def_stmt(rhs1);
88764 + rhs2_def_stmt = get_def_stmt(rhs2);
88765 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
88766 + return false;
88767 +
88768 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
88769 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
88770 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
88771 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
88772 + if (rhs1_def_stmt_rhs1_mode != DImode || rhs2_def_stmt_rhs1_mode != DImode)
88773 + return false;
88774 +
88775 + gimple_set_plf(rhs1_def_stmt, NO_CAST_CHECK, true);
88776 + gimple_set_plf(rhs2_def_stmt, NO_CAST_CHECK, true);
88777 + return true;
88778 +}
88779 +
88780 +static tree handle_integer_truncation(struct pointer_set_t *visited, const_tree lhs)
88781 +{
88782 + tree new_rhs1, new_rhs2;
88783 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
88784 + tree new_rhs1_def_stmt_rhs1_type, new_rhs2_def_stmt_rhs1_type;
88785 + gimple assign, stmt = get_def_stmt(lhs);
88786 + tree rhs1 = gimple_assign_rhs1(stmt);
88787 + tree rhs2 = gimple_assign_rhs2(stmt);
88788 +
88789 + if (!is_an_integer_trunction(stmt))
88790 + return NULL_TREE;
88791 +
88792 + new_rhs1 = expand(visited, rhs1);
88793 + new_rhs2 = expand(visited, rhs2);
88794 +
88795 + new_rhs1_def_stmt_rhs1 = get_cast_def_stmt_rhs(new_rhs1);
88796 + new_rhs2_def_stmt_rhs1 = get_cast_def_stmt_rhs(new_rhs2);
88797 +
88798 + new_rhs1_def_stmt_rhs1_type = TREE_TYPE(new_rhs1_def_stmt_rhs1);
88799 + new_rhs2_def_stmt_rhs1_type = TREE_TYPE(new_rhs2_def_stmt_rhs1);
88800 +
88801 + if (!useless_type_conversion_p(new_rhs1_def_stmt_rhs1_type, new_rhs2_def_stmt_rhs1_type)) {
88802 + new_rhs1_def_stmt_rhs1 = cast_to_int_TI_type_and_check(stmt, new_rhs1_def_stmt_rhs1);
88803 + new_rhs2_def_stmt_rhs1 = cast_to_int_TI_type_and_check(stmt, new_rhs2_def_stmt_rhs1);
88804 + }
88805 +
88806 + assign = create_binary_assign(MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
88807 + new_lhs = gimple_get_lhs(assign);
88808 + check_size_overflow(assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
88809 +
88810 + return follow_overflow_type_and_dup(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
88811 +}
88812 +
88813 +static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
88814 +{
88815 + const_gimple def_stmt;
88816 +
88817 + if (TREE_CODE(rhs) != SSA_NAME)
88818 + return false;
88819 +
88820 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
88821 + return false;
88822 +
88823 + def_stmt = get_def_stmt(rhs);
88824 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
88825 + return false;
88826 +
88827 + return true;
88828 +}
88829 +
88830 +static tree handle_intentional_overflow(struct pointer_set_t *visited, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs1, tree new_rhs2)
88831 +{
88832 + tree new_rhs, size_overflow_type, orig_rhs;
88833 + void (*gimple_assign_set_rhs)(gimple, tree);
88834 + tree rhs1 = gimple_assign_rhs1(stmt);
88835 + tree rhs2 = gimple_assign_rhs2(stmt);
88836 + tree lhs = gimple_get_lhs(stmt);
88837 +
88838 + if (change_rhs == NULL_TREE)
88839 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88840 +
88841 + if (new_rhs2 == NULL_TREE) {
88842 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs1);
88843 + new_rhs2 = cast_a_tree(size_overflow_type, rhs2);
88844 + orig_rhs = rhs1;
88845 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
88846 + } else {
88847 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs2);
88848 + new_rhs1 = cast_a_tree(size_overflow_type, rhs1);
88849 + orig_rhs = rhs2;
88850 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
88851 + }
88852 +
88853 + change_rhs = cast_to_new_size_overflow_type(stmt, change_rhs, size_overflow_type, BEFORE_STMT);
88854 +
88855 + if (check_overflow)
88856 + check_size_overflow(stmt, size_overflow_type, change_rhs, orig_rhs, BEFORE_STMT);
88857 +
88858 + new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
88859 + gimple_assign_set_rhs(stmt, new_rhs);
88860 + update_stmt(stmt);
88861 +
88862 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88863 +}
88864 +
88865 +static tree handle_binary_ops(struct pointer_set_t *visited, tree lhs)
88866 +{
88867 + tree rhs1, rhs2, new_lhs;
88868 + gimple def_stmt = get_def_stmt(lhs);
88869 + tree new_rhs1 = NULL_TREE;
88870 + tree new_rhs2 = NULL_TREE;
88871 +
88872 + rhs1 = gimple_assign_rhs1(def_stmt);
88873 + rhs2 = gimple_assign_rhs2(def_stmt);
88874 +
88875 + /* no DImode/TImode division in the 32/64 bit kernel */
88876 + switch (gimple_assign_rhs_code(def_stmt)) {
88877 + case RDIV_EXPR:
88878 + case TRUNC_DIV_EXPR:
88879 + case CEIL_DIV_EXPR:
88880 + case FLOOR_DIV_EXPR:
88881 + case ROUND_DIV_EXPR:
88882 + case TRUNC_MOD_EXPR:
88883 + case CEIL_MOD_EXPR:
88884 + case FLOOR_MOD_EXPR:
88885 + case ROUND_MOD_EXPR:
88886 + case EXACT_DIV_EXPR:
88887 + case POINTER_PLUS_EXPR:
88888 + case BIT_AND_EXPR:
88889 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88890 + default:
88891 + break;
88892 + }
88893 +
88894 + new_lhs = handle_integer_truncation(visited, lhs);
88895 + if (new_lhs != NULL_TREE)
88896 + return new_lhs;
88897 +
88898 + if (TREE_CODE(rhs1) == SSA_NAME)
88899 + new_rhs1 = expand(visited, rhs1);
88900 + if (TREE_CODE(rhs2) == SSA_NAME)
88901 + new_rhs2 = expand(visited, rhs2);
88902 +
88903 + if (is_a_neg_overflow(def_stmt, rhs2))
88904 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs1, new_rhs1, NULL_TREE);
88905 + if (is_a_neg_overflow(def_stmt, rhs1))
88906 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs2, NULL_TREE, new_rhs2);
88907 +
88908 + if (is_a_constant_overflow(def_stmt, rhs2))
88909 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, new_rhs1, NULL_TREE);
88910 + if (is_a_constant_overflow(def_stmt, rhs1))
88911 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, NULL_TREE, new_rhs2);
88912 +
88913 + return follow_overflow_type_and_dup(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
88914 +}
88915 +
88916 +#if BUILDING_GCC_VERSION >= 4007
88917 +static tree get_new_rhs(struct pointer_set_t *visited, tree size_overflow_type, tree rhs)
88918 +{
88919 + if (is_gimple_constant(rhs))
88920 + return cast_a_tree(size_overflow_type, rhs);
88921 + if (TREE_CODE(rhs) != SSA_NAME)
88922 + return NULL_TREE;
88923 + return expand(visited, rhs);
88924 +}
88925 +
88926 +static tree handle_ternary_ops(struct pointer_set_t *visited, tree lhs)
88927 +{
88928 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
88929 + gimple def_stmt = get_def_stmt(lhs);
88930 +
88931 + size_overflow_type = get_size_overflow_type(def_stmt, lhs);
88932 +
88933 + rhs1 = gimple_assign_rhs1(def_stmt);
88934 + rhs2 = gimple_assign_rhs2(def_stmt);
88935 + rhs3 = gimple_assign_rhs3(def_stmt);
88936 + new_rhs1 = get_new_rhs(visited, size_overflow_type, rhs1);
88937 + new_rhs2 = get_new_rhs(visited, size_overflow_type, rhs2);
88938 + new_rhs3 = get_new_rhs(visited, size_overflow_type, rhs3);
88939 +
88940 + return follow_overflow_type_and_dup(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
88941 +}
88942 +#endif
88943 +
88944 +static tree get_size_overflow_type(gimple stmt, const_tree node)
88945 +{
88946 + const_tree type;
88947 +
88948 + gcc_assert(node != NULL_TREE);
88949 +
88950 + type = TREE_TYPE(node);
88951 +
88952 + if (gimple_plf(stmt, MY_STMT))
88953 + return TREE_TYPE(node);
88954 +
88955 + switch (TYPE_MODE(type)) {
88956 + case QImode:
88957 + return (TYPE_UNSIGNED(type)) ? unsigned_intHI_type_node : intHI_type_node;
88958 + case HImode:
88959 + return (TYPE_UNSIGNED(type)) ? unsigned_intSI_type_node : intSI_type_node;
88960 + case SImode:
88961 + return (TYPE_UNSIGNED(type)) ? unsigned_intDI_type_node : intDI_type_node;
88962 + case DImode:
88963 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
88964 + return (TYPE_UNSIGNED(type)) ? unsigned_intDI_type_node : intDI_type_node;
88965 + return (TYPE_UNSIGNED(type)) ? unsigned_intTI_type_node : intTI_type_node;
88966 + default:
88967 + debug_tree((tree)node);
88968 + error("%s: unsupported gcc configuration.", __func__);
88969 + gcc_unreachable();
88970 + }
88971 +}
88972 +
88973 +static tree expand_visited(gimple def_stmt)
88974 +{
88975 + const_gimple next_stmt;
88976 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
88977 +
88978 + gsi_next(&gsi);
88979 + next_stmt = gsi_stmt(gsi);
88980 +
88981 + gcc_assert(gimple_plf((gimple)next_stmt, MY_STMT));
88982 +
88983 + switch (gimple_code(next_stmt)) {
88984 + case GIMPLE_ASSIGN:
88985 + return gimple_get_lhs(next_stmt);
88986 + case GIMPLE_PHI:
88987 + return gimple_phi_result(next_stmt);
88988 + case GIMPLE_CALL:
88989 + return gimple_call_lhs(next_stmt);
88990 + default:
88991 + return NULL_TREE;
88992 + }
88993 +}
88994 +
88995 +static tree expand(struct pointer_set_t *visited, tree lhs)
88996 +{
88997 + gimple def_stmt;
88998 + enum tree_code code = TREE_CODE(TREE_TYPE(lhs));
88999 +
89000 + if (is_gimple_constant(lhs))
89001 + return NULL_TREE;
89002 +
89003 + if (TREE_CODE(lhs) == ADDR_EXPR)
89004 + return NULL_TREE;
89005 +
89006 + if (code == REAL_TYPE)
89007 + return NULL_TREE;
89008 +
89009 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE || code == ENUMERAL_TYPE);
89010 +
89011 +
89012 + def_stmt = get_def_stmt(lhs);
89013 +
89014 + if (!def_stmt)
89015 + return NULL_TREE;
89016 +
89017 + if (gimple_plf(def_stmt, MY_STMT))
89018 + return lhs;
89019 +
89020 + if (pointer_set_contains(visited, def_stmt))
89021 + return expand_visited(def_stmt);
89022 +
89023 + switch (gimple_code(def_stmt)) {
89024 + case GIMPLE_NOP:
89025 + return NULL_TREE;
89026 + case GIMPLE_PHI:
89027 + return build_new_phi(visited, lhs);
89028 + case GIMPLE_CALL:
89029 + case GIMPLE_ASM:
89030 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
89031 + case GIMPLE_ASSIGN:
89032 + switch (gimple_num_ops(def_stmt)) {
89033 + case 2:
89034 + return handle_unary_ops(visited, lhs);
89035 + case 3:
89036 + return handle_binary_ops(visited, lhs);
89037 +#if BUILDING_GCC_VERSION >= 4007
89038 + case 4:
89039 + return handle_ternary_ops(visited, lhs);
89040 +#endif
89041 + }
89042 + default:
89043 + debug_gimple_stmt(def_stmt);
89044 + error("%s: unknown gimple code", __func__);
89045 + gcc_unreachable();
89046 + }
89047 +}
89048 +
89049 +static void change_function_arg(gimple stmt, const_tree origarg, unsigned int argnum, tree newarg)
89050 +{
89051 + const_gimple assign;
89052 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
89053 + tree origtype = TREE_TYPE(origarg);
89054 +
89055 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
89056 +
89057 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
89058 +
89059 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
89060 + update_stmt(stmt);
89061 +}
89062 +
89063 +static bool get_function_arg(unsigned int* argnum, const_tree fndecl)
89064 +{
89065 + const char *origid;
89066 + tree arg;
89067 + const_tree origarg;
89068 +
89069 + if (!DECL_ABSTRACT_ORIGIN(fndecl))
89070 + return true;
89071 +
89072 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
89073 + while (origarg && *argnum) {
89074 + (*argnum)--;
89075 + origarg = TREE_CHAIN(origarg);
89076 + }
89077 +
89078 + gcc_assert(*argnum == 0);
89079 +
89080 + gcc_assert(origarg != NULL_TREE);
89081 + origid = NAME(origarg);
89082 + *argnum = 0;
89083 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
89084 + if (!strcmp(origid, NAME(arg)))
89085 + return true;
89086 + (*argnum)++;
89087 + }
89088 + return false;
89089 +}
89090 +
89091 +static bool skip_types(const_tree var)
89092 +{
89093 + switch (TREE_CODE(var)) {
89094 + case ADDR_EXPR:
89095 +#if BUILDING_GCC_VERSION >= 4006
89096 + case MEM_REF:
89097 +#endif
89098 + case ARRAY_REF:
89099 + case BIT_FIELD_REF:
89100 + case INDIRECT_REF:
89101 + case TARGET_MEM_REF:
89102 + case VAR_DECL:
89103 + return true;
89104 + default:
89105 + break;
89106 + }
89107 + return false;
89108 +}
89109 +
89110 +static bool walk_phi(struct pointer_set_t *visited, const_tree result)
89111 +{
89112 + gimple phi = get_def_stmt(result);
89113 + unsigned int i, n = gimple_phi_num_args(phi);
89114 +
89115 + if (!phi)
89116 + return false;
89117 +
89118 + pointer_set_insert(visited, phi);
89119 + for (i = 0; i < n; i++) {
89120 + const_tree arg = gimple_phi_arg_def(phi, i);
89121 + if (pre_expand(visited, arg))
89122 + return true;
89123 + }
89124 + return false;
89125 +}
89126 +
89127 +static bool walk_unary_ops(struct pointer_set_t *visited, const_tree lhs)
89128 +{
89129 + gimple def_stmt = get_def_stmt(lhs);
89130 + const_tree rhs;
89131 +
89132 + if (!def_stmt)
89133 + return false;
89134 +
89135 + rhs = gimple_assign_rhs1(def_stmt);
89136 + if (pre_expand(visited, rhs))
89137 + return true;
89138 + return false;
89139 +}
89140 +
89141 +static bool walk_binary_ops(struct pointer_set_t *visited, const_tree lhs)
89142 +{
89143 + bool rhs1_found, rhs2_found;
89144 + gimple def_stmt = get_def_stmt(lhs);
89145 + const_tree rhs1, rhs2;
89146 +
89147 + if (!def_stmt)
89148 + return false;
89149 +
89150 + rhs1 = gimple_assign_rhs1(def_stmt);
89151 + rhs2 = gimple_assign_rhs2(def_stmt);
89152 + rhs1_found = pre_expand(visited, rhs1);
89153 + rhs2_found = pre_expand(visited, rhs2);
89154 +
89155 + return rhs1_found || rhs2_found;
89156 +}
89157 +
89158 +static const_tree search_field_decl(const_tree comp_ref)
89159 +{
89160 + const_tree field = NULL_TREE;
89161 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
89162 +
89163 + for (i = 0; i < len; i++) {
89164 + field = TREE_OPERAND(comp_ref, i);
89165 + if (TREE_CODE(field) == FIELD_DECL)
89166 + break;
89167 + }
89168 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
89169 + return field;
89170 +}
89171 +
89172 +static enum marked mark_status(const_tree fndecl, unsigned int argnum)
89173 +{
89174 + const_tree attr, p;
89175 +
89176 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(fndecl));
89177 + if (!attr || !TREE_VALUE(attr))
89178 + return MARKED_NO;
89179 +
89180 + p = TREE_VALUE(attr);
89181 + if (!TREE_INT_CST_LOW(TREE_VALUE(p)))
89182 + return MARKED_NOT_INTENTIONAL;
89183 +
89184 + do {
89185 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(p)))
89186 + return MARKED_YES;
89187 + p = TREE_CHAIN(p);
89188 + } while (p);
89189 +
89190 + return MARKED_NO;
89191 +}
89192 +
89193 +static void print_missing_msg(tree func, unsigned int argnum)
89194 +{
89195 + unsigned int new_hash;
89196 + size_t len;
89197 + unsigned char tree_codes[CODES_LIMIT];
89198 + location_t loc = DECL_SOURCE_LOCATION(func);
89199 + const char *curfunc = get_asm_name(func);
89200 +
89201 + len = get_function_decl(func, tree_codes);
89202 + new_hash = get_hash_num(curfunc, (const char *) tree_codes, len, 0);
89203 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, new_hash);
89204 +}
89205 +
89206 +static unsigned int search_missing_attribute(const_tree arg)
89207 +{
89208 + const_tree type = TREE_TYPE(arg);
89209 + tree func = get_original_function_decl(current_function_decl);
89210 + unsigned int argnum;
89211 + const struct size_overflow_hash *hash;
89212 +
89213 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
89214 +
89215 + if (TREE_CODE(type) == POINTER_TYPE)
89216 + return 0;
89217 +
89218 + argnum = find_arg_number(arg, func);
89219 + if (argnum == 0)
89220 + return 0;
89221 +
89222 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(func)))
89223 + return argnum;
89224 +
89225 + hash = get_function_hash(func);
89226 + if (!hash || !(hash->param & (1U << argnum))) {
89227 + print_missing_msg(func, argnum);
89228 + return 0;
89229 + }
89230 + return argnum;
89231 +}
89232 +
89233 +static bool is_already_marked(const_tree lhs)
89234 +{
89235 + unsigned int argnum;
89236 + const_tree fndecl;
89237 +
89238 + argnum = search_missing_attribute(lhs);
89239 + fndecl = get_original_function_decl(current_function_decl);
89240 + if (argnum && mark_status(fndecl, argnum) == MARKED_YES)
89241 + return true;
89242 + return false;
89243 +}
89244 +
89245 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs)
89246 +{
89247 + const_gimple def_stmt;
89248 +
89249 + if (is_gimple_constant(lhs))
89250 + return false;
89251 +
89252 + if (skip_types(lhs))
89253 + return false;
89254 +
89255 + if (TREE_CODE(lhs) == PARM_DECL)
89256 + return is_already_marked(lhs);
89257 +
89258 + if (TREE_CODE(lhs) == COMPONENT_REF) {
89259 + const_tree field, attr;
89260 +
89261 + field = search_field_decl(lhs);
89262 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(field));
89263 + if (!attr || !TREE_VALUE(attr))
89264 + return false;
89265 + return true;
89266 + }
89267 +
89268 + def_stmt = get_def_stmt(lhs);
89269 +
89270 + if (!def_stmt)
89271 + return false;
89272 +
89273 + if (pointer_set_contains(visited, def_stmt))
89274 + return false;
89275 +
89276 + switch (gimple_code(def_stmt)) {
89277 + case GIMPLE_NOP:
89278 + if (TREE_CODE(SSA_NAME_VAR(lhs)) == PARM_DECL)
89279 + return is_already_marked(lhs);
89280 + return false;
89281 + case GIMPLE_PHI:
89282 + return walk_phi(visited, lhs);
89283 + case GIMPLE_CALL:
89284 + case GIMPLE_ASM:
89285 + return false;
89286 + case GIMPLE_ASSIGN:
89287 + switch (gimple_num_ops(def_stmt)) {
89288 + case 2:
89289 + return walk_unary_ops(visited, lhs);
89290 + case 3:
89291 + return walk_binary_ops(visited, lhs);
89292 + }
89293 + default:
89294 + debug_gimple_stmt((gimple)def_stmt);
89295 + error("%s: unknown gimple code", __func__);
89296 + gcc_unreachable();
89297 + }
89298 +}
89299 +
89300 +static bool search_attributes(tree fndecl, const_tree arg, unsigned int argnum)
89301 +{
89302 + struct pointer_set_t *visited;
89303 + bool is_found;
89304 + enum marked is_marked;
89305 + location_t loc;
89306 +
89307 + visited = pointer_set_create();
89308 + is_found = pre_expand(visited, arg);
89309 + pointer_set_destroy(visited);
89310 +
89311 + is_marked = mark_status(fndecl, argnum + 1);
89312 + if ((is_found && is_marked == MARKED_YES) || is_marked == MARKED_NOT_INTENTIONAL)
89313 + return true;
89314 +
89315 + if (is_found) {
89316 + loc = DECL_SOURCE_LOCATION(fndecl);
89317 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", get_asm_name(fndecl), argnum + 1);
89318 + return true;
89319 + }
89320 + return false;
89321 +}
89322 +
89323 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
89324 +{
89325 + struct pointer_set_t *visited;
89326 + tree arg, newarg;
89327 + bool match;
89328 +
89329 + match = get_function_arg(&argnum, fndecl);
89330 + if (!match)
89331 + return;
89332 + gcc_assert(gimple_call_num_args(stmt) > argnum);
89333 + arg = gimple_call_arg(stmt, argnum);
89334 + if (arg == NULL_TREE)
89335 + return;
89336 +
89337 + if (is_gimple_constant(arg))
89338 + return;
89339 +
89340 + if (search_attributes(fndecl, arg, argnum))
89341 + return;
89342 +
89343 + if (TREE_CODE(arg) != SSA_NAME)
89344 + return;
89345 +
89346 + check_arg_type(arg);
89347 +
89348 + visited = pointer_set_create();
89349 + newarg = expand(visited, arg);
89350 + pointer_set_destroy(visited);
89351 +
89352 + if (newarg == NULL_TREE)
89353 + return;
89354 +
89355 + change_function_arg(stmt, arg, argnum, newarg);
89356 +
89357 + check_size_overflow(stmt, TREE_TYPE(newarg), newarg, arg, BEFORE_STMT);
89358 +}
89359 +
89360 +static void handle_function_by_attribute(gimple stmt, const_tree attr, tree fndecl)
89361 +{
89362 + tree p = TREE_VALUE(attr);
89363 + do {
89364 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
89365 + p = TREE_CHAIN(p);
89366 + } while (p);
89367 +}
89368 +
89369 +static void handle_function_by_hash(gimple stmt, tree fndecl)
89370 +{
89371 + tree orig_fndecl;
89372 + unsigned int num;
89373 + const struct size_overflow_hash *hash;
89374 +
89375 + orig_fndecl = get_original_function_decl(fndecl);
89376 + if (C_DECL_IMPLICIT(orig_fndecl))
89377 + return;
89378 + hash = get_function_hash(orig_fndecl);
89379 + if (!hash)
89380 + return;
89381 +
89382 + for (num = 1; num <= MAX_PARAM; num++)
89383 + if (hash->param & (1U << num))
89384 + handle_function_arg(stmt, fndecl, num - 1);
89385 +}
89386 +
89387 +static void set_plf_false(void)
89388 +{
89389 + basic_block bb;
89390 +
89391 + FOR_ALL_BB(bb) {
89392 + gimple_stmt_iterator si;
89393 +
89394 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
89395 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
89396 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
89397 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
89398 + }
89399 +}
89400 +
89401 +static unsigned int handle_function(void)
89402 +{
89403 + basic_block next, bb = ENTRY_BLOCK_PTR->next_bb;
89404 +
89405 + set_plf_false();
89406 +
89407 + do {
89408 + gimple_stmt_iterator gsi;
89409 + next = bb->next_bb;
89410 +
89411 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
89412 + tree fndecl, attr;
89413 + gimple stmt = gsi_stmt(gsi);
89414 +
89415 + if (!(is_gimple_call(stmt)))
89416 + continue;
89417 + fndecl = gimple_call_fndecl(stmt);
89418 + if (fndecl == NULL_TREE)
89419 + continue;
89420 + if (gimple_call_num_args(stmt) == 0)
89421 + continue;
89422 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
89423 + if (!attr || !TREE_VALUE(attr))
89424 + handle_function_by_hash(stmt, fndecl);
89425 + else
89426 + handle_function_by_attribute(stmt, attr, fndecl);
89427 + gsi = gsi_for_stmt(stmt);
89428 + next = gimple_bb(stmt)->next_bb;
89429 + }
89430 + bb = next;
89431 + } while (bb);
89432 + return 0;
89433 +}
89434 +
89435 +static struct gimple_opt_pass size_overflow_pass = {
89436 + .pass = {
89437 + .type = GIMPLE_PASS,
89438 + .name = "size_overflow",
89439 + .gate = NULL,
89440 + .execute = handle_function,
89441 + .sub = NULL,
89442 + .next = NULL,
89443 + .static_pass_number = 0,
89444 + .tv_id = TV_NONE,
89445 + .properties_required = PROP_cfg | PROP_referenced_vars,
89446 + .properties_provided = 0,
89447 + .properties_destroyed = 0,
89448 + .todo_flags_start = 0,
89449 + .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
89450 + }
89451 +};
89452 +
89453 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
89454 +{
89455 + tree fntype;
89456 +
89457 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
89458 +
89459 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
89460 + fntype = build_function_type_list(void_type_node,
89461 + const_char_ptr_type_node,
89462 + unsigned_type_node,
89463 + const_char_ptr_type_node,
89464 + const_char_ptr_type_node,
89465 + NULL_TREE);
89466 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
89467 +
89468 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
89469 + TREE_PUBLIC(report_size_overflow_decl) = 1;
89470 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
89471 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
89472 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
89473 +}
89474 +
89475 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
89476 +{
89477 + int i;
89478 + const char * const plugin_name = plugin_info->base_name;
89479 + const int argc = plugin_info->argc;
89480 + const struct plugin_argument * const argv = plugin_info->argv;
89481 + bool enable = true;
89482 +
89483 + struct register_pass_info size_overflow_pass_info = {
89484 + .pass = &size_overflow_pass.pass,
89485 + .reference_pass_name = "ssa",
89486 + .ref_pass_instance_number = 1,
89487 + .pos_op = PASS_POS_INSERT_AFTER
89488 + };
89489 +
89490 + if (!plugin_default_version_check(version, &gcc_version)) {
89491 + error(G_("incompatible gcc/plugin versions"));
89492 + return 1;
89493 + }
89494 +
89495 + for (i = 0; i < argc; ++i) {
89496 + if (!strcmp(argv[i].key, "no-size-overflow")) {
89497 + enable = false;
89498 + continue;
89499 + }
89500 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
89501 + }
89502 +
89503 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
89504 + if (enable) {
89505 + register_callback("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
89506 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
89507 + }
89508 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
89509 +
89510 + return 0;
89511 +}
89512 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
89513 new file mode 100644
89514 index 0000000..38d2014
89515 --- /dev/null
89516 +++ b/tools/gcc/stackleak_plugin.c
89517 @@ -0,0 +1,313 @@
89518 +/*
89519 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
89520 + * Licensed under the GPL v2
89521 + *
89522 + * Note: the choice of the license means that the compilation process is
89523 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
89524 + * but for the kernel it doesn't matter since it doesn't link against
89525 + * any of the gcc libraries
89526 + *
89527 + * gcc plugin to help implement various PaX features
89528 + *
89529 + * - track lowest stack pointer
89530 + *
89531 + * TODO:
89532 + * - initialize all local variables
89533 + *
89534 + * BUGS:
89535 + * - none known
89536 + */
89537 +#include "gcc-plugin.h"
89538 +#include "config.h"
89539 +#include "system.h"
89540 +#include "coretypes.h"
89541 +#include "tree.h"
89542 +#include "tree-pass.h"
89543 +#include "flags.h"
89544 +#include "intl.h"
89545 +#include "toplev.h"
89546 +#include "plugin.h"
89547 +//#include "expr.h" where are you...
89548 +#include "diagnostic.h"
89549 +#include "plugin-version.h"
89550 +#include "tm.h"
89551 +#include "function.h"
89552 +#include "basic-block.h"
89553 +#include "gimple.h"
89554 +#include "rtl.h"
89555 +#include "emit-rtl.h"
89556 +
89557 +extern void print_gimple_stmt(FILE *, gimple, int, int);
89558 +
89559 +int plugin_is_GPL_compatible;
89560 +
89561 +static int track_frame_size = -1;
89562 +static const char track_function[] = "pax_track_stack";
89563 +static const char check_function[] = "pax_check_alloca";
89564 +static bool init_locals;
89565 +
89566 +static struct plugin_info stackleak_plugin_info = {
89567 + .version = "201203140940",
89568 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
89569 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
89570 +};
89571 +
89572 +static bool gate_stackleak_track_stack(void);
89573 +static unsigned int execute_stackleak_tree_instrument(void);
89574 +static unsigned int execute_stackleak_final(void);
89575 +
89576 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
89577 + .pass = {
89578 + .type = GIMPLE_PASS,
89579 + .name = "stackleak_tree_instrument",
89580 + .gate = gate_stackleak_track_stack,
89581 + .execute = execute_stackleak_tree_instrument,
89582 + .sub = NULL,
89583 + .next = NULL,
89584 + .static_pass_number = 0,
89585 + .tv_id = TV_NONE,
89586 + .properties_required = PROP_gimple_leh | PROP_cfg,
89587 + .properties_provided = 0,
89588 + .properties_destroyed = 0,
89589 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
89590 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
89591 + }
89592 +};
89593 +
89594 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
89595 + .pass = {
89596 + .type = RTL_PASS,
89597 + .name = "stackleak_final",
89598 + .gate = gate_stackleak_track_stack,
89599 + .execute = execute_stackleak_final,
89600 + .sub = NULL,
89601 + .next = NULL,
89602 + .static_pass_number = 0,
89603 + .tv_id = TV_NONE,
89604 + .properties_required = 0,
89605 + .properties_provided = 0,
89606 + .properties_destroyed = 0,
89607 + .todo_flags_start = 0,
89608 + .todo_flags_finish = TODO_dump_func
89609 + }
89610 +};
89611 +
89612 +static bool gate_stackleak_track_stack(void)
89613 +{
89614 + return track_frame_size >= 0;
89615 +}
89616 +
89617 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
89618 +{
89619 + gimple check_alloca;
89620 + tree fntype, fndecl, alloca_size;
89621 +
89622 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
89623 + fndecl = build_fn_decl(check_function, fntype);
89624 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
89625 +
89626 + // insert call to void pax_check_alloca(unsigned long size)
89627 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
89628 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
89629 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
89630 +}
89631 +
89632 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
89633 +{
89634 + gimple track_stack;
89635 + tree fntype, fndecl;
89636 +
89637 + fntype = build_function_type_list(void_type_node, NULL_TREE);
89638 + fndecl = build_fn_decl(track_function, fntype);
89639 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
89640 +
89641 + // insert call to void pax_track_stack(void)
89642 + track_stack = gimple_build_call(fndecl, 0);
89643 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
89644 +}
89645 +
89646 +#if BUILDING_GCC_VERSION == 4005
89647 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
89648 +{
89649 + tree fndecl;
89650 +
89651 + if (!is_gimple_call(stmt))
89652 + return false;
89653 + fndecl = gimple_call_fndecl(stmt);
89654 + if (!fndecl)
89655 + return false;
89656 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
89657 + return false;
89658 +// print_node(stderr, "pax", fndecl, 4);
89659 + return DECL_FUNCTION_CODE(fndecl) == code;
89660 +}
89661 +#endif
89662 +
89663 +static bool is_alloca(gimple stmt)
89664 +{
89665 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
89666 + return true;
89667 +
89668 +#if BUILDING_GCC_VERSION >= 4007
89669 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
89670 + return true;
89671 +#endif
89672 +
89673 + return false;
89674 +}
89675 +
89676 +static unsigned int execute_stackleak_tree_instrument(void)
89677 +{
89678 + basic_block bb, entry_bb;
89679 + bool prologue_instrumented = false, is_leaf = true;
89680 +
89681 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
89682 +
89683 + // 1. loop through BBs and GIMPLE statements
89684 + FOR_EACH_BB(bb) {
89685 + gimple_stmt_iterator gsi;
89686 +
89687 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
89688 + gimple stmt;
89689 +
89690 + stmt = gsi_stmt(gsi);
89691 +
89692 + if (is_gimple_call(stmt))
89693 + is_leaf = false;
89694 +
89695 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
89696 + if (!is_alloca(stmt))
89697 + continue;
89698 +
89699 + // 2. insert stack overflow check before each __builtin_alloca call
89700 + stackleak_check_alloca(&gsi);
89701 +
89702 + // 3. insert track call after each __builtin_alloca call
89703 + stackleak_add_instrumentation(&gsi);
89704 + if (bb == entry_bb)
89705 + prologue_instrumented = true;
89706 + }
89707 + }
89708 +
89709 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
89710 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
89711 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
89712 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
89713 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
89714 + return 0;
89715 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
89716 + return 0;
89717 +
89718 + // 4. insert track call at the beginning
89719 + if (!prologue_instrumented) {
89720 + gimple_stmt_iterator gsi;
89721 +
89722 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
89723 + if (dom_info_available_p(CDI_DOMINATORS))
89724 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
89725 + gsi = gsi_start_bb(bb);
89726 + stackleak_add_instrumentation(&gsi);
89727 + }
89728 +
89729 + return 0;
89730 +}
89731 +
89732 +static unsigned int execute_stackleak_final(void)
89733 +{
89734 + rtx insn;
89735 +
89736 + if (cfun->calls_alloca)
89737 + return 0;
89738 +
89739 + // keep calls only if function frame is big enough
89740 + if (get_frame_size() >= track_frame_size)
89741 + return 0;
89742 +
89743 + // 1. find pax_track_stack calls
89744 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
89745 + // 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))
89746 + rtx body;
89747 +
89748 + if (!CALL_P(insn))
89749 + continue;
89750 + body = PATTERN(insn);
89751 + if (GET_CODE(body) != CALL)
89752 + continue;
89753 + body = XEXP(body, 0);
89754 + if (GET_CODE(body) != MEM)
89755 + continue;
89756 + body = XEXP(body, 0);
89757 + if (GET_CODE(body) != SYMBOL_REF)
89758 + continue;
89759 + if (strcmp(XSTR(body, 0), track_function))
89760 + continue;
89761 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
89762 + // 2. delete call
89763 + insn = delete_insn_and_edges(insn);
89764 +#if BUILDING_GCC_VERSION >= 4007
89765 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
89766 + insn = delete_insn_and_edges(insn);
89767 +#endif
89768 + }
89769 +
89770 +// print_simple_rtl(stderr, get_insns());
89771 +// print_rtl(stderr, get_insns());
89772 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
89773 +
89774 + return 0;
89775 +}
89776 +
89777 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
89778 +{
89779 + const char * const plugin_name = plugin_info->base_name;
89780 + const int argc = plugin_info->argc;
89781 + const struct plugin_argument * const argv = plugin_info->argv;
89782 + int i;
89783 + struct register_pass_info stackleak_tree_instrument_pass_info = {
89784 + .pass = &stackleak_tree_instrument_pass.pass,
89785 +// .reference_pass_name = "tree_profile",
89786 + .reference_pass_name = "optimized",
89787 + .ref_pass_instance_number = 1,
89788 + .pos_op = PASS_POS_INSERT_BEFORE
89789 + };
89790 + struct register_pass_info stackleak_final_pass_info = {
89791 + .pass = &stackleak_final_rtl_opt_pass.pass,
89792 + .reference_pass_name = "final",
89793 + .ref_pass_instance_number = 1,
89794 + .pos_op = PASS_POS_INSERT_BEFORE
89795 + };
89796 +
89797 + if (!plugin_default_version_check(version, &gcc_version)) {
89798 + error(G_("incompatible gcc/plugin versions"));
89799 + return 1;
89800 + }
89801 +
89802 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
89803 +
89804 + for (i = 0; i < argc; ++i) {
89805 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
89806 + if (!argv[i].value) {
89807 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
89808 + continue;
89809 + }
89810 + track_frame_size = atoi(argv[i].value);
89811 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
89812 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
89813 + continue;
89814 + }
89815 + if (!strcmp(argv[i].key, "initialize-locals")) {
89816 + if (argv[i].value) {
89817 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
89818 + continue;
89819 + }
89820 + init_locals = true;
89821 + continue;
89822 + }
89823 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
89824 + }
89825 +
89826 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
89827 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
89828 +
89829 + return 0;
89830 +}
89831 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
89832 index 6789d78..4afd019e 100644
89833 --- a/tools/perf/util/include/asm/alternative-asm.h
89834 +++ b/tools/perf/util/include/asm/alternative-asm.h
89835 @@ -5,4 +5,7 @@
89836
89837 #define altinstruction_entry #
89838
89839 + .macro pax_force_retaddr rip=0, reload=0
89840 + .endm
89841 +
89842 #endif
89843 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
89844 index d617f69..6b445d2 100644
89845 --- a/virt/kvm/kvm_main.c
89846 +++ b/virt/kvm/kvm_main.c
89847 @@ -75,7 +75,7 @@ LIST_HEAD(vm_list);
89848
89849 static cpumask_var_t cpus_hardware_enabled;
89850 static int kvm_usage_count = 0;
89851 -static atomic_t hardware_enable_failed;
89852 +static atomic_unchecked_t hardware_enable_failed;
89853
89854 struct kmem_cache *kvm_vcpu_cache;
89855 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
89856 @@ -715,7 +715,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
89857 /* We can read the guest memory with __xxx_user() later on. */
89858 if (user_alloc &&
89859 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
89860 - !access_ok(VERIFY_WRITE,
89861 + !__access_ok(VERIFY_WRITE,
89862 (void __user *)(unsigned long)mem->userspace_addr,
89863 mem->memory_size)))
89864 goto out;
89865 @@ -2304,7 +2304,7 @@ static void hardware_enable_nolock(void *junk)
89866
89867 if (r) {
89868 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
89869 - atomic_inc(&hardware_enable_failed);
89870 + atomic_inc_unchecked(&hardware_enable_failed);
89871 printk(KERN_INFO "kvm: enabling virtualization on "
89872 "CPU%d failed\n", cpu);
89873 }
89874 @@ -2358,10 +2358,10 @@ static int hardware_enable_all(void)
89875
89876 kvm_usage_count++;
89877 if (kvm_usage_count == 1) {
89878 - atomic_set(&hardware_enable_failed, 0);
89879 + atomic_set_unchecked(&hardware_enable_failed, 0);
89880 on_each_cpu(hardware_enable_nolock, NULL, 1);
89881
89882 - if (atomic_read(&hardware_enable_failed)) {
89883 + if (atomic_read_unchecked(&hardware_enable_failed)) {
89884 hardware_disable_all_nolock();
89885 r = -EBUSY;
89886 }
89887 @@ -2722,7 +2722,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
89888 kvm_arch_vcpu_put(vcpu);
89889 }
89890
89891 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
89892 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
89893 struct module *module)
89894 {
89895 int r;
89896 @@ -2785,7 +2785,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
89897 if (!vcpu_align)
89898 vcpu_align = __alignof__(struct kvm_vcpu);
89899 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
89900 - 0, NULL);
89901 + SLAB_USERCOPY, NULL);
89902 if (!kvm_vcpu_cache) {
89903 r = -ENOMEM;
89904 goto out_free_3;
89905 @@ -2795,9 +2795,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
89906 if (r)
89907 goto out_free;
89908
89909 - kvm_chardev_ops.owner = module;
89910 - kvm_vm_fops.owner = module;
89911 - kvm_vcpu_fops.owner = module;
89912 + pax_open_kernel();
89913 + *(void **)&kvm_chardev_ops.owner = module;
89914 + *(void **)&kvm_vm_fops.owner = module;
89915 + *(void **)&kvm_vcpu_fops.owner = module;
89916 + pax_close_kernel();
89917
89918 r = misc_register(&kvm_dev);
89919 if (r) {