]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9.1-3.6.6-201211072001.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.6.6-201211072001.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..0fc945b 100644
24598 --- a/arch/x86/mm/init.c
24599 +++ b/arch/x86/mm/init.c
24600 @@ -4,6 +4,7 @@
24601 #include <linux/swap.h>
24602 #include <linux/memblock.h>
24603 #include <linux/bootmem.h> /* for max_low_pfn */
24604 +#include <linux/tboot.h>
24605
24606 #include <asm/cacheflush.h>
24607 #include <asm/e820.h>
24608 @@ -16,6 +17,8 @@
24609 #include <asm/tlb.h>
24610 #include <asm/proto.h>
24611 #include <asm/dma.h> /* for MAX_DMA_PFN */
24612 +#include <asm/desc.h>
24613 +#include <asm/bios_ebda.h>
24614
24615 unsigned long __initdata pgt_buf_start;
24616 unsigned long __meminitdata pgt_buf_end;
24617 @@ -44,7 +47,7 @@ static void __init find_early_table_space(struct map_range *mr, int nr_range)
24618 {
24619 int i;
24620 unsigned long puds = 0, pmds = 0, ptes = 0, tables;
24621 - unsigned long start = 0, good_end;
24622 + unsigned long start = 0x100000, good_end;
24623 phys_addr_t base;
24624
24625 for (i = 0; i < nr_range; i++) {
24626 @@ -321,10 +324,40 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24627 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
24628 * mmio resources as well as potential bios/acpi data regions.
24629 */
24630 +
24631 +#ifdef CONFIG_GRKERNSEC_KMEM
24632 +static unsigned int ebda_start __read_only;
24633 +static unsigned int ebda_end __read_only;
24634 +#endif
24635 +
24636 int devmem_is_allowed(unsigned long pagenr)
24637 {
24638 - if (pagenr < 256)
24639 +#ifdef CONFIG_GRKERNSEC_KMEM
24640 + /* allow BDA */
24641 + if (!pagenr)
24642 return 1;
24643 + /* allow EBDA */
24644 + if (pagenr >= ebda_start && pagenr < ebda_end)
24645 + return 1;
24646 + /* if tboot is in use, allow access to its hardcoded serial log range */
24647 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
24648 + return 1;
24649 +#else
24650 + if (!pagenr)
24651 + return 1;
24652 +#ifdef CONFIG_VM86
24653 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24654 + return 1;
24655 +#endif
24656 +#endif
24657 +
24658 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24659 + return 1;
24660 +#ifdef CONFIG_GRKERNSEC_KMEM
24661 + /* throw out everything else below 1MB */
24662 + if (pagenr <= 256)
24663 + return 0;
24664 +#endif
24665 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24666 return 0;
24667 if (!page_is_ram(pagenr))
24668 @@ -381,8 +414,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24669 #endif
24670 }
24671
24672 +#ifdef CONFIG_GRKERNSEC_KMEM
24673 +static inline void gr_init_ebda(void)
24674 +{
24675 + unsigned int ebda_addr;
24676 + unsigned int ebda_size = 0;
24677 +
24678 + ebda_addr = get_bios_ebda();
24679 + if (ebda_addr) {
24680 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
24681 + ebda_size <<= 10;
24682 + }
24683 + if (ebda_addr && ebda_size) {
24684 + ebda_start = ebda_addr >> PAGE_SHIFT;
24685 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
24686 + } else {
24687 + ebda_start = 0x9f000 >> PAGE_SHIFT;
24688 + ebda_end = 0xa0000 >> PAGE_SHIFT;
24689 + }
24690 +}
24691 +#else
24692 +static inline void gr_init_ebda(void) { }
24693 +#endif
24694 +
24695 void free_initmem(void)
24696 {
24697 +#ifdef CONFIG_PAX_KERNEXEC
24698 +#ifdef CONFIG_X86_32
24699 + /* PaX: limit KERNEL_CS to actual size */
24700 + unsigned long addr, limit;
24701 + struct desc_struct d;
24702 + int cpu;
24703 +#else
24704 + pgd_t *pgd;
24705 + pud_t *pud;
24706 + pmd_t *pmd;
24707 + unsigned long addr, end;
24708 +#endif
24709 +#endif
24710 +
24711 + gr_init_ebda();
24712 +
24713 +#ifdef CONFIG_PAX_KERNEXEC
24714 +#ifdef CONFIG_X86_32
24715 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24716 + limit = (limit - 1UL) >> PAGE_SHIFT;
24717 +
24718 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24719 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24720 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24721 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24722 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
24723 + }
24724 +
24725 + /* PaX: make KERNEL_CS read-only */
24726 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24727 + if (!paravirt_enabled())
24728 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24729 +/*
24730 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24731 + pgd = pgd_offset_k(addr);
24732 + pud = pud_offset(pgd, addr);
24733 + pmd = pmd_offset(pud, addr);
24734 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24735 + }
24736 +*/
24737 +#ifdef CONFIG_X86_PAE
24738 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24739 +/*
24740 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24741 + pgd = pgd_offset_k(addr);
24742 + pud = pud_offset(pgd, addr);
24743 + pmd = pmd_offset(pud, addr);
24744 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24745 + }
24746 +*/
24747 +#endif
24748 +
24749 +#ifdef CONFIG_MODULES
24750 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24751 +#endif
24752 +
24753 +#else
24754 + /* PaX: make kernel code/rodata read-only, rest non-executable */
24755 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24756 + pgd = pgd_offset_k(addr);
24757 + pud = pud_offset(pgd, addr);
24758 + pmd = pmd_offset(pud, addr);
24759 + if (!pmd_present(*pmd))
24760 + continue;
24761 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24762 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24763 + else
24764 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24765 + }
24766 +
24767 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24768 + end = addr + KERNEL_IMAGE_SIZE;
24769 + for (; addr < end; addr += PMD_SIZE) {
24770 + pgd = pgd_offset_k(addr);
24771 + pud = pud_offset(pgd, addr);
24772 + pmd = pmd_offset(pud, addr);
24773 + if (!pmd_present(*pmd))
24774 + continue;
24775 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24776 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24777 + }
24778 +#endif
24779 +
24780 + flush_tlb_all();
24781 +#endif
24782 +
24783 free_init_pages("unused kernel memory",
24784 (unsigned long)(&__init_begin),
24785 (unsigned long)(&__init_end));
24786 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24787 index 575d86f..4987469 100644
24788 --- a/arch/x86/mm/init_32.c
24789 +++ b/arch/x86/mm/init_32.c
24790 @@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
24791 }
24792
24793 /*
24794 - * Creates a middle page table and puts a pointer to it in the
24795 - * given global directory entry. This only returns the gd entry
24796 - * in non-PAE compilation mode, since the middle layer is folded.
24797 - */
24798 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
24799 -{
24800 - pud_t *pud;
24801 - pmd_t *pmd_table;
24802 -
24803 -#ifdef CONFIG_X86_PAE
24804 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24805 - if (after_bootmem)
24806 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24807 - else
24808 - pmd_table = (pmd_t *)alloc_low_page();
24809 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24810 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24811 - pud = pud_offset(pgd, 0);
24812 - BUG_ON(pmd_table != pmd_offset(pud, 0));
24813 -
24814 - return pmd_table;
24815 - }
24816 -#endif
24817 - pud = pud_offset(pgd, 0);
24818 - pmd_table = pmd_offset(pud, 0);
24819 -
24820 - return pmd_table;
24821 -}
24822 -
24823 -/*
24824 * Create a page table and place a pointer to it in a middle page
24825 * directory entry:
24826 */
24827 @@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24828 page_table = (pte_t *)alloc_low_page();
24829
24830 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24831 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24832 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24833 +#else
24834 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24835 +#endif
24836 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24837 }
24838
24839 return pte_offset_kernel(pmd, 0);
24840 }
24841
24842 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
24843 +{
24844 + pud_t *pud;
24845 + pmd_t *pmd_table;
24846 +
24847 + pud = pud_offset(pgd, 0);
24848 + pmd_table = pmd_offset(pud, 0);
24849 +
24850 + return pmd_table;
24851 +}
24852 +
24853 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24854 {
24855 int pgd_idx = pgd_index(vaddr);
24856 @@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24857 int pgd_idx, pmd_idx;
24858 unsigned long vaddr;
24859 pgd_t *pgd;
24860 + pud_t *pud;
24861 pmd_t *pmd;
24862 pte_t *pte = NULL;
24863
24864 @@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24865 pgd = pgd_base + pgd_idx;
24866
24867 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24868 - pmd = one_md_table_init(pgd);
24869 - pmd = pmd + pmd_index(vaddr);
24870 + pud = pud_offset(pgd, vaddr);
24871 + pmd = pmd_offset(pud, vaddr);
24872 +
24873 +#ifdef CONFIG_X86_PAE
24874 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24875 +#endif
24876 +
24877 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24878 pmd++, pmd_idx++) {
24879 pte = page_table_kmap_check(one_page_table_init(pmd),
24880 @@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24881 }
24882 }
24883
24884 -static inline int is_kernel_text(unsigned long addr)
24885 +static inline int is_kernel_text(unsigned long start, unsigned long end)
24886 {
24887 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
24888 - return 1;
24889 - return 0;
24890 + if ((start > ktla_ktva((unsigned long)_etext) ||
24891 + end <= ktla_ktva((unsigned long)_stext)) &&
24892 + (start > ktla_ktva((unsigned long)_einittext) ||
24893 + end <= ktla_ktva((unsigned long)_sinittext)) &&
24894 +
24895 +#ifdef CONFIG_ACPI_SLEEP
24896 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24897 +#endif
24898 +
24899 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24900 + return 0;
24901 + return 1;
24902 }
24903
24904 /*
24905 @@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
24906 unsigned long last_map_addr = end;
24907 unsigned long start_pfn, end_pfn;
24908 pgd_t *pgd_base = swapper_pg_dir;
24909 - int pgd_idx, pmd_idx, pte_ofs;
24910 + unsigned int pgd_idx, pmd_idx, pte_ofs;
24911 unsigned long pfn;
24912 pgd_t *pgd;
24913 + pud_t *pud;
24914 pmd_t *pmd;
24915 pte_t *pte;
24916 unsigned pages_2m, pages_4k;
24917 @@ -280,8 +281,13 @@ repeat:
24918 pfn = start_pfn;
24919 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24920 pgd = pgd_base + pgd_idx;
24921 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
24922 - pmd = one_md_table_init(pgd);
24923 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
24924 + pud = pud_offset(pgd, 0);
24925 + pmd = pmd_offset(pud, 0);
24926 +
24927 +#ifdef CONFIG_X86_PAE
24928 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24929 +#endif
24930
24931 if (pfn >= end_pfn)
24932 continue;
24933 @@ -293,14 +299,13 @@ repeat:
24934 #endif
24935 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
24936 pmd++, pmd_idx++) {
24937 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
24938 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
24939
24940 /*
24941 * Map with big pages if possible, otherwise
24942 * create normal page tables:
24943 */
24944 if (use_pse) {
24945 - unsigned int addr2;
24946 pgprot_t prot = PAGE_KERNEL_LARGE;
24947 /*
24948 * first pass will use the same initial
24949 @@ -310,11 +315,7 @@ repeat:
24950 __pgprot(PTE_IDENT_ATTR |
24951 _PAGE_PSE);
24952
24953 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
24954 - PAGE_OFFSET + PAGE_SIZE-1;
24955 -
24956 - if (is_kernel_text(addr) ||
24957 - is_kernel_text(addr2))
24958 + if (is_kernel_text(address, address + PMD_SIZE))
24959 prot = PAGE_KERNEL_LARGE_EXEC;
24960
24961 pages_2m++;
24962 @@ -331,7 +332,7 @@ repeat:
24963 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24964 pte += pte_ofs;
24965 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
24966 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
24967 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
24968 pgprot_t prot = PAGE_KERNEL;
24969 /*
24970 * first pass will use the same initial
24971 @@ -339,7 +340,7 @@ repeat:
24972 */
24973 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
24974
24975 - if (is_kernel_text(addr))
24976 + if (is_kernel_text(address, address + PAGE_SIZE))
24977 prot = PAGE_KERNEL_EXEC;
24978
24979 pages_4k++;
24980 @@ -465,7 +466,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
24981
24982 pud = pud_offset(pgd, va);
24983 pmd = pmd_offset(pud, va);
24984 - if (!pmd_present(*pmd))
24985 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
24986 break;
24987
24988 pte = pte_offset_kernel(pmd, va);
24989 @@ -517,12 +518,10 @@ void __init early_ioremap_page_table_range_init(void)
24990
24991 static void __init pagetable_init(void)
24992 {
24993 - pgd_t *pgd_base = swapper_pg_dir;
24994 -
24995 - permanent_kmaps_init(pgd_base);
24996 + permanent_kmaps_init(swapper_pg_dir);
24997 }
24998
24999 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
25000 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
25001 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25002
25003 /* user-defined highmem size */
25004 @@ -734,6 +733,12 @@ void __init mem_init(void)
25005
25006 pci_iommu_alloc();
25007
25008 +#ifdef CONFIG_PAX_PER_CPU_PGD
25009 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25010 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25011 + KERNEL_PGD_PTRS);
25012 +#endif
25013 +
25014 #ifdef CONFIG_FLATMEM
25015 BUG_ON(!mem_map);
25016 #endif
25017 @@ -760,7 +765,7 @@ void __init mem_init(void)
25018 reservedpages++;
25019
25020 codesize = (unsigned long) &_etext - (unsigned long) &_text;
25021 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
25022 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
25023 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
25024
25025 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
25026 @@ -801,10 +806,10 @@ void __init mem_init(void)
25027 ((unsigned long)&__init_end -
25028 (unsigned long)&__init_begin) >> 10,
25029
25030 - (unsigned long)&_etext, (unsigned long)&_edata,
25031 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
25032 + (unsigned long)&_sdata, (unsigned long)&_edata,
25033 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
25034
25035 - (unsigned long)&_text, (unsigned long)&_etext,
25036 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
25037 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
25038
25039 /*
25040 @@ -882,6 +887,7 @@ void set_kernel_text_rw(void)
25041 if (!kernel_set_to_readonly)
25042 return;
25043
25044 + start = ktla_ktva(start);
25045 pr_debug("Set kernel text: %lx - %lx for read write\n",
25046 start, start+size);
25047
25048 @@ -896,6 +902,7 @@ void set_kernel_text_ro(void)
25049 if (!kernel_set_to_readonly)
25050 return;
25051
25052 + start = ktla_ktva(start);
25053 pr_debug("Set kernel text: %lx - %lx for read only\n",
25054 start, start+size);
25055
25056 @@ -924,6 +931,7 @@ void mark_rodata_ro(void)
25057 unsigned long start = PFN_ALIGN(_text);
25058 unsigned long size = PFN_ALIGN(_etext) - start;
25059
25060 + start = ktla_ktva(start);
25061 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
25062 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
25063 size >> 10);
25064 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
25065 index 3baff25..8b37564 100644
25066 --- a/arch/x86/mm/init_64.c
25067 +++ b/arch/x86/mm/init_64.c
25068 @@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
25069 * around without checking the pgd every time.
25070 */
25071
25072 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
25073 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
25074 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25075
25076 int force_personality32;
25077 @@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25078
25079 for (address = start; address <= end; address += PGDIR_SIZE) {
25080 const pgd_t *pgd_ref = pgd_offset_k(address);
25081 +
25082 +#ifdef CONFIG_PAX_PER_CPU_PGD
25083 + unsigned long cpu;
25084 +#else
25085 struct page *page;
25086 +#endif
25087
25088 if (pgd_none(*pgd_ref))
25089 continue;
25090
25091 spin_lock(&pgd_lock);
25092 +
25093 +#ifdef CONFIG_PAX_PER_CPU_PGD
25094 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25095 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
25096 +#else
25097 list_for_each_entry(page, &pgd_list, lru) {
25098 pgd_t *pgd;
25099 spinlock_t *pgt_lock;
25100 @@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25101 /* the pgt_lock only for Xen */
25102 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
25103 spin_lock(pgt_lock);
25104 +#endif
25105
25106 if (pgd_none(*pgd))
25107 set_pgd(pgd, *pgd_ref);
25108 @@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25109 BUG_ON(pgd_page_vaddr(*pgd)
25110 != pgd_page_vaddr(*pgd_ref));
25111
25112 +#ifndef CONFIG_PAX_PER_CPU_PGD
25113 spin_unlock(pgt_lock);
25114 +#endif
25115 +
25116 }
25117 spin_unlock(&pgd_lock);
25118 }
25119 @@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
25120 {
25121 if (pgd_none(*pgd)) {
25122 pud_t *pud = (pud_t *)spp_getpage();
25123 - pgd_populate(&init_mm, pgd, pud);
25124 + pgd_populate_kernel(&init_mm, pgd, pud);
25125 if (pud != pud_offset(pgd, 0))
25126 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
25127 pud, pud_offset(pgd, 0));
25128 @@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
25129 {
25130 if (pud_none(*pud)) {
25131 pmd_t *pmd = (pmd_t *) spp_getpage();
25132 - pud_populate(&init_mm, pud, pmd);
25133 + pud_populate_kernel(&init_mm, pud, pmd);
25134 if (pmd != pmd_offset(pud, 0))
25135 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
25136 pmd, pmd_offset(pud, 0));
25137 @@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
25138 pmd = fill_pmd(pud, vaddr);
25139 pte = fill_pte(pmd, vaddr);
25140
25141 + pax_open_kernel();
25142 set_pte(pte, new_pte);
25143 + pax_close_kernel();
25144
25145 /*
25146 * It's enough to flush this one mapping.
25147 @@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
25148 pgd = pgd_offset_k((unsigned long)__va(phys));
25149 if (pgd_none(*pgd)) {
25150 pud = (pud_t *) spp_getpage();
25151 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
25152 - _PAGE_USER));
25153 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
25154 }
25155 pud = pud_offset(pgd, (unsigned long)__va(phys));
25156 if (pud_none(*pud)) {
25157 pmd = (pmd_t *) spp_getpage();
25158 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
25159 - _PAGE_USER));
25160 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
25161 }
25162 pmd = pmd_offset(pud, phys);
25163 BUG_ON(!pmd_none(*pmd));
25164 @@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
25165 if (pfn >= pgt_buf_top)
25166 panic("alloc_low_page: ran out of memory");
25167
25168 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25169 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25170 clear_page(adr);
25171 *phys = pfn * PAGE_SIZE;
25172 return adr;
25173 @@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
25174
25175 phys = __pa(virt);
25176 left = phys & (PAGE_SIZE - 1);
25177 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25178 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25179 adr = (void *)(((unsigned long)adr) | left);
25180
25181 return adr;
25182 @@ -553,7 +567,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
25183 unmap_low_page(pmd);
25184
25185 spin_lock(&init_mm.page_table_lock);
25186 - pud_populate(&init_mm, pud, __va(pmd_phys));
25187 + pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
25188 spin_unlock(&init_mm.page_table_lock);
25189 }
25190 __flush_tlb_all();
25191 @@ -599,7 +613,7 @@ kernel_physical_mapping_init(unsigned long start,
25192 unmap_low_page(pud);
25193
25194 spin_lock(&init_mm.page_table_lock);
25195 - pgd_populate(&init_mm, pgd, __va(pud_phys));
25196 + pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
25197 spin_unlock(&init_mm.page_table_lock);
25198 pgd_changed = true;
25199 }
25200 @@ -691,6 +705,12 @@ void __init mem_init(void)
25201
25202 pci_iommu_alloc();
25203
25204 +#ifdef CONFIG_PAX_PER_CPU_PGD
25205 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25206 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25207 + KERNEL_PGD_PTRS);
25208 +#endif
25209 +
25210 /* clear_bss() already clear the empty_zero_page */
25211
25212 reservedpages = 0;
25213 @@ -851,8 +871,8 @@ int kern_addr_valid(unsigned long addr)
25214 static struct vm_area_struct gate_vma = {
25215 .vm_start = VSYSCALL_START,
25216 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
25217 - .vm_page_prot = PAGE_READONLY_EXEC,
25218 - .vm_flags = VM_READ | VM_EXEC
25219 + .vm_page_prot = PAGE_READONLY,
25220 + .vm_flags = VM_READ
25221 };
25222
25223 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
25224 @@ -886,7 +906,7 @@ int in_gate_area_no_mm(unsigned long addr)
25225
25226 const char *arch_vma_name(struct vm_area_struct *vma)
25227 {
25228 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
25229 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
25230 return "[vdso]";
25231 if (vma == &gate_vma)
25232 return "[vsyscall]";
25233 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
25234 index 7b179b4..6bd1777 100644
25235 --- a/arch/x86/mm/iomap_32.c
25236 +++ b/arch/x86/mm/iomap_32.c
25237 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
25238 type = kmap_atomic_idx_push();
25239 idx = type + KM_TYPE_NR * smp_processor_id();
25240 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25241 +
25242 + pax_open_kernel();
25243 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
25244 + pax_close_kernel();
25245 +
25246 arch_flush_lazy_mmu_mode();
25247
25248 return (void *)vaddr;
25249 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
25250 index 78fe3f1..8293b6f 100644
25251 --- a/arch/x86/mm/ioremap.c
25252 +++ b/arch/x86/mm/ioremap.c
25253 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
25254 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
25255 int is_ram = page_is_ram(pfn);
25256
25257 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
25258 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
25259 return NULL;
25260 WARN_ON_ONCE(is_ram);
25261 }
25262 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
25263
25264 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
25265 if (page_is_ram(start >> PAGE_SHIFT))
25266 +#ifdef CONFIG_HIGHMEM
25267 + if ((start >> PAGE_SHIFT) < max_low_pfn)
25268 +#endif
25269 return __va(phys);
25270
25271 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
25272 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
25273 early_param("early_ioremap_debug", early_ioremap_debug_setup);
25274
25275 static __initdata int after_paging_init;
25276 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
25277 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
25278
25279 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
25280 {
25281 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
25282 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
25283
25284 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25285 - memset(bm_pte, 0, sizeof(bm_pte));
25286 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
25287 + pmd_populate_user(&init_mm, pmd, bm_pte);
25288
25289 /*
25290 * The boot-ioremap range spans multiple pmds, for which
25291 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25292 index d87dd6d..bf3fa66 100644
25293 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
25294 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25295 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25296 * memory (e.g. tracked pages)? For now, we need this to avoid
25297 * invoking kmemcheck for PnP BIOS calls.
25298 */
25299 - if (regs->flags & X86_VM_MASK)
25300 + if (v8086_mode(regs))
25301 return false;
25302 - if (regs->cs != __KERNEL_CS)
25303 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25304 return false;
25305
25306 pte = kmemcheck_pte_lookup(address);
25307 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25308 index 845df68..1d8d29f 100644
25309 --- a/arch/x86/mm/mmap.c
25310 +++ b/arch/x86/mm/mmap.c
25311 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
25312 * Leave an at least ~128 MB hole with possible stack randomization.
25313 */
25314 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25315 -#define MAX_GAP (TASK_SIZE/6*5)
25316 +#define MAX_GAP (pax_task_size/6*5)
25317
25318 static int mmap_is_legacy(void)
25319 {
25320 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
25321 return rnd << PAGE_SHIFT;
25322 }
25323
25324 -static unsigned long mmap_base(void)
25325 +static unsigned long mmap_base(struct mm_struct *mm)
25326 {
25327 unsigned long gap = rlimit(RLIMIT_STACK);
25328 + unsigned long pax_task_size = TASK_SIZE;
25329 +
25330 +#ifdef CONFIG_PAX_SEGMEXEC
25331 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25332 + pax_task_size = SEGMEXEC_TASK_SIZE;
25333 +#endif
25334
25335 if (gap < MIN_GAP)
25336 gap = MIN_GAP;
25337 else if (gap > MAX_GAP)
25338 gap = MAX_GAP;
25339
25340 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25341 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25342 }
25343
25344 /*
25345 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25346 * does, but not when emulating X86_32
25347 */
25348 -static unsigned long mmap_legacy_base(void)
25349 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
25350 {
25351 - if (mmap_is_ia32())
25352 + if (mmap_is_ia32()) {
25353 +
25354 +#ifdef CONFIG_PAX_SEGMEXEC
25355 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25356 + return SEGMEXEC_TASK_UNMAPPED_BASE;
25357 + else
25358 +#endif
25359 +
25360 return TASK_UNMAPPED_BASE;
25361 - else
25362 + } else
25363 return TASK_UNMAPPED_BASE + mmap_rnd();
25364 }
25365
25366 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25367 void arch_pick_mmap_layout(struct mm_struct *mm)
25368 {
25369 if (mmap_is_legacy()) {
25370 - mm->mmap_base = mmap_legacy_base();
25371 + mm->mmap_base = mmap_legacy_base(mm);
25372 +
25373 +#ifdef CONFIG_PAX_RANDMMAP
25374 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25375 + mm->mmap_base += mm->delta_mmap;
25376 +#endif
25377 +
25378 mm->get_unmapped_area = arch_get_unmapped_area;
25379 mm->unmap_area = arch_unmap_area;
25380 } else {
25381 - mm->mmap_base = mmap_base();
25382 + mm->mmap_base = mmap_base(mm);
25383 +
25384 +#ifdef CONFIG_PAX_RANDMMAP
25385 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25386 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25387 +#endif
25388 +
25389 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25390 mm->unmap_area = arch_unmap_area_topdown;
25391 }
25392 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25393 index dc0b727..dc9d71a 100644
25394 --- a/arch/x86/mm/mmio-mod.c
25395 +++ b/arch/x86/mm/mmio-mod.c
25396 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25397 break;
25398 default:
25399 {
25400 - unsigned char *ip = (unsigned char *)instptr;
25401 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25402 my_trace->opcode = MMIO_UNKNOWN_OP;
25403 my_trace->width = 0;
25404 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25405 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25406 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25407 void __iomem *addr)
25408 {
25409 - static atomic_t next_id;
25410 + static atomic_unchecked_t next_id;
25411 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25412 /* These are page-unaligned. */
25413 struct mmiotrace_map map = {
25414 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25415 .private = trace
25416 },
25417 .phys = offset,
25418 - .id = atomic_inc_return(&next_id)
25419 + .id = atomic_inc_return_unchecked(&next_id)
25420 };
25421 map.map_id = trace->id;
25422
25423 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25424 index b008656..773eac2 100644
25425 --- a/arch/x86/mm/pageattr-test.c
25426 +++ b/arch/x86/mm/pageattr-test.c
25427 @@ -36,7 +36,7 @@ enum {
25428
25429 static int pte_testbit(pte_t pte)
25430 {
25431 - return pte_flags(pte) & _PAGE_UNUSED1;
25432 + return pte_flags(pte) & _PAGE_CPA_TEST;
25433 }
25434
25435 struct split_state {
25436 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25437 index a718e0d..45efc32 100644
25438 --- a/arch/x86/mm/pageattr.c
25439 +++ b/arch/x86/mm/pageattr.c
25440 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25441 */
25442 #ifdef CONFIG_PCI_BIOS
25443 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25444 - pgprot_val(forbidden) |= _PAGE_NX;
25445 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25446 #endif
25447
25448 /*
25449 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25450 * Does not cover __inittext since that is gone later on. On
25451 * 64bit we do not enforce !NX on the low mapping
25452 */
25453 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
25454 - pgprot_val(forbidden) |= _PAGE_NX;
25455 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25456 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25457
25458 +#ifdef CONFIG_DEBUG_RODATA
25459 /*
25460 * The .rodata section needs to be read-only. Using the pfn
25461 * catches all aliases.
25462 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25463 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25464 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25465 pgprot_val(forbidden) |= _PAGE_RW;
25466 +#endif
25467
25468 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25469 /*
25470 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25471 }
25472 #endif
25473
25474 +#ifdef CONFIG_PAX_KERNEXEC
25475 + if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25476 + pgprot_val(forbidden) |= _PAGE_RW;
25477 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25478 + }
25479 +#endif
25480 +
25481 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25482
25483 return prot;
25484 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25485 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25486 {
25487 /* change init_mm */
25488 + pax_open_kernel();
25489 set_pte_atomic(kpte, pte);
25490 +
25491 #ifdef CONFIG_X86_32
25492 if (!SHARED_KERNEL_PMD) {
25493 +
25494 +#ifdef CONFIG_PAX_PER_CPU_PGD
25495 + unsigned long cpu;
25496 +#else
25497 struct page *page;
25498 +#endif
25499
25500 +#ifdef CONFIG_PAX_PER_CPU_PGD
25501 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25502 + pgd_t *pgd = get_cpu_pgd(cpu);
25503 +#else
25504 list_for_each_entry(page, &pgd_list, lru) {
25505 - pgd_t *pgd;
25506 + pgd_t *pgd = (pgd_t *)page_address(page);
25507 +#endif
25508 +
25509 pud_t *pud;
25510 pmd_t *pmd;
25511
25512 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
25513 + pgd += pgd_index(address);
25514 pud = pud_offset(pgd, address);
25515 pmd = pmd_offset(pud, address);
25516 set_pte_atomic((pte_t *)pmd, pte);
25517 }
25518 }
25519 #endif
25520 + pax_close_kernel();
25521 }
25522
25523 static int
25524 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25525 index 3d68ef6..7f69136 100644
25526 --- a/arch/x86/mm/pat.c
25527 +++ b/arch/x86/mm/pat.c
25528 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
25529
25530 if (!entry) {
25531 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
25532 - current->comm, current->pid, start, end - 1);
25533 + current->comm, task_pid_nr(current), start, end - 1);
25534 return -EINVAL;
25535 }
25536
25537 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25538
25539 while (cursor < to) {
25540 if (!devmem_is_allowed(pfn)) {
25541 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
25542 - current->comm, from, to - 1);
25543 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
25544 + current->comm, from, to - 1, cursor);
25545 return 0;
25546 }
25547 cursor += PAGE_SIZE;
25548 @@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25549 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
25550 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
25551 "for [mem %#010Lx-%#010Lx]\n",
25552 - current->comm, current->pid,
25553 + current->comm, task_pid_nr(current),
25554 cattr_name(flags),
25555 base, (unsigned long long)(base + size-1));
25556 return -EINVAL;
25557 @@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25558 flags = lookup_memtype(paddr);
25559 if (want_flags != flags) {
25560 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
25561 - current->comm, current->pid,
25562 + current->comm, task_pid_nr(current),
25563 cattr_name(want_flags),
25564 (unsigned long long)paddr,
25565 (unsigned long long)(paddr + size - 1),
25566 @@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25567 free_memtype(paddr, paddr + size);
25568 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25569 " for [mem %#010Lx-%#010Lx], got %s\n",
25570 - current->comm, current->pid,
25571 + current->comm, task_pid_nr(current),
25572 cattr_name(want_flags),
25573 (unsigned long long)paddr,
25574 (unsigned long long)(paddr + size - 1),
25575 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25576 index 9f0614d..92ae64a 100644
25577 --- a/arch/x86/mm/pf_in.c
25578 +++ b/arch/x86/mm/pf_in.c
25579 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25580 int i;
25581 enum reason_type rv = OTHERS;
25582
25583 - p = (unsigned char *)ins_addr;
25584 + p = (unsigned char *)ktla_ktva(ins_addr);
25585 p += skip_prefix(p, &prf);
25586 p += get_opcode(p, &opcode);
25587
25588 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25589 struct prefix_bits prf;
25590 int i;
25591
25592 - p = (unsigned char *)ins_addr;
25593 + p = (unsigned char *)ktla_ktva(ins_addr);
25594 p += skip_prefix(p, &prf);
25595 p += get_opcode(p, &opcode);
25596
25597 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25598 struct prefix_bits prf;
25599 int i;
25600
25601 - p = (unsigned char *)ins_addr;
25602 + p = (unsigned char *)ktla_ktva(ins_addr);
25603 p += skip_prefix(p, &prf);
25604 p += get_opcode(p, &opcode);
25605
25606 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25607 struct prefix_bits prf;
25608 int i;
25609
25610 - p = (unsigned char *)ins_addr;
25611 + p = (unsigned char *)ktla_ktva(ins_addr);
25612 p += skip_prefix(p, &prf);
25613 p += get_opcode(p, &opcode);
25614 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25615 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25616 struct prefix_bits prf;
25617 int i;
25618
25619 - p = (unsigned char *)ins_addr;
25620 + p = (unsigned char *)ktla_ktva(ins_addr);
25621 p += skip_prefix(p, &prf);
25622 p += get_opcode(p, &opcode);
25623 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25624 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25625 index 8573b83..4f3ed7e 100644
25626 --- a/arch/x86/mm/pgtable.c
25627 +++ b/arch/x86/mm/pgtable.c
25628 @@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
25629 list_del(&page->lru);
25630 }
25631
25632 -#define UNSHARED_PTRS_PER_PGD \
25633 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25634 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25635 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25636
25637 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
25638 +{
25639 + unsigned int count = USER_PGD_PTRS;
25640
25641 + while (count--)
25642 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25643 +}
25644 +#endif
25645 +
25646 +#ifdef CONFIG_PAX_PER_CPU_PGD
25647 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
25648 +{
25649 + unsigned int count = USER_PGD_PTRS;
25650 +
25651 + while (count--) {
25652 + pgd_t pgd;
25653 +
25654 +#ifdef CONFIG_X86_64
25655 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
25656 +#else
25657 + pgd = *src++;
25658 +#endif
25659 +
25660 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25661 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
25662 +#endif
25663 +
25664 + *dst++ = pgd;
25665 + }
25666 +
25667 +}
25668 +#endif
25669 +
25670 +#ifdef CONFIG_X86_64
25671 +#define pxd_t pud_t
25672 +#define pyd_t pgd_t
25673 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25674 +#define pxd_free(mm, pud) pud_free((mm), (pud))
25675 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25676 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
25677 +#define PYD_SIZE PGDIR_SIZE
25678 +#else
25679 +#define pxd_t pmd_t
25680 +#define pyd_t pud_t
25681 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25682 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
25683 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25684 +#define pyd_offset(mm, address) pud_offset((mm), (address))
25685 +#define PYD_SIZE PUD_SIZE
25686 +#endif
25687 +
25688 +#ifdef CONFIG_PAX_PER_CPU_PGD
25689 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25690 +static inline void pgd_dtor(pgd_t *pgd) {}
25691 +#else
25692 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25693 {
25694 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25695 @@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
25696 pgd_list_del(pgd);
25697 spin_unlock(&pgd_lock);
25698 }
25699 +#endif
25700
25701 /*
25702 * List of all pgd's needed for non-PAE so it can invalidate entries
25703 @@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
25704 * -- wli
25705 */
25706
25707 -#ifdef CONFIG_X86_PAE
25708 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25709 /*
25710 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25711 * updating the top-level pagetable entries to guarantee the
25712 @@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
25713 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25714 * and initialize the kernel pmds here.
25715 */
25716 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25717 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25718
25719 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25720 {
25721 @@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25722 */
25723 flush_tlb_mm(mm);
25724 }
25725 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25726 +#define PREALLOCATED_PXDS USER_PGD_PTRS
25727 #else /* !CONFIG_X86_PAE */
25728
25729 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25730 -#define PREALLOCATED_PMDS 0
25731 +#define PREALLOCATED_PXDS 0
25732
25733 #endif /* CONFIG_X86_PAE */
25734
25735 -static void free_pmds(pmd_t *pmds[])
25736 +static void free_pxds(pxd_t *pxds[])
25737 {
25738 int i;
25739
25740 - for(i = 0; i < PREALLOCATED_PMDS; i++)
25741 - if (pmds[i])
25742 - free_page((unsigned long)pmds[i]);
25743 + for(i = 0; i < PREALLOCATED_PXDS; i++)
25744 + if (pxds[i])
25745 + free_page((unsigned long)pxds[i]);
25746 }
25747
25748 -static int preallocate_pmds(pmd_t *pmds[])
25749 +static int preallocate_pxds(pxd_t *pxds[])
25750 {
25751 int i;
25752 bool failed = false;
25753
25754 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25755 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25756 - if (pmd == NULL)
25757 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25758 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25759 + if (pxd == NULL)
25760 failed = true;
25761 - pmds[i] = pmd;
25762 + pxds[i] = pxd;
25763 }
25764
25765 if (failed) {
25766 - free_pmds(pmds);
25767 + free_pxds(pxds);
25768 return -ENOMEM;
25769 }
25770
25771 @@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25772 * preallocate which never got a corresponding vma will need to be
25773 * freed manually.
25774 */
25775 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25776 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25777 {
25778 int i;
25779
25780 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25781 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25782 pgd_t pgd = pgdp[i];
25783
25784 if (pgd_val(pgd) != 0) {
25785 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25786 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25787
25788 - pgdp[i] = native_make_pgd(0);
25789 + set_pgd(pgdp + i, native_make_pgd(0));
25790
25791 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25792 - pmd_free(mm, pmd);
25793 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25794 + pxd_free(mm, pxd);
25795 }
25796 }
25797 }
25798
25799 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25800 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25801 {
25802 - pud_t *pud;
25803 + pyd_t *pyd;
25804 unsigned long addr;
25805 int i;
25806
25807 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25808 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25809 return;
25810
25811 - pud = pud_offset(pgd, 0);
25812 +#ifdef CONFIG_X86_64
25813 + pyd = pyd_offset(mm, 0L);
25814 +#else
25815 + pyd = pyd_offset(pgd, 0L);
25816 +#endif
25817
25818 - for (addr = i = 0; i < PREALLOCATED_PMDS;
25819 - i++, pud++, addr += PUD_SIZE) {
25820 - pmd_t *pmd = pmds[i];
25821 + for (addr = i = 0; i < PREALLOCATED_PXDS;
25822 + i++, pyd++, addr += PYD_SIZE) {
25823 + pxd_t *pxd = pxds[i];
25824
25825 if (i >= KERNEL_PGD_BOUNDARY)
25826 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25827 - sizeof(pmd_t) * PTRS_PER_PMD);
25828 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25829 + sizeof(pxd_t) * PTRS_PER_PMD);
25830
25831 - pud_populate(mm, pud, pmd);
25832 + pyd_populate(mm, pyd, pxd);
25833 }
25834 }
25835
25836 pgd_t *pgd_alloc(struct mm_struct *mm)
25837 {
25838 pgd_t *pgd;
25839 - pmd_t *pmds[PREALLOCATED_PMDS];
25840 + pxd_t *pxds[PREALLOCATED_PXDS];
25841
25842 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25843
25844 @@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25845
25846 mm->pgd = pgd;
25847
25848 - if (preallocate_pmds(pmds) != 0)
25849 + if (preallocate_pxds(pxds) != 0)
25850 goto out_free_pgd;
25851
25852 if (paravirt_pgd_alloc(mm) != 0)
25853 - goto out_free_pmds;
25854 + goto out_free_pxds;
25855
25856 /*
25857 * Make sure that pre-populating the pmds is atomic with
25858 @@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25859 spin_lock(&pgd_lock);
25860
25861 pgd_ctor(mm, pgd);
25862 - pgd_prepopulate_pmd(mm, pgd, pmds);
25863 + pgd_prepopulate_pxd(mm, pgd, pxds);
25864
25865 spin_unlock(&pgd_lock);
25866
25867 return pgd;
25868
25869 -out_free_pmds:
25870 - free_pmds(pmds);
25871 +out_free_pxds:
25872 + free_pxds(pxds);
25873 out_free_pgd:
25874 free_page((unsigned long)pgd);
25875 out:
25876 @@ -295,7 +356,7 @@ out:
25877
25878 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25879 {
25880 - pgd_mop_up_pmds(mm, pgd);
25881 + pgd_mop_up_pxds(mm, pgd);
25882 pgd_dtor(pgd);
25883 paravirt_pgd_free(mm, pgd);
25884 free_page((unsigned long)pgd);
25885 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25886 index a69bcb8..19068ab 100644
25887 --- a/arch/x86/mm/pgtable_32.c
25888 +++ b/arch/x86/mm/pgtable_32.c
25889 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25890 return;
25891 }
25892 pte = pte_offset_kernel(pmd, vaddr);
25893 +
25894 + pax_open_kernel();
25895 if (pte_val(pteval))
25896 set_pte_at(&init_mm, vaddr, pte, pteval);
25897 else
25898 pte_clear(&init_mm, vaddr, pte);
25899 + pax_close_kernel();
25900
25901 /*
25902 * It's enough to flush this one mapping.
25903 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25904 index 410531d..0f16030 100644
25905 --- a/arch/x86/mm/setup_nx.c
25906 +++ b/arch/x86/mm/setup_nx.c
25907 @@ -5,8 +5,10 @@
25908 #include <asm/pgtable.h>
25909 #include <asm/proto.h>
25910
25911 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25912 static int disable_nx __cpuinitdata;
25913
25914 +#ifndef CONFIG_PAX_PAGEEXEC
25915 /*
25916 * noexec = on|off
25917 *
25918 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
25919 return 0;
25920 }
25921 early_param("noexec", noexec_setup);
25922 +#endif
25923 +
25924 +#endif
25925
25926 void __cpuinit x86_configure_nx(void)
25927 {
25928 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25929 if (cpu_has_nx && !disable_nx)
25930 __supported_pte_mask |= _PAGE_NX;
25931 else
25932 +#endif
25933 __supported_pte_mask &= ~_PAGE_NX;
25934 }
25935
25936 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
25937 index 613cd83..3a21f1c 100644
25938 --- a/arch/x86/mm/tlb.c
25939 +++ b/arch/x86/mm/tlb.c
25940 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
25941 BUG();
25942 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
25943 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
25944 +
25945 +#ifndef CONFIG_PAX_PER_CPU_PGD
25946 load_cr3(swapper_pg_dir);
25947 +#endif
25948 +
25949 }
25950 }
25951 EXPORT_SYMBOL_GPL(leave_mm);
25952 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
25953 index 877b9a1..a8ecf42 100644
25954 --- a/arch/x86/net/bpf_jit.S
25955 +++ b/arch/x86/net/bpf_jit.S
25956 @@ -9,6 +9,7 @@
25957 */
25958 #include <linux/linkage.h>
25959 #include <asm/dwarf2.h>
25960 +#include <asm/alternative-asm.h>
25961
25962 /*
25963 * Calling convention :
25964 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
25965 jle bpf_slow_path_word
25966 mov (SKBDATA,%rsi),%eax
25967 bswap %eax /* ntohl() */
25968 + pax_force_retaddr
25969 ret
25970
25971 sk_load_half:
25972 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
25973 jle bpf_slow_path_half
25974 movzwl (SKBDATA,%rsi),%eax
25975 rol $8,%ax # ntohs()
25976 + pax_force_retaddr
25977 ret
25978
25979 sk_load_byte:
25980 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
25981 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
25982 jle bpf_slow_path_byte
25983 movzbl (SKBDATA,%rsi),%eax
25984 + pax_force_retaddr
25985 ret
25986
25987 /**
25988 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
25989 movzbl (SKBDATA,%rsi),%ebx
25990 and $15,%bl
25991 shl $2,%bl
25992 + pax_force_retaddr
25993 ret
25994
25995 /* rsi contains offset and can be scratched */
25996 @@ -109,6 +114,7 @@ bpf_slow_path_word:
25997 js bpf_error
25998 mov -12(%rbp),%eax
25999 bswap %eax
26000 + pax_force_retaddr
26001 ret
26002
26003 bpf_slow_path_half:
26004 @@ -117,12 +123,14 @@ bpf_slow_path_half:
26005 mov -12(%rbp),%ax
26006 rol $8,%ax
26007 movzwl %ax,%eax
26008 + pax_force_retaddr
26009 ret
26010
26011 bpf_slow_path_byte:
26012 bpf_slow_path_common(1)
26013 js bpf_error
26014 movzbl -12(%rbp),%eax
26015 + pax_force_retaddr
26016 ret
26017
26018 bpf_slow_path_byte_msh:
26019 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
26020 and $15,%al
26021 shl $2,%al
26022 xchg %eax,%ebx
26023 + pax_force_retaddr
26024 ret
26025
26026 #define sk_negative_common(SIZE) \
26027 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
26028 sk_negative_common(4)
26029 mov (%rax), %eax
26030 bswap %eax
26031 + pax_force_retaddr
26032 ret
26033
26034 bpf_slow_path_half_neg:
26035 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
26036 mov (%rax),%ax
26037 rol $8,%ax
26038 movzwl %ax,%eax
26039 + pax_force_retaddr
26040 ret
26041
26042 bpf_slow_path_byte_neg:
26043 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
26044 .globl sk_load_byte_negative_offset
26045 sk_negative_common(1)
26046 movzbl (%rax), %eax
26047 + pax_force_retaddr
26048 ret
26049
26050 bpf_slow_path_byte_msh_neg:
26051 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
26052 and $15,%al
26053 shl $2,%al
26054 xchg %eax,%ebx
26055 + pax_force_retaddr
26056 ret
26057
26058 bpf_error:
26059 @@ -197,4 +210,5 @@ bpf_error:
26060 xor %eax,%eax
26061 mov -8(%rbp),%rbx
26062 leaveq
26063 + pax_force_retaddr
26064 ret
26065 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
26066 index 33643a8..8e44870 100644
26067 --- a/arch/x86/net/bpf_jit_comp.c
26068 +++ b/arch/x86/net/bpf_jit_comp.c
26069 @@ -120,6 +120,11 @@ static inline void bpf_flush_icache(void *start, void *end)
26070 set_fs(old_fs);
26071 }
26072
26073 +struct bpf_jit_work {
26074 + struct work_struct work;
26075 + void *image;
26076 +};
26077 +
26078 #define CHOOSE_LOAD_FUNC(K, func) \
26079 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
26080
26081 @@ -146,6 +151,10 @@ void bpf_jit_compile(struct sk_filter *fp)
26082 if (addrs == NULL)
26083 return;
26084
26085 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
26086 + if (!fp->work)
26087 + goto out;
26088 +
26089 /* Before first pass, make a rough estimation of addrs[]
26090 * each bpf instruction is translated to less than 64 bytes
26091 */
26092 @@ -593,17 +602,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26093 break;
26094 default:
26095 /* hmm, too complex filter, give up with jit compiler */
26096 - goto out;
26097 + goto error;
26098 }
26099 ilen = prog - temp;
26100 if (image) {
26101 if (unlikely(proglen + ilen > oldproglen)) {
26102 pr_err("bpb_jit_compile fatal error\n");
26103 - kfree(addrs);
26104 - module_free(NULL, image);
26105 - return;
26106 + module_free_exec(NULL, image);
26107 + goto error;
26108 }
26109 + pax_open_kernel();
26110 memcpy(image + proglen, temp, ilen);
26111 + pax_close_kernel();
26112 }
26113 proglen += ilen;
26114 addrs[i] = proglen;
26115 @@ -624,11 +634,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26116 break;
26117 }
26118 if (proglen == oldproglen) {
26119 - image = module_alloc(max_t(unsigned int,
26120 - proglen,
26121 - sizeof(struct work_struct)));
26122 + image = module_alloc_exec(proglen);
26123 if (!image)
26124 - goto out;
26125 + goto error;
26126 }
26127 oldproglen = proglen;
26128 }
26129 @@ -644,7 +652,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26130 bpf_flush_icache(image, image + proglen);
26131
26132 fp->bpf_func = (void *)image;
26133 - }
26134 + } else
26135 +error:
26136 + kfree(fp->work);
26137 +
26138 out:
26139 kfree(addrs);
26140 return;
26141 @@ -652,18 +663,20 @@ out:
26142
26143 static void jit_free_defer(struct work_struct *arg)
26144 {
26145 - module_free(NULL, arg);
26146 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
26147 + kfree(arg);
26148 }
26149
26150 /* run from softirq, we must use a work_struct to call
26151 - * module_free() from process context
26152 + * module_free_exec() from process context
26153 */
26154 void bpf_jit_free(struct sk_filter *fp)
26155 {
26156 if (fp->bpf_func != sk_run_filter) {
26157 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
26158 + struct work_struct *work = &fp->work->work;
26159
26160 INIT_WORK(work, jit_free_defer);
26161 + fp->work->image = fp->bpf_func;
26162 schedule_work(work);
26163 }
26164 }
26165 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
26166 index d6aa6e8..266395a 100644
26167 --- a/arch/x86/oprofile/backtrace.c
26168 +++ b/arch/x86/oprofile/backtrace.c
26169 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
26170 struct stack_frame_ia32 *fp;
26171 unsigned long bytes;
26172
26173 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26174 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26175 if (bytes != sizeof(bufhead))
26176 return NULL;
26177
26178 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
26179 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
26180
26181 oprofile_add_trace(bufhead[0].return_address);
26182
26183 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
26184 struct stack_frame bufhead[2];
26185 unsigned long bytes;
26186
26187 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26188 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26189 if (bytes != sizeof(bufhead))
26190 return NULL;
26191
26192 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
26193 {
26194 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
26195
26196 - if (!user_mode_vm(regs)) {
26197 + if (!user_mode(regs)) {
26198 unsigned long stack = kernel_stack_pointer(regs);
26199 if (depth)
26200 dump_trace(NULL, regs, (unsigned long *)stack, 0,
26201 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
26202 index e14a2ff..3fd6b58 100644
26203 --- a/arch/x86/pci/mrst.c
26204 +++ b/arch/x86/pci/mrst.c
26205 @@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
26206 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
26207 pci_mmcfg_late_init();
26208 pcibios_enable_irq = mrst_pci_irq_enable;
26209 - pci_root_ops = pci_mrst_ops;
26210 + pax_open_kernel();
26211 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
26212 + pax_close_kernel();
26213 pci_soc_mode = 1;
26214 /* Continue with standard init */
26215 return 1;
26216 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
26217 index da8fe05..7ee6704 100644
26218 --- a/arch/x86/pci/pcbios.c
26219 +++ b/arch/x86/pci/pcbios.c
26220 @@ -79,50 +79,93 @@ union bios32 {
26221 static struct {
26222 unsigned long address;
26223 unsigned short segment;
26224 -} bios32_indirect = { 0, __KERNEL_CS };
26225 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
26226
26227 /*
26228 * Returns the entry point for the given service, NULL on error
26229 */
26230
26231 -static unsigned long bios32_service(unsigned long service)
26232 +static unsigned long __devinit bios32_service(unsigned long service)
26233 {
26234 unsigned char return_code; /* %al */
26235 unsigned long address; /* %ebx */
26236 unsigned long length; /* %ecx */
26237 unsigned long entry; /* %edx */
26238 unsigned long flags;
26239 + struct desc_struct d, *gdt;
26240
26241 local_irq_save(flags);
26242 - __asm__("lcall *(%%edi); cld"
26243 +
26244 + gdt = get_cpu_gdt_table(smp_processor_id());
26245 +
26246 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
26247 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26248 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
26249 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26250 +
26251 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
26252 : "=a" (return_code),
26253 "=b" (address),
26254 "=c" (length),
26255 "=d" (entry)
26256 : "0" (service),
26257 "1" (0),
26258 - "D" (&bios32_indirect));
26259 + "D" (&bios32_indirect),
26260 + "r"(__PCIBIOS_DS)
26261 + : "memory");
26262 +
26263 + pax_open_kernel();
26264 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
26265 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
26266 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
26267 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
26268 + pax_close_kernel();
26269 +
26270 local_irq_restore(flags);
26271
26272 switch (return_code) {
26273 - case 0:
26274 - return address + entry;
26275 - case 0x80: /* Not present */
26276 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26277 - return 0;
26278 - default: /* Shouldn't happen */
26279 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26280 - service, return_code);
26281 + case 0: {
26282 + int cpu;
26283 + unsigned char flags;
26284 +
26285 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26286 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26287 + printk(KERN_WARNING "bios32_service: not valid\n");
26288 return 0;
26289 + }
26290 + address = address + PAGE_OFFSET;
26291 + length += 16UL; /* some BIOSs underreport this... */
26292 + flags = 4;
26293 + if (length >= 64*1024*1024) {
26294 + length >>= PAGE_SHIFT;
26295 + flags |= 8;
26296 + }
26297 +
26298 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26299 + gdt = get_cpu_gdt_table(cpu);
26300 + pack_descriptor(&d, address, length, 0x9b, flags);
26301 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26302 + pack_descriptor(&d, address, length, 0x93, flags);
26303 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26304 + }
26305 + return entry;
26306 + }
26307 + case 0x80: /* Not present */
26308 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26309 + return 0;
26310 + default: /* Shouldn't happen */
26311 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26312 + service, return_code);
26313 + return 0;
26314 }
26315 }
26316
26317 static struct {
26318 unsigned long address;
26319 unsigned short segment;
26320 -} pci_indirect = { 0, __KERNEL_CS };
26321 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26322
26323 -static int pci_bios_present;
26324 +static int pci_bios_present __read_only;
26325
26326 static int __devinit check_pcibios(void)
26327 {
26328 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
26329 unsigned long flags, pcibios_entry;
26330
26331 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26332 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26333 + pci_indirect.address = pcibios_entry;
26334
26335 local_irq_save(flags);
26336 - __asm__(
26337 - "lcall *(%%edi); cld\n\t"
26338 + __asm__("movw %w6, %%ds\n\t"
26339 + "lcall *%%ss:(%%edi); cld\n\t"
26340 + "push %%ss\n\t"
26341 + "pop %%ds\n\t"
26342 "jc 1f\n\t"
26343 "xor %%ah, %%ah\n"
26344 "1:"
26345 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
26346 "=b" (ebx),
26347 "=c" (ecx)
26348 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26349 - "D" (&pci_indirect)
26350 + "D" (&pci_indirect),
26351 + "r" (__PCIBIOS_DS)
26352 : "memory");
26353 local_irq_restore(flags);
26354
26355 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26356
26357 switch (len) {
26358 case 1:
26359 - __asm__("lcall *(%%esi); cld\n\t"
26360 + __asm__("movw %w6, %%ds\n\t"
26361 + "lcall *%%ss:(%%esi); cld\n\t"
26362 + "push %%ss\n\t"
26363 + "pop %%ds\n\t"
26364 "jc 1f\n\t"
26365 "xor %%ah, %%ah\n"
26366 "1:"
26367 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26368 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26369 "b" (bx),
26370 "D" ((long)reg),
26371 - "S" (&pci_indirect));
26372 + "S" (&pci_indirect),
26373 + "r" (__PCIBIOS_DS));
26374 /*
26375 * Zero-extend the result beyond 8 bits, do not trust the
26376 * BIOS having done it:
26377 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26378 *value &= 0xff;
26379 break;
26380 case 2:
26381 - __asm__("lcall *(%%esi); cld\n\t"
26382 + __asm__("movw %w6, %%ds\n\t"
26383 + "lcall *%%ss:(%%esi); cld\n\t"
26384 + "push %%ss\n\t"
26385 + "pop %%ds\n\t"
26386 "jc 1f\n\t"
26387 "xor %%ah, %%ah\n"
26388 "1:"
26389 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26390 : "1" (PCIBIOS_READ_CONFIG_WORD),
26391 "b" (bx),
26392 "D" ((long)reg),
26393 - "S" (&pci_indirect));
26394 + "S" (&pci_indirect),
26395 + "r" (__PCIBIOS_DS));
26396 /*
26397 * Zero-extend the result beyond 16 bits, do not trust the
26398 * BIOS having done it:
26399 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26400 *value &= 0xffff;
26401 break;
26402 case 4:
26403 - __asm__("lcall *(%%esi); cld\n\t"
26404 + __asm__("movw %w6, %%ds\n\t"
26405 + "lcall *%%ss:(%%esi); cld\n\t"
26406 + "push %%ss\n\t"
26407 + "pop %%ds\n\t"
26408 "jc 1f\n\t"
26409 "xor %%ah, %%ah\n"
26410 "1:"
26411 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26412 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26413 "b" (bx),
26414 "D" ((long)reg),
26415 - "S" (&pci_indirect));
26416 + "S" (&pci_indirect),
26417 + "r" (__PCIBIOS_DS));
26418 break;
26419 }
26420
26421 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26422
26423 switch (len) {
26424 case 1:
26425 - __asm__("lcall *(%%esi); cld\n\t"
26426 + __asm__("movw %w6, %%ds\n\t"
26427 + "lcall *%%ss:(%%esi); cld\n\t"
26428 + "push %%ss\n\t"
26429 + "pop %%ds\n\t"
26430 "jc 1f\n\t"
26431 "xor %%ah, %%ah\n"
26432 "1:"
26433 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26434 "c" (value),
26435 "b" (bx),
26436 "D" ((long)reg),
26437 - "S" (&pci_indirect));
26438 + "S" (&pci_indirect),
26439 + "r" (__PCIBIOS_DS));
26440 break;
26441 case 2:
26442 - __asm__("lcall *(%%esi); cld\n\t"
26443 + __asm__("movw %w6, %%ds\n\t"
26444 + "lcall *%%ss:(%%esi); cld\n\t"
26445 + "push %%ss\n\t"
26446 + "pop %%ds\n\t"
26447 "jc 1f\n\t"
26448 "xor %%ah, %%ah\n"
26449 "1:"
26450 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26451 "c" (value),
26452 "b" (bx),
26453 "D" ((long)reg),
26454 - "S" (&pci_indirect));
26455 + "S" (&pci_indirect),
26456 + "r" (__PCIBIOS_DS));
26457 break;
26458 case 4:
26459 - __asm__("lcall *(%%esi); cld\n\t"
26460 + __asm__("movw %w6, %%ds\n\t"
26461 + "lcall *%%ss:(%%esi); cld\n\t"
26462 + "push %%ss\n\t"
26463 + "pop %%ds\n\t"
26464 "jc 1f\n\t"
26465 "xor %%ah, %%ah\n"
26466 "1:"
26467 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26468 "c" (value),
26469 "b" (bx),
26470 "D" ((long)reg),
26471 - "S" (&pci_indirect));
26472 + "S" (&pci_indirect),
26473 + "r" (__PCIBIOS_DS));
26474 break;
26475 }
26476
26477 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26478
26479 DBG("PCI: Fetching IRQ routing table... ");
26480 __asm__("push %%es\n\t"
26481 + "movw %w8, %%ds\n\t"
26482 "push %%ds\n\t"
26483 "pop %%es\n\t"
26484 - "lcall *(%%esi); cld\n\t"
26485 + "lcall *%%ss:(%%esi); cld\n\t"
26486 "pop %%es\n\t"
26487 + "push %%ss\n\t"
26488 + "pop %%ds\n"
26489 "jc 1f\n\t"
26490 "xor %%ah, %%ah\n"
26491 "1:"
26492 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26493 "1" (0),
26494 "D" ((long) &opt),
26495 "S" (&pci_indirect),
26496 - "m" (opt)
26497 + "m" (opt),
26498 + "r" (__PCIBIOS_DS)
26499 : "memory");
26500 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26501 if (ret & 0xff00)
26502 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26503 {
26504 int ret;
26505
26506 - __asm__("lcall *(%%esi); cld\n\t"
26507 + __asm__("movw %w5, %%ds\n\t"
26508 + "lcall *%%ss:(%%esi); cld\n\t"
26509 + "push %%ss\n\t"
26510 + "pop %%ds\n"
26511 "jc 1f\n\t"
26512 "xor %%ah, %%ah\n"
26513 "1:"
26514 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26515 : "0" (PCIBIOS_SET_PCI_HW_INT),
26516 "b" ((dev->bus->number << 8) | dev->devfn),
26517 "c" ((irq << 8) | (pin + 10)),
26518 - "S" (&pci_indirect));
26519 + "S" (&pci_indirect),
26520 + "r" (__PCIBIOS_DS));
26521 return !(ret & 0xff00);
26522 }
26523 EXPORT_SYMBOL(pcibios_set_irq_routing);
26524 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26525 index 40e4469..1ab536e 100644
26526 --- a/arch/x86/platform/efi/efi_32.c
26527 +++ b/arch/x86/platform/efi/efi_32.c
26528 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26529 {
26530 struct desc_ptr gdt_descr;
26531
26532 +#ifdef CONFIG_PAX_KERNEXEC
26533 + struct desc_struct d;
26534 +#endif
26535 +
26536 local_irq_save(efi_rt_eflags);
26537
26538 load_cr3(initial_page_table);
26539 __flush_tlb_all();
26540
26541 +#ifdef CONFIG_PAX_KERNEXEC
26542 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26543 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26544 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26545 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26546 +#endif
26547 +
26548 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26549 gdt_descr.size = GDT_SIZE - 1;
26550 load_gdt(&gdt_descr);
26551 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26552 {
26553 struct desc_ptr gdt_descr;
26554
26555 +#ifdef CONFIG_PAX_KERNEXEC
26556 + struct desc_struct d;
26557 +
26558 + memset(&d, 0, sizeof d);
26559 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26560 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26561 +#endif
26562 +
26563 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26564 gdt_descr.size = GDT_SIZE - 1;
26565 load_gdt(&gdt_descr);
26566 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26567 index fbe66e6..eae5e38 100644
26568 --- a/arch/x86/platform/efi/efi_stub_32.S
26569 +++ b/arch/x86/platform/efi/efi_stub_32.S
26570 @@ -6,7 +6,9 @@
26571 */
26572
26573 #include <linux/linkage.h>
26574 +#include <linux/init.h>
26575 #include <asm/page_types.h>
26576 +#include <asm/segment.h>
26577
26578 /*
26579 * efi_call_phys(void *, ...) is a function with variable parameters.
26580 @@ -20,7 +22,7 @@
26581 * service functions will comply with gcc calling convention, too.
26582 */
26583
26584 -.text
26585 +__INIT
26586 ENTRY(efi_call_phys)
26587 /*
26588 * 0. The function can only be called in Linux kernel. So CS has been
26589 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
26590 * The mapping of lower virtual memory has been created in prelog and
26591 * epilog.
26592 */
26593 - movl $1f, %edx
26594 - subl $__PAGE_OFFSET, %edx
26595 - jmp *%edx
26596 +#ifdef CONFIG_PAX_KERNEXEC
26597 + movl $(__KERNEXEC_EFI_DS), %edx
26598 + mov %edx, %ds
26599 + mov %edx, %es
26600 + mov %edx, %ss
26601 + addl $2f,(1f)
26602 + ljmp *(1f)
26603 +
26604 +__INITDATA
26605 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
26606 +.previous
26607 +
26608 +2:
26609 + subl $2b,(1b)
26610 +#else
26611 + jmp 1f-__PAGE_OFFSET
26612 1:
26613 +#endif
26614
26615 /*
26616 * 2. Now on the top of stack is the return
26617 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
26618 * parameter 2, ..., param n. To make things easy, we save the return
26619 * address of efi_call_phys in a global variable.
26620 */
26621 - popl %edx
26622 - movl %edx, saved_return_addr
26623 - /* get the function pointer into ECX*/
26624 - popl %ecx
26625 - movl %ecx, efi_rt_function_ptr
26626 - movl $2f, %edx
26627 - subl $__PAGE_OFFSET, %edx
26628 - pushl %edx
26629 + popl (saved_return_addr)
26630 + popl (efi_rt_function_ptr)
26631
26632 /*
26633 * 3. Clear PG bit in %CR0.
26634 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
26635 /*
26636 * 5. Call the physical function.
26637 */
26638 - jmp *%ecx
26639 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
26640
26641 -2:
26642 /*
26643 * 6. After EFI runtime service returns, control will return to
26644 * following instruction. We'd better readjust stack pointer first.
26645 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
26646 movl %cr0, %edx
26647 orl $0x80000000, %edx
26648 movl %edx, %cr0
26649 - jmp 1f
26650 -1:
26651 +
26652 /*
26653 * 8. Now restore the virtual mode from flat mode by
26654 * adding EIP with PAGE_OFFSET.
26655 */
26656 - movl $1f, %edx
26657 - jmp *%edx
26658 +#ifdef CONFIG_PAX_KERNEXEC
26659 + movl $(__KERNEL_DS), %edx
26660 + mov %edx, %ds
26661 + mov %edx, %es
26662 + mov %edx, %ss
26663 + ljmp $(__KERNEL_CS),$1f
26664 +#else
26665 + jmp 1f+__PAGE_OFFSET
26666 +#endif
26667 1:
26668
26669 /*
26670 * 9. Balance the stack. And because EAX contain the return value,
26671 * we'd better not clobber it.
26672 */
26673 - leal efi_rt_function_ptr, %edx
26674 - movl (%edx), %ecx
26675 - pushl %ecx
26676 + pushl (efi_rt_function_ptr)
26677
26678 /*
26679 - * 10. Push the saved return address onto the stack and return.
26680 + * 10. Return to the saved return address.
26681 */
26682 - leal saved_return_addr, %edx
26683 - movl (%edx), %ecx
26684 - pushl %ecx
26685 - ret
26686 + jmpl *(saved_return_addr)
26687 ENDPROC(efi_call_phys)
26688 .previous
26689
26690 -.data
26691 +__INITDATA
26692 saved_return_addr:
26693 .long 0
26694 efi_rt_function_ptr:
26695 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
26696 index 4c07cca..2c8427d 100644
26697 --- a/arch/x86/platform/efi/efi_stub_64.S
26698 +++ b/arch/x86/platform/efi/efi_stub_64.S
26699 @@ -7,6 +7,7 @@
26700 */
26701
26702 #include <linux/linkage.h>
26703 +#include <asm/alternative-asm.h>
26704
26705 #define SAVE_XMM \
26706 mov %rsp, %rax; \
26707 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
26708 call *%rdi
26709 addq $32, %rsp
26710 RESTORE_XMM
26711 + pax_force_retaddr 0, 1
26712 ret
26713 ENDPROC(efi_call0)
26714
26715 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
26716 call *%rdi
26717 addq $32, %rsp
26718 RESTORE_XMM
26719 + pax_force_retaddr 0, 1
26720 ret
26721 ENDPROC(efi_call1)
26722
26723 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
26724 call *%rdi
26725 addq $32, %rsp
26726 RESTORE_XMM
26727 + pax_force_retaddr 0, 1
26728 ret
26729 ENDPROC(efi_call2)
26730
26731 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
26732 call *%rdi
26733 addq $32, %rsp
26734 RESTORE_XMM
26735 + pax_force_retaddr 0, 1
26736 ret
26737 ENDPROC(efi_call3)
26738
26739 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
26740 call *%rdi
26741 addq $32, %rsp
26742 RESTORE_XMM
26743 + pax_force_retaddr 0, 1
26744 ret
26745 ENDPROC(efi_call4)
26746
26747 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
26748 call *%rdi
26749 addq $48, %rsp
26750 RESTORE_XMM
26751 + pax_force_retaddr 0, 1
26752 ret
26753 ENDPROC(efi_call5)
26754
26755 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
26756 call *%rdi
26757 addq $48, %rsp
26758 RESTORE_XMM
26759 + pax_force_retaddr 0, 1
26760 ret
26761 ENDPROC(efi_call6)
26762 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
26763 index fd41a92..9c33628 100644
26764 --- a/arch/x86/platform/mrst/mrst.c
26765 +++ b/arch/x86/platform/mrst/mrst.c
26766 @@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
26767 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
26768 int sfi_mrtc_num;
26769
26770 -static void mrst_power_off(void)
26771 +static __noreturn void mrst_power_off(void)
26772 {
26773 + BUG();
26774 }
26775
26776 -static void mrst_reboot(void)
26777 +static __noreturn void mrst_reboot(void)
26778 {
26779 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
26780 + BUG();
26781 }
26782
26783 /* parse all the mtimer info to a static mtimer array */
26784 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
26785 index 218cdb1..fd55c08 100644
26786 --- a/arch/x86/power/cpu.c
26787 +++ b/arch/x86/power/cpu.c
26788 @@ -132,7 +132,7 @@ static void do_fpu_end(void)
26789 static void fix_processor_context(void)
26790 {
26791 int cpu = smp_processor_id();
26792 - struct tss_struct *t = &per_cpu(init_tss, cpu);
26793 + struct tss_struct *t = init_tss + cpu;
26794
26795 set_tss_desc(cpu, t); /*
26796 * This just modifies memory; should not be
26797 @@ -142,7 +142,9 @@ static void fix_processor_context(void)
26798 */
26799
26800 #ifdef CONFIG_X86_64
26801 + pax_open_kernel();
26802 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
26803 + pax_close_kernel();
26804
26805 syscall_init(); /* This sets MSR_*STAR and related */
26806 #endif
26807 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
26808 index cbca565..bae7133 100644
26809 --- a/arch/x86/realmode/init.c
26810 +++ b/arch/x86/realmode/init.c
26811 @@ -62,7 +62,13 @@ void __init setup_real_mode(void)
26812 __va(real_mode_header->trampoline_header);
26813
26814 #ifdef CONFIG_X86_32
26815 - trampoline_header->start = __pa(startup_32_smp);
26816 + trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
26817 +
26818 +#ifdef CONFIG_PAX_KERNEXEC
26819 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
26820 +#endif
26821 +
26822 + trampoline_header->boot_cs = __BOOT_CS;
26823 trampoline_header->gdt_limit = __BOOT_DS + 7;
26824 trampoline_header->gdt_base = __pa(boot_gdt);
26825 #else
26826 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
26827 index 8869287..d577672 100644
26828 --- a/arch/x86/realmode/rm/Makefile
26829 +++ b/arch/x86/realmode/rm/Makefile
26830 @@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
26831 $(call cc-option, -fno-unit-at-a-time)) \
26832 $(call cc-option, -fno-stack-protector) \
26833 $(call cc-option, -mpreferred-stack-boundary=2)
26834 +ifdef CONSTIFY_PLUGIN
26835 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
26836 +endif
26837 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
26838 GCOV_PROFILE := n
26839 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
26840 index a28221d..93c40f1 100644
26841 --- a/arch/x86/realmode/rm/header.S
26842 +++ b/arch/x86/realmode/rm/header.S
26843 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
26844 #endif
26845 /* APM/BIOS reboot */
26846 .long pa_machine_real_restart_asm
26847 -#ifdef CONFIG_X86_64
26848 +#ifdef CONFIG_X86_32
26849 + .long __KERNEL_CS
26850 +#else
26851 .long __KERNEL32_CS
26852 #endif
26853 END(real_mode_header)
26854 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
26855 index c1b2791..f9e31c7 100644
26856 --- a/arch/x86/realmode/rm/trampoline_32.S
26857 +++ b/arch/x86/realmode/rm/trampoline_32.S
26858 @@ -25,6 +25,12 @@
26859 #include <asm/page_types.h>
26860 #include "realmode.h"
26861
26862 +#ifdef CONFIG_PAX_KERNEXEC
26863 +#define ta(X) (X)
26864 +#else
26865 +#define ta(X) (pa_ ## X)
26866 +#endif
26867 +
26868 .text
26869 .code16
26870
26871 @@ -39,8 +45,6 @@ ENTRY(trampoline_start)
26872
26873 cli # We should be safe anyway
26874
26875 - movl tr_start, %eax # where we need to go
26876 -
26877 movl $0xA5A5A5A5, trampoline_status
26878 # write marker for master knows we're running
26879
26880 @@ -56,7 +60,7 @@ ENTRY(trampoline_start)
26881 movw $1, %dx # protected mode (PE) bit
26882 lmsw %dx # into protected mode
26883
26884 - ljmpl $__BOOT_CS, $pa_startup_32
26885 + ljmpl *(trampoline_header)
26886
26887 .section ".text32","ax"
26888 .code32
26889 @@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
26890 .balign 8
26891 GLOBAL(trampoline_header)
26892 tr_start: .space 4
26893 - tr_gdt_pad: .space 2
26894 + tr_boot_cs: .space 2
26895 tr_gdt: .space 6
26896 END(trampoline_header)
26897
26898 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
26899 index bb360dc..3e5945f 100644
26900 --- a/arch/x86/realmode/rm/trampoline_64.S
26901 +++ b/arch/x86/realmode/rm/trampoline_64.S
26902 @@ -107,7 +107,7 @@ ENTRY(startup_32)
26903 wrmsr
26904
26905 # Enable paging and in turn activate Long Mode
26906 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
26907 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
26908 movl %eax, %cr0
26909
26910 /*
26911 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
26912 index 5a1847d..deccb30 100644
26913 --- a/arch/x86/tools/relocs.c
26914 +++ b/arch/x86/tools/relocs.c
26915 @@ -12,10 +12,13 @@
26916 #include <regex.h>
26917 #include <tools/le_byteshift.h>
26918
26919 +#include "../../../include/generated/autoconf.h"
26920 +
26921 static void die(char *fmt, ...);
26922
26923 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
26924 static Elf32_Ehdr ehdr;
26925 +static Elf32_Phdr *phdr;
26926 static unsigned long reloc_count, reloc_idx;
26927 static unsigned long *relocs;
26928 static unsigned long reloc16_count, reloc16_idx;
26929 @@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
26930 }
26931 }
26932
26933 +static void read_phdrs(FILE *fp)
26934 +{
26935 + unsigned int i;
26936 +
26937 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
26938 + if (!phdr) {
26939 + die("Unable to allocate %d program headers\n",
26940 + ehdr.e_phnum);
26941 + }
26942 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
26943 + die("Seek to %d failed: %s\n",
26944 + ehdr.e_phoff, strerror(errno));
26945 + }
26946 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
26947 + die("Cannot read ELF program headers: %s\n",
26948 + strerror(errno));
26949 + }
26950 + for(i = 0; i < ehdr.e_phnum; i++) {
26951 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
26952 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
26953 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
26954 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
26955 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
26956 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
26957 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
26958 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
26959 + }
26960 +
26961 +}
26962 +
26963 static void read_shdrs(FILE *fp)
26964 {
26965 - int i;
26966 + unsigned int i;
26967 Elf32_Shdr shdr;
26968
26969 secs = calloc(ehdr.e_shnum, sizeof(struct section));
26970 @@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
26971
26972 static void read_strtabs(FILE *fp)
26973 {
26974 - int i;
26975 + unsigned int i;
26976 for (i = 0; i < ehdr.e_shnum; i++) {
26977 struct section *sec = &secs[i];
26978 if (sec->shdr.sh_type != SHT_STRTAB) {
26979 @@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
26980
26981 static void read_symtabs(FILE *fp)
26982 {
26983 - int i,j;
26984 + unsigned int i,j;
26985 for (i = 0; i < ehdr.e_shnum; i++) {
26986 struct section *sec = &secs[i];
26987 if (sec->shdr.sh_type != SHT_SYMTAB) {
26988 @@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
26989 }
26990
26991
26992 -static void read_relocs(FILE *fp)
26993 +static void read_relocs(FILE *fp, int use_real_mode)
26994 {
26995 - int i,j;
26996 + unsigned int i,j;
26997 + uint32_t base;
26998 +
26999 for (i = 0; i < ehdr.e_shnum; i++) {
27000 struct section *sec = &secs[i];
27001 if (sec->shdr.sh_type != SHT_REL) {
27002 @@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
27003 die("Cannot read symbol table: %s\n",
27004 strerror(errno));
27005 }
27006 + base = 0;
27007 +
27008 +#ifdef CONFIG_X86_32
27009 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
27010 + if (phdr[j].p_type != PT_LOAD )
27011 + continue;
27012 + 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)
27013 + continue;
27014 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
27015 + break;
27016 + }
27017 +#endif
27018 +
27019 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
27020 Elf32_Rel *rel = &sec->reltab[j];
27021 - rel->r_offset = elf32_to_cpu(rel->r_offset);
27022 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
27023 rel->r_info = elf32_to_cpu(rel->r_info);
27024 }
27025 }
27026 @@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
27027
27028 static void print_absolute_symbols(void)
27029 {
27030 - int i;
27031 + unsigned int i;
27032 printf("Absolute symbols\n");
27033 printf(" Num: Value Size Type Bind Visibility Name\n");
27034 for (i = 0; i < ehdr.e_shnum; i++) {
27035 struct section *sec = &secs[i];
27036 char *sym_strtab;
27037 - int j;
27038 + unsigned int j;
27039
27040 if (sec->shdr.sh_type != SHT_SYMTAB) {
27041 continue;
27042 @@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
27043
27044 static void print_absolute_relocs(void)
27045 {
27046 - int i, printed = 0;
27047 + unsigned int i, printed = 0;
27048
27049 for (i = 0; i < ehdr.e_shnum; i++) {
27050 struct section *sec = &secs[i];
27051 struct section *sec_applies, *sec_symtab;
27052 char *sym_strtab;
27053 Elf32_Sym *sh_symtab;
27054 - int j;
27055 + unsigned int j;
27056 if (sec->shdr.sh_type != SHT_REL) {
27057 continue;
27058 }
27059 @@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
27060 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
27061 int use_real_mode)
27062 {
27063 - int i;
27064 + unsigned int i;
27065 /* Walk through the relocations */
27066 for (i = 0; i < ehdr.e_shnum; i++) {
27067 char *sym_strtab;
27068 Elf32_Sym *sh_symtab;
27069 struct section *sec_applies, *sec_symtab;
27070 - int j;
27071 + unsigned int j;
27072 struct section *sec = &secs[i];
27073
27074 if (sec->shdr.sh_type != SHT_REL) {
27075 @@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
27076 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
27077 r_type = ELF32_R_TYPE(rel->r_info);
27078
27079 + if (!use_real_mode) {
27080 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
27081 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
27082 + continue;
27083 +
27084 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
27085 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
27086 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
27087 + continue;
27088 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
27089 + continue;
27090 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
27091 + continue;
27092 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
27093 + continue;
27094 +#endif
27095 + }
27096 +
27097 shn_abs = sym->st_shndx == SHN_ABS;
27098
27099 switch (r_type) {
27100 @@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
27101
27102 static void emit_relocs(int as_text, int use_real_mode)
27103 {
27104 - int i;
27105 + unsigned int i;
27106 /* Count how many relocations I have and allocate space for them. */
27107 reloc_count = 0;
27108 walk_relocs(count_reloc, use_real_mode);
27109 @@ -808,10 +874,11 @@ int main(int argc, char **argv)
27110 fname, strerror(errno));
27111 }
27112 read_ehdr(fp);
27113 + read_phdrs(fp);
27114 read_shdrs(fp);
27115 read_strtabs(fp);
27116 read_symtabs(fp);
27117 - read_relocs(fp);
27118 + read_relocs(fp, use_real_mode);
27119 if (show_absolute_syms) {
27120 print_absolute_symbols();
27121 return 0;
27122 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
27123 index fd14be1..e3c79c0 100644
27124 --- a/arch/x86/vdso/Makefile
27125 +++ b/arch/x86/vdso/Makefile
27126 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
27127 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
27128 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
27129
27130 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27131 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27132 GCOV_PROFILE := n
27133
27134 #
27135 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
27136 index 0faad64..39ef157 100644
27137 --- a/arch/x86/vdso/vdso32-setup.c
27138 +++ b/arch/x86/vdso/vdso32-setup.c
27139 @@ -25,6 +25,7 @@
27140 #include <asm/tlbflush.h>
27141 #include <asm/vdso.h>
27142 #include <asm/proto.h>
27143 +#include <asm/mman.h>
27144
27145 enum {
27146 VDSO_DISABLED = 0,
27147 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
27148 void enable_sep_cpu(void)
27149 {
27150 int cpu = get_cpu();
27151 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
27152 + struct tss_struct *tss = init_tss + cpu;
27153
27154 if (!boot_cpu_has(X86_FEATURE_SEP)) {
27155 put_cpu();
27156 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
27157 gate_vma.vm_start = FIXADDR_USER_START;
27158 gate_vma.vm_end = FIXADDR_USER_END;
27159 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
27160 - gate_vma.vm_page_prot = __P101;
27161 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
27162
27163 return 0;
27164 }
27165 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27166 if (compat)
27167 addr = VDSO_HIGH_BASE;
27168 else {
27169 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
27170 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
27171 if (IS_ERR_VALUE(addr)) {
27172 ret = addr;
27173 goto up_fail;
27174 }
27175 }
27176
27177 - current->mm->context.vdso = (void *)addr;
27178 + current->mm->context.vdso = addr;
27179
27180 if (compat_uses_vma || !compat) {
27181 /*
27182 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27183 }
27184
27185 current_thread_info()->sysenter_return =
27186 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27187 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27188
27189 up_fail:
27190 if (ret)
27191 - current->mm->context.vdso = NULL;
27192 + current->mm->context.vdso = 0;
27193
27194 up_write(&mm->mmap_sem);
27195
27196 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
27197
27198 const char *arch_vma_name(struct vm_area_struct *vma)
27199 {
27200 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
27201 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
27202 return "[vdso]";
27203 +
27204 +#ifdef CONFIG_PAX_SEGMEXEC
27205 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
27206 + return "[vdso]";
27207 +#endif
27208 +
27209 return NULL;
27210 }
27211
27212 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
27213 * Check to see if the corresponding task was created in compat vdso
27214 * mode.
27215 */
27216 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
27217 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
27218 return &gate_vma;
27219 return NULL;
27220 }
27221 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
27222 index 00aaf04..4a26505 100644
27223 --- a/arch/x86/vdso/vma.c
27224 +++ b/arch/x86/vdso/vma.c
27225 @@ -16,8 +16,6 @@
27226 #include <asm/vdso.h>
27227 #include <asm/page.h>
27228
27229 -unsigned int __read_mostly vdso_enabled = 1;
27230 -
27231 extern char vdso_start[], vdso_end[];
27232 extern unsigned short vdso_sync_cpuid;
27233
27234 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
27235 * unaligned here as a result of stack start randomization.
27236 */
27237 addr = PAGE_ALIGN(addr);
27238 - addr = align_addr(addr, NULL, ALIGN_VDSO);
27239
27240 return addr;
27241 }
27242 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
27243 unsigned size)
27244 {
27245 struct mm_struct *mm = current->mm;
27246 - unsigned long addr;
27247 + unsigned long addr = 0;
27248 int ret;
27249
27250 - if (!vdso_enabled)
27251 - return 0;
27252 -
27253 down_write(&mm->mmap_sem);
27254 +
27255 +#ifdef CONFIG_PAX_RANDMMAP
27256 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27257 +#endif
27258 +
27259 addr = vdso_addr(mm->start_stack, size);
27260 + addr = align_addr(addr, NULL, ALIGN_VDSO);
27261 addr = get_unmapped_area(NULL, addr, size, 0, 0);
27262 if (IS_ERR_VALUE(addr)) {
27263 ret = addr;
27264 goto up_fail;
27265 }
27266
27267 - current->mm->context.vdso = (void *)addr;
27268 + mm->context.vdso = addr;
27269
27270 ret = install_special_mapping(mm, addr, size,
27271 VM_READ|VM_EXEC|
27272 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
27273 pages);
27274 - if (ret) {
27275 - current->mm->context.vdso = NULL;
27276 - goto up_fail;
27277 - }
27278 + if (ret)
27279 + mm->context.vdso = 0;
27280
27281 up_fail:
27282 up_write(&mm->mmap_sem);
27283 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27284 vdsox32_size);
27285 }
27286 #endif
27287 -
27288 -static __init int vdso_setup(char *s)
27289 -{
27290 - vdso_enabled = simple_strtoul(s, NULL, 0);
27291 - return 0;
27292 -}
27293 -__setup("vdso=", vdso_setup);
27294 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
27295 index c1461de..355f120 100644
27296 --- a/arch/x86/xen/enlighten.c
27297 +++ b/arch/x86/xen/enlighten.c
27298 @@ -98,8 +98,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
27299
27300 struct shared_info xen_dummy_shared_info;
27301
27302 -void *xen_initial_gdt;
27303 -
27304 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
27305 __read_mostly int xen_have_vector_callback;
27306 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
27307 @@ -917,21 +915,21 @@ static u32 xen_safe_apic_wait_icr_idle(void)
27308
27309 static void set_xen_basic_apic_ops(void)
27310 {
27311 - apic->read = xen_apic_read;
27312 - apic->write = xen_apic_write;
27313 - apic->icr_read = xen_apic_icr_read;
27314 - apic->icr_write = xen_apic_icr_write;
27315 - apic->wait_icr_idle = xen_apic_wait_icr_idle;
27316 - apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
27317 - apic->set_apic_id = xen_set_apic_id;
27318 - apic->get_apic_id = xen_get_apic_id;
27319 + *(void **)&apic->read = xen_apic_read;
27320 + *(void **)&apic->write = xen_apic_write;
27321 + *(void **)&apic->icr_read = xen_apic_icr_read;
27322 + *(void **)&apic->icr_write = xen_apic_icr_write;
27323 + *(void **)&apic->wait_icr_idle = xen_apic_wait_icr_idle;
27324 + *(void **)&apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
27325 + *(void **)&apic->set_apic_id = xen_set_apic_id;
27326 + *(void **)&apic->get_apic_id = xen_get_apic_id;
27327
27328 #ifdef CONFIG_SMP
27329 - apic->send_IPI_allbutself = xen_send_IPI_allbutself;
27330 - apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
27331 - apic->send_IPI_mask = xen_send_IPI_mask;
27332 - apic->send_IPI_all = xen_send_IPI_all;
27333 - apic->send_IPI_self = xen_send_IPI_self;
27334 + *(void **)&apic->send_IPI_allbutself = xen_send_IPI_allbutself;
27335 + *(void **)&apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
27336 + *(void **)&apic->send_IPI_mask = xen_send_IPI_mask;
27337 + *(void **)&apic->send_IPI_all = xen_send_IPI_all;
27338 + *(void **)&apic->send_IPI_self = xen_send_IPI_self;
27339 #endif
27340 }
27341
27342 @@ -1221,30 +1219,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
27343 #endif
27344 };
27345
27346 -static void xen_reboot(int reason)
27347 +static __noreturn void xen_reboot(int reason)
27348 {
27349 struct sched_shutdown r = { .reason = reason };
27350
27351 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
27352 - BUG();
27353 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
27354 + BUG();
27355 }
27356
27357 -static void xen_restart(char *msg)
27358 +static __noreturn void xen_restart(char *msg)
27359 {
27360 xen_reboot(SHUTDOWN_reboot);
27361 }
27362
27363 -static void xen_emergency_restart(void)
27364 +static __noreturn void xen_emergency_restart(void)
27365 {
27366 xen_reboot(SHUTDOWN_reboot);
27367 }
27368
27369 -static void xen_machine_halt(void)
27370 +static __noreturn void xen_machine_halt(void)
27371 {
27372 xen_reboot(SHUTDOWN_poweroff);
27373 }
27374
27375 -static void xen_machine_power_off(void)
27376 +static __noreturn void xen_machine_power_off(void)
27377 {
27378 if (pm_power_off)
27379 pm_power_off();
27380 @@ -1347,7 +1345,17 @@ asmlinkage void __init xen_start_kernel(void)
27381 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
27382
27383 /* Work out if we support NX */
27384 - x86_configure_nx();
27385 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27386 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
27387 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
27388 + unsigned l, h;
27389 +
27390 + __supported_pte_mask |= _PAGE_NX;
27391 + rdmsr(MSR_EFER, l, h);
27392 + l |= EFER_NX;
27393 + wrmsr(MSR_EFER, l, h);
27394 + }
27395 +#endif
27396
27397 xen_setup_features();
27398
27399 @@ -1378,13 +1386,6 @@ asmlinkage void __init xen_start_kernel(void)
27400
27401 machine_ops = xen_machine_ops;
27402
27403 - /*
27404 - * The only reliable way to retain the initial address of the
27405 - * percpu gdt_page is to remember it here, so we can go and
27406 - * mark it RW later, when the initial percpu area is freed.
27407 - */
27408 - xen_initial_gdt = &per_cpu(gdt_page, 0);
27409 -
27410 xen_smp_init();
27411
27412 #ifdef CONFIG_ACPI_NUMA
27413 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
27414 index 5141d80..6c9fb41 100644
27415 --- a/arch/x86/xen/mmu.c
27416 +++ b/arch/x86/xen/mmu.c
27417 @@ -1765,6 +1765,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27418 convert_pfn_mfn(init_level4_pgt);
27419 convert_pfn_mfn(level3_ident_pgt);
27420 convert_pfn_mfn(level3_kernel_pgt);
27421 + convert_pfn_mfn(level3_vmalloc_start_pgt);
27422 + convert_pfn_mfn(level3_vmalloc_end_pgt);
27423 + convert_pfn_mfn(level3_vmemmap_pgt);
27424
27425 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
27426 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
27427 @@ -1783,7 +1786,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27428 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
27429 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
27430 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
27431 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
27432 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
27433 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
27434 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
27435 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
27436 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
27437 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
27438
27439 @@ -1967,6 +1974,7 @@ static void __init xen_post_allocator_init(void)
27440 pv_mmu_ops.set_pud = xen_set_pud;
27441 #if PAGETABLE_LEVELS == 4
27442 pv_mmu_ops.set_pgd = xen_set_pgd;
27443 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
27444 #endif
27445
27446 /* This will work as long as patching hasn't happened yet
27447 @@ -2048,6 +2056,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
27448 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
27449 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
27450 .set_pgd = xen_set_pgd_hyper,
27451 + .set_pgd_batched = xen_set_pgd_hyper,
27452
27453 .alloc_pud = xen_alloc_pmd_init,
27454 .release_pud = xen_release_pmd_init,
27455 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
27456 index f58dca7..ad21f52 100644
27457 --- a/arch/x86/xen/smp.c
27458 +++ b/arch/x86/xen/smp.c
27459 @@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
27460 {
27461 BUG_ON(smp_processor_id() != 0);
27462 native_smp_prepare_boot_cpu();
27463 -
27464 - /* We've switched to the "real" per-cpu gdt, so make sure the
27465 - old memory can be recycled */
27466 - make_lowmem_page_readwrite(xen_initial_gdt);
27467 -
27468 xen_filter_cpu_maps();
27469 xen_setup_vcpu_info_placement();
27470 }
27471 @@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
27472 gdt = get_cpu_gdt_table(cpu);
27473
27474 ctxt->flags = VGCF_IN_KERNEL;
27475 - ctxt->user_regs.ds = __USER_DS;
27476 - ctxt->user_regs.es = __USER_DS;
27477 + ctxt->user_regs.ds = __KERNEL_DS;
27478 + ctxt->user_regs.es = __KERNEL_DS;
27479 ctxt->user_regs.ss = __KERNEL_DS;
27480 #ifdef CONFIG_X86_32
27481 ctxt->user_regs.fs = __KERNEL_PERCPU;
27482 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
27483 + savesegment(gs, ctxt->user_regs.gs);
27484 #else
27485 ctxt->gs_base_kernel = per_cpu_offset(cpu);
27486 #endif
27487 @@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
27488 int rc;
27489
27490 per_cpu(current_task, cpu) = idle;
27491 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
27492 #ifdef CONFIG_X86_32
27493 irq_ctx_init(cpu);
27494 #else
27495 clear_tsk_thread_flag(idle, TIF_FORK);
27496 - per_cpu(kernel_stack, cpu) =
27497 - (unsigned long)task_stack_page(idle) -
27498 - KERNEL_STACK_OFFSET + THREAD_SIZE;
27499 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27500 #endif
27501 xen_setup_runstate_info(cpu);
27502 xen_setup_timer(cpu);
27503 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
27504 index f9643fc..602e8af 100644
27505 --- a/arch/x86/xen/xen-asm_32.S
27506 +++ b/arch/x86/xen/xen-asm_32.S
27507 @@ -84,14 +84,14 @@ ENTRY(xen_iret)
27508 ESP_OFFSET=4 # bytes pushed onto stack
27509
27510 /*
27511 - * Store vcpu_info pointer for easy access. Do it this way to
27512 - * avoid having to reload %fs
27513 + * Store vcpu_info pointer for easy access.
27514 */
27515 #ifdef CONFIG_SMP
27516 - GET_THREAD_INFO(%eax)
27517 - movl TI_cpu(%eax), %eax
27518 - movl __per_cpu_offset(,%eax,4), %eax
27519 - mov xen_vcpu(%eax), %eax
27520 + push %fs
27521 + mov $(__KERNEL_PERCPU), %eax
27522 + mov %eax, %fs
27523 + mov PER_CPU_VAR(xen_vcpu), %eax
27524 + pop %fs
27525 #else
27526 movl xen_vcpu, %eax
27527 #endif
27528 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27529 index aaa7291..3f77960 100644
27530 --- a/arch/x86/xen/xen-head.S
27531 +++ b/arch/x86/xen/xen-head.S
27532 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
27533 #ifdef CONFIG_X86_32
27534 mov %esi,xen_start_info
27535 mov $init_thread_union+THREAD_SIZE,%esp
27536 +#ifdef CONFIG_SMP
27537 + movl $cpu_gdt_table,%edi
27538 + movl $__per_cpu_load,%eax
27539 + movw %ax,__KERNEL_PERCPU + 2(%edi)
27540 + rorl $16,%eax
27541 + movb %al,__KERNEL_PERCPU + 4(%edi)
27542 + movb %ah,__KERNEL_PERCPU + 7(%edi)
27543 + movl $__per_cpu_end - 1,%eax
27544 + subl $__per_cpu_start,%eax
27545 + movw %ax,__KERNEL_PERCPU + 0(%edi)
27546 +#endif
27547 #else
27548 mov %rsi,xen_start_info
27549 mov $init_thread_union+THREAD_SIZE,%rsp
27550 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27551 index 202d4c1..99b072a 100644
27552 --- a/arch/x86/xen/xen-ops.h
27553 +++ b/arch/x86/xen/xen-ops.h
27554 @@ -10,8 +10,6 @@
27555 extern const char xen_hypervisor_callback[];
27556 extern const char xen_failsafe_callback[];
27557
27558 -extern void *xen_initial_gdt;
27559 -
27560 struct trap_info;
27561 void xen_copy_trap_info(struct trap_info *traps);
27562
27563 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
27564 index 525bd3d..ef888b1 100644
27565 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
27566 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
27567 @@ -119,9 +119,9 @@
27568 ----------------------------------------------------------------------*/
27569
27570 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
27571 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
27572 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
27573 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
27574 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27575
27576 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
27577 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
27578 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
27579 index 2f33760..835e50a 100644
27580 --- a/arch/xtensa/variants/fsf/include/variant/core.h
27581 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
27582 @@ -11,6 +11,7 @@
27583 #ifndef _XTENSA_CORE_H
27584 #define _XTENSA_CORE_H
27585
27586 +#include <linux/const.h>
27587
27588 /****************************************************************************
27589 Parameters Useful for Any Code, USER or PRIVILEGED
27590 @@ -112,9 +113,9 @@
27591 ----------------------------------------------------------------------*/
27592
27593 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27594 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27595 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27596 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27597 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27598
27599 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
27600 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
27601 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
27602 index af00795..2bb8105 100644
27603 --- a/arch/xtensa/variants/s6000/include/variant/core.h
27604 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
27605 @@ -11,6 +11,7 @@
27606 #ifndef _XTENSA_CORE_CONFIGURATION_H
27607 #define _XTENSA_CORE_CONFIGURATION_H
27608
27609 +#include <linux/const.h>
27610
27611 /****************************************************************************
27612 Parameters Useful for Any Code, USER or PRIVILEGED
27613 @@ -118,9 +119,9 @@
27614 ----------------------------------------------------------------------*/
27615
27616 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27617 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27618 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27619 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27620 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27621
27622 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
27623 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
27624 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27625 index 58916af..9cb880b 100644
27626 --- a/block/blk-iopoll.c
27627 +++ b/block/blk-iopoll.c
27628 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27629 }
27630 EXPORT_SYMBOL(blk_iopoll_complete);
27631
27632 -static void blk_iopoll_softirq(struct softirq_action *h)
27633 +static void blk_iopoll_softirq(void)
27634 {
27635 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27636 int rearm = 0, budget = blk_iopoll_budget;
27637 diff --git a/block/blk-map.c b/block/blk-map.c
27638 index 623e1cd..ca1e109 100644
27639 --- a/block/blk-map.c
27640 +++ b/block/blk-map.c
27641 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27642 if (!len || !kbuf)
27643 return -EINVAL;
27644
27645 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
27646 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
27647 if (do_copy)
27648 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27649 else
27650 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27651 index 467c8de..4bddc6d 100644
27652 --- a/block/blk-softirq.c
27653 +++ b/block/blk-softirq.c
27654 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27655 * Softirq action handler - move entries to local list and loop over them
27656 * while passing them to the queue registered handler.
27657 */
27658 -static void blk_done_softirq(struct softirq_action *h)
27659 +static void blk_done_softirq(void)
27660 {
27661 struct list_head *cpu_list, local_list;
27662
27663 diff --git a/block/bsg.c b/block/bsg.c
27664 index ff64ae3..593560c 100644
27665 --- a/block/bsg.c
27666 +++ b/block/bsg.c
27667 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
27668 struct sg_io_v4 *hdr, struct bsg_device *bd,
27669 fmode_t has_write_perm)
27670 {
27671 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27672 + unsigned char *cmdptr;
27673 +
27674 if (hdr->request_len > BLK_MAX_CDB) {
27675 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27676 if (!rq->cmd)
27677 return -ENOMEM;
27678 - }
27679 + cmdptr = rq->cmd;
27680 + } else
27681 + cmdptr = tmpcmd;
27682
27683 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
27684 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27685 hdr->request_len))
27686 return -EFAULT;
27687
27688 + if (cmdptr != rq->cmd)
27689 + memcpy(rq->cmd, cmdptr, hdr->request_len);
27690 +
27691 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27692 if (blk_verify_command(rq->cmd, has_write_perm))
27693 return -EPERM;
27694 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27695 index 7c668c8..db3521c 100644
27696 --- a/block/compat_ioctl.c
27697 +++ b/block/compat_ioctl.c
27698 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27699 err |= __get_user(f->spec1, &uf->spec1);
27700 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27701 err |= __get_user(name, &uf->name);
27702 - f->name = compat_ptr(name);
27703 + f->name = (void __force_kernel *)compat_ptr(name);
27704 if (err) {
27705 err = -EFAULT;
27706 goto out;
27707 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
27708 index 6296b40..417c00f 100644
27709 --- a/block/partitions/efi.c
27710 +++ b/block/partitions/efi.c
27711 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
27712 if (!gpt)
27713 return NULL;
27714
27715 + if (!le32_to_cpu(gpt->num_partition_entries))
27716 + return NULL;
27717 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
27718 + if (!pte)
27719 + return NULL;
27720 +
27721 count = le32_to_cpu(gpt->num_partition_entries) *
27722 le32_to_cpu(gpt->sizeof_partition_entry);
27723 - if (!count)
27724 - return NULL;
27725 - pte = kzalloc(count, GFP_KERNEL);
27726 - if (!pte)
27727 - return NULL;
27728 -
27729 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
27730 (u8 *) pte,
27731 count) < count) {
27732 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27733 index 9a87daa..fb17486 100644
27734 --- a/block/scsi_ioctl.c
27735 +++ b/block/scsi_ioctl.c
27736 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
27737 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27738 struct sg_io_hdr *hdr, fmode_t mode)
27739 {
27740 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27741 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27742 + unsigned char *cmdptr;
27743 +
27744 + if (rq->cmd != rq->__cmd)
27745 + cmdptr = rq->cmd;
27746 + else
27747 + cmdptr = tmpcmd;
27748 +
27749 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27750 return -EFAULT;
27751 +
27752 + if (cmdptr != rq->cmd)
27753 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27754 +
27755 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27756 return -EPERM;
27757
27758 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27759 int err;
27760 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27761 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27762 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27763 + unsigned char *cmdptr;
27764
27765 if (!sic)
27766 return -EINVAL;
27767 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27768 */
27769 err = -EFAULT;
27770 rq->cmd_len = cmdlen;
27771 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
27772 +
27773 + if (rq->cmd != rq->__cmd)
27774 + cmdptr = rq->cmd;
27775 + else
27776 + cmdptr = tmpcmd;
27777 +
27778 + if (copy_from_user(cmdptr, sic->data, cmdlen))
27779 goto error;
27780
27781 + if (rq->cmd != cmdptr)
27782 + memcpy(rq->cmd, cmdptr, cmdlen);
27783 +
27784 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
27785 goto error;
27786
27787 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
27788 index 671d4d6..5f24030 100644
27789 --- a/crypto/cryptd.c
27790 +++ b/crypto/cryptd.c
27791 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
27792
27793 struct cryptd_blkcipher_request_ctx {
27794 crypto_completion_t complete;
27795 -};
27796 +} __no_const;
27797
27798 struct cryptd_hash_ctx {
27799 struct crypto_shash *child;
27800 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
27801
27802 struct cryptd_aead_request_ctx {
27803 crypto_completion_t complete;
27804 -};
27805 +} __no_const;
27806
27807 static void cryptd_queue_worker(struct work_struct *work);
27808
27809 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
27810 index e6defd8..c26a225 100644
27811 --- a/drivers/acpi/apei/cper.c
27812 +++ b/drivers/acpi/apei/cper.c
27813 @@ -38,12 +38,12 @@
27814 */
27815 u64 cper_next_record_id(void)
27816 {
27817 - static atomic64_t seq;
27818 + static atomic64_unchecked_t seq;
27819
27820 - if (!atomic64_read(&seq))
27821 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
27822 + if (!atomic64_read_unchecked(&seq))
27823 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
27824
27825 - return atomic64_inc_return(&seq);
27826 + return atomic64_inc_return_unchecked(&seq);
27827 }
27828 EXPORT_SYMBOL_GPL(cper_next_record_id);
27829
27830 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
27831 index 7586544..636a2f0 100644
27832 --- a/drivers/acpi/ec_sys.c
27833 +++ b/drivers/acpi/ec_sys.c
27834 @@ -12,6 +12,7 @@
27835 #include <linux/acpi.h>
27836 #include <linux/debugfs.h>
27837 #include <linux/module.h>
27838 +#include <linux/uaccess.h>
27839 #include "internal.h"
27840
27841 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
27842 @@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27843 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
27844 */
27845 unsigned int size = EC_SPACE_SIZE;
27846 - u8 *data = (u8 *) buf;
27847 + u8 data;
27848 loff_t init_off = *off;
27849 int err = 0;
27850
27851 @@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27852 size = count;
27853
27854 while (size) {
27855 - err = ec_read(*off, &data[*off - init_off]);
27856 + err = ec_read(*off, &data);
27857 if (err)
27858 return err;
27859 + if (put_user(data, &buf[*off - init_off]))
27860 + return -EFAULT;
27861 *off += 1;
27862 size--;
27863 }
27864 @@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27865
27866 unsigned int size = count;
27867 loff_t init_off = *off;
27868 - u8 *data = (u8 *) buf;
27869 int err = 0;
27870
27871 if (*off >= EC_SPACE_SIZE)
27872 @@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27873 }
27874
27875 while (size) {
27876 - u8 byte_write = data[*off - init_off];
27877 + u8 byte_write;
27878 + if (get_user(byte_write, &buf[*off - init_off]))
27879 + return -EFAULT;
27880 err = ec_write(*off, byte_write);
27881 if (err)
27882 return err;
27883 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
27884 index 251c7b62..000462d 100644
27885 --- a/drivers/acpi/proc.c
27886 +++ b/drivers/acpi/proc.c
27887 @@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
27888 size_t count, loff_t * ppos)
27889 {
27890 struct list_head *node, *next;
27891 - char strbuf[5];
27892 - char str[5] = "";
27893 - unsigned int len = count;
27894 + char strbuf[5] = {0};
27895
27896 - if (len > 4)
27897 - len = 4;
27898 - if (len < 0)
27899 + if (count > 4)
27900 + count = 4;
27901 + if (copy_from_user(strbuf, buffer, count))
27902 return -EFAULT;
27903 -
27904 - if (copy_from_user(strbuf, buffer, len))
27905 - return -EFAULT;
27906 - strbuf[len] = '\0';
27907 - sscanf(strbuf, "%s", str);
27908 + strbuf[count] = '\0';
27909
27910 mutex_lock(&acpi_device_lock);
27911 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
27912 @@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
27913 if (!dev->wakeup.flags.valid)
27914 continue;
27915
27916 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
27917 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
27918 if (device_can_wakeup(&dev->dev)) {
27919 bool enable = !device_may_wakeup(&dev->dev);
27920 device_set_wakeup_enable(&dev->dev, enable);
27921 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
27922 index bfc31cb..8213ce1 100644
27923 --- a/drivers/acpi/processor_driver.c
27924 +++ b/drivers/acpi/processor_driver.c
27925 @@ -551,7 +551,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
27926 return 0;
27927 #endif
27928
27929 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
27930 + BUG_ON(pr->id >= nr_cpu_ids);
27931
27932 /*
27933 * Buggy BIOS check
27934 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
27935 index 8e1039c..ea9cbd4 100644
27936 --- a/drivers/ata/libata-core.c
27937 +++ b/drivers/ata/libata-core.c
27938 @@ -4750,7 +4750,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
27939 struct ata_port *ap;
27940 unsigned int tag;
27941
27942 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27943 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27944 ap = qc->ap;
27945
27946 qc->flags = 0;
27947 @@ -4766,7 +4766,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
27948 struct ata_port *ap;
27949 struct ata_link *link;
27950
27951 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27952 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27953 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
27954 ap = qc->ap;
27955 link = qc->dev->link;
27956 @@ -5828,6 +5828,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27957 return;
27958
27959 spin_lock(&lock);
27960 + pax_open_kernel();
27961
27962 for (cur = ops->inherits; cur; cur = cur->inherits) {
27963 void **inherit = (void **)cur;
27964 @@ -5841,8 +5842,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27965 if (IS_ERR(*pp))
27966 *pp = NULL;
27967
27968 - ops->inherits = NULL;
27969 + *(struct ata_port_operations **)&ops->inherits = NULL;
27970
27971 + pax_close_kernel();
27972 spin_unlock(&lock);
27973 }
27974
27975 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
27976 index bfaa5cb..3ba1cc3 100644
27977 --- a/drivers/ata/pata_arasan_cf.c
27978 +++ b/drivers/ata/pata_arasan_cf.c
27979 @@ -854,7 +854,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
27980 /* Handle platform specific quirks */
27981 if (pdata->quirk) {
27982 if (pdata->quirk & CF_BROKEN_PIO) {
27983 - ap->ops->set_piomode = NULL;
27984 + pax_open_kernel();
27985 + *(void **)&ap->ops->set_piomode = NULL;
27986 + pax_close_kernel();
27987 ap->pio_mask = 0;
27988 }
27989 if (pdata->quirk & CF_BROKEN_MWDMA)
27990 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
27991 index f9b983a..887b9d8 100644
27992 --- a/drivers/atm/adummy.c
27993 +++ b/drivers/atm/adummy.c
27994 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
27995 vcc->pop(vcc, skb);
27996 else
27997 dev_kfree_skb_any(skb);
27998 - atomic_inc(&vcc->stats->tx);
27999 + atomic_inc_unchecked(&vcc->stats->tx);
28000
28001 return 0;
28002 }
28003 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
28004 index 89b30f3..7964211 100644
28005 --- a/drivers/atm/ambassador.c
28006 +++ b/drivers/atm/ambassador.c
28007 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
28008 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
28009
28010 // VC layer stats
28011 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28012 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28013
28014 // free the descriptor
28015 kfree (tx_descr);
28016 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
28017 dump_skb ("<<<", vc, skb);
28018
28019 // VC layer stats
28020 - atomic_inc(&atm_vcc->stats->rx);
28021 + atomic_inc_unchecked(&atm_vcc->stats->rx);
28022 __net_timestamp(skb);
28023 // end of our responsibility
28024 atm_vcc->push (atm_vcc, skb);
28025 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
28026 } else {
28027 PRINTK (KERN_INFO, "dropped over-size frame");
28028 // should we count this?
28029 - atomic_inc(&atm_vcc->stats->rx_drop);
28030 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28031 }
28032
28033 } else {
28034 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
28035 }
28036
28037 if (check_area (skb->data, skb->len)) {
28038 - atomic_inc(&atm_vcc->stats->tx_err);
28039 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
28040 return -ENOMEM; // ?
28041 }
28042
28043 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
28044 index b22d71c..d6e1049 100644
28045 --- a/drivers/atm/atmtcp.c
28046 +++ b/drivers/atm/atmtcp.c
28047 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28048 if (vcc->pop) vcc->pop(vcc,skb);
28049 else dev_kfree_skb(skb);
28050 if (dev_data) return 0;
28051 - atomic_inc(&vcc->stats->tx_err);
28052 + atomic_inc_unchecked(&vcc->stats->tx_err);
28053 return -ENOLINK;
28054 }
28055 size = skb->len+sizeof(struct atmtcp_hdr);
28056 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28057 if (!new_skb) {
28058 if (vcc->pop) vcc->pop(vcc,skb);
28059 else dev_kfree_skb(skb);
28060 - atomic_inc(&vcc->stats->tx_err);
28061 + atomic_inc_unchecked(&vcc->stats->tx_err);
28062 return -ENOBUFS;
28063 }
28064 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
28065 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28066 if (vcc->pop) vcc->pop(vcc,skb);
28067 else dev_kfree_skb(skb);
28068 out_vcc->push(out_vcc,new_skb);
28069 - atomic_inc(&vcc->stats->tx);
28070 - atomic_inc(&out_vcc->stats->rx);
28071 + atomic_inc_unchecked(&vcc->stats->tx);
28072 + atomic_inc_unchecked(&out_vcc->stats->rx);
28073 return 0;
28074 }
28075
28076 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
28077 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
28078 read_unlock(&vcc_sklist_lock);
28079 if (!out_vcc) {
28080 - atomic_inc(&vcc->stats->tx_err);
28081 + atomic_inc_unchecked(&vcc->stats->tx_err);
28082 goto done;
28083 }
28084 skb_pull(skb,sizeof(struct atmtcp_hdr));
28085 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
28086 __net_timestamp(new_skb);
28087 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
28088 out_vcc->push(out_vcc,new_skb);
28089 - atomic_inc(&vcc->stats->tx);
28090 - atomic_inc(&out_vcc->stats->rx);
28091 + atomic_inc_unchecked(&vcc->stats->tx);
28092 + atomic_inc_unchecked(&out_vcc->stats->rx);
28093 done:
28094 if (vcc->pop) vcc->pop(vcc,skb);
28095 else dev_kfree_skb(skb);
28096 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
28097 index 2059ee4..faf51c7 100644
28098 --- a/drivers/atm/eni.c
28099 +++ b/drivers/atm/eni.c
28100 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
28101 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
28102 vcc->dev->number);
28103 length = 0;
28104 - atomic_inc(&vcc->stats->rx_err);
28105 + atomic_inc_unchecked(&vcc->stats->rx_err);
28106 }
28107 else {
28108 length = ATM_CELL_SIZE-1; /* no HEC */
28109 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
28110 size);
28111 }
28112 eff = length = 0;
28113 - atomic_inc(&vcc->stats->rx_err);
28114 + atomic_inc_unchecked(&vcc->stats->rx_err);
28115 }
28116 else {
28117 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
28118 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
28119 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
28120 vcc->dev->number,vcc->vci,length,size << 2,descr);
28121 length = eff = 0;
28122 - atomic_inc(&vcc->stats->rx_err);
28123 + atomic_inc_unchecked(&vcc->stats->rx_err);
28124 }
28125 }
28126 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
28127 @@ -767,7 +767,7 @@ rx_dequeued++;
28128 vcc->push(vcc,skb);
28129 pushed++;
28130 }
28131 - atomic_inc(&vcc->stats->rx);
28132 + atomic_inc_unchecked(&vcc->stats->rx);
28133 }
28134 wake_up(&eni_dev->rx_wait);
28135 }
28136 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
28137 PCI_DMA_TODEVICE);
28138 if (vcc->pop) vcc->pop(vcc,skb);
28139 else dev_kfree_skb_irq(skb);
28140 - atomic_inc(&vcc->stats->tx);
28141 + atomic_inc_unchecked(&vcc->stats->tx);
28142 wake_up(&eni_dev->tx_wait);
28143 dma_complete++;
28144 }
28145 @@ -1567,7 +1567,7 @@ tx_complete++;
28146 /*--------------------------------- entries ---------------------------------*/
28147
28148
28149 -static const char *media_name[] __devinitdata = {
28150 +static const char *media_name[] __devinitconst = {
28151 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
28152 "UTP", "05?", "06?", "07?", /* 4- 7 */
28153 "TAXI","09?", "10?", "11?", /* 8-11 */
28154 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
28155 index 86fed1b..6dc4721 100644
28156 --- a/drivers/atm/firestream.c
28157 +++ b/drivers/atm/firestream.c
28158 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
28159 }
28160 }
28161
28162 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28163 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28164
28165 fs_dprintk (FS_DEBUG_TXMEM, "i");
28166 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
28167 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28168 #endif
28169 skb_put (skb, qe->p1 & 0xffff);
28170 ATM_SKB(skb)->vcc = atm_vcc;
28171 - atomic_inc(&atm_vcc->stats->rx);
28172 + atomic_inc_unchecked(&atm_vcc->stats->rx);
28173 __net_timestamp(skb);
28174 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
28175 atm_vcc->push (atm_vcc, skb);
28176 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28177 kfree (pe);
28178 }
28179 if (atm_vcc)
28180 - atomic_inc(&atm_vcc->stats->rx_drop);
28181 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28182 break;
28183 case 0x1f: /* Reassembly abort: no buffers. */
28184 /* Silently increment error counter. */
28185 if (atm_vcc)
28186 - atomic_inc(&atm_vcc->stats->rx_drop);
28187 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28188 break;
28189 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
28190 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
28191 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
28192 index 361f5ae..7fc552d 100644
28193 --- a/drivers/atm/fore200e.c
28194 +++ b/drivers/atm/fore200e.c
28195 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
28196 #endif
28197 /* check error condition */
28198 if (*entry->status & STATUS_ERROR)
28199 - atomic_inc(&vcc->stats->tx_err);
28200 + atomic_inc_unchecked(&vcc->stats->tx_err);
28201 else
28202 - atomic_inc(&vcc->stats->tx);
28203 + atomic_inc_unchecked(&vcc->stats->tx);
28204 }
28205 }
28206
28207 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28208 if (skb == NULL) {
28209 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
28210
28211 - atomic_inc(&vcc->stats->rx_drop);
28212 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28213 return -ENOMEM;
28214 }
28215
28216 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28217
28218 dev_kfree_skb_any(skb);
28219
28220 - atomic_inc(&vcc->stats->rx_drop);
28221 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28222 return -ENOMEM;
28223 }
28224
28225 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28226
28227 vcc->push(vcc, skb);
28228 - atomic_inc(&vcc->stats->rx);
28229 + atomic_inc_unchecked(&vcc->stats->rx);
28230
28231 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28232
28233 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
28234 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
28235 fore200e->atm_dev->number,
28236 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
28237 - atomic_inc(&vcc->stats->rx_err);
28238 + atomic_inc_unchecked(&vcc->stats->rx_err);
28239 }
28240 }
28241
28242 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
28243 goto retry_here;
28244 }
28245
28246 - atomic_inc(&vcc->stats->tx_err);
28247 + atomic_inc_unchecked(&vcc->stats->tx_err);
28248
28249 fore200e->tx_sat++;
28250 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
28251 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
28252 index b182c2f..1c6fa8a 100644
28253 --- a/drivers/atm/he.c
28254 +++ b/drivers/atm/he.c
28255 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28256
28257 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
28258 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
28259 - atomic_inc(&vcc->stats->rx_drop);
28260 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28261 goto return_host_buffers;
28262 }
28263
28264 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28265 RBRQ_LEN_ERR(he_dev->rbrq_head)
28266 ? "LEN_ERR" : "",
28267 vcc->vpi, vcc->vci);
28268 - atomic_inc(&vcc->stats->rx_err);
28269 + atomic_inc_unchecked(&vcc->stats->rx_err);
28270 goto return_host_buffers;
28271 }
28272
28273 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28274 vcc->push(vcc, skb);
28275 spin_lock(&he_dev->global_lock);
28276
28277 - atomic_inc(&vcc->stats->rx);
28278 + atomic_inc_unchecked(&vcc->stats->rx);
28279
28280 return_host_buffers:
28281 ++pdus_assembled;
28282 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
28283 tpd->vcc->pop(tpd->vcc, tpd->skb);
28284 else
28285 dev_kfree_skb_any(tpd->skb);
28286 - atomic_inc(&tpd->vcc->stats->tx_err);
28287 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
28288 }
28289 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
28290 return;
28291 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28292 vcc->pop(vcc, skb);
28293 else
28294 dev_kfree_skb_any(skb);
28295 - atomic_inc(&vcc->stats->tx_err);
28296 + atomic_inc_unchecked(&vcc->stats->tx_err);
28297 return -EINVAL;
28298 }
28299
28300 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28301 vcc->pop(vcc, skb);
28302 else
28303 dev_kfree_skb_any(skb);
28304 - atomic_inc(&vcc->stats->tx_err);
28305 + atomic_inc_unchecked(&vcc->stats->tx_err);
28306 return -EINVAL;
28307 }
28308 #endif
28309 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28310 vcc->pop(vcc, skb);
28311 else
28312 dev_kfree_skb_any(skb);
28313 - atomic_inc(&vcc->stats->tx_err);
28314 + atomic_inc_unchecked(&vcc->stats->tx_err);
28315 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28316 return -ENOMEM;
28317 }
28318 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28319 vcc->pop(vcc, skb);
28320 else
28321 dev_kfree_skb_any(skb);
28322 - atomic_inc(&vcc->stats->tx_err);
28323 + atomic_inc_unchecked(&vcc->stats->tx_err);
28324 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28325 return -ENOMEM;
28326 }
28327 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28328 __enqueue_tpd(he_dev, tpd, cid);
28329 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28330
28331 - atomic_inc(&vcc->stats->tx);
28332 + atomic_inc_unchecked(&vcc->stats->tx);
28333
28334 return 0;
28335 }
28336 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
28337 index 7d01c2a..4e3ac01 100644
28338 --- a/drivers/atm/horizon.c
28339 +++ b/drivers/atm/horizon.c
28340 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
28341 {
28342 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
28343 // VC layer stats
28344 - atomic_inc(&vcc->stats->rx);
28345 + atomic_inc_unchecked(&vcc->stats->rx);
28346 __net_timestamp(skb);
28347 // end of our responsibility
28348 vcc->push (vcc, skb);
28349 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
28350 dev->tx_iovec = NULL;
28351
28352 // VC layer stats
28353 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28354 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28355
28356 // free the skb
28357 hrz_kfree_skb (skb);
28358 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
28359 index 8974bd2..b856f85 100644
28360 --- a/drivers/atm/idt77252.c
28361 +++ b/drivers/atm/idt77252.c
28362 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
28363 else
28364 dev_kfree_skb(skb);
28365
28366 - atomic_inc(&vcc->stats->tx);
28367 + atomic_inc_unchecked(&vcc->stats->tx);
28368 }
28369
28370 atomic_dec(&scq->used);
28371 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28372 if ((sb = dev_alloc_skb(64)) == NULL) {
28373 printk("%s: Can't allocate buffers for aal0.\n",
28374 card->name);
28375 - atomic_add(i, &vcc->stats->rx_drop);
28376 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28377 break;
28378 }
28379 if (!atm_charge(vcc, sb->truesize)) {
28380 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
28381 card->name);
28382 - atomic_add(i - 1, &vcc->stats->rx_drop);
28383 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
28384 dev_kfree_skb(sb);
28385 break;
28386 }
28387 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28388 ATM_SKB(sb)->vcc = vcc;
28389 __net_timestamp(sb);
28390 vcc->push(vcc, sb);
28391 - atomic_inc(&vcc->stats->rx);
28392 + atomic_inc_unchecked(&vcc->stats->rx);
28393
28394 cell += ATM_CELL_PAYLOAD;
28395 }
28396 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28397 "(CDC: %08x)\n",
28398 card->name, len, rpp->len, readl(SAR_REG_CDC));
28399 recycle_rx_pool_skb(card, rpp);
28400 - atomic_inc(&vcc->stats->rx_err);
28401 + atomic_inc_unchecked(&vcc->stats->rx_err);
28402 return;
28403 }
28404 if (stat & SAR_RSQE_CRC) {
28405 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
28406 recycle_rx_pool_skb(card, rpp);
28407 - atomic_inc(&vcc->stats->rx_err);
28408 + atomic_inc_unchecked(&vcc->stats->rx_err);
28409 return;
28410 }
28411 if (skb_queue_len(&rpp->queue) > 1) {
28412 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28413 RXPRINTK("%s: Can't alloc RX skb.\n",
28414 card->name);
28415 recycle_rx_pool_skb(card, rpp);
28416 - atomic_inc(&vcc->stats->rx_err);
28417 + atomic_inc_unchecked(&vcc->stats->rx_err);
28418 return;
28419 }
28420 if (!atm_charge(vcc, skb->truesize)) {
28421 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28422 __net_timestamp(skb);
28423
28424 vcc->push(vcc, skb);
28425 - atomic_inc(&vcc->stats->rx);
28426 + atomic_inc_unchecked(&vcc->stats->rx);
28427
28428 return;
28429 }
28430 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28431 __net_timestamp(skb);
28432
28433 vcc->push(vcc, skb);
28434 - atomic_inc(&vcc->stats->rx);
28435 + atomic_inc_unchecked(&vcc->stats->rx);
28436
28437 if (skb->truesize > SAR_FB_SIZE_3)
28438 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
28439 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
28440 if (vcc->qos.aal != ATM_AAL0) {
28441 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
28442 card->name, vpi, vci);
28443 - atomic_inc(&vcc->stats->rx_drop);
28444 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28445 goto drop;
28446 }
28447
28448 if ((sb = dev_alloc_skb(64)) == NULL) {
28449 printk("%s: Can't allocate buffers for AAL0.\n",
28450 card->name);
28451 - atomic_inc(&vcc->stats->rx_err);
28452 + atomic_inc_unchecked(&vcc->stats->rx_err);
28453 goto drop;
28454 }
28455
28456 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
28457 ATM_SKB(sb)->vcc = vcc;
28458 __net_timestamp(sb);
28459 vcc->push(vcc, sb);
28460 - atomic_inc(&vcc->stats->rx);
28461 + atomic_inc_unchecked(&vcc->stats->rx);
28462
28463 drop:
28464 skb_pull(queue, 64);
28465 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28466
28467 if (vc == NULL) {
28468 printk("%s: NULL connection in send().\n", card->name);
28469 - atomic_inc(&vcc->stats->tx_err);
28470 + atomic_inc_unchecked(&vcc->stats->tx_err);
28471 dev_kfree_skb(skb);
28472 return -EINVAL;
28473 }
28474 if (!test_bit(VCF_TX, &vc->flags)) {
28475 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
28476 - atomic_inc(&vcc->stats->tx_err);
28477 + atomic_inc_unchecked(&vcc->stats->tx_err);
28478 dev_kfree_skb(skb);
28479 return -EINVAL;
28480 }
28481 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28482 break;
28483 default:
28484 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
28485 - atomic_inc(&vcc->stats->tx_err);
28486 + atomic_inc_unchecked(&vcc->stats->tx_err);
28487 dev_kfree_skb(skb);
28488 return -EINVAL;
28489 }
28490
28491 if (skb_shinfo(skb)->nr_frags != 0) {
28492 printk("%s: No scatter-gather yet.\n", card->name);
28493 - atomic_inc(&vcc->stats->tx_err);
28494 + atomic_inc_unchecked(&vcc->stats->tx_err);
28495 dev_kfree_skb(skb);
28496 return -EINVAL;
28497 }
28498 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28499
28500 err = queue_skb(card, vc, skb, oam);
28501 if (err) {
28502 - atomic_inc(&vcc->stats->tx_err);
28503 + atomic_inc_unchecked(&vcc->stats->tx_err);
28504 dev_kfree_skb(skb);
28505 return err;
28506 }
28507 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
28508 skb = dev_alloc_skb(64);
28509 if (!skb) {
28510 printk("%s: Out of memory in send_oam().\n", card->name);
28511 - atomic_inc(&vcc->stats->tx_err);
28512 + atomic_inc_unchecked(&vcc->stats->tx_err);
28513 return -ENOMEM;
28514 }
28515 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
28516 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
28517 index 96cce6d..62c3ec5 100644
28518 --- a/drivers/atm/iphase.c
28519 +++ b/drivers/atm/iphase.c
28520 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
28521 status = (u_short) (buf_desc_ptr->desc_mode);
28522 if (status & (RX_CER | RX_PTE | RX_OFL))
28523 {
28524 - atomic_inc(&vcc->stats->rx_err);
28525 + atomic_inc_unchecked(&vcc->stats->rx_err);
28526 IF_ERR(printk("IA: bad packet, dropping it");)
28527 if (status & RX_CER) {
28528 IF_ERR(printk(" cause: packet CRC error\n");)
28529 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
28530 len = dma_addr - buf_addr;
28531 if (len > iadev->rx_buf_sz) {
28532 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
28533 - atomic_inc(&vcc->stats->rx_err);
28534 + atomic_inc_unchecked(&vcc->stats->rx_err);
28535 goto out_free_desc;
28536 }
28537
28538 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28539 ia_vcc = INPH_IA_VCC(vcc);
28540 if (ia_vcc == NULL)
28541 {
28542 - atomic_inc(&vcc->stats->rx_err);
28543 + atomic_inc_unchecked(&vcc->stats->rx_err);
28544 atm_return(vcc, skb->truesize);
28545 dev_kfree_skb_any(skb);
28546 goto INCR_DLE;
28547 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28548 if ((length > iadev->rx_buf_sz) || (length >
28549 (skb->len - sizeof(struct cpcs_trailer))))
28550 {
28551 - atomic_inc(&vcc->stats->rx_err);
28552 + atomic_inc_unchecked(&vcc->stats->rx_err);
28553 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
28554 length, skb->len);)
28555 atm_return(vcc, skb->truesize);
28556 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28557
28558 IF_RX(printk("rx_dle_intr: skb push");)
28559 vcc->push(vcc,skb);
28560 - atomic_inc(&vcc->stats->rx);
28561 + atomic_inc_unchecked(&vcc->stats->rx);
28562 iadev->rx_pkt_cnt++;
28563 }
28564 INCR_DLE:
28565 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
28566 {
28567 struct k_sonet_stats *stats;
28568 stats = &PRIV(_ia_dev[board])->sonet_stats;
28569 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
28570 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
28571 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
28572 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
28573 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
28574 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
28575 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
28576 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
28577 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
28578 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
28579 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
28580 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
28581 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
28582 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
28583 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
28584 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
28585 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
28586 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
28587 }
28588 ia_cmds.status = 0;
28589 break;
28590 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28591 if ((desc == 0) || (desc > iadev->num_tx_desc))
28592 {
28593 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
28594 - atomic_inc(&vcc->stats->tx);
28595 + atomic_inc_unchecked(&vcc->stats->tx);
28596 if (vcc->pop)
28597 vcc->pop(vcc, skb);
28598 else
28599 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28600 ATM_DESC(skb) = vcc->vci;
28601 skb_queue_tail(&iadev->tx_dma_q, skb);
28602
28603 - atomic_inc(&vcc->stats->tx);
28604 + atomic_inc_unchecked(&vcc->stats->tx);
28605 iadev->tx_pkt_cnt++;
28606 /* Increment transaction counter */
28607 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
28608
28609 #if 0
28610 /* add flow control logic */
28611 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
28612 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
28613 if (iavcc->vc_desc_cnt > 10) {
28614 vcc->tx_quota = vcc->tx_quota * 3 / 4;
28615 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
28616 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
28617 index 68c7588..7036683 100644
28618 --- a/drivers/atm/lanai.c
28619 +++ b/drivers/atm/lanai.c
28620 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
28621 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
28622 lanai_endtx(lanai, lvcc);
28623 lanai_free_skb(lvcc->tx.atmvcc, skb);
28624 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28625 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28626 }
28627
28628 /* Try to fill the buffer - don't call unless there is backlog */
28629 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28630 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28631 __net_timestamp(skb);
28632 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28633 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28634 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28635 out:
28636 lvcc->rx.buf.ptr = end;
28637 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28638 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28639 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28640 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28641 lanai->stats.service_rxnotaal5++;
28642 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28643 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28644 return 0;
28645 }
28646 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28647 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28648 int bytes;
28649 read_unlock(&vcc_sklist_lock);
28650 DPRINTK("got trashed rx pdu on vci %d\n", vci);
28651 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28652 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28653 lvcc->stats.x.aal5.service_trash++;
28654 bytes = (SERVICE_GET_END(s) * 16) -
28655 (((unsigned long) lvcc->rx.buf.ptr) -
28656 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28657 }
28658 if (s & SERVICE_STREAM) {
28659 read_unlock(&vcc_sklist_lock);
28660 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28661 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28662 lvcc->stats.x.aal5.service_stream++;
28663 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
28664 "PDU on VCI %d!\n", lanai->number, vci);
28665 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28666 return 0;
28667 }
28668 DPRINTK("got rx crc error on vci %d\n", vci);
28669 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28670 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28671 lvcc->stats.x.aal5.service_rxcrc++;
28672 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
28673 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
28674 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
28675 index 1c70c45..300718d 100644
28676 --- a/drivers/atm/nicstar.c
28677 +++ b/drivers/atm/nicstar.c
28678 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28679 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
28680 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
28681 card->index);
28682 - atomic_inc(&vcc->stats->tx_err);
28683 + atomic_inc_unchecked(&vcc->stats->tx_err);
28684 dev_kfree_skb_any(skb);
28685 return -EINVAL;
28686 }
28687 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28688 if (!vc->tx) {
28689 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
28690 card->index);
28691 - atomic_inc(&vcc->stats->tx_err);
28692 + atomic_inc_unchecked(&vcc->stats->tx_err);
28693 dev_kfree_skb_any(skb);
28694 return -EINVAL;
28695 }
28696 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28697 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
28698 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
28699 card->index);
28700 - atomic_inc(&vcc->stats->tx_err);
28701 + atomic_inc_unchecked(&vcc->stats->tx_err);
28702 dev_kfree_skb_any(skb);
28703 return -EINVAL;
28704 }
28705
28706 if (skb_shinfo(skb)->nr_frags != 0) {
28707 printk("nicstar%d: No scatter-gather yet.\n", card->index);
28708 - atomic_inc(&vcc->stats->tx_err);
28709 + atomic_inc_unchecked(&vcc->stats->tx_err);
28710 dev_kfree_skb_any(skb);
28711 return -EINVAL;
28712 }
28713 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28714 }
28715
28716 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
28717 - atomic_inc(&vcc->stats->tx_err);
28718 + atomic_inc_unchecked(&vcc->stats->tx_err);
28719 dev_kfree_skb_any(skb);
28720 return -EIO;
28721 }
28722 - atomic_inc(&vcc->stats->tx);
28723 + atomic_inc_unchecked(&vcc->stats->tx);
28724
28725 return 0;
28726 }
28727 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28728 printk
28729 ("nicstar%d: Can't allocate buffers for aal0.\n",
28730 card->index);
28731 - atomic_add(i, &vcc->stats->rx_drop);
28732 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28733 break;
28734 }
28735 if (!atm_charge(vcc, sb->truesize)) {
28736 RXPRINTK
28737 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
28738 card->index);
28739 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28740 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28741 dev_kfree_skb_any(sb);
28742 break;
28743 }
28744 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28745 ATM_SKB(sb)->vcc = vcc;
28746 __net_timestamp(sb);
28747 vcc->push(vcc, sb);
28748 - atomic_inc(&vcc->stats->rx);
28749 + atomic_inc_unchecked(&vcc->stats->rx);
28750 cell += ATM_CELL_PAYLOAD;
28751 }
28752
28753 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28754 if (iovb == NULL) {
28755 printk("nicstar%d: Out of iovec buffers.\n",
28756 card->index);
28757 - atomic_inc(&vcc->stats->rx_drop);
28758 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28759 recycle_rx_buf(card, skb);
28760 return;
28761 }
28762 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28763 small or large buffer itself. */
28764 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
28765 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
28766 - atomic_inc(&vcc->stats->rx_err);
28767 + atomic_inc_unchecked(&vcc->stats->rx_err);
28768 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28769 NS_MAX_IOVECS);
28770 NS_PRV_IOVCNT(iovb) = 0;
28771 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28772 ("nicstar%d: Expected a small buffer, and this is not one.\n",
28773 card->index);
28774 which_list(card, skb);
28775 - atomic_inc(&vcc->stats->rx_err);
28776 + atomic_inc_unchecked(&vcc->stats->rx_err);
28777 recycle_rx_buf(card, skb);
28778 vc->rx_iov = NULL;
28779 recycle_iov_buf(card, iovb);
28780 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28781 ("nicstar%d: Expected a large buffer, and this is not one.\n",
28782 card->index);
28783 which_list(card, skb);
28784 - atomic_inc(&vcc->stats->rx_err);
28785 + atomic_inc_unchecked(&vcc->stats->rx_err);
28786 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28787 NS_PRV_IOVCNT(iovb));
28788 vc->rx_iov = NULL;
28789 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28790 printk(" - PDU size mismatch.\n");
28791 else
28792 printk(".\n");
28793 - atomic_inc(&vcc->stats->rx_err);
28794 + atomic_inc_unchecked(&vcc->stats->rx_err);
28795 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28796 NS_PRV_IOVCNT(iovb));
28797 vc->rx_iov = NULL;
28798 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28799 /* skb points to a small buffer */
28800 if (!atm_charge(vcc, skb->truesize)) {
28801 push_rxbufs(card, skb);
28802 - atomic_inc(&vcc->stats->rx_drop);
28803 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28804 } else {
28805 skb_put(skb, len);
28806 dequeue_sm_buf(card, skb);
28807 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28808 ATM_SKB(skb)->vcc = vcc;
28809 __net_timestamp(skb);
28810 vcc->push(vcc, skb);
28811 - atomic_inc(&vcc->stats->rx);
28812 + atomic_inc_unchecked(&vcc->stats->rx);
28813 }
28814 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
28815 struct sk_buff *sb;
28816 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28817 if (len <= NS_SMBUFSIZE) {
28818 if (!atm_charge(vcc, sb->truesize)) {
28819 push_rxbufs(card, sb);
28820 - atomic_inc(&vcc->stats->rx_drop);
28821 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28822 } else {
28823 skb_put(sb, len);
28824 dequeue_sm_buf(card, sb);
28825 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28826 ATM_SKB(sb)->vcc = vcc;
28827 __net_timestamp(sb);
28828 vcc->push(vcc, sb);
28829 - atomic_inc(&vcc->stats->rx);
28830 + atomic_inc_unchecked(&vcc->stats->rx);
28831 }
28832
28833 push_rxbufs(card, skb);
28834 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28835
28836 if (!atm_charge(vcc, skb->truesize)) {
28837 push_rxbufs(card, skb);
28838 - atomic_inc(&vcc->stats->rx_drop);
28839 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28840 } else {
28841 dequeue_lg_buf(card, skb);
28842 #ifdef NS_USE_DESTRUCTORS
28843 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28844 ATM_SKB(skb)->vcc = vcc;
28845 __net_timestamp(skb);
28846 vcc->push(vcc, skb);
28847 - atomic_inc(&vcc->stats->rx);
28848 + atomic_inc_unchecked(&vcc->stats->rx);
28849 }
28850
28851 push_rxbufs(card, sb);
28852 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28853 printk
28854 ("nicstar%d: Out of huge buffers.\n",
28855 card->index);
28856 - atomic_inc(&vcc->stats->rx_drop);
28857 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28858 recycle_iovec_rx_bufs(card,
28859 (struct iovec *)
28860 iovb->data,
28861 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28862 card->hbpool.count++;
28863 } else
28864 dev_kfree_skb_any(hb);
28865 - atomic_inc(&vcc->stats->rx_drop);
28866 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28867 } else {
28868 /* Copy the small buffer to the huge buffer */
28869 sb = (struct sk_buff *)iov->iov_base;
28870 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28871 #endif /* NS_USE_DESTRUCTORS */
28872 __net_timestamp(hb);
28873 vcc->push(vcc, hb);
28874 - atomic_inc(&vcc->stats->rx);
28875 + atomic_inc_unchecked(&vcc->stats->rx);
28876 }
28877 }
28878
28879 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
28880 index 9851093..adb2b1e 100644
28881 --- a/drivers/atm/solos-pci.c
28882 +++ b/drivers/atm/solos-pci.c
28883 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
28884 }
28885 atm_charge(vcc, skb->truesize);
28886 vcc->push(vcc, skb);
28887 - atomic_inc(&vcc->stats->rx);
28888 + atomic_inc_unchecked(&vcc->stats->rx);
28889 break;
28890
28891 case PKT_STATUS:
28892 @@ -1009,7 +1009,7 @@ static uint32_t fpga_tx(struct solos_card *card)
28893 vcc = SKB_CB(oldskb)->vcc;
28894
28895 if (vcc) {
28896 - atomic_inc(&vcc->stats->tx);
28897 + atomic_inc_unchecked(&vcc->stats->tx);
28898 solos_pop(vcc, oldskb);
28899 } else
28900 dev_kfree_skb_irq(oldskb);
28901 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
28902 index 0215934..ce9f5b1 100644
28903 --- a/drivers/atm/suni.c
28904 +++ b/drivers/atm/suni.c
28905 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
28906
28907
28908 #define ADD_LIMITED(s,v) \
28909 - atomic_add((v),&stats->s); \
28910 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
28911 + atomic_add_unchecked((v),&stats->s); \
28912 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
28913
28914
28915 static void suni_hz(unsigned long from_timer)
28916 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
28917 index 5120a96..e2572bd 100644
28918 --- a/drivers/atm/uPD98402.c
28919 +++ b/drivers/atm/uPD98402.c
28920 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
28921 struct sonet_stats tmp;
28922 int error = 0;
28923
28924 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28925 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28926 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
28927 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
28928 if (zero && !error) {
28929 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
28930
28931
28932 #define ADD_LIMITED(s,v) \
28933 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
28934 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
28935 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28936 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
28937 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
28938 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28939
28940
28941 static void stat_event(struct atm_dev *dev)
28942 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
28943 if (reason & uPD98402_INT_PFM) stat_event(dev);
28944 if (reason & uPD98402_INT_PCO) {
28945 (void) GET(PCOCR); /* clear interrupt cause */
28946 - atomic_add(GET(HECCT),
28947 + atomic_add_unchecked(GET(HECCT),
28948 &PRIV(dev)->sonet_stats.uncorr_hcs);
28949 }
28950 if ((reason & uPD98402_INT_RFO) &&
28951 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
28952 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
28953 uPD98402_INT_LOS),PIMR); /* enable them */
28954 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
28955 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28956 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
28957 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
28958 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28959 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
28960 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
28961 return 0;
28962 }
28963
28964 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
28965 index abe4e20..83c4727 100644
28966 --- a/drivers/atm/zatm.c
28967 +++ b/drivers/atm/zatm.c
28968 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28969 }
28970 if (!size) {
28971 dev_kfree_skb_irq(skb);
28972 - if (vcc) atomic_inc(&vcc->stats->rx_err);
28973 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
28974 continue;
28975 }
28976 if (!atm_charge(vcc,skb->truesize)) {
28977 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28978 skb->len = size;
28979 ATM_SKB(skb)->vcc = vcc;
28980 vcc->push(vcc,skb);
28981 - atomic_inc(&vcc->stats->rx);
28982 + atomic_inc_unchecked(&vcc->stats->rx);
28983 }
28984 zout(pos & 0xffff,MTA(mbx));
28985 #if 0 /* probably a stupid idea */
28986 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
28987 skb_queue_head(&zatm_vcc->backlog,skb);
28988 break;
28989 }
28990 - atomic_inc(&vcc->stats->tx);
28991 + atomic_inc_unchecked(&vcc->stats->tx);
28992 wake_up(&zatm_vcc->tx_wait);
28993 }
28994
28995 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
28996 index deb4a45..211eff2 100644
28997 --- a/drivers/base/devtmpfs.c
28998 +++ b/drivers/base/devtmpfs.c
28999 @@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
29000 if (!thread)
29001 return 0;
29002
29003 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
29004 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
29005 if (err)
29006 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
29007 else
29008 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
29009 index cbb463b..babe2cf 100644
29010 --- a/drivers/base/power/wakeup.c
29011 +++ b/drivers/base/power/wakeup.c
29012 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
29013 * They need to be modified together atomically, so it's better to use one
29014 * atomic variable to hold them both.
29015 */
29016 -static atomic_t combined_event_count = ATOMIC_INIT(0);
29017 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
29018
29019 #define IN_PROGRESS_BITS (sizeof(int) * 4)
29020 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
29021
29022 static void split_counters(unsigned int *cnt, unsigned int *inpr)
29023 {
29024 - unsigned int comb = atomic_read(&combined_event_count);
29025 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
29026
29027 *cnt = (comb >> IN_PROGRESS_BITS);
29028 *inpr = comb & MAX_IN_PROGRESS;
29029 @@ -385,7 +385,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
29030 ws->start_prevent_time = ws->last_time;
29031
29032 /* Increment the counter of events in progress. */
29033 - cec = atomic_inc_return(&combined_event_count);
29034 + cec = atomic_inc_return_unchecked(&combined_event_count);
29035
29036 trace_wakeup_source_activate(ws->name, cec);
29037 }
29038 @@ -511,7 +511,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
29039 * Increment the counter of registered wakeup events and decrement the
29040 * couter of wakeup events in progress simultaneously.
29041 */
29042 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
29043 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
29044 trace_wakeup_source_deactivate(ws->name, cec);
29045
29046 split_counters(&cnt, &inpr);
29047 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
29048 index b0f553b..77b928b 100644
29049 --- a/drivers/block/cciss.c
29050 +++ b/drivers/block/cciss.c
29051 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
29052 int err;
29053 u32 cp;
29054
29055 + memset(&arg64, 0, sizeof(arg64));
29056 +
29057 err = 0;
29058 err |=
29059 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
29060 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
29061 while (!list_empty(&h->reqQ)) {
29062 c = list_entry(h->reqQ.next, CommandList_struct, list);
29063 /* can't do anything if fifo is full */
29064 - if ((h->access.fifo_full(h))) {
29065 + if ((h->access->fifo_full(h))) {
29066 dev_warn(&h->pdev->dev, "fifo full\n");
29067 break;
29068 }
29069 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
29070 h->Qdepth--;
29071
29072 /* Tell the controller execute command */
29073 - h->access.submit_command(h, c);
29074 + h->access->submit_command(h, c);
29075
29076 /* Put job onto the completed Q */
29077 addQ(&h->cmpQ, c);
29078 @@ -3443,17 +3445,17 @@ startio:
29079
29080 static inline unsigned long get_next_completion(ctlr_info_t *h)
29081 {
29082 - return h->access.command_completed(h);
29083 + return h->access->command_completed(h);
29084 }
29085
29086 static inline int interrupt_pending(ctlr_info_t *h)
29087 {
29088 - return h->access.intr_pending(h);
29089 + return h->access->intr_pending(h);
29090 }
29091
29092 static inline long interrupt_not_for_us(ctlr_info_t *h)
29093 {
29094 - return ((h->access.intr_pending(h) == 0) ||
29095 + return ((h->access->intr_pending(h) == 0) ||
29096 (h->interrupts_enabled == 0));
29097 }
29098
29099 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
29100 u32 a;
29101
29102 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
29103 - return h->access.command_completed(h);
29104 + return h->access->command_completed(h);
29105
29106 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
29107 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
29108 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
29109 trans_support & CFGTBL_Trans_use_short_tags);
29110
29111 /* Change the access methods to the performant access methods */
29112 - h->access = SA5_performant_access;
29113 + h->access = &SA5_performant_access;
29114 h->transMethod = CFGTBL_Trans_Performant;
29115
29116 return;
29117 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
29118 if (prod_index < 0)
29119 return -ENODEV;
29120 h->product_name = products[prod_index].product_name;
29121 - h->access = *(products[prod_index].access);
29122 + h->access = products[prod_index].access;
29123
29124 if (cciss_board_disabled(h)) {
29125 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
29126 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
29127 }
29128
29129 /* make sure the board interrupts are off */
29130 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29131 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29132 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
29133 if (rc)
29134 goto clean2;
29135 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
29136 * fake ones to scoop up any residual completions.
29137 */
29138 spin_lock_irqsave(&h->lock, flags);
29139 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29140 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29141 spin_unlock_irqrestore(&h->lock, flags);
29142 free_irq(h->intr[h->intr_mode], h);
29143 rc = cciss_request_irq(h, cciss_msix_discard_completions,
29144 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
29145 dev_info(&h->pdev->dev, "Board READY.\n");
29146 dev_info(&h->pdev->dev,
29147 "Waiting for stale completions to drain.\n");
29148 - h->access.set_intr_mask(h, CCISS_INTR_ON);
29149 + h->access->set_intr_mask(h, CCISS_INTR_ON);
29150 msleep(10000);
29151 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29152 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29153
29154 rc = controller_reset_failed(h->cfgtable);
29155 if (rc)
29156 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
29157 cciss_scsi_setup(h);
29158
29159 /* Turn the interrupts on so we can service requests */
29160 - h->access.set_intr_mask(h, CCISS_INTR_ON);
29161 + h->access->set_intr_mask(h, CCISS_INTR_ON);
29162
29163 /* Get the firmware version */
29164 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
29165 @@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
29166 kfree(flush_buf);
29167 if (return_code != IO_OK)
29168 dev_warn(&h->pdev->dev, "Error flushing cache\n");
29169 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29170 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29171 free_irq(h->intr[h->intr_mode], h);
29172 }
29173
29174 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
29175 index 7fda30e..eb5dfe0 100644
29176 --- a/drivers/block/cciss.h
29177 +++ b/drivers/block/cciss.h
29178 @@ -101,7 +101,7 @@ struct ctlr_info
29179 /* information about each logical volume */
29180 drive_info_struct *drv[CISS_MAX_LUN];
29181
29182 - struct access_method access;
29183 + struct access_method *access;
29184
29185 /* queue and queue Info */
29186 struct list_head reqQ;
29187 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
29188 index 9125bbe..eede5c8 100644
29189 --- a/drivers/block/cpqarray.c
29190 +++ b/drivers/block/cpqarray.c
29191 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29192 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
29193 goto Enomem4;
29194 }
29195 - hba[i]->access.set_intr_mask(hba[i], 0);
29196 + hba[i]->access->set_intr_mask(hba[i], 0);
29197 if (request_irq(hba[i]->intr, do_ida_intr,
29198 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
29199 {
29200 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29201 add_timer(&hba[i]->timer);
29202
29203 /* Enable IRQ now that spinlock and rate limit timer are set up */
29204 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29205 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29206
29207 for(j=0; j<NWD; j++) {
29208 struct gendisk *disk = ida_gendisk[i][j];
29209 @@ -694,7 +694,7 @@ DBGINFO(
29210 for(i=0; i<NR_PRODUCTS; i++) {
29211 if (board_id == products[i].board_id) {
29212 c->product_name = products[i].product_name;
29213 - c->access = *(products[i].access);
29214 + c->access = products[i].access;
29215 break;
29216 }
29217 }
29218 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
29219 hba[ctlr]->intr = intr;
29220 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
29221 hba[ctlr]->product_name = products[j].product_name;
29222 - hba[ctlr]->access = *(products[j].access);
29223 + hba[ctlr]->access = products[j].access;
29224 hba[ctlr]->ctlr = ctlr;
29225 hba[ctlr]->board_id = board_id;
29226 hba[ctlr]->pci_dev = NULL; /* not PCI */
29227 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
29228
29229 while((c = h->reqQ) != NULL) {
29230 /* Can't do anything if we're busy */
29231 - if (h->access.fifo_full(h) == 0)
29232 + if (h->access->fifo_full(h) == 0)
29233 return;
29234
29235 /* Get the first entry from the request Q */
29236 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
29237 h->Qdepth--;
29238
29239 /* Tell the controller to do our bidding */
29240 - h->access.submit_command(h, c);
29241 + h->access->submit_command(h, c);
29242
29243 /* Get onto the completion Q */
29244 addQ(&h->cmpQ, c);
29245 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29246 unsigned long flags;
29247 __u32 a,a1;
29248
29249 - istat = h->access.intr_pending(h);
29250 + istat = h->access->intr_pending(h);
29251 /* Is this interrupt for us? */
29252 if (istat == 0)
29253 return IRQ_NONE;
29254 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29255 */
29256 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
29257 if (istat & FIFO_NOT_EMPTY) {
29258 - while((a = h->access.command_completed(h))) {
29259 + while((a = h->access->command_completed(h))) {
29260 a1 = a; a &= ~3;
29261 if ((c = h->cmpQ) == NULL)
29262 {
29263 @@ -1449,11 +1449,11 @@ static int sendcmd(
29264 /*
29265 * Disable interrupt
29266 */
29267 - info_p->access.set_intr_mask(info_p, 0);
29268 + info_p->access->set_intr_mask(info_p, 0);
29269 /* Make sure there is room in the command FIFO */
29270 /* Actually it should be completely empty at this time. */
29271 for (i = 200000; i > 0; i--) {
29272 - temp = info_p->access.fifo_full(info_p);
29273 + temp = info_p->access->fifo_full(info_p);
29274 if (temp != 0) {
29275 break;
29276 }
29277 @@ -1466,7 +1466,7 @@ DBG(
29278 /*
29279 * Send the cmd
29280 */
29281 - info_p->access.submit_command(info_p, c);
29282 + info_p->access->submit_command(info_p, c);
29283 complete = pollcomplete(ctlr);
29284
29285 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
29286 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
29287 * we check the new geometry. Then turn interrupts back on when
29288 * we're done.
29289 */
29290 - host->access.set_intr_mask(host, 0);
29291 + host->access->set_intr_mask(host, 0);
29292 getgeometry(ctlr);
29293 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
29294 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
29295
29296 for(i=0; i<NWD; i++) {
29297 struct gendisk *disk = ida_gendisk[ctlr][i];
29298 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
29299 /* Wait (up to 2 seconds) for a command to complete */
29300
29301 for (i = 200000; i > 0; i--) {
29302 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
29303 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
29304 if (done == 0) {
29305 udelay(10); /* a short fixed delay */
29306 } else
29307 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
29308 index be73e9d..7fbf140 100644
29309 --- a/drivers/block/cpqarray.h
29310 +++ b/drivers/block/cpqarray.h
29311 @@ -99,7 +99,7 @@ struct ctlr_info {
29312 drv_info_t drv[NWD];
29313 struct proc_dir_entry *proc;
29314
29315 - struct access_method access;
29316 + struct access_method *access;
29317
29318 cmdlist_t *reqQ;
29319 cmdlist_t *cmpQ;
29320 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
29321 index b953cc7..e3dc580 100644
29322 --- a/drivers/block/drbd/drbd_int.h
29323 +++ b/drivers/block/drbd/drbd_int.h
29324 @@ -735,7 +735,7 @@ struct drbd_request;
29325 struct drbd_epoch {
29326 struct list_head list;
29327 unsigned int barrier_nr;
29328 - atomic_t epoch_size; /* increased on every request added. */
29329 + atomic_unchecked_t epoch_size; /* increased on every request added. */
29330 atomic_t active; /* increased on every req. added, and dec on every finished. */
29331 unsigned long flags;
29332 };
29333 @@ -1116,7 +1116,7 @@ struct drbd_conf {
29334 void *int_dig_in;
29335 void *int_dig_vv;
29336 wait_queue_head_t seq_wait;
29337 - atomic_t packet_seq;
29338 + atomic_unchecked_t packet_seq;
29339 unsigned int peer_seq;
29340 spinlock_t peer_seq_lock;
29341 unsigned int minor;
29342 @@ -1658,30 +1658,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
29343
29344 static inline void drbd_tcp_cork(struct socket *sock)
29345 {
29346 - int __user val = 1;
29347 + int val = 1;
29348 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29349 - (char __user *)&val, sizeof(val));
29350 + (char __force_user *)&val, sizeof(val));
29351 }
29352
29353 static inline void drbd_tcp_uncork(struct socket *sock)
29354 {
29355 - int __user val = 0;
29356 + int val = 0;
29357 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29358 - (char __user *)&val, sizeof(val));
29359 + (char __force_user *)&val, sizeof(val));
29360 }
29361
29362 static inline void drbd_tcp_nodelay(struct socket *sock)
29363 {
29364 - int __user val = 1;
29365 + int val = 1;
29366 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
29367 - (char __user *)&val, sizeof(val));
29368 + (char __force_user *)&val, sizeof(val));
29369 }
29370
29371 static inline void drbd_tcp_quickack(struct socket *sock)
29372 {
29373 - int __user val = 2;
29374 + int val = 2;
29375 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
29376 - (char __user *)&val, sizeof(val));
29377 + (char __force_user *)&val, sizeof(val));
29378 }
29379
29380 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
29381 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
29382 index f93a032..71c87bf 100644
29383 --- a/drivers/block/drbd/drbd_main.c
29384 +++ b/drivers/block/drbd/drbd_main.c
29385 @@ -2567,7 +2567,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
29386 p.sector = sector;
29387 p.block_id = block_id;
29388 p.blksize = blksize;
29389 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29390 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29391
29392 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
29393 return false;
29394 @@ -2865,7 +2865,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
29395
29396 p.sector = cpu_to_be64(req->sector);
29397 p.block_id = (unsigned long)req;
29398 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29399 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29400
29401 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
29402
29403 @@ -3150,7 +3150,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
29404 atomic_set(&mdev->unacked_cnt, 0);
29405 atomic_set(&mdev->local_cnt, 0);
29406 atomic_set(&mdev->net_cnt, 0);
29407 - atomic_set(&mdev->packet_seq, 0);
29408 + atomic_set_unchecked(&mdev->packet_seq, 0);
29409 atomic_set(&mdev->pp_in_use, 0);
29410 atomic_set(&mdev->pp_in_use_by_net, 0);
29411 atomic_set(&mdev->rs_sect_in, 0);
29412 @@ -3232,8 +3232,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
29413 mdev->receiver.t_state);
29414
29415 /* no need to lock it, I'm the only thread alive */
29416 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
29417 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
29418 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
29419 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
29420 mdev->al_writ_cnt =
29421 mdev->bm_writ_cnt =
29422 mdev->read_cnt =
29423 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
29424 index edb490a..ecd69da 100644
29425 --- a/drivers/block/drbd/drbd_nl.c
29426 +++ b/drivers/block/drbd/drbd_nl.c
29427 @@ -2407,7 +2407,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29428 module_put(THIS_MODULE);
29429 }
29430
29431 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29432 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29433
29434 static unsigned short *
29435 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
29436 @@ -2478,7 +2478,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
29437 cn_reply->id.idx = CN_IDX_DRBD;
29438 cn_reply->id.val = CN_VAL_DRBD;
29439
29440 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29441 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29442 cn_reply->ack = 0; /* not used here. */
29443 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29444 (int)((char *)tl - (char *)reply->tag_list);
29445 @@ -2510,7 +2510,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
29446 cn_reply->id.idx = CN_IDX_DRBD;
29447 cn_reply->id.val = CN_VAL_DRBD;
29448
29449 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29450 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29451 cn_reply->ack = 0; /* not used here. */
29452 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29453 (int)((char *)tl - (char *)reply->tag_list);
29454 @@ -2588,7 +2588,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
29455 cn_reply->id.idx = CN_IDX_DRBD;
29456 cn_reply->id.val = CN_VAL_DRBD;
29457
29458 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
29459 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
29460 cn_reply->ack = 0; // not used here.
29461 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29462 (int)((char*)tl - (char*)reply->tag_list);
29463 @@ -2627,7 +2627,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
29464 cn_reply->id.idx = CN_IDX_DRBD;
29465 cn_reply->id.val = CN_VAL_DRBD;
29466
29467 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29468 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29469 cn_reply->ack = 0; /* not used here. */
29470 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29471 (int)((char *)tl - (char *)reply->tag_list);
29472 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
29473 index c74ca2d..860c819 100644
29474 --- a/drivers/block/drbd/drbd_receiver.c
29475 +++ b/drivers/block/drbd/drbd_receiver.c
29476 @@ -898,7 +898,7 @@ retry:
29477 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
29478 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
29479
29480 - atomic_set(&mdev->packet_seq, 0);
29481 + atomic_set_unchecked(&mdev->packet_seq, 0);
29482 mdev->peer_seq = 0;
29483
29484 if (drbd_send_protocol(mdev) == -1)
29485 @@ -999,7 +999,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29486 do {
29487 next_epoch = NULL;
29488
29489 - epoch_size = atomic_read(&epoch->epoch_size);
29490 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
29491
29492 switch (ev & ~EV_CLEANUP) {
29493 case EV_PUT:
29494 @@ -1035,7 +1035,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29495 rv = FE_DESTROYED;
29496 } else {
29497 epoch->flags = 0;
29498 - atomic_set(&epoch->epoch_size, 0);
29499 + atomic_set_unchecked(&epoch->epoch_size, 0);
29500 /* atomic_set(&epoch->active, 0); is already zero */
29501 if (rv == FE_STILL_LIVE)
29502 rv = FE_RECYCLED;
29503 @@ -1210,14 +1210,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29504 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
29505 drbd_flush(mdev);
29506
29507 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29508 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29509 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
29510 if (epoch)
29511 break;
29512 }
29513
29514 epoch = mdev->current_epoch;
29515 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
29516 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
29517
29518 D_ASSERT(atomic_read(&epoch->active) == 0);
29519 D_ASSERT(epoch->flags == 0);
29520 @@ -1229,11 +1229,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29521 }
29522
29523 epoch->flags = 0;
29524 - atomic_set(&epoch->epoch_size, 0);
29525 + atomic_set_unchecked(&epoch->epoch_size, 0);
29526 atomic_set(&epoch->active, 0);
29527
29528 spin_lock(&mdev->epoch_lock);
29529 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29530 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29531 list_add(&epoch->list, &mdev->current_epoch->list);
29532 mdev->current_epoch = epoch;
29533 mdev->epochs++;
29534 @@ -1702,7 +1702,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29535 spin_unlock(&mdev->peer_seq_lock);
29536
29537 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
29538 - atomic_inc(&mdev->current_epoch->epoch_size);
29539 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
29540 return drbd_drain_block(mdev, data_size);
29541 }
29542
29543 @@ -1732,7 +1732,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29544
29545 spin_lock(&mdev->epoch_lock);
29546 e->epoch = mdev->current_epoch;
29547 - atomic_inc(&e->epoch->epoch_size);
29548 + atomic_inc_unchecked(&e->epoch->epoch_size);
29549 atomic_inc(&e->epoch->active);
29550 spin_unlock(&mdev->epoch_lock);
29551
29552 @@ -3954,7 +3954,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
29553 D_ASSERT(list_empty(&mdev->done_ee));
29554
29555 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
29556 - atomic_set(&mdev->current_epoch->epoch_size, 0);
29557 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
29558 D_ASSERT(list_empty(&mdev->current_epoch->list));
29559 }
29560
29561 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
29562 index 3bba655..6151b66 100644
29563 --- a/drivers/block/loop.c
29564 +++ b/drivers/block/loop.c
29565 @@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
29566 mm_segment_t old_fs = get_fs();
29567
29568 set_fs(get_ds());
29569 - bw = file->f_op->write(file, buf, len, &pos);
29570 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
29571 set_fs(old_fs);
29572 if (likely(bw == len))
29573 return 0;
29574 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
29575 index ea6f632..eafb192 100644
29576 --- a/drivers/char/Kconfig
29577 +++ b/drivers/char/Kconfig
29578 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
29579
29580 config DEVKMEM
29581 bool "/dev/kmem virtual device support"
29582 - default y
29583 + default n
29584 + depends on !GRKERNSEC_KMEM
29585 help
29586 Say Y here if you want to support the /dev/kmem device. The
29587 /dev/kmem device is rarely used, but can be used for certain
29588 @@ -581,6 +582,7 @@ config DEVPORT
29589 bool
29590 depends on !M68K
29591 depends on ISA || PCI
29592 + depends on !GRKERNSEC_KMEM
29593 default y
29594
29595 source "drivers/s390/char/Kconfig"
29596 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
29597 index 2e04433..22afc64 100644
29598 --- a/drivers/char/agp/frontend.c
29599 +++ b/drivers/char/agp/frontend.c
29600 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
29601 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
29602 return -EFAULT;
29603
29604 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
29605 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29606 return -EFAULT;
29607
29608 client = agp_find_client_by_pid(reserve.pid);
29609 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29610 index 21cb980..f15107c 100644
29611 --- a/drivers/char/genrtc.c
29612 +++ b/drivers/char/genrtc.c
29613 @@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
29614 switch (cmd) {
29615
29616 case RTC_PLL_GET:
29617 + memset(&pll, 0, sizeof(pll));
29618 if (get_rtc_pll(&pll))
29619 return -EINVAL;
29620 else
29621 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29622 index dfd7876..c0b0885 100644
29623 --- a/drivers/char/hpet.c
29624 +++ b/drivers/char/hpet.c
29625 @@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29626 }
29627
29628 static int
29629 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29630 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29631 struct hpet_info *info)
29632 {
29633 struct hpet_timer __iomem *timer;
29634 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29635 index 2c29942..604c5ba 100644
29636 --- a/drivers/char/ipmi/ipmi_msghandler.c
29637 +++ b/drivers/char/ipmi/ipmi_msghandler.c
29638 @@ -420,7 +420,7 @@ struct ipmi_smi {
29639 struct proc_dir_entry *proc_dir;
29640 char proc_dir_name[10];
29641
29642 - atomic_t stats[IPMI_NUM_STATS];
29643 + atomic_unchecked_t stats[IPMI_NUM_STATS];
29644
29645 /*
29646 * run_to_completion duplicate of smb_info, smi_info
29647 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29648
29649
29650 #define ipmi_inc_stat(intf, stat) \
29651 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29652 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29653 #define ipmi_get_stat(intf, stat) \
29654 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29655 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29656
29657 static int is_lan_addr(struct ipmi_addr *addr)
29658 {
29659 @@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29660 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29661 init_waitqueue_head(&intf->waitq);
29662 for (i = 0; i < IPMI_NUM_STATS; i++)
29663 - atomic_set(&intf->stats[i], 0);
29664 + atomic_set_unchecked(&intf->stats[i], 0);
29665
29666 intf->proc_dir = NULL;
29667
29668 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
29669 index 83f85cf..279e63f 100644
29670 --- a/drivers/char/ipmi/ipmi_si_intf.c
29671 +++ b/drivers/char/ipmi/ipmi_si_intf.c
29672 @@ -275,7 +275,7 @@ struct smi_info {
29673 unsigned char slave_addr;
29674
29675 /* Counters and things for the proc filesystem. */
29676 - atomic_t stats[SI_NUM_STATS];
29677 + atomic_unchecked_t stats[SI_NUM_STATS];
29678
29679 struct task_struct *thread;
29680
29681 @@ -284,9 +284,9 @@ struct smi_info {
29682 };
29683
29684 #define smi_inc_stat(smi, stat) \
29685 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
29686 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
29687 #define smi_get_stat(smi, stat) \
29688 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
29689 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
29690
29691 #define SI_MAX_PARMS 4
29692
29693 @@ -3193,7 +3193,7 @@ static int try_smi_init(struct smi_info *new_smi)
29694 atomic_set(&new_smi->req_events, 0);
29695 new_smi->run_to_completion = 0;
29696 for (i = 0; i < SI_NUM_STATS; i++)
29697 - atomic_set(&new_smi->stats[i], 0);
29698 + atomic_set_unchecked(&new_smi->stats[i], 0);
29699
29700 new_smi->interrupt_disabled = 1;
29701 atomic_set(&new_smi->stop_operation, 0);
29702 diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
29703 index 47ff7e4..0c7d340 100644
29704 --- a/drivers/char/mbcs.c
29705 +++ b/drivers/char/mbcs.c
29706 @@ -799,7 +799,7 @@ static int mbcs_remove(struct cx_dev *dev)
29707 return 0;
29708 }
29709
29710 -static const struct cx_device_id __devinitdata mbcs_id_table[] = {
29711 +static const struct cx_device_id __devinitconst mbcs_id_table[] = {
29712 {
29713 .part_num = MBCS_PART_NUM,
29714 .mfg_num = MBCS_MFG_NUM,
29715 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
29716 index e5eedfa..fcab50ea 100644
29717 --- a/drivers/char/mem.c
29718 +++ b/drivers/char/mem.c
29719 @@ -18,6 +18,7 @@
29720 #include <linux/raw.h>
29721 #include <linux/tty.h>
29722 #include <linux/capability.h>
29723 +#include <linux/security.h>
29724 #include <linux/ptrace.h>
29725 #include <linux/device.h>
29726 #include <linux/highmem.h>
29727 @@ -37,6 +38,10 @@
29728
29729 #define DEVPORT_MINOR 4
29730
29731 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29732 +extern const struct file_operations grsec_fops;
29733 +#endif
29734 +
29735 static inline unsigned long size_inside_page(unsigned long start,
29736 unsigned long size)
29737 {
29738 @@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29739
29740 while (cursor < to) {
29741 if (!devmem_is_allowed(pfn)) {
29742 +#ifdef CONFIG_GRKERNSEC_KMEM
29743 + gr_handle_mem_readwrite(from, to);
29744 +#else
29745 printk(KERN_INFO
29746 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
29747 current->comm, from, to);
29748 +#endif
29749 return 0;
29750 }
29751 cursor += PAGE_SIZE;
29752 @@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29753 }
29754 return 1;
29755 }
29756 +#elif defined(CONFIG_GRKERNSEC_KMEM)
29757 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29758 +{
29759 + return 0;
29760 +}
29761 #else
29762 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29763 {
29764 @@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29765
29766 while (count > 0) {
29767 unsigned long remaining;
29768 + char *temp;
29769
29770 sz = size_inside_page(p, count);
29771
29772 @@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29773 if (!ptr)
29774 return -EFAULT;
29775
29776 - remaining = copy_to_user(buf, ptr, sz);
29777 +#ifdef CONFIG_PAX_USERCOPY
29778 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29779 + if (!temp) {
29780 + unxlate_dev_mem_ptr(p, ptr);
29781 + return -ENOMEM;
29782 + }
29783 + memcpy(temp, ptr, sz);
29784 +#else
29785 + temp = ptr;
29786 +#endif
29787 +
29788 + remaining = copy_to_user(buf, temp, sz);
29789 +
29790 +#ifdef CONFIG_PAX_USERCOPY
29791 + kfree(temp);
29792 +#endif
29793 +
29794 unxlate_dev_mem_ptr(p, ptr);
29795 if (remaining)
29796 return -EFAULT;
29797 @@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29798 size_t count, loff_t *ppos)
29799 {
29800 unsigned long p = *ppos;
29801 - ssize_t low_count, read, sz;
29802 + ssize_t low_count, read, sz, err = 0;
29803 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
29804 - int err = 0;
29805
29806 read = 0;
29807 if (p < (unsigned long) high_memory) {
29808 @@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29809 }
29810 #endif
29811 while (low_count > 0) {
29812 + char *temp;
29813 +
29814 sz = size_inside_page(p, low_count);
29815
29816 /*
29817 @@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29818 */
29819 kbuf = xlate_dev_kmem_ptr((char *)p);
29820
29821 - if (copy_to_user(buf, kbuf, sz))
29822 +#ifdef CONFIG_PAX_USERCOPY
29823 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29824 + if (!temp)
29825 + return -ENOMEM;
29826 + memcpy(temp, kbuf, sz);
29827 +#else
29828 + temp = kbuf;
29829 +#endif
29830 +
29831 + err = copy_to_user(buf, temp, sz);
29832 +
29833 +#ifdef CONFIG_PAX_USERCOPY
29834 + kfree(temp);
29835 +#endif
29836 +
29837 + if (err)
29838 return -EFAULT;
29839 buf += sz;
29840 p += sz;
29841 @@ -833,6 +880,9 @@ static const struct memdev {
29842 #ifdef CONFIG_CRASH_DUMP
29843 [12] = { "oldmem", 0, &oldmem_fops, NULL },
29844 #endif
29845 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29846 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
29847 +#endif
29848 };
29849
29850 static int memory_open(struct inode *inode, struct file *filp)
29851 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
29852 index 9df78e2..01ba9ae 100644
29853 --- a/drivers/char/nvram.c
29854 +++ b/drivers/char/nvram.c
29855 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
29856
29857 spin_unlock_irq(&rtc_lock);
29858
29859 - if (copy_to_user(buf, contents, tmp - contents))
29860 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
29861 return -EFAULT;
29862
29863 *ppos = i;
29864 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
29865 index 0a484b4..f48ccd1 100644
29866 --- a/drivers/char/pcmcia/synclink_cs.c
29867 +++ b/drivers/char/pcmcia/synclink_cs.c
29868 @@ -2340,9 +2340,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29869
29870 if (debug_level >= DEBUG_LEVEL_INFO)
29871 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
29872 - __FILE__,__LINE__, info->device_name, port->count);
29873 + __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
29874
29875 - WARN_ON(!port->count);
29876 + WARN_ON(!atomic_read(&port->count));
29877
29878 if (tty_port_close_start(port, tty, filp) == 0)
29879 goto cleanup;
29880 @@ -2360,7 +2360,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29881 cleanup:
29882 if (debug_level >= DEBUG_LEVEL_INFO)
29883 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
29884 - tty->driver->name, port->count);
29885 + tty->driver->name, atomic_read(&port->count));
29886 }
29887
29888 /* Wait until the transmitter is empty.
29889 @@ -2502,7 +2502,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29890
29891 if (debug_level >= DEBUG_LEVEL_INFO)
29892 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
29893 - __FILE__,__LINE__,tty->driver->name, port->count);
29894 + __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
29895
29896 /* If port is closing, signal caller to try again */
29897 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
29898 @@ -2522,11 +2522,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29899 goto cleanup;
29900 }
29901 spin_lock(&port->lock);
29902 - port->count++;
29903 + atomic_inc(&port->count);
29904 spin_unlock(&port->lock);
29905 spin_unlock_irqrestore(&info->netlock, flags);
29906
29907 - if (port->count == 1) {
29908 + if (atomic_read(&port->count) == 1) {
29909 /* 1st open on this device, init hardware */
29910 retval = startup(info, tty);
29911 if (retval < 0)
29912 @@ -3891,7 +3891,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
29913 unsigned short new_crctype;
29914
29915 /* return error if TTY interface open */
29916 - if (info->port.count)
29917 + if (atomic_read(&info->port.count))
29918 return -EBUSY;
29919
29920 switch (encoding)
29921 @@ -3994,7 +3994,7 @@ static int hdlcdev_open(struct net_device *dev)
29922
29923 /* arbitrate between network and tty opens */
29924 spin_lock_irqsave(&info->netlock, flags);
29925 - if (info->port.count != 0 || info->netcount != 0) {
29926 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
29927 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
29928 spin_unlock_irqrestore(&info->netlock, flags);
29929 return -EBUSY;
29930 @@ -4083,7 +4083,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
29931 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
29932
29933 /* return error if TTY interface open */
29934 - if (info->port.count)
29935 + if (atomic_read(&info->port.count))
29936 return -EBUSY;
29937
29938 if (cmd != SIOCWANDEV)
29939 diff --git a/drivers/char/random.c b/drivers/char/random.c
29940 index b86eae9..4192a7a 100644
29941 --- a/drivers/char/random.c
29942 +++ b/drivers/char/random.c
29943 @@ -272,8 +272,13 @@
29944 /*
29945 * Configuration information
29946 */
29947 +#ifdef CONFIG_GRKERNSEC_RANDNET
29948 +#define INPUT_POOL_WORDS 512
29949 +#define OUTPUT_POOL_WORDS 128
29950 +#else
29951 #define INPUT_POOL_WORDS 128
29952 #define OUTPUT_POOL_WORDS 32
29953 +#endif
29954 #define SEC_XFER_SIZE 512
29955 #define EXTRACT_SIZE 10
29956
29957 @@ -313,10 +318,17 @@ static struct poolinfo {
29958 int poolwords;
29959 int tap1, tap2, tap3, tap4, tap5;
29960 } poolinfo_table[] = {
29961 +#ifdef CONFIG_GRKERNSEC_RANDNET
29962 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
29963 + { 512, 411, 308, 208, 104, 1 },
29964 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
29965 + { 128, 103, 76, 51, 25, 1 },
29966 +#else
29967 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
29968 { 128, 103, 76, 51, 25, 1 },
29969 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
29970 { 32, 26, 20, 14, 7, 1 },
29971 +#endif
29972 #if 0
29973 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
29974 { 2048, 1638, 1231, 819, 411, 1 },
29975 @@ -527,8 +539,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
29976 input_rotate += i ? 7 : 14;
29977 }
29978
29979 - ACCESS_ONCE(r->input_rotate) = input_rotate;
29980 - ACCESS_ONCE(r->add_ptr) = i;
29981 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
29982 + ACCESS_ONCE_RW(r->add_ptr) = i;
29983 smp_wmb();
29984
29985 if (out)
29986 @@ -799,6 +811,17 @@ void add_disk_randomness(struct gendisk *disk)
29987 }
29988 #endif
29989
29990 +#ifdef CONFIG_PAX_LATENT_ENTROPY
29991 +u64 latent_entropy;
29992 +
29993 +__init void transfer_latent_entropy(void)
29994 +{
29995 + mix_pool_bytes(&input_pool, &latent_entropy, sizeof(latent_entropy), NULL);
29996 + mix_pool_bytes(&nonblocking_pool, &latent_entropy, sizeof(latent_entropy), NULL);
29997 +// printk(KERN_INFO "PAX: transferring latent entropy: %16llx\n", latent_entropy);
29998 +}
29999 +#endif
30000 +
30001 /*********************************************************************
30002 *
30003 * Entropy extraction routines
30004 @@ -1008,7 +1031,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
30005
30006 extract_buf(r, tmp);
30007 i = min_t(int, nbytes, EXTRACT_SIZE);
30008 - if (copy_to_user(buf, tmp, i)) {
30009 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
30010 ret = -EFAULT;
30011 break;
30012 }
30013 @@ -1342,7 +1365,7 @@ EXPORT_SYMBOL(generate_random_uuid);
30014 #include <linux/sysctl.h>
30015
30016 static int min_read_thresh = 8, min_write_thresh;
30017 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
30018 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
30019 static int max_write_thresh = INPUT_POOL_WORDS * 32;
30020 static char sysctl_bootid[16];
30021
30022 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
30023 index f877805..403375a 100644
30024 --- a/drivers/char/sonypi.c
30025 +++ b/drivers/char/sonypi.c
30026 @@ -54,6 +54,7 @@
30027
30028 #include <asm/uaccess.h>
30029 #include <asm/io.h>
30030 +#include <asm/local.h>
30031
30032 #include <linux/sonypi.h>
30033
30034 @@ -490,7 +491,7 @@ static struct sonypi_device {
30035 spinlock_t fifo_lock;
30036 wait_queue_head_t fifo_proc_list;
30037 struct fasync_struct *fifo_async;
30038 - int open_count;
30039 + local_t open_count;
30040 int model;
30041 struct input_dev *input_jog_dev;
30042 struct input_dev *input_key_dev;
30043 @@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
30044 static int sonypi_misc_release(struct inode *inode, struct file *file)
30045 {
30046 mutex_lock(&sonypi_device.lock);
30047 - sonypi_device.open_count--;
30048 + local_dec(&sonypi_device.open_count);
30049 mutex_unlock(&sonypi_device.lock);
30050 return 0;
30051 }
30052 @@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
30053 {
30054 mutex_lock(&sonypi_device.lock);
30055 /* Flush input queue on first open */
30056 - if (!sonypi_device.open_count)
30057 + if (!local_read(&sonypi_device.open_count))
30058 kfifo_reset(&sonypi_device.fifo);
30059 - sonypi_device.open_count++;
30060 + local_inc(&sonypi_device.open_count);
30061 mutex_unlock(&sonypi_device.lock);
30062
30063 return 0;
30064 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
30065 index 4dc8024..90108d1 100644
30066 --- a/drivers/char/tpm/tpm.c
30067 +++ b/drivers/char/tpm/tpm.c
30068 @@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
30069 chip->vendor.req_complete_val)
30070 goto out_recv;
30071
30072 - if ((status == chip->vendor.req_canceled)) {
30073 + if (status == chip->vendor.req_canceled) {
30074 dev_err(chip->dev, "Operation Canceled\n");
30075 rc = -ECANCELED;
30076 goto out;
30077 diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
30078 index 0636520..169c1d0 100644
30079 --- a/drivers/char/tpm/tpm_bios.c
30080 +++ b/drivers/char/tpm/tpm_bios.c
30081 @@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
30082 event = addr;
30083
30084 if ((event->event_type == 0 && event->event_size == 0) ||
30085 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
30086 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
30087 return NULL;
30088
30089 return addr;
30090 @@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
30091 return NULL;
30092
30093 if ((event->event_type == 0 && event->event_size == 0) ||
30094 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
30095 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
30096 return NULL;
30097
30098 (*pos)++;
30099 @@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
30100 int i;
30101
30102 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
30103 - seq_putc(m, data[i]);
30104 + if (!seq_putc(m, data[i]))
30105 + return -EFAULT;
30106
30107 return 0;
30108 }
30109 @@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
30110 log->bios_event_log_end = log->bios_event_log + len;
30111
30112 virt = acpi_os_map_memory(start, len);
30113 + if (!virt) {
30114 + kfree(log->bios_event_log);
30115 + log->bios_event_log = NULL;
30116 + return -EFAULT;
30117 + }
30118
30119 - memcpy(log->bios_event_log, virt, len);
30120 + memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
30121
30122 acpi_os_unmap_memory(virt, len);
30123 return 0;
30124 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
30125 index cdf2f54..e55c197 100644
30126 --- a/drivers/char/virtio_console.c
30127 +++ b/drivers/char/virtio_console.c
30128 @@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
30129 if (to_user) {
30130 ssize_t ret;
30131
30132 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
30133 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
30134 if (ret)
30135 return -EFAULT;
30136 } else {
30137 @@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
30138 if (!port_has_data(port) && !port->host_connected)
30139 return 0;
30140
30141 - return fill_readbuf(port, ubuf, count, true);
30142 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
30143 }
30144
30145 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
30146 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
30147 index e164c55..3aabb50 100644
30148 --- a/drivers/edac/edac_pci_sysfs.c
30149 +++ b/drivers/edac/edac_pci_sysfs.c
30150 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
30151 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
30152 static int edac_pci_poll_msec = 1000; /* one second workq period */
30153
30154 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
30155 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
30156 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
30157 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
30158
30159 static struct kobject *edac_pci_top_main_kobj;
30160 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
30161 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30162 edac_printk(KERN_CRIT, EDAC_PCI,
30163 "Signaled System Error on %s\n",
30164 pci_name(dev));
30165 - atomic_inc(&pci_nonparity_count);
30166 + atomic_inc_unchecked(&pci_nonparity_count);
30167 }
30168
30169 if (status & (PCI_STATUS_PARITY)) {
30170 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30171 "Master Data Parity Error on %s\n",
30172 pci_name(dev));
30173
30174 - atomic_inc(&pci_parity_count);
30175 + atomic_inc_unchecked(&pci_parity_count);
30176 }
30177
30178 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30179 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30180 "Detected Parity Error on %s\n",
30181 pci_name(dev));
30182
30183 - atomic_inc(&pci_parity_count);
30184 + atomic_inc_unchecked(&pci_parity_count);
30185 }
30186 }
30187
30188 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30189 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
30190 "Signaled System Error on %s\n",
30191 pci_name(dev));
30192 - atomic_inc(&pci_nonparity_count);
30193 + atomic_inc_unchecked(&pci_nonparity_count);
30194 }
30195
30196 if (status & (PCI_STATUS_PARITY)) {
30197 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30198 "Master Data Parity Error on "
30199 "%s\n", pci_name(dev));
30200
30201 - atomic_inc(&pci_parity_count);
30202 + atomic_inc_unchecked(&pci_parity_count);
30203 }
30204
30205 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30206 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30207 "Detected Parity Error on %s\n",
30208 pci_name(dev));
30209
30210 - atomic_inc(&pci_parity_count);
30211 + atomic_inc_unchecked(&pci_parity_count);
30212 }
30213 }
30214 }
30215 @@ -676,7 +676,7 @@ void edac_pci_do_parity_check(void)
30216 if (!check_pci_errors)
30217 return;
30218
30219 - before_count = atomic_read(&pci_parity_count);
30220 + before_count = atomic_read_unchecked(&pci_parity_count);
30221
30222 /* scan all PCI devices looking for a Parity Error on devices and
30223 * bridges.
30224 @@ -688,7 +688,7 @@ void edac_pci_do_parity_check(void)
30225 /* Only if operator has selected panic on PCI Error */
30226 if (edac_pci_get_panic_on_pe()) {
30227 /* If the count is different 'after' from 'before' */
30228 - if (before_count != atomic_read(&pci_parity_count))
30229 + if (before_count != atomic_read_unchecked(&pci_parity_count))
30230 panic("EDAC: PCI Parity Error");
30231 }
30232 }
30233 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
30234 index 8c87a5e..a19cbd7 100644
30235 --- a/drivers/edac/mce_amd.h
30236 +++ b/drivers/edac/mce_amd.h
30237 @@ -80,7 +80,7 @@ extern const char * const ii_msgs[];
30238 struct amd_decoder_ops {
30239 bool (*dc_mce)(u16, u8);
30240 bool (*ic_mce)(u16, u8);
30241 -};
30242 +} __no_const;
30243
30244 void amd_report_gart_errors(bool);
30245 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
30246 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
30247 index 57ea7f4..789e3c3 100644
30248 --- a/drivers/firewire/core-card.c
30249 +++ b/drivers/firewire/core-card.c
30250 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
30251
30252 void fw_core_remove_card(struct fw_card *card)
30253 {
30254 - struct fw_card_driver dummy_driver = dummy_driver_template;
30255 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
30256
30257 card->driver->update_phy_reg(card, 4,
30258 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
30259 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
30260 index f8d2287..5aaf4db 100644
30261 --- a/drivers/firewire/core-cdev.c
30262 +++ b/drivers/firewire/core-cdev.c
30263 @@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
30264 int ret;
30265
30266 if ((request->channels == 0 && request->bandwidth == 0) ||
30267 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
30268 - request->bandwidth < 0)
30269 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
30270 return -EINVAL;
30271
30272 r = kmalloc(sizeof(*r), GFP_KERNEL);
30273 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
30274 index 87d6f2d..5bf9d90 100644
30275 --- a/drivers/firewire/core-transaction.c
30276 +++ b/drivers/firewire/core-transaction.c
30277 @@ -37,6 +37,7 @@
30278 #include <linux/timer.h>
30279 #include <linux/types.h>
30280 #include <linux/workqueue.h>
30281 +#include <linux/sched.h>
30282
30283 #include <asm/byteorder.h>
30284
30285 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
30286 index 515a42c..5ecf3ba 100644
30287 --- a/drivers/firewire/core.h
30288 +++ b/drivers/firewire/core.h
30289 @@ -111,6 +111,7 @@ struct fw_card_driver {
30290
30291 int (*stop_iso)(struct fw_iso_context *ctx);
30292 };
30293 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
30294
30295 void fw_card_initialize(struct fw_card *card,
30296 const struct fw_card_driver *driver, struct device *device);
30297 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
30298 index b298158..7ed8432 100644
30299 --- a/drivers/firmware/dmi_scan.c
30300 +++ b/drivers/firmware/dmi_scan.c
30301 @@ -452,11 +452,6 @@ void __init dmi_scan_machine(void)
30302 }
30303 }
30304 else {
30305 - /*
30306 - * no iounmap() for that ioremap(); it would be a no-op, but
30307 - * it's so early in setup that sucker gets confused into doing
30308 - * what it shouldn't if we actually call it.
30309 - */
30310 p = dmi_ioremap(0xF0000, 0x10000);
30311 if (p == NULL)
30312 goto error;
30313 @@ -726,7 +721,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
30314 if (buf == NULL)
30315 return -1;
30316
30317 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
30318 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
30319
30320 iounmap(buf);
30321 return 0;
30322 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
30323 index 82d5c20..44a7177 100644
30324 --- a/drivers/gpio/gpio-vr41xx.c
30325 +++ b/drivers/gpio/gpio-vr41xx.c
30326 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
30327 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
30328 maskl, pendl, maskh, pendh);
30329
30330 - atomic_inc(&irq_err_count);
30331 + atomic_inc_unchecked(&irq_err_count);
30332
30333 return -EINVAL;
30334 }
30335 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
30336 index 3252e70..b5314ace 100644
30337 --- a/drivers/gpu/drm/drm_crtc_helper.c
30338 +++ b/drivers/gpu/drm/drm_crtc_helper.c
30339 @@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
30340 struct drm_crtc *tmp;
30341 int crtc_mask = 1;
30342
30343 - WARN(!crtc, "checking null crtc?\n");
30344 + BUG_ON(!crtc);
30345
30346 dev = crtc->dev;
30347
30348 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
30349 index 9238de4..a27c72a 100644
30350 --- a/drivers/gpu/drm/drm_drv.c
30351 +++ b/drivers/gpu/drm/drm_drv.c
30352 @@ -307,7 +307,7 @@ module_exit(drm_core_exit);
30353 /**
30354 * Copy and IOCTL return string to user space
30355 */
30356 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
30357 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
30358 {
30359 int len;
30360
30361 @@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
30362 return -ENODEV;
30363
30364 atomic_inc(&dev->ioctl_count);
30365 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
30366 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
30367 ++file_priv->ioctl_count;
30368
30369 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
30370 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
30371 index 5062eec..4e3e51f 100644
30372 --- a/drivers/gpu/drm/drm_fops.c
30373 +++ b/drivers/gpu/drm/drm_fops.c
30374 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
30375 }
30376
30377 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30378 - atomic_set(&dev->counts[i], 0);
30379 + atomic_set_unchecked(&dev->counts[i], 0);
30380
30381 dev->sigdata.lock = NULL;
30382
30383 @@ -134,8 +134,8 @@ int drm_open(struct inode *inode, struct file *filp)
30384
30385 retcode = drm_open_helper(inode, filp, dev);
30386 if (!retcode) {
30387 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30388 - if (!dev->open_count++)
30389 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30390 + if (local_inc_return(&dev->open_count) == 1)
30391 retcode = drm_setup(dev);
30392 }
30393 if (!retcode) {
30394 @@ -422,7 +422,7 @@ int drm_release(struct inode *inode, struct file *filp)
30395
30396 mutex_lock(&drm_global_mutex);
30397
30398 - DRM_DEBUG("open_count = %d\n", dev->open_count);
30399 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
30400
30401 if (dev->driver->preclose)
30402 dev->driver->preclose(dev, file_priv);
30403 @@ -431,10 +431,10 @@ int drm_release(struct inode *inode, struct file *filp)
30404 * Begin inline drm_release
30405 */
30406
30407 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30408 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
30409 task_pid_nr(current),
30410 (long)old_encode_dev(file_priv->minor->device),
30411 - dev->open_count);
30412 + local_read(&dev->open_count));
30413
30414 /* Release any auth tokens that might point to this file_priv,
30415 (do that under the drm_global_mutex) */
30416 @@ -530,8 +530,8 @@ int drm_release(struct inode *inode, struct file *filp)
30417 * End inline drm_release
30418 */
30419
30420 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30421 - if (!--dev->open_count) {
30422 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30423 + if (local_dec_and_test(&dev->open_count)) {
30424 if (atomic_read(&dev->ioctl_count)) {
30425 DRM_ERROR("Device busy: %d\n",
30426 atomic_read(&dev->ioctl_count));
30427 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30428 index c87dc96..326055d 100644
30429 --- a/drivers/gpu/drm/drm_global.c
30430 +++ b/drivers/gpu/drm/drm_global.c
30431 @@ -36,7 +36,7 @@
30432 struct drm_global_item {
30433 struct mutex mutex;
30434 void *object;
30435 - int refcount;
30436 + atomic_t refcount;
30437 };
30438
30439 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30440 @@ -49,7 +49,7 @@ void drm_global_init(void)
30441 struct drm_global_item *item = &glob[i];
30442 mutex_init(&item->mutex);
30443 item->object = NULL;
30444 - item->refcount = 0;
30445 + atomic_set(&item->refcount, 0);
30446 }
30447 }
30448
30449 @@ -59,7 +59,7 @@ void drm_global_release(void)
30450 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30451 struct drm_global_item *item = &glob[i];
30452 BUG_ON(item->object != NULL);
30453 - BUG_ON(item->refcount != 0);
30454 + BUG_ON(atomic_read(&item->refcount) != 0);
30455 }
30456 }
30457
30458 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30459 void *object;
30460
30461 mutex_lock(&item->mutex);
30462 - if (item->refcount == 0) {
30463 + if (atomic_read(&item->refcount) == 0) {
30464 item->object = kzalloc(ref->size, GFP_KERNEL);
30465 if (unlikely(item->object == NULL)) {
30466 ret = -ENOMEM;
30467 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30468 goto out_err;
30469
30470 }
30471 - ++item->refcount;
30472 + atomic_inc(&item->refcount);
30473 ref->object = item->object;
30474 object = item->object;
30475 mutex_unlock(&item->mutex);
30476 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30477 struct drm_global_item *item = &glob[ref->global_type];
30478
30479 mutex_lock(&item->mutex);
30480 - BUG_ON(item->refcount == 0);
30481 + BUG_ON(atomic_read(&item->refcount) == 0);
30482 BUG_ON(ref->object != item->object);
30483 - if (--item->refcount == 0) {
30484 + if (atomic_dec_and_test(&item->refcount)) {
30485 ref->release(ref);
30486 item->object = NULL;
30487 }
30488 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30489 index 8928edb..0c79258 100644
30490 --- a/drivers/gpu/drm/drm_info.c
30491 +++ b/drivers/gpu/drm/drm_info.c
30492 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30493 struct drm_local_map *map;
30494 struct drm_map_list *r_list;
30495
30496 - /* Hardcoded from _DRM_FRAME_BUFFER,
30497 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30498 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30499 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30500 + static const char * const types[] = {
30501 + [_DRM_FRAME_BUFFER] = "FB",
30502 + [_DRM_REGISTERS] = "REG",
30503 + [_DRM_SHM] = "SHM",
30504 + [_DRM_AGP] = "AGP",
30505 + [_DRM_SCATTER_GATHER] = "SG",
30506 + [_DRM_CONSISTENT] = "PCI",
30507 + [_DRM_GEM] = "GEM" };
30508 const char *type;
30509 int i;
30510
30511 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30512 map = r_list->map;
30513 if (!map)
30514 continue;
30515 - if (map->type < 0 || map->type > 5)
30516 + if (map->type >= ARRAY_SIZE(types))
30517 type = "??";
30518 else
30519 type = types[map->type];
30520 @@ -254,7 +258,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30521 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30522 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30523 vma->vm_flags & VM_IO ? 'i' : '-',
30524 +#ifdef CONFIG_GRKERNSEC_HIDESYM
30525 + 0);
30526 +#else
30527 vma->vm_pgoff);
30528 +#endif
30529
30530 #if defined(__i386__)
30531 pgprot = pgprot_val(vma->vm_page_prot);
30532 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30533 index 637fcc3..e890b33 100644
30534 --- a/drivers/gpu/drm/drm_ioc32.c
30535 +++ b/drivers/gpu/drm/drm_ioc32.c
30536 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30537 request = compat_alloc_user_space(nbytes);
30538 if (!access_ok(VERIFY_WRITE, request, nbytes))
30539 return -EFAULT;
30540 - list = (struct drm_buf_desc *) (request + 1);
30541 + list = (struct drm_buf_desc __user *) (request + 1);
30542
30543 if (__put_user(count, &request->count)
30544 || __put_user(list, &request->list))
30545 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30546 request = compat_alloc_user_space(nbytes);
30547 if (!access_ok(VERIFY_WRITE, request, nbytes))
30548 return -EFAULT;
30549 - list = (struct drm_buf_pub *) (request + 1);
30550 + list = (struct drm_buf_pub __user *) (request + 1);
30551
30552 if (__put_user(count, &request->count)
30553 || __put_user(list, &request->list))
30554 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30555 index 64a62c6..ceab35e 100644
30556 --- a/drivers/gpu/drm/drm_ioctl.c
30557 +++ b/drivers/gpu/drm/drm_ioctl.c
30558 @@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30559 stats->data[i].value =
30560 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30561 else
30562 - stats->data[i].value = atomic_read(&dev->counts[i]);
30563 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30564 stats->data[i].type = dev->types[i];
30565 }
30566
30567 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30568 index 3203955..c8090af 100644
30569 --- a/drivers/gpu/drm/drm_lock.c
30570 +++ b/drivers/gpu/drm/drm_lock.c
30571 @@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30572 if (drm_lock_take(&master->lock, lock->context)) {
30573 master->lock.file_priv = file_priv;
30574 master->lock.lock_time = jiffies;
30575 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30576 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30577 break; /* Got lock */
30578 }
30579
30580 @@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30581 return -EINVAL;
30582 }
30583
30584 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30585 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30586
30587 if (drm_lock_free(&master->lock, lock->context)) {
30588 /* FIXME: Should really bail out here. */
30589 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
30590 index 21bcd4a..8e074e0 100644
30591 --- a/drivers/gpu/drm/drm_stub.c
30592 +++ b/drivers/gpu/drm/drm_stub.c
30593 @@ -511,7 +511,7 @@ void drm_unplug_dev(struct drm_device *dev)
30594
30595 drm_device_set_unplugged(dev);
30596
30597 - if (dev->open_count == 0) {
30598 + if (local_read(&dev->open_count) == 0) {
30599 drm_put_dev(dev);
30600 }
30601 mutex_unlock(&drm_global_mutex);
30602 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30603 index 463ec68..f5bd2b5 100644
30604 --- a/drivers/gpu/drm/i810/i810_dma.c
30605 +++ b/drivers/gpu/drm/i810/i810_dma.c
30606 @@ -946,8 +946,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30607 dma->buflist[vertex->idx],
30608 vertex->discard, vertex->used);
30609
30610 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30611 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30612 + atomic_add_unchecked(vertex->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 @@ -1107,8 +1107,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30618 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30619 mc->last_render);
30620
30621 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30622 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30623 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30624 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30625 sarea_priv->last_enqueue = dev_priv->counter - 1;
30626 sarea_priv->last_dispatch = (int)hw_status[5];
30627
30628 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30629 index 6e0acad..93c8289 100644
30630 --- a/drivers/gpu/drm/i810/i810_drv.h
30631 +++ b/drivers/gpu/drm/i810/i810_drv.h
30632 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30633 int page_flipping;
30634
30635 wait_queue_head_t irq_queue;
30636 - atomic_t irq_received;
30637 - atomic_t irq_emitted;
30638 + atomic_unchecked_t irq_received;
30639 + atomic_unchecked_t irq_emitted;
30640
30641 int front_offset;
30642 } drm_i810_private_t;
30643 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30644 index 359f6e8..ada68fd 100644
30645 --- a/drivers/gpu/drm/i915/i915_debugfs.c
30646 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
30647 @@ -518,7 +518,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30648 I915_READ(GTIMR));
30649 }
30650 seq_printf(m, "Interrupts received: %d\n",
30651 - atomic_read(&dev_priv->irq_received));
30652 + atomic_read_unchecked(&dev_priv->irq_received));
30653 for (i = 0; i < I915_NUM_RINGS; i++) {
30654 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30655 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
30656 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30657 index 914c0df..d47d380 100644
30658 --- a/drivers/gpu/drm/i915/i915_dma.c
30659 +++ b/drivers/gpu/drm/i915/i915_dma.c
30660 @@ -1269,7 +1269,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
30661 bool can_switch;
30662
30663 spin_lock(&dev->count_lock);
30664 - can_switch = (dev->open_count == 0);
30665 + can_switch = (local_read(&dev->open_count) == 0);
30666 spin_unlock(&dev->count_lock);
30667 return can_switch;
30668 }
30669 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
30670 index 627fe35..c9a7346 100644
30671 --- a/drivers/gpu/drm/i915/i915_drv.h
30672 +++ b/drivers/gpu/drm/i915/i915_drv.h
30673 @@ -272,12 +272,12 @@ struct drm_i915_display_funcs {
30674 /* render clock increase/decrease */
30675 /* display clock increase/decrease */
30676 /* pll clock increase/decrease */
30677 -};
30678 +} __no_const;
30679
30680 struct drm_i915_gt_funcs {
30681 void (*force_wake_get)(struct drm_i915_private *dev_priv);
30682 void (*force_wake_put)(struct drm_i915_private *dev_priv);
30683 -};
30684 +} __no_const;
30685
30686 struct intel_device_info {
30687 u8 gen;
30688 @@ -408,7 +408,7 @@ typedef struct drm_i915_private {
30689 int current_page;
30690 int page_flipping;
30691
30692 - atomic_t irq_received;
30693 + atomic_unchecked_t irq_received;
30694
30695 /* protects the irq masks */
30696 spinlock_t irq_lock;
30697 @@ -1014,7 +1014,7 @@ struct drm_i915_gem_object {
30698 * will be page flipped away on the next vblank. When it
30699 * reaches 0, dev_priv->pending_flip_queue will be woken up.
30700 */
30701 - atomic_t pending_flip;
30702 + atomic_unchecked_t pending_flip;
30703 };
30704
30705 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
30706 @@ -1482,7 +1482,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
30707 struct drm_i915_private *dev_priv, unsigned port);
30708 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
30709 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
30710 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30711 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30712 {
30713 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
30714 }
30715 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30716 index cdf46b5..e785624 100644
30717 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30718 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30719 @@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
30720 i915_gem_clflush_object(obj);
30721
30722 if (obj->base.pending_write_domain)
30723 - cd->flips |= atomic_read(&obj->pending_flip);
30724 + cd->flips |= atomic_read_unchecked(&obj->pending_flip);
30725
30726 /* The actual obj->write_domain will be updated with
30727 * pending_write_domain after we emit the accumulated flush for all
30728 @@ -907,9 +907,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
30729
30730 static int
30731 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
30732 - int count)
30733 + unsigned int count)
30734 {
30735 - int i;
30736 + unsigned int i;
30737
30738 for (i = 0; i < count; i++) {
30739 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
30740 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
30741 index 73fa3e1..ab2e9b9 100644
30742 --- a/drivers/gpu/drm/i915/i915_irq.c
30743 +++ b/drivers/gpu/drm/i915/i915_irq.c
30744 @@ -514,7 +514,7 @@ static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS)
30745 u32 pipe_stats[I915_MAX_PIPES];
30746 bool blc_event;
30747
30748 - atomic_inc(&dev_priv->irq_received);
30749 + atomic_inc_unchecked(&dev_priv->irq_received);
30750
30751 while (true) {
30752 iir = I915_READ(VLV_IIR);
30753 @@ -661,7 +661,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
30754 irqreturn_t ret = IRQ_NONE;
30755 int i;
30756
30757 - atomic_inc(&dev_priv->irq_received);
30758 + atomic_inc_unchecked(&dev_priv->irq_received);
30759
30760 /* disable master interrupt before clearing iir */
30761 de_ier = I915_READ(DEIER);
30762 @@ -736,7 +736,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
30763 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
30764 u32 hotplug_mask;
30765
30766 - atomic_inc(&dev_priv->irq_received);
30767 + atomic_inc_unchecked(&dev_priv->irq_received);
30768
30769 /* disable master interrupt before clearing iir */
30770 de_ier = I915_READ(DEIER);
30771 @@ -1717,7 +1717,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
30772 {
30773 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30774
30775 - atomic_set(&dev_priv->irq_received, 0);
30776 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30777
30778 I915_WRITE(HWSTAM, 0xeffe);
30779
30780 @@ -1743,7 +1743,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
30781 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30782 int pipe;
30783
30784 - atomic_set(&dev_priv->irq_received, 0);
30785 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30786
30787 /* VLV magic */
30788 I915_WRITE(VLV_IMR, 0);
30789 @@ -2048,7 +2048,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
30790 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30791 int pipe;
30792
30793 - atomic_set(&dev_priv->irq_received, 0);
30794 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30795
30796 for_each_pipe(pipe)
30797 I915_WRITE(PIPESTAT(pipe), 0);
30798 @@ -2099,7 +2099,7 @@ static irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS)
30799 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
30800 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
30801
30802 - atomic_inc(&dev_priv->irq_received);
30803 + atomic_inc_unchecked(&dev_priv->irq_received);
30804
30805 iir = I915_READ16(IIR);
30806 if (iir == 0)
30807 @@ -2184,7 +2184,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
30808 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30809 int pipe;
30810
30811 - atomic_set(&dev_priv->irq_received, 0);
30812 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30813
30814 if (I915_HAS_HOTPLUG(dev)) {
30815 I915_WRITE(PORT_HOTPLUG_EN, 0);
30816 @@ -2279,7 +2279,7 @@ static irqreturn_t i915_irq_handler(DRM_IRQ_ARGS)
30817 };
30818 int pipe, ret = IRQ_NONE;
30819
30820 - atomic_inc(&dev_priv->irq_received);
30821 + atomic_inc_unchecked(&dev_priv->irq_received);
30822
30823 iir = I915_READ(IIR);
30824 do {
30825 @@ -2405,7 +2405,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
30826 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30827 int pipe;
30828
30829 - atomic_set(&dev_priv->irq_received, 0);
30830 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30831
30832 I915_WRITE(PORT_HOTPLUG_EN, 0);
30833 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
30834 @@ -2512,7 +2512,7 @@ static irqreturn_t i965_irq_handler(DRM_IRQ_ARGS)
30835 int irq_received;
30836 int ret = IRQ_NONE, pipe;
30837
30838 - atomic_inc(&dev_priv->irq_received);
30839 + atomic_inc_unchecked(&dev_priv->irq_received);
30840
30841 iir = I915_READ(IIR);
30842
30843 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
30844 index b634f6f..43c62f5 100644
30845 --- a/drivers/gpu/drm/i915/intel_display.c
30846 +++ b/drivers/gpu/drm/i915/intel_display.c
30847 @@ -2182,7 +2182,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
30848
30849 wait_event(dev_priv->pending_flip_queue,
30850 atomic_read(&dev_priv->mm.wedged) ||
30851 - atomic_read(&obj->pending_flip) == 0);
30852 + atomic_read_unchecked(&obj->pending_flip) == 0);
30853
30854 /* Big Hammer, we also need to ensure that any pending
30855 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
30856 @@ -6168,8 +6168,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
30857
30858 obj = work->old_fb_obj;
30859
30860 - atomic_clear_mask(1 << intel_crtc->plane,
30861 - &obj->pending_flip.counter);
30862 + atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
30863
30864 wake_up(&dev_priv->pending_flip_queue);
30865 schedule_work(&work->work);
30866 @@ -6515,7 +6514,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30867 /* Block clients from rendering to the new back buffer until
30868 * the flip occurs and the object is no longer visible.
30869 */
30870 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30871 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30872
30873 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
30874 if (ret)
30875 @@ -6530,7 +6529,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30876 return 0;
30877
30878 cleanup_pending:
30879 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30880 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30881 drm_gem_object_unreference(&work->old_fb_obj->base);
30882 drm_gem_object_unreference(&obj->base);
30883 mutex_unlock(&dev->struct_mutex);
30884 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
30885 index 54558a0..2d97005 100644
30886 --- a/drivers/gpu/drm/mga/mga_drv.h
30887 +++ b/drivers/gpu/drm/mga/mga_drv.h
30888 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
30889 u32 clear_cmd;
30890 u32 maccess;
30891
30892 - atomic_t vbl_received; /**< Number of vblanks received. */
30893 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
30894 wait_queue_head_t fence_queue;
30895 - atomic_t last_fence_retired;
30896 + atomic_unchecked_t last_fence_retired;
30897 u32 next_fence_to_post;
30898
30899 unsigned int fb_cpp;
30900 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
30901 index 2581202..f230a8d9 100644
30902 --- a/drivers/gpu/drm/mga/mga_irq.c
30903 +++ b/drivers/gpu/drm/mga/mga_irq.c
30904 @@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
30905 if (crtc != 0)
30906 return 0;
30907
30908 - return atomic_read(&dev_priv->vbl_received);
30909 + return atomic_read_unchecked(&dev_priv->vbl_received);
30910 }
30911
30912
30913 @@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30914 /* VBLANK interrupt */
30915 if (status & MGA_VLINEPEN) {
30916 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
30917 - atomic_inc(&dev_priv->vbl_received);
30918 + atomic_inc_unchecked(&dev_priv->vbl_received);
30919 drm_handle_vblank(dev, 0);
30920 handled = 1;
30921 }
30922 @@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30923 if ((prim_start & ~0x03) != (prim_end & ~0x03))
30924 MGA_WRITE(MGA_PRIMEND, prim_end);
30925
30926 - atomic_inc(&dev_priv->last_fence_retired);
30927 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
30928 DRM_WAKEUP(&dev_priv->fence_queue);
30929 handled = 1;
30930 }
30931 @@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
30932 * using fences.
30933 */
30934 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
30935 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
30936 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
30937 - *sequence) <= (1 << 23)));
30938
30939 *sequence = cur_fence;
30940 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
30941 index a0a3fe3..209bf10 100644
30942 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
30943 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
30944 @@ -5340,7 +5340,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
30945 struct bit_table {
30946 const char id;
30947 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
30948 -};
30949 +} __no_const;
30950
30951 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
30952
30953 diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
30954 index 4f2cc95..9c6c510 100644
30955 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h
30956 +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
30957 @@ -302,7 +302,7 @@ struct nouveau_exec_engine {
30958 u32 handle, u16 class);
30959 void (*set_tile_region)(struct drm_device *dev, int i);
30960 void (*tlb_flush)(struct drm_device *, int engine);
30961 -};
30962 +} __no_const;
30963
30964 struct nouveau_instmem_engine {
30965 void *priv;
30966 @@ -324,13 +324,13 @@ struct nouveau_instmem_engine {
30967 struct nouveau_mc_engine {
30968 int (*init)(struct drm_device *dev);
30969 void (*takedown)(struct drm_device *dev);
30970 -};
30971 +} __no_const;
30972
30973 struct nouveau_timer_engine {
30974 int (*init)(struct drm_device *dev);
30975 void (*takedown)(struct drm_device *dev);
30976 uint64_t (*read)(struct drm_device *dev);
30977 -};
30978 +} __no_const;
30979
30980 struct nouveau_fb_engine {
30981 int num_tiles;
30982 @@ -547,7 +547,7 @@ struct nouveau_vram_engine {
30983 void (*put)(struct drm_device *, struct nouveau_mem **);
30984
30985 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
30986 -};
30987 +} __no_const;
30988
30989 struct nouveau_engine {
30990 struct nouveau_instmem_engine instmem;
30991 @@ -693,7 +693,7 @@ struct drm_nouveau_private {
30992 struct drm_global_reference mem_global_ref;
30993 struct ttm_bo_global_ref bo_global_ref;
30994 struct ttm_bo_device bdev;
30995 - atomic_t validate_sequence;
30996 + atomic_unchecked_t validate_sequence;
30997 int (*move)(struct nouveau_channel *,
30998 struct ttm_buffer_object *,
30999 struct ttm_mem_reg *, struct ttm_mem_reg *);
31000 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
31001 index af7cfb8..aadc2a3 100644
31002 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
31003 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
31004 @@ -318,7 +318,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
31005 int trycnt = 0;
31006 int ret, i;
31007
31008 - sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
31009 + sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
31010 retry:
31011 if (++trycnt > 100000) {
31012 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
31013 diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
31014 index f5e9584..05934ba 100644
31015 --- a/drivers/gpu/drm/nouveau/nouveau_state.c
31016 +++ b/drivers/gpu/drm/nouveau/nouveau_state.c
31017 @@ -492,7 +492,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
31018 bool can_switch;
31019
31020 spin_lock(&dev->count_lock);
31021 - can_switch = (dev->open_count == 0);
31022 + can_switch = (local_read(&dev->open_count) == 0);
31023 spin_unlock(&dev->count_lock);
31024 return can_switch;
31025 }
31026 diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
31027 index 93240bd..c490f60 100644
31028 --- a/drivers/gpu/drm/nouveau/nv50_sor.c
31029 +++ b/drivers/gpu/drm/nouveau/nv50_sor.c
31030 @@ -304,7 +304,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
31031 }
31032
31033 if (nv_encoder->dcb->type == OUTPUT_DP) {
31034 - struct dp_train_func func = {
31035 + static struct dp_train_func func = {
31036 .link_set = nv50_sor_dp_link_set,
31037 .train_set = nv50_sor_dp_train_set,
31038 .train_adj = nv50_sor_dp_train_adj
31039 diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
31040 index 8a2fc89..3a5cf40 100644
31041 --- a/drivers/gpu/drm/nouveau/nvd0_display.c
31042 +++ b/drivers/gpu/drm/nouveau/nvd0_display.c
31043 @@ -1367,7 +1367,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
31044 nv_wait(dev, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
31045
31046 if (nv_encoder->dcb->type == OUTPUT_DP) {
31047 - struct dp_train_func func = {
31048 + static struct dp_train_func func = {
31049 .link_set = nvd0_sor_dp_link_set,
31050 .train_set = nvd0_sor_dp_train_set,
31051 .train_adj = nvd0_sor_dp_train_adj
31052 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
31053 index bcac90b..53bfc76 100644
31054 --- a/drivers/gpu/drm/r128/r128_cce.c
31055 +++ b/drivers/gpu/drm/r128/r128_cce.c
31056 @@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
31057
31058 /* GH: Simple idle check.
31059 */
31060 - atomic_set(&dev_priv->idle_count, 0);
31061 + atomic_set_unchecked(&dev_priv->idle_count, 0);
31062
31063 /* We don't support anything other than bus-mastering ring mode,
31064 * but the ring can be in either AGP or PCI space for the ring
31065 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
31066 index 930c71b..499aded 100644
31067 --- a/drivers/gpu/drm/r128/r128_drv.h
31068 +++ b/drivers/gpu/drm/r128/r128_drv.h
31069 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
31070 int is_pci;
31071 unsigned long cce_buffers_offset;
31072
31073 - atomic_t idle_count;
31074 + atomic_unchecked_t idle_count;
31075
31076 int page_flipping;
31077 int current_page;
31078 u32 crtc_offset;
31079 u32 crtc_offset_cntl;
31080
31081 - atomic_t vbl_received;
31082 + atomic_unchecked_t vbl_received;
31083
31084 u32 color_fmt;
31085 unsigned int front_offset;
31086 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
31087 index 429d5a0..7e899ed 100644
31088 --- a/drivers/gpu/drm/r128/r128_irq.c
31089 +++ b/drivers/gpu/drm/r128/r128_irq.c
31090 @@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
31091 if (crtc != 0)
31092 return 0;
31093
31094 - return atomic_read(&dev_priv->vbl_received);
31095 + return atomic_read_unchecked(&dev_priv->vbl_received);
31096 }
31097
31098 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31099 @@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31100 /* VBLANK interrupt */
31101 if (status & R128_CRTC_VBLANK_INT) {
31102 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
31103 - atomic_inc(&dev_priv->vbl_received);
31104 + atomic_inc_unchecked(&dev_priv->vbl_received);
31105 drm_handle_vblank(dev, 0);
31106 return IRQ_HANDLED;
31107 }
31108 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
31109 index a9e33ce..09edd4b 100644
31110 --- a/drivers/gpu/drm/r128/r128_state.c
31111 +++ b/drivers/gpu/drm/r128/r128_state.c
31112 @@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
31113
31114 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
31115 {
31116 - if (atomic_read(&dev_priv->idle_count) == 0)
31117 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
31118 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
31119 else
31120 - atomic_set(&dev_priv->idle_count, 0);
31121 + atomic_set_unchecked(&dev_priv->idle_count, 0);
31122 }
31123
31124 #endif
31125 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
31126 index 5a82b6b..9e69c73 100644
31127 --- a/drivers/gpu/drm/radeon/mkregtable.c
31128 +++ b/drivers/gpu/drm/radeon/mkregtable.c
31129 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
31130 regex_t mask_rex;
31131 regmatch_t match[4];
31132 char buf[1024];
31133 - size_t end;
31134 + long end;
31135 int len;
31136 int done = 0;
31137 int r;
31138 unsigned o;
31139 struct offset *offset;
31140 char last_reg_s[10];
31141 - int last_reg;
31142 + unsigned long last_reg;
31143
31144 if (regcomp
31145 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
31146 diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
31147 index 59a1531..3bab49b 100644
31148 --- a/drivers/gpu/drm/radeon/radeon.h
31149 +++ b/drivers/gpu/drm/radeon/radeon.h
31150 @@ -711,7 +711,7 @@ struct r600_blit_cp_primitives {
31151 int x2, int y2);
31152 void (*draw_auto)(struct radeon_device *rdev);
31153 void (*set_default_state)(struct radeon_device *rdev);
31154 -};
31155 +} __no_const;
31156
31157 struct r600_blit {
31158 struct radeon_bo *shader_obj;
31159 @@ -1216,7 +1216,7 @@ struct radeon_asic {
31160 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
31161 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
31162 } pflip;
31163 -};
31164 +} __no_const;
31165
31166 /*
31167 * Asic structures
31168 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
31169 index 7a3daeb..5016171 100644
31170 --- a/drivers/gpu/drm/radeon/radeon_device.c
31171 +++ b/drivers/gpu/drm/radeon/radeon_device.c
31172 @@ -952,7 +952,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
31173 bool can_switch;
31174
31175 spin_lock(&dev->count_lock);
31176 - can_switch = (dev->open_count == 0);
31177 + can_switch = (local_read(&dev->open_count) == 0);
31178 spin_unlock(&dev->count_lock);
31179 return can_switch;
31180 }
31181 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
31182 index a1b59ca..86f2d44 100644
31183 --- a/drivers/gpu/drm/radeon/radeon_drv.h
31184 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
31185 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
31186
31187 /* SW interrupt */
31188 wait_queue_head_t swi_queue;
31189 - atomic_t swi_emitted;
31190 + atomic_unchecked_t swi_emitted;
31191 int vblank_crtc;
31192 uint32_t irq_enable_reg;
31193 uint32_t r500_disp_irq_reg;
31194 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
31195 index 48b7cea..342236f 100644
31196 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
31197 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
31198 @@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
31199 request = compat_alloc_user_space(sizeof(*request));
31200 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
31201 || __put_user(req32.param, &request->param)
31202 - || __put_user((void __user *)(unsigned long)req32.value,
31203 + || __put_user((unsigned long)req32.value,
31204 &request->value))
31205 return -EFAULT;
31206
31207 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
31208 index 00da384..32f972d 100644
31209 --- a/drivers/gpu/drm/radeon/radeon_irq.c
31210 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
31211 @@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
31212 unsigned int ret;
31213 RING_LOCALS;
31214
31215 - atomic_inc(&dev_priv->swi_emitted);
31216 - ret = atomic_read(&dev_priv->swi_emitted);
31217 + atomic_inc_unchecked(&dev_priv->swi_emitted);
31218 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
31219
31220 BEGIN_RING(4);
31221 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
31222 @@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
31223 drm_radeon_private_t *dev_priv =
31224 (drm_radeon_private_t *) dev->dev_private;
31225
31226 - atomic_set(&dev_priv->swi_emitted, 0);
31227 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
31228 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
31229
31230 dev->max_vblank_count = 0x001fffff;
31231 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
31232 index e8422ae..d22d4a8 100644
31233 --- a/drivers/gpu/drm/radeon/radeon_state.c
31234 +++ b/drivers/gpu/drm/radeon/radeon_state.c
31235 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
31236 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
31237 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
31238
31239 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31240 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31241 sarea_priv->nbox * sizeof(depth_boxes[0])))
31242 return -EFAULT;
31243
31244 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
31245 {
31246 drm_radeon_private_t *dev_priv = dev->dev_private;
31247 drm_radeon_getparam_t *param = data;
31248 - int value;
31249 + int value = 0;
31250
31251 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
31252
31253 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
31254 index 5b71c71..650f9e4 100644
31255 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
31256 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
31257 @@ -822,8 +822,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
31258 }
31259 if (unlikely(ttm_vm_ops == NULL)) {
31260 ttm_vm_ops = vma->vm_ops;
31261 - radeon_ttm_vm_ops = *ttm_vm_ops;
31262 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31263 + pax_open_kernel();
31264 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
31265 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31266 + pax_close_kernel();
31267 }
31268 vma->vm_ops = &radeon_ttm_vm_ops;
31269 return 0;
31270 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
31271 index 3b663fc..57850f4 100644
31272 --- a/drivers/gpu/drm/radeon/rs690.c
31273 +++ b/drivers/gpu/drm/radeon/rs690.c
31274 @@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
31275 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
31276 rdev->pm.sideport_bandwidth.full)
31277 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
31278 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
31279 + read_delay_latency.full = dfixed_const(800 * 1000);
31280 read_delay_latency.full = dfixed_div(read_delay_latency,
31281 rdev->pm.igp_sideport_mclk);
31282 + a.full = dfixed_const(370);
31283 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
31284 } else {
31285 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
31286 rdev->pm.k8_bandwidth.full)
31287 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31288 index ebc6fac..a8313ed 100644
31289 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
31290 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31291 @@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
31292 static int ttm_pool_mm_shrink(struct shrinker *shrink,
31293 struct shrink_control *sc)
31294 {
31295 - static atomic_t start_pool = ATOMIC_INIT(0);
31296 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
31297 unsigned i;
31298 - unsigned pool_offset = atomic_add_return(1, &start_pool);
31299 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
31300 struct ttm_page_pool *pool;
31301 int shrink_pages = sc->nr_to_scan;
31302
31303 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
31304 index 88edacc..1e5412b 100644
31305 --- a/drivers/gpu/drm/via/via_drv.h
31306 +++ b/drivers/gpu/drm/via/via_drv.h
31307 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
31308 typedef uint32_t maskarray_t[5];
31309
31310 typedef struct drm_via_irq {
31311 - atomic_t irq_received;
31312 + atomic_unchecked_t irq_received;
31313 uint32_t pending_mask;
31314 uint32_t enable_mask;
31315 wait_queue_head_t irq_queue;
31316 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
31317 struct timeval last_vblank;
31318 int last_vblank_valid;
31319 unsigned usec_per_vblank;
31320 - atomic_t vbl_received;
31321 + atomic_unchecked_t vbl_received;
31322 drm_via_state_t hc_state;
31323 char pci_buf[VIA_PCI_BUF_SIZE];
31324 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
31325 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
31326 index d391f48..10c8ca3 100644
31327 --- a/drivers/gpu/drm/via/via_irq.c
31328 +++ b/drivers/gpu/drm/via/via_irq.c
31329 @@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
31330 if (crtc != 0)
31331 return 0;
31332
31333 - return atomic_read(&dev_priv->vbl_received);
31334 + return atomic_read_unchecked(&dev_priv->vbl_received);
31335 }
31336
31337 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31338 @@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31339
31340 status = VIA_READ(VIA_REG_INTERRUPT);
31341 if (status & VIA_IRQ_VBLANK_PENDING) {
31342 - atomic_inc(&dev_priv->vbl_received);
31343 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
31344 + atomic_inc_unchecked(&dev_priv->vbl_received);
31345 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
31346 do_gettimeofday(&cur_vblank);
31347 if (dev_priv->last_vblank_valid) {
31348 dev_priv->usec_per_vblank =
31349 @@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31350 dev_priv->last_vblank = cur_vblank;
31351 dev_priv->last_vblank_valid = 1;
31352 }
31353 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
31354 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
31355 DRM_DEBUG("US per vblank is: %u\n",
31356 dev_priv->usec_per_vblank);
31357 }
31358 @@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31359
31360 for (i = 0; i < dev_priv->num_irqs; ++i) {
31361 if (status & cur_irq->pending_mask) {
31362 - atomic_inc(&cur_irq->irq_received);
31363 + atomic_inc_unchecked(&cur_irq->irq_received);
31364 DRM_WAKEUP(&cur_irq->irq_queue);
31365 handled = 1;
31366 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
31367 @@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
31368 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31369 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31370 masks[irq][4]));
31371 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31372 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31373 } else {
31374 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31375 (((cur_irq_sequence =
31376 - atomic_read(&cur_irq->irq_received)) -
31377 + atomic_read_unchecked(&cur_irq->irq_received)) -
31378 *sequence) <= (1 << 23)));
31379 }
31380 *sequence = cur_irq_sequence;
31381 @@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
31382 }
31383
31384 for (i = 0; i < dev_priv->num_irqs; ++i) {
31385 - atomic_set(&cur_irq->irq_received, 0);
31386 + atomic_set_unchecked(&cur_irq->irq_received, 0);
31387 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31388 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31389 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31390 @@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
31391 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31392 case VIA_IRQ_RELATIVE:
31393 irqwait->request.sequence +=
31394 - atomic_read(&cur_irq->irq_received);
31395 + atomic_read_unchecked(&cur_irq->irq_received);
31396 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31397 case VIA_IRQ_ABSOLUTE:
31398 break;
31399 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31400 index 29c984f..4084f1a 100644
31401 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31402 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31403 @@ -263,7 +263,7 @@ struct vmw_private {
31404 * Fencing and IRQs.
31405 */
31406
31407 - atomic_t marker_seq;
31408 + atomic_unchecked_t marker_seq;
31409 wait_queue_head_t fence_queue;
31410 wait_queue_head_t fifo_queue;
31411 int fence_queue_waiters; /* Protected by hw_mutex */
31412 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31413 index a0c2f12..68ae6cb 100644
31414 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31415 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31416 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31417 (unsigned int) min,
31418 (unsigned int) fifo->capabilities);
31419
31420 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31421 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31422 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31423 vmw_marker_queue_init(&fifo->marker_queue);
31424 return vmw_fifo_send_fence(dev_priv, &dummy);
31425 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31426 if (reserveable)
31427 iowrite32(bytes, fifo_mem +
31428 SVGA_FIFO_RESERVED);
31429 - return fifo_mem + (next_cmd >> 2);
31430 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31431 } else {
31432 need_bounce = true;
31433 }
31434 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31435
31436 fm = vmw_fifo_reserve(dev_priv, bytes);
31437 if (unlikely(fm == NULL)) {
31438 - *seqno = atomic_read(&dev_priv->marker_seq);
31439 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31440 ret = -ENOMEM;
31441 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31442 false, 3*HZ);
31443 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31444 }
31445
31446 do {
31447 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31448 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31449 } while (*seqno == 0);
31450
31451 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31452 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31453 index cabc95f..14b3d77 100644
31454 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31455 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31456 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31457 * emitted. Then the fence is stale and signaled.
31458 */
31459
31460 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31461 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31462 > VMW_FENCE_WRAP);
31463
31464 return ret;
31465 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31466
31467 if (fifo_idle)
31468 down_read(&fifo_state->rwsem);
31469 - signal_seq = atomic_read(&dev_priv->marker_seq);
31470 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31471 ret = 0;
31472
31473 for (;;) {
31474 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31475 index 8a8725c..afed796 100644
31476 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31477 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31478 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31479 while (!vmw_lag_lt(queue, us)) {
31480 spin_lock(&queue->lock);
31481 if (list_empty(&queue->head))
31482 - seqno = atomic_read(&dev_priv->marker_seq);
31483 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31484 else {
31485 marker = list_first_entry(&queue->head,
31486 struct vmw_marker, head);
31487 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31488 index 5de3bb3..08e5063 100644
31489 --- a/drivers/hid/hid-core.c
31490 +++ b/drivers/hid/hid-core.c
31491 @@ -2177,7 +2177,7 @@ static bool hid_ignore(struct hid_device *hdev)
31492
31493 int hid_add_device(struct hid_device *hdev)
31494 {
31495 - static atomic_t id = ATOMIC_INIT(0);
31496 + static atomic_unchecked_t id = ATOMIC_INIT(0);
31497 int ret;
31498
31499 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31500 @@ -2212,7 +2212,7 @@ int hid_add_device(struct hid_device *hdev)
31501 /* XXX hack, any other cleaner solution after the driver core
31502 * is converted to allow more than 20 bytes as the device name? */
31503 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31504 - hdev->vendor, hdev->product, atomic_inc_return(&id));
31505 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31506
31507 hid_debug_register(hdev, dev_name(&hdev->dev));
31508 ret = device_add(&hdev->dev);
31509 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
31510 index eec3291..8ed706b 100644
31511 --- a/drivers/hid/hid-wiimote-debug.c
31512 +++ b/drivers/hid/hid-wiimote-debug.c
31513 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
31514 else if (size == 0)
31515 return -EIO;
31516
31517 - if (copy_to_user(u, buf, size))
31518 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
31519 return -EFAULT;
31520
31521 *off += size;
31522 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31523 index 14599e2..711c965 100644
31524 --- a/drivers/hid/usbhid/hiddev.c
31525 +++ b/drivers/hid/usbhid/hiddev.c
31526 @@ -625,7 +625,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31527 break;
31528
31529 case HIDIOCAPPLICATION:
31530 - if (arg < 0 || arg >= hid->maxapplication)
31531 + if (arg >= hid->maxapplication)
31532 break;
31533
31534 for (i = 0; i < hid->maxcollection; i++)
31535 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31536 index f4c3d28..82f45a9 100644
31537 --- a/drivers/hv/channel.c
31538 +++ b/drivers/hv/channel.c
31539 @@ -402,8 +402,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31540 int ret = 0;
31541 int t;
31542
31543 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31544 - atomic_inc(&vmbus_connection.next_gpadl_handle);
31545 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31546 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31547
31548 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31549 if (ret)
31550 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31551 index 86f8885..ab9cb2b 100644
31552 --- a/drivers/hv/hv.c
31553 +++ b/drivers/hv/hv.c
31554 @@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31555 u64 output_address = (output) ? virt_to_phys(output) : 0;
31556 u32 output_address_hi = output_address >> 32;
31557 u32 output_address_lo = output_address & 0xFFFFFFFF;
31558 - void *hypercall_page = hv_context.hypercall_page;
31559 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31560
31561 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31562 "=a"(hv_status_lo) : "d" (control_hi),
31563 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31564 index 0614ff3..f0b2b5c 100644
31565 --- a/drivers/hv/hyperv_vmbus.h
31566 +++ b/drivers/hv/hyperv_vmbus.h
31567 @@ -555,7 +555,7 @@ enum vmbus_connect_state {
31568 struct vmbus_connection {
31569 enum vmbus_connect_state conn_state;
31570
31571 - atomic_t next_gpadl_handle;
31572 + atomic_unchecked_t next_gpadl_handle;
31573
31574 /*
31575 * Represents channel interrupts. Each bit position represents a
31576 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31577 index 4748086..3abf845 100644
31578 --- a/drivers/hv/vmbus_drv.c
31579 +++ b/drivers/hv/vmbus_drv.c
31580 @@ -662,10 +662,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31581 {
31582 int ret = 0;
31583
31584 - static atomic_t device_num = ATOMIC_INIT(0);
31585 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31586
31587 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31588 - atomic_inc_return(&device_num));
31589 + atomic_inc_return_unchecked(&device_num));
31590
31591 child_device_obj->device.bus = &hv_bus;
31592 child_device_obj->device.parent = &hv_acpi_dev->dev;
31593 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31594 index 8b011d0..3de24a1 100644
31595 --- a/drivers/hwmon/sht15.c
31596 +++ b/drivers/hwmon/sht15.c
31597 @@ -166,7 +166,7 @@ struct sht15_data {
31598 int supply_uV;
31599 bool supply_uV_valid;
31600 struct work_struct update_supply_work;
31601 - atomic_t interrupt_handled;
31602 + atomic_unchecked_t interrupt_handled;
31603 };
31604
31605 /**
31606 @@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
31607 return ret;
31608
31609 gpio_direction_input(data->pdata->gpio_data);
31610 - atomic_set(&data->interrupt_handled, 0);
31611 + atomic_set_unchecked(&data->interrupt_handled, 0);
31612
31613 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31614 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31615 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31616 /* Only relevant if the interrupt hasn't occurred. */
31617 - if (!atomic_read(&data->interrupt_handled))
31618 + if (!atomic_read_unchecked(&data->interrupt_handled))
31619 schedule_work(&data->read_work);
31620 }
31621 ret = wait_event_timeout(data->wait_queue,
31622 @@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31623
31624 /* First disable the interrupt */
31625 disable_irq_nosync(irq);
31626 - atomic_inc(&data->interrupt_handled);
31627 + atomic_inc_unchecked(&data->interrupt_handled);
31628 /* Then schedule a reading work struct */
31629 if (data->state != SHT15_READING_NOTHING)
31630 schedule_work(&data->read_work);
31631 @@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31632 * If not, then start the interrupt again - care here as could
31633 * have gone low in meantime so verify it hasn't!
31634 */
31635 - atomic_set(&data->interrupt_handled, 0);
31636 + atomic_set_unchecked(&data->interrupt_handled, 0);
31637 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31638 /* If still not occurred or another handler was scheduled */
31639 if (gpio_get_value(data->pdata->gpio_data)
31640 - || atomic_read(&data->interrupt_handled))
31641 + || atomic_read_unchecked(&data->interrupt_handled))
31642 return;
31643 }
31644
31645 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31646 index 378fcb5..5e91fa8 100644
31647 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
31648 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31649 @@ -43,7 +43,7 @@
31650 extern struct i2c_adapter amd756_smbus;
31651
31652 static struct i2c_adapter *s4882_adapter;
31653 -static struct i2c_algorithm *s4882_algo;
31654 +static i2c_algorithm_no_const *s4882_algo;
31655
31656 /* Wrapper access functions for multiplexed SMBus */
31657 static DEFINE_MUTEX(amd756_lock);
31658 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31659 index 29015eb..af2d8e9 100644
31660 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31661 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
31662 @@ -41,7 +41,7 @@
31663 extern struct i2c_adapter *nforce2_smbus;
31664
31665 static struct i2c_adapter *s4985_adapter;
31666 -static struct i2c_algorithm *s4985_algo;
31667 +static i2c_algorithm_no_const *s4985_algo;
31668
31669 /* Wrapper access functions for multiplexed SMBus */
31670 static DEFINE_MUTEX(nforce2_lock);
31671 diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
31672 index 1038c38..eb92f51 100644
31673 --- a/drivers/i2c/i2c-mux.c
31674 +++ b/drivers/i2c/i2c-mux.c
31675 @@ -30,7 +30,7 @@
31676 /* multiplexer per channel data */
31677 struct i2c_mux_priv {
31678 struct i2c_adapter adap;
31679 - struct i2c_algorithm algo;
31680 + i2c_algorithm_no_const algo;
31681
31682 struct i2c_adapter *parent;
31683 void *mux_priv; /* the mux chip/device */
31684 diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
31685 index 57d00ca..0145194 100644
31686 --- a/drivers/ide/aec62xx.c
31687 +++ b/drivers/ide/aec62xx.c
31688 @@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
31689 .cable_detect = atp86x_cable_detect,
31690 };
31691
31692 -static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
31693 +static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
31694 { /* 0: AEC6210 */
31695 .name = DRV_NAME,
31696 .init_chipset = init_chipset_aec62xx,
31697 diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
31698 index 2c8016a..911a27c 100644
31699 --- a/drivers/ide/alim15x3.c
31700 +++ b/drivers/ide/alim15x3.c
31701 @@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
31702 .dma_sff_read_status = ide_dma_sff_read_status,
31703 };
31704
31705 -static const struct ide_port_info ali15x3_chipset __devinitdata = {
31706 +static const struct ide_port_info ali15x3_chipset __devinitconst = {
31707 .name = DRV_NAME,
31708 .init_chipset = init_chipset_ali15x3,
31709 .init_hwif = init_hwif_ali15x3,
31710 diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
31711 index 3747b25..56fc995 100644
31712 --- a/drivers/ide/amd74xx.c
31713 +++ b/drivers/ide/amd74xx.c
31714 @@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
31715 .udma_mask = udma, \
31716 }
31717
31718 -static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
31719 +static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
31720 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
31721 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
31722 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
31723 diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
31724 index 15f0ead..cb43480 100644
31725 --- a/drivers/ide/atiixp.c
31726 +++ b/drivers/ide/atiixp.c
31727 @@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
31728 .cable_detect = atiixp_cable_detect,
31729 };
31730
31731 -static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
31732 +static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
31733 { /* 0: IXP200/300/400/700 */
31734 .name = DRV_NAME,
31735 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
31736 diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
31737 index 5f80312..d1fc438 100644
31738 --- a/drivers/ide/cmd64x.c
31739 +++ b/drivers/ide/cmd64x.c
31740 @@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
31741 .dma_sff_read_status = ide_dma_sff_read_status,
31742 };
31743
31744 -static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
31745 +static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
31746 { /* 0: CMD643 */
31747 .name = DRV_NAME,
31748 .init_chipset = init_chipset_cmd64x,
31749 diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
31750 index 2c1e5f7..1444762 100644
31751 --- a/drivers/ide/cs5520.c
31752 +++ b/drivers/ide/cs5520.c
31753 @@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
31754 .set_dma_mode = cs5520_set_dma_mode,
31755 };
31756
31757 -static const struct ide_port_info cyrix_chipset __devinitdata = {
31758 +static const struct ide_port_info cyrix_chipset __devinitconst = {
31759 .name = DRV_NAME,
31760 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
31761 .port_ops = &cs5520_port_ops,
31762 diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
31763 index 4dc4eb9..49b40ad 100644
31764 --- a/drivers/ide/cs5530.c
31765 +++ b/drivers/ide/cs5530.c
31766 @@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
31767 .udma_filter = cs5530_udma_filter,
31768 };
31769
31770 -static const struct ide_port_info cs5530_chipset __devinitdata = {
31771 +static const struct ide_port_info cs5530_chipset __devinitconst = {
31772 .name = DRV_NAME,
31773 .init_chipset = init_chipset_cs5530,
31774 .init_hwif = init_hwif_cs5530,
31775 diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
31776 index 5059faf..18d4c85 100644
31777 --- a/drivers/ide/cs5535.c
31778 +++ b/drivers/ide/cs5535.c
31779 @@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
31780 .cable_detect = cs5535_cable_detect,
31781 };
31782
31783 -static const struct ide_port_info cs5535_chipset __devinitdata = {
31784 +static const struct ide_port_info cs5535_chipset __devinitconst = {
31785 .name = DRV_NAME,
31786 .port_ops = &cs5535_port_ops,
31787 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
31788 diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
31789 index 847553f..3ffb49d 100644
31790 --- a/drivers/ide/cy82c693.c
31791 +++ b/drivers/ide/cy82c693.c
31792 @@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
31793 .set_dma_mode = cy82c693_set_dma_mode,
31794 };
31795
31796 -static const struct ide_port_info cy82c693_chipset __devinitdata = {
31797 +static const struct ide_port_info cy82c693_chipset __devinitconst = {
31798 .name = DRV_NAME,
31799 .init_iops = init_iops_cy82c693,
31800 .port_ops = &cy82c693_port_ops,
31801 diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
31802 index 58c51cd..4aec3b8 100644
31803 --- a/drivers/ide/hpt366.c
31804 +++ b/drivers/ide/hpt366.c
31805 @@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
31806 }
31807 };
31808
31809 -static const struct hpt_info hpt36x __devinitdata = {
31810 +static const struct hpt_info hpt36x __devinitconst = {
31811 .chip_name = "HPT36x",
31812 .chip_type = HPT36x,
31813 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
31814 @@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
31815 .timings = &hpt36x_timings
31816 };
31817
31818 -static const struct hpt_info hpt370 __devinitdata = {
31819 +static const struct hpt_info hpt370 __devinitconst = {
31820 .chip_name = "HPT370",
31821 .chip_type = HPT370,
31822 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31823 @@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
31824 .timings = &hpt37x_timings
31825 };
31826
31827 -static const struct hpt_info hpt370a __devinitdata = {
31828 +static const struct hpt_info hpt370a __devinitconst = {
31829 .chip_name = "HPT370A",
31830 .chip_type = HPT370A,
31831 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31832 @@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
31833 .timings = &hpt37x_timings
31834 };
31835
31836 -static const struct hpt_info hpt374 __devinitdata = {
31837 +static const struct hpt_info hpt374 __devinitconst = {
31838 .chip_name = "HPT374",
31839 .chip_type = HPT374,
31840 .udma_mask = ATA_UDMA5,
31841 @@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
31842 .timings = &hpt37x_timings
31843 };
31844
31845 -static const struct hpt_info hpt372 __devinitdata = {
31846 +static const struct hpt_info hpt372 __devinitconst = {
31847 .chip_name = "HPT372",
31848 .chip_type = HPT372,
31849 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31850 @@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
31851 .timings = &hpt37x_timings
31852 };
31853
31854 -static const struct hpt_info hpt372a __devinitdata = {
31855 +static const struct hpt_info hpt372a __devinitconst = {
31856 .chip_name = "HPT372A",
31857 .chip_type = HPT372A,
31858 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31859 @@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
31860 .timings = &hpt37x_timings
31861 };
31862
31863 -static const struct hpt_info hpt302 __devinitdata = {
31864 +static const struct hpt_info hpt302 __devinitconst = {
31865 .chip_name = "HPT302",
31866 .chip_type = HPT302,
31867 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31868 @@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
31869 .timings = &hpt37x_timings
31870 };
31871
31872 -static const struct hpt_info hpt371 __devinitdata = {
31873 +static const struct hpt_info hpt371 __devinitconst = {
31874 .chip_name = "HPT371",
31875 .chip_type = HPT371,
31876 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31877 @@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
31878 .timings = &hpt37x_timings
31879 };
31880
31881 -static const struct hpt_info hpt372n __devinitdata = {
31882 +static const struct hpt_info hpt372n __devinitconst = {
31883 .chip_name = "HPT372N",
31884 .chip_type = HPT372N,
31885 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31886 @@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
31887 .timings = &hpt37x_timings
31888 };
31889
31890 -static const struct hpt_info hpt302n __devinitdata = {
31891 +static const struct hpt_info hpt302n __devinitconst = {
31892 .chip_name = "HPT302N",
31893 .chip_type = HPT302N,
31894 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31895 @@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
31896 .timings = &hpt37x_timings
31897 };
31898
31899 -static const struct hpt_info hpt371n __devinitdata = {
31900 +static const struct hpt_info hpt371n __devinitconst = {
31901 .chip_name = "HPT371N",
31902 .chip_type = HPT371N,
31903 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31904 @@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
31905 .dma_sff_read_status = ide_dma_sff_read_status,
31906 };
31907
31908 -static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
31909 +static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
31910 { /* 0: HPT36x */
31911 .name = DRV_NAME,
31912 .init_chipset = init_chipset_hpt366,
31913 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
31914 index 8126824..55a2798 100644
31915 --- a/drivers/ide/ide-cd.c
31916 +++ b/drivers/ide/ide-cd.c
31917 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
31918 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
31919 if ((unsigned long)buf & alignment
31920 || blk_rq_bytes(rq) & q->dma_pad_mask
31921 - || object_is_on_stack(buf))
31922 + || object_starts_on_stack(buf))
31923 drive->dma = 0;
31924 }
31925 }
31926 diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
31927 index 7f56b73..dab5b67 100644
31928 --- a/drivers/ide/ide-pci-generic.c
31929 +++ b/drivers/ide/ide-pci-generic.c
31930 @@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
31931 .udma_mask = ATA_UDMA6, \
31932 }
31933
31934 -static const struct ide_port_info generic_chipsets[] __devinitdata = {
31935 +static const struct ide_port_info generic_chipsets[] __devinitconst = {
31936 /* 0: Unknown */
31937 DECLARE_GENERIC_PCI_DEV(0),
31938
31939 diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
31940 index 560e66d..d5dd180 100644
31941 --- a/drivers/ide/it8172.c
31942 +++ b/drivers/ide/it8172.c
31943 @@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
31944 .set_dma_mode = it8172_set_dma_mode,
31945 };
31946
31947 -static const struct ide_port_info it8172_port_info __devinitdata = {
31948 +static const struct ide_port_info it8172_port_info __devinitconst = {
31949 .name = DRV_NAME,
31950 .port_ops = &it8172_port_ops,
31951 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
31952 diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
31953 index 46816ba..1847aeb 100644
31954 --- a/drivers/ide/it8213.c
31955 +++ b/drivers/ide/it8213.c
31956 @@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
31957 .cable_detect = it8213_cable_detect,
31958 };
31959
31960 -static const struct ide_port_info it8213_chipset __devinitdata = {
31961 +static const struct ide_port_info it8213_chipset __devinitconst = {
31962 .name = DRV_NAME,
31963 .enablebits = { {0x41, 0x80, 0x80} },
31964 .port_ops = &it8213_port_ops,
31965 diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
31966 index 2e3169f..c5611db 100644
31967 --- a/drivers/ide/it821x.c
31968 +++ b/drivers/ide/it821x.c
31969 @@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
31970 .cable_detect = it821x_cable_detect,
31971 };
31972
31973 -static const struct ide_port_info it821x_chipset __devinitdata = {
31974 +static const struct ide_port_info it821x_chipset __devinitconst = {
31975 .name = DRV_NAME,
31976 .init_chipset = init_chipset_it821x,
31977 .init_hwif = init_hwif_it821x,
31978 diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
31979 index 74c2c4a..efddd7d 100644
31980 --- a/drivers/ide/jmicron.c
31981 +++ b/drivers/ide/jmicron.c
31982 @@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
31983 .cable_detect = jmicron_cable_detect,
31984 };
31985
31986 -static const struct ide_port_info jmicron_chipset __devinitdata = {
31987 +static const struct ide_port_info jmicron_chipset __devinitconst = {
31988 .name = DRV_NAME,
31989 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
31990 .port_ops = &jmicron_port_ops,
31991 diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
31992 index 95327a2..73f78d8 100644
31993 --- a/drivers/ide/ns87415.c
31994 +++ b/drivers/ide/ns87415.c
31995 @@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
31996 .dma_sff_read_status = superio_dma_sff_read_status,
31997 };
31998
31999 -static const struct ide_port_info ns87415_chipset __devinitdata = {
32000 +static const struct ide_port_info ns87415_chipset __devinitconst = {
32001 .name = DRV_NAME,
32002 .init_hwif = init_hwif_ns87415,
32003 .tp_ops = &ns87415_tp_ops,
32004 diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
32005 index 1a53a4c..39edc66 100644
32006 --- a/drivers/ide/opti621.c
32007 +++ b/drivers/ide/opti621.c
32008 @@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
32009 .set_pio_mode = opti621_set_pio_mode,
32010 };
32011
32012 -static const struct ide_port_info opti621_chipset __devinitdata = {
32013 +static const struct ide_port_info opti621_chipset __devinitconst = {
32014 .name = DRV_NAME,
32015 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
32016 .port_ops = &opti621_port_ops,
32017 diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
32018 index 9546fe2..2e5ceb6 100644
32019 --- a/drivers/ide/pdc202xx_new.c
32020 +++ b/drivers/ide/pdc202xx_new.c
32021 @@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
32022 .udma_mask = udma, \
32023 }
32024
32025 -static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
32026 +static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
32027 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
32028 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
32029 };
32030 diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
32031 index 3a35ec6..5634510 100644
32032 --- a/drivers/ide/pdc202xx_old.c
32033 +++ b/drivers/ide/pdc202xx_old.c
32034 @@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
32035 .max_sectors = sectors, \
32036 }
32037
32038 -static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
32039 +static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
32040 { /* 0: PDC20246 */
32041 .name = DRV_NAME,
32042 .init_chipset = init_chipset_pdc202xx,
32043 diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
32044 index 1892e81..fe0fd60 100644
32045 --- a/drivers/ide/piix.c
32046 +++ b/drivers/ide/piix.c
32047 @@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
32048 .udma_mask = udma, \
32049 }
32050
32051 -static const struct ide_port_info piix_pci_info[] __devinitdata = {
32052 +static const struct ide_port_info piix_pci_info[] __devinitconst = {
32053 /* 0: MPIIX */
32054 { /*
32055 * MPIIX actually has only a single IDE channel mapped to
32056 diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
32057 index a6414a8..c04173e 100644
32058 --- a/drivers/ide/rz1000.c
32059 +++ b/drivers/ide/rz1000.c
32060 @@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
32061 }
32062 }
32063
32064 -static const struct ide_port_info rz1000_chipset __devinitdata = {
32065 +static const struct ide_port_info rz1000_chipset __devinitconst = {
32066 .name = DRV_NAME,
32067 .host_flags = IDE_HFLAG_NO_DMA,
32068 };
32069 diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
32070 index 356b9b5..d4758eb 100644
32071 --- a/drivers/ide/sc1200.c
32072 +++ b/drivers/ide/sc1200.c
32073 @@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
32074 .dma_sff_read_status = ide_dma_sff_read_status,
32075 };
32076
32077 -static const struct ide_port_info sc1200_chipset __devinitdata = {
32078 +static const struct ide_port_info sc1200_chipset __devinitconst = {
32079 .name = DRV_NAME,
32080 .port_ops = &sc1200_port_ops,
32081 .dma_ops = &sc1200_dma_ops,
32082 diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
32083 index b7f5b0c..9701038 100644
32084 --- a/drivers/ide/scc_pata.c
32085 +++ b/drivers/ide/scc_pata.c
32086 @@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
32087 .dma_sff_read_status = scc_dma_sff_read_status,
32088 };
32089
32090 -static const struct ide_port_info scc_chipset __devinitdata = {
32091 +static const struct ide_port_info scc_chipset __devinitconst = {
32092 .name = "sccIDE",
32093 .init_iops = init_iops_scc,
32094 .init_dma = scc_init_dma,
32095 diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
32096 index 35fb8da..24d72ef 100644
32097 --- a/drivers/ide/serverworks.c
32098 +++ b/drivers/ide/serverworks.c
32099 @@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
32100 .cable_detect = svwks_cable_detect,
32101 };
32102
32103 -static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
32104 +static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
32105 { /* 0: OSB4 */
32106 .name = DRV_NAME,
32107 .init_chipset = init_chipset_svwks,
32108 diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
32109 index ddeda44..46f7e30 100644
32110 --- a/drivers/ide/siimage.c
32111 +++ b/drivers/ide/siimage.c
32112 @@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
32113 .udma_mask = ATA_UDMA6, \
32114 }
32115
32116 -static const struct ide_port_info siimage_chipsets[] __devinitdata = {
32117 +static const struct ide_port_info siimage_chipsets[] __devinitconst = {
32118 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
32119 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
32120 };
32121 diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
32122 index 4a00225..09e61b4 100644
32123 --- a/drivers/ide/sis5513.c
32124 +++ b/drivers/ide/sis5513.c
32125 @@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
32126 .cable_detect = sis_cable_detect,
32127 };
32128
32129 -static const struct ide_port_info sis5513_chipset __devinitdata = {
32130 +static const struct ide_port_info sis5513_chipset __devinitconst = {
32131 .name = DRV_NAME,
32132 .init_chipset = init_chipset_sis5513,
32133 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
32134 diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
32135 index f21dc2a..d051cd2 100644
32136 --- a/drivers/ide/sl82c105.c
32137 +++ b/drivers/ide/sl82c105.c
32138 @@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
32139 .dma_sff_read_status = ide_dma_sff_read_status,
32140 };
32141
32142 -static const struct ide_port_info sl82c105_chipset __devinitdata = {
32143 +static const struct ide_port_info sl82c105_chipset __devinitconst = {
32144 .name = DRV_NAME,
32145 .init_chipset = init_chipset_sl82c105,
32146 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
32147 diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
32148 index 864ffe0..863a5e9 100644
32149 --- a/drivers/ide/slc90e66.c
32150 +++ b/drivers/ide/slc90e66.c
32151 @@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
32152 .cable_detect = slc90e66_cable_detect,
32153 };
32154
32155 -static const struct ide_port_info slc90e66_chipset __devinitdata = {
32156 +static const struct ide_port_info slc90e66_chipset __devinitconst = {
32157 .name = DRV_NAME,
32158 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
32159 .port_ops = &slc90e66_port_ops,
32160 diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
32161 index 4799d5c..1794678 100644
32162 --- a/drivers/ide/tc86c001.c
32163 +++ b/drivers/ide/tc86c001.c
32164 @@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
32165 .dma_sff_read_status = ide_dma_sff_read_status,
32166 };
32167
32168 -static const struct ide_port_info tc86c001_chipset __devinitdata = {
32169 +static const struct ide_port_info tc86c001_chipset __devinitconst = {
32170 .name = DRV_NAME,
32171 .init_hwif = init_hwif_tc86c001,
32172 .port_ops = &tc86c001_port_ops,
32173 diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
32174 index 281c914..55ce1b8 100644
32175 --- a/drivers/ide/triflex.c
32176 +++ b/drivers/ide/triflex.c
32177 @@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
32178 .set_dma_mode = triflex_set_mode,
32179 };
32180
32181 -static const struct ide_port_info triflex_device __devinitdata = {
32182 +static const struct ide_port_info triflex_device __devinitconst = {
32183 .name = DRV_NAME,
32184 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
32185 .port_ops = &triflex_port_ops,
32186 diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
32187 index 4b42ca0..e494a98 100644
32188 --- a/drivers/ide/trm290.c
32189 +++ b/drivers/ide/trm290.c
32190 @@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
32191 .dma_check = trm290_dma_check,
32192 };
32193
32194 -static const struct ide_port_info trm290_chipset __devinitdata = {
32195 +static const struct ide_port_info trm290_chipset __devinitconst = {
32196 .name = DRV_NAME,
32197 .init_hwif = init_hwif_trm290,
32198 .tp_ops = &trm290_tp_ops,
32199 diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
32200 index f46f49c..eb77678 100644
32201 --- a/drivers/ide/via82cxxx.c
32202 +++ b/drivers/ide/via82cxxx.c
32203 @@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
32204 .cable_detect = via82cxxx_cable_detect,
32205 };
32206
32207 -static const struct ide_port_info via82cxxx_chipset __devinitdata = {
32208 +static const struct ide_port_info via82cxxx_chipset __devinitconst = {
32209 .name = DRV_NAME,
32210 .init_chipset = init_chipset_via82cxxx,
32211 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
32212 diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
32213 index 73d4531..c90cd2d 100644
32214 --- a/drivers/ieee802154/fakehard.c
32215 +++ b/drivers/ieee802154/fakehard.c
32216 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
32217 phy->transmit_power = 0xbf;
32218
32219 dev->netdev_ops = &fake_ops;
32220 - dev->ml_priv = &fake_mlme;
32221 + dev->ml_priv = (void *)&fake_mlme;
32222
32223 priv = netdev_priv(dev);
32224 priv->phy = phy;
32225 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
32226 index d67999f..4c5d083 100644
32227 --- a/drivers/infiniband/core/cm.c
32228 +++ b/drivers/infiniband/core/cm.c
32229 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
32230
32231 struct cm_counter_group {
32232 struct kobject obj;
32233 - atomic_long_t counter[CM_ATTR_COUNT];
32234 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
32235 };
32236
32237 struct cm_counter_attribute {
32238 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
32239 struct ib_mad_send_buf *msg = NULL;
32240 int ret;
32241
32242 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32243 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32244 counter[CM_REQ_COUNTER]);
32245
32246 /* Quick state check to discard duplicate REQs. */
32247 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
32248 if (!cm_id_priv)
32249 return;
32250
32251 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32252 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32253 counter[CM_REP_COUNTER]);
32254 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
32255 if (ret)
32256 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
32257 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
32258 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
32259 spin_unlock_irq(&cm_id_priv->lock);
32260 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32261 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32262 counter[CM_RTU_COUNTER]);
32263 goto out;
32264 }
32265 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
32266 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
32267 dreq_msg->local_comm_id);
32268 if (!cm_id_priv) {
32269 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32270 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32271 counter[CM_DREQ_COUNTER]);
32272 cm_issue_drep(work->port, work->mad_recv_wc);
32273 return -EINVAL;
32274 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
32275 case IB_CM_MRA_REP_RCVD:
32276 break;
32277 case IB_CM_TIMEWAIT:
32278 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32279 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32280 counter[CM_DREQ_COUNTER]);
32281 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32282 goto unlock;
32283 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
32284 cm_free_msg(msg);
32285 goto deref;
32286 case IB_CM_DREQ_RCVD:
32287 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32288 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32289 counter[CM_DREQ_COUNTER]);
32290 goto unlock;
32291 default:
32292 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
32293 ib_modify_mad(cm_id_priv->av.port->mad_agent,
32294 cm_id_priv->msg, timeout)) {
32295 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
32296 - atomic_long_inc(&work->port->
32297 + atomic_long_inc_unchecked(&work->port->
32298 counter_group[CM_RECV_DUPLICATES].
32299 counter[CM_MRA_COUNTER]);
32300 goto out;
32301 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
32302 break;
32303 case IB_CM_MRA_REQ_RCVD:
32304 case IB_CM_MRA_REP_RCVD:
32305 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32306 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32307 counter[CM_MRA_COUNTER]);
32308 /* fall through */
32309 default:
32310 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
32311 case IB_CM_LAP_IDLE:
32312 break;
32313 case IB_CM_MRA_LAP_SENT:
32314 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32315 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32316 counter[CM_LAP_COUNTER]);
32317 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32318 goto unlock;
32319 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
32320 cm_free_msg(msg);
32321 goto deref;
32322 case IB_CM_LAP_RCVD:
32323 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32324 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32325 counter[CM_LAP_COUNTER]);
32326 goto unlock;
32327 default:
32328 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
32329 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
32330 if (cur_cm_id_priv) {
32331 spin_unlock_irq(&cm.lock);
32332 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32333 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32334 counter[CM_SIDR_REQ_COUNTER]);
32335 goto out; /* Duplicate message. */
32336 }
32337 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
32338 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
32339 msg->retries = 1;
32340
32341 - atomic_long_add(1 + msg->retries,
32342 + atomic_long_add_unchecked(1 + msg->retries,
32343 &port->counter_group[CM_XMIT].counter[attr_index]);
32344 if (msg->retries)
32345 - atomic_long_add(msg->retries,
32346 + atomic_long_add_unchecked(msg->retries,
32347 &port->counter_group[CM_XMIT_RETRIES].
32348 counter[attr_index]);
32349
32350 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
32351 }
32352
32353 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
32354 - atomic_long_inc(&port->counter_group[CM_RECV].
32355 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
32356 counter[attr_id - CM_ATTR_ID_OFFSET]);
32357
32358 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
32359 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
32360 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
32361
32362 return sprintf(buf, "%ld\n",
32363 - atomic_long_read(&group->counter[cm_attr->index]));
32364 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
32365 }
32366
32367 static const struct sysfs_ops cm_counter_ops = {
32368 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
32369 index 176c8f9..2627b62 100644
32370 --- a/drivers/infiniband/core/fmr_pool.c
32371 +++ b/drivers/infiniband/core/fmr_pool.c
32372 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
32373
32374 struct task_struct *thread;
32375
32376 - atomic_t req_ser;
32377 - atomic_t flush_ser;
32378 + atomic_unchecked_t req_ser;
32379 + atomic_unchecked_t flush_ser;
32380
32381 wait_queue_head_t force_wait;
32382 };
32383 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32384 struct ib_fmr_pool *pool = pool_ptr;
32385
32386 do {
32387 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
32388 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
32389 ib_fmr_batch_release(pool);
32390
32391 - atomic_inc(&pool->flush_ser);
32392 + atomic_inc_unchecked(&pool->flush_ser);
32393 wake_up_interruptible(&pool->force_wait);
32394
32395 if (pool->flush_function)
32396 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32397 }
32398
32399 set_current_state(TASK_INTERRUPTIBLE);
32400 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32401 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32402 !kthread_should_stop())
32403 schedule();
32404 __set_current_state(TASK_RUNNING);
32405 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32406 pool->dirty_watermark = params->dirty_watermark;
32407 pool->dirty_len = 0;
32408 spin_lock_init(&pool->pool_lock);
32409 - atomic_set(&pool->req_ser, 0);
32410 - atomic_set(&pool->flush_ser, 0);
32411 + atomic_set_unchecked(&pool->req_ser, 0);
32412 + atomic_set_unchecked(&pool->flush_ser, 0);
32413 init_waitqueue_head(&pool->force_wait);
32414
32415 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32416 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32417 }
32418 spin_unlock_irq(&pool->pool_lock);
32419
32420 - serial = atomic_inc_return(&pool->req_ser);
32421 + serial = atomic_inc_return_unchecked(&pool->req_ser);
32422 wake_up_process(pool->thread);
32423
32424 if (wait_event_interruptible(pool->force_wait,
32425 - atomic_read(&pool->flush_ser) - serial >= 0))
32426 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32427 return -EINTR;
32428
32429 return 0;
32430 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32431 } else {
32432 list_add_tail(&fmr->list, &pool->dirty_list);
32433 if (++pool->dirty_len >= pool->dirty_watermark) {
32434 - atomic_inc(&pool->req_ser);
32435 + atomic_inc_unchecked(&pool->req_ser);
32436 wake_up_process(pool->thread);
32437 }
32438 }
32439 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32440 index 57e07c6..56d09d4 100644
32441 --- a/drivers/infiniband/hw/cxgb4/mem.c
32442 +++ b/drivers/infiniband/hw/cxgb4/mem.c
32443 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32444 int err;
32445 struct fw_ri_tpte tpt;
32446 u32 stag_idx;
32447 - static atomic_t key;
32448 + static atomic_unchecked_t key;
32449
32450 if (c4iw_fatal_error(rdev))
32451 return -EIO;
32452 @@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32453 if (rdev->stats.stag.cur > rdev->stats.stag.max)
32454 rdev->stats.stag.max = rdev->stats.stag.cur;
32455 mutex_unlock(&rdev->stats.lock);
32456 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32457 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32458 }
32459 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32460 __func__, stag_state, type, pdid, stag_idx);
32461 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32462 index 79b3dbc..96e5fcc 100644
32463 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
32464 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32465 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32466 struct ib_atomic_eth *ateth;
32467 struct ipath_ack_entry *e;
32468 u64 vaddr;
32469 - atomic64_t *maddr;
32470 + atomic64_unchecked_t *maddr;
32471 u64 sdata;
32472 u32 rkey;
32473 u8 next;
32474 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32475 IB_ACCESS_REMOTE_ATOMIC)))
32476 goto nack_acc_unlck;
32477 /* Perform atomic OP and save result. */
32478 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32479 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32480 sdata = be64_to_cpu(ateth->swap_data);
32481 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32482 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32483 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32484 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32485 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32486 be64_to_cpu(ateth->compare_data),
32487 sdata);
32488 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32489 index 1f95bba..9530f87 100644
32490 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32491 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32492 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32493 unsigned long flags;
32494 struct ib_wc wc;
32495 u64 sdata;
32496 - atomic64_t *maddr;
32497 + atomic64_unchecked_t *maddr;
32498 enum ib_wc_status send_status;
32499
32500 /*
32501 @@ -382,11 +382,11 @@ again:
32502 IB_ACCESS_REMOTE_ATOMIC)))
32503 goto acc_err;
32504 /* Perform atomic OP and save result. */
32505 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32506 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32507 sdata = wqe->wr.wr.atomic.compare_add;
32508 *(u64 *) sqp->s_sge.sge.vaddr =
32509 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32510 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32511 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32512 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32513 sdata, wqe->wr.wr.atomic.swap);
32514 goto send_comp;
32515 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32516 index 7140199..da60063 100644
32517 --- a/drivers/infiniband/hw/nes/nes.c
32518 +++ b/drivers/infiniband/hw/nes/nes.c
32519 @@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32520 LIST_HEAD(nes_adapter_list);
32521 static LIST_HEAD(nes_dev_list);
32522
32523 -atomic_t qps_destroyed;
32524 +atomic_unchecked_t qps_destroyed;
32525
32526 static unsigned int ee_flsh_adapter;
32527 static unsigned int sysfs_nonidx_addr;
32528 @@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32529 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32530 struct nes_adapter *nesadapter = nesdev->nesadapter;
32531
32532 - atomic_inc(&qps_destroyed);
32533 + atomic_inc_unchecked(&qps_destroyed);
32534
32535 /* Free the control structures */
32536
32537 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32538 index c438e46..ca30356 100644
32539 --- a/drivers/infiniband/hw/nes/nes.h
32540 +++ b/drivers/infiniband/hw/nes/nes.h
32541 @@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
32542 extern unsigned int wqm_quanta;
32543 extern struct list_head nes_adapter_list;
32544
32545 -extern atomic_t cm_connects;
32546 -extern atomic_t cm_accepts;
32547 -extern atomic_t cm_disconnects;
32548 -extern atomic_t cm_closes;
32549 -extern atomic_t cm_connecteds;
32550 -extern atomic_t cm_connect_reqs;
32551 -extern atomic_t cm_rejects;
32552 -extern atomic_t mod_qp_timouts;
32553 -extern atomic_t qps_created;
32554 -extern atomic_t qps_destroyed;
32555 -extern atomic_t sw_qps_destroyed;
32556 +extern atomic_unchecked_t cm_connects;
32557 +extern atomic_unchecked_t cm_accepts;
32558 +extern atomic_unchecked_t cm_disconnects;
32559 +extern atomic_unchecked_t cm_closes;
32560 +extern atomic_unchecked_t cm_connecteds;
32561 +extern atomic_unchecked_t cm_connect_reqs;
32562 +extern atomic_unchecked_t cm_rejects;
32563 +extern atomic_unchecked_t mod_qp_timouts;
32564 +extern atomic_unchecked_t qps_created;
32565 +extern atomic_unchecked_t qps_destroyed;
32566 +extern atomic_unchecked_t sw_qps_destroyed;
32567 extern u32 mh_detected;
32568 extern u32 mh_pauses_sent;
32569 extern u32 cm_packets_sent;
32570 @@ -197,16 +197,16 @@ extern u32 cm_packets_created;
32571 extern u32 cm_packets_received;
32572 extern u32 cm_packets_dropped;
32573 extern u32 cm_packets_retrans;
32574 -extern atomic_t cm_listens_created;
32575 -extern atomic_t cm_listens_destroyed;
32576 +extern atomic_unchecked_t cm_listens_created;
32577 +extern atomic_unchecked_t cm_listens_destroyed;
32578 extern u32 cm_backlog_drops;
32579 -extern atomic_t cm_loopbacks;
32580 -extern atomic_t cm_nodes_created;
32581 -extern atomic_t cm_nodes_destroyed;
32582 -extern atomic_t cm_accel_dropped_pkts;
32583 -extern atomic_t cm_resets_recvd;
32584 -extern atomic_t pau_qps_created;
32585 -extern atomic_t pau_qps_destroyed;
32586 +extern atomic_unchecked_t cm_loopbacks;
32587 +extern atomic_unchecked_t cm_nodes_created;
32588 +extern atomic_unchecked_t cm_nodes_destroyed;
32589 +extern atomic_unchecked_t cm_accel_dropped_pkts;
32590 +extern atomic_unchecked_t cm_resets_recvd;
32591 +extern atomic_unchecked_t pau_qps_created;
32592 +extern atomic_unchecked_t pau_qps_destroyed;
32593
32594 extern u32 int_mod_timer_init;
32595 extern u32 int_mod_cq_depth_256;
32596 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32597 index 020e95c..fbb3450 100644
32598 --- a/drivers/infiniband/hw/nes/nes_cm.c
32599 +++ b/drivers/infiniband/hw/nes/nes_cm.c
32600 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32601 u32 cm_packets_retrans;
32602 u32 cm_packets_created;
32603 u32 cm_packets_received;
32604 -atomic_t cm_listens_created;
32605 -atomic_t cm_listens_destroyed;
32606 +atomic_unchecked_t cm_listens_created;
32607 +atomic_unchecked_t cm_listens_destroyed;
32608 u32 cm_backlog_drops;
32609 -atomic_t cm_loopbacks;
32610 -atomic_t cm_nodes_created;
32611 -atomic_t cm_nodes_destroyed;
32612 -atomic_t cm_accel_dropped_pkts;
32613 -atomic_t cm_resets_recvd;
32614 +atomic_unchecked_t cm_loopbacks;
32615 +atomic_unchecked_t cm_nodes_created;
32616 +atomic_unchecked_t cm_nodes_destroyed;
32617 +atomic_unchecked_t cm_accel_dropped_pkts;
32618 +atomic_unchecked_t cm_resets_recvd;
32619
32620 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32621 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32622 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32623
32624 static struct nes_cm_core *g_cm_core;
32625
32626 -atomic_t cm_connects;
32627 -atomic_t cm_accepts;
32628 -atomic_t cm_disconnects;
32629 -atomic_t cm_closes;
32630 -atomic_t cm_connecteds;
32631 -atomic_t cm_connect_reqs;
32632 -atomic_t cm_rejects;
32633 +atomic_unchecked_t cm_connects;
32634 +atomic_unchecked_t cm_accepts;
32635 +atomic_unchecked_t cm_disconnects;
32636 +atomic_unchecked_t cm_closes;
32637 +atomic_unchecked_t cm_connecteds;
32638 +atomic_unchecked_t cm_connect_reqs;
32639 +atomic_unchecked_t cm_rejects;
32640
32641 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32642 {
32643 @@ -1279,7 +1279,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32644 kfree(listener);
32645 listener = NULL;
32646 ret = 0;
32647 - atomic_inc(&cm_listens_destroyed);
32648 + atomic_inc_unchecked(&cm_listens_destroyed);
32649 } else {
32650 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32651 }
32652 @@ -1482,7 +1482,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32653 cm_node->rem_mac);
32654
32655 add_hte_node(cm_core, cm_node);
32656 - atomic_inc(&cm_nodes_created);
32657 + atomic_inc_unchecked(&cm_nodes_created);
32658
32659 return cm_node;
32660 }
32661 @@ -1540,7 +1540,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32662 }
32663
32664 atomic_dec(&cm_core->node_cnt);
32665 - atomic_inc(&cm_nodes_destroyed);
32666 + atomic_inc_unchecked(&cm_nodes_destroyed);
32667 nesqp = cm_node->nesqp;
32668 if (nesqp) {
32669 nesqp->cm_node = NULL;
32670 @@ -1604,7 +1604,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32671
32672 static void drop_packet(struct sk_buff *skb)
32673 {
32674 - atomic_inc(&cm_accel_dropped_pkts);
32675 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32676 dev_kfree_skb_any(skb);
32677 }
32678
32679 @@ -1667,7 +1667,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32680 {
32681
32682 int reset = 0; /* whether to send reset in case of err.. */
32683 - atomic_inc(&cm_resets_recvd);
32684 + atomic_inc_unchecked(&cm_resets_recvd);
32685 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32686 " refcnt=%d\n", cm_node, cm_node->state,
32687 atomic_read(&cm_node->ref_count));
32688 @@ -2308,7 +2308,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32689 rem_ref_cm_node(cm_node->cm_core, cm_node);
32690 return NULL;
32691 }
32692 - atomic_inc(&cm_loopbacks);
32693 + atomic_inc_unchecked(&cm_loopbacks);
32694 loopbackremotenode->loopbackpartner = cm_node;
32695 loopbackremotenode->tcp_cntxt.rcv_wscale =
32696 NES_CM_DEFAULT_RCV_WND_SCALE;
32697 @@ -2583,7 +2583,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32698 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32699 else {
32700 rem_ref_cm_node(cm_core, cm_node);
32701 - atomic_inc(&cm_accel_dropped_pkts);
32702 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32703 dev_kfree_skb_any(skb);
32704 }
32705 break;
32706 @@ -2891,7 +2891,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32707
32708 if ((cm_id) && (cm_id->event_handler)) {
32709 if (issue_disconn) {
32710 - atomic_inc(&cm_disconnects);
32711 + atomic_inc_unchecked(&cm_disconnects);
32712 cm_event.event = IW_CM_EVENT_DISCONNECT;
32713 cm_event.status = disconn_status;
32714 cm_event.local_addr = cm_id->local_addr;
32715 @@ -2913,7 +2913,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32716 }
32717
32718 if (issue_close) {
32719 - atomic_inc(&cm_closes);
32720 + atomic_inc_unchecked(&cm_closes);
32721 nes_disconnect(nesqp, 1);
32722
32723 cm_id->provider_data = nesqp;
32724 @@ -3049,7 +3049,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32725
32726 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32727 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32728 - atomic_inc(&cm_accepts);
32729 + atomic_inc_unchecked(&cm_accepts);
32730
32731 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32732 netdev_refcnt_read(nesvnic->netdev));
32733 @@ -3251,7 +3251,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
32734 struct nes_cm_core *cm_core;
32735 u8 *start_buff;
32736
32737 - atomic_inc(&cm_rejects);
32738 + atomic_inc_unchecked(&cm_rejects);
32739 cm_node = (struct nes_cm_node *)cm_id->provider_data;
32740 loopback = cm_node->loopbackpartner;
32741 cm_core = cm_node->cm_core;
32742 @@ -3311,7 +3311,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32743 ntohl(cm_id->local_addr.sin_addr.s_addr),
32744 ntohs(cm_id->local_addr.sin_port));
32745
32746 - atomic_inc(&cm_connects);
32747 + atomic_inc_unchecked(&cm_connects);
32748 nesqp->active_conn = 1;
32749
32750 /* cache the cm_id in the qp */
32751 @@ -3421,7 +3421,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
32752 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
32753 return err;
32754 }
32755 - atomic_inc(&cm_listens_created);
32756 + atomic_inc_unchecked(&cm_listens_created);
32757 }
32758
32759 cm_id->add_ref(cm_id);
32760 @@ -3522,7 +3522,7 @@ static void cm_event_connected(struct nes_cm_event *event)
32761
32762 if (nesqp->destroyed)
32763 return;
32764 - atomic_inc(&cm_connecteds);
32765 + atomic_inc_unchecked(&cm_connecteds);
32766 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
32767 " local port 0x%04X. jiffies = %lu.\n",
32768 nesqp->hwqp.qp_id,
32769 @@ -3709,7 +3709,7 @@ static void cm_event_reset(struct nes_cm_event *event)
32770
32771 cm_id->add_ref(cm_id);
32772 ret = cm_id->event_handler(cm_id, &cm_event);
32773 - atomic_inc(&cm_closes);
32774 + atomic_inc_unchecked(&cm_closes);
32775 cm_event.event = IW_CM_EVENT_CLOSE;
32776 cm_event.status = 0;
32777 cm_event.provider_data = cm_id->provider_data;
32778 @@ -3745,7 +3745,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
32779 return;
32780 cm_id = cm_node->cm_id;
32781
32782 - atomic_inc(&cm_connect_reqs);
32783 + atomic_inc_unchecked(&cm_connect_reqs);
32784 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32785 cm_node, cm_id, jiffies);
32786
32787 @@ -3785,7 +3785,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
32788 return;
32789 cm_id = cm_node->cm_id;
32790
32791 - atomic_inc(&cm_connect_reqs);
32792 + atomic_inc_unchecked(&cm_connect_reqs);
32793 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32794 cm_node, cm_id, jiffies);
32795
32796 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
32797 index 3ba7be3..c81f6ff 100644
32798 --- a/drivers/infiniband/hw/nes/nes_mgt.c
32799 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
32800 @@ -40,8 +40,8 @@
32801 #include "nes.h"
32802 #include "nes_mgt.h"
32803
32804 -atomic_t pau_qps_created;
32805 -atomic_t pau_qps_destroyed;
32806 +atomic_unchecked_t pau_qps_created;
32807 +atomic_unchecked_t pau_qps_destroyed;
32808
32809 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
32810 {
32811 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
32812 {
32813 struct sk_buff *skb;
32814 unsigned long flags;
32815 - atomic_inc(&pau_qps_destroyed);
32816 + atomic_inc_unchecked(&pau_qps_destroyed);
32817
32818 /* Free packets that have not yet been forwarded */
32819 /* Lock is acquired by skb_dequeue when removing the skb */
32820 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
32821 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
32822 skb_queue_head_init(&nesqp->pau_list);
32823 spin_lock_init(&nesqp->pau_lock);
32824 - atomic_inc(&pau_qps_created);
32825 + atomic_inc_unchecked(&pau_qps_created);
32826 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
32827 }
32828
32829 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
32830 index f3a3ecf..57d311d 100644
32831 --- a/drivers/infiniband/hw/nes/nes_nic.c
32832 +++ b/drivers/infiniband/hw/nes/nes_nic.c
32833 @@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
32834 target_stat_values[++index] = mh_detected;
32835 target_stat_values[++index] = mh_pauses_sent;
32836 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
32837 - target_stat_values[++index] = atomic_read(&cm_connects);
32838 - target_stat_values[++index] = atomic_read(&cm_accepts);
32839 - target_stat_values[++index] = atomic_read(&cm_disconnects);
32840 - target_stat_values[++index] = atomic_read(&cm_connecteds);
32841 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
32842 - target_stat_values[++index] = atomic_read(&cm_rejects);
32843 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
32844 - target_stat_values[++index] = atomic_read(&qps_created);
32845 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
32846 - target_stat_values[++index] = atomic_read(&qps_destroyed);
32847 - target_stat_values[++index] = atomic_read(&cm_closes);
32848 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
32849 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
32850 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
32851 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
32852 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
32853 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
32854 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
32855 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
32856 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
32857 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
32858 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
32859 target_stat_values[++index] = cm_packets_sent;
32860 target_stat_values[++index] = cm_packets_bounced;
32861 target_stat_values[++index] = cm_packets_created;
32862 target_stat_values[++index] = cm_packets_received;
32863 target_stat_values[++index] = cm_packets_dropped;
32864 target_stat_values[++index] = cm_packets_retrans;
32865 - target_stat_values[++index] = atomic_read(&cm_listens_created);
32866 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
32867 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
32868 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
32869 target_stat_values[++index] = cm_backlog_drops;
32870 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
32871 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
32872 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
32873 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
32874 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
32875 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
32876 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
32877 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
32878 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
32879 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
32880 target_stat_values[++index] = nesadapter->free_4kpbl;
32881 target_stat_values[++index] = nesadapter->free_256pbl;
32882 target_stat_values[++index] = int_mod_timer_init;
32883 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
32884 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
32885 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
32886 - target_stat_values[++index] = atomic_read(&pau_qps_created);
32887 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
32888 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
32889 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
32890 }
32891
32892 /**
32893 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
32894 index 8b8812d..a5e1133 100644
32895 --- a/drivers/infiniband/hw/nes/nes_verbs.c
32896 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
32897 @@ -46,9 +46,9 @@
32898
32899 #include <rdma/ib_umem.h>
32900
32901 -atomic_t mod_qp_timouts;
32902 -atomic_t qps_created;
32903 -atomic_t sw_qps_destroyed;
32904 +atomic_unchecked_t mod_qp_timouts;
32905 +atomic_unchecked_t qps_created;
32906 +atomic_unchecked_t sw_qps_destroyed;
32907
32908 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
32909
32910 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
32911 if (init_attr->create_flags)
32912 return ERR_PTR(-EINVAL);
32913
32914 - atomic_inc(&qps_created);
32915 + atomic_inc_unchecked(&qps_created);
32916 switch (init_attr->qp_type) {
32917 case IB_QPT_RC:
32918 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
32919 @@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
32920 struct iw_cm_event cm_event;
32921 int ret = 0;
32922
32923 - atomic_inc(&sw_qps_destroyed);
32924 + atomic_inc_unchecked(&sw_qps_destroyed);
32925 nesqp->destroyed = 1;
32926
32927 /* Blow away the connection if it exists. */
32928 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
32929 index 7b1b8669..4b69f85 100644
32930 --- a/drivers/infiniband/hw/qib/qib.h
32931 +++ b/drivers/infiniband/hw/qib/qib.h
32932 @@ -51,6 +51,7 @@
32933 #include <linux/completion.h>
32934 #include <linux/kref.h>
32935 #include <linux/sched.h>
32936 +#include <linux/slab.h>
32937
32938 #include "qib_common.h"
32939 #include "qib_verbs.h"
32940 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
32941 index da739d9..da1c7f4 100644
32942 --- a/drivers/input/gameport/gameport.c
32943 +++ b/drivers/input/gameport/gameport.c
32944 @@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
32945 */
32946 static void gameport_init_port(struct gameport *gameport)
32947 {
32948 - static atomic_t gameport_no = ATOMIC_INIT(0);
32949 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
32950
32951 __module_get(THIS_MODULE);
32952
32953 mutex_init(&gameport->drv_mutex);
32954 device_initialize(&gameport->dev);
32955 dev_set_name(&gameport->dev, "gameport%lu",
32956 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
32957 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
32958 gameport->dev.bus = &gameport_bus;
32959 gameport->dev.release = gameport_release_port;
32960 if (gameport->parent)
32961 diff --git a/drivers/input/input.c b/drivers/input/input.c
32962 index 8921c61..f5cd63d 100644
32963 --- a/drivers/input/input.c
32964 +++ b/drivers/input/input.c
32965 @@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
32966 */
32967 int input_register_device(struct input_dev *dev)
32968 {
32969 - static atomic_t input_no = ATOMIC_INIT(0);
32970 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
32971 struct input_handler *handler;
32972 const char *path;
32973 int error;
32974 @@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
32975 dev->setkeycode = input_default_setkeycode;
32976
32977 dev_set_name(&dev->dev, "input%ld",
32978 - (unsigned long) atomic_inc_return(&input_no) - 1);
32979 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
32980
32981 error = device_add(&dev->dev);
32982 if (error)
32983 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
32984 index 04c69af..5f92d00 100644
32985 --- a/drivers/input/joystick/sidewinder.c
32986 +++ b/drivers/input/joystick/sidewinder.c
32987 @@ -30,6 +30,7 @@
32988 #include <linux/kernel.h>
32989 #include <linux/module.h>
32990 #include <linux/slab.h>
32991 +#include <linux/sched.h>
32992 #include <linux/init.h>
32993 #include <linux/input.h>
32994 #include <linux/gameport.h>
32995 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
32996 index 83811e4..0822b90 100644
32997 --- a/drivers/input/joystick/xpad.c
32998 +++ b/drivers/input/joystick/xpad.c
32999 @@ -726,7 +726,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
33000
33001 static int xpad_led_probe(struct usb_xpad *xpad)
33002 {
33003 - static atomic_t led_seq = ATOMIC_INIT(0);
33004 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
33005 long led_no;
33006 struct xpad_led *led;
33007 struct led_classdev *led_cdev;
33008 @@ -739,7 +739,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
33009 if (!led)
33010 return -ENOMEM;
33011
33012 - led_no = (long)atomic_inc_return(&led_seq) - 1;
33013 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
33014
33015 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
33016 led->xpad = xpad;
33017 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
33018 index 0110b5a..d3ad144 100644
33019 --- a/drivers/input/mousedev.c
33020 +++ b/drivers/input/mousedev.c
33021 @@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
33022
33023 spin_unlock_irq(&client->packet_lock);
33024
33025 - if (copy_to_user(buffer, data, count))
33026 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
33027 return -EFAULT;
33028
33029 return count;
33030 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
33031 index d0f7533..fb8215b 100644
33032 --- a/drivers/input/serio/serio.c
33033 +++ b/drivers/input/serio/serio.c
33034 @@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
33035 */
33036 static void serio_init_port(struct serio *serio)
33037 {
33038 - static atomic_t serio_no = ATOMIC_INIT(0);
33039 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
33040
33041 __module_get(THIS_MODULE);
33042
33043 @@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
33044 mutex_init(&serio->drv_mutex);
33045 device_initialize(&serio->dev);
33046 dev_set_name(&serio->dev, "serio%ld",
33047 - (long)atomic_inc_return(&serio_no) - 1);
33048 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
33049 serio->dev.bus = &serio_bus;
33050 serio->dev.release = serio_release_port;
33051 serio->dev.groups = serio_device_attr_groups;
33052 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
33053 index 38c4bd8..58965d9 100644
33054 --- a/drivers/isdn/capi/capi.c
33055 +++ b/drivers/isdn/capi/capi.c
33056 @@ -83,8 +83,8 @@ struct capiminor {
33057
33058 struct capi20_appl *ap;
33059 u32 ncci;
33060 - atomic_t datahandle;
33061 - atomic_t msgid;
33062 + atomic_unchecked_t datahandle;
33063 + atomic_unchecked_t msgid;
33064
33065 struct tty_port port;
33066 int ttyinstop;
33067 @@ -392,7 +392,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
33068 capimsg_setu16(s, 2, mp->ap->applid);
33069 capimsg_setu8 (s, 4, CAPI_DATA_B3);
33070 capimsg_setu8 (s, 5, CAPI_RESP);
33071 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
33072 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
33073 capimsg_setu32(s, 8, mp->ncci);
33074 capimsg_setu16(s, 12, datahandle);
33075 }
33076 @@ -513,14 +513,14 @@ static void handle_minor_send(struct capiminor *mp)
33077 mp->outbytes -= len;
33078 spin_unlock_bh(&mp->outlock);
33079
33080 - datahandle = atomic_inc_return(&mp->datahandle);
33081 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
33082 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
33083 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
33084 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
33085 capimsg_setu16(skb->data, 2, mp->ap->applid);
33086 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
33087 capimsg_setu8 (skb->data, 5, CAPI_REQ);
33088 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
33089 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
33090 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
33091 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
33092 capimsg_setu16(skb->data, 16, len); /* Data length */
33093 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
33094 index a6d9fd2..afdb8a3 100644
33095 --- a/drivers/isdn/gigaset/interface.c
33096 +++ b/drivers/isdn/gigaset/interface.c
33097 @@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
33098 }
33099 tty->driver_data = cs;
33100
33101 - ++cs->port.count;
33102 + atomic_inc(&cs->port.count);
33103
33104 - if (cs->port.count == 1) {
33105 + if (atomic_read(&cs->port.count) == 1) {
33106 tty_port_tty_set(&cs->port, tty);
33107 tty->low_latency = 1;
33108 }
33109 @@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
33110
33111 if (!cs->connected)
33112 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
33113 - else if (!cs->port.count)
33114 + else if (!atomic_read(&cs->port.count))
33115 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33116 - else if (!--cs->port.count)
33117 + else if (!atomic_dec_return(&cs->port.count))
33118 tty_port_tty_set(&cs->port, NULL);
33119
33120 mutex_unlock(&cs->mutex);
33121 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
33122 index 821f7ac..28d4030 100644
33123 --- a/drivers/isdn/hardware/avm/b1.c
33124 +++ b/drivers/isdn/hardware/avm/b1.c
33125 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
33126 }
33127 if (left) {
33128 if (t4file->user) {
33129 - if (copy_from_user(buf, dp, left))
33130 + if (left > sizeof buf || copy_from_user(buf, dp, left))
33131 return -EFAULT;
33132 } else {
33133 memcpy(buf, dp, left);
33134 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
33135 }
33136 if (left) {
33137 if (config->user) {
33138 - if (copy_from_user(buf, dp, left))
33139 + if (left > sizeof buf || copy_from_user(buf, dp, left))
33140 return -EFAULT;
33141 } else {
33142 memcpy(buf, dp, left);
33143 diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
33144 index dd6b53a..19d9ee6 100644
33145 --- a/drivers/isdn/hardware/eicon/divasync.h
33146 +++ b/drivers/isdn/hardware/eicon/divasync.h
33147 @@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
33148 } diva_didd_add_adapter_t;
33149 typedef struct _diva_didd_remove_adapter {
33150 IDI_CALL p_request;
33151 -} diva_didd_remove_adapter_t;
33152 +} __no_const diva_didd_remove_adapter_t;
33153 typedef struct _diva_didd_read_adapter_array {
33154 void *buffer;
33155 dword length;
33156 diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
33157 index d303e65..28bcb7b 100644
33158 --- a/drivers/isdn/hardware/eicon/xdi_adapter.h
33159 +++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
33160 @@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
33161 typedef struct _diva_os_idi_adapter_interface {
33162 diva_init_card_proc_t cleanup_adapter_proc;
33163 diva_cmd_card_proc_t cmd_proc;
33164 -} diva_os_idi_adapter_interface_t;
33165 +} __no_const diva_os_idi_adapter_interface_t;
33166
33167 typedef struct _diva_os_xdi_adapter {
33168 struct list_head link;
33169 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
33170 index 7bc5067..fd36232 100644
33171 --- a/drivers/isdn/i4l/isdn_tty.c
33172 +++ b/drivers/isdn/i4l/isdn_tty.c
33173 @@ -1505,9 +1505,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
33174 port = &info->port;
33175 #ifdef ISDN_DEBUG_MODEM_OPEN
33176 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
33177 - port->count);
33178 + atomic_read(&port->count))
33179 #endif
33180 - port->count++;
33181 + atomic_inc(&port->count);
33182 tty->driver_data = info;
33183 port->tty = tty;
33184 tty->port = port;
33185 @@ -1553,7 +1553,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
33186 #endif
33187 return;
33188 }
33189 - if ((tty->count == 1) && (port->count != 1)) {
33190 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
33191 /*
33192 * Uh, oh. tty->count is 1, which means that the tty
33193 * structure will be freed. Info->count should always
33194 @@ -1562,15 +1562,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
33195 * serial port won't be shutdown.
33196 */
33197 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
33198 - "info->count is %d\n", port->count);
33199 - port->count = 1;
33200 + "info->count is %d\n", atomic_read(&port->count));
33201 + atomic_set(&port->count, 1);
33202 }
33203 - if (--port->count < 0) {
33204 + if (atomic_dec_return(&port->count) < 0) {
33205 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
33206 - info->line, port->count);
33207 - port->count = 0;
33208 + info->line, atomic_read(&port->count));
33209 + atomic_set(&port->count, 0);
33210 }
33211 - if (port->count) {
33212 + if (atomic_read(&port->count)) {
33213 #ifdef ISDN_DEBUG_MODEM_OPEN
33214 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
33215 #endif
33216 @@ -1624,7 +1624,7 @@ isdn_tty_hangup(struct tty_struct *tty)
33217 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
33218 return;
33219 isdn_tty_shutdown(info);
33220 - port->count = 0;
33221 + atomic_set(&port->count, 0);
33222 port->flags &= ~ASYNC_NORMAL_ACTIVE;
33223 port->tty = NULL;
33224 wake_up_interruptible(&port->open_wait);
33225 @@ -1964,7 +1964,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
33226 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
33227 modem_info *info = &dev->mdm.info[i];
33228
33229 - if (info->port.count == 0)
33230 + if (atomic_read(&info->port.count) == 0)
33231 continue;
33232 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
33233 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
33234 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
33235 index e74df7c..03a03ba 100644
33236 --- a/drivers/isdn/icn/icn.c
33237 +++ b/drivers/isdn/icn/icn.c
33238 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
33239 if (count > len)
33240 count = len;
33241 if (user) {
33242 - if (copy_from_user(msg, buf, count))
33243 + if (count > sizeof msg || copy_from_user(msg, buf, count))
33244 return -EFAULT;
33245 } else
33246 memcpy(msg, buf, count);
33247 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
33248 index b5fdcb7..5b6c59f 100644
33249 --- a/drivers/lguest/core.c
33250 +++ b/drivers/lguest/core.c
33251 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
33252 * it's worked so far. The end address needs +1 because __get_vm_area
33253 * allocates an extra guard page, so we need space for that.
33254 */
33255 +
33256 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
33257 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33258 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
33259 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33260 +#else
33261 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33262 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
33263 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33264 +#endif
33265 +
33266 if (!switcher_vma) {
33267 err = -ENOMEM;
33268 printk("lguest: could not map switcher pages high\n");
33269 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
33270 * Now the Switcher is mapped at the right address, we can't fail!
33271 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
33272 */
33273 - memcpy(switcher_vma->addr, start_switcher_text,
33274 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
33275 end_switcher_text - start_switcher_text);
33276
33277 printk(KERN_INFO "lguest: mapped switcher at %p\n",
33278 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
33279 index 39809035..ce25c5e 100644
33280 --- a/drivers/lguest/x86/core.c
33281 +++ b/drivers/lguest/x86/core.c
33282 @@ -59,7 +59,7 @@ static struct {
33283 /* Offset from where switcher.S was compiled to where we've copied it */
33284 static unsigned long switcher_offset(void)
33285 {
33286 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
33287 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
33288 }
33289
33290 /* This cpu's struct lguest_pages. */
33291 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
33292 * These copies are pretty cheap, so we do them unconditionally: */
33293 /* Save the current Host top-level page directory.
33294 */
33295 +
33296 +#ifdef CONFIG_PAX_PER_CPU_PGD
33297 + pages->state.host_cr3 = read_cr3();
33298 +#else
33299 pages->state.host_cr3 = __pa(current->mm->pgd);
33300 +#endif
33301 +
33302 /*
33303 * Set up the Guest's page tables to see this CPU's pages (and no
33304 * other CPU's pages).
33305 @@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
33306 * compiled-in switcher code and the high-mapped copy we just made.
33307 */
33308 for (i = 0; i < IDT_ENTRIES; i++)
33309 - default_idt_entries[i] += switcher_offset();
33310 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
33311
33312 /*
33313 * Set up the Switcher's per-cpu areas.
33314 @@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
33315 * it will be undisturbed when we switch. To change %cs and jump we
33316 * need this structure to feed to Intel's "lcall" instruction.
33317 */
33318 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
33319 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
33320 lguest_entry.segment = LGUEST_CS;
33321
33322 /*
33323 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
33324 index 40634b0..4f5855e 100644
33325 --- a/drivers/lguest/x86/switcher_32.S
33326 +++ b/drivers/lguest/x86/switcher_32.S
33327 @@ -87,6 +87,7 @@
33328 #include <asm/page.h>
33329 #include <asm/segment.h>
33330 #include <asm/lguest.h>
33331 +#include <asm/processor-flags.h>
33332
33333 // We mark the start of the code to copy
33334 // It's placed in .text tho it's never run here
33335 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
33336 // Changes type when we load it: damn Intel!
33337 // For after we switch over our page tables
33338 // That entry will be read-only: we'd crash.
33339 +
33340 +#ifdef CONFIG_PAX_KERNEXEC
33341 + mov %cr0, %edx
33342 + xor $X86_CR0_WP, %edx
33343 + mov %edx, %cr0
33344 +#endif
33345 +
33346 movl $(GDT_ENTRY_TSS*8), %edx
33347 ltr %dx
33348
33349 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
33350 // Let's clear it again for our return.
33351 // The GDT descriptor of the Host
33352 // Points to the table after two "size" bytes
33353 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33354 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33355 // Clear "used" from type field (byte 5, bit 2)
33356 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33357 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33358 +
33359 +#ifdef CONFIG_PAX_KERNEXEC
33360 + mov %cr0, %eax
33361 + xor $X86_CR0_WP, %eax
33362 + mov %eax, %cr0
33363 +#endif
33364
33365 // Once our page table's switched, the Guest is live!
33366 // The Host fades as we run this final step.
33367 @@ -295,13 +309,12 @@ deliver_to_host:
33368 // I consulted gcc, and it gave
33369 // These instructions, which I gladly credit:
33370 leal (%edx,%ebx,8), %eax
33371 - movzwl (%eax),%edx
33372 - movl 4(%eax), %eax
33373 - xorw %ax, %ax
33374 - orl %eax, %edx
33375 + movl 4(%eax), %edx
33376 + movw (%eax), %dx
33377 // Now the address of the handler's in %edx
33378 // We call it now: its "iret" drops us home.
33379 - jmp *%edx
33380 + ljmp $__KERNEL_CS, $1f
33381 +1: jmp *%edx
33382
33383 // Every interrupt can come to us here
33384 // But we must truly tell each apart.
33385 diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
33386 index 20e5c2c..9e849a9 100644
33387 --- a/drivers/macintosh/macio_asic.c
33388 +++ b/drivers/macintosh/macio_asic.c
33389 @@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
33390 * MacIO is matched against any Apple ID, it's probe() function
33391 * will then decide wether it applies or not
33392 */
33393 -static const struct pci_device_id __devinitdata pci_ids [] = { {
33394 +static const struct pci_device_id __devinitconst pci_ids [] = { {
33395 .vendor = PCI_VENDOR_ID_APPLE,
33396 .device = PCI_ANY_ID,
33397 .subvendor = PCI_ANY_ID,
33398 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
33399 index 94e7f6b..2f4a0d8 100644
33400 --- a/drivers/md/bitmap.c
33401 +++ b/drivers/md/bitmap.c
33402 @@ -1786,7 +1786,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
33403 chunk_kb ? "KB" : "B");
33404 if (bitmap->storage.file) {
33405 seq_printf(seq, ", file: ");
33406 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
33407 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
33408 }
33409
33410 seq_printf(seq, "\n");
33411 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33412 index afd9598..528d8f9 100644
33413 --- a/drivers/md/dm-ioctl.c
33414 +++ b/drivers/md/dm-ioctl.c
33415 @@ -1593,7 +1593,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33416 cmd == DM_LIST_VERSIONS_CMD)
33417 return 0;
33418
33419 - if ((cmd == DM_DEV_CREATE_CMD)) {
33420 + if (cmd == DM_DEV_CREATE_CMD) {
33421 if (!*param->name) {
33422 DMWARN("name not supplied when creating device");
33423 return -EINVAL;
33424 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33425 index bc5ddba8..b961159 100644
33426 --- a/drivers/md/dm-raid1.c
33427 +++ b/drivers/md/dm-raid1.c
33428 @@ -40,7 +40,7 @@ enum dm_raid1_error {
33429
33430 struct mirror {
33431 struct mirror_set *ms;
33432 - atomic_t error_count;
33433 + atomic_unchecked_t error_count;
33434 unsigned long error_type;
33435 struct dm_dev *dev;
33436 sector_t offset;
33437 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33438 struct mirror *m;
33439
33440 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33441 - if (!atomic_read(&m->error_count))
33442 + if (!atomic_read_unchecked(&m->error_count))
33443 return m;
33444
33445 return NULL;
33446 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33447 * simple way to tell if a device has encountered
33448 * errors.
33449 */
33450 - atomic_inc(&m->error_count);
33451 + atomic_inc_unchecked(&m->error_count);
33452
33453 if (test_and_set_bit(error_type, &m->error_type))
33454 return;
33455 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33456 struct mirror *m = get_default_mirror(ms);
33457
33458 do {
33459 - if (likely(!atomic_read(&m->error_count)))
33460 + if (likely(!atomic_read_unchecked(&m->error_count)))
33461 return m;
33462
33463 if (m-- == ms->mirror)
33464 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33465 {
33466 struct mirror *default_mirror = get_default_mirror(m->ms);
33467
33468 - return !atomic_read(&default_mirror->error_count);
33469 + return !atomic_read_unchecked(&default_mirror->error_count);
33470 }
33471
33472 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33473 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33474 */
33475 if (likely(region_in_sync(ms, region, 1)))
33476 m = choose_mirror(ms, bio->bi_sector);
33477 - else if (m && atomic_read(&m->error_count))
33478 + else if (m && atomic_read_unchecked(&m->error_count))
33479 m = NULL;
33480
33481 if (likely(m))
33482 @@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33483 }
33484
33485 ms->mirror[mirror].ms = ms;
33486 - atomic_set(&(ms->mirror[mirror].error_count), 0);
33487 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33488 ms->mirror[mirror].error_type = 0;
33489 ms->mirror[mirror].offset = offset;
33490
33491 @@ -1356,7 +1356,7 @@ static void mirror_resume(struct dm_target *ti)
33492 */
33493 static char device_status_char(struct mirror *m)
33494 {
33495 - if (!atomic_read(&(m->error_count)))
33496 + if (!atomic_read_unchecked(&(m->error_count)))
33497 return 'A';
33498
33499 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33500 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33501 index a087bf2..4c94786 100644
33502 --- a/drivers/md/dm-stripe.c
33503 +++ b/drivers/md/dm-stripe.c
33504 @@ -20,7 +20,7 @@ struct stripe {
33505 struct dm_dev *dev;
33506 sector_t physical_start;
33507
33508 - atomic_t error_count;
33509 + atomic_unchecked_t error_count;
33510 };
33511
33512 struct stripe_c {
33513 @@ -183,7 +183,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33514 kfree(sc);
33515 return r;
33516 }
33517 - atomic_set(&(sc->stripe[i].error_count), 0);
33518 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33519 }
33520
33521 ti->private = sc;
33522 @@ -324,7 +324,7 @@ static int stripe_status(struct dm_target *ti, status_type_t type,
33523 DMEMIT("%d ", sc->stripes);
33524 for (i = 0; i < sc->stripes; i++) {
33525 DMEMIT("%s ", sc->stripe[i].dev->name);
33526 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33527 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33528 'D' : 'A';
33529 }
33530 buffer[i] = '\0';
33531 @@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33532 */
33533 for (i = 0; i < sc->stripes; i++)
33534 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33535 - atomic_inc(&(sc->stripe[i].error_count));
33536 - if (atomic_read(&(sc->stripe[i].error_count)) <
33537 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
33538 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33539 DM_IO_ERROR_THRESHOLD)
33540 schedule_work(&sc->trigger_event);
33541 }
33542 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33543 index 100368e..64262ce 100644
33544 --- a/drivers/md/dm-table.c
33545 +++ b/drivers/md/dm-table.c
33546 @@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33547 if (!dev_size)
33548 return 0;
33549
33550 - if ((start >= dev_size) || (start + len > dev_size)) {
33551 + if ((start >= dev_size) || (len > dev_size - start)) {
33552 DMWARN("%s: %s too small for target: "
33553 "start=%llu, len=%llu, dev_size=%llu",
33554 dm_device_name(ti->table->md), bdevname(bdev, b),
33555 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33556 index 693e149..b7e0fde 100644
33557 --- a/drivers/md/dm-thin-metadata.c
33558 +++ b/drivers/md/dm-thin-metadata.c
33559 @@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
33560 {
33561 pmd->info.tm = pmd->tm;
33562 pmd->info.levels = 2;
33563 - pmd->info.value_type.context = pmd->data_sm;
33564 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33565 pmd->info.value_type.size = sizeof(__le64);
33566 pmd->info.value_type.inc = data_block_inc;
33567 pmd->info.value_type.dec = data_block_dec;
33568 @@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
33569
33570 pmd->bl_info.tm = pmd->tm;
33571 pmd->bl_info.levels = 1;
33572 - pmd->bl_info.value_type.context = pmd->data_sm;
33573 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33574 pmd->bl_info.value_type.size = sizeof(__le64);
33575 pmd->bl_info.value_type.inc = data_block_inc;
33576 pmd->bl_info.value_type.dec = data_block_dec;
33577 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33578 index 67ffa39..cb3b1dd 100644
33579 --- a/drivers/md/dm.c
33580 +++ b/drivers/md/dm.c
33581 @@ -176,9 +176,9 @@ struct mapped_device {
33582 /*
33583 * Event handling.
33584 */
33585 - atomic_t event_nr;
33586 + atomic_unchecked_t event_nr;
33587 wait_queue_head_t eventq;
33588 - atomic_t uevent_seq;
33589 + atomic_unchecked_t uevent_seq;
33590 struct list_head uevent_list;
33591 spinlock_t uevent_lock; /* Protect access to uevent_list */
33592
33593 @@ -1887,8 +1887,8 @@ static struct mapped_device *alloc_dev(int minor)
33594 rwlock_init(&md->map_lock);
33595 atomic_set(&md->holders, 1);
33596 atomic_set(&md->open_count, 0);
33597 - atomic_set(&md->event_nr, 0);
33598 - atomic_set(&md->uevent_seq, 0);
33599 + atomic_set_unchecked(&md->event_nr, 0);
33600 + atomic_set_unchecked(&md->uevent_seq, 0);
33601 INIT_LIST_HEAD(&md->uevent_list);
33602 spin_lock_init(&md->uevent_lock);
33603
33604 @@ -2022,7 +2022,7 @@ static void event_callback(void *context)
33605
33606 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33607
33608 - atomic_inc(&md->event_nr);
33609 + atomic_inc_unchecked(&md->event_nr);
33610 wake_up(&md->eventq);
33611 }
33612
33613 @@ -2677,18 +2677,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33614
33615 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33616 {
33617 - return atomic_add_return(1, &md->uevent_seq);
33618 + return atomic_add_return_unchecked(1, &md->uevent_seq);
33619 }
33620
33621 uint32_t dm_get_event_nr(struct mapped_device *md)
33622 {
33623 - return atomic_read(&md->event_nr);
33624 + return atomic_read_unchecked(&md->event_nr);
33625 }
33626
33627 int dm_wait_event(struct mapped_device *md, int event_nr)
33628 {
33629 return wait_event_interruptible(md->eventq,
33630 - (event_nr != atomic_read(&md->event_nr)));
33631 + (event_nr != atomic_read_unchecked(&md->event_nr)));
33632 }
33633
33634 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33635 diff --git a/drivers/md/md.c b/drivers/md/md.c
33636 index 308e87b..7f365d6 100644
33637 --- a/drivers/md/md.c
33638 +++ b/drivers/md/md.c
33639 @@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33640 * start build, activate spare
33641 */
33642 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33643 -static atomic_t md_event_count;
33644 +static atomic_unchecked_t md_event_count;
33645 void md_new_event(struct mddev *mddev)
33646 {
33647 - atomic_inc(&md_event_count);
33648 + atomic_inc_unchecked(&md_event_count);
33649 wake_up(&md_event_waiters);
33650 }
33651 EXPORT_SYMBOL_GPL(md_new_event);
33652 @@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33653 */
33654 static void md_new_event_inintr(struct mddev *mddev)
33655 {
33656 - atomic_inc(&md_event_count);
33657 + atomic_inc_unchecked(&md_event_count);
33658 wake_up(&md_event_waiters);
33659 }
33660
33661 @@ -1519,7 +1519,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33662 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
33663 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
33664 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
33665 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33666 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33667
33668 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33669 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33670 @@ -1763,7 +1763,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33671 else
33672 sb->resync_offset = cpu_to_le64(0);
33673
33674 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33675 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33676
33677 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33678 sb->size = cpu_to_le64(mddev->dev_sectors);
33679 @@ -2757,7 +2757,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33680 static ssize_t
33681 errors_show(struct md_rdev *rdev, char *page)
33682 {
33683 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33684 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33685 }
33686
33687 static ssize_t
33688 @@ -2766,7 +2766,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33689 char *e;
33690 unsigned long n = simple_strtoul(buf, &e, 10);
33691 if (*buf && (*e == 0 || *e == '\n')) {
33692 - atomic_set(&rdev->corrected_errors, n);
33693 + atomic_set_unchecked(&rdev->corrected_errors, n);
33694 return len;
33695 }
33696 return -EINVAL;
33697 @@ -3213,8 +3213,8 @@ int md_rdev_init(struct md_rdev *rdev)
33698 rdev->sb_loaded = 0;
33699 rdev->bb_page = NULL;
33700 atomic_set(&rdev->nr_pending, 0);
33701 - atomic_set(&rdev->read_errors, 0);
33702 - atomic_set(&rdev->corrected_errors, 0);
33703 + atomic_set_unchecked(&rdev->read_errors, 0);
33704 + atomic_set_unchecked(&rdev->corrected_errors, 0);
33705
33706 INIT_LIST_HEAD(&rdev->same_set);
33707 init_waitqueue_head(&rdev->blocked_wait);
33708 @@ -6947,7 +6947,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33709
33710 spin_unlock(&pers_lock);
33711 seq_printf(seq, "\n");
33712 - seq->poll_event = atomic_read(&md_event_count);
33713 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33714 return 0;
33715 }
33716 if (v == (void*)2) {
33717 @@ -7050,7 +7050,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33718 return error;
33719
33720 seq = file->private_data;
33721 - seq->poll_event = atomic_read(&md_event_count);
33722 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33723 return error;
33724 }
33725
33726 @@ -7064,7 +7064,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33727 /* always allow read */
33728 mask = POLLIN | POLLRDNORM;
33729
33730 - if (seq->poll_event != atomic_read(&md_event_count))
33731 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
33732 mask |= POLLERR | POLLPRI;
33733 return mask;
33734 }
33735 @@ -7108,7 +7108,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
33736 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33737 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33738 (int)part_stat_read(&disk->part0, sectors[1]) -
33739 - atomic_read(&disk->sync_io);
33740 + atomic_read_unchecked(&disk->sync_io);
33741 /* sync IO will cause sync_io to increase before the disk_stats
33742 * as sync_io is counted when a request starts, and
33743 * disk_stats is counted when it completes.
33744 diff --git a/drivers/md/md.h b/drivers/md/md.h
33745 index f385b03..b600be8 100644
33746 --- a/drivers/md/md.h
33747 +++ b/drivers/md/md.h
33748 @@ -94,13 +94,13 @@ struct md_rdev {
33749 * only maintained for arrays that
33750 * support hot removal
33751 */
33752 - atomic_t read_errors; /* number of consecutive read errors that
33753 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
33754 * we have tried to ignore.
33755 */
33756 struct timespec last_read_error; /* monotonic time since our
33757 * last read error
33758 */
33759 - atomic_t corrected_errors; /* number of corrected read errors,
33760 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
33761 * for reporting to userspace and storing
33762 * in superblock.
33763 */
33764 @@ -432,7 +432,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
33765
33766 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
33767 {
33768 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33769 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33770 }
33771
33772 struct md_personality
33773 diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
33774 index f6d29e6..7917f5e 100644
33775 --- a/drivers/md/persistent-data/dm-space-map-disk.c
33776 +++ b/drivers/md/persistent-data/dm-space-map-disk.c
33777 @@ -22,7 +22,7 @@
33778 * Space map interface.
33779 */
33780 struct sm_disk {
33781 - struct dm_space_map sm;
33782 + dm_space_map_no_const sm;
33783
33784 struct ll_disk ll;
33785 struct ll_disk old_ll;
33786 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
33787 index e89ae5e..062e4c2 100644
33788 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
33789 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
33790 @@ -43,7 +43,7 @@ struct block_op {
33791 };
33792
33793 struct sm_metadata {
33794 - struct dm_space_map sm;
33795 + dm_space_map_no_const sm;
33796
33797 struct ll_disk ll;
33798 struct ll_disk old_ll;
33799 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
33800 index 1cbfc6b..56e1dbb 100644
33801 --- a/drivers/md/persistent-data/dm-space-map.h
33802 +++ b/drivers/md/persistent-data/dm-space-map.h
33803 @@ -60,6 +60,7 @@ struct dm_space_map {
33804 int (*root_size)(struct dm_space_map *sm, size_t *result);
33805 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
33806 };
33807 +typedef struct dm_space_map __no_const dm_space_map_no_const;
33808
33809 /*----------------------------------------------------------------*/
33810
33811 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
33812 index 05bb49e..84d7ce6 100644
33813 --- a/drivers/md/raid1.c
33814 +++ b/drivers/md/raid1.c
33815 @@ -1810,7 +1810,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
33816 if (r1_sync_page_io(rdev, sect, s,
33817 bio->bi_io_vec[idx].bv_page,
33818 READ) != 0)
33819 - atomic_add(s, &rdev->corrected_errors);
33820 + atomic_add_unchecked(s, &rdev->corrected_errors);
33821 }
33822 sectors -= s;
33823 sect += s;
33824 @@ -2032,7 +2032,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
33825 test_bit(In_sync, &rdev->flags)) {
33826 if (r1_sync_page_io(rdev, sect, s,
33827 conf->tmppage, READ)) {
33828 - atomic_add(s, &rdev->corrected_errors);
33829 + atomic_add_unchecked(s, &rdev->corrected_errors);
33830 printk(KERN_INFO
33831 "md/raid1:%s: read error corrected "
33832 "(%d sectors at %llu on %s)\n",
33833 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
33834 index a48c215..6bda6f4 100644
33835 --- a/drivers/md/raid10.c
33836 +++ b/drivers/md/raid10.c
33837 @@ -1810,7 +1810,7 @@ static void end_sync_read(struct bio *bio, int error)
33838 /* The write handler will notice the lack of
33839 * R10BIO_Uptodate and record any errors etc
33840 */
33841 - atomic_add(r10_bio->sectors,
33842 + atomic_add_unchecked(r10_bio->sectors,
33843 &conf->mirrors[d].rdev->corrected_errors);
33844
33845 /* for reconstruct, we always reschedule after a read.
33846 @@ -2159,7 +2159,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33847 {
33848 struct timespec cur_time_mon;
33849 unsigned long hours_since_last;
33850 - unsigned int read_errors = atomic_read(&rdev->read_errors);
33851 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
33852
33853 ktime_get_ts(&cur_time_mon);
33854
33855 @@ -2181,9 +2181,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33856 * overflowing the shift of read_errors by hours_since_last.
33857 */
33858 if (hours_since_last >= 8 * sizeof(read_errors))
33859 - atomic_set(&rdev->read_errors, 0);
33860 + atomic_set_unchecked(&rdev->read_errors, 0);
33861 else
33862 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
33863 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
33864 }
33865
33866 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
33867 @@ -2237,8 +2237,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33868 return;
33869
33870 check_decay_read_errors(mddev, rdev);
33871 - atomic_inc(&rdev->read_errors);
33872 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
33873 + atomic_inc_unchecked(&rdev->read_errors);
33874 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
33875 char b[BDEVNAME_SIZE];
33876 bdevname(rdev->bdev, b);
33877
33878 @@ -2246,7 +2246,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33879 "md/raid10:%s: %s: Raid device exceeded "
33880 "read_error threshold [cur %d:max %d]\n",
33881 mdname(mddev), b,
33882 - atomic_read(&rdev->read_errors), max_read_errors);
33883 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
33884 printk(KERN_NOTICE
33885 "md/raid10:%s: %s: Failing raid device\n",
33886 mdname(mddev), b);
33887 @@ -2401,7 +2401,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33888 sect +
33889 choose_data_offset(r10_bio, rdev)),
33890 bdevname(rdev->bdev, b));
33891 - atomic_add(s, &rdev->corrected_errors);
33892 + atomic_add_unchecked(s, &rdev->corrected_errors);
33893 }
33894
33895 rdev_dec_pending(rdev, mddev);
33896 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
33897 index 0689173..35df76c 100644
33898 --- a/drivers/md/raid5.c
33899 +++ b/drivers/md/raid5.c
33900 @@ -1756,21 +1756,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
33901 mdname(conf->mddev), STRIPE_SECTORS,
33902 (unsigned long long)s,
33903 bdevname(rdev->bdev, b));
33904 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
33905 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
33906 clear_bit(R5_ReadError, &sh->dev[i].flags);
33907 clear_bit(R5_ReWrite, &sh->dev[i].flags);
33908 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
33909 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
33910
33911 - if (atomic_read(&rdev->read_errors))
33912 - atomic_set(&rdev->read_errors, 0);
33913 + if (atomic_read_unchecked(&rdev->read_errors))
33914 + atomic_set_unchecked(&rdev->read_errors, 0);
33915 } else {
33916 const char *bdn = bdevname(rdev->bdev, b);
33917 int retry = 0;
33918 int set_bad = 0;
33919
33920 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
33921 - atomic_inc(&rdev->read_errors);
33922 + atomic_inc_unchecked(&rdev->read_errors);
33923 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
33924 printk_ratelimited(
33925 KERN_WARNING
33926 @@ -1798,7 +1798,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
33927 mdname(conf->mddev),
33928 (unsigned long long)s,
33929 bdn);
33930 - } else if (atomic_read(&rdev->read_errors)
33931 + } else if (atomic_read_unchecked(&rdev->read_errors)
33932 > conf->max_nr_stripes)
33933 printk(KERN_WARNING
33934 "md/raid:%s: Too many read errors, failing device %s.\n",
33935 diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
33936 index ebf3f05..b1f3e77 100644
33937 --- a/drivers/media/dvb/ddbridge/ddbridge-core.c
33938 +++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
33939 @@ -1679,7 +1679,7 @@ static struct ddb_info ddb_v6 = {
33940 .subvendor = _subvend, .subdevice = _subdev, \
33941 .driver_data = (unsigned long)&_driverdata }
33942
33943 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
33944 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
33945 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
33946 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
33947 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
33948 diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
33949 index fa7188a..04a045e 100644
33950 --- a/drivers/media/dvb/dvb-core/dvb_demux.h
33951 +++ b/drivers/media/dvb/dvb-core/dvb_demux.h
33952 @@ -73,7 +73,7 @@ struct dvb_demux_feed {
33953 union {
33954 dmx_ts_cb ts;
33955 dmx_section_cb sec;
33956 - } cb;
33957 + } __no_const cb;
33958
33959 struct dvb_demux *demux;
33960 void *priv;
33961 diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
33962 index 39eab73..60033e7 100644
33963 --- a/drivers/media/dvb/dvb-core/dvbdev.c
33964 +++ b/drivers/media/dvb/dvb-core/dvbdev.c
33965 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
33966 const struct dvb_device *template, void *priv, int type)
33967 {
33968 struct dvb_device *dvbdev;
33969 - struct file_operations *dvbdevfops;
33970 + file_operations_no_const *dvbdevfops;
33971 struct device *clsdev;
33972 int minor;
33973 int id;
33974 diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
33975 index 3940bb0..fb3952a 100644
33976 --- a/drivers/media/dvb/dvb-usb/cxusb.c
33977 +++ b/drivers/media/dvb/dvb-usb/cxusb.c
33978 @@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
33979
33980 struct dib0700_adapter_state {
33981 int (*set_param_save) (struct dvb_frontend *);
33982 -};
33983 +} __no_const;
33984
33985 static int dib7070_set_param_override(struct dvb_frontend *fe)
33986 {
33987 diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
33988 index 9382895..ac8093c 100644
33989 --- a/drivers/media/dvb/dvb-usb/dw2102.c
33990 +++ b/drivers/media/dvb/dvb-usb/dw2102.c
33991 @@ -95,7 +95,7 @@ struct su3000_state {
33992
33993 struct s6x0_state {
33994 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
33995 -};
33996 +} __no_const;
33997
33998 /* debug */
33999 static int dvb_usb_dw2102_debug;
34000 diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
34001 index 404f63a..4796533 100644
34002 --- a/drivers/media/dvb/frontends/dib3000.h
34003 +++ b/drivers/media/dvb/frontends/dib3000.h
34004 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
34005 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
34006 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
34007 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
34008 -};
34009 +} __no_const;
34010
34011 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
34012 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
34013 diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
34014 index 72ee8de..eae0c80 100644
34015 --- a/drivers/media/dvb/ngene/ngene-cards.c
34016 +++ b/drivers/media/dvb/ngene/ngene-cards.c
34017 @@ -479,7 +479,7 @@ static struct ngene_info ngene_info_m780 = {
34018
34019 /****************************************************************************/
34020
34021 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
34022 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
34023 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
34024 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
34025 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
34026 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
34027 index 697a421..16c5a5f 100644
34028 --- a/drivers/media/radio/radio-cadet.c
34029 +++ b/drivers/media/radio/radio-cadet.c
34030 @@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
34031 unsigned char readbuf[RDS_BUFFER];
34032 int i = 0;
34033
34034 + if (count > RDS_BUFFER)
34035 + return -EFAULT;
34036 mutex_lock(&dev->lock);
34037 if (dev->rdsstat == 0)
34038 cadet_start_rds(dev);
34039 @@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
34040 while (i < count && dev->rdsin != dev->rdsout)
34041 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
34042
34043 - if (i && copy_to_user(data, readbuf, i))
34044 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
34045 i = -EFAULT;
34046 unlock:
34047 mutex_unlock(&dev->lock);
34048 diff --git a/drivers/media/radio/radio-tea5777.h b/drivers/media/radio/radio-tea5777.h
34049 index 55cbd78..428b0da 100644
34050 --- a/drivers/media/radio/radio-tea5777.h
34051 +++ b/drivers/media/radio/radio-tea5777.h
34052 @@ -63,7 +63,7 @@ struct radio_tea5777_ops {
34053
34054 struct radio_tea5777 {
34055 struct v4l2_device *v4l2_dev;
34056 - struct v4l2_file_operations fops;
34057 + v4l2_file_operations_no_const fops;
34058 struct video_device vd; /* video device */
34059 bool has_am; /* Device can tune to AM freqs */
34060 bool write_before_read; /* must write before read quirk */
34061 diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
34062 index 9cde353..8c6a1c3 100644
34063 --- a/drivers/media/video/au0828/au0828.h
34064 +++ b/drivers/media/video/au0828/au0828.h
34065 @@ -191,7 +191,7 @@ struct au0828_dev {
34066
34067 /* I2C */
34068 struct i2c_adapter i2c_adap;
34069 - struct i2c_algorithm i2c_algo;
34070 + i2c_algorithm_no_const i2c_algo;
34071 struct i2c_client i2c_client;
34072 u32 i2c_rc;
34073
34074 diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
34075 index dfac6e3..c26de31 100644
34076 --- a/drivers/media/video/cx88/cx88-alsa.c
34077 +++ b/drivers/media/video/cx88/cx88-alsa.c
34078 @@ -749,7 +749,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
34079 * Only boards with eeprom and byte 1 at eeprom=1 have it
34080 */
34081
34082 -static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
34083 +static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
34084 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34085 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34086 {0, }
34087 diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
34088 index 88cf9d9..bbc4b2c 100644
34089 --- a/drivers/media/video/omap/omap_vout.c
34090 +++ b/drivers/media/video/omap/omap_vout.c
34091 @@ -64,7 +64,6 @@ enum omap_vout_channels {
34092 OMAP_VIDEO2,
34093 };
34094
34095 -static struct videobuf_queue_ops video_vbq_ops;
34096 /* Variables configurable through module params*/
34097 static u32 video1_numbuffers = 3;
34098 static u32 video2_numbuffers = 3;
34099 @@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
34100 {
34101 struct videobuf_queue *q;
34102 struct omap_vout_device *vout = NULL;
34103 + static struct videobuf_queue_ops video_vbq_ops = {
34104 + .buf_setup = omap_vout_buffer_setup,
34105 + .buf_prepare = omap_vout_buffer_prepare,
34106 + .buf_release = omap_vout_buffer_release,
34107 + .buf_queue = omap_vout_buffer_queue,
34108 + };
34109
34110 vout = video_drvdata(file);
34111 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
34112 @@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
34113 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
34114
34115 q = &vout->vbq;
34116 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
34117 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
34118 - video_vbq_ops.buf_release = omap_vout_buffer_release;
34119 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
34120 spin_lock_init(&vout->vbq_lock);
34121
34122 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
34123 diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34124 index 036952f..80d356d 100644
34125 --- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34126 +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34127 @@ -196,7 +196,7 @@ struct pvr2_hdw {
34128
34129 /* I2C stuff */
34130 struct i2c_adapter i2c_adap;
34131 - struct i2c_algorithm i2c_algo;
34132 + i2c_algorithm_no_const i2c_algo;
34133 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
34134 int i2c_cx25840_hack_state;
34135 int i2c_linked;
34136 diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
34137 index 02194c0..091733b 100644
34138 --- a/drivers/media/video/timblogiw.c
34139 +++ b/drivers/media/video/timblogiw.c
34140 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
34141
34142 /* Platform device functions */
34143
34144 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34145 +static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
34146 .vidioc_querycap = timblogiw_querycap,
34147 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
34148 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
34149 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34150 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
34151 };
34152
34153 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
34154 +static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
34155 .owner = THIS_MODULE,
34156 .open = timblogiw_open,
34157 .release = timblogiw_close,
34158 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
34159 index d99db56..a16b959 100644
34160 --- a/drivers/message/fusion/mptbase.c
34161 +++ b/drivers/message/fusion/mptbase.c
34162 @@ -6751,8 +6751,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
34163 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
34164 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
34165
34166 +#ifdef CONFIG_GRKERNSEC_HIDESYM
34167 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
34168 +#else
34169 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
34170 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
34171 +#endif
34172 +
34173 /*
34174 * Rounding UP to nearest 4-kB boundary here...
34175 */
34176 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
34177 index 551262e..7551198 100644
34178 --- a/drivers/message/fusion/mptsas.c
34179 +++ b/drivers/message/fusion/mptsas.c
34180 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
34181 return 0;
34182 }
34183
34184 +static inline void
34185 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34186 +{
34187 + if (phy_info->port_details) {
34188 + phy_info->port_details->rphy = rphy;
34189 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34190 + ioc->name, rphy));
34191 + }
34192 +
34193 + if (rphy) {
34194 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34195 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34196 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34197 + ioc->name, rphy, rphy->dev.release));
34198 + }
34199 +}
34200 +
34201 /* no mutex */
34202 static void
34203 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
34204 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
34205 return NULL;
34206 }
34207
34208 -static inline void
34209 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34210 -{
34211 - if (phy_info->port_details) {
34212 - phy_info->port_details->rphy = rphy;
34213 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34214 - ioc->name, rphy));
34215 - }
34216 -
34217 - if (rphy) {
34218 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34219 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34220 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34221 - ioc->name, rphy, rphy->dev.release));
34222 - }
34223 -}
34224 -
34225 static inline struct sas_port *
34226 mptsas_get_port(struct mptsas_phyinfo *phy_info)
34227 {
34228 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
34229 index 0c3ced7..1fe34ec 100644
34230 --- a/drivers/message/fusion/mptscsih.c
34231 +++ b/drivers/message/fusion/mptscsih.c
34232 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
34233
34234 h = shost_priv(SChost);
34235
34236 - if (h) {
34237 - if (h->info_kbuf == NULL)
34238 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34239 - return h->info_kbuf;
34240 - h->info_kbuf[0] = '\0';
34241 + if (!h)
34242 + return NULL;
34243
34244 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34245 - h->info_kbuf[size-1] = '\0';
34246 - }
34247 + if (h->info_kbuf == NULL)
34248 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34249 + return h->info_kbuf;
34250 + h->info_kbuf[0] = '\0';
34251 +
34252 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34253 + h->info_kbuf[size-1] = '\0';
34254
34255 return h->info_kbuf;
34256 }
34257 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
34258 index 8001aa6..b137580 100644
34259 --- a/drivers/message/i2o/i2o_proc.c
34260 +++ b/drivers/message/i2o/i2o_proc.c
34261 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
34262 "Array Controller Device"
34263 };
34264
34265 -static char *chtostr(char *tmp, u8 *chars, int n)
34266 -{
34267 - tmp[0] = 0;
34268 - return strncat(tmp, (char *)chars, n);
34269 -}
34270 -
34271 static int i2o_report_query_status(struct seq_file *seq, int block_status,
34272 char *group)
34273 {
34274 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34275 } *result;
34276
34277 i2o_exec_execute_ddm_table ddm_table;
34278 - char tmp[28 + 1];
34279
34280 result = kmalloc(sizeof(*result), GFP_KERNEL);
34281 if (!result)
34282 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34283
34284 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
34285 seq_printf(seq, "%-#8x", ddm_table.module_id);
34286 - seq_printf(seq, "%-29s",
34287 - chtostr(tmp, ddm_table.module_name_version, 28));
34288 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
34289 seq_printf(seq, "%9d ", ddm_table.data_size);
34290 seq_printf(seq, "%8d", ddm_table.code_size);
34291
34292 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34293
34294 i2o_driver_result_table *result;
34295 i2o_driver_store_table *dst;
34296 - char tmp[28 + 1];
34297
34298 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
34299 if (result == NULL)
34300 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34301
34302 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
34303 seq_printf(seq, "%-#8x", dst->module_id);
34304 - seq_printf(seq, "%-29s",
34305 - chtostr(tmp, dst->module_name_version, 28));
34306 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
34307 + seq_printf(seq, "%-.28s", dst->module_name_version);
34308 + seq_printf(seq, "%-.8s", dst->date);
34309 seq_printf(seq, "%8d ", dst->module_size);
34310 seq_printf(seq, "%8d ", dst->mpb_size);
34311 seq_printf(seq, "0x%04x", dst->module_flags);
34312 @@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34313 // == (allow) 512d bytes (max)
34314 static u16 *work16 = (u16 *) work32;
34315 int token;
34316 - char tmp[16 + 1];
34317
34318 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
34319
34320 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34321 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
34322 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
34323 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
34324 - seq_printf(seq, "Vendor info : %s\n",
34325 - chtostr(tmp, (u8 *) (work32 + 2), 16));
34326 - seq_printf(seq, "Product info : %s\n",
34327 - chtostr(tmp, (u8 *) (work32 + 6), 16));
34328 - seq_printf(seq, "Description : %s\n",
34329 - chtostr(tmp, (u8 *) (work32 + 10), 16));
34330 - seq_printf(seq, "Product rev. : %s\n",
34331 - chtostr(tmp, (u8 *) (work32 + 14), 8));
34332 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
34333 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
34334 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
34335 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
34336
34337 seq_printf(seq, "Serial number : ");
34338 print_serial_number(seq, (u8 *) (work32 + 16),
34339 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34340 u8 pad[256]; // allow up to 256 byte (max) serial number
34341 } result;
34342
34343 - char tmp[24 + 1];
34344 -
34345 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
34346
34347 if (token < 0) {
34348 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34349 }
34350
34351 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
34352 - seq_printf(seq, "Module name : %s\n",
34353 - chtostr(tmp, result.module_name, 24));
34354 - seq_printf(seq, "Module revision : %s\n",
34355 - chtostr(tmp, result.module_rev, 8));
34356 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
34357 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
34358
34359 seq_printf(seq, "Serial number : ");
34360 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
34361 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34362 u8 instance_number[4];
34363 } result;
34364
34365 - char tmp[64 + 1];
34366 -
34367 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
34368
34369 if (token < 0) {
34370 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34371 return 0;
34372 }
34373
34374 - seq_printf(seq, "Device name : %s\n",
34375 - chtostr(tmp, result.device_name, 64));
34376 - seq_printf(seq, "Service name : %s\n",
34377 - chtostr(tmp, result.service_name, 64));
34378 - seq_printf(seq, "Physical name : %s\n",
34379 - chtostr(tmp, result.physical_location, 64));
34380 - seq_printf(seq, "Instance number : %s\n",
34381 - chtostr(tmp, result.instance_number, 4));
34382 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
34383 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
34384 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34385 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34386
34387 return 0;
34388 }
34389 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34390 index a8c08f3..155fe3d 100644
34391 --- a/drivers/message/i2o/iop.c
34392 +++ b/drivers/message/i2o/iop.c
34393 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34394
34395 spin_lock_irqsave(&c->context_list_lock, flags);
34396
34397 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34398 - atomic_inc(&c->context_list_counter);
34399 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34400 + atomic_inc_unchecked(&c->context_list_counter);
34401
34402 - entry->context = atomic_read(&c->context_list_counter);
34403 + entry->context = atomic_read_unchecked(&c->context_list_counter);
34404
34405 list_add(&entry->list, &c->context_list);
34406
34407 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34408
34409 #if BITS_PER_LONG == 64
34410 spin_lock_init(&c->context_list_lock);
34411 - atomic_set(&c->context_list_counter, 0);
34412 + atomic_set_unchecked(&c->context_list_counter, 0);
34413 INIT_LIST_HEAD(&c->context_list);
34414 #endif
34415
34416 diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34417 index 7ce65f4..e66e9bc 100644
34418 --- a/drivers/mfd/abx500-core.c
34419 +++ b/drivers/mfd/abx500-core.c
34420 @@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34421
34422 struct abx500_device_entry {
34423 struct list_head list;
34424 - struct abx500_ops ops;
34425 + abx500_ops_no_const ops;
34426 struct device *dev;
34427 };
34428
34429 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34430 index 965c480..71f2db9 100644
34431 --- a/drivers/mfd/janz-cmodio.c
34432 +++ b/drivers/mfd/janz-cmodio.c
34433 @@ -13,6 +13,7 @@
34434
34435 #include <linux/kernel.h>
34436 #include <linux/module.h>
34437 +#include <linux/slab.h>
34438 #include <linux/init.h>
34439 #include <linux/pci.h>
34440 #include <linux/interrupt.h>
34441 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34442 index a981e2a..5ca0c8b 100644
34443 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
34444 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34445 @@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34446 * the lid is closed. This leads to interrupts as soon as a little move
34447 * is done.
34448 */
34449 - atomic_inc(&lis3->count);
34450 + atomic_inc_unchecked(&lis3->count);
34451
34452 wake_up_interruptible(&lis3->misc_wait);
34453 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34454 @@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34455 if (lis3->pm_dev)
34456 pm_runtime_get_sync(lis3->pm_dev);
34457
34458 - atomic_set(&lis3->count, 0);
34459 + atomic_set_unchecked(&lis3->count, 0);
34460 return 0;
34461 }
34462
34463 @@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34464 add_wait_queue(&lis3->misc_wait, &wait);
34465 while (true) {
34466 set_current_state(TASK_INTERRUPTIBLE);
34467 - data = atomic_xchg(&lis3->count, 0);
34468 + data = atomic_xchg_unchecked(&lis3->count, 0);
34469 if (data)
34470 break;
34471
34472 @@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34473 struct lis3lv02d, miscdev);
34474
34475 poll_wait(file, &lis3->misc_wait, wait);
34476 - if (atomic_read(&lis3->count))
34477 + if (atomic_read_unchecked(&lis3->count))
34478 return POLLIN | POLLRDNORM;
34479 return 0;
34480 }
34481 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34482 index 2b1482a..5d33616 100644
34483 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
34484 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34485 @@ -266,7 +266,7 @@ struct lis3lv02d {
34486 struct input_polled_dev *idev; /* input device */
34487 struct platform_device *pdev; /* platform device */
34488 struct regulator_bulk_data regulators[2];
34489 - atomic_t count; /* interrupt count after last read */
34490 + atomic_unchecked_t count; /* interrupt count after last read */
34491 union axis_conversion ac; /* hw -> logical axis */
34492 int mapped_btns[3];
34493
34494 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34495 index 2f30bad..c4c13d0 100644
34496 --- a/drivers/misc/sgi-gru/gruhandles.c
34497 +++ b/drivers/misc/sgi-gru/gruhandles.c
34498 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34499 unsigned long nsec;
34500
34501 nsec = CLKS2NSEC(clks);
34502 - atomic_long_inc(&mcs_op_statistics[op].count);
34503 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
34504 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34505 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34506 if (mcs_op_statistics[op].max < nsec)
34507 mcs_op_statistics[op].max = nsec;
34508 }
34509 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34510 index 950dbe9..eeef0f8 100644
34511 --- a/drivers/misc/sgi-gru/gruprocfs.c
34512 +++ b/drivers/misc/sgi-gru/gruprocfs.c
34513 @@ -32,9 +32,9 @@
34514
34515 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34516
34517 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34518 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34519 {
34520 - unsigned long val = atomic_long_read(v);
34521 + unsigned long val = atomic_long_read_unchecked(v);
34522
34523 seq_printf(s, "%16lu %s\n", val, id);
34524 }
34525 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34526
34527 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34528 for (op = 0; op < mcsop_last; op++) {
34529 - count = atomic_long_read(&mcs_op_statistics[op].count);
34530 - total = atomic_long_read(&mcs_op_statistics[op].total);
34531 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34532 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34533 max = mcs_op_statistics[op].max;
34534 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34535 count ? total / count : 0, max);
34536 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34537 index 5c3ce24..4915ccb 100644
34538 --- a/drivers/misc/sgi-gru/grutables.h
34539 +++ b/drivers/misc/sgi-gru/grutables.h
34540 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34541 * GRU statistics.
34542 */
34543 struct gru_stats_s {
34544 - atomic_long_t vdata_alloc;
34545 - atomic_long_t vdata_free;
34546 - atomic_long_t gts_alloc;
34547 - atomic_long_t gts_free;
34548 - atomic_long_t gms_alloc;
34549 - atomic_long_t gms_free;
34550 - atomic_long_t gts_double_allocate;
34551 - atomic_long_t assign_context;
34552 - atomic_long_t assign_context_failed;
34553 - atomic_long_t free_context;
34554 - atomic_long_t load_user_context;
34555 - atomic_long_t load_kernel_context;
34556 - atomic_long_t lock_kernel_context;
34557 - atomic_long_t unlock_kernel_context;
34558 - atomic_long_t steal_user_context;
34559 - atomic_long_t steal_kernel_context;
34560 - atomic_long_t steal_context_failed;
34561 - atomic_long_t nopfn;
34562 - atomic_long_t asid_new;
34563 - atomic_long_t asid_next;
34564 - atomic_long_t asid_wrap;
34565 - atomic_long_t asid_reuse;
34566 - atomic_long_t intr;
34567 - atomic_long_t intr_cbr;
34568 - atomic_long_t intr_tfh;
34569 - atomic_long_t intr_spurious;
34570 - atomic_long_t intr_mm_lock_failed;
34571 - atomic_long_t call_os;
34572 - atomic_long_t call_os_wait_queue;
34573 - atomic_long_t user_flush_tlb;
34574 - atomic_long_t user_unload_context;
34575 - atomic_long_t user_exception;
34576 - atomic_long_t set_context_option;
34577 - atomic_long_t check_context_retarget_intr;
34578 - atomic_long_t check_context_unload;
34579 - atomic_long_t tlb_dropin;
34580 - atomic_long_t tlb_preload_page;
34581 - atomic_long_t tlb_dropin_fail_no_asid;
34582 - atomic_long_t tlb_dropin_fail_upm;
34583 - atomic_long_t tlb_dropin_fail_invalid;
34584 - atomic_long_t tlb_dropin_fail_range_active;
34585 - atomic_long_t tlb_dropin_fail_idle;
34586 - atomic_long_t tlb_dropin_fail_fmm;
34587 - atomic_long_t tlb_dropin_fail_no_exception;
34588 - atomic_long_t tfh_stale_on_fault;
34589 - atomic_long_t mmu_invalidate_range;
34590 - atomic_long_t mmu_invalidate_page;
34591 - atomic_long_t flush_tlb;
34592 - atomic_long_t flush_tlb_gru;
34593 - atomic_long_t flush_tlb_gru_tgh;
34594 - atomic_long_t flush_tlb_gru_zero_asid;
34595 + atomic_long_unchecked_t vdata_alloc;
34596 + atomic_long_unchecked_t vdata_free;
34597 + atomic_long_unchecked_t gts_alloc;
34598 + atomic_long_unchecked_t gts_free;
34599 + atomic_long_unchecked_t gms_alloc;
34600 + atomic_long_unchecked_t gms_free;
34601 + atomic_long_unchecked_t gts_double_allocate;
34602 + atomic_long_unchecked_t assign_context;
34603 + atomic_long_unchecked_t assign_context_failed;
34604 + atomic_long_unchecked_t free_context;
34605 + atomic_long_unchecked_t load_user_context;
34606 + atomic_long_unchecked_t load_kernel_context;
34607 + atomic_long_unchecked_t lock_kernel_context;
34608 + atomic_long_unchecked_t unlock_kernel_context;
34609 + atomic_long_unchecked_t steal_user_context;
34610 + atomic_long_unchecked_t steal_kernel_context;
34611 + atomic_long_unchecked_t steal_context_failed;
34612 + atomic_long_unchecked_t nopfn;
34613 + atomic_long_unchecked_t asid_new;
34614 + atomic_long_unchecked_t asid_next;
34615 + atomic_long_unchecked_t asid_wrap;
34616 + atomic_long_unchecked_t asid_reuse;
34617 + atomic_long_unchecked_t intr;
34618 + atomic_long_unchecked_t intr_cbr;
34619 + atomic_long_unchecked_t intr_tfh;
34620 + atomic_long_unchecked_t intr_spurious;
34621 + atomic_long_unchecked_t intr_mm_lock_failed;
34622 + atomic_long_unchecked_t call_os;
34623 + atomic_long_unchecked_t call_os_wait_queue;
34624 + atomic_long_unchecked_t user_flush_tlb;
34625 + atomic_long_unchecked_t user_unload_context;
34626 + atomic_long_unchecked_t user_exception;
34627 + atomic_long_unchecked_t set_context_option;
34628 + atomic_long_unchecked_t check_context_retarget_intr;
34629 + atomic_long_unchecked_t check_context_unload;
34630 + atomic_long_unchecked_t tlb_dropin;
34631 + atomic_long_unchecked_t tlb_preload_page;
34632 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34633 + atomic_long_unchecked_t tlb_dropin_fail_upm;
34634 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
34635 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
34636 + atomic_long_unchecked_t tlb_dropin_fail_idle;
34637 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
34638 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34639 + atomic_long_unchecked_t tfh_stale_on_fault;
34640 + atomic_long_unchecked_t mmu_invalidate_range;
34641 + atomic_long_unchecked_t mmu_invalidate_page;
34642 + atomic_long_unchecked_t flush_tlb;
34643 + atomic_long_unchecked_t flush_tlb_gru;
34644 + atomic_long_unchecked_t flush_tlb_gru_tgh;
34645 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34646
34647 - atomic_long_t copy_gpa;
34648 - atomic_long_t read_gpa;
34649 + atomic_long_unchecked_t copy_gpa;
34650 + atomic_long_unchecked_t read_gpa;
34651
34652 - atomic_long_t mesq_receive;
34653 - atomic_long_t mesq_receive_none;
34654 - atomic_long_t mesq_send;
34655 - atomic_long_t mesq_send_failed;
34656 - atomic_long_t mesq_noop;
34657 - atomic_long_t mesq_send_unexpected_error;
34658 - atomic_long_t mesq_send_lb_overflow;
34659 - atomic_long_t mesq_send_qlimit_reached;
34660 - atomic_long_t mesq_send_amo_nacked;
34661 - atomic_long_t mesq_send_put_nacked;
34662 - atomic_long_t mesq_page_overflow;
34663 - atomic_long_t mesq_qf_locked;
34664 - atomic_long_t mesq_qf_noop_not_full;
34665 - atomic_long_t mesq_qf_switch_head_failed;
34666 - atomic_long_t mesq_qf_unexpected_error;
34667 - atomic_long_t mesq_noop_unexpected_error;
34668 - atomic_long_t mesq_noop_lb_overflow;
34669 - atomic_long_t mesq_noop_qlimit_reached;
34670 - atomic_long_t mesq_noop_amo_nacked;
34671 - atomic_long_t mesq_noop_put_nacked;
34672 - atomic_long_t mesq_noop_page_overflow;
34673 + atomic_long_unchecked_t mesq_receive;
34674 + atomic_long_unchecked_t mesq_receive_none;
34675 + atomic_long_unchecked_t mesq_send;
34676 + atomic_long_unchecked_t mesq_send_failed;
34677 + atomic_long_unchecked_t mesq_noop;
34678 + atomic_long_unchecked_t mesq_send_unexpected_error;
34679 + atomic_long_unchecked_t mesq_send_lb_overflow;
34680 + atomic_long_unchecked_t mesq_send_qlimit_reached;
34681 + atomic_long_unchecked_t mesq_send_amo_nacked;
34682 + atomic_long_unchecked_t mesq_send_put_nacked;
34683 + atomic_long_unchecked_t mesq_page_overflow;
34684 + atomic_long_unchecked_t mesq_qf_locked;
34685 + atomic_long_unchecked_t mesq_qf_noop_not_full;
34686 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
34687 + atomic_long_unchecked_t mesq_qf_unexpected_error;
34688 + atomic_long_unchecked_t mesq_noop_unexpected_error;
34689 + atomic_long_unchecked_t mesq_noop_lb_overflow;
34690 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
34691 + atomic_long_unchecked_t mesq_noop_amo_nacked;
34692 + atomic_long_unchecked_t mesq_noop_put_nacked;
34693 + atomic_long_unchecked_t mesq_noop_page_overflow;
34694
34695 };
34696
34697 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34698 tghop_invalidate, mcsop_last};
34699
34700 struct mcs_op_statistic {
34701 - atomic_long_t count;
34702 - atomic_long_t total;
34703 + atomic_long_unchecked_t count;
34704 + atomic_long_unchecked_t total;
34705 unsigned long max;
34706 };
34707
34708 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34709
34710 #define STAT(id) do { \
34711 if (gru_options & OPT_STATS) \
34712 - atomic_long_inc(&gru_stats.id); \
34713 + atomic_long_inc_unchecked(&gru_stats.id); \
34714 } while (0)
34715
34716 #ifdef CONFIG_SGI_GRU_DEBUG
34717 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34718 index c862cd4..0d176fe 100644
34719 --- a/drivers/misc/sgi-xp/xp.h
34720 +++ b/drivers/misc/sgi-xp/xp.h
34721 @@ -288,7 +288,7 @@ struct xpc_interface {
34722 xpc_notify_func, void *);
34723 void (*received) (short, int, void *);
34724 enum xp_retval (*partid_to_nasids) (short, void *);
34725 -};
34726 +} __no_const;
34727
34728 extern struct xpc_interface xpc_interface;
34729
34730 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
34731 index b94d5f7..7f494c5 100644
34732 --- a/drivers/misc/sgi-xp/xpc.h
34733 +++ b/drivers/misc/sgi-xp/xpc.h
34734 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
34735 void (*received_payload) (struct xpc_channel *, void *);
34736 void (*notify_senders_of_disconnect) (struct xpc_channel *);
34737 };
34738 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
34739
34740 /* struct xpc_partition act_state values (for XPC HB) */
34741
34742 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
34743 /* found in xpc_main.c */
34744 extern struct device *xpc_part;
34745 extern struct device *xpc_chan;
34746 -extern struct xpc_arch_operations xpc_arch_ops;
34747 +extern xpc_arch_operations_no_const xpc_arch_ops;
34748 extern int xpc_disengage_timelimit;
34749 extern int xpc_disengage_timedout;
34750 extern int xpc_activate_IRQ_rcvd;
34751 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
34752 index 8d082b4..aa749ae 100644
34753 --- a/drivers/misc/sgi-xp/xpc_main.c
34754 +++ b/drivers/misc/sgi-xp/xpc_main.c
34755 @@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
34756 .notifier_call = xpc_system_die,
34757 };
34758
34759 -struct xpc_arch_operations xpc_arch_ops;
34760 +xpc_arch_operations_no_const xpc_arch_ops;
34761
34762 /*
34763 * Timer function to enforce the timelimit on the partition disengage.
34764 diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
34765 index 504da71..9722d43 100644
34766 --- a/drivers/mmc/host/sdhci-pci.c
34767 +++ b/drivers/mmc/host/sdhci-pci.c
34768 @@ -653,7 +653,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
34769 .probe = via_probe,
34770 };
34771
34772 -static const struct pci_device_id pci_ids[] __devinitdata = {
34773 +static const struct pci_device_id pci_ids[] __devinitconst = {
34774 {
34775 .vendor = PCI_VENDOR_ID_RICOH,
34776 .device = PCI_DEVICE_ID_RICOH_R5C822,
34777 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
34778 index a4eb8b5..8c0628f 100644
34779 --- a/drivers/mtd/devices/doc2000.c
34780 +++ b/drivers/mtd/devices/doc2000.c
34781 @@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
34782
34783 /* The ECC will not be calculated correctly if less than 512 is written */
34784 /* DBB-
34785 - if (len != 0x200 && eccbuf)
34786 + if (len != 0x200)
34787 printk(KERN_WARNING
34788 "ECC needs a full sector write (adr: %lx size %lx)\n",
34789 (long) to, (long) len);
34790 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
34791 index 0650aaf..7718762 100644
34792 --- a/drivers/mtd/nand/denali.c
34793 +++ b/drivers/mtd/nand/denali.c
34794 @@ -26,6 +26,7 @@
34795 #include <linux/pci.h>
34796 #include <linux/mtd/mtd.h>
34797 #include <linux/module.h>
34798 +#include <linux/slab.h>
34799
34800 #include "denali.h"
34801
34802 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
34803 index 51b9d6a..52af9a7 100644
34804 --- a/drivers/mtd/nftlmount.c
34805 +++ b/drivers/mtd/nftlmount.c
34806 @@ -24,6 +24,7 @@
34807 #include <asm/errno.h>
34808 #include <linux/delay.h>
34809 #include <linux/slab.h>
34810 +#include <linux/sched.h>
34811 #include <linux/mtd/mtd.h>
34812 #include <linux/mtd/nand.h>
34813 #include <linux/mtd/nftl.h>
34814 diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c
34815 index dc15d24..ef8d2a0 100644
34816 --- a/drivers/net/bonding/bond_sysfs.c
34817 +++ b/drivers/net/bonding/bond_sysfs.c
34818 @@ -1060,7 +1060,7 @@ static ssize_t bonding_store_primary(struct device *d,
34819 goto out;
34820 }
34821
34822 - sscanf(buf, "%16s", ifname); /* IFNAMSIZ */
34823 + sscanf(buf, "%15s", ifname); /* IFNAMSIZ */
34824
34825 /* check to see if we are clearing primary */
34826 if (!strlen(ifname) || buf[0] == '\n') {
34827 @@ -1237,7 +1237,7 @@ static ssize_t bonding_store_active_slave(struct device *d,
34828 goto out;
34829 }
34830
34831 - sscanf(buf, "%16s", ifname); /* IFNAMSIZ */
34832 + sscanf(buf, "%15s", ifname); /* IFNAMSIZ */
34833
34834 /* check to see if we are clearing active */
34835 if (!strlen(ifname) || buf[0] == '\n') {
34836 diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
34837 index 57d64b8..623dd86 100644
34838 --- a/drivers/net/ethernet/atheros/atlx/atl2.c
34839 +++ b/drivers/net/ethernet/atheros/atlx/atl2.c
34840 @@ -2845,7 +2845,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
34841 */
34842
34843 #define ATL2_PARAM(X, desc) \
34844 - static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34845 + static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34846 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
34847 MODULE_PARM_DESC(X, desc);
34848 #else
34849 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
34850 index 0875ecf..794cdf3 100644
34851 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
34852 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
34853 @@ -3051,9 +3051,8 @@ static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
34854 struct eth_stats_info *ether_stat =
34855 &bp->slowpath->drv_info_to_mcp.ether_stat;
34856
34857 - /* leave last char as NULL */
34858 - memcpy(ether_stat->version, DRV_MODULE_VERSION,
34859 - ETH_STAT_INFO_VERSION_LEN - 1);
34860 + strlcpy(ether_stat->version, DRV_MODULE_VERSION,
34861 + ETH_STAT_INFO_VERSION_LEN);
34862
34863 bp->sp_objs[0].mac_obj.get_n_elements(bp, &bp->sp_objs[0].mac_obj,
34864 DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
34865 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34866 index f83e033..8b4f43a 100644
34867 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34868 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34869 @@ -486,7 +486,7 @@ struct bnx2x_rx_mode_obj {
34870
34871 int (*wait_comp)(struct bnx2x *bp,
34872 struct bnx2x_rx_mode_ramrod_params *p);
34873 -};
34874 +} __no_const;
34875
34876 /********************** Set multicast group ***********************************/
34877
34878 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
34879 index 6d52cb2..bc95640 100644
34880 --- a/drivers/net/ethernet/broadcom/tg3.h
34881 +++ b/drivers/net/ethernet/broadcom/tg3.h
34882 @@ -140,6 +140,7 @@
34883 #define CHIPREV_ID_5750_A0 0x4000
34884 #define CHIPREV_ID_5750_A1 0x4001
34885 #define CHIPREV_ID_5750_A3 0x4003
34886 +#define CHIPREV_ID_5750_C1 0x4201
34887 #define CHIPREV_ID_5750_C2 0x4202
34888 #define CHIPREV_ID_5752_A0_HW 0x5000
34889 #define CHIPREV_ID_5752_A0 0x6000
34890 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34891 index 8cffcdf..aadf043 100644
34892 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34893 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34894 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
34895 */
34896 struct l2t_skb_cb {
34897 arp_failure_handler_func arp_failure_handler;
34898 -};
34899 +} __no_const;
34900
34901 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
34902
34903 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
34904 index f879e92..726f20f 100644
34905 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
34906 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
34907 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34908 for (i=0; i<ETH_ALEN; i++) {
34909 tmp.addr[i] = dev->dev_addr[i];
34910 }
34911 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34912 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34913 break;
34914
34915 case DE4X5_SET_HWADDR: /* Set the hardware address */
34916 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34917 spin_lock_irqsave(&lp->lock, flags);
34918 memcpy(&statbuf, &lp->pktStats, ioc->len);
34919 spin_unlock_irqrestore(&lp->lock, flags);
34920 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
34921 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
34922 return -EFAULT;
34923 break;
34924 }
34925 diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
34926 index ed7d1dc..d426748 100644
34927 --- a/drivers/net/ethernet/dec/tulip/eeprom.c
34928 +++ b/drivers/net/ethernet/dec/tulip/eeprom.c
34929 @@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
34930 {NULL}};
34931
34932
34933 -static const char *block_name[] __devinitdata = {
34934 +static const char *block_name[] __devinitconst = {
34935 "21140 non-MII",
34936 "21140 MII PHY",
34937 "21142 Serial PHY",
34938 diff --git a/drivers/net/ethernet/dec/tulip/uli526x.c b/drivers/net/ethernet/dec/tulip/uli526x.c
34939 index 75d45f8..3d9c55b 100644
34940 --- a/drivers/net/ethernet/dec/tulip/uli526x.c
34941 +++ b/drivers/net/ethernet/dec/tulip/uli526x.c
34942 @@ -129,7 +129,7 @@ struct uli526x_board_info {
34943 struct uli_phy_ops {
34944 void (*write)(struct uli526x_board_info *, u8, u8, u16);
34945 u16 (*read)(struct uli526x_board_info *, u8, u8);
34946 - } phy;
34947 + } __no_const phy;
34948 struct net_device *next_dev; /* next device */
34949 struct pci_dev *pdev; /* PCI device */
34950 spinlock_t lock;
34951 diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
34952 index 4d1ffca..7c1ec4d 100644
34953 --- a/drivers/net/ethernet/dec/tulip/winbond-840.c
34954 +++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
34955 @@ -236,7 +236,7 @@ struct pci_id_info {
34956 int drv_flags; /* Driver use, intended as capability flags. */
34957 };
34958
34959 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34960 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34961 { /* Sometime a Level-One switch card. */
34962 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
34963 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
34964 diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
34965 index d7bb52a..3b83588 100644
34966 --- a/drivers/net/ethernet/dlink/sundance.c
34967 +++ b/drivers/net/ethernet/dlink/sundance.c
34968 @@ -218,7 +218,7 @@ enum {
34969 struct pci_id_info {
34970 const char *name;
34971 };
34972 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34973 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34974 {"D-Link DFE-550TX FAST Ethernet Adapter"},
34975 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
34976 {"D-Link DFE-580TX 4 port Server Adapter"},
34977 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
34978 index 78b8aa8..dd6323a 100644
34979 --- a/drivers/net/ethernet/emulex/benet/be_main.c
34980 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
34981 @@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
34982
34983 if (wrapped)
34984 newacc += 65536;
34985 - ACCESS_ONCE(*acc) = newacc;
34986 + ACCESS_ONCE_RW(*acc) = newacc;
34987 }
34988
34989 void be_parse_stats(struct be_adapter *adapter)
34990 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
34991 index 74d749e..eefb1bd 100644
34992 --- a/drivers/net/ethernet/faraday/ftgmac100.c
34993 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
34994 @@ -31,6 +31,8 @@
34995 #include <linux/netdevice.h>
34996 #include <linux/phy.h>
34997 #include <linux/platform_device.h>
34998 +#include <linux/interrupt.h>
34999 +#include <linux/irqreturn.h>
35000 #include <net/ip.h>
35001
35002 #include "ftgmac100.h"
35003 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
35004 index b901a01..1ff32ee 100644
35005 --- a/drivers/net/ethernet/faraday/ftmac100.c
35006 +++ b/drivers/net/ethernet/faraday/ftmac100.c
35007 @@ -31,6 +31,8 @@
35008 #include <linux/module.h>
35009 #include <linux/netdevice.h>
35010 #include <linux/platform_device.h>
35011 +#include <linux/interrupt.h>
35012 +#include <linux/irqreturn.h>
35013
35014 #include "ftmac100.h"
35015
35016 diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
35017 index 9d71c9c..0e4a0ac 100644
35018 --- a/drivers/net/ethernet/fealnx.c
35019 +++ b/drivers/net/ethernet/fealnx.c
35020 @@ -150,7 +150,7 @@ struct chip_info {
35021 int flags;
35022 };
35023
35024 -static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
35025 +static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
35026 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
35027 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
35028 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
35029 diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
35030 index ed5b409..ec37828 100644
35031 --- a/drivers/net/ethernet/intel/e1000e/hw.h
35032 +++ b/drivers/net/ethernet/intel/e1000e/hw.h
35033 @@ -797,6 +797,7 @@ struct e1000_mac_operations {
35034 void (*rar_set)(struct e1000_hw *, u8 *, u32);
35035 s32 (*read_mac_addr)(struct e1000_hw *);
35036 };
35037 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35038
35039 /*
35040 * When to use various PHY register access functions:
35041 @@ -837,6 +838,7 @@ struct e1000_phy_operations {
35042 void (*power_up)(struct e1000_hw *);
35043 void (*power_down)(struct e1000_hw *);
35044 };
35045 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
35046
35047 /* Function pointers for the NVM. */
35048 struct e1000_nvm_operations {
35049 @@ -849,9 +851,10 @@ struct e1000_nvm_operations {
35050 s32 (*validate)(struct e1000_hw *);
35051 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
35052 };
35053 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
35054
35055 struct e1000_mac_info {
35056 - struct e1000_mac_operations ops;
35057 + e1000_mac_operations_no_const ops;
35058 u8 addr[ETH_ALEN];
35059 u8 perm_addr[ETH_ALEN];
35060
35061 @@ -892,7 +895,7 @@ struct e1000_mac_info {
35062 };
35063
35064 struct e1000_phy_info {
35065 - struct e1000_phy_operations ops;
35066 + e1000_phy_operations_no_const ops;
35067
35068 enum e1000_phy_type type;
35069
35070 @@ -926,7 +929,7 @@ struct e1000_phy_info {
35071 };
35072
35073 struct e1000_nvm_info {
35074 - struct e1000_nvm_operations ops;
35075 + e1000_nvm_operations_no_const ops;
35076
35077 enum e1000_nvm_type type;
35078 enum e1000_nvm_override override;
35079 diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
35080 index c2a51dc..c2bd262 100644
35081 --- a/drivers/net/ethernet/intel/igb/e1000_hw.h
35082 +++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
35083 @@ -327,6 +327,7 @@ struct e1000_mac_operations {
35084 void (*release_swfw_sync)(struct e1000_hw *, u16);
35085
35086 };
35087 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35088
35089 struct e1000_phy_operations {
35090 s32 (*acquire)(struct e1000_hw *);
35091 @@ -343,6 +344,7 @@ struct e1000_phy_operations {
35092 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
35093 s32 (*write_reg)(struct e1000_hw *, u32, u16);
35094 };
35095 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
35096
35097 struct e1000_nvm_operations {
35098 s32 (*acquire)(struct e1000_hw *);
35099 @@ -353,6 +355,7 @@ struct e1000_nvm_operations {
35100 s32 (*validate)(struct e1000_hw *);
35101 s32 (*valid_led_default)(struct e1000_hw *, u16 *);
35102 };
35103 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
35104
35105 struct e1000_info {
35106 s32 (*get_invariants)(struct e1000_hw *);
35107 @@ -364,7 +367,7 @@ struct e1000_info {
35108 extern const struct e1000_info e1000_82575_info;
35109
35110 struct e1000_mac_info {
35111 - struct e1000_mac_operations ops;
35112 + e1000_mac_operations_no_const ops;
35113
35114 u8 addr[6];
35115 u8 perm_addr[6];
35116 @@ -402,7 +405,7 @@ struct e1000_mac_info {
35117 };
35118
35119 struct e1000_phy_info {
35120 - struct e1000_phy_operations ops;
35121 + e1000_phy_operations_no_const ops;
35122
35123 enum e1000_phy_type type;
35124
35125 @@ -437,7 +440,7 @@ struct e1000_phy_info {
35126 };
35127
35128 struct e1000_nvm_info {
35129 - struct e1000_nvm_operations ops;
35130 + e1000_nvm_operations_no_const ops;
35131 enum e1000_nvm_type type;
35132 enum e1000_nvm_override override;
35133
35134 @@ -482,6 +485,7 @@ struct e1000_mbx_operations {
35135 s32 (*check_for_ack)(struct e1000_hw *, u16);
35136 s32 (*check_for_rst)(struct e1000_hw *, u16);
35137 };
35138 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35139
35140 struct e1000_mbx_stats {
35141 u32 msgs_tx;
35142 @@ -493,7 +497,7 @@ struct e1000_mbx_stats {
35143 };
35144
35145 struct e1000_mbx_info {
35146 - struct e1000_mbx_operations ops;
35147 + e1000_mbx_operations_no_const ops;
35148 struct e1000_mbx_stats stats;
35149 u32 timeout;
35150 u32 usec_delay;
35151 diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
35152 index 57db3c6..aa825fc 100644
35153 --- a/drivers/net/ethernet/intel/igbvf/vf.h
35154 +++ b/drivers/net/ethernet/intel/igbvf/vf.h
35155 @@ -189,9 +189,10 @@ struct e1000_mac_operations {
35156 s32 (*read_mac_addr)(struct e1000_hw *);
35157 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
35158 };
35159 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35160
35161 struct e1000_mac_info {
35162 - struct e1000_mac_operations ops;
35163 + e1000_mac_operations_no_const ops;
35164 u8 addr[6];
35165 u8 perm_addr[6];
35166
35167 @@ -213,6 +214,7 @@ struct e1000_mbx_operations {
35168 s32 (*check_for_ack)(struct e1000_hw *);
35169 s32 (*check_for_rst)(struct e1000_hw *);
35170 };
35171 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35172
35173 struct e1000_mbx_stats {
35174 u32 msgs_tx;
35175 @@ -224,7 +226,7 @@ struct e1000_mbx_stats {
35176 };
35177
35178 struct e1000_mbx_info {
35179 - struct e1000_mbx_operations ops;
35180 + e1000_mbx_operations_no_const ops;
35181 struct e1000_mbx_stats stats;
35182 u32 timeout;
35183 u32 usec_delay;
35184 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35185 index 3456d56..b688d81 100644
35186 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35187 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35188 @@ -884,7 +884,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
35189 /* store the new cycle speed */
35190 adapter->cycle_speed = cycle_speed;
35191
35192 - ACCESS_ONCE(adapter->base_incval) = incval;
35193 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
35194 smp_mb();
35195
35196 /* grab the ptp lock */
35197 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35198 index 400f86a..7f2e062 100644
35199 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35200 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35201 @@ -2799,6 +2799,7 @@ struct ixgbe_eeprom_operations {
35202 s32 (*update_checksum)(struct ixgbe_hw *);
35203 u16 (*calc_checksum)(struct ixgbe_hw *);
35204 };
35205 +typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
35206
35207 struct ixgbe_mac_operations {
35208 s32 (*init_hw)(struct ixgbe_hw *);
35209 @@ -2865,6 +2866,7 @@ struct ixgbe_mac_operations {
35210 s32 (*get_thermal_sensor_data)(struct ixgbe_hw *);
35211 s32 (*init_thermal_sensor_thresh)(struct ixgbe_hw *hw);
35212 };
35213 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35214
35215 struct ixgbe_phy_operations {
35216 s32 (*identify)(struct ixgbe_hw *);
35217 @@ -2884,9 +2886,10 @@ struct ixgbe_phy_operations {
35218 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
35219 s32 (*check_overtemp)(struct ixgbe_hw *);
35220 };
35221 +typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
35222
35223 struct ixgbe_eeprom_info {
35224 - struct ixgbe_eeprom_operations ops;
35225 + ixgbe_eeprom_operations_no_const ops;
35226 enum ixgbe_eeprom_type type;
35227 u32 semaphore_delay;
35228 u16 word_size;
35229 @@ -2896,7 +2899,7 @@ struct ixgbe_eeprom_info {
35230
35231 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
35232 struct ixgbe_mac_info {
35233 - struct ixgbe_mac_operations ops;
35234 + ixgbe_mac_operations_no_const ops;
35235 enum ixgbe_mac_type type;
35236 u8 addr[ETH_ALEN];
35237 u8 perm_addr[ETH_ALEN];
35238 @@ -2926,7 +2929,7 @@ struct ixgbe_mac_info {
35239 };
35240
35241 struct ixgbe_phy_info {
35242 - struct ixgbe_phy_operations ops;
35243 + ixgbe_phy_operations_no_const ops;
35244 struct mdio_if_info mdio;
35245 enum ixgbe_phy_type type;
35246 u32 id;
35247 @@ -2954,6 +2957,7 @@ struct ixgbe_mbx_operations {
35248 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
35249 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
35250 };
35251 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35252
35253 struct ixgbe_mbx_stats {
35254 u32 msgs_tx;
35255 @@ -2965,7 +2969,7 @@ struct ixgbe_mbx_stats {
35256 };
35257
35258 struct ixgbe_mbx_info {
35259 - struct ixgbe_mbx_operations ops;
35260 + ixgbe_mbx_operations_no_const ops;
35261 struct ixgbe_mbx_stats stats;
35262 u32 timeout;
35263 u32 usec_delay;
35264 diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
35265 index 25c951d..cc7cf33 100644
35266 --- a/drivers/net/ethernet/intel/ixgbevf/vf.h
35267 +++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
35268 @@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
35269 s32 (*clear_vfta)(struct ixgbe_hw *);
35270 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
35271 };
35272 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35273
35274 enum ixgbe_mac_type {
35275 ixgbe_mac_unknown = 0,
35276 @@ -79,7 +80,7 @@ enum ixgbe_mac_type {
35277 };
35278
35279 struct ixgbe_mac_info {
35280 - struct ixgbe_mac_operations ops;
35281 + ixgbe_mac_operations_no_const ops;
35282 u8 addr[6];
35283 u8 perm_addr[6];
35284
35285 @@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
35286 s32 (*check_for_ack)(struct ixgbe_hw *);
35287 s32 (*check_for_rst)(struct ixgbe_hw *);
35288 };
35289 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35290
35291 struct ixgbe_mbx_stats {
35292 u32 msgs_tx;
35293 @@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
35294 };
35295
35296 struct ixgbe_mbx_info {
35297 - struct ixgbe_mbx_operations ops;
35298 + ixgbe_mbx_operations_no_const ops;
35299 struct ixgbe_mbx_stats stats;
35300 u32 timeout;
35301 u32 udelay;
35302 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35303 index 9e0c1ee..8471f77 100644
35304 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
35305 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35306 @@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
35307 void (*link_down)(struct __vxge_hw_device *devh);
35308 void (*crit_err)(struct __vxge_hw_device *devh,
35309 enum vxge_hw_event type, u64 ext_data);
35310 -};
35311 +} __no_const;
35312
35313 /*
35314 * struct __vxge_hw_blockpool_entry - Block private data structure
35315 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35316 index 4a518a3..936b334 100644
35317 --- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35318 +++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35319 @@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
35320 struct vxge_hw_mempool_dma *dma_object,
35321 u32 index,
35322 u32 is_last);
35323 -};
35324 +} __no_const;
35325
35326 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
35327 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
35328 diff --git a/drivers/net/ethernet/nxp/lpc_eth.c b/drivers/net/ethernet/nxp/lpc_eth.c
35329 index 53743f7..af8b414 100644
35330 --- a/drivers/net/ethernet/nxp/lpc_eth.c
35331 +++ b/drivers/net/ethernet/nxp/lpc_eth.c
35332 @@ -1524,6 +1524,7 @@ static int lpc_eth_drv_remove(struct platform_device *pdev)
35333 pldat->dma_buff_base_p);
35334 free_irq(ndev->irq, ndev);
35335 iounmap(pldat->net_base);
35336 + mdiobus_unregister(pldat->mii_bus);
35337 mdiobus_free(pldat->mii_bus);
35338 clk_disable(pldat->clk);
35339 clk_put(pldat->clk);
35340 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
35341 index b47d5b3..273a516 100644
35342 --- a/drivers/net/ethernet/realtek/r8169.c
35343 +++ b/drivers/net/ethernet/realtek/r8169.c
35344 @@ -745,22 +745,22 @@ struct rtl8169_private {
35345 struct mdio_ops {
35346 void (*write)(struct rtl8169_private *, int, int);
35347 int (*read)(struct rtl8169_private *, int);
35348 - } mdio_ops;
35349 + } __no_const mdio_ops;
35350
35351 struct pll_power_ops {
35352 void (*down)(struct rtl8169_private *);
35353 void (*up)(struct rtl8169_private *);
35354 - } pll_power_ops;
35355 + } __no_const pll_power_ops;
35356
35357 struct jumbo_ops {
35358 void (*enable)(struct rtl8169_private *);
35359 void (*disable)(struct rtl8169_private *);
35360 - } jumbo_ops;
35361 + } __no_const jumbo_ops;
35362
35363 struct csi_ops {
35364 void (*write)(struct rtl8169_private *, int, int);
35365 u32 (*read)(struct rtl8169_private *, int);
35366 - } csi_ops;
35367 + } __no_const csi_ops;
35368
35369 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
35370 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
35371 diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
35372 index 4613591..d816601 100644
35373 --- a/drivers/net/ethernet/sis/sis190.c
35374 +++ b/drivers/net/ethernet/sis/sis190.c
35375 @@ -1618,7 +1618,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
35376 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
35377 struct net_device *dev)
35378 {
35379 - static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
35380 + static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
35381 struct sis190_private *tp = netdev_priv(dev);
35382 struct pci_dev *isa_bridge;
35383 u8 reg, tmp8;
35384 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35385 index 0c74a70..3bc6f68 100644
35386 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35387 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35388 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
35389
35390 writel(value, ioaddr + MMC_CNTRL);
35391
35392 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35393 - MMC_CNTRL, value);
35394 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35395 +// MMC_CNTRL, value);
35396 }
35397
35398 /* To mask all all interrupts.*/
35399 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
35400 index 95ceb35..318fc12 100644
35401 --- a/drivers/net/hyperv/hyperv_net.h
35402 +++ b/drivers/net/hyperv/hyperv_net.h
35403 @@ -99,7 +99,7 @@ struct rndis_device {
35404
35405 enum rndis_device_state state;
35406 bool link_state;
35407 - atomic_t new_req_id;
35408 + atomic_unchecked_t new_req_id;
35409
35410 spinlock_t request_lock;
35411 struct list_head req_list;
35412 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
35413 index 1e88a10..1b01736 100644
35414 --- a/drivers/net/hyperv/rndis_filter.c
35415 +++ b/drivers/net/hyperv/rndis_filter.c
35416 @@ -99,7 +99,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35417 * template
35418 */
35419 set = &rndis_msg->msg.set_req;
35420 - set->req_id = atomic_inc_return(&dev->new_req_id);
35421 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35422
35423 /* Add to the request list */
35424 spin_lock_irqsave(&dev->request_lock, flags);
35425 @@ -730,7 +730,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35426
35427 /* Setup the rndis set */
35428 halt = &request->request_msg.msg.halt_req;
35429 - halt->req_id = atomic_inc_return(&dev->new_req_id);
35430 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35431
35432 /* Ignore return since this msg is optional. */
35433 rndis_filter_send_request(dev, request);
35434 diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
35435 index daec9b0..6428fcb 100644
35436 --- a/drivers/net/phy/mdio-bitbang.c
35437 +++ b/drivers/net/phy/mdio-bitbang.c
35438 @@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
35439 struct mdiobb_ctrl *ctrl = bus->priv;
35440
35441 module_put(ctrl->ops->owner);
35442 + mdiobus_unregister(bus);
35443 mdiobus_free(bus);
35444 }
35445 EXPORT_SYMBOL(free_mdio_bitbang);
35446 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35447 index 5c05572..389610b 100644
35448 --- a/drivers/net/ppp/ppp_generic.c
35449 +++ b/drivers/net/ppp/ppp_generic.c
35450 @@ -986,7 +986,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35451 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35452 struct ppp_stats stats;
35453 struct ppp_comp_stats cstats;
35454 - char *vers;
35455
35456 switch (cmd) {
35457 case SIOCGPPPSTATS:
35458 @@ -1008,8 +1007,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35459 break;
35460
35461 case SIOCGPPPVER:
35462 - vers = PPP_VERSION;
35463 - if (copy_to_user(addr, vers, strlen(vers) + 1))
35464 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35465 break;
35466 err = 0;
35467 break;
35468 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
35469 index 3a16d4f..a311cec 100644
35470 --- a/drivers/net/tun.c
35471 +++ b/drivers/net/tun.c
35472 @@ -1367,7 +1367,7 @@ static int set_offload(struct tun_struct *tun, unsigned long arg)
35473 }
35474
35475 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
35476 - unsigned long arg, int ifreq_len)
35477 + unsigned long arg, size_t ifreq_len)
35478 {
35479 struct tun_file *tfile = file->private_data;
35480 struct tun_struct *tun;
35481 @@ -1378,6 +1378,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
35482 int vnet_hdr_sz;
35483 int ret;
35484
35485 + if (ifreq_len > sizeof ifr)
35486 + return -EFAULT;
35487 +
35488 if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89) {
35489 if (copy_from_user(&ifr, argp, ifreq_len))
35490 return -EFAULT;
35491 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35492 index 62f30b4..ff99dfd 100644
35493 --- a/drivers/net/usb/hso.c
35494 +++ b/drivers/net/usb/hso.c
35495 @@ -71,7 +71,7 @@
35496 #include <asm/byteorder.h>
35497 #include <linux/serial_core.h>
35498 #include <linux/serial.h>
35499 -
35500 +#include <asm/local.h>
35501
35502 #define MOD_AUTHOR "Option Wireless"
35503 #define MOD_DESCRIPTION "USB High Speed Option driver"
35504 @@ -1182,7 +1182,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35505 struct urb *urb;
35506
35507 urb = serial->rx_urb[0];
35508 - if (serial->port.count > 0) {
35509 + if (atomic_read(&serial->port.count) > 0) {
35510 count = put_rxbuf_data(urb, serial);
35511 if (count == -1)
35512 return;
35513 @@ -1218,7 +1218,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35514 DUMP1(urb->transfer_buffer, urb->actual_length);
35515
35516 /* Anyone listening? */
35517 - if (serial->port.count == 0)
35518 + if (atomic_read(&serial->port.count) == 0)
35519 return;
35520
35521 if (status == 0) {
35522 @@ -1300,8 +1300,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35523 tty_port_tty_set(&serial->port, tty);
35524
35525 /* check for port already opened, if not set the termios */
35526 - serial->port.count++;
35527 - if (serial->port.count == 1) {
35528 + if (atomic_inc_return(&serial->port.count) == 1) {
35529 serial->rx_state = RX_IDLE;
35530 /* Force default termio settings */
35531 _hso_serial_set_termios(tty, NULL);
35532 @@ -1313,7 +1312,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35533 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35534 if (result) {
35535 hso_stop_serial_device(serial->parent);
35536 - serial->port.count--;
35537 + atomic_dec(&serial->port.count);
35538 kref_put(&serial->parent->ref, hso_serial_ref_free);
35539 }
35540 } else {
35541 @@ -1350,10 +1349,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35542
35543 /* reset the rts and dtr */
35544 /* do the actual close */
35545 - serial->port.count--;
35546 + atomic_dec(&serial->port.count);
35547
35548 - if (serial->port.count <= 0) {
35549 - serial->port.count = 0;
35550 + if (atomic_read(&serial->port.count) <= 0) {
35551 + atomic_set(&serial->port.count, 0);
35552 tty_port_tty_set(&serial->port, NULL);
35553 if (!usb_gone)
35554 hso_stop_serial_device(serial->parent);
35555 @@ -1429,7 +1428,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35556
35557 /* the actual setup */
35558 spin_lock_irqsave(&serial->serial_lock, flags);
35559 - if (serial->port.count)
35560 + if (atomic_read(&serial->port.count))
35561 _hso_serial_set_termios(tty, old);
35562 else
35563 tty->termios = old;
35564 @@ -1888,7 +1887,7 @@ static void intr_callback(struct urb *urb)
35565 D1("Pending read interrupt on port %d\n", i);
35566 spin_lock(&serial->serial_lock);
35567 if (serial->rx_state == RX_IDLE &&
35568 - serial->port.count > 0) {
35569 + atomic_read(&serial->port.count) > 0) {
35570 /* Setup and send a ctrl req read on
35571 * port i */
35572 if (!serial->rx_urb_filled[0]) {
35573 @@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
35574 /* Start all serial ports */
35575 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35576 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35577 - if (dev2ser(serial_table[i])->port.count) {
35578 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
35579 result =
35580 hso_start_serial_device(serial_table[i], GFP_NOIO);
35581 hso_kick_transmit(dev2ser(serial_table[i]));
35582 diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35583 index 6169fbd..40e8422 100644
35584 --- a/drivers/net/wireless/ath/ath.h
35585 +++ b/drivers/net/wireless/ath/ath.h
35586 @@ -119,6 +119,7 @@ struct ath_ops {
35587 void (*write_flush) (void *);
35588 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35589 };
35590 +typedef struct ath_ops __no_const ath_ops_no_const;
35591
35592 struct ath_common;
35593 struct ath_bus_ops;
35594 diff --git a/drivers/net/wireless/ath/ath5k/base.c b/drivers/net/wireless/ath/ath5k/base.c
35595 index 2aab20e..b761ef8 100644
35596 --- a/drivers/net/wireless/ath/ath5k/base.c
35597 +++ b/drivers/net/wireless/ath/ath5k/base.c
35598 @@ -1803,7 +1803,7 @@ ath5k_beacon_update(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
35599 {
35600 int ret;
35601 struct ath5k_hw *ah = hw->priv;
35602 - struct ath5k_vif *avf = (void *)vif->drv_priv;
35603 + struct ath5k_vif *avf;
35604 struct sk_buff *skb;
35605
35606 if (WARN_ON(!vif)) {
35607 @@ -1818,6 +1818,7 @@ ath5k_beacon_update(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
35608 goto out;
35609 }
35610
35611 + avf = (void *)vif->drv_priv;
35612 ath5k_txbuf_free_skb(ah, avf->bbuf);
35613 avf->bbuf->skb = skb;
35614 ret = ath5k_beacon_setup(ah, avf->bbuf);
35615 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35616 index 8d78253..bebbb68 100644
35617 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35618 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35619 @@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35620 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35621 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35622
35623 - ACCESS_ONCE(ads->ds_link) = i->link;
35624 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35625 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
35626 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35627
35628 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35629 ctl6 = SM(i->keytype, AR_EncrType);
35630 @@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35631
35632 if ((i->is_first || i->is_last) &&
35633 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35634 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35635 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35636 | set11nTries(i->rates, 1)
35637 | set11nTries(i->rates, 2)
35638 | set11nTries(i->rates, 3)
35639 | (i->dur_update ? AR_DurUpdateEna : 0)
35640 | SM(0, AR_BurstDur);
35641
35642 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35643 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35644 | set11nRate(i->rates, 1)
35645 | set11nRate(i->rates, 2)
35646 | set11nRate(i->rates, 3);
35647 } else {
35648 - ACCESS_ONCE(ads->ds_ctl2) = 0;
35649 - ACCESS_ONCE(ads->ds_ctl3) = 0;
35650 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35651 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35652 }
35653
35654 if (!i->is_first) {
35655 - ACCESS_ONCE(ads->ds_ctl0) = 0;
35656 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35657 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35658 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35659 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35660 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35661 return;
35662 }
35663
35664 @@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35665 break;
35666 }
35667
35668 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35669 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35670 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35671 | SM(i->txpower, AR_XmitPower)
35672 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35673 @@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35674 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35675 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35676
35677 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35678 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35679 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35680 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35681
35682 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35683 return;
35684
35685 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35686 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35687 | set11nPktDurRTSCTS(i->rates, 1);
35688
35689 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35690 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35691 | set11nPktDurRTSCTS(i->rates, 3);
35692
35693 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35694 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35695 | set11nRateFlags(i->rates, 1)
35696 | set11nRateFlags(i->rates, 2)
35697 | set11nRateFlags(i->rates, 3)
35698 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35699 index 78816b8..1fcdfae 100644
35700 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35701 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35702 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35703 (i->qcu << AR_TxQcuNum_S) | desc_len;
35704
35705 checksum += val;
35706 - ACCESS_ONCE(ads->info) = val;
35707 + ACCESS_ONCE_RW(ads->info) = val;
35708
35709 checksum += i->link;
35710 - ACCESS_ONCE(ads->link) = i->link;
35711 + ACCESS_ONCE_RW(ads->link) = i->link;
35712
35713 checksum += i->buf_addr[0];
35714 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35715 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35716 checksum += i->buf_addr[1];
35717 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35718 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35719 checksum += i->buf_addr[2];
35720 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35721 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35722 checksum += i->buf_addr[3];
35723 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35724 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35725
35726 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35727 - ACCESS_ONCE(ads->ctl3) = val;
35728 + ACCESS_ONCE_RW(ads->ctl3) = val;
35729 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35730 - ACCESS_ONCE(ads->ctl5) = val;
35731 + ACCESS_ONCE_RW(ads->ctl5) = val;
35732 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35733 - ACCESS_ONCE(ads->ctl7) = val;
35734 + ACCESS_ONCE_RW(ads->ctl7) = val;
35735 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35736 - ACCESS_ONCE(ads->ctl9) = val;
35737 + ACCESS_ONCE_RW(ads->ctl9) = val;
35738
35739 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35740 - ACCESS_ONCE(ads->ctl10) = checksum;
35741 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
35742
35743 if (i->is_first || i->is_last) {
35744 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35745 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
35746 | set11nTries(i->rates, 1)
35747 | set11nTries(i->rates, 2)
35748 | set11nTries(i->rates, 3)
35749 | (i->dur_update ? AR_DurUpdateEna : 0)
35750 | SM(0, AR_BurstDur);
35751
35752 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
35753 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
35754 | set11nRate(i->rates, 1)
35755 | set11nRate(i->rates, 2)
35756 | set11nRate(i->rates, 3);
35757 } else {
35758 - ACCESS_ONCE(ads->ctl13) = 0;
35759 - ACCESS_ONCE(ads->ctl14) = 0;
35760 + ACCESS_ONCE_RW(ads->ctl13) = 0;
35761 + ACCESS_ONCE_RW(ads->ctl14) = 0;
35762 }
35763
35764 ads->ctl20 = 0;
35765 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35766
35767 ctl17 = SM(i->keytype, AR_EncrType);
35768 if (!i->is_first) {
35769 - ACCESS_ONCE(ads->ctl11) = 0;
35770 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35771 - ACCESS_ONCE(ads->ctl15) = 0;
35772 - ACCESS_ONCE(ads->ctl16) = 0;
35773 - ACCESS_ONCE(ads->ctl17) = ctl17;
35774 - ACCESS_ONCE(ads->ctl18) = 0;
35775 - ACCESS_ONCE(ads->ctl19) = 0;
35776 + ACCESS_ONCE_RW(ads->ctl11) = 0;
35777 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35778 + ACCESS_ONCE_RW(ads->ctl15) = 0;
35779 + ACCESS_ONCE_RW(ads->ctl16) = 0;
35780 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35781 + ACCESS_ONCE_RW(ads->ctl18) = 0;
35782 + ACCESS_ONCE_RW(ads->ctl19) = 0;
35783 return;
35784 }
35785
35786 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35787 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35788 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35789 | SM(i->txpower, AR_XmitPower)
35790 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35791 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35792 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
35793 ctl12 |= SM(val, AR_PAPRDChainMask);
35794
35795 - ACCESS_ONCE(ads->ctl12) = ctl12;
35796 - ACCESS_ONCE(ads->ctl17) = ctl17;
35797 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
35798 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35799
35800 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35801 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35802 | set11nPktDurRTSCTS(i->rates, 1);
35803
35804 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35805 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35806 | set11nPktDurRTSCTS(i->rates, 3);
35807
35808 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
35809 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
35810 | set11nRateFlags(i->rates, 1)
35811 | set11nRateFlags(i->rates, 2)
35812 | set11nRateFlags(i->rates, 3)
35813 | SM(i->rtscts_rate, AR_RTSCTSRate);
35814
35815 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
35816 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
35817 }
35818
35819 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
35820 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
35821 index de6968f..29ac4c1 100644
35822 --- a/drivers/net/wireless/ath/ath9k/hw.h
35823 +++ b/drivers/net/wireless/ath/ath9k/hw.h
35824 @@ -656,7 +656,7 @@ struct ath_hw_private_ops {
35825
35826 /* ANI */
35827 void (*ani_cache_ini_regs)(struct ath_hw *ah);
35828 -};
35829 +} __no_const;
35830
35831 /**
35832 * struct ath_hw_ops - callbacks used by hardware code and driver code
35833 @@ -686,7 +686,7 @@ struct ath_hw_ops {
35834 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
35835 struct ath_hw_antcomb_conf *antconf);
35836
35837 -};
35838 +} __no_const;
35839
35840 struct ath_nf_limits {
35841 s16 max;
35842 @@ -706,7 +706,7 @@ enum ath_cal_list {
35843 #define AH_FASTCC 0x4
35844
35845 struct ath_hw {
35846 - struct ath_ops reg_ops;
35847 + ath_ops_no_const reg_ops;
35848
35849 struct ieee80211_hw *hw;
35850 struct ath_common common;
35851 diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35852 index af00e2c..ab04d34 100644
35853 --- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35854 +++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35855 @@ -545,7 +545,7 @@ struct phy_func_ptr {
35856 void (*carrsuppr)(struct brcms_phy *);
35857 s32 (*rxsigpwr)(struct brcms_phy *, s32);
35858 void (*detach)(struct brcms_phy *);
35859 -};
35860 +} __no_const;
35861
35862 struct brcms_phy {
35863 struct brcms_phy_pub pubpi_ro;
35864 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
35865 index faec404..a5277f1 100644
35866 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
35867 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
35868 @@ -3611,7 +3611,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
35869 */
35870 if (il3945_mod_params.disable_hw_scan) {
35871 D_INFO("Disabling hw_scan\n");
35872 - il3945_mac_ops.hw_scan = NULL;
35873 + pax_open_kernel();
35874 + *(void **)&il3945_mac_ops.hw_scan = NULL;
35875 + pax_close_kernel();
35876 }
35877
35878 D_INFO("*** LOAD DRIVER ***\n");
35879 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35880 index a47b306..297daf2 100644
35881 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35882 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35883 @@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
35884 {
35885 struct iwl_priv *priv = file->private_data;
35886 char buf[64];
35887 - int buf_size;
35888 + size_t buf_size;
35889 u32 offset, len;
35890
35891 memset(buf, 0, sizeof(buf));
35892 @@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
35893 struct iwl_priv *priv = file->private_data;
35894
35895 char buf[8];
35896 - int buf_size;
35897 + size_t buf_size;
35898 u32 reset_flag;
35899
35900 memset(buf, 0, sizeof(buf));
35901 @@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
35902 {
35903 struct iwl_priv *priv = file->private_data;
35904 char buf[8];
35905 - int buf_size;
35906 + size_t buf_size;
35907 int ht40;
35908
35909 memset(buf, 0, sizeof(buf));
35910 @@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
35911 {
35912 struct iwl_priv *priv = file->private_data;
35913 char buf[8];
35914 - int buf_size;
35915 + size_t buf_size;
35916 int value;
35917
35918 memset(buf, 0, sizeof(buf));
35919 @@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
35920 {
35921 struct iwl_priv *priv = file->private_data;
35922 char buf[8];
35923 - int buf_size;
35924 + size_t buf_size;
35925 int clear;
35926
35927 memset(buf, 0, sizeof(buf));
35928 @@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
35929 {
35930 struct iwl_priv *priv = file->private_data;
35931 char buf[8];
35932 - int buf_size;
35933 + size_t buf_size;
35934 int trace;
35935
35936 memset(buf, 0, sizeof(buf));
35937 @@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
35938 {
35939 struct iwl_priv *priv = file->private_data;
35940 char buf[8];
35941 - int buf_size;
35942 + size_t buf_size;
35943 int missed;
35944
35945 memset(buf, 0, sizeof(buf));
35946 @@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
35947
35948 struct iwl_priv *priv = file->private_data;
35949 char buf[8];
35950 - int buf_size;
35951 + size_t buf_size;
35952 int plcp;
35953
35954 memset(buf, 0, sizeof(buf));
35955 @@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
35956
35957 struct iwl_priv *priv = file->private_data;
35958 char buf[8];
35959 - int buf_size;
35960 + size_t buf_size;
35961 int flush;
35962
35963 memset(buf, 0, sizeof(buf));
35964 @@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
35965
35966 struct iwl_priv *priv = file->private_data;
35967 char buf[8];
35968 - int buf_size;
35969 + size_t buf_size;
35970 int rts;
35971
35972 if (!priv->cfg->ht_params)
35973 @@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
35974 {
35975 struct iwl_priv *priv = file->private_data;
35976 char buf[8];
35977 - int buf_size;
35978 + size_t buf_size;
35979
35980 memset(buf, 0, sizeof(buf));
35981 buf_size = min(count, sizeof(buf) - 1);
35982 @@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
35983 struct iwl_priv *priv = file->private_data;
35984 u32 event_log_flag;
35985 char buf[8];
35986 - int buf_size;
35987 + size_t buf_size;
35988
35989 /* check that the interface is up */
35990 if (!iwl_is_ready(priv))
35991 @@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
35992 struct iwl_priv *priv = file->private_data;
35993 char buf[8];
35994 u32 calib_disabled;
35995 - int buf_size;
35996 + size_t buf_size;
35997
35998 memset(buf, 0, sizeof(buf));
35999 buf_size = min(count, sizeof(buf) - 1);
36000 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
36001 index dbeebef..b45a152 100644
36002 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
36003 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
36004 @@ -1944,7 +1944,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
36005 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
36006
36007 char buf[8];
36008 - int buf_size;
36009 + size_t buf_size;
36010 u32 reset_flag;
36011
36012 memset(buf, 0, sizeof(buf));
36013 @@ -1965,7 +1965,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
36014 {
36015 struct iwl_trans *trans = file->private_data;
36016 char buf[8];
36017 - int buf_size;
36018 + size_t buf_size;
36019 int csr;
36020
36021 memset(buf, 0, sizeof(buf));
36022 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
36023 index 0083839..fcb7225 100644
36024 --- a/drivers/net/wireless/mac80211_hwsim.c
36025 +++ b/drivers/net/wireless/mac80211_hwsim.c
36026 @@ -1748,9 +1748,11 @@ static int __init init_mac80211_hwsim(void)
36027 return -EINVAL;
36028
36029 if (fake_hw_scan) {
36030 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
36031 - mac80211_hwsim_ops.sw_scan_start = NULL;
36032 - mac80211_hwsim_ops.sw_scan_complete = NULL;
36033 + pax_open_kernel();
36034 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
36035 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
36036 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
36037 + pax_close_kernel();
36038 }
36039
36040 spin_lock_init(&hwsim_radio_lock);
36041 diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
36042 index e7c2a82..582e228 100644
36043 --- a/drivers/net/wireless/mwifiex/main.h
36044 +++ b/drivers/net/wireless/mwifiex/main.h
36045 @@ -571,7 +571,7 @@ struct mwifiex_if_ops {
36046 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
36047 int (*data_complete) (struct mwifiex_adapter *, struct sk_buff *);
36048 int (*dnld_fw) (struct mwifiex_adapter *, struct mwifiex_fw_image *);
36049 -};
36050 +} __no_const;
36051
36052 struct mwifiex_adapter {
36053 u8 iface_type;
36054 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
36055 index 7a4ae9e..56e00bd 100644
36056 --- a/drivers/net/wireless/rndis_wlan.c
36057 +++ b/drivers/net/wireless/rndis_wlan.c
36058 @@ -1235,7 +1235,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
36059
36060 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
36061
36062 - if (rts_threshold < 0 || rts_threshold > 2347)
36063 + if (rts_threshold > 2347)
36064 rts_threshold = 2347;
36065
36066 tmp = cpu_to_le32(rts_threshold);
36067 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
36068 index 8afb546..0c0dc5c 100644
36069 --- a/drivers/net/wireless/rt2x00/rt2x00.h
36070 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
36071 @@ -397,7 +397,7 @@ struct rt2x00_intf {
36072 * for hardware which doesn't support hardware
36073 * sequence counting.
36074 */
36075 - atomic_t seqno;
36076 + atomic_unchecked_t seqno;
36077 };
36078
36079 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
36080 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
36081 index f7e74a0..da71431 100644
36082 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
36083 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
36084 @@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
36085 * sequence counter given by mac80211.
36086 */
36087 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
36088 - seqno = atomic_add_return(0x10, &intf->seqno);
36089 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
36090 else
36091 - seqno = atomic_read(&intf->seqno);
36092 + seqno = atomic_read_unchecked(&intf->seqno);
36093
36094 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
36095 hdr->seq_ctrl |= cpu_to_le16(seqno);
36096 diff --git a/drivers/net/wireless/ti/wl1251/wl1251.h b/drivers/net/wireless/ti/wl1251/wl1251.h
36097 index fd02060..74ee481 100644
36098 --- a/drivers/net/wireless/ti/wl1251/wl1251.h
36099 +++ b/drivers/net/wireless/ti/wl1251/wl1251.h
36100 @@ -266,7 +266,7 @@ struct wl1251_if_operations {
36101 void (*reset)(struct wl1251 *wl);
36102 void (*enable_irq)(struct wl1251 *wl);
36103 void (*disable_irq)(struct wl1251 *wl);
36104 -};
36105 +} __no_const;
36106
36107 struct wl1251 {
36108 struct ieee80211_hw *hw;
36109 diff --git a/drivers/net/wireless/ti/wlcore/wlcore.h b/drivers/net/wireless/ti/wlcore/wlcore.h
36110 index 0ce7a8e..56a0ccf 100644
36111 --- a/drivers/net/wireless/ti/wlcore/wlcore.h
36112 +++ b/drivers/net/wireless/ti/wlcore/wlcore.h
36113 @@ -81,7 +81,7 @@ struct wlcore_ops {
36114 struct ieee80211_sta *sta,
36115 struct ieee80211_key_conf *key_conf);
36116 u32 (*pre_pkt_send)(struct wl1271 *wl, u32 buf_offset, u32 last_len);
36117 -};
36118 +} __no_const;
36119
36120 enum wlcore_partitions {
36121 PART_DOWN,
36122 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
36123 index f34b5b2..b5abb9f 100644
36124 --- a/drivers/oprofile/buffer_sync.c
36125 +++ b/drivers/oprofile/buffer_sync.c
36126 @@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
36127 if (cookie == NO_COOKIE)
36128 offset = pc;
36129 if (cookie == INVALID_COOKIE) {
36130 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36131 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36132 offset = pc;
36133 }
36134 if (cookie != last_cookie) {
36135 @@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
36136 /* add userspace sample */
36137
36138 if (!mm) {
36139 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
36140 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
36141 return 0;
36142 }
36143
36144 cookie = lookup_dcookie(mm, s->eip, &offset);
36145
36146 if (cookie == INVALID_COOKIE) {
36147 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36148 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36149 return 0;
36150 }
36151
36152 @@ -563,7 +563,7 @@ void sync_buffer(int cpu)
36153 /* ignore backtraces if failed to add a sample */
36154 if (state == sb_bt_start) {
36155 state = sb_bt_ignore;
36156 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
36157 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
36158 }
36159 }
36160 release_mm(mm);
36161 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
36162 index c0cc4e7..44d4e54 100644
36163 --- a/drivers/oprofile/event_buffer.c
36164 +++ b/drivers/oprofile/event_buffer.c
36165 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
36166 }
36167
36168 if (buffer_pos == buffer_size) {
36169 - atomic_inc(&oprofile_stats.event_lost_overflow);
36170 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
36171 return;
36172 }
36173
36174 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
36175 index ed2c3ec..deda85a 100644
36176 --- a/drivers/oprofile/oprof.c
36177 +++ b/drivers/oprofile/oprof.c
36178 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
36179 if (oprofile_ops.switch_events())
36180 return;
36181
36182 - atomic_inc(&oprofile_stats.multiplex_counter);
36183 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
36184 start_switch_worker();
36185 }
36186
36187 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
36188 index 917d28e..d62d981 100644
36189 --- a/drivers/oprofile/oprofile_stats.c
36190 +++ b/drivers/oprofile/oprofile_stats.c
36191 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
36192 cpu_buf->sample_invalid_eip = 0;
36193 }
36194
36195 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
36196 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
36197 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
36198 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
36199 - atomic_set(&oprofile_stats.multiplex_counter, 0);
36200 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
36201 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
36202 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
36203 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
36204 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
36205 }
36206
36207
36208 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
36209 index 38b6fc0..b5cbfce 100644
36210 --- a/drivers/oprofile/oprofile_stats.h
36211 +++ b/drivers/oprofile/oprofile_stats.h
36212 @@ -13,11 +13,11 @@
36213 #include <linux/atomic.h>
36214
36215 struct oprofile_stat_struct {
36216 - atomic_t sample_lost_no_mm;
36217 - atomic_t sample_lost_no_mapping;
36218 - atomic_t bt_lost_no_mapping;
36219 - atomic_t event_lost_overflow;
36220 - atomic_t multiplex_counter;
36221 + atomic_unchecked_t sample_lost_no_mm;
36222 + atomic_unchecked_t sample_lost_no_mapping;
36223 + atomic_unchecked_t bt_lost_no_mapping;
36224 + atomic_unchecked_t event_lost_overflow;
36225 + atomic_unchecked_t multiplex_counter;
36226 };
36227
36228 extern struct oprofile_stat_struct oprofile_stats;
36229 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
36230 index 849357c..b83c1e0 100644
36231 --- a/drivers/oprofile/oprofilefs.c
36232 +++ b/drivers/oprofile/oprofilefs.c
36233 @@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
36234
36235
36236 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
36237 - char const *name, atomic_t *val)
36238 + char const *name, atomic_unchecked_t *val)
36239 {
36240 return __oprofilefs_create_file(sb, root, name,
36241 &atomic_ro_fops, 0444, val);
36242 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
36243 index 3f56bc0..707d642 100644
36244 --- a/drivers/parport/procfs.c
36245 +++ b/drivers/parport/procfs.c
36246 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
36247
36248 *ppos += len;
36249
36250 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
36251 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
36252 }
36253
36254 #ifdef CONFIG_PARPORT_1284
36255 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
36256
36257 *ppos += len;
36258
36259 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
36260 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
36261 }
36262 #endif /* IEEE1284.3 support. */
36263
36264 diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
36265 index 9fff878..ad0ad53 100644
36266 --- a/drivers/pci/hotplug/cpci_hotplug.h
36267 +++ b/drivers/pci/hotplug/cpci_hotplug.h
36268 @@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
36269 int (*hardware_test) (struct slot* slot, u32 value);
36270 u8 (*get_power) (struct slot* slot);
36271 int (*set_power) (struct slot* slot, int value);
36272 -};
36273 +} __no_const;
36274
36275 struct cpci_hp_controller {
36276 unsigned int irq;
36277 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
36278 index 76ba8a1..20ca857 100644
36279 --- a/drivers/pci/hotplug/cpqphp_nvram.c
36280 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
36281 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
36282
36283 void compaq_nvram_init (void __iomem *rom_start)
36284 {
36285 +
36286 +#ifndef CONFIG_PAX_KERNEXEC
36287 if (rom_start) {
36288 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
36289 }
36290 +#endif
36291 +
36292 dbg("int15 entry = %p\n", compaq_int15_entry_point);
36293
36294 /* initialize our int15 lock */
36295 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
36296 index b500840..d7159d3 100644
36297 --- a/drivers/pci/pcie/aspm.c
36298 +++ b/drivers/pci/pcie/aspm.c
36299 @@ -27,9 +27,9 @@
36300 #define MODULE_PARAM_PREFIX "pcie_aspm."
36301
36302 /* Note: those are not register definitions */
36303 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
36304 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
36305 -#define ASPM_STATE_L1 (4) /* L1 state */
36306 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
36307 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
36308 +#define ASPM_STATE_L1 (4U) /* L1 state */
36309 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
36310 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
36311
36312 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
36313 index 61859d0..124539e 100644
36314 --- a/drivers/pci/probe.c
36315 +++ b/drivers/pci/probe.c
36316 @@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
36317 struct pci_bus_region region;
36318 bool bar_too_big = false, bar_disabled = false;
36319
36320 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
36321 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
36322
36323 /* No printks while decoding is disabled! */
36324 if (!dev->mmio_always_on) {
36325 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
36326 index 27911b5..5b6db88 100644
36327 --- a/drivers/pci/proc.c
36328 +++ b/drivers/pci/proc.c
36329 @@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
36330 static int __init pci_proc_init(void)
36331 {
36332 struct pci_dev *dev = NULL;
36333 +
36334 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
36335 +#ifdef CONFIG_GRKERNSEC_PROC_USER
36336 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
36337 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
36338 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
36339 +#endif
36340 +#else
36341 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
36342 +#endif
36343 proc_create("devices", 0, proc_bus_pci_dir,
36344 &proc_bus_pci_dev_operations);
36345 proc_initialized = 1;
36346 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
36347 index 52daaa8..d6b81eb 100644
36348 --- a/drivers/platform/x86/thinkpad_acpi.c
36349 +++ b/drivers/platform/x86/thinkpad_acpi.c
36350 @@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
36351 return 0;
36352 }
36353
36354 -void static hotkey_mask_warn_incomplete_mask(void)
36355 +static void hotkey_mask_warn_incomplete_mask(void)
36356 {
36357 /* log only what the user can fix... */
36358 const u32 wantedmask = hotkey_driver_mask &
36359 @@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
36360 }
36361 }
36362
36363 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36364 - struct tp_nvram_state *newn,
36365 - const u32 event_mask)
36366 -{
36367 -
36368 #define TPACPI_COMPARE_KEY(__scancode, __member) \
36369 do { \
36370 if ((event_mask & (1 << __scancode)) && \
36371 @@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36372 tpacpi_hotkey_send_key(__scancode); \
36373 } while (0)
36374
36375 - void issue_volchange(const unsigned int oldvol,
36376 - const unsigned int newvol)
36377 - {
36378 - unsigned int i = oldvol;
36379 +static void issue_volchange(const unsigned int oldvol,
36380 + const unsigned int newvol,
36381 + const u32 event_mask)
36382 +{
36383 + unsigned int i = oldvol;
36384
36385 - while (i > newvol) {
36386 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36387 - i--;
36388 - }
36389 - while (i < newvol) {
36390 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36391 - i++;
36392 - }
36393 + while (i > newvol) {
36394 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36395 + i--;
36396 }
36397 + while (i < newvol) {
36398 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36399 + i++;
36400 + }
36401 +}
36402
36403 - void issue_brightnesschange(const unsigned int oldbrt,
36404 - const unsigned int newbrt)
36405 - {
36406 - unsigned int i = oldbrt;
36407 +static void issue_brightnesschange(const unsigned int oldbrt,
36408 + const unsigned int newbrt,
36409 + const u32 event_mask)
36410 +{
36411 + unsigned int i = oldbrt;
36412
36413 - while (i > newbrt) {
36414 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36415 - i--;
36416 - }
36417 - while (i < newbrt) {
36418 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36419 - i++;
36420 - }
36421 + while (i > newbrt) {
36422 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36423 + i--;
36424 + }
36425 + while (i < newbrt) {
36426 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36427 + i++;
36428 }
36429 +}
36430
36431 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36432 + struct tp_nvram_state *newn,
36433 + const u32 event_mask)
36434 +{
36435 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
36436 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
36437 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
36438 @@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36439 oldn->volume_level != newn->volume_level) {
36440 /* recently muted, or repeated mute keypress, or
36441 * multiple presses ending in mute */
36442 - issue_volchange(oldn->volume_level, newn->volume_level);
36443 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36444 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
36445 }
36446 } else {
36447 @@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36448 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36449 }
36450 if (oldn->volume_level != newn->volume_level) {
36451 - issue_volchange(oldn->volume_level, newn->volume_level);
36452 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36453 } else if (oldn->volume_toggle != newn->volume_toggle) {
36454 /* repeated vol up/down keypress at end of scale ? */
36455 if (newn->volume_level == 0)
36456 @@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36457 /* handle brightness */
36458 if (oldn->brightness_level != newn->brightness_level) {
36459 issue_brightnesschange(oldn->brightness_level,
36460 - newn->brightness_level);
36461 + newn->brightness_level,
36462 + event_mask);
36463 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
36464 /* repeated key presses that didn't change state */
36465 if (newn->brightness_level == 0)
36466 @@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36467 && !tp_features.bright_unkfw)
36468 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36469 }
36470 +}
36471
36472 #undef TPACPI_COMPARE_KEY
36473 #undef TPACPI_MAY_SEND_KEY
36474 -}
36475
36476 /*
36477 * Polling driver
36478 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
36479 index 769d265..a3a05ca 100644
36480 --- a/drivers/pnp/pnpbios/bioscalls.c
36481 +++ b/drivers/pnp/pnpbios/bioscalls.c
36482 @@ -58,7 +58,7 @@ do { \
36483 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
36484 } while(0)
36485
36486 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
36487 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
36488 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
36489
36490 /*
36491 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36492
36493 cpu = get_cpu();
36494 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
36495 +
36496 + pax_open_kernel();
36497 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
36498 + pax_close_kernel();
36499
36500 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
36501 spin_lock_irqsave(&pnp_bios_lock, flags);
36502 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36503 :"memory");
36504 spin_unlock_irqrestore(&pnp_bios_lock, flags);
36505
36506 + pax_open_kernel();
36507 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
36508 + pax_close_kernel();
36509 +
36510 put_cpu();
36511
36512 /* If we get here and this is set then the PnP BIOS faulted on us. */
36513 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
36514 return status;
36515 }
36516
36517 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
36518 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
36519 {
36520 int i;
36521
36522 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36523 pnp_bios_callpoint.offset = header->fields.pm16offset;
36524 pnp_bios_callpoint.segment = PNP_CS16;
36525
36526 + pax_open_kernel();
36527 +
36528 for_each_possible_cpu(i) {
36529 struct desc_struct *gdt = get_cpu_gdt_table(i);
36530 if (!gdt)
36531 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36532 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
36533 (unsigned long)__va(header->fields.pm16dseg));
36534 }
36535 +
36536 + pax_close_kernel();
36537 }
36538 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
36539 index b0ecacb..7c9da2e 100644
36540 --- a/drivers/pnp/resource.c
36541 +++ b/drivers/pnp/resource.c
36542 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
36543 return 1;
36544
36545 /* check if the resource is valid */
36546 - if (*irq < 0 || *irq > 15)
36547 + if (*irq > 15)
36548 return 0;
36549
36550 /* check if the resource is reserved */
36551 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
36552 return 1;
36553
36554 /* check if the resource is valid */
36555 - if (*dma < 0 || *dma == 4 || *dma > 7)
36556 + if (*dma == 4 || *dma > 7)
36557 return 0;
36558
36559 /* check if the resource is reserved */
36560 diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
36561 index 181ddec..774b6da 100644
36562 --- a/drivers/power/bq27x00_battery.c
36563 +++ b/drivers/power/bq27x00_battery.c
36564 @@ -80,7 +80,7 @@
36565 struct bq27x00_device_info;
36566 struct bq27x00_access_methods {
36567 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36568 -};
36569 +} __no_const;
36570
36571 enum bq27x00_chip { BQ27000, BQ27500, BQ27425};
36572
36573 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36574 index 8d53174..04c65de 100644
36575 --- a/drivers/regulator/max8660.c
36576 +++ b/drivers/regulator/max8660.c
36577 @@ -333,8 +333,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36578 max8660->shadow_regs[MAX8660_OVER1] = 5;
36579 } else {
36580 /* Otherwise devices can be toggled via software */
36581 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
36582 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
36583 + pax_open_kernel();
36584 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36585 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36586 + pax_close_kernel();
36587 }
36588
36589 /*
36590 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36591 index b388b74..ed82573 100644
36592 --- a/drivers/regulator/mc13892-regulator.c
36593 +++ b/drivers/regulator/mc13892-regulator.c
36594 @@ -565,10 +565,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36595 }
36596 mc13xxx_unlock(mc13892);
36597
36598 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36599 + pax_open_kernel();
36600 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36601 = mc13892_vcam_set_mode;
36602 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36603 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36604 = mc13892_vcam_get_mode;
36605 + pax_close_kernel();
36606
36607 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36608 ARRAY_SIZE(mc13892_regulators));
36609 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36610 index cace6d3..f623fda 100644
36611 --- a/drivers/rtc/rtc-dev.c
36612 +++ b/drivers/rtc/rtc-dev.c
36613 @@ -14,6 +14,7 @@
36614 #include <linux/module.h>
36615 #include <linux/rtc.h>
36616 #include <linux/sched.h>
36617 +#include <linux/grsecurity.h>
36618 #include "rtc-core.h"
36619
36620 static dev_t rtc_devt;
36621 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36622 if (copy_from_user(&tm, uarg, sizeof(tm)))
36623 return -EFAULT;
36624
36625 + gr_log_timechange();
36626 +
36627 return rtc_set_time(rtc, &tm);
36628
36629 case RTC_PIE_ON:
36630 diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36631 index 9e933a8..4f969f7 100644
36632 --- a/drivers/scsi/aacraid/aacraid.h
36633 +++ b/drivers/scsi/aacraid/aacraid.h
36634 @@ -503,7 +503,7 @@ struct adapter_ops
36635 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36636 /* Administrative operations */
36637 int (*adapter_comm)(struct aac_dev * dev, int comm);
36638 -};
36639 +} __no_const;
36640
36641 /*
36642 * Define which interrupt handler needs to be installed
36643 diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
36644 index 7199534..cb7f158 100644
36645 --- a/drivers/scsi/aacraid/linit.c
36646 +++ b/drivers/scsi/aacraid/linit.c
36647 @@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
36648 #elif defined(__devinitconst)
36649 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36650 #else
36651 -static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
36652 +static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36653 #endif
36654 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
36655 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
36656 diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
36657 index ff80552..1c4120c 100644
36658 --- a/drivers/scsi/aic94xx/aic94xx_init.c
36659 +++ b/drivers/scsi/aic94xx/aic94xx_init.c
36660 @@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
36661 .lldd_ata_set_dmamode = asd_set_dmamode,
36662 };
36663
36664 -static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
36665 +static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
36666 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
36667 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
36668 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
36669 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36670 index 4ad7e36..d004679 100644
36671 --- a/drivers/scsi/bfa/bfa.h
36672 +++ b/drivers/scsi/bfa/bfa.h
36673 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
36674 u32 *end);
36675 int cpe_vec_q0;
36676 int rme_vec_q0;
36677 -};
36678 +} __no_const;
36679 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36680
36681 struct bfa_faa_cbfn_s {
36682 diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36683 index f0f80e2..8ec946b 100644
36684 --- a/drivers/scsi/bfa/bfa_fcpim.c
36685 +++ b/drivers/scsi/bfa/bfa_fcpim.c
36686 @@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36687
36688 bfa_iotag_attach(fcp);
36689
36690 - fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36691 + fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36692 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36693 (fcp->num_itns * sizeof(struct bfa_itn_s));
36694 memset(fcp->itn_arr, 0,
36695 @@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36696 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36697 {
36698 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36699 - struct bfa_itn_s *itn;
36700 + bfa_itn_s_no_const *itn;
36701
36702 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36703 itn->isr = isr;
36704 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36705 index 36f26da..38a34a8 100644
36706 --- a/drivers/scsi/bfa/bfa_fcpim.h
36707 +++ b/drivers/scsi/bfa/bfa_fcpim.h
36708 @@ -37,6 +37,7 @@ struct bfa_iotag_s {
36709 struct bfa_itn_s {
36710 bfa_isr_func_t isr;
36711 };
36712 +typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36713
36714 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36715 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36716 @@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
36717 struct list_head iotag_tio_free_q; /* free IO resources */
36718 struct list_head iotag_unused_q; /* unused IO resources*/
36719 struct bfa_iotag_s *iotag_arr;
36720 - struct bfa_itn_s *itn_arr;
36721 + bfa_itn_s_no_const *itn_arr;
36722 int num_ioim_reqs;
36723 int num_fwtio_reqs;
36724 int num_itns;
36725 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36726 index 1a99d4b..e85d64b 100644
36727 --- a/drivers/scsi/bfa/bfa_ioc.h
36728 +++ b/drivers/scsi/bfa/bfa_ioc.h
36729 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36730 bfa_ioc_disable_cbfn_t disable_cbfn;
36731 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36732 bfa_ioc_reset_cbfn_t reset_cbfn;
36733 -};
36734 +} __no_const;
36735
36736 /*
36737 * IOC event notification mechanism.
36738 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36739 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36740 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36741 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36742 -};
36743 +} __no_const;
36744
36745 /*
36746 * Queue element to wait for room in request queue. FIFO order is
36747 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36748 index 593085a..47aa999 100644
36749 --- a/drivers/scsi/hosts.c
36750 +++ b/drivers/scsi/hosts.c
36751 @@ -42,7 +42,7 @@
36752 #include "scsi_logging.h"
36753
36754
36755 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
36756 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
36757
36758
36759 static void scsi_host_cls_release(struct device *dev)
36760 @@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36761 * subtract one because we increment first then return, but we need to
36762 * know what the next host number was before increment
36763 */
36764 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36765 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36766 shost->dma_channel = 0xff;
36767
36768 /* These three are default values which can be overridden */
36769 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
36770 index f9823f2..7bc3e81 100644
36771 --- a/drivers/scsi/hpsa.c
36772 +++ b/drivers/scsi/hpsa.c
36773 @@ -536,7 +536,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
36774 unsigned long flags;
36775
36776 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36777 - return h->access.command_completed(h, q);
36778 + return h->access->command_completed(h, q);
36779
36780 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
36781 a = rq->head[rq->current_entry];
36782 @@ -3355,7 +3355,7 @@ static void start_io(struct ctlr_info *h)
36783 while (!list_empty(&h->reqQ)) {
36784 c = list_entry(h->reqQ.next, struct CommandList, list);
36785 /* can't do anything if fifo is full */
36786 - if ((h->access.fifo_full(h))) {
36787 + if ((h->access->fifo_full(h))) {
36788 dev_warn(&h->pdev->dev, "fifo full\n");
36789 break;
36790 }
36791 @@ -3377,7 +3377,7 @@ static void start_io(struct ctlr_info *h)
36792
36793 /* Tell the controller execute command */
36794 spin_unlock_irqrestore(&h->lock, flags);
36795 - h->access.submit_command(h, c);
36796 + h->access->submit_command(h, c);
36797 spin_lock_irqsave(&h->lock, flags);
36798 }
36799 spin_unlock_irqrestore(&h->lock, flags);
36800 @@ -3385,17 +3385,17 @@ static void start_io(struct ctlr_info *h)
36801
36802 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
36803 {
36804 - return h->access.command_completed(h, q);
36805 + return h->access->command_completed(h, q);
36806 }
36807
36808 static inline bool interrupt_pending(struct ctlr_info *h)
36809 {
36810 - return h->access.intr_pending(h);
36811 + return h->access->intr_pending(h);
36812 }
36813
36814 static inline long interrupt_not_for_us(struct ctlr_info *h)
36815 {
36816 - return (h->access.intr_pending(h) == 0) ||
36817 + return (h->access->intr_pending(h) == 0) ||
36818 (h->interrupts_enabled == 0);
36819 }
36820
36821 @@ -4299,7 +4299,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
36822 if (prod_index < 0)
36823 return -ENODEV;
36824 h->product_name = products[prod_index].product_name;
36825 - h->access = *(products[prod_index].access);
36826 + h->access = products[prod_index].access;
36827
36828 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
36829 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
36830 @@ -4581,7 +4581,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
36831
36832 assert_spin_locked(&lockup_detector_lock);
36833 remove_ctlr_from_lockup_detector_list(h);
36834 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36835 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36836 spin_lock_irqsave(&h->lock, flags);
36837 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
36838 spin_unlock_irqrestore(&h->lock, flags);
36839 @@ -4759,7 +4759,7 @@ reinit_after_soft_reset:
36840 }
36841
36842 /* make sure the board interrupts are off */
36843 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36844 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36845
36846 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
36847 goto clean2;
36848 @@ -4793,7 +4793,7 @@ reinit_after_soft_reset:
36849 * fake ones to scoop up any residual completions.
36850 */
36851 spin_lock_irqsave(&h->lock, flags);
36852 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36853 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36854 spin_unlock_irqrestore(&h->lock, flags);
36855 free_irqs(h);
36856 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
36857 @@ -4812,9 +4812,9 @@ reinit_after_soft_reset:
36858 dev_info(&h->pdev->dev, "Board READY.\n");
36859 dev_info(&h->pdev->dev,
36860 "Waiting for stale completions to drain.\n");
36861 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36862 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36863 msleep(10000);
36864 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36865 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36866
36867 rc = controller_reset_failed(h->cfgtable);
36868 if (rc)
36869 @@ -4835,7 +4835,7 @@ reinit_after_soft_reset:
36870 }
36871
36872 /* Turn the interrupts on so we can service requests */
36873 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36874 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36875
36876 hpsa_hba_inquiry(h);
36877 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
36878 @@ -4887,7 +4887,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
36879 * To write all data in the battery backed cache to disks
36880 */
36881 hpsa_flush_cache(h);
36882 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36883 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36884 hpsa_free_irqs_and_disable_msix(h);
36885 }
36886
36887 @@ -5056,7 +5056,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
36888 return;
36889 }
36890 /* Change the access methods to the performant access methods */
36891 - h->access = SA5_performant_access;
36892 + h->access = &SA5_performant_access;
36893 h->transMethod = CFGTBL_Trans_Performant;
36894 }
36895
36896 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
36897 index 9816479..c5d4e97 100644
36898 --- a/drivers/scsi/hpsa.h
36899 +++ b/drivers/scsi/hpsa.h
36900 @@ -79,7 +79,7 @@ struct ctlr_info {
36901 unsigned int msix_vector;
36902 unsigned int msi_vector;
36903 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
36904 - struct access_method access;
36905 + struct access_method *access;
36906
36907 /* queue and queue Info */
36908 struct list_head reqQ;
36909 diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
36910 index f2df059..a3a9930 100644
36911 --- a/drivers/scsi/ips.h
36912 +++ b/drivers/scsi/ips.h
36913 @@ -1027,7 +1027,7 @@ typedef struct {
36914 int (*intr)(struct ips_ha *);
36915 void (*enableint)(struct ips_ha *);
36916 uint32_t (*statupd)(struct ips_ha *);
36917 -} ips_hw_func_t;
36918 +} __no_const ips_hw_func_t;
36919
36920 typedef struct ips_ha {
36921 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36922 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
36923 index c772d8d..35c362c 100644
36924 --- a/drivers/scsi/libfc/fc_exch.c
36925 +++ b/drivers/scsi/libfc/fc_exch.c
36926 @@ -100,12 +100,12 @@ struct fc_exch_mgr {
36927 u16 pool_max_index;
36928
36929 struct {
36930 - atomic_t no_free_exch;
36931 - atomic_t no_free_exch_xid;
36932 - atomic_t xid_not_found;
36933 - atomic_t xid_busy;
36934 - atomic_t seq_not_found;
36935 - atomic_t non_bls_resp;
36936 + atomic_unchecked_t no_free_exch;
36937 + atomic_unchecked_t no_free_exch_xid;
36938 + atomic_unchecked_t xid_not_found;
36939 + atomic_unchecked_t xid_busy;
36940 + atomic_unchecked_t seq_not_found;
36941 + atomic_unchecked_t non_bls_resp;
36942 } stats;
36943 };
36944
36945 @@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
36946 /* allocate memory for exchange */
36947 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
36948 if (!ep) {
36949 - atomic_inc(&mp->stats.no_free_exch);
36950 + atomic_inc_unchecked(&mp->stats.no_free_exch);
36951 goto out;
36952 }
36953 memset(ep, 0, sizeof(*ep));
36954 @@ -786,7 +786,7 @@ out:
36955 return ep;
36956 err:
36957 spin_unlock_bh(&pool->lock);
36958 - atomic_inc(&mp->stats.no_free_exch_xid);
36959 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
36960 mempool_free(ep, mp->ep_pool);
36961 return NULL;
36962 }
36963 @@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36964 xid = ntohs(fh->fh_ox_id); /* we originated exch */
36965 ep = fc_exch_find(mp, xid);
36966 if (!ep) {
36967 - atomic_inc(&mp->stats.xid_not_found);
36968 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36969 reject = FC_RJT_OX_ID;
36970 goto out;
36971 }
36972 @@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36973 ep = fc_exch_find(mp, xid);
36974 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
36975 if (ep) {
36976 - atomic_inc(&mp->stats.xid_busy);
36977 + atomic_inc_unchecked(&mp->stats.xid_busy);
36978 reject = FC_RJT_RX_ID;
36979 goto rel;
36980 }
36981 @@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36982 }
36983 xid = ep->xid; /* get our XID */
36984 } else if (!ep) {
36985 - atomic_inc(&mp->stats.xid_not_found);
36986 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36987 reject = FC_RJT_RX_ID; /* XID not found */
36988 goto out;
36989 }
36990 @@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36991 } else {
36992 sp = &ep->seq;
36993 if (sp->id != fh->fh_seq_id) {
36994 - atomic_inc(&mp->stats.seq_not_found);
36995 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36996 if (f_ctl & FC_FC_END_SEQ) {
36997 /*
36998 * Update sequence_id based on incoming last
36999 @@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
37000
37001 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
37002 if (!ep) {
37003 - atomic_inc(&mp->stats.xid_not_found);
37004 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37005 goto out;
37006 }
37007 if (ep->esb_stat & ESB_ST_COMPLETE) {
37008 - atomic_inc(&mp->stats.xid_not_found);
37009 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37010 goto rel;
37011 }
37012 if (ep->rxid == FC_XID_UNKNOWN)
37013 ep->rxid = ntohs(fh->fh_rx_id);
37014 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
37015 - atomic_inc(&mp->stats.xid_not_found);
37016 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37017 goto rel;
37018 }
37019 if (ep->did != ntoh24(fh->fh_s_id) &&
37020 ep->did != FC_FID_FLOGI) {
37021 - atomic_inc(&mp->stats.xid_not_found);
37022 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37023 goto rel;
37024 }
37025 sof = fr_sof(fp);
37026 @@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
37027 sp->ssb_stat |= SSB_ST_RESP;
37028 sp->id = fh->fh_seq_id;
37029 } else if (sp->id != fh->fh_seq_id) {
37030 - atomic_inc(&mp->stats.seq_not_found);
37031 + atomic_inc_unchecked(&mp->stats.seq_not_found);
37032 goto rel;
37033 }
37034
37035 @@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
37036 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
37037
37038 if (!sp)
37039 - atomic_inc(&mp->stats.xid_not_found);
37040 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37041 else
37042 - atomic_inc(&mp->stats.non_bls_resp);
37043 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
37044
37045 fc_frame_free(fp);
37046 }
37047 @@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
37048
37049 list_for_each_entry(ema, &lport->ema_list, ema_list) {
37050 mp = ema->mp;
37051 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
37052 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
37053 st->fc_no_free_exch_xid +=
37054 - atomic_read(&mp->stats.no_free_exch_xid);
37055 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
37056 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
37057 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
37058 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
37059 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
37060 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
37061 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
37062 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
37063 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
37064 }
37065 }
37066 EXPORT_SYMBOL(fc_exch_update_stats);
37067 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
37068 index a59fcdc..abe55f3 100644
37069 --- a/drivers/scsi/libsas/sas_ata.c
37070 +++ b/drivers/scsi/libsas/sas_ata.c
37071 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
37072 .postreset = ata_std_postreset,
37073 .error_handler = ata_std_error_handler,
37074 .post_internal_cmd = sas_ata_post_internal,
37075 - .qc_defer = ata_std_qc_defer,
37076 + .qc_defer = ata_std_qc_defer,
37077 .qc_prep = ata_noop_qc_prep,
37078 .qc_issue = sas_ata_qc_issue,
37079 .qc_fill_rtf = sas_ata_qc_fill_rtf,
37080 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
37081 index a65c05a..a39e402 100644
37082 --- a/drivers/scsi/lpfc/lpfc.h
37083 +++ b/drivers/scsi/lpfc/lpfc.h
37084 @@ -420,7 +420,7 @@ struct lpfc_vport {
37085 struct dentry *debug_nodelist;
37086 struct dentry *vport_debugfs_root;
37087 struct lpfc_debugfs_trc *disc_trc;
37088 - atomic_t disc_trc_cnt;
37089 + atomic_unchecked_t disc_trc_cnt;
37090 #endif
37091 uint8_t stat_data_enabled;
37092 uint8_t stat_data_blocked;
37093 @@ -834,8 +834,8 @@ struct lpfc_hba {
37094 struct timer_list fabric_block_timer;
37095 unsigned long bit_flags;
37096 #define FABRIC_COMANDS_BLOCKED 0
37097 - atomic_t num_rsrc_err;
37098 - atomic_t num_cmd_success;
37099 + atomic_unchecked_t num_rsrc_err;
37100 + atomic_unchecked_t num_cmd_success;
37101 unsigned long last_rsrc_error_time;
37102 unsigned long last_ramp_down_time;
37103 unsigned long last_ramp_up_time;
37104 @@ -871,7 +871,7 @@ struct lpfc_hba {
37105
37106 struct dentry *debug_slow_ring_trc;
37107 struct lpfc_debugfs_trc *slow_ring_trc;
37108 - atomic_t slow_ring_trc_cnt;
37109 + atomic_unchecked_t slow_ring_trc_cnt;
37110 /* iDiag debugfs sub-directory */
37111 struct dentry *idiag_root;
37112 struct dentry *idiag_pci_cfg;
37113 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
37114 index 3217d63..c417981 100644
37115 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
37116 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
37117 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
37118
37119 #include <linux/debugfs.h>
37120
37121 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37122 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37123 static unsigned long lpfc_debugfs_start_time = 0L;
37124
37125 /* iDiag */
37126 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
37127 lpfc_debugfs_enable = 0;
37128
37129 len = 0;
37130 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
37131 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
37132 (lpfc_debugfs_max_disc_trc - 1);
37133 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
37134 dtp = vport->disc_trc + i;
37135 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
37136 lpfc_debugfs_enable = 0;
37137
37138 len = 0;
37139 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
37140 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
37141 (lpfc_debugfs_max_slow_ring_trc - 1);
37142 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
37143 dtp = phba->slow_ring_trc + i;
37144 @@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
37145 !vport || !vport->disc_trc)
37146 return;
37147
37148 - index = atomic_inc_return(&vport->disc_trc_cnt) &
37149 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
37150 (lpfc_debugfs_max_disc_trc - 1);
37151 dtp = vport->disc_trc + index;
37152 dtp->fmt = fmt;
37153 dtp->data1 = data1;
37154 dtp->data2 = data2;
37155 dtp->data3 = data3;
37156 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37157 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37158 dtp->jif = jiffies;
37159 #endif
37160 return;
37161 @@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
37162 !phba || !phba->slow_ring_trc)
37163 return;
37164
37165 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
37166 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
37167 (lpfc_debugfs_max_slow_ring_trc - 1);
37168 dtp = phba->slow_ring_trc + index;
37169 dtp->fmt = fmt;
37170 dtp->data1 = data1;
37171 dtp->data2 = data2;
37172 dtp->data3 = data3;
37173 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37174 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37175 dtp->jif = jiffies;
37176 #endif
37177 return;
37178 @@ -4090,7 +4090,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37179 "slow_ring buffer\n");
37180 goto debug_failed;
37181 }
37182 - atomic_set(&phba->slow_ring_trc_cnt, 0);
37183 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
37184 memset(phba->slow_ring_trc, 0,
37185 (sizeof(struct lpfc_debugfs_trc) *
37186 lpfc_debugfs_max_slow_ring_trc));
37187 @@ -4136,7 +4136,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37188 "buffer\n");
37189 goto debug_failed;
37190 }
37191 - atomic_set(&vport->disc_trc_cnt, 0);
37192 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
37193
37194 snprintf(name, sizeof(name), "discovery_trace");
37195 vport->debug_disc_trc =
37196 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
37197 index 45c1520..35ba744 100644
37198 --- a/drivers/scsi/lpfc/lpfc_init.c
37199 +++ b/drivers/scsi/lpfc/lpfc_init.c
37200 @@ -10478,8 +10478,10 @@ lpfc_init(void)
37201 "misc_register returned with status %d", error);
37202
37203 if (lpfc_enable_npiv) {
37204 - lpfc_transport_functions.vport_create = lpfc_vport_create;
37205 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37206 + pax_open_kernel();
37207 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
37208 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37209 + pax_close_kernel();
37210 }
37211 lpfc_transport_template =
37212 fc_attach_transport(&lpfc_transport_functions);
37213 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
37214 index 925975d..0f1fc07 100644
37215 --- a/drivers/scsi/lpfc/lpfc_scsi.c
37216 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
37217 @@ -311,7 +311,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
37218 uint32_t evt_posted;
37219
37220 spin_lock_irqsave(&phba->hbalock, flags);
37221 - atomic_inc(&phba->num_rsrc_err);
37222 + atomic_inc_unchecked(&phba->num_rsrc_err);
37223 phba->last_rsrc_error_time = jiffies;
37224
37225 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
37226 @@ -352,7 +352,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
37227 unsigned long flags;
37228 struct lpfc_hba *phba = vport->phba;
37229 uint32_t evt_posted;
37230 - atomic_inc(&phba->num_cmd_success);
37231 + atomic_inc_unchecked(&phba->num_cmd_success);
37232
37233 if (vport->cfg_lun_queue_depth <= queue_depth)
37234 return;
37235 @@ -396,8 +396,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37236 unsigned long num_rsrc_err, num_cmd_success;
37237 int i;
37238
37239 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
37240 - num_cmd_success = atomic_read(&phba->num_cmd_success);
37241 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
37242 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
37243
37244 /*
37245 * The error and success command counters are global per
37246 @@ -425,8 +425,8 @@ lpfc_ramp_down_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 @@ -460,8 +460,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
37258 }
37259 }
37260 lpfc_destroy_vport_work_array(phba, vports);
37261 - atomic_set(&phba->num_rsrc_err, 0);
37262 - atomic_set(&phba->num_cmd_success, 0);
37263 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37264 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37265 }
37266
37267 /**
37268 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
37269 index ea8a0b4..812a124 100644
37270 --- a/drivers/scsi/pmcraid.c
37271 +++ b/drivers/scsi/pmcraid.c
37272 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
37273 res->scsi_dev = scsi_dev;
37274 scsi_dev->hostdata = res;
37275 res->change_detected = 0;
37276 - atomic_set(&res->read_failures, 0);
37277 - atomic_set(&res->write_failures, 0);
37278 + atomic_set_unchecked(&res->read_failures, 0);
37279 + atomic_set_unchecked(&res->write_failures, 0);
37280 rc = 0;
37281 }
37282 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
37283 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
37284
37285 /* If this was a SCSI read/write command keep count of errors */
37286 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
37287 - atomic_inc(&res->read_failures);
37288 + atomic_inc_unchecked(&res->read_failures);
37289 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
37290 - atomic_inc(&res->write_failures);
37291 + atomic_inc_unchecked(&res->write_failures);
37292
37293 if (!RES_IS_GSCSI(res->cfg_entry) &&
37294 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
37295 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
37296 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37297 * hrrq_id assigned here in queuecommand
37298 */
37299 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37300 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37301 pinstance->num_hrrq;
37302 cmd->cmd_done = pmcraid_io_done;
37303
37304 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
37305 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37306 * hrrq_id assigned here in queuecommand
37307 */
37308 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37309 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37310 pinstance->num_hrrq;
37311
37312 if (request_size) {
37313 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
37314
37315 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
37316 /* add resources only after host is added into system */
37317 - if (!atomic_read(&pinstance->expose_resources))
37318 + if (!atomic_read_unchecked(&pinstance->expose_resources))
37319 return;
37320
37321 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
37322 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
37323 init_waitqueue_head(&pinstance->reset_wait_q);
37324
37325 atomic_set(&pinstance->outstanding_cmds, 0);
37326 - atomic_set(&pinstance->last_message_id, 0);
37327 - atomic_set(&pinstance->expose_resources, 0);
37328 + atomic_set_unchecked(&pinstance->last_message_id, 0);
37329 + atomic_set_unchecked(&pinstance->expose_resources, 0);
37330
37331 INIT_LIST_HEAD(&pinstance->free_res_q);
37332 INIT_LIST_HEAD(&pinstance->used_res_q);
37333 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
37334 /* Schedule worker thread to handle CCN and take care of adding and
37335 * removing devices to OS
37336 */
37337 - atomic_set(&pinstance->expose_resources, 1);
37338 + atomic_set_unchecked(&pinstance->expose_resources, 1);
37339 schedule_work(&pinstance->worker_q);
37340 return rc;
37341
37342 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
37343 index e1d150f..6c6df44 100644
37344 --- a/drivers/scsi/pmcraid.h
37345 +++ b/drivers/scsi/pmcraid.h
37346 @@ -748,7 +748,7 @@ struct pmcraid_instance {
37347 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
37348
37349 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
37350 - atomic_t last_message_id;
37351 + atomic_unchecked_t last_message_id;
37352
37353 /* configuration table */
37354 struct pmcraid_config_table *cfg_table;
37355 @@ -777,7 +777,7 @@ struct pmcraid_instance {
37356 atomic_t outstanding_cmds;
37357
37358 /* should add/delete resources to mid-layer now ?*/
37359 - atomic_t expose_resources;
37360 + atomic_unchecked_t expose_resources;
37361
37362
37363
37364 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
37365 struct pmcraid_config_table_entry_ext cfg_entry_ext;
37366 };
37367 struct scsi_device *scsi_dev; /* Link scsi_device structure */
37368 - atomic_t read_failures; /* count of failed READ commands */
37369 - atomic_t write_failures; /* count of failed WRITE commands */
37370 + atomic_unchecked_t read_failures; /* count of failed READ commands */
37371 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
37372
37373 /* To indicate add/delete/modify during CCN */
37374 u8 change_detected;
37375 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
37376 index 5ab9530..2dd80f7 100644
37377 --- a/drivers/scsi/qla2xxx/qla_attr.c
37378 +++ b/drivers/scsi/qla2xxx/qla_attr.c
37379 @@ -1855,7 +1855,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
37380 return 0;
37381 }
37382
37383 -struct fc_function_template qla2xxx_transport_functions = {
37384 +fc_function_template_no_const qla2xxx_transport_functions = {
37385
37386 .show_host_node_name = 1,
37387 .show_host_port_name = 1,
37388 @@ -1902,7 +1902,7 @@ struct fc_function_template qla2xxx_transport_functions = {
37389 .bsg_timeout = qla24xx_bsg_timeout,
37390 };
37391
37392 -struct fc_function_template qla2xxx_transport_vport_functions = {
37393 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
37394
37395 .show_host_node_name = 1,
37396 .show_host_port_name = 1,
37397 diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
37398 index 39007f5..7fafc64 100644
37399 --- a/drivers/scsi/qla2xxx/qla_def.h
37400 +++ b/drivers/scsi/qla2xxx/qla_def.h
37401 @@ -2284,7 +2284,7 @@ struct isp_operations {
37402 int (*start_scsi) (srb_t *);
37403 int (*abort_isp) (struct scsi_qla_host *);
37404 int (*iospace_config)(struct qla_hw_data*);
37405 -};
37406 +} __no_const;
37407
37408 /* MSI-X Support *************************************************************/
37409
37410 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
37411 index 9eacd2d..d79629c 100644
37412 --- a/drivers/scsi/qla2xxx/qla_gbl.h
37413 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
37414 @@ -484,8 +484,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
37415 struct device_attribute;
37416 extern struct device_attribute *qla2x00_host_attrs[];
37417 struct fc_function_template;
37418 -extern struct fc_function_template qla2xxx_transport_functions;
37419 -extern struct fc_function_template qla2xxx_transport_vport_functions;
37420 +extern fc_function_template_no_const qla2xxx_transport_functions;
37421 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
37422 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
37423 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
37424 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
37425 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
37426 index 7fdba7f..1b4b2c2 100644
37427 --- a/drivers/scsi/qla4xxx/ql4_def.h
37428 +++ b/drivers/scsi/qla4xxx/ql4_def.h
37429 @@ -268,7 +268,7 @@ struct ddb_entry {
37430 * (4000 only) */
37431 atomic_t relogin_timer; /* Max Time to wait for
37432 * relogin to complete */
37433 - atomic_t relogin_retry_count; /* Num of times relogin has been
37434 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
37435 * retried */
37436 uint32_t default_time2wait; /* Default Min time between
37437 * relogins (+aens) */
37438 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
37439 index 9da4266..377b3b6 100644
37440 --- a/drivers/scsi/qla4xxx/ql4_os.c
37441 +++ b/drivers/scsi/qla4xxx/ql4_os.c
37442 @@ -2615,12 +2615,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
37443 */
37444 if (!iscsi_is_session_online(cls_sess)) {
37445 /* Reset retry relogin timer */
37446 - atomic_inc(&ddb_entry->relogin_retry_count);
37447 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
37448 DEBUG2(ql4_printk(KERN_INFO, ha,
37449 "%s: index[%d] relogin timed out-retrying"
37450 " relogin (%d), retry (%d)\n", __func__,
37451 ddb_entry->fw_ddb_index,
37452 - atomic_read(&ddb_entry->relogin_retry_count),
37453 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
37454 ddb_entry->default_time2wait + 4));
37455 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
37456 atomic_set(&ddb_entry->retry_relogin_timer,
37457 @@ -4635,7 +4635,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
37458
37459 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
37460 atomic_set(&ddb_entry->relogin_timer, 0);
37461 - atomic_set(&ddb_entry->relogin_retry_count, 0);
37462 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
37463 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
37464 ddb_entry->default_relogin_timeout =
37465 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
37466 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
37467 index 2936b44..546ecdb 100644
37468 --- a/drivers/scsi/scsi.c
37469 +++ b/drivers/scsi/scsi.c
37470 @@ -660,7 +660,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
37471 unsigned long timeout;
37472 int rtn = 0;
37473
37474 - atomic_inc(&cmd->device->iorequest_cnt);
37475 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37476
37477 /* check if the device is still usable */
37478 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
37479 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
37480 index faa790f..7e351ddd 100644
37481 --- a/drivers/scsi/scsi_lib.c
37482 +++ b/drivers/scsi/scsi_lib.c
37483 @@ -1442,7 +1442,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
37484 shost = sdev->host;
37485 scsi_init_cmd_errh(cmd);
37486 cmd->result = DID_NO_CONNECT << 16;
37487 - atomic_inc(&cmd->device->iorequest_cnt);
37488 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37489
37490 /*
37491 * SCSI request completion path will do scsi_device_unbusy(),
37492 @@ -1468,9 +1468,9 @@ static void scsi_softirq_done(struct request *rq)
37493
37494 INIT_LIST_HEAD(&cmd->eh_entry);
37495
37496 - atomic_inc(&cmd->device->iodone_cnt);
37497 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
37498 if (cmd->result)
37499 - atomic_inc(&cmd->device->ioerr_cnt);
37500 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
37501
37502 disposition = scsi_decide_disposition(cmd);
37503 if (disposition != SUCCESS &&
37504 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
37505 index ce5224c..8c6d071 100644
37506 --- a/drivers/scsi/scsi_sysfs.c
37507 +++ b/drivers/scsi/scsi_sysfs.c
37508 @@ -661,7 +661,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
37509 char *buf) \
37510 { \
37511 struct scsi_device *sdev = to_scsi_device(dev); \
37512 - unsigned long long count = atomic_read(&sdev->field); \
37513 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
37514 return snprintf(buf, 20, "0x%llx\n", count); \
37515 } \
37516 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
37517 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
37518 index 84a1fdf..693b0d6 100644
37519 --- a/drivers/scsi/scsi_tgt_lib.c
37520 +++ b/drivers/scsi/scsi_tgt_lib.c
37521 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
37522 int err;
37523
37524 dprintk("%lx %u\n", uaddr, len);
37525 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
37526 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
37527 if (err) {
37528 /*
37529 * TODO: need to fixup sg_tablesize, max_segment_size,
37530 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
37531 index e894ca7..de9d7660 100644
37532 --- a/drivers/scsi/scsi_transport_fc.c
37533 +++ b/drivers/scsi/scsi_transport_fc.c
37534 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
37535 * Netlink Infrastructure
37536 */
37537
37538 -static atomic_t fc_event_seq;
37539 +static atomic_unchecked_t fc_event_seq;
37540
37541 /**
37542 * fc_get_event_number - Obtain the next sequential FC event number
37543 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
37544 u32
37545 fc_get_event_number(void)
37546 {
37547 - return atomic_add_return(1, &fc_event_seq);
37548 + return atomic_add_return_unchecked(1, &fc_event_seq);
37549 }
37550 EXPORT_SYMBOL(fc_get_event_number);
37551
37552 @@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
37553 {
37554 int error;
37555
37556 - atomic_set(&fc_event_seq, 0);
37557 + atomic_set_unchecked(&fc_event_seq, 0);
37558
37559 error = transport_class_register(&fc_host_class);
37560 if (error)
37561 @@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
37562 char *cp;
37563
37564 *val = simple_strtoul(buf, &cp, 0);
37565 - if ((*cp && (*cp != '\n')) || (*val < 0))
37566 + if (*cp && (*cp != '\n'))
37567 return -EINVAL;
37568 /*
37569 * Check for overflow; dev_loss_tmo is u32
37570 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
37571 index fa1dfaa..4bb620c 100644
37572 --- a/drivers/scsi/scsi_transport_iscsi.c
37573 +++ b/drivers/scsi/scsi_transport_iscsi.c
37574 @@ -79,7 +79,7 @@ struct iscsi_internal {
37575 struct transport_container session_cont;
37576 };
37577
37578 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37579 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37580 static struct workqueue_struct *iscsi_eh_timer_workq;
37581
37582 static DEFINE_IDA(iscsi_sess_ida);
37583 @@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
37584 int err;
37585
37586 ihost = shost->shost_data;
37587 - session->sid = atomic_add_return(1, &iscsi_session_nr);
37588 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37589
37590 if (target_id == ISCSI_MAX_TARGET) {
37591 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37592 @@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
37593 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37594 ISCSI_TRANSPORT_VERSION);
37595
37596 - atomic_set(&iscsi_session_nr, 0);
37597 + atomic_set_unchecked(&iscsi_session_nr, 0);
37598
37599 err = class_register(&iscsi_transport_class);
37600 if (err)
37601 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37602 index 21a045e..ec89e03 100644
37603 --- a/drivers/scsi/scsi_transport_srp.c
37604 +++ b/drivers/scsi/scsi_transport_srp.c
37605 @@ -33,7 +33,7 @@
37606 #include "scsi_transport_srp_internal.h"
37607
37608 struct srp_host_attrs {
37609 - atomic_t next_port_id;
37610 + atomic_unchecked_t next_port_id;
37611 };
37612 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37613
37614 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37615 struct Scsi_Host *shost = dev_to_shost(dev);
37616 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37617
37618 - atomic_set(&srp_host->next_port_id, 0);
37619 + atomic_set_unchecked(&srp_host->next_port_id, 0);
37620 return 0;
37621 }
37622
37623 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37624 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37625 rport->roles = ids->roles;
37626
37627 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37628 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37629 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37630
37631 transport_setup_device(&rport->dev);
37632 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
37633 index 4df73e5..b691c58 100644
37634 --- a/drivers/scsi/sd.c
37635 +++ b/drivers/scsi/sd.c
37636 @@ -2709,7 +2709,7 @@ static int sd_probe(struct device *dev)
37637 sdkp->disk = gd;
37638 sdkp->index = index;
37639 atomic_set(&sdkp->openers, 0);
37640 - atomic_set(&sdkp->device->ioerr_cnt, 0);
37641 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
37642
37643 if (!sdp->request_queue->rq_timeout) {
37644 if (sdp->type != TYPE_MOD)
37645 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37646 index 9c5c5f2..8414557 100644
37647 --- a/drivers/scsi/sg.c
37648 +++ b/drivers/scsi/sg.c
37649 @@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37650 sdp->disk->disk_name,
37651 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37652 NULL,
37653 - (char *)arg);
37654 + (char __user *)arg);
37655 case BLKTRACESTART:
37656 return blk_trace_startstop(sdp->device->request_queue, 1);
37657 case BLKTRACESTOP:
37658 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37659 index 84c2861..ece0a31 100644
37660 --- a/drivers/spi/spi.c
37661 +++ b/drivers/spi/spi.c
37662 @@ -1453,7 +1453,7 @@ int spi_bus_unlock(struct spi_master *master)
37663 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37664
37665 /* portable code must never pass more than 32 bytes */
37666 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37667 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37668
37669 static u8 *buf;
37670
37671 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37672 index 34afc16..ffe44dd 100644
37673 --- a/drivers/staging/octeon/ethernet-rx.c
37674 +++ b/drivers/staging/octeon/ethernet-rx.c
37675 @@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37676 /* Increment RX stats for virtual ports */
37677 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37678 #ifdef CONFIG_64BIT
37679 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37680 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37681 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37682 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37683 #else
37684 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37685 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37686 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37687 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37688 #endif
37689 }
37690 netif_receive_skb(skb);
37691 @@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37692 dev->name);
37693 */
37694 #ifdef CONFIG_64BIT
37695 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37696 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37697 #else
37698 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37699 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37700 #endif
37701 dev_kfree_skb_irq(skb);
37702 }
37703 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37704 index 683bedc..86dba9a 100644
37705 --- a/drivers/staging/octeon/ethernet.c
37706 +++ b/drivers/staging/octeon/ethernet.c
37707 @@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37708 * since the RX tasklet also increments it.
37709 */
37710 #ifdef CONFIG_64BIT
37711 - atomic64_add(rx_status.dropped_packets,
37712 - (atomic64_t *)&priv->stats.rx_dropped);
37713 + atomic64_add_unchecked(rx_status.dropped_packets,
37714 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37715 #else
37716 - atomic_add(rx_status.dropped_packets,
37717 - (atomic_t *)&priv->stats.rx_dropped);
37718 + atomic_add_unchecked(rx_status.dropped_packets,
37719 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
37720 #endif
37721 }
37722
37723 diff --git a/drivers/staging/omapdrm/omap_drv.c b/drivers/staging/omapdrm/omap_drv.c
37724 index 4beab94..44149ee 100644
37725 --- a/drivers/staging/omapdrm/omap_drv.c
37726 +++ b/drivers/staging/omapdrm/omap_drv.c
37727 @@ -761,7 +761,6 @@ static struct drm_driver omap_drm_driver = {
37728 .irq_postinstall = dev_irq_postinstall,
37729 .irq_uninstall = dev_irq_uninstall,
37730 .irq_handler = dev_irq_handler,
37731 - .reclaim_buffers = drm_core_reclaim_buffers,
37732 #ifdef CONFIG_DEBUG_FS
37733 .debugfs_init = omap_debugfs_init,
37734 .debugfs_cleanup = omap_debugfs_cleanup,
37735 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37736 index dc23395..cf7e9b1 100644
37737 --- a/drivers/staging/rtl8712/rtl871x_io.h
37738 +++ b/drivers/staging/rtl8712/rtl871x_io.h
37739 @@ -108,7 +108,7 @@ struct _io_ops {
37740 u8 *pmem);
37741 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37742 u8 *pmem);
37743 -};
37744 +} __no_const;
37745
37746 struct io_req {
37747 struct list_head list;
37748 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37749 index c7b5e8b..783d6cb 100644
37750 --- a/drivers/staging/sbe-2t3e3/netdev.c
37751 +++ b/drivers/staging/sbe-2t3e3/netdev.c
37752 @@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37753 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37754
37755 if (rlen)
37756 - if (copy_to_user(data, &resp, rlen))
37757 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37758 return -EFAULT;
37759
37760 return 0;
37761 diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37762 index 5d89c0f..9261317 100644
37763 --- a/drivers/staging/usbip/usbip_common.h
37764 +++ b/drivers/staging/usbip/usbip_common.h
37765 @@ -289,7 +289,7 @@ struct usbip_device {
37766 void (*shutdown)(struct usbip_device *);
37767 void (*reset)(struct usbip_device *);
37768 void (*unusable)(struct usbip_device *);
37769 - } eh_ops;
37770 + } __no_const eh_ops;
37771 };
37772
37773 #define kthread_get_run(threadfn, data, namefmt, ...) \
37774 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
37775 index c66b8b3..a4a035b 100644
37776 --- a/drivers/staging/usbip/vhci.h
37777 +++ b/drivers/staging/usbip/vhci.h
37778 @@ -83,7 +83,7 @@ struct vhci_hcd {
37779 unsigned resuming:1;
37780 unsigned long re_timeout;
37781
37782 - atomic_t seqnum;
37783 + atomic_unchecked_t seqnum;
37784
37785 /*
37786 * NOTE:
37787 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
37788 index 12a9a5f..afd8295 100644
37789 --- a/drivers/staging/usbip/vhci_hcd.c
37790 +++ b/drivers/staging/usbip/vhci_hcd.c
37791 @@ -471,7 +471,7 @@ static void vhci_tx_urb(struct urb *urb)
37792 return;
37793 }
37794
37795 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37796 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37797 if (priv->seqnum == 0xffff)
37798 dev_info(&urb->dev->dev, "seqnum max\n");
37799
37800 @@ -723,7 +723,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
37801 return -ENOMEM;
37802 }
37803
37804 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37805 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37806 if (unlink->seqnum == 0xffff)
37807 pr_info("seqnum max\n");
37808
37809 @@ -911,7 +911,7 @@ static int vhci_start(struct usb_hcd *hcd)
37810 vdev->rhport = rhport;
37811 }
37812
37813 - atomic_set(&vhci->seqnum, 0);
37814 + atomic_set_unchecked(&vhci->seqnum, 0);
37815 spin_lock_init(&vhci->lock);
37816
37817 hcd->power_budget = 0; /* no limit */
37818 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
37819 index f0eaf04..5a82e06 100644
37820 --- a/drivers/staging/usbip/vhci_rx.c
37821 +++ b/drivers/staging/usbip/vhci_rx.c
37822 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
37823 if (!urb) {
37824 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
37825 pr_info("max seqnum %d\n",
37826 - atomic_read(&the_controller->seqnum));
37827 + atomic_read_unchecked(&the_controller->seqnum));
37828 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
37829 return;
37830 }
37831 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
37832 index 6ac6f45..1b208ba 100644
37833 --- a/drivers/staging/vt6655/hostap.c
37834 +++ b/drivers/staging/vt6655/hostap.c
37835 @@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
37836 *
37837 */
37838
37839 +static net_device_ops_no_const apdev_netdev_ops;
37840 +
37841 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37842 {
37843 PSDevice apdev_priv;
37844 struct net_device *dev = pDevice->dev;
37845 int ret;
37846 - const struct net_device_ops apdev_netdev_ops = {
37847 - .ndo_start_xmit = pDevice->tx_80211,
37848 - };
37849
37850 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37851
37852 @@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37853 *apdev_priv = *pDevice;
37854 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37855
37856 + /* only half broken now */
37857 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37858 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37859
37860 pDevice->apdev->type = ARPHRD_IEEE80211;
37861 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
37862 index 682002a..35ed5cf 100644
37863 --- a/drivers/staging/vt6656/hostap.c
37864 +++ b/drivers/staging/vt6656/hostap.c
37865 @@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
37866 *
37867 */
37868
37869 +static net_device_ops_no_const apdev_netdev_ops;
37870 +
37871 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37872 {
37873 PSDevice apdev_priv;
37874 struct net_device *dev = pDevice->dev;
37875 int ret;
37876 - const struct net_device_ops apdev_netdev_ops = {
37877 - .ndo_start_xmit = pDevice->tx_80211,
37878 - };
37879
37880 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37881
37882 @@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37883 *apdev_priv = *pDevice;
37884 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37885
37886 + /* only half broken now */
37887 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37888 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37889
37890 pDevice->apdev->type = ARPHRD_IEEE80211;
37891 diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
37892 index 7843dfd..3db105f 100644
37893 --- a/drivers/staging/wlan-ng/hfa384x_usb.c
37894 +++ b/drivers/staging/wlan-ng/hfa384x_usb.c
37895 @@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
37896
37897 struct usbctlx_completor {
37898 int (*complete) (struct usbctlx_completor *);
37899 -};
37900 +} __no_const;
37901
37902 static int
37903 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
37904 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
37905 index eaa9021..43f023b 100644
37906 --- a/drivers/staging/zcache/tmem.c
37907 +++ b/drivers/staging/zcache/tmem.c
37908 @@ -39,7 +39,7 @@
37909 * A tmem host implementation must use this function to register callbacks
37910 * for memory allocation.
37911 */
37912 -static struct tmem_hostops tmem_hostops;
37913 +static tmem_hostops_no_const tmem_hostops;
37914
37915 static void tmem_objnode_tree_init(void);
37916
37917 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
37918 * A tmem host implementation must use this function to register
37919 * callbacks for a page-accessible memory (PAM) implementation
37920 */
37921 -static struct tmem_pamops tmem_pamops;
37922 +static tmem_pamops_no_const tmem_pamops;
37923
37924 void tmem_register_pamops(struct tmem_pamops *m)
37925 {
37926 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
37927 index 0d4aa82..f7832d4 100644
37928 --- a/drivers/staging/zcache/tmem.h
37929 +++ b/drivers/staging/zcache/tmem.h
37930 @@ -180,6 +180,7 @@ struct tmem_pamops {
37931 void (*new_obj)(struct tmem_obj *);
37932 int (*replace_in_obj)(void *, struct tmem_obj *);
37933 };
37934 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
37935 extern void tmem_register_pamops(struct tmem_pamops *m);
37936
37937 /* memory allocation methods provided by the host implementation */
37938 @@ -189,6 +190,7 @@ struct tmem_hostops {
37939 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
37940 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
37941 };
37942 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
37943 extern void tmem_register_hostops(struct tmem_hostops *m);
37944
37945 /* core tmem accessor functions */
37946 diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
37947 index 9fc9a60..68d4c10 100644
37948 --- a/drivers/target/target_core_device.c
37949 +++ b/drivers/target/target_core_device.c
37950 @@ -850,20 +850,20 @@ int se_dev_check_shutdown(struct se_device *dev)
37951
37952 static u32 se_dev_align_max_sectors(u32 max_sectors, u32 block_size)
37953 {
37954 - u32 tmp, aligned_max_sectors;
37955 + u32 aligned_max_sectors;
37956 + u32 alignment;
37957 /*
37958 * Limit max_sectors to a PAGE_SIZE aligned value for modern
37959 * transport_allocate_data_tasks() operation.
37960 */
37961 - tmp = rounddown((max_sectors * block_size), PAGE_SIZE);
37962 - aligned_max_sectors = (tmp / block_size);
37963 - if (max_sectors != aligned_max_sectors) {
37964 - printk(KERN_INFO "Rounding down aligned max_sectors from %u"
37965 - " to %u\n", max_sectors, aligned_max_sectors);
37966 - return aligned_max_sectors;
37967 - }
37968 + alignment = max(1ul, PAGE_SIZE / block_size);
37969 + aligned_max_sectors = rounddown(max_sectors, alignment);
37970
37971 - return max_sectors;
37972 + if (max_sectors != aligned_max_sectors)
37973 + pr_info("Rounding down aligned max_sectors from %u to %u\n",
37974 + max_sectors, aligned_max_sectors);
37975 +
37976 + return aligned_max_sectors;
37977 }
37978
37979 void se_dev_set_default_attribs(
37980 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
37981 index 7502660..f214d9f 100644
37982 --- a/drivers/target/target_core_transport.c
37983 +++ b/drivers/target/target_core_transport.c
37984 @@ -1098,7 +1098,7 @@ struct se_device *transport_add_device_to_core_hba(
37985 spin_lock_init(&dev->se_port_lock);
37986 spin_lock_init(&dev->se_tmr_lock);
37987 spin_lock_init(&dev->qf_cmd_lock);
37988 - atomic_set(&dev->dev_ordered_id, 0);
37989 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
37990
37991 se_dev_set_default_attribs(dev, dev_limits);
37992
37993 @@ -1288,7 +1288,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
37994 * Used to determine when ORDERED commands should go from
37995 * Dormant to Active status.
37996 */
37997 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
37998 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
37999 smp_mb__after_atomic_inc();
38000 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
38001 cmd->se_ordered_id, cmd->sam_task_attr,
38002 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
38003 index e61cabd..7617d26 100644
38004 --- a/drivers/tty/cyclades.c
38005 +++ b/drivers/tty/cyclades.c
38006 @@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
38007 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
38008 info->port.count);
38009 #endif
38010 - info->port.count++;
38011 + atomic_inc(&info->port.count);
38012 #ifdef CY_DEBUG_COUNT
38013 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
38014 - current->pid, info->port.count);
38015 + current->pid, atomic_read(&info->port.count));
38016 #endif
38017
38018 /*
38019 @@ -3987,7 +3987,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
38020 for (j = 0; j < cy_card[i].nports; j++) {
38021 info = &cy_card[i].ports[j];
38022
38023 - if (info->port.count) {
38024 + if (atomic_read(&info->port.count)) {
38025 /* XXX is the ldisc num worth this? */
38026 struct tty_struct *tty;
38027 struct tty_ldisc *ld;
38028 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
38029 index 2d691eb..be02ebd 100644
38030 --- a/drivers/tty/hvc/hvc_console.c
38031 +++ b/drivers/tty/hvc/hvc_console.c
38032 @@ -315,7 +315,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
38033
38034 spin_lock_irqsave(&hp->port.lock, flags);
38035 /* Check and then increment for fast path open. */
38036 - if (hp->port.count++ > 0) {
38037 + if (atomic_inc_return(&hp->port.count) > 1) {
38038 spin_unlock_irqrestore(&hp->port.lock, flags);
38039 hvc_kick();
38040 return 0;
38041 @@ -366,7 +366,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
38042
38043 spin_lock_irqsave(&hp->port.lock, flags);
38044
38045 - if (--hp->port.count == 0) {
38046 + if (atomic_dec_return(&hp->port.count) == 0) {
38047 spin_unlock_irqrestore(&hp->port.lock, flags);
38048 /* We are done with the tty pointer now. */
38049 tty_port_tty_set(&hp->port, NULL);
38050 @@ -384,9 +384,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
38051 */
38052 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
38053 } else {
38054 - if (hp->port.count < 0)
38055 + if (atomic_read(&hp->port.count) < 0)
38056 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
38057 - hp->vtermno, hp->port.count);
38058 + hp->vtermno, atomic_read(&hp->port.count));
38059 spin_unlock_irqrestore(&hp->port.lock, flags);
38060 }
38061
38062 @@ -412,13 +412,13 @@ static void hvc_hangup(struct tty_struct *tty)
38063 * open->hangup case this can be called after the final close so prevent
38064 * that from happening for now.
38065 */
38066 - if (hp->port.count <= 0) {
38067 + if (atomic_read(&hp->port.count) <= 0) {
38068 spin_unlock_irqrestore(&hp->port.lock, flags);
38069 return;
38070 }
38071
38072 - temp_open_count = hp->port.count;
38073 - hp->port.count = 0;
38074 + temp_open_count = atomic_read(&hp->port.count);
38075 + atomic_set(&hp->port.count, 0);
38076 spin_unlock_irqrestore(&hp->port.lock, flags);
38077 tty_port_tty_set(&hp->port, NULL);
38078
38079 @@ -471,7 +471,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
38080 return -EPIPE;
38081
38082 /* FIXME what's this (unprotected) check for? */
38083 - if (hp->port.count <= 0)
38084 + if (atomic_read(&hp->port.count) <= 0)
38085 return -EIO;
38086
38087 spin_lock_irqsave(&hp->lock, flags);
38088 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
38089 index d56788c..12d8f85 100644
38090 --- a/drivers/tty/hvc/hvcs.c
38091 +++ b/drivers/tty/hvc/hvcs.c
38092 @@ -83,6 +83,7 @@
38093 #include <asm/hvcserver.h>
38094 #include <asm/uaccess.h>
38095 #include <asm/vio.h>
38096 +#include <asm/local.h>
38097
38098 /*
38099 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
38100 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
38101
38102 spin_lock_irqsave(&hvcsd->lock, flags);
38103
38104 - if (hvcsd->port.count > 0) {
38105 + if (atomic_read(&hvcsd->port.count) > 0) {
38106 spin_unlock_irqrestore(&hvcsd->lock, flags);
38107 printk(KERN_INFO "HVCS: vterm state unchanged. "
38108 "The hvcs device node is still in use.\n");
38109 @@ -1134,7 +1135,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
38110 if ((retval = hvcs_partner_connect(hvcsd)))
38111 goto error_release;
38112
38113 - hvcsd->port.count = 1;
38114 + atomic_set(&hvcsd->port.count, 1);
38115 hvcsd->port.tty = tty;
38116 tty->driver_data = hvcsd;
38117
38118 @@ -1168,7 +1169,7 @@ fast_open:
38119
38120 spin_lock_irqsave(&hvcsd->lock, flags);
38121 tty_port_get(&hvcsd->port);
38122 - hvcsd->port.count++;
38123 + atomic_inc(&hvcsd->port.count);
38124 hvcsd->todo_mask |= HVCS_SCHED_READ;
38125 spin_unlock_irqrestore(&hvcsd->lock, flags);
38126
38127 @@ -1212,7 +1213,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
38128 hvcsd = tty->driver_data;
38129
38130 spin_lock_irqsave(&hvcsd->lock, flags);
38131 - if (--hvcsd->port.count == 0) {
38132 + if (atomic_dec_and_test(&hvcsd->port.count)) {
38133
38134 vio_disable_interrupts(hvcsd->vdev);
38135
38136 @@ -1238,10 +1239,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
38137 free_irq(irq, hvcsd);
38138 tty_port_put(&hvcsd->port);
38139 return;
38140 - } else if (hvcsd->port.count < 0) {
38141 + } else if (atomic_read(&hvcsd->port.count) < 0) {
38142 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
38143 " is missmanaged.\n",
38144 - hvcsd->vdev->unit_address, hvcsd->port.count);
38145 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
38146 }
38147
38148 spin_unlock_irqrestore(&hvcsd->lock, flags);
38149 @@ -1257,7 +1258,7 @@ static void hvcs_hangup(struct tty_struct * tty)
38150
38151 spin_lock_irqsave(&hvcsd->lock, flags);
38152 /* Preserve this so that we know how many kref refs to put */
38153 - temp_open_count = hvcsd->port.count;
38154 + temp_open_count = atomic_read(&hvcsd->port.count);
38155
38156 /*
38157 * Don't kref put inside the spinlock because the destruction
38158 @@ -1272,7 +1273,7 @@ static void hvcs_hangup(struct tty_struct * tty)
38159 tty->driver_data = NULL;
38160 hvcsd->port.tty = NULL;
38161
38162 - hvcsd->port.count = 0;
38163 + atomic_set(&hvcsd->port.count, 0);
38164
38165 /* This will drop any buffered data on the floor which is OK in a hangup
38166 * scenario. */
38167 @@ -1343,7 +1344,7 @@ static int hvcs_write(struct tty_struct *tty,
38168 * the middle of a write operation? This is a crummy place to do this
38169 * but we want to keep it all in the spinlock.
38170 */
38171 - if (hvcsd->port.count <= 0) {
38172 + if (atomic_read(&hvcsd->port.count) <= 0) {
38173 spin_unlock_irqrestore(&hvcsd->lock, flags);
38174 return -ENODEV;
38175 }
38176 @@ -1417,7 +1418,7 @@ static int hvcs_write_room(struct tty_struct *tty)
38177 {
38178 struct hvcs_struct *hvcsd = tty->driver_data;
38179
38180 - if (!hvcsd || hvcsd->port.count <= 0)
38181 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
38182 return 0;
38183
38184 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
38185 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
38186 index f8b5fa0..4ba9f89 100644
38187 --- a/drivers/tty/ipwireless/tty.c
38188 +++ b/drivers/tty/ipwireless/tty.c
38189 @@ -29,6 +29,7 @@
38190 #include <linux/tty_driver.h>
38191 #include <linux/tty_flip.h>
38192 #include <linux/uaccess.h>
38193 +#include <asm/local.h>
38194
38195 #include "tty.h"
38196 #include "network.h"
38197 @@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38198 mutex_unlock(&tty->ipw_tty_mutex);
38199 return -ENODEV;
38200 }
38201 - if (tty->port.count == 0)
38202 + if (atomic_read(&tty->port.count) == 0)
38203 tty->tx_bytes_queued = 0;
38204
38205 - tty->port.count++;
38206 + atomic_inc(&tty->port.count);
38207
38208 tty->port.tty = linux_tty;
38209 linux_tty->driver_data = tty;
38210 @@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38211
38212 static void do_ipw_close(struct ipw_tty *tty)
38213 {
38214 - tty->port.count--;
38215 -
38216 - if (tty->port.count == 0) {
38217 + if (atomic_dec_return(&tty->port.count) == 0) {
38218 struct tty_struct *linux_tty = tty->port.tty;
38219
38220 if (linux_tty != NULL) {
38221 @@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
38222 return;
38223
38224 mutex_lock(&tty->ipw_tty_mutex);
38225 - if (tty->port.count == 0) {
38226 + if (atomic_read(&tty->port.count) == 0) {
38227 mutex_unlock(&tty->ipw_tty_mutex);
38228 return;
38229 }
38230 @@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
38231 return;
38232 }
38233
38234 - if (!tty->port.count) {
38235 + if (!atomic_read(&tty->port.count)) {
38236 mutex_unlock(&tty->ipw_tty_mutex);
38237 return;
38238 }
38239 @@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
38240 return -ENODEV;
38241
38242 mutex_lock(&tty->ipw_tty_mutex);
38243 - if (!tty->port.count) {
38244 + if (!atomic_read(&tty->port.count)) {
38245 mutex_unlock(&tty->ipw_tty_mutex);
38246 return -EINVAL;
38247 }
38248 @@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
38249 if (!tty)
38250 return -ENODEV;
38251
38252 - if (!tty->port.count)
38253 + if (!atomic_read(&tty->port.count))
38254 return -EINVAL;
38255
38256 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
38257 @@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
38258 if (!tty)
38259 return 0;
38260
38261 - if (!tty->port.count)
38262 + if (!atomic_read(&tty->port.count))
38263 return 0;
38264
38265 return tty->tx_bytes_queued;
38266 @@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
38267 if (!tty)
38268 return -ENODEV;
38269
38270 - if (!tty->port.count)
38271 + if (!atomic_read(&tty->port.count))
38272 return -EINVAL;
38273
38274 return get_control_lines(tty);
38275 @@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
38276 if (!tty)
38277 return -ENODEV;
38278
38279 - if (!tty->port.count)
38280 + if (!atomic_read(&tty->port.count))
38281 return -EINVAL;
38282
38283 return set_control_lines(tty, set, clear);
38284 @@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
38285 if (!tty)
38286 return -ENODEV;
38287
38288 - if (!tty->port.count)
38289 + if (!atomic_read(&tty->port.count))
38290 return -EINVAL;
38291
38292 /* FIXME: Exactly how is the tty object locked here .. */
38293 @@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
38294 * are gone */
38295 mutex_lock(&ttyj->ipw_tty_mutex);
38296 }
38297 - while (ttyj->port.count)
38298 + while (atomic_read(&ttyj->port.count))
38299 do_ipw_close(ttyj);
38300 ipwireless_disassociate_network_ttys(network,
38301 ttyj->channel_idx);
38302 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
38303 index 324467d..504cc25 100644
38304 --- a/drivers/tty/moxa.c
38305 +++ b/drivers/tty/moxa.c
38306 @@ -1172,7 +1172,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
38307 }
38308
38309 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
38310 - ch->port.count++;
38311 + atomic_inc(&ch->port.count);
38312 tty->driver_data = ch;
38313 tty_port_tty_set(&ch->port, tty);
38314 mutex_lock(&ch->port.mutex);
38315 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
38316 index 90dff82..08119c3 100644
38317 --- a/drivers/tty/n_gsm.c
38318 +++ b/drivers/tty/n_gsm.c
38319 @@ -1639,7 +1639,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
38320 kref_init(&dlci->ref);
38321 mutex_init(&dlci->mutex);
38322 dlci->fifo = &dlci->_fifo;
38323 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
38324 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
38325 kfree(dlci);
38326 return NULL;
38327 }
38328 @@ -2909,7 +2909,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
38329 if (dlci == NULL)
38330 return -ENOMEM;
38331 port = &dlci->port;
38332 - port->count++;
38333 + atomic_inc(&port->count);
38334 tty->driver_data = dlci;
38335 dlci_get(dlci);
38336 dlci_get(dlci->gsm->dlci[0]);
38337 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
38338 index 26f0d0e..b7c4273 100644
38339 --- a/drivers/tty/n_tty.c
38340 +++ b/drivers/tty/n_tty.c
38341 @@ -2124,6 +2124,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
38342 {
38343 *ops = tty_ldisc_N_TTY;
38344 ops->owner = NULL;
38345 - ops->refcount = ops->flags = 0;
38346 + atomic_set(&ops->refcount, 0);
38347 + ops->flags = 0;
38348 }
38349 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
38350 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
38351 index 5505ffc..7affff9 100644
38352 --- a/drivers/tty/pty.c
38353 +++ b/drivers/tty/pty.c
38354 @@ -718,8 +718,10 @@ static void __init unix98_pty_init(void)
38355 panic("Couldn't register Unix98 pts driver");
38356
38357 /* Now create the /dev/ptmx special device */
38358 + pax_open_kernel();
38359 tty_default_fops(&ptmx_fops);
38360 - ptmx_fops.open = ptmx_open;
38361 + *(void **)&ptmx_fops.open = ptmx_open;
38362 + pax_close_kernel();
38363
38364 cdev_init(&ptmx_cdev, &ptmx_fops);
38365 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
38366 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
38367 index 777d5f9..56d67ca 100644
38368 --- a/drivers/tty/rocket.c
38369 +++ b/drivers/tty/rocket.c
38370 @@ -924,7 +924,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
38371 tty->driver_data = info;
38372 tty_port_tty_set(port, tty);
38373
38374 - if (port->count++ == 0) {
38375 + if (atomic_inc_return(&port->count) == 1) {
38376 atomic_inc(&rp_num_ports_open);
38377
38378 #ifdef ROCKET_DEBUG_OPEN
38379 @@ -933,7 +933,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
38380 #endif
38381 }
38382 #ifdef ROCKET_DEBUG_OPEN
38383 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
38384 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
38385 #endif
38386
38387 /*
38388 @@ -1528,7 +1528,7 @@ static void rp_hangup(struct tty_struct *tty)
38389 spin_unlock_irqrestore(&info->port.lock, flags);
38390 return;
38391 }
38392 - if (info->port.count)
38393 + if (atomic_read(&info->port.count))
38394 atomic_dec(&rp_num_ports_open);
38395 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
38396 spin_unlock_irqrestore(&info->port.lock, flags);
38397 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
38398 index 2b42a01..32a2ed3 100644
38399 --- a/drivers/tty/serial/kgdboc.c
38400 +++ b/drivers/tty/serial/kgdboc.c
38401 @@ -24,8 +24,9 @@
38402 #define MAX_CONFIG_LEN 40
38403
38404 static struct kgdb_io kgdboc_io_ops;
38405 +static struct kgdb_io kgdboc_io_ops_console;
38406
38407 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
38408 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
38409 static int configured = -1;
38410
38411 static char config[MAX_CONFIG_LEN];
38412 @@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
38413 kgdboc_unregister_kbd();
38414 if (configured == 1)
38415 kgdb_unregister_io_module(&kgdboc_io_ops);
38416 + else if (configured == 2)
38417 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
38418 }
38419
38420 static int configure_kgdboc(void)
38421 @@ -157,13 +160,13 @@ static int configure_kgdboc(void)
38422 int err;
38423 char *cptr = config;
38424 struct console *cons;
38425 + int is_console = 0;
38426
38427 err = kgdboc_option_setup(config);
38428 if (err || !strlen(config) || isspace(config[0]))
38429 goto noconfig;
38430
38431 err = -ENODEV;
38432 - kgdboc_io_ops.is_console = 0;
38433 kgdb_tty_driver = NULL;
38434
38435 kgdboc_use_kms = 0;
38436 @@ -184,7 +187,7 @@ static int configure_kgdboc(void)
38437 int idx;
38438 if (cons->device && cons->device(cons, &idx) == p &&
38439 idx == tty_line) {
38440 - kgdboc_io_ops.is_console = 1;
38441 + is_console = 1;
38442 break;
38443 }
38444 cons = cons->next;
38445 @@ -194,12 +197,16 @@ static int configure_kgdboc(void)
38446 kgdb_tty_line = tty_line;
38447
38448 do_register:
38449 - err = kgdb_register_io_module(&kgdboc_io_ops);
38450 + if (is_console) {
38451 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
38452 + configured = 2;
38453 + } else {
38454 + err = kgdb_register_io_module(&kgdboc_io_ops);
38455 + configured = 1;
38456 + }
38457 if (err)
38458 goto noconfig;
38459
38460 - configured = 1;
38461 -
38462 return 0;
38463
38464 noconfig:
38465 @@ -213,7 +220,7 @@ noconfig:
38466 static int __init init_kgdboc(void)
38467 {
38468 /* Already configured? */
38469 - if (configured == 1)
38470 + if (configured >= 1)
38471 return 0;
38472
38473 return configure_kgdboc();
38474 @@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
38475 if (config[len - 1] == '\n')
38476 config[len - 1] = '\0';
38477
38478 - if (configured == 1)
38479 + if (configured >= 1)
38480 cleanup_kgdboc();
38481
38482 /* Go and configure with the new params. */
38483 @@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
38484 .post_exception = kgdboc_post_exp_handler,
38485 };
38486
38487 +static struct kgdb_io kgdboc_io_ops_console = {
38488 + .name = "kgdboc",
38489 + .read_char = kgdboc_get_char,
38490 + .write_char = kgdboc_put_char,
38491 + .pre_exception = kgdboc_pre_exp_handler,
38492 + .post_exception = kgdboc_post_exp_handler,
38493 + .is_console = 1
38494 +};
38495 +
38496 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
38497 /* This is only available if kgdboc is a built in for early debugging */
38498 static int __init kgdboc_early_init(char *opt)
38499 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
38500 index a21dc8e..fe43e9e 100644
38501 --- a/drivers/tty/serial/serial_core.c
38502 +++ b/drivers/tty/serial/serial_core.c
38503 @@ -1392,7 +1392,7 @@ static void uart_hangup(struct tty_struct *tty)
38504 uart_flush_buffer(tty);
38505 uart_shutdown(tty, state);
38506 spin_lock_irqsave(&port->lock, flags);
38507 - port->count = 0;
38508 + atomic_set(&port->count, 0);
38509 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
38510 spin_unlock_irqrestore(&port->lock, flags);
38511 tty_port_tty_set(port, NULL);
38512 @@ -1488,7 +1488,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38513 goto end;
38514 }
38515
38516 - port->count++;
38517 + atomic_inc(&port->count);
38518 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
38519 retval = -ENXIO;
38520 goto err_dec_count;
38521 @@ -1515,7 +1515,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38522 /*
38523 * Make sure the device is in D0 state.
38524 */
38525 - if (port->count == 1)
38526 + if (atomic_read(&port->count) == 1)
38527 uart_change_pm(state, 0);
38528
38529 /*
38530 @@ -1533,7 +1533,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38531 end:
38532 return retval;
38533 err_dec_count:
38534 - port->count--;
38535 + atomic_inc(&port->count);
38536 mutex_unlock(&port->mutex);
38537 goto end;
38538 }
38539 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
38540 index 593d40a..bdc61f3 100644
38541 --- a/drivers/tty/synclink.c
38542 +++ b/drivers/tty/synclink.c
38543 @@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38544
38545 if (debug_level >= DEBUG_LEVEL_INFO)
38546 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
38547 - __FILE__,__LINE__, info->device_name, info->port.count);
38548 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38549
38550 if (tty_port_close_start(&info->port, tty, filp) == 0)
38551 goto cleanup;
38552 @@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38553 cleanup:
38554 if (debug_level >= DEBUG_LEVEL_INFO)
38555 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
38556 - tty->driver->name, info->port.count);
38557 + tty->driver->name, atomic_read(&info->port.count));
38558
38559 } /* end of mgsl_close() */
38560
38561 @@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
38562
38563 mgsl_flush_buffer(tty);
38564 shutdown(info);
38565 -
38566 - info->port.count = 0;
38567 +
38568 + atomic_set(&info->port.count, 0);
38569 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38570 info->port.tty = NULL;
38571
38572 @@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38573
38574 if (debug_level >= DEBUG_LEVEL_INFO)
38575 printk("%s(%d):block_til_ready before block on %s count=%d\n",
38576 - __FILE__,__LINE__, tty->driver->name, port->count );
38577 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38578
38579 spin_lock_irqsave(&info->irq_spinlock, flags);
38580 if (!tty_hung_up_p(filp)) {
38581 extra_count = true;
38582 - port->count--;
38583 + atomic_dec(&port->count);
38584 }
38585 spin_unlock_irqrestore(&info->irq_spinlock, flags);
38586 port->blocked_open++;
38587 @@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38588
38589 if (debug_level >= DEBUG_LEVEL_INFO)
38590 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
38591 - __FILE__,__LINE__, tty->driver->name, port->count );
38592 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38593
38594 tty_unlock();
38595 schedule();
38596 @@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38597
38598 /* FIXME: Racy on hangup during close wait */
38599 if (extra_count)
38600 - port->count++;
38601 + atomic_inc(&port->count);
38602 port->blocked_open--;
38603
38604 if (debug_level >= DEBUG_LEVEL_INFO)
38605 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
38606 - __FILE__,__LINE__, tty->driver->name, port->count );
38607 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38608
38609 if (!retval)
38610 port->flags |= ASYNC_NORMAL_ACTIVE;
38611 @@ -3398,7 +3398,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38612
38613 if (debug_level >= DEBUG_LEVEL_INFO)
38614 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
38615 - __FILE__,__LINE__,tty->driver->name, info->port.count);
38616 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38617
38618 /* If port is closing, signal caller to try again */
38619 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38620 @@ -3417,10 +3417,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38621 spin_unlock_irqrestore(&info->netlock, flags);
38622 goto cleanup;
38623 }
38624 - info->port.count++;
38625 + atomic_inc(&info->port.count);
38626 spin_unlock_irqrestore(&info->netlock, flags);
38627
38628 - if (info->port.count == 1) {
38629 + if (atomic_read(&info->port.count) == 1) {
38630 /* 1st open on this device, init hardware */
38631 retval = startup(info);
38632 if (retval < 0)
38633 @@ -3444,8 +3444,8 @@ cleanup:
38634 if (retval) {
38635 if (tty->count == 1)
38636 info->port.tty = NULL; /* tty layer will release tty struct */
38637 - if(info->port.count)
38638 - info->port.count--;
38639 + if (atomic_read(&info->port.count))
38640 + atomic_dec(&info->port.count);
38641 }
38642
38643 return retval;
38644 @@ -7653,7 +7653,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38645 unsigned short new_crctype;
38646
38647 /* return error if TTY interface open */
38648 - if (info->port.count)
38649 + if (atomic_read(&info->port.count))
38650 return -EBUSY;
38651
38652 switch (encoding)
38653 @@ -7748,7 +7748,7 @@ static int hdlcdev_open(struct net_device *dev)
38654
38655 /* arbitrate between network and tty opens */
38656 spin_lock_irqsave(&info->netlock, flags);
38657 - if (info->port.count != 0 || info->netcount != 0) {
38658 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38659 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38660 spin_unlock_irqrestore(&info->netlock, flags);
38661 return -EBUSY;
38662 @@ -7834,7 +7834,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38663 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38664
38665 /* return error if TTY interface open */
38666 - if (info->port.count)
38667 + if (atomic_read(&info->port.count))
38668 return -EBUSY;
38669
38670 if (cmd != SIOCWANDEV)
38671 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
38672 index aa1debf..9297a16 100644
38673 --- a/drivers/tty/synclink_gt.c
38674 +++ b/drivers/tty/synclink_gt.c
38675 @@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38676 tty->driver_data = info;
38677 info->port.tty = tty;
38678
38679 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
38680 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
38681
38682 /* If port is closing, signal caller to try again */
38683 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38684 @@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38685 mutex_unlock(&info->port.mutex);
38686 goto cleanup;
38687 }
38688 - info->port.count++;
38689 + atomic_inc(&info->port.count);
38690 spin_unlock_irqrestore(&info->netlock, flags);
38691
38692 - if (info->port.count == 1) {
38693 + if (atomic_read(&info->port.count) == 1) {
38694 /* 1st open on this device, init hardware */
38695 retval = startup(info);
38696 if (retval < 0) {
38697 @@ -716,8 +716,8 @@ cleanup:
38698 if (retval) {
38699 if (tty->count == 1)
38700 info->port.tty = NULL; /* tty layer will release tty struct */
38701 - if(info->port.count)
38702 - info->port.count--;
38703 + if(atomic_read(&info->port.count))
38704 + atomic_dec(&info->port.count);
38705 }
38706
38707 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
38708 @@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38709
38710 if (sanity_check(info, tty->name, "close"))
38711 return;
38712 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
38713 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
38714
38715 if (tty_port_close_start(&info->port, tty, filp) == 0)
38716 goto cleanup;
38717 @@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38718 tty_port_close_end(&info->port, tty);
38719 info->port.tty = NULL;
38720 cleanup:
38721 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
38722 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
38723 }
38724
38725 static void hangup(struct tty_struct *tty)
38726 @@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
38727 shutdown(info);
38728
38729 spin_lock_irqsave(&info->port.lock, flags);
38730 - info->port.count = 0;
38731 + atomic_set(&info->port.count, 0);
38732 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38733 info->port.tty = NULL;
38734 spin_unlock_irqrestore(&info->port.lock, flags);
38735 @@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38736 unsigned short new_crctype;
38737
38738 /* return error if TTY interface open */
38739 - if (info->port.count)
38740 + if (atomic_read(&info->port.count))
38741 return -EBUSY;
38742
38743 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
38744 @@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
38745
38746 /* arbitrate between network and tty opens */
38747 spin_lock_irqsave(&info->netlock, flags);
38748 - if (info->port.count != 0 || info->netcount != 0) {
38749 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38750 DBGINFO(("%s hdlc_open busy\n", dev->name));
38751 spin_unlock_irqrestore(&info->netlock, flags);
38752 return -EBUSY;
38753 @@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38754 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
38755
38756 /* return error if TTY interface open */
38757 - if (info->port.count)
38758 + if (atomic_read(&info->port.count))
38759 return -EBUSY;
38760
38761 if (cmd != SIOCWANDEV)
38762 @@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
38763 if (port == NULL)
38764 continue;
38765 spin_lock(&port->lock);
38766 - if ((port->port.count || port->netcount) &&
38767 + if ((atomic_read(&port->port.count) || port->netcount) &&
38768 port->pending_bh && !port->bh_running &&
38769 !port->bh_requested) {
38770 DBGISR(("%s bh queued\n", port->device_name));
38771 @@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38772 spin_lock_irqsave(&info->lock, flags);
38773 if (!tty_hung_up_p(filp)) {
38774 extra_count = true;
38775 - port->count--;
38776 + atomic_dec(&port->count);
38777 }
38778 spin_unlock_irqrestore(&info->lock, flags);
38779 port->blocked_open++;
38780 @@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38781 remove_wait_queue(&port->open_wait, &wait);
38782
38783 if (extra_count)
38784 - port->count++;
38785 + atomic_inc(&port->count);
38786 port->blocked_open--;
38787
38788 if (!retval)
38789 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
38790 index a3dddc1..8905ab2 100644
38791 --- a/drivers/tty/synclinkmp.c
38792 +++ b/drivers/tty/synclinkmp.c
38793 @@ -742,7 +742,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38794
38795 if (debug_level >= DEBUG_LEVEL_INFO)
38796 printk("%s(%d):%s open(), old ref count = %d\n",
38797 - __FILE__,__LINE__,tty->driver->name, info->port.count);
38798 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38799
38800 /* If port is closing, signal caller to try again */
38801 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38802 @@ -761,10 +761,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38803 spin_unlock_irqrestore(&info->netlock, flags);
38804 goto cleanup;
38805 }
38806 - info->port.count++;
38807 + atomic_inc(&info->port.count);
38808 spin_unlock_irqrestore(&info->netlock, flags);
38809
38810 - if (info->port.count == 1) {
38811 + if (atomic_read(&info->port.count) == 1) {
38812 /* 1st open on this device, init hardware */
38813 retval = startup(info);
38814 if (retval < 0)
38815 @@ -788,8 +788,8 @@ cleanup:
38816 if (retval) {
38817 if (tty->count == 1)
38818 info->port.tty = NULL; /* tty layer will release tty struct */
38819 - if(info->port.count)
38820 - info->port.count--;
38821 + if(atomic_read(&info->port.count))
38822 + atomic_dec(&info->port.count);
38823 }
38824
38825 return retval;
38826 @@ -807,7 +807,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38827
38828 if (debug_level >= DEBUG_LEVEL_INFO)
38829 printk("%s(%d):%s close() entry, count=%d\n",
38830 - __FILE__,__LINE__, info->device_name, info->port.count);
38831 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38832
38833 if (tty_port_close_start(&info->port, tty, filp) == 0)
38834 goto cleanup;
38835 @@ -826,7 +826,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38836 cleanup:
38837 if (debug_level >= DEBUG_LEVEL_INFO)
38838 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
38839 - tty->driver->name, info->port.count);
38840 + tty->driver->name, atomic_read(&info->port.count));
38841 }
38842
38843 /* Called by tty_hangup() when a hangup is signaled.
38844 @@ -849,7 +849,7 @@ static void hangup(struct tty_struct *tty)
38845 shutdown(info);
38846
38847 spin_lock_irqsave(&info->port.lock, flags);
38848 - info->port.count = 0;
38849 + atomic_set(&info->port.count, 0);
38850 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38851 info->port.tty = NULL;
38852 spin_unlock_irqrestore(&info->port.lock, flags);
38853 @@ -1557,7 +1557,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38854 unsigned short new_crctype;
38855
38856 /* return error if TTY interface open */
38857 - if (info->port.count)
38858 + if (atomic_read(&info->port.count))
38859 return -EBUSY;
38860
38861 switch (encoding)
38862 @@ -1652,7 +1652,7 @@ static int hdlcdev_open(struct net_device *dev)
38863
38864 /* arbitrate between network and tty opens */
38865 spin_lock_irqsave(&info->netlock, flags);
38866 - if (info->port.count != 0 || info->netcount != 0) {
38867 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38868 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38869 spin_unlock_irqrestore(&info->netlock, flags);
38870 return -EBUSY;
38871 @@ -1738,7 +1738,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38872 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38873
38874 /* return error if TTY interface open */
38875 - if (info->port.count)
38876 + if (atomic_read(&info->port.count))
38877 return -EBUSY;
38878
38879 if (cmd != SIOCWANDEV)
38880 @@ -2623,7 +2623,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
38881 * do not request bottom half processing if the
38882 * device is not open in a normal mode.
38883 */
38884 - if ( port && (port->port.count || port->netcount) &&
38885 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
38886 port->pending_bh && !port->bh_running &&
38887 !port->bh_requested ) {
38888 if ( debug_level >= DEBUG_LEVEL_ISR )
38889 @@ -3321,12 +3321,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38890
38891 if (debug_level >= DEBUG_LEVEL_INFO)
38892 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
38893 - __FILE__,__LINE__, tty->driver->name, port->count );
38894 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38895
38896 spin_lock_irqsave(&info->lock, flags);
38897 if (!tty_hung_up_p(filp)) {
38898 extra_count = true;
38899 - port->count--;
38900 + atomic_dec(&port->count);
38901 }
38902 spin_unlock_irqrestore(&info->lock, flags);
38903 port->blocked_open++;
38904 @@ -3355,7 +3355,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38905
38906 if (debug_level >= DEBUG_LEVEL_INFO)
38907 printk("%s(%d):%s block_til_ready() count=%d\n",
38908 - __FILE__,__LINE__, tty->driver->name, port->count );
38909 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38910
38911 tty_unlock();
38912 schedule();
38913 @@ -3366,12 +3366,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38914 remove_wait_queue(&port->open_wait, &wait);
38915
38916 if (extra_count)
38917 - port->count++;
38918 + atomic_inc(&port->count);
38919 port->blocked_open--;
38920
38921 if (debug_level >= DEBUG_LEVEL_INFO)
38922 printk("%s(%d):%s block_til_ready() after, count=%d\n",
38923 - __FILE__,__LINE__, tty->driver->name, port->count );
38924 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38925
38926 if (!retval)
38927 port->flags |= ASYNC_NORMAL_ACTIVE;
38928 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
38929 index 05728894..b9d44c6 100644
38930 --- a/drivers/tty/sysrq.c
38931 +++ b/drivers/tty/sysrq.c
38932 @@ -865,7 +865,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
38933 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
38934 size_t count, loff_t *ppos)
38935 {
38936 - if (count) {
38937 + if (count && capable(CAP_SYS_ADMIN)) {
38938 char c;
38939
38940 if (get_user(c, buf))
38941 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
38942 index b425c79..08a3f06 100644
38943 --- a/drivers/tty/tty_io.c
38944 +++ b/drivers/tty/tty_io.c
38945 @@ -3283,7 +3283,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
38946
38947 void tty_default_fops(struct file_operations *fops)
38948 {
38949 - *fops = tty_fops;
38950 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
38951 }
38952
38953 /*
38954 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
38955 index 6f99c99..8947bc4 100644
38956 --- a/drivers/tty/tty_ldisc.c
38957 +++ b/drivers/tty/tty_ldisc.c
38958 @@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
38959 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
38960 struct tty_ldisc_ops *ldo = ld->ops;
38961
38962 - ldo->refcount--;
38963 + atomic_dec(&ldo->refcount);
38964 module_put(ldo->owner);
38965 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38966
38967 @@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
38968 spin_lock_irqsave(&tty_ldisc_lock, flags);
38969 tty_ldiscs[disc] = new_ldisc;
38970 new_ldisc->num = disc;
38971 - new_ldisc->refcount = 0;
38972 + atomic_set(&new_ldisc->refcount, 0);
38973 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38974
38975 return ret;
38976 @@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
38977 return -EINVAL;
38978
38979 spin_lock_irqsave(&tty_ldisc_lock, flags);
38980 - if (tty_ldiscs[disc]->refcount)
38981 + if (atomic_read(&tty_ldiscs[disc]->refcount))
38982 ret = -EBUSY;
38983 else
38984 tty_ldiscs[disc] = NULL;
38985 @@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
38986 if (ldops) {
38987 ret = ERR_PTR(-EAGAIN);
38988 if (try_module_get(ldops->owner)) {
38989 - ldops->refcount++;
38990 + atomic_inc(&ldops->refcount);
38991 ret = ldops;
38992 }
38993 }
38994 @@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
38995 unsigned long flags;
38996
38997 spin_lock_irqsave(&tty_ldisc_lock, flags);
38998 - ldops->refcount--;
38999 + atomic_dec(&ldops->refcount);
39000 module_put(ldops->owner);
39001 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
39002 }
39003 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
39004 index bf6e238..d401c04 100644
39005 --- a/drivers/tty/tty_port.c
39006 +++ b/drivers/tty/tty_port.c
39007 @@ -138,7 +138,7 @@ void tty_port_hangup(struct tty_port *port)
39008 unsigned long flags;
39009
39010 spin_lock_irqsave(&port->lock, flags);
39011 - port->count = 0;
39012 + atomic_set(&port->count, 0);
39013 port->flags &= ~ASYNC_NORMAL_ACTIVE;
39014 if (port->tty) {
39015 set_bit(TTY_IO_ERROR, &port->tty->flags);
39016 @@ -264,7 +264,7 @@ int tty_port_block_til_ready(struct tty_port *port,
39017 /* The port lock protects the port counts */
39018 spin_lock_irqsave(&port->lock, flags);
39019 if (!tty_hung_up_p(filp))
39020 - port->count--;
39021 + atomic_dec(&port->count);
39022 port->blocked_open++;
39023 spin_unlock_irqrestore(&port->lock, flags);
39024
39025 @@ -306,7 +306,7 @@ int tty_port_block_til_ready(struct tty_port *port,
39026 we must not mess that up further */
39027 spin_lock_irqsave(&port->lock, flags);
39028 if (!tty_hung_up_p(filp))
39029 - port->count++;
39030 + atomic_inc(&port->count);
39031 port->blocked_open--;
39032 if (retval == 0)
39033 port->flags |= ASYNC_NORMAL_ACTIVE;
39034 @@ -326,19 +326,19 @@ int tty_port_close_start(struct tty_port *port,
39035 return 0;
39036 }
39037
39038 - if (tty->count == 1 && port->count != 1) {
39039 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
39040 printk(KERN_WARNING
39041 "tty_port_close_start: tty->count = 1 port count = %d.\n",
39042 - port->count);
39043 - port->count = 1;
39044 + atomic_read(&port->count));
39045 + atomic_set(&port->count, 1);
39046 }
39047 - if (--port->count < 0) {
39048 + if (atomic_dec_return(&port->count) < 0) {
39049 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
39050 - port->count);
39051 - port->count = 0;
39052 + atomic_read(&port->count));
39053 + atomic_set(&port->count, 0);
39054 }
39055
39056 - if (port->count) {
39057 + if (atomic_read(&port->count)) {
39058 spin_unlock_irqrestore(&port->lock, flags);
39059 if (port->ops->drop)
39060 port->ops->drop(port);
39061 @@ -418,7 +418,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
39062 {
39063 spin_lock_irq(&port->lock);
39064 if (!tty_hung_up_p(filp))
39065 - ++port->count;
39066 + atomic_inc(&port->count);
39067 spin_unlock_irq(&port->lock);
39068 tty_port_tty_set(port, tty);
39069
39070 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
39071 index 770a854..e5d3db3 100644
39072 --- a/drivers/tty/vt/keyboard.c
39073 +++ b/drivers/tty/vt/keyboard.c
39074 @@ -659,6 +659,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
39075 kbd->kbdmode == VC_OFF) &&
39076 value != KVAL(K_SAK))
39077 return; /* SAK is allowed even in raw mode */
39078 +
39079 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
39080 + {
39081 + void *func = fn_handler[value];
39082 + if (func == fn_show_state || func == fn_show_ptregs ||
39083 + func == fn_show_mem)
39084 + return;
39085 + }
39086 +#endif
39087 +
39088 fn_handler[value](vc);
39089 }
39090
39091 @@ -1805,9 +1815,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
39092 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
39093 return -EFAULT;
39094
39095 - if (!capable(CAP_SYS_TTY_CONFIG))
39096 - perm = 0;
39097 -
39098 switch (cmd) {
39099 case KDGKBENT:
39100 /* Ensure another thread doesn't free it under us */
39101 @@ -1822,6 +1829,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
39102 spin_unlock_irqrestore(&kbd_event_lock, flags);
39103 return put_user(val, &user_kbe->kb_value);
39104 case KDSKBENT:
39105 + if (!capable(CAP_SYS_TTY_CONFIG))
39106 + perm = 0;
39107 +
39108 if (!perm)
39109 return -EPERM;
39110 if (!i && v == K_NOSUCHMAP) {
39111 @@ -1912,9 +1922,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
39112 int i, j, k;
39113 int ret;
39114
39115 - if (!capable(CAP_SYS_TTY_CONFIG))
39116 - perm = 0;
39117 -
39118 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
39119 if (!kbs) {
39120 ret = -ENOMEM;
39121 @@ -1948,6 +1955,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
39122 kfree(kbs);
39123 return ((p && *p) ? -EOVERFLOW : 0);
39124 case KDSKBSENT:
39125 + if (!capable(CAP_SYS_TTY_CONFIG))
39126 + perm = 0;
39127 +
39128 if (!perm) {
39129 ret = -EPERM;
39130 goto reterr;
39131 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
39132 index a783d53..cb30d94 100644
39133 --- a/drivers/uio/uio.c
39134 +++ b/drivers/uio/uio.c
39135 @@ -25,6 +25,7 @@
39136 #include <linux/kobject.h>
39137 #include <linux/cdev.h>
39138 #include <linux/uio_driver.h>
39139 +#include <asm/local.h>
39140
39141 #define UIO_MAX_DEVICES (1U << MINORBITS)
39142
39143 @@ -32,10 +33,10 @@ struct uio_device {
39144 struct module *owner;
39145 struct device *dev;
39146 int minor;
39147 - atomic_t event;
39148 + atomic_unchecked_t event;
39149 struct fasync_struct *async_queue;
39150 wait_queue_head_t wait;
39151 - int vma_count;
39152 + local_t vma_count;
39153 struct uio_info *info;
39154 struct kobject *map_dir;
39155 struct kobject *portio_dir;
39156 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
39157 struct device_attribute *attr, char *buf)
39158 {
39159 struct uio_device *idev = dev_get_drvdata(dev);
39160 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
39161 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
39162 }
39163
39164 static struct device_attribute uio_class_attributes[] = {
39165 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
39166 {
39167 struct uio_device *idev = info->uio_dev;
39168
39169 - atomic_inc(&idev->event);
39170 + atomic_inc_unchecked(&idev->event);
39171 wake_up_interruptible(&idev->wait);
39172 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
39173 }
39174 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
39175 }
39176
39177 listener->dev = idev;
39178 - listener->event_count = atomic_read(&idev->event);
39179 + listener->event_count = atomic_read_unchecked(&idev->event);
39180 filep->private_data = listener;
39181
39182 if (idev->info->open) {
39183 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
39184 return -EIO;
39185
39186 poll_wait(filep, &idev->wait, wait);
39187 - if (listener->event_count != atomic_read(&idev->event))
39188 + if (listener->event_count != atomic_read_unchecked(&idev->event))
39189 return POLLIN | POLLRDNORM;
39190 return 0;
39191 }
39192 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
39193 do {
39194 set_current_state(TASK_INTERRUPTIBLE);
39195
39196 - event_count = atomic_read(&idev->event);
39197 + event_count = atomic_read_unchecked(&idev->event);
39198 if (event_count != listener->event_count) {
39199 if (copy_to_user(buf, &event_count, count))
39200 retval = -EFAULT;
39201 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
39202 static void uio_vma_open(struct vm_area_struct *vma)
39203 {
39204 struct uio_device *idev = vma->vm_private_data;
39205 - idev->vma_count++;
39206 + local_inc(&idev->vma_count);
39207 }
39208
39209 static void uio_vma_close(struct vm_area_struct *vma)
39210 {
39211 struct uio_device *idev = vma->vm_private_data;
39212 - idev->vma_count--;
39213 + local_dec(&idev->vma_count);
39214 }
39215
39216 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
39217 @@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
39218 idev->owner = owner;
39219 idev->info = info;
39220 init_waitqueue_head(&idev->wait);
39221 - atomic_set(&idev->event, 0);
39222 + atomic_set_unchecked(&idev->event, 0);
39223
39224 ret = uio_get_minor(idev);
39225 if (ret)
39226 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
39227 index b7eb86a..36d28af 100644
39228 --- a/drivers/usb/atm/cxacru.c
39229 +++ b/drivers/usb/atm/cxacru.c
39230 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
39231 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
39232 if (ret < 2)
39233 return -EINVAL;
39234 - if (index < 0 || index > 0x7f)
39235 + if (index > 0x7f)
39236 return -EINVAL;
39237 pos += tmp;
39238
39239 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
39240 index ee62b35..b663594 100644
39241 --- a/drivers/usb/atm/usbatm.c
39242 +++ b/drivers/usb/atm/usbatm.c
39243 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39244 if (printk_ratelimit())
39245 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
39246 __func__, vpi, vci);
39247 - atomic_inc(&vcc->stats->rx_err);
39248 + atomic_inc_unchecked(&vcc->stats->rx_err);
39249 return;
39250 }
39251
39252 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39253 if (length > ATM_MAX_AAL5_PDU) {
39254 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
39255 __func__, length, vcc);
39256 - atomic_inc(&vcc->stats->rx_err);
39257 + atomic_inc_unchecked(&vcc->stats->rx_err);
39258 goto out;
39259 }
39260
39261 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39262 if (sarb->len < pdu_length) {
39263 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
39264 __func__, pdu_length, sarb->len, vcc);
39265 - atomic_inc(&vcc->stats->rx_err);
39266 + atomic_inc_unchecked(&vcc->stats->rx_err);
39267 goto out;
39268 }
39269
39270 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
39271 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
39272 __func__, vcc);
39273 - atomic_inc(&vcc->stats->rx_err);
39274 + atomic_inc_unchecked(&vcc->stats->rx_err);
39275 goto out;
39276 }
39277
39278 @@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39279 if (printk_ratelimit())
39280 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
39281 __func__, length);
39282 - atomic_inc(&vcc->stats->rx_drop);
39283 + atomic_inc_unchecked(&vcc->stats->rx_drop);
39284 goto out;
39285 }
39286
39287 @@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39288
39289 vcc->push(vcc, skb);
39290
39291 - atomic_inc(&vcc->stats->rx);
39292 + atomic_inc_unchecked(&vcc->stats->rx);
39293 out:
39294 skb_trim(sarb, 0);
39295 }
39296 @@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
39297 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
39298
39299 usbatm_pop(vcc, skb);
39300 - atomic_inc(&vcc->stats->tx);
39301 + atomic_inc_unchecked(&vcc->stats->tx);
39302
39303 skb = skb_dequeue(&instance->sndqueue);
39304 }
39305 @@ -770,11 +770,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
39306 if (!left--)
39307 return sprintf(page,
39308 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
39309 - atomic_read(&atm_dev->stats.aal5.tx),
39310 - atomic_read(&atm_dev->stats.aal5.tx_err),
39311 - atomic_read(&atm_dev->stats.aal5.rx),
39312 - atomic_read(&atm_dev->stats.aal5.rx_err),
39313 - atomic_read(&atm_dev->stats.aal5.rx_drop));
39314 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
39315 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
39316 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
39317 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
39318 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
39319
39320 if (!left--) {
39321 if (instance->disconnected)
39322 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
39323 index 3440812..2a4ef1f 100644
39324 --- a/drivers/usb/core/devices.c
39325 +++ b/drivers/usb/core/devices.c
39326 @@ -126,7 +126,7 @@ static const char format_endpt[] =
39327 * time it gets called.
39328 */
39329 static struct device_connect_event {
39330 - atomic_t count;
39331 + atomic_unchecked_t count;
39332 wait_queue_head_t wait;
39333 } device_event = {
39334 .count = ATOMIC_INIT(1),
39335 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
39336
39337 void usbfs_conn_disc_event(void)
39338 {
39339 - atomic_add(2, &device_event.count);
39340 + atomic_add_unchecked(2, &device_event.count);
39341 wake_up(&device_event.wait);
39342 }
39343
39344 @@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
39345
39346 poll_wait(file, &device_event.wait, wait);
39347
39348 - event_count = atomic_read(&device_event.count);
39349 + event_count = atomic_read_unchecked(&device_event.count);
39350 if (file->f_version != event_count) {
39351 file->f_version = event_count;
39352 return POLLIN | POLLRDNORM;
39353 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
39354 index 89dcf15..481800b 100644
39355 --- a/drivers/usb/early/ehci-dbgp.c
39356 +++ b/drivers/usb/early/ehci-dbgp.c
39357 @@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
39358
39359 #ifdef CONFIG_KGDB
39360 static struct kgdb_io kgdbdbgp_io_ops;
39361 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
39362 +static struct kgdb_io kgdbdbgp_io_ops_console;
39363 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
39364 #else
39365 #define dbgp_kgdb_mode (0)
39366 #endif
39367 @@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
39368 .write_char = kgdbdbgp_write_char,
39369 };
39370
39371 +static struct kgdb_io kgdbdbgp_io_ops_console = {
39372 + .name = "kgdbdbgp",
39373 + .read_char = kgdbdbgp_read_char,
39374 + .write_char = kgdbdbgp_write_char,
39375 + .is_console = 1
39376 +};
39377 +
39378 static int kgdbdbgp_wait_time;
39379
39380 static int __init kgdbdbgp_parse_config(char *str)
39381 @@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
39382 ptr++;
39383 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
39384 }
39385 - kgdb_register_io_module(&kgdbdbgp_io_ops);
39386 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
39387 + if (early_dbgp_console.index != -1)
39388 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
39389 + else
39390 + kgdb_register_io_module(&kgdbdbgp_io_ops);
39391
39392 return 0;
39393 }
39394 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
39395 index da6d479..80ed10b 100644
39396 --- a/drivers/usb/gadget/u_serial.c
39397 +++ b/drivers/usb/gadget/u_serial.c
39398 @@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
39399 spin_lock_irq(&port->port_lock);
39400
39401 /* already open? Great. */
39402 - if (port->port.count) {
39403 + if (atomic_read(&port->port.count)) {
39404 status = 0;
39405 - port->port.count++;
39406 + atomic_inc(&port->port.count);
39407
39408 /* currently opening/closing? wait ... */
39409 } else if (port->openclose) {
39410 @@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
39411 tty->driver_data = port;
39412 port->port.tty = tty;
39413
39414 - port->port.count = 1;
39415 + atomic_set(&port->port.count, 1);
39416 port->openclose = false;
39417
39418 /* if connected, start the I/O stream */
39419 @@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
39420
39421 spin_lock_irq(&port->port_lock);
39422
39423 - if (port->port.count != 1) {
39424 - if (port->port.count == 0)
39425 + if (atomic_read(&port->port.count) != 1) {
39426 + if (atomic_read(&port->port.count) == 0)
39427 WARN_ON(1);
39428 else
39429 - --port->port.count;
39430 + atomic_dec(&port->port.count);
39431 goto exit;
39432 }
39433
39434 @@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
39435 * and sleep if necessary
39436 */
39437 port->openclose = true;
39438 - port->port.count = 0;
39439 + atomic_set(&port->port.count, 0);
39440
39441 gser = port->port_usb;
39442 if (gser && gser->disconnect)
39443 @@ -1156,7 +1156,7 @@ static int gs_closed(struct gs_port *port)
39444 int cond;
39445
39446 spin_lock_irq(&port->port_lock);
39447 - cond = (port->port.count == 0) && !port->openclose;
39448 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
39449 spin_unlock_irq(&port->port_lock);
39450 return cond;
39451 }
39452 @@ -1269,7 +1269,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
39453 /* if it's already open, start I/O ... and notify the serial
39454 * protocol about open/close status (connect/disconnect).
39455 */
39456 - if (port->port.count) {
39457 + if (atomic_read(&port->port.count)) {
39458 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
39459 gs_start_io(port);
39460 if (gser->connect)
39461 @@ -1316,7 +1316,7 @@ void gserial_disconnect(struct gserial *gser)
39462
39463 port->port_usb = NULL;
39464 gser->ioport = NULL;
39465 - if (port->port.count > 0 || port->openclose) {
39466 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
39467 wake_up_interruptible(&port->drain_wait);
39468 if (port->port.tty)
39469 tty_hangup(port->port.tty);
39470 @@ -1332,7 +1332,7 @@ void gserial_disconnect(struct gserial *gser)
39471
39472 /* finally, free any unused/unusable I/O buffers */
39473 spin_lock_irqsave(&port->port_lock, flags);
39474 - if (port->port.count == 0 && !port->openclose)
39475 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
39476 gs_buf_free(&port->port_write_buf);
39477 gs_free_requests(gser->out, &port->read_pool, NULL);
39478 gs_free_requests(gser->out, &port->read_queue, NULL);
39479 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
39480 index b9cca6d..75c75df 100644
39481 --- a/drivers/usb/serial/console.c
39482 +++ b/drivers/usb/serial/console.c
39483 @@ -127,7 +127,7 @@ static int usb_console_setup(struct console *co, char *options)
39484
39485 info->port = port;
39486
39487 - ++port->port.count;
39488 + atomic_inc(&port->port.count);
39489 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
39490 if (serial->type->set_termios) {
39491 /*
39492 @@ -177,7 +177,7 @@ static int usb_console_setup(struct console *co, char *options)
39493 }
39494 /* Now that any required fake tty operations are completed restore
39495 * the tty port count */
39496 - --port->port.count;
39497 + atomic_dec(&port->port.count);
39498 /* The console is special in terms of closing the device so
39499 * indicate this port is now acting as a system console. */
39500 port->port.console = 1;
39501 @@ -190,7 +190,7 @@ static int usb_console_setup(struct console *co, char *options)
39502 free_tty:
39503 kfree(tty);
39504 reset_open_count:
39505 - port->port.count = 0;
39506 + atomic_set(&port->port.count, 0);
39507 usb_autopm_put_interface(serial->interface);
39508 error_get_interface:
39509 usb_serial_put(serial);
39510 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
39511 index d6bea3e..60b250e 100644
39512 --- a/drivers/usb/wusbcore/wa-hc.h
39513 +++ b/drivers/usb/wusbcore/wa-hc.h
39514 @@ -192,7 +192,7 @@ struct wahc {
39515 struct list_head xfer_delayed_list;
39516 spinlock_t xfer_list_lock;
39517 struct work_struct xfer_work;
39518 - atomic_t xfer_id_count;
39519 + atomic_unchecked_t xfer_id_count;
39520 };
39521
39522
39523 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
39524 INIT_LIST_HEAD(&wa->xfer_delayed_list);
39525 spin_lock_init(&wa->xfer_list_lock);
39526 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
39527 - atomic_set(&wa->xfer_id_count, 1);
39528 + atomic_set_unchecked(&wa->xfer_id_count, 1);
39529 }
39530
39531 /**
39532 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
39533 index 57c01ab..8a05959 100644
39534 --- a/drivers/usb/wusbcore/wa-xfer.c
39535 +++ b/drivers/usb/wusbcore/wa-xfer.c
39536 @@ -296,7 +296,7 @@ out:
39537 */
39538 static void wa_xfer_id_init(struct wa_xfer *xfer)
39539 {
39540 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
39541 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
39542 }
39543
39544 /*
39545 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
39546 index ef82a0d..da8a0b3 100644
39547 --- a/drivers/vhost/vhost.c
39548 +++ b/drivers/vhost/vhost.c
39549 @@ -634,7 +634,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
39550 return 0;
39551 }
39552
39553 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
39554 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
39555 {
39556 struct file *eventfp, *filep = NULL,
39557 *pollstart = NULL, *pollstop = NULL;
39558 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
39559 index 747442d..7c0c434 100644
39560 --- a/drivers/video/aty/aty128fb.c
39561 +++ b/drivers/video/aty/aty128fb.c
39562 @@ -149,7 +149,7 @@ enum {
39563 };
39564
39565 /* Must match above enum */
39566 -static const char *r128_family[] __devinitdata = {
39567 +static const char *r128_family[] __devinitconst = {
39568 "AGP",
39569 "PCI",
39570 "PRO AGP",
39571 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
39572 index 5c3960d..15cf8fc 100644
39573 --- a/drivers/video/fbcmap.c
39574 +++ b/drivers/video/fbcmap.c
39575 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
39576 rc = -ENODEV;
39577 goto out;
39578 }
39579 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
39580 - !info->fbops->fb_setcmap)) {
39581 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
39582 rc = -EINVAL;
39583 goto out1;
39584 }
39585 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
39586 index 0dff12a..2ef47b3 100644
39587 --- a/drivers/video/fbmem.c
39588 +++ b/drivers/video/fbmem.c
39589 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39590 image->dx += image->width + 8;
39591 }
39592 } else if (rotate == FB_ROTATE_UD) {
39593 - for (x = 0; x < num && image->dx >= 0; x++) {
39594 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
39595 info->fbops->fb_imageblit(info, image);
39596 image->dx -= image->width + 8;
39597 }
39598 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39599 image->dy += image->height + 8;
39600 }
39601 } else if (rotate == FB_ROTATE_CCW) {
39602 - for (x = 0; x < num && image->dy >= 0; x++) {
39603 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
39604 info->fbops->fb_imageblit(info, image);
39605 image->dy -= image->height + 8;
39606 }
39607 @@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
39608 return -EFAULT;
39609 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
39610 return -EINVAL;
39611 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
39612 + if (con2fb.framebuffer >= FB_MAX)
39613 return -EINVAL;
39614 if (!registered_fb[con2fb.framebuffer])
39615 request_module("fb%d", con2fb.framebuffer);
39616 diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
39617 index 5a5d092..265c5ed 100644
39618 --- a/drivers/video/geode/gx1fb_core.c
39619 +++ b/drivers/video/geode/gx1fb_core.c
39620 @@ -29,7 +29,7 @@ static int crt_option = 1;
39621 static char panel_option[32] = "";
39622
39623 /* Modes relevant to the GX1 (taken from modedb.c) */
39624 -static const struct fb_videomode __devinitdata gx1_modedb[] = {
39625 +static const struct fb_videomode __devinitconst gx1_modedb[] = {
39626 /* 640x480-60 VESA */
39627 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
39628 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
39629 diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
39630 index 0fad23f..0e9afa4 100644
39631 --- a/drivers/video/gxt4500.c
39632 +++ b/drivers/video/gxt4500.c
39633 @@ -156,7 +156,7 @@ struct gxt4500_par {
39634 static char *mode_option;
39635
39636 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
39637 -static const struct fb_videomode defaultmode __devinitdata = {
39638 +static const struct fb_videomode defaultmode __devinitconst = {
39639 .refresh = 60,
39640 .xres = 1280,
39641 .yres = 1024,
39642 @@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
39643 return 0;
39644 }
39645
39646 -static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
39647 +static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
39648 .id = "IBM GXT4500P",
39649 .type = FB_TYPE_PACKED_PIXELS,
39650 .visual = FB_VISUAL_PSEUDOCOLOR,
39651 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
39652 index 7672d2e..b56437f 100644
39653 --- a/drivers/video/i810/i810_accel.c
39654 +++ b/drivers/video/i810/i810_accel.c
39655 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
39656 }
39657 }
39658 printk("ringbuffer lockup!!!\n");
39659 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
39660 i810_report_error(mmio);
39661 par->dev_flags |= LOCKUP;
39662 info->pixmap.scan_align = 1;
39663 diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
39664 index b83f361..2b05a91 100644
39665 --- a/drivers/video/i810/i810_main.c
39666 +++ b/drivers/video/i810/i810_main.c
39667 @@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
39668 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
39669
39670 /* PCI */
39671 -static const char *i810_pci_list[] __devinitdata = {
39672 +static const char *i810_pci_list[] __devinitconst = {
39673 "Intel(R) 810 Framebuffer Device" ,
39674 "Intel(R) 810-DC100 Framebuffer Device" ,
39675 "Intel(R) 810E Framebuffer Device" ,
39676 diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
39677 index de36693..3c63fc2 100644
39678 --- a/drivers/video/jz4740_fb.c
39679 +++ b/drivers/video/jz4740_fb.c
39680 @@ -136,7 +136,7 @@ struct jzfb {
39681 uint32_t pseudo_palette[16];
39682 };
39683
39684 -static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
39685 +static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
39686 .id = "JZ4740 FB",
39687 .type = FB_TYPE_PACKED_PIXELS,
39688 .visual = FB_VISUAL_TRUECOLOR,
39689 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
39690 index 3c14e43..eafa544 100644
39691 --- a/drivers/video/logo/logo_linux_clut224.ppm
39692 +++ b/drivers/video/logo/logo_linux_clut224.ppm
39693 @@ -1,1604 +1,1123 @@
39694 P3
39695 -# Standard 224-color Linux logo
39696 80 80
39697 255
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 - 6 6 6 6 6 6 10 10 10 10 10 10
39708 - 10 10 10 6 6 6 6 6 6 6 6 6
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 0 0 0 0 0 0 0 0 0
39716 - 0 0 0 0 0 0 0 0 0 0 0 0
39717 - 0 0 0 0 0 0 0 0 0 0 0 0
39718 - 0 0 0 0 0 0 0 0 0 0 0 0
39719 - 0 0 0 0 0 0 0 0 0 0 0 0
39720 - 0 0 0 0 0 0 0 0 0 0 0 0
39721 - 0 0 0 0 0 0 0 0 0 0 0 0
39722 - 0 0 0 0 0 0 0 0 0 0 0 0
39723 - 0 0 0 0 0 0 0 0 0 0 0 0
39724 - 0 0 0 0 0 0 0 0 0 0 0 0
39725 - 0 0 0 0 0 0 0 0 0 0 0 0
39726 - 0 0 0 6 6 6 10 10 10 14 14 14
39727 - 22 22 22 26 26 26 30 30 30 34 34 34
39728 - 30 30 30 30 30 30 26 26 26 18 18 18
39729 - 14 14 14 10 10 10 6 6 6 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 - 0 0 0 0 0 0 0 0 0 0 0 0
39736 - 0 0 0 0 0 0 0 0 0 0 0 0
39737 - 0 0 0 0 0 0 0 0 0 0 0 0
39738 - 0 0 0 0 0 0 0 0 0 0 0 0
39739 - 0 0 0 0 0 1 0 0 1 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 - 6 6 6 14 14 14 26 26 26 42 42 42
39747 - 54 54 54 66 66 66 78 78 78 78 78 78
39748 - 78 78 78 74 74 74 66 66 66 54 54 54
39749 - 42 42 42 26 26 26 18 18 18 10 10 10
39750 - 6 6 6 0 0 0 0 0 0 0 0 0
39751 - 0 0 0 0 0 0 0 0 0 0 0 0
39752 - 0 0 0 0 0 0 0 0 0 0 0 0
39753 - 0 0 0 0 0 0 0 0 0 0 0 0
39754 - 0 0 0 0 0 0 0 0 0 0 0 0
39755 - 0 0 0 0 0 0 0 0 0 0 0 0
39756 - 0 0 0 0 0 0 0 0 0 0 0 0
39757 - 0 0 0 0 0 0 0 0 0 0 0 0
39758 - 0 0 0 0 0 0 0 0 0 0 0 0
39759 - 0 0 1 0 0 0 0 0 0 0 0 0
39760 - 0 0 0 0 0 0 0 0 0 0 0 0
39761 - 0 0 0 0 0 0 0 0 0 0 0 0
39762 - 0 0 0 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 10 10 10
39766 - 22 22 22 42 42 42 66 66 66 86 86 86
39767 - 66 66 66 38 38 38 38 38 38 22 22 22
39768 - 26 26 26 34 34 34 54 54 54 66 66 66
39769 - 86 86 86 70 70 70 46 46 46 26 26 26
39770 - 14 14 14 6 6 6 0 0 0 0 0 0
39771 - 0 0 0 0 0 0 0 0 0 0 0 0
39772 - 0 0 0 0 0 0 0 0 0 0 0 0
39773 - 0 0 0 0 0 0 0 0 0 0 0 0
39774 - 0 0 0 0 0 0 0 0 0 0 0 0
39775 - 0 0 0 0 0 0 0 0 0 0 0 0
39776 - 0 0 0 0 0 0 0 0 0 0 0 0
39777 - 0 0 0 0 0 0 0 0 0 0 0 0
39778 - 0 0 0 0 0 0 0 0 0 0 0 0
39779 - 0 0 1 0 0 1 0 0 1 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 10 10 10 26 26 26
39786 - 50 50 50 82 82 82 58 58 58 6 6 6
39787 - 2 2 6 2 2 6 2 2 6 2 2 6
39788 - 2 2 6 2 2 6 2 2 6 2 2 6
39789 - 6 6 6 54 54 54 86 86 86 66 66 66
39790 - 38 38 38 18 18 18 6 6 6 0 0 0
39791 - 0 0 0 0 0 0 0 0 0 0 0 0
39792 - 0 0 0 0 0 0 0 0 0 0 0 0
39793 - 0 0 0 0 0 0 0 0 0 0 0 0
39794 - 0 0 0 0 0 0 0 0 0 0 0 0
39795 - 0 0 0 0 0 0 0 0 0 0 0 0
39796 - 0 0 0 0 0 0 0 0 0 0 0 0
39797 - 0 0 0 0 0 0 0 0 0 0 0 0
39798 - 0 0 0 0 0 0 0 0 0 0 0 0
39799 - 0 0 0 0 0 0 0 0 0 0 0 0
39800 - 0 0 0 0 0 0 0 0 0 0 0 0
39801 - 0 0 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 6 6 6 22 22 22 50 50 50
39806 - 78 78 78 34 34 34 2 2 6 2 2 6
39807 - 2 2 6 2 2 6 2 2 6 2 2 6
39808 - 2 2 6 2 2 6 2 2 6 2 2 6
39809 - 2 2 6 2 2 6 6 6 6 70 70 70
39810 - 78 78 78 46 46 46 22 22 22 6 6 6
39811 - 0 0 0 0 0 0 0 0 0 0 0 0
39812 - 0 0 0 0 0 0 0 0 0 0 0 0
39813 - 0 0 0 0 0 0 0 0 0 0 0 0
39814 - 0 0 0 0 0 0 0 0 0 0 0 0
39815 - 0 0 0 0 0 0 0 0 0 0 0 0
39816 - 0 0 0 0 0 0 0 0 0 0 0 0
39817 - 0 0 0 0 0 0 0 0 0 0 0 0
39818 - 0 0 0 0 0 0 0 0 0 0 0 0
39819 - 0 0 1 0 0 1 0 0 1 0 0 0
39820 - 0 0 0 0 0 0 0 0 0 0 0 0
39821 - 0 0 0 0 0 0 0 0 0 0 0 0
39822 - 0 0 0 0 0 0 0 0 0 0 0 0
39823 - 0 0 0 0 0 0 0 0 0 0 0 0
39824 - 0 0 0 0 0 0 0 0 0 0 0 0
39825 - 6 6 6 18 18 18 42 42 42 82 82 82
39826 - 26 26 26 2 2 6 2 2 6 2 2 6
39827 - 2 2 6 2 2 6 2 2 6 2 2 6
39828 - 2 2 6 2 2 6 2 2 6 14 14 14
39829 - 46 46 46 34 34 34 6 6 6 2 2 6
39830 - 42 42 42 78 78 78 42 42 42 18 18 18
39831 - 6 6 6 0 0 0 0 0 0 0 0 0
39832 - 0 0 0 0 0 0 0 0 0 0 0 0
39833 - 0 0 0 0 0 0 0 0 0 0 0 0
39834 - 0 0 0 0 0 0 0 0 0 0 0 0
39835 - 0 0 0 0 0 0 0 0 0 0 0 0
39836 - 0 0 0 0 0 0 0 0 0 0 0 0
39837 - 0 0 0 0 0 0 0 0 0 0 0 0
39838 - 0 0 0 0 0 0 0 0 0 0 0 0
39839 - 0 0 1 0 0 0 0 0 1 0 0 0
39840 - 0 0 0 0 0 0 0 0 0 0 0 0
39841 - 0 0 0 0 0 0 0 0 0 0 0 0
39842 - 0 0 0 0 0 0 0 0 0 0 0 0
39843 - 0 0 0 0 0 0 0 0 0 0 0 0
39844 - 0 0 0 0 0 0 0 0 0 0 0 0
39845 - 10 10 10 30 30 30 66 66 66 58 58 58
39846 - 2 2 6 2 2 6 2 2 6 2 2 6
39847 - 2 2 6 2 2 6 2 2 6 2 2 6
39848 - 2 2 6 2 2 6 2 2 6 26 26 26
39849 - 86 86 86 101 101 101 46 46 46 10 10 10
39850 - 2 2 6 58 58 58 70 70 70 34 34 34
39851 - 10 10 10 0 0 0 0 0 0 0 0 0
39852 - 0 0 0 0 0 0 0 0 0 0 0 0
39853 - 0 0 0 0 0 0 0 0 0 0 0 0
39854 - 0 0 0 0 0 0 0 0 0 0 0 0
39855 - 0 0 0 0 0 0 0 0 0 0 0 0
39856 - 0 0 0 0 0 0 0 0 0 0 0 0
39857 - 0 0 0 0 0 0 0 0 0 0 0 0
39858 - 0 0 0 0 0 0 0 0 0 0 0 0
39859 - 0 0 1 0 0 1 0 0 1 0 0 0
39860 - 0 0 0 0 0 0 0 0 0 0 0 0
39861 - 0 0 0 0 0 0 0 0 0 0 0 0
39862 - 0 0 0 0 0 0 0 0 0 0 0 0
39863 - 0 0 0 0 0 0 0 0 0 0 0 0
39864 - 0 0 0 0 0 0 0 0 0 0 0 0
39865 - 14 14 14 42 42 42 86 86 86 10 10 10
39866 - 2 2 6 2 2 6 2 2 6 2 2 6
39867 - 2 2 6 2 2 6 2 2 6 2 2 6
39868 - 2 2 6 2 2 6 2 2 6 30 30 30
39869 - 94 94 94 94 94 94 58 58 58 26 26 26
39870 - 2 2 6 6 6 6 78 78 78 54 54 54
39871 - 22 22 22 6 6 6 0 0 0 0 0 0
39872 - 0 0 0 0 0 0 0 0 0 0 0 0
39873 - 0 0 0 0 0 0 0 0 0 0 0 0
39874 - 0 0 0 0 0 0 0 0 0 0 0 0
39875 - 0 0 0 0 0 0 0 0 0 0 0 0
39876 - 0 0 0 0 0 0 0 0 0 0 0 0
39877 - 0 0 0 0 0 0 0 0 0 0 0 0
39878 - 0 0 0 0 0 0 0 0 0 0 0 0
39879 - 0 0 0 0 0 0 0 0 0 0 0 0
39880 - 0 0 0 0 0 0 0 0 0 0 0 0
39881 - 0 0 0 0 0 0 0 0 0 0 0 0
39882 - 0 0 0 0 0 0 0 0 0 0 0 0
39883 - 0 0 0 0 0 0 0 0 0 0 0 0
39884 - 0 0 0 0 0 0 0 0 0 6 6 6
39885 - 22 22 22 62 62 62 62 62 62 2 2 6
39886 - 2 2 6 2 2 6 2 2 6 2 2 6
39887 - 2 2 6 2 2 6 2 2 6 2 2 6
39888 - 2 2 6 2 2 6 2 2 6 26 26 26
39889 - 54 54 54 38 38 38 18 18 18 10 10 10
39890 - 2 2 6 2 2 6 34 34 34 82 82 82
39891 - 38 38 38 14 14 14 0 0 0 0 0 0
39892 - 0 0 0 0 0 0 0 0 0 0 0 0
39893 - 0 0 0 0 0 0 0 0 0 0 0 0
39894 - 0 0 0 0 0 0 0 0 0 0 0 0
39895 - 0 0 0 0 0 0 0 0 0 0 0 0
39896 - 0 0 0 0 0 0 0 0 0 0 0 0
39897 - 0 0 0 0 0 0 0 0 0 0 0 0
39898 - 0 0 0 0 0 0 0 0 0 0 0 0
39899 - 0 0 0 0 0 1 0 0 1 0 0 0
39900 - 0 0 0 0 0 0 0 0 0 0 0 0
39901 - 0 0 0 0 0 0 0 0 0 0 0 0
39902 - 0 0 0 0 0 0 0 0 0 0 0 0
39903 - 0 0 0 0 0 0 0 0 0 0 0 0
39904 - 0 0 0 0 0 0 0 0 0 6 6 6
39905 - 30 30 30 78 78 78 30 30 30 2 2 6
39906 - 2 2 6 2 2 6 2 2 6 2 2 6
39907 - 2 2 6 2 2 6 2 2 6 2 2 6
39908 - 2 2 6 2 2 6 2 2 6 10 10 10
39909 - 10 10 10 2 2 6 2 2 6 2 2 6
39910 - 2 2 6 2 2 6 2 2 6 78 78 78
39911 - 50 50 50 18 18 18 6 6 6 0 0 0
39912 - 0 0 0 0 0 0 0 0 0 0 0 0
39913 - 0 0 0 0 0 0 0 0 0 0 0 0
39914 - 0 0 0 0 0 0 0 0 0 0 0 0
39915 - 0 0 0 0 0 0 0 0 0 0 0 0
39916 - 0 0 0 0 0 0 0 0 0 0 0 0
39917 - 0 0 0 0 0 0 0 0 0 0 0 0
39918 - 0 0 0 0 0 0 0 0 0 0 0 0
39919 - 0 0 1 0 0 0 0 0 0 0 0 0
39920 - 0 0 0 0 0 0 0 0 0 0 0 0
39921 - 0 0 0 0 0 0 0 0 0 0 0 0
39922 - 0 0 0 0 0 0 0 0 0 0 0 0
39923 - 0 0 0 0 0 0 0 0 0 0 0 0
39924 - 0 0 0 0 0 0 0 0 0 10 10 10
39925 - 38 38 38 86 86 86 14 14 14 2 2 6
39926 - 2 2 6 2 2 6 2 2 6 2 2 6
39927 - 2 2 6 2 2 6 2 2 6 2 2 6
39928 - 2 2 6 2 2 6 2 2 6 2 2 6
39929 - 2 2 6 2 2 6 2 2 6 2 2 6
39930 - 2 2 6 2 2 6 2 2 6 54 54 54
39931 - 66 66 66 26 26 26 6 6 6 0 0 0
39932 - 0 0 0 0 0 0 0 0 0 0 0 0
39933 - 0 0 0 0 0 0 0 0 0 0 0 0
39934 - 0 0 0 0 0 0 0 0 0 0 0 0
39935 - 0 0 0 0 0 0 0 0 0 0 0 0
39936 - 0 0 0 0 0 0 0 0 0 0 0 0
39937 - 0 0 0 0 0 0 0 0 0 0 0 0
39938 - 0 0 0 0 0 0 0 0 0 0 0 0
39939 - 0 0 0 0 0 1 0 0 1 0 0 0
39940 - 0 0 0 0 0 0 0 0 0 0 0 0
39941 - 0 0 0 0 0 0 0 0 0 0 0 0
39942 - 0 0 0 0 0 0 0 0 0 0 0 0
39943 - 0 0 0 0 0 0 0 0 0 0 0 0
39944 - 0 0 0 0 0 0 0 0 0 14 14 14
39945 - 42 42 42 82 82 82 2 2 6 2 2 6
39946 - 2 2 6 6 6 6 10 10 10 2 2 6
39947 - 2 2 6 2 2 6 2 2 6 2 2 6
39948 - 2 2 6 2 2 6 2 2 6 6 6 6
39949 - 14 14 14 10 10 10 2 2 6 2 2 6
39950 - 2 2 6 2 2 6 2 2 6 18 18 18
39951 - 82 82 82 34 34 34 10 10 10 0 0 0
39952 - 0 0 0 0 0 0 0 0 0 0 0 0
39953 - 0 0 0 0 0 0 0 0 0 0 0 0
39954 - 0 0 0 0 0 0 0 0 0 0 0 0
39955 - 0 0 0 0 0 0 0 0 0 0 0 0
39956 - 0 0 0 0 0 0 0 0 0 0 0 0
39957 - 0 0 0 0 0 0 0 0 0 0 0 0
39958 - 0 0 0 0 0 0 0 0 0 0 0 0
39959 - 0 0 1 0 0 0 0 0 0 0 0 0
39960 - 0 0 0 0 0 0 0 0 0 0 0 0
39961 - 0 0 0 0 0 0 0 0 0 0 0 0
39962 - 0 0 0 0 0 0 0 0 0 0 0 0
39963 - 0 0 0 0 0 0 0 0 0 0 0 0
39964 - 0 0 0 0 0 0 0 0 0 14 14 14
39965 - 46 46 46 86 86 86 2 2 6 2 2 6
39966 - 6 6 6 6 6 6 22 22 22 34 34 34
39967 - 6 6 6 2 2 6 2 2 6 2 2 6
39968 - 2 2 6 2 2 6 18 18 18 34 34 34
39969 - 10 10 10 50 50 50 22 22 22 2 2 6
39970 - 2 2 6 2 2 6 2 2 6 10 10 10
39971 - 86 86 86 42 42 42 14 14 14 0 0 0
39972 - 0 0 0 0 0 0 0 0 0 0 0 0
39973 - 0 0 0 0 0 0 0 0 0 0 0 0
39974 - 0 0 0 0 0 0 0 0 0 0 0 0
39975 - 0 0 0 0 0 0 0 0 0 0 0 0
39976 - 0 0 0 0 0 0 0 0 0 0 0 0
39977 - 0 0 0 0 0 0 0 0 0 0 0 0
39978 - 0 0 0 0 0 0 0 0 0 0 0 0
39979 - 0 0 1 0 0 1 0 0 1 0 0 0
39980 - 0 0 0 0 0 0 0 0 0 0 0 0
39981 - 0 0 0 0 0 0 0 0 0 0 0 0
39982 - 0 0 0 0 0 0 0 0 0 0 0 0
39983 - 0 0 0 0 0 0 0 0 0 0 0 0
39984 - 0 0 0 0 0 0 0 0 0 14 14 14
39985 - 46 46 46 86 86 86 2 2 6 2 2 6
39986 - 38 38 38 116 116 116 94 94 94 22 22 22
39987 - 22 22 22 2 2 6 2 2 6 2 2 6
39988 - 14 14 14 86 86 86 138 138 138 162 162 162
39989 -154 154 154 38 38 38 26 26 26 6 6 6
39990 - 2 2 6 2 2 6 2 2 6 2 2 6
39991 - 86 86 86 46 46 46 14 14 14 0 0 0
39992 - 0 0 0 0 0 0 0 0 0 0 0 0
39993 - 0 0 0 0 0 0 0 0 0 0 0 0
39994 - 0 0 0 0 0 0 0 0 0 0 0 0
39995 - 0 0 0 0 0 0 0 0 0 0 0 0
39996 - 0 0 0 0 0 0 0 0 0 0 0 0
39997 - 0 0 0 0 0 0 0 0 0 0 0 0
39998 - 0 0 0 0 0 0 0 0 0 0 0 0
39999 - 0 0 0 0 0 0 0 0 0 0 0 0
40000 - 0 0 0 0 0 0 0 0 0 0 0 0
40001 - 0 0 0 0 0 0 0 0 0 0 0 0
40002 - 0 0 0 0 0 0 0 0 0 0 0 0
40003 - 0 0 0 0 0 0 0 0 0 0 0 0
40004 - 0 0 0 0 0 0 0 0 0 14 14 14
40005 - 46 46 46 86 86 86 2 2 6 14 14 14
40006 -134 134 134 198 198 198 195 195 195 116 116 116
40007 - 10 10 10 2 2 6 2 2 6 6 6 6
40008 -101 98 89 187 187 187 210 210 210 218 218 218
40009 -214 214 214 134 134 134 14 14 14 6 6 6
40010 - 2 2 6 2 2 6 2 2 6 2 2 6
40011 - 86 86 86 50 50 50 18 18 18 6 6 6
40012 - 0 0 0 0 0 0 0 0 0 0 0 0
40013 - 0 0 0 0 0 0 0 0 0 0 0 0
40014 - 0 0 0 0 0 0 0 0 0 0 0 0
40015 - 0 0 0 0 0 0 0 0 0 0 0 0
40016 - 0 0 0 0 0 0 0 0 0 0 0 0
40017 - 0 0 0 0 0 0 0 0 0 0 0 0
40018 - 0 0 0 0 0 0 0 0 1 0 0 0
40019 - 0 0 1 0 0 1 0 0 1 0 0 0
40020 - 0 0 0 0 0 0 0 0 0 0 0 0
40021 - 0 0 0 0 0 0 0 0 0 0 0 0
40022 - 0 0 0 0 0 0 0 0 0 0 0 0
40023 - 0 0 0 0 0 0 0 0 0 0 0 0
40024 - 0 0 0 0 0 0 0 0 0 14 14 14
40025 - 46 46 46 86 86 86 2 2 6 54 54 54
40026 -218 218 218 195 195 195 226 226 226 246 246 246
40027 - 58 58 58 2 2 6 2 2 6 30 30 30
40028 -210 210 210 253 253 253 174 174 174 123 123 123
40029 -221 221 221 234 234 234 74 74 74 2 2 6
40030 - 2 2 6 2 2 6 2 2 6 2 2 6
40031 - 70 70 70 58 58 58 22 22 22 6 6 6
40032 - 0 0 0 0 0 0 0 0 0 0 0 0
40033 - 0 0 0 0 0 0 0 0 0 0 0 0
40034 - 0 0 0 0 0 0 0 0 0 0 0 0
40035 - 0 0 0 0 0 0 0 0 0 0 0 0
40036 - 0 0 0 0 0 0 0 0 0 0 0 0
40037 - 0 0 0 0 0 0 0 0 0 0 0 0
40038 - 0 0 0 0 0 0 0 0 0 0 0 0
40039 - 0 0 0 0 0 0 0 0 0 0 0 0
40040 - 0 0 0 0 0 0 0 0 0 0 0 0
40041 - 0 0 0 0 0 0 0 0 0 0 0 0
40042 - 0 0 0 0 0 0 0 0 0 0 0 0
40043 - 0 0 0 0 0 0 0 0 0 0 0 0
40044 - 0 0 0 0 0 0 0 0 0 14 14 14
40045 - 46 46 46 82 82 82 2 2 6 106 106 106
40046 -170 170 170 26 26 26 86 86 86 226 226 226
40047 -123 123 123 10 10 10 14 14 14 46 46 46
40048 -231 231 231 190 190 190 6 6 6 70 70 70
40049 - 90 90 90 238 238 238 158 158 158 2 2 6
40050 - 2 2 6 2 2 6 2 2 6 2 2 6
40051 - 70 70 70 58 58 58 22 22 22 6 6 6
40052 - 0 0 0 0 0 0 0 0 0 0 0 0
40053 - 0 0 0 0 0 0 0 0 0 0 0 0
40054 - 0 0 0 0 0 0 0 0 0 0 0 0
40055 - 0 0 0 0 0 0 0 0 0 0 0 0
40056 - 0 0 0 0 0 0 0 0 0 0 0 0
40057 - 0 0 0 0 0 0 0 0 0 0 0 0
40058 - 0 0 0 0 0 0 0 0 1 0 0 0
40059 - 0 0 1 0 0 1 0 0 1 0 0 0
40060 - 0 0 0 0 0 0 0 0 0 0 0 0
40061 - 0 0 0 0 0 0 0 0 0 0 0 0
40062 - 0 0 0 0 0 0 0 0 0 0 0 0
40063 - 0 0 0 0 0 0 0 0 0 0 0 0
40064 - 0 0 0 0 0 0 0 0 0 14 14 14
40065 - 42 42 42 86 86 86 6 6 6 116 116 116
40066 -106 106 106 6 6 6 70 70 70 149 149 149
40067 -128 128 128 18 18 18 38 38 38 54 54 54
40068 -221 221 221 106 106 106 2 2 6 14 14 14
40069 - 46 46 46 190 190 190 198 198 198 2 2 6
40070 - 2 2 6 2 2 6 2 2 6 2 2 6
40071 - 74 74 74 62 62 62 22 22 22 6 6 6
40072 - 0 0 0 0 0 0 0 0 0 0 0 0
40073 - 0 0 0 0 0 0 0 0 0 0 0 0
40074 - 0 0 0 0 0 0 0 0 0 0 0 0
40075 - 0 0 0 0 0 0 0 0 0 0 0 0
40076 - 0 0 0 0 0 0 0 0 0 0 0 0
40077 - 0 0 0 0 0 0 0 0 0 0 0 0
40078 - 0 0 0 0 0 0 0 0 1 0 0 0
40079 - 0 0 1 0 0 0 0 0 1 0 0 0
40080 - 0 0 0 0 0 0 0 0 0 0 0 0
40081 - 0 0 0 0 0 0 0 0 0 0 0 0
40082 - 0 0 0 0 0 0 0 0 0 0 0 0
40083 - 0 0 0 0 0 0 0 0 0 0 0 0
40084 - 0 0 0 0 0 0 0 0 0 14 14 14
40085 - 42 42 42 94 94 94 14 14 14 101 101 101
40086 -128 128 128 2 2 6 18 18 18 116 116 116
40087 -118 98 46 121 92 8 121 92 8 98 78 10
40088 -162 162 162 106 106 106 2 2 6 2 2 6
40089 - 2 2 6 195 195 195 195 195 195 6 6 6
40090 - 2 2 6 2 2 6 2 2 6 2 2 6
40091 - 74 74 74 62 62 62 22 22 22 6 6 6
40092 - 0 0 0 0 0 0 0 0 0 0 0 0
40093 - 0 0 0 0 0 0 0 0 0 0 0 0
40094 - 0 0 0 0 0 0 0 0 0 0 0 0
40095 - 0 0 0 0 0 0 0 0 0 0 0 0
40096 - 0 0 0 0 0 0 0 0 0 0 0 0
40097 - 0 0 0 0 0 0 0 0 0 0 0 0
40098 - 0 0 0 0 0 0 0 0 1 0 0 1
40099 - 0 0 1 0 0 0 0 0 1 0 0 0
40100 - 0 0 0 0 0 0 0 0 0 0 0 0
40101 - 0 0 0 0 0 0 0 0 0 0 0 0
40102 - 0 0 0 0 0 0 0 0 0 0 0 0
40103 - 0 0 0 0 0 0 0 0 0 0 0 0
40104 - 0 0 0 0 0 0 0 0 0 10 10 10
40105 - 38 38 38 90 90 90 14 14 14 58 58 58
40106 -210 210 210 26 26 26 54 38 6 154 114 10
40107 -226 170 11 236 186 11 225 175 15 184 144 12
40108 -215 174 15 175 146 61 37 26 9 2 2 6
40109 - 70 70 70 246 246 246 138 138 138 2 2 6
40110 - 2 2 6 2 2 6 2 2 6 2 2 6
40111 - 70 70 70 66 66 66 26 26 26 6 6 6
40112 - 0 0 0 0 0 0 0 0 0 0 0 0
40113 - 0 0 0 0 0 0 0 0 0 0 0 0
40114 - 0 0 0 0 0 0 0 0 0 0 0 0
40115 - 0 0 0 0 0 0 0 0 0 0 0 0
40116 - 0 0 0 0 0 0 0 0 0 0 0 0
40117 - 0 0 0 0 0 0 0 0 0 0 0 0
40118 - 0 0 0 0 0 0 0 0 0 0 0 0
40119 - 0 0 0 0 0 0 0 0 0 0 0 0
40120 - 0 0 0 0 0 0 0 0 0 0 0 0
40121 - 0 0 0 0 0 0 0 0 0 0 0 0
40122 - 0 0 0 0 0 0 0 0 0 0 0 0
40123 - 0 0 0 0 0 0 0 0 0 0 0 0
40124 - 0 0 0 0 0 0 0 0 0 10 10 10
40125 - 38 38 38 86 86 86 14 14 14 10 10 10
40126 -195 195 195 188 164 115 192 133 9 225 175 15
40127 -239 182 13 234 190 10 232 195 16 232 200 30
40128 -245 207 45 241 208 19 232 195 16 184 144 12
40129 -218 194 134 211 206 186 42 42 42 2 2 6
40130 - 2 2 6 2 2 6 2 2 6 2 2 6
40131 - 50 50 50 74 74 74 30 30 30 6 6 6
40132 - 0 0 0 0 0 0 0 0 0 0 0 0
40133 - 0 0 0 0 0 0 0 0 0 0 0 0
40134 - 0 0 0 0 0 0 0 0 0 0 0 0
40135 - 0 0 0 0 0 0 0 0 0 0 0 0
40136 - 0 0 0 0 0 0 0 0 0 0 0 0
40137 - 0 0 0 0 0 0 0 0 0 0 0 0
40138 - 0 0 0 0 0 0 0 0 0 0 0 0
40139 - 0 0 0 0 0 0 0 0 0 0 0 0
40140 - 0 0 0 0 0 0 0 0 0 0 0 0
40141 - 0 0 0 0 0 0 0 0 0 0 0 0
40142 - 0 0 0 0 0 0 0 0 0 0 0 0
40143 - 0 0 0 0 0 0 0 0 0 0 0 0
40144 - 0 0 0 0 0 0 0 0 0 10 10 10
40145 - 34 34 34 86 86 86 14 14 14 2 2 6
40146 -121 87 25 192 133 9 219 162 10 239 182 13
40147 -236 186 11 232 195 16 241 208 19 244 214 54
40148 -246 218 60 246 218 38 246 215 20 241 208 19
40149 -241 208 19 226 184 13 121 87 25 2 2 6
40150 - 2 2 6 2 2 6 2 2 6 2 2 6
40151 - 50 50 50 82 82 82 34 34 34 10 10 10
40152 - 0 0 0 0 0 0 0 0 0 0 0 0
40153 - 0 0 0 0 0 0 0 0 0 0 0 0
40154 - 0 0 0 0 0 0 0 0 0 0 0 0
40155 - 0 0 0 0 0 0 0 0 0 0 0 0
40156 - 0 0 0 0 0 0 0 0 0 0 0 0
40157 - 0 0 0 0 0 0 0 0 0 0 0 0
40158 - 0 0 0 0 0 0 0 0 0 0 0 0
40159 - 0 0 0 0 0 0 0 0 0 0 0 0
40160 - 0 0 0 0 0 0 0 0 0 0 0 0
40161 - 0 0 0 0 0 0 0 0 0 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 10 10 10
40165 - 34 34 34 82 82 82 30 30 30 61 42 6
40166 -180 123 7 206 145 10 230 174 11 239 182 13
40167 -234 190 10 238 202 15 241 208 19 246 218 74
40168 -246 218 38 246 215 20 246 215 20 246 215 20
40169 -226 184 13 215 174 15 184 144 12 6 6 6
40170 - 2 2 6 2 2 6 2 2 6 2 2 6
40171 - 26 26 26 94 94 94 42 42 42 14 14 14
40172 - 0 0 0 0 0 0 0 0 0 0 0 0
40173 - 0 0 0 0 0 0 0 0 0 0 0 0
40174 - 0 0 0 0 0 0 0 0 0 0 0 0
40175 - 0 0 0 0 0 0 0 0 0 0 0 0
40176 - 0 0 0 0 0 0 0 0 0 0 0 0
40177 - 0 0 0 0 0 0 0 0 0 0 0 0
40178 - 0 0 0 0 0 0 0 0 0 0 0 0
40179 - 0 0 0 0 0 0 0 0 0 0 0 0
40180 - 0 0 0 0 0 0 0 0 0 0 0 0
40181 - 0 0 0 0 0 0 0 0 0 0 0 0
40182 - 0 0 0 0 0 0 0 0 0 0 0 0
40183 - 0 0 0 0 0 0 0 0 0 0 0 0
40184 - 0 0 0 0 0 0 0 0 0 10 10 10
40185 - 30 30 30 78 78 78 50 50 50 104 69 6
40186 -192 133 9 216 158 10 236 178 12 236 186 11
40187 -232 195 16 241 208 19 244 214 54 245 215 43
40188 -246 215 20 246 215 20 241 208 19 198 155 10
40189 -200 144 11 216 158 10 156 118 10 2 2 6
40190 - 2 2 6 2 2 6 2 2 6 2 2 6
40191 - 6 6 6 90 90 90 54 54 54 18 18 18
40192 - 6 6 6 0 0 0 0 0 0 0 0 0
40193 - 0 0 0 0 0 0 0 0 0 0 0 0
40194 - 0 0 0 0 0 0 0 0 0 0 0 0
40195 - 0 0 0 0 0 0 0 0 0 0 0 0
40196 - 0 0 0 0 0 0 0 0 0 0 0 0
40197 - 0 0 0 0 0 0 0 0 0 0 0 0
40198 - 0 0 0 0 0 0 0 0 0 0 0 0
40199 - 0 0 0 0 0 0 0 0 0 0 0 0
40200 - 0 0 0 0 0 0 0 0 0 0 0 0
40201 - 0 0 0 0 0 0 0 0 0 0 0 0
40202 - 0 0 0 0 0 0 0 0 0 0 0 0
40203 - 0 0 0 0 0 0 0 0 0 0 0 0
40204 - 0 0 0 0 0 0 0 0 0 10 10 10
40205 - 30 30 30 78 78 78 46 46 46 22 22 22
40206 -137 92 6 210 162 10 239 182 13 238 190 10
40207 -238 202 15 241 208 19 246 215 20 246 215 20
40208 -241 208 19 203 166 17 185 133 11 210 150 10
40209 -216 158 10 210 150 10 102 78 10 2 2 6
40210 - 6 6 6 54 54 54 14 14 14 2 2 6
40211 - 2 2 6 62 62 62 74 74 74 30 30 30
40212 - 10 10 10 0 0 0 0 0 0 0 0 0
40213 - 0 0 0 0 0 0 0 0 0 0 0 0
40214 - 0 0 0 0 0 0 0 0 0 0 0 0
40215 - 0 0 0 0 0 0 0 0 0 0 0 0
40216 - 0 0 0 0 0 0 0 0 0 0 0 0
40217 - 0 0 0 0 0 0 0 0 0 0 0 0
40218 - 0 0 0 0 0 0 0 0 0 0 0 0
40219 - 0 0 0 0 0 0 0 0 0 0 0 0
40220 - 0 0 0 0 0 0 0 0 0 0 0 0
40221 - 0 0 0 0 0 0 0 0 0 0 0 0
40222 - 0 0 0 0 0 0 0 0 0 0 0 0
40223 - 0 0 0 0 0 0 0 0 0 0 0 0
40224 - 0 0 0 0 0 0 0 0 0 10 10 10
40225 - 34 34 34 78 78 78 50 50 50 6 6 6
40226 - 94 70 30 139 102 15 190 146 13 226 184 13
40227 -232 200 30 232 195 16 215 174 15 190 146 13
40228 -168 122 10 192 133 9 210 150 10 213 154 11
40229 -202 150 34 182 157 106 101 98 89 2 2 6
40230 - 2 2 6 78 78 78 116 116 116 58 58 58
40231 - 2 2 6 22 22 22 90 90 90 46 46 46
40232 - 18 18 18 6 6 6 0 0 0 0 0 0
40233 - 0 0 0 0 0 0 0 0 0 0 0 0
40234 - 0 0 0 0 0 0 0 0 0 0 0 0
40235 - 0 0 0 0 0 0 0 0 0 0 0 0
40236 - 0 0 0 0 0 0 0 0 0 0 0 0
40237 - 0 0 0 0 0 0 0 0 0 0 0 0
40238 - 0 0 0 0 0 0 0 0 0 0 0 0
40239 - 0 0 0 0 0 0 0 0 0 0 0 0
40240 - 0 0 0 0 0 0 0 0 0 0 0 0
40241 - 0 0 0 0 0 0 0 0 0 0 0 0
40242 - 0 0 0 0 0 0 0 0 0 0 0 0
40243 - 0 0 0 0 0 0 0 0 0 0 0 0
40244 - 0 0 0 0 0 0 0 0 0 10 10 10
40245 - 38 38 38 86 86 86 50 50 50 6 6 6
40246 -128 128 128 174 154 114 156 107 11 168 122 10
40247 -198 155 10 184 144 12 197 138 11 200 144 11
40248 -206 145 10 206 145 10 197 138 11 188 164 115
40249 -195 195 195 198 198 198 174 174 174 14 14 14
40250 - 2 2 6 22 22 22 116 116 116 116 116 116
40251 - 22 22 22 2 2 6 74 74 74 70 70 70
40252 - 30 30 30 10 10 10 0 0 0 0 0 0
40253 - 0 0 0 0 0 0 0 0 0 0 0 0
40254 - 0 0 0 0 0 0 0 0 0 0 0 0
40255 - 0 0 0 0 0 0 0 0 0 0 0 0
40256 - 0 0 0 0 0 0 0 0 0 0 0 0
40257 - 0 0 0 0 0 0 0 0 0 0 0 0
40258 - 0 0 0 0 0 0 0 0 0 0 0 0
40259 - 0 0 0 0 0 0 0 0 0 0 0 0
40260 - 0 0 0 0 0 0 0 0 0 0 0 0
40261 - 0 0 0 0 0 0 0 0 0 0 0 0
40262 - 0 0 0 0 0 0 0 0 0 0 0 0
40263 - 0 0 0 0 0 0 0 0 0 0 0 0
40264 - 0 0 0 0 0 0 6 6 6 18 18 18
40265 - 50 50 50 101 101 101 26 26 26 10 10 10
40266 -138 138 138 190 190 190 174 154 114 156 107 11
40267 -197 138 11 200 144 11 197 138 11 192 133 9
40268 -180 123 7 190 142 34 190 178 144 187 187 187
40269 -202 202 202 221 221 221 214 214 214 66 66 66
40270 - 2 2 6 2 2 6 50 50 50 62 62 62
40271 - 6 6 6 2 2 6 10 10 10 90 90 90
40272 - 50 50 50 18 18 18 6 6 6 0 0 0
40273 - 0 0 0 0 0 0 0 0 0 0 0 0
40274 - 0 0 0 0 0 0 0 0 0 0 0 0
40275 - 0 0 0 0 0 0 0 0 0 0 0 0
40276 - 0 0 0 0 0 0 0 0 0 0 0 0
40277 - 0 0 0 0 0 0 0 0 0 0 0 0
40278 - 0 0 0 0 0 0 0 0 0 0 0 0
40279 - 0 0 0 0 0 0 0 0 0 0 0 0
40280 - 0 0 0 0 0 0 0 0 0 0 0 0
40281 - 0 0 0 0 0 0 0 0 0 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 10 10 10 34 34 34
40285 - 74 74 74 74 74 74 2 2 6 6 6 6
40286 -144 144 144 198 198 198 190 190 190 178 166 146
40287 -154 121 60 156 107 11 156 107 11 168 124 44
40288 -174 154 114 187 187 187 190 190 190 210 210 210
40289 -246 246 246 253 253 253 253 253 253 182 182 182
40290 - 6 6 6 2 2 6 2 2 6 2 2 6
40291 - 2 2 6 2 2 6 2 2 6 62 62 62
40292 - 74 74 74 34 34 34 14 14 14 0 0 0
40293 - 0 0 0 0 0 0 0 0 0 0 0 0
40294 - 0 0 0 0 0 0 0 0 0 0 0 0
40295 - 0 0 0 0 0 0 0 0 0 0 0 0
40296 - 0 0 0 0 0 0 0 0 0 0 0 0
40297 - 0 0 0 0 0 0 0 0 0 0 0 0
40298 - 0 0 0 0 0 0 0 0 0 0 0 0
40299 - 0 0 0 0 0 0 0 0 0 0 0 0
40300 - 0 0 0 0 0 0 0 0 0 0 0 0
40301 - 0 0 0 0 0 0 0 0 0 0 0 0
40302 - 0 0 0 0 0 0 0 0 0 0 0 0
40303 - 0 0 0 0 0 0 0 0 0 0 0 0
40304 - 0 0 0 10 10 10 22 22 22 54 54 54
40305 - 94 94 94 18 18 18 2 2 6 46 46 46
40306 -234 234 234 221 221 221 190 190 190 190 190 190
40307 -190 190 190 187 187 187 187 187 187 190 190 190
40308 -190 190 190 195 195 195 214 214 214 242 242 242
40309 -253 253 253 253 253 253 253 253 253 253 253 253
40310 - 82 82 82 2 2 6 2 2 6 2 2 6
40311 - 2 2 6 2 2 6 2 2 6 14 14 14
40312 - 86 86 86 54 54 54 22 22 22 6 6 6
40313 - 0 0 0 0 0 0 0 0 0 0 0 0
40314 - 0 0 0 0 0 0 0 0 0 0 0 0
40315 - 0 0 0 0 0 0 0 0 0 0 0 0
40316 - 0 0 0 0 0 0 0 0 0 0 0 0
40317 - 0 0 0 0 0 0 0 0 0 0 0 0
40318 - 0 0 0 0 0 0 0 0 0 0 0 0
40319 - 0 0 0 0 0 0 0 0 0 0 0 0
40320 - 0 0 0 0 0 0 0 0 0 0 0 0
40321 - 0 0 0 0 0 0 0 0 0 0 0 0
40322 - 0 0 0 0 0 0 0 0 0 0 0 0
40323 - 0 0 0 0 0 0 0 0 0 0 0 0
40324 - 6 6 6 18 18 18 46 46 46 90 90 90
40325 - 46 46 46 18 18 18 6 6 6 182 182 182
40326 -253 253 253 246 246 246 206 206 206 190 190 190
40327 -190 190 190 190 190 190 190 190 190 190 190 190
40328 -206 206 206 231 231 231 250 250 250 253 253 253
40329 -253 253 253 253 253 253 253 253 253 253 253 253
40330 -202 202 202 14 14 14 2 2 6 2 2 6
40331 - 2 2 6 2 2 6 2 2 6 2 2 6
40332 - 42 42 42 86 86 86 42 42 42 18 18 18
40333 - 6 6 6 0 0 0 0 0 0 0 0 0
40334 - 0 0 0 0 0 0 0 0 0 0 0 0
40335 - 0 0 0 0 0 0 0 0 0 0 0 0
40336 - 0 0 0 0 0 0 0 0 0 0 0 0
40337 - 0 0 0 0 0 0 0 0 0 0 0 0
40338 - 0 0 0 0 0 0 0 0 0 0 0 0
40339 - 0 0 0 0 0 0 0 0 0 0 0 0
40340 - 0 0 0 0 0 0 0 0 0 0 0 0
40341 - 0 0 0 0 0 0 0 0 0 0 0 0
40342 - 0 0 0 0 0 0 0 0 0 0 0 0
40343 - 0 0 0 0 0 0 0 0 0 6 6 6
40344 - 14 14 14 38 38 38 74 74 74 66 66 66
40345 - 2 2 6 6 6 6 90 90 90 250 250 250
40346 -253 253 253 253 253 253 238 238 238 198 198 198
40347 -190 190 190 190 190 190 195 195 195 221 221 221
40348 -246 246 246 253 253 253 253 253 253 253 253 253
40349 -253 253 253 253 253 253 253 253 253 253 253 253
40350 -253 253 253 82 82 82 2 2 6 2 2 6
40351 - 2 2 6 2 2 6 2 2 6 2 2 6
40352 - 2 2 6 78 78 78 70 70 70 34 34 34
40353 - 14 14 14 6 6 6 0 0 0 0 0 0
40354 - 0 0 0 0 0 0 0 0 0 0 0 0
40355 - 0 0 0 0 0 0 0 0 0 0 0 0
40356 - 0 0 0 0 0 0 0 0 0 0 0 0
40357 - 0 0 0 0 0 0 0 0 0 0 0 0
40358 - 0 0 0 0 0 0 0 0 0 0 0 0
40359 - 0 0 0 0 0 0 0 0 0 0 0 0
40360 - 0 0 0 0 0 0 0 0 0 0 0 0
40361 - 0 0 0 0 0 0 0 0 0 0 0 0
40362 - 0 0 0 0 0 0 0 0 0 0 0 0
40363 - 0 0 0 0 0 0 0 0 0 14 14 14
40364 - 34 34 34 66 66 66 78 78 78 6 6 6
40365 - 2 2 6 18 18 18 218 218 218 253 253 253
40366 -253 253 253 253 253 253 253 253 253 246 246 246
40367 -226 226 226 231 231 231 246 246 246 253 253 253
40368 -253 253 253 253 253 253 253 253 253 253 253 253
40369 -253 253 253 253 253 253 253 253 253 253 253 253
40370 -253 253 253 178 178 178 2 2 6 2 2 6
40371 - 2 2 6 2 2 6 2 2 6 2 2 6
40372 - 2 2 6 18 18 18 90 90 90 62 62 62
40373 - 30 30 30 10 10 10 0 0 0 0 0 0
40374 - 0 0 0 0 0 0 0 0 0 0 0 0
40375 - 0 0 0 0 0 0 0 0 0 0 0 0
40376 - 0 0 0 0 0 0 0 0 0 0 0 0
40377 - 0 0 0 0 0 0 0 0 0 0 0 0
40378 - 0 0 0 0 0 0 0 0 0 0 0 0
40379 - 0 0 0 0 0 0 0 0 0 0 0 0
40380 - 0 0 0 0 0 0 0 0 0 0 0 0
40381 - 0 0 0 0 0 0 0 0 0 0 0 0
40382 - 0 0 0 0 0 0 0 0 0 0 0 0
40383 - 0 0 0 0 0 0 10 10 10 26 26 26
40384 - 58 58 58 90 90 90 18 18 18 2 2 6
40385 - 2 2 6 110 110 110 253 253 253 253 253 253
40386 -253 253 253 253 253 253 253 253 253 253 253 253
40387 -250 250 250 253 253 253 253 253 253 253 253 253
40388 -253 253 253 253 253 253 253 253 253 253 253 253
40389 -253 253 253 253 253 253 253 253 253 253 253 253
40390 -253 253 253 231 231 231 18 18 18 2 2 6
40391 - 2 2 6 2 2 6 2 2 6 2 2 6
40392 - 2 2 6 2 2 6 18 18 18 94 94 94
40393 - 54 54 54 26 26 26 10 10 10 0 0 0
40394 - 0 0 0 0 0 0 0 0 0 0 0 0
40395 - 0 0 0 0 0 0 0 0 0 0 0 0
40396 - 0 0 0 0 0 0 0 0 0 0 0 0
40397 - 0 0 0 0 0 0 0 0 0 0 0 0
40398 - 0 0 0 0 0 0 0 0 0 0 0 0
40399 - 0 0 0 0 0 0 0 0 0 0 0 0
40400 - 0 0 0 0 0 0 0 0 0 0 0 0
40401 - 0 0 0 0 0 0 0 0 0 0 0 0
40402 - 0 0 0 0 0 0 0 0 0 0 0 0
40403 - 0 0 0 6 6 6 22 22 22 50 50 50
40404 - 90 90 90 26 26 26 2 2 6 2 2 6
40405 - 14 14 14 195 195 195 250 250 250 253 253 253
40406 -253 253 253 253 253 253 253 253 253 253 253 253
40407 -253 253 253 253 253 253 253 253 253 253 253 253
40408 -253 253 253 253 253 253 253 253 253 253 253 253
40409 -253 253 253 253 253 253 253 253 253 253 253 253
40410 -250 250 250 242 242 242 54 54 54 2 2 6
40411 - 2 2 6 2 2 6 2 2 6 2 2 6
40412 - 2 2 6 2 2 6 2 2 6 38 38 38
40413 - 86 86 86 50 50 50 22 22 22 6 6 6
40414 - 0 0 0 0 0 0 0 0 0 0 0 0
40415 - 0 0 0 0 0 0 0 0 0 0 0 0
40416 - 0 0 0 0 0 0 0 0 0 0 0 0
40417 - 0 0 0 0 0 0 0 0 0 0 0 0
40418 - 0 0 0 0 0 0 0 0 0 0 0 0
40419 - 0 0 0 0 0 0 0 0 0 0 0 0
40420 - 0 0 0 0 0 0 0 0 0 0 0 0
40421 - 0 0 0 0 0 0 0 0 0 0 0 0
40422 - 0 0 0 0 0 0 0 0 0 0 0 0
40423 - 6 6 6 14 14 14 38 38 38 82 82 82
40424 - 34 34 34 2 2 6 2 2 6 2 2 6
40425 - 42 42 42 195 195 195 246 246 246 253 253 253
40426 -253 253 253 253 253 253 253 253 253 250 250 250
40427 -242 242 242 242 242 242 250 250 250 253 253 253
40428 -253 253 253 253 253 253 253 253 253 253 253 253
40429 -253 253 253 250 250 250 246 246 246 238 238 238
40430 -226 226 226 231 231 231 101 101 101 6 6 6
40431 - 2 2 6 2 2 6 2 2 6 2 2 6
40432 - 2 2 6 2 2 6 2 2 6 2 2 6
40433 - 38 38 38 82 82 82 42 42 42 14 14 14
40434 - 6 6 6 0 0 0 0 0 0 0 0 0
40435 - 0 0 0 0 0 0 0 0 0 0 0 0
40436 - 0 0 0 0 0 0 0 0 0 0 0 0
40437 - 0 0 0 0 0 0 0 0 0 0 0 0
40438 - 0 0 0 0 0 0 0 0 0 0 0 0
40439 - 0 0 0 0 0 0 0 0 0 0 0 0
40440 - 0 0 0 0 0 0 0 0 0 0 0 0
40441 - 0 0 0 0 0 0 0 0 0 0 0 0
40442 - 0 0 0 0 0 0 0 0 0 0 0 0
40443 - 10 10 10 26 26 26 62 62 62 66 66 66
40444 - 2 2 6 2 2 6 2 2 6 6 6 6
40445 - 70 70 70 170 170 170 206 206 206 234 234 234
40446 -246 246 246 250 250 250 250 250 250 238 238 238
40447 -226 226 226 231 231 231 238 238 238 250 250 250
40448 -250 250 250 250 250 250 246 246 246 231 231 231
40449 -214 214 214 206 206 206 202 202 202 202 202 202
40450 -198 198 198 202 202 202 182 182 182 18 18 18
40451 - 2 2 6 2 2 6 2 2 6 2 2 6
40452 - 2 2 6 2 2 6 2 2 6 2 2 6
40453 - 2 2 6 62 62 62 66 66 66 30 30 30
40454 - 10 10 10 0 0 0 0 0 0 0 0 0
40455 - 0 0 0 0 0 0 0 0 0 0 0 0
40456 - 0 0 0 0 0 0 0 0 0 0 0 0
40457 - 0 0 0 0 0 0 0 0 0 0 0 0
40458 - 0 0 0 0 0 0 0 0 0 0 0 0
40459 - 0 0 0 0 0 0 0 0 0 0 0 0
40460 - 0 0 0 0 0 0 0 0 0 0 0 0
40461 - 0 0 0 0 0 0 0 0 0 0 0 0
40462 - 0 0 0 0 0 0 0 0 0 0 0 0
40463 - 14 14 14 42 42 42 82 82 82 18 18 18
40464 - 2 2 6 2 2 6 2 2 6 10 10 10
40465 - 94 94 94 182 182 182 218 218 218 242 242 242
40466 -250 250 250 253 253 253 253 253 253 250 250 250
40467 -234 234 234 253 253 253 253 253 253 253 253 253
40468 -253 253 253 253 253 253 253 253 253 246 246 246
40469 -238 238 238 226 226 226 210 210 210 202 202 202
40470 -195 195 195 195 195 195 210 210 210 158 158 158
40471 - 6 6 6 14 14 14 50 50 50 14 14 14
40472 - 2 2 6 2 2 6 2 2 6 2 2 6
40473 - 2 2 6 6 6 6 86 86 86 46 46 46
40474 - 18 18 18 6 6 6 0 0 0 0 0 0
40475 - 0 0 0 0 0 0 0 0 0 0 0 0
40476 - 0 0 0 0 0 0 0 0 0 0 0 0
40477 - 0 0 0 0 0 0 0 0 0 0 0 0
40478 - 0 0 0 0 0 0 0 0 0 0 0 0
40479 - 0 0 0 0 0 0 0 0 0 0 0 0
40480 - 0 0 0 0 0 0 0 0 0 0 0 0
40481 - 0 0 0 0 0 0 0 0 0 0 0 0
40482 - 0 0 0 0 0 0 0 0 0 6 6 6
40483 - 22 22 22 54 54 54 70 70 70 2 2 6
40484 - 2 2 6 10 10 10 2 2 6 22 22 22
40485 -166 166 166 231 231 231 250 250 250 253 253 253
40486 -253 253 253 253 253 253 253 253 253 250 250 250
40487 -242 242 242 253 253 253 253 253 253 253 253 253
40488 -253 253 253 253 253 253 253 253 253 253 253 253
40489 -253 253 253 253 253 253 253 253 253 246 246 246
40490 -231 231 231 206 206 206 198 198 198 226 226 226
40491 - 94 94 94 2 2 6 6 6 6 38 38 38
40492 - 30 30 30 2 2 6 2 2 6 2 2 6
40493 - 2 2 6 2 2 6 62 62 62 66 66 66
40494 - 26 26 26 10 10 10 0 0 0 0 0 0
40495 - 0 0 0 0 0 0 0 0 0 0 0 0
40496 - 0 0 0 0 0 0 0 0 0 0 0 0
40497 - 0 0 0 0 0 0 0 0 0 0 0 0
40498 - 0 0 0 0 0 0 0 0 0 0 0 0
40499 - 0 0 0 0 0 0 0 0 0 0 0 0
40500 - 0 0 0 0 0 0 0 0 0 0 0 0
40501 - 0 0 0 0 0 0 0 0 0 0 0 0
40502 - 0 0 0 0 0 0 0 0 0 10 10 10
40503 - 30 30 30 74 74 74 50 50 50 2 2 6
40504 - 26 26 26 26 26 26 2 2 6 106 106 106
40505 -238 238 238 253 253 253 253 253 253 253 253 253
40506 -253 253 253 253 253 253 253 253 253 253 253 253
40507 -253 253 253 253 253 253 253 253 253 253 253 253
40508 -253 253 253 253 253 253 253 253 253 253 253 253
40509 -253 253 253 253 253 253 253 253 253 253 253 253
40510 -253 253 253 246 246 246 218 218 218 202 202 202
40511 -210 210 210 14 14 14 2 2 6 2 2 6
40512 - 30 30 30 22 22 22 2 2 6 2 2 6
40513 - 2 2 6 2 2 6 18 18 18 86 86 86
40514 - 42 42 42 14 14 14 0 0 0 0 0 0
40515 - 0 0 0 0 0 0 0 0 0 0 0 0
40516 - 0 0 0 0 0 0 0 0 0 0 0 0
40517 - 0 0 0 0 0 0 0 0 0 0 0 0
40518 - 0 0 0 0 0 0 0 0 0 0 0 0
40519 - 0 0 0 0 0 0 0 0 0 0 0 0
40520 - 0 0 0 0 0 0 0 0 0 0 0 0
40521 - 0 0 0 0 0 0 0 0 0 0 0 0
40522 - 0 0 0 0 0 0 0 0 0 14 14 14
40523 - 42 42 42 90 90 90 22 22 22 2 2 6
40524 - 42 42 42 2 2 6 18 18 18 218 218 218
40525 -253 253 253 253 253 253 253 253 253 253 253 253
40526 -253 253 253 253 253 253 253 253 253 253 253 253
40527 -253 253 253 253 253 253 253 253 253 253 253 253
40528 -253 253 253 253 253 253 253 253 253 253 253 253
40529 -253 253 253 253 253 253 253 253 253 253 253 253
40530 -253 253 253 253 253 253 250 250 250 221 221 221
40531 -218 218 218 101 101 101 2 2 6 14 14 14
40532 - 18 18 18 38 38 38 10 10 10 2 2 6
40533 - 2 2 6 2 2 6 2 2 6 78 78 78
40534 - 58 58 58 22 22 22 6 6 6 0 0 0
40535 - 0 0 0 0 0 0 0 0 0 0 0 0
40536 - 0 0 0 0 0 0 0 0 0 0 0 0
40537 - 0 0 0 0 0 0 0 0 0 0 0 0
40538 - 0 0 0 0 0 0 0 0 0 0 0 0
40539 - 0 0 0 0 0 0 0 0 0 0 0 0
40540 - 0 0 0 0 0 0 0 0 0 0 0 0
40541 - 0 0 0 0 0 0 0 0 0 0 0 0
40542 - 0 0 0 0 0 0 6 6 6 18 18 18
40543 - 54 54 54 82 82 82 2 2 6 26 26 26
40544 - 22 22 22 2 2 6 123 123 123 253 253 253
40545 -253 253 253 253 253 253 253 253 253 253 253 253
40546 -253 253 253 253 253 253 253 253 253 253 253 253
40547 -253 253 253 253 253 253 253 253 253 253 253 253
40548 -253 253 253 253 253 253 253 253 253 253 253 253
40549 -253 253 253 253 253 253 253 253 253 253 253 253
40550 -253 253 253 253 253 253 253 253 253 250 250 250
40551 -238 238 238 198 198 198 6 6 6 38 38 38
40552 - 58 58 58 26 26 26 38 38 38 2 2 6
40553 - 2 2 6 2 2 6 2 2 6 46 46 46
40554 - 78 78 78 30 30 30 10 10 10 0 0 0
40555 - 0 0 0 0 0 0 0 0 0 0 0 0
40556 - 0 0 0 0 0 0 0 0 0 0 0 0
40557 - 0 0 0 0 0 0 0 0 0 0 0 0
40558 - 0 0 0 0 0 0 0 0 0 0 0 0
40559 - 0 0 0 0 0 0 0 0 0 0 0 0
40560 - 0 0 0 0 0 0 0 0 0 0 0 0
40561 - 0 0 0 0 0 0 0 0 0 0 0 0
40562 - 0 0 0 0 0 0 10 10 10 30 30 30
40563 - 74 74 74 58 58 58 2 2 6 42 42 42
40564 - 2 2 6 22 22 22 231 231 231 253 253 253
40565 -253 253 253 253 253 253 253 253 253 253 253 253
40566 -253 253 253 253 253 253 253 253 253 250 250 250
40567 -253 253 253 253 253 253 253 253 253 253 253 253
40568 -253 253 253 253 253 253 253 253 253 253 253 253
40569 -253 253 253 253 253 253 253 253 253 253 253 253
40570 -253 253 253 253 253 253 253 253 253 253 253 253
40571 -253 253 253 246 246 246 46 46 46 38 38 38
40572 - 42 42 42 14 14 14 38 38 38 14 14 14
40573 - 2 2 6 2 2 6 2 2 6 6 6 6
40574 - 86 86 86 46 46 46 14 14 14 0 0 0
40575 - 0 0 0 0 0 0 0 0 0 0 0 0
40576 - 0 0 0 0 0 0 0 0 0 0 0 0
40577 - 0 0 0 0 0 0 0 0 0 0 0 0
40578 - 0 0 0 0 0 0 0 0 0 0 0 0
40579 - 0 0 0 0 0 0 0 0 0 0 0 0
40580 - 0 0 0 0 0 0 0 0 0 0 0 0
40581 - 0 0 0 0 0 0 0 0 0 0 0 0
40582 - 0 0 0 6 6 6 14 14 14 42 42 42
40583 - 90 90 90 18 18 18 18 18 18 26 26 26
40584 - 2 2 6 116 116 116 253 253 253 253 253 253
40585 -253 253 253 253 253 253 253 253 253 253 253 253
40586 -253 253 253 253 253 253 250 250 250 238 238 238
40587 -253 253 253 253 253 253 253 253 253 253 253 253
40588 -253 253 253 253 253 253 253 253 253 253 253 253
40589 -253 253 253 253 253 253 253 253 253 253 253 253
40590 -253 253 253 253 253 253 253 253 253 253 253 253
40591 -253 253 253 253 253 253 94 94 94 6 6 6
40592 - 2 2 6 2 2 6 10 10 10 34 34 34
40593 - 2 2 6 2 2 6 2 2 6 2 2 6
40594 - 74 74 74 58 58 58 22 22 22 6 6 6
40595 - 0 0 0 0 0 0 0 0 0 0 0 0
40596 - 0 0 0 0 0 0 0 0 0 0 0 0
40597 - 0 0 0 0 0 0 0 0 0 0 0 0
40598 - 0 0 0 0 0 0 0 0 0 0 0 0
40599 - 0 0 0 0 0 0 0 0 0 0 0 0
40600 - 0 0 0 0 0 0 0 0 0 0 0 0
40601 - 0 0 0 0 0 0 0 0 0 0 0 0
40602 - 0 0 0 10 10 10 26 26 26 66 66 66
40603 - 82 82 82 2 2 6 38 38 38 6 6 6
40604 - 14 14 14 210 210 210 253 253 253 253 253 253
40605 -253 253 253 253 253 253 253 253 253 253 253 253
40606 -253 253 253 253 253 253 246 246 246 242 242 242
40607 -253 253 253 253 253 253 253 253 253 253 253 253
40608 -253 253 253 253 253 253 253 253 253 253 253 253
40609 -253 253 253 253 253 253 253 253 253 253 253 253
40610 -253 253 253 253 253 253 253 253 253 253 253 253
40611 -253 253 253 253 253 253 144 144 144 2 2 6
40612 - 2 2 6 2 2 6 2 2 6 46 46 46
40613 - 2 2 6 2 2 6 2 2 6 2 2 6
40614 - 42 42 42 74 74 74 30 30 30 10 10 10
40615 - 0 0 0 0 0 0 0 0 0 0 0 0
40616 - 0 0 0 0 0 0 0 0 0 0 0 0
40617 - 0 0 0 0 0 0 0 0 0 0 0 0
40618 - 0 0 0 0 0 0 0 0 0 0 0 0
40619 - 0 0 0 0 0 0 0 0 0 0 0 0
40620 - 0 0 0 0 0 0 0 0 0 0 0 0
40621 - 0 0 0 0 0 0 0 0 0 0 0 0
40622 - 6 6 6 14 14 14 42 42 42 90 90 90
40623 - 26 26 26 6 6 6 42 42 42 2 2 6
40624 - 74 74 74 250 250 250 253 253 253 253 253 253
40625 -253 253 253 253 253 253 253 253 253 253 253 253
40626 -253 253 253 253 253 253 242 242 242 242 242 242
40627 -253 253 253 253 253 253 253 253 253 253 253 253
40628 -253 253 253 253 253 253 253 253 253 253 253 253
40629 -253 253 253 253 253 253 253 253 253 253 253 253
40630 -253 253 253 253 253 253 253 253 253 253 253 253
40631 -253 253 253 253 253 253 182 182 182 2 2 6
40632 - 2 2 6 2 2 6 2 2 6 46 46 46
40633 - 2 2 6 2 2 6 2 2 6 2 2 6
40634 - 10 10 10 86 86 86 38 38 38 10 10 10
40635 - 0 0 0 0 0 0 0 0 0 0 0 0
40636 - 0 0 0 0 0 0 0 0 0 0 0 0
40637 - 0 0 0 0 0 0 0 0 0 0 0 0
40638 - 0 0 0 0 0 0 0 0 0 0 0 0
40639 - 0 0 0 0 0 0 0 0 0 0 0 0
40640 - 0 0 0 0 0 0 0 0 0 0 0 0
40641 - 0 0 0 0 0 0 0 0 0 0 0 0
40642 - 10 10 10 26 26 26 66 66 66 82 82 82
40643 - 2 2 6 22 22 22 18 18 18 2 2 6
40644 -149 149 149 253 253 253 253 253 253 253 253 253
40645 -253 253 253 253 253 253 253 253 253 253 253 253
40646 -253 253 253 253 253 253 234 234 234 242 242 242
40647 -253 253 253 253 253 253 253 253 253 253 253 253
40648 -253 253 253 253 253 253 253 253 253 253 253 253
40649 -253 253 253 253 253 253 253 253 253 253 253 253
40650 -253 253 253 253 253 253 253 253 253 253 253 253
40651 -253 253 253 253 253 253 206 206 206 2 2 6
40652 - 2 2 6 2 2 6 2 2 6 38 38 38
40653 - 2 2 6 2 2 6 2 2 6 2 2 6
40654 - 6 6 6 86 86 86 46 46 46 14 14 14
40655 - 0 0 0 0 0 0 0 0 0 0 0 0
40656 - 0 0 0 0 0 0 0 0 0 0 0 0
40657 - 0 0 0 0 0 0 0 0 0 0 0 0
40658 - 0 0 0 0 0 0 0 0 0 0 0 0
40659 - 0 0 0 0 0 0 0 0 0 0 0 0
40660 - 0 0 0 0 0 0 0 0 0 0 0 0
40661 - 0 0 0 0 0 0 0 0 0 6 6 6
40662 - 18 18 18 46 46 46 86 86 86 18 18 18
40663 - 2 2 6 34 34 34 10 10 10 6 6 6
40664 -210 210 210 253 253 253 253 253 253 253 253 253
40665 -253 253 253 253 253 253 253 253 253 253 253 253
40666 -253 253 253 253 253 253 234 234 234 242 242 242
40667 -253 253 253 253 253 253 253 253 253 253 253 253
40668 -253 253 253 253 253 253 253 253 253 253 253 253
40669 -253 253 253 253 253 253 253 253 253 253 253 253
40670 -253 253 253 253 253 253 253 253 253 253 253 253
40671 -253 253 253 253 253 253 221 221 221 6 6 6
40672 - 2 2 6 2 2 6 6 6 6 30 30 30
40673 - 2 2 6 2 2 6 2 2 6 2 2 6
40674 - 2 2 6 82 82 82 54 54 54 18 18 18
40675 - 6 6 6 0 0 0 0 0 0 0 0 0
40676 - 0 0 0 0 0 0 0 0 0 0 0 0
40677 - 0 0 0 0 0 0 0 0 0 0 0 0
40678 - 0 0 0 0 0 0 0 0 0 0 0 0
40679 - 0 0 0 0 0 0 0 0 0 0 0 0
40680 - 0 0 0 0 0 0 0 0 0 0 0 0
40681 - 0 0 0 0 0 0 0 0 0 10 10 10
40682 - 26 26 26 66 66 66 62 62 62 2 2 6
40683 - 2 2 6 38 38 38 10 10 10 26 26 26
40684 -238 238 238 253 253 253 253 253 253 253 253 253
40685 -253 253 253 253 253 253 253 253 253 253 253 253
40686 -253 253 253 253 253 253 231 231 231 238 238 238
40687 -253 253 253 253 253 253 253 253 253 253 253 253
40688 -253 253 253 253 253 253 253 253 253 253 253 253
40689 -253 253 253 253 253 253 253 253 253 253 253 253
40690 -253 253 253 253 253 253 253 253 253 253 253 253
40691 -253 253 253 253 253 253 231 231 231 6 6 6
40692 - 2 2 6 2 2 6 10 10 10 30 30 30
40693 - 2 2 6 2 2 6 2 2 6 2 2 6
40694 - 2 2 6 66 66 66 58 58 58 22 22 22
40695 - 6 6 6 0 0 0 0 0 0 0 0 0
40696 - 0 0 0 0 0 0 0 0 0 0 0 0
40697 - 0 0 0 0 0 0 0 0 0 0 0 0
40698 - 0 0 0 0 0 0 0 0 0 0 0 0
40699 - 0 0 0 0 0 0 0 0 0 0 0 0
40700 - 0 0 0 0 0 0 0 0 0 0 0 0
40701 - 0 0 0 0 0 0 0 0 0 10 10 10
40702 - 38 38 38 78 78 78 6 6 6 2 2 6
40703 - 2 2 6 46 46 46 14 14 14 42 42 42
40704 -246 246 246 253 253 253 253 253 253 253 253 253
40705 -253 253 253 253 253 253 253 253 253 253 253 253
40706 -253 253 253 253 253 253 231 231 231 242 242 242
40707 -253 253 253 253 253 253 253 253 253 253 253 253
40708 -253 253 253 253 253 253 253 253 253 253 253 253
40709 -253 253 253 253 253 253 253 253 253 253 253 253
40710 -253 253 253 253 253 253 253 253 253 253 253 253
40711 -253 253 253 253 253 253 234 234 234 10 10 10
40712 - 2 2 6 2 2 6 22 22 22 14 14 14
40713 - 2 2 6 2 2 6 2 2 6 2 2 6
40714 - 2 2 6 66 66 66 62 62 62 22 22 22
40715 - 6 6 6 0 0 0 0 0 0 0 0 0
40716 - 0 0 0 0 0 0 0 0 0 0 0 0
40717 - 0 0 0 0 0 0 0 0 0 0 0 0
40718 - 0 0 0 0 0 0 0 0 0 0 0 0
40719 - 0 0 0 0 0 0 0 0 0 0 0 0
40720 - 0 0 0 0 0 0 0 0 0 0 0 0
40721 - 0 0 0 0 0 0 6 6 6 18 18 18
40722 - 50 50 50 74 74 74 2 2 6 2 2 6
40723 - 14 14 14 70 70 70 34 34 34 62 62 62
40724 -250 250 250 253 253 253 253 253 253 253 253 253
40725 -253 253 253 253 253 253 253 253 253 253 253 253
40726 -253 253 253 253 253 253 231 231 231 246 246 246
40727 -253 253 253 253 253 253 253 253 253 253 253 253
40728 -253 253 253 253 253 253 253 253 253 253 253 253
40729 -253 253 253 253 253 253 253 253 253 253 253 253
40730 -253 253 253 253 253 253 253 253 253 253 253 253
40731 -253 253 253 253 253 253 234 234 234 14 14 14
40732 - 2 2 6 2 2 6 30 30 30 2 2 6
40733 - 2 2 6 2 2 6 2 2 6 2 2 6
40734 - 2 2 6 66 66 66 62 62 62 22 22 22
40735 - 6 6 6 0 0 0 0 0 0 0 0 0
40736 - 0 0 0 0 0 0 0 0 0 0 0 0
40737 - 0 0 0 0 0 0 0 0 0 0 0 0
40738 - 0 0 0 0 0 0 0 0 0 0 0 0
40739 - 0 0 0 0 0 0 0 0 0 0 0 0
40740 - 0 0 0 0 0 0 0 0 0 0 0 0
40741 - 0 0 0 0 0 0 6 6 6 18 18 18
40742 - 54 54 54 62 62 62 2 2 6 2 2 6
40743 - 2 2 6 30 30 30 46 46 46 70 70 70
40744 -250 250 250 253 253 253 253 253 253 253 253 253
40745 -253 253 253 253 253 253 253 253 253 253 253 253
40746 -253 253 253 253 253 253 231 231 231 246 246 246
40747 -253 253 253 253 253 253 253 253 253 253 253 253
40748 -253 253 253 253 253 253 253 253 253 253 253 253
40749 -253 253 253 253 253 253 253 253 253 253 253 253
40750 -253 253 253 253 253 253 253 253 253 253 253 253
40751 -253 253 253 253 253 253 226 226 226 10 10 10
40752 - 2 2 6 6 6 6 30 30 30 2 2 6
40753 - 2 2 6 2 2 6 2 2 6 2 2 6
40754 - 2 2 6 66 66 66 58 58 58 22 22 22
40755 - 6 6 6 0 0 0 0 0 0 0 0 0
40756 - 0 0 0 0 0 0 0 0 0 0 0 0
40757 - 0 0 0 0 0 0 0 0 0 0 0 0
40758 - 0 0 0 0 0 0 0 0 0 0 0 0
40759 - 0 0 0 0 0 0 0 0 0 0 0 0
40760 - 0 0 0 0 0 0 0 0 0 0 0 0
40761 - 0 0 0 0 0 0 6 6 6 22 22 22
40762 - 58 58 58 62 62 62 2 2 6 2 2 6
40763 - 2 2 6 2 2 6 30 30 30 78 78 78
40764 -250 250 250 253 253 253 253 253 253 253 253 253
40765 -253 253 253 253 253 253 253 253 253 253 253 253
40766 -253 253 253 253 253 253 231 231 231 246 246 246
40767 -253 253 253 253 253 253 253 253 253 253 253 253
40768 -253 253 253 253 253 253 253 253 253 253 253 253
40769 -253 253 253 253 253 253 253 253 253 253 253 253
40770 -253 253 253 253 253 253 253 253 253 253 253 253
40771 -253 253 253 253 253 253 206 206 206 2 2 6
40772 - 22 22 22 34 34 34 18 14 6 22 22 22
40773 - 26 26 26 18 18 18 6 6 6 2 2 6
40774 - 2 2 6 82 82 82 54 54 54 18 18 18
40775 - 6 6 6 0 0 0 0 0 0 0 0 0
40776 - 0 0 0 0 0 0 0 0 0 0 0 0
40777 - 0 0 0 0 0 0 0 0 0 0 0 0
40778 - 0 0 0 0 0 0 0 0 0 0 0 0
40779 - 0 0 0 0 0 0 0 0 0 0 0 0
40780 - 0 0 0 0 0 0 0 0 0 0 0 0
40781 - 0 0 0 0 0 0 6 6 6 26 26 26
40782 - 62 62 62 106 106 106 74 54 14 185 133 11
40783 -210 162 10 121 92 8 6 6 6 62 62 62
40784 -238 238 238 253 253 253 253 253 253 253 253 253
40785 -253 253 253 253 253 253 253 253 253 253 253 253
40786 -253 253 253 253 253 253 231 231 231 246 246 246
40787 -253 253 253 253 253 253 253 253 253 253 253 253
40788 -253 253 253 253 253 253 253 253 253 253 253 253
40789 -253 253 253 253 253 253 253 253 253 253 253 253
40790 -253 253 253 253 253 253 253 253 253 253 253 253
40791 -253 253 253 253 253 253 158 158 158 18 18 18
40792 - 14 14 14 2 2 6 2 2 6 2 2 6
40793 - 6 6 6 18 18 18 66 66 66 38 38 38
40794 - 6 6 6 94 94 94 50 50 50 18 18 18
40795 - 6 6 6 0 0 0 0 0 0 0 0 0
40796 - 0 0 0 0 0 0 0 0 0 0 0 0
40797 - 0 0 0 0 0 0 0 0 0 0 0 0
40798 - 0 0 0 0 0 0 0 0 0 0 0 0
40799 - 0 0 0 0 0 0 0 0 0 0 0 0
40800 - 0 0 0 0 0 0 0 0 0 6 6 6
40801 - 10 10 10 10 10 10 18 18 18 38 38 38
40802 - 78 78 78 142 134 106 216 158 10 242 186 14
40803 -246 190 14 246 190 14 156 118 10 10 10 10
40804 - 90 90 90 238 238 238 253 253 253 253 253 253
40805 -253 253 253 253 253 253 253 253 253 253 253 253
40806 -253 253 253 253 253 253 231 231 231 250 250 250
40807 -253 253 253 253 253 253 253 253 253 253 253 253
40808 -253 253 253 253 253 253 253 253 253 253 253 253
40809 -253 253 253 253 253 253 253 253 253 253 253 253
40810 -253 253 253 253 253 253 253 253 253 246 230 190
40811 -238 204 91 238 204 91 181 142 44 37 26 9
40812 - 2 2 6 2 2 6 2 2 6 2 2 6
40813 - 2 2 6 2 2 6 38 38 38 46 46 46
40814 - 26 26 26 106 106 106 54 54 54 18 18 18
40815 - 6 6 6 0 0 0 0 0 0 0 0 0
40816 - 0 0 0 0 0 0 0 0 0 0 0 0
40817 - 0 0 0 0 0 0 0 0 0 0 0 0
40818 - 0 0 0 0 0 0 0 0 0 0 0 0
40819 - 0 0 0 0 0 0 0 0 0 0 0 0
40820 - 0 0 0 6 6 6 14 14 14 22 22 22
40821 - 30 30 30 38 38 38 50 50 50 70 70 70
40822 -106 106 106 190 142 34 226 170 11 242 186 14
40823 -246 190 14 246 190 14 246 190 14 154 114 10
40824 - 6 6 6 74 74 74 226 226 226 253 253 253
40825 -253 253 253 253 253 253 253 253 253 253 253 253
40826 -253 253 253 253 253 253 231 231 231 250 250 250
40827 -253 253 253 253 253 253 253 253 253 253 253 253
40828 -253 253 253 253 253 253 253 253 253 253 253 253
40829 -253 253 253 253 253 253 253 253 253 253 253 253
40830 -253 253 253 253 253 253 253 253 253 228 184 62
40831 -241 196 14 241 208 19 232 195 16 38 30 10
40832 - 2 2 6 2 2 6 2 2 6 2 2 6
40833 - 2 2 6 6 6 6 30 30 30 26 26 26
40834 -203 166 17 154 142 90 66 66 66 26 26 26
40835 - 6 6 6 0 0 0 0 0 0 0 0 0
40836 - 0 0 0 0 0 0 0 0 0 0 0 0
40837 - 0 0 0 0 0 0 0 0 0 0 0 0
40838 - 0 0 0 0 0 0 0 0 0 0 0 0
40839 - 0 0 0 0 0 0 0 0 0 0 0 0
40840 - 6 6 6 18 18 18 38 38 38 58 58 58
40841 - 78 78 78 86 86 86 101 101 101 123 123 123
40842 -175 146 61 210 150 10 234 174 13 246 186 14
40843 -246 190 14 246 190 14 246 190 14 238 190 10
40844 -102 78 10 2 2 6 46 46 46 198 198 198
40845 -253 253 253 253 253 253 253 253 253 253 253 253
40846 -253 253 253 253 253 253 234 234 234 242 242 242
40847 -253 253 253 253 253 253 253 253 253 253 253 253
40848 -253 253 253 253 253 253 253 253 253 253 253 253
40849 -253 253 253 253 253 253 253 253 253 253 253 253
40850 -253 253 253 253 253 253 253 253 253 224 178 62
40851 -242 186 14 241 196 14 210 166 10 22 18 6
40852 - 2 2 6 2 2 6 2 2 6 2 2 6
40853 - 2 2 6 2 2 6 6 6 6 121 92 8
40854 -238 202 15 232 195 16 82 82 82 34 34 34
40855 - 10 10 10 0 0 0 0 0 0 0 0 0
40856 - 0 0 0 0 0 0 0 0 0 0 0 0
40857 - 0 0 0 0 0 0 0 0 0 0 0 0
40858 - 0 0 0 0 0 0 0 0 0 0 0 0
40859 - 0 0 0 0 0 0 0 0 0 0 0 0
40860 - 14 14 14 38 38 38 70 70 70 154 122 46
40861 -190 142 34 200 144 11 197 138 11 197 138 11
40862 -213 154 11 226 170 11 242 186 14 246 190 14
40863 -246 190 14 246 190 14 246 190 14 246 190 14
40864 -225 175 15 46 32 6 2 2 6 22 22 22
40865 -158 158 158 250 250 250 253 253 253 253 253 253
40866 -253 253 253 253 253 253 253 253 253 253 253 253
40867 -253 253 253 253 253 253 253 253 253 253 253 253
40868 -253 253 253 253 253 253 253 253 253 253 253 253
40869 -253 253 253 253 253 253 253 253 253 253 253 253
40870 -253 253 253 250 250 250 242 242 242 224 178 62
40871 -239 182 13 236 186 11 213 154 11 46 32 6
40872 - 2 2 6 2 2 6 2 2 6 2 2 6
40873 - 2 2 6 2 2 6 61 42 6 225 175 15
40874 -238 190 10 236 186 11 112 100 78 42 42 42
40875 - 14 14 14 0 0 0 0 0 0 0 0 0
40876 - 0 0 0 0 0 0 0 0 0 0 0 0
40877 - 0 0 0 0 0 0 0 0 0 0 0 0
40878 - 0 0 0 0 0 0 0 0 0 0 0 0
40879 - 0 0 0 0 0 0 0 0 0 6 6 6
40880 - 22 22 22 54 54 54 154 122 46 213 154 11
40881 -226 170 11 230 174 11 226 170 11 226 170 11
40882 -236 178 12 242 186 14 246 190 14 246 190 14
40883 -246 190 14 246 190 14 246 190 14 246 190 14
40884 -241 196 14 184 144 12 10 10 10 2 2 6
40885 - 6 6 6 116 116 116 242 242 242 253 253 253
40886 -253 253 253 253 253 253 253 253 253 253 253 253
40887 -253 253 253 253 253 253 253 253 253 253 253 253
40888 -253 253 253 253 253 253 253 253 253 253 253 253
40889 -253 253 253 253 253 253 253 253 253 253 253 253
40890 -253 253 253 231 231 231 198 198 198 214 170 54
40891 -236 178 12 236 178 12 210 150 10 137 92 6
40892 - 18 14 6 2 2 6 2 2 6 2 2 6
40893 - 6 6 6 70 47 6 200 144 11 236 178 12
40894 -239 182 13 239 182 13 124 112 88 58 58 58
40895 - 22 22 22 6 6 6 0 0 0 0 0 0
40896 - 0 0 0 0 0 0 0 0 0 0 0 0
40897 - 0 0 0 0 0 0 0 0 0 0 0 0
40898 - 0 0 0 0 0 0 0 0 0 0 0 0
40899 - 0 0 0 0 0 0 0 0 0 10 10 10
40900 - 30 30 30 70 70 70 180 133 36 226 170 11
40901 -239 182 13 242 186 14 242 186 14 246 186 14
40902 -246 190 14 246 190 14 246 190 14 246 190 14
40903 -246 190 14 246 190 14 246 190 14 246 190 14
40904 -246 190 14 232 195 16 98 70 6 2 2 6
40905 - 2 2 6 2 2 6 66 66 66 221 221 221
40906 -253 253 253 253 253 253 253 253 253 253 253 253
40907 -253 253 253 253 253 253 253 253 253 253 253 253
40908 -253 253 253 253 253 253 253 253 253 253 253 253
40909 -253 253 253 253 253 253 253 253 253 253 253 253
40910 -253 253 253 206 206 206 198 198 198 214 166 58
40911 -230 174 11 230 174 11 216 158 10 192 133 9
40912 -163 110 8 116 81 8 102 78 10 116 81 8
40913 -167 114 7 197 138 11 226 170 11 239 182 13
40914 -242 186 14 242 186 14 162 146 94 78 78 78
40915 - 34 34 34 14 14 14 6 6 6 0 0 0
40916 - 0 0 0 0 0 0 0 0 0 0 0 0
40917 - 0 0 0 0 0 0 0 0 0 0 0 0
40918 - 0 0 0 0 0 0 0 0 0 0 0 0
40919 - 0 0 0 0 0 0 0 0 0 6 6 6
40920 - 30 30 30 78 78 78 190 142 34 226 170 11
40921 -239 182 13 246 190 14 246 190 14 246 190 14
40922 -246 190 14 246 190 14 246 190 14 246 190 14
40923 -246 190 14 246 190 14 246 190 14 246 190 14
40924 -246 190 14 241 196 14 203 166 17 22 18 6
40925 - 2 2 6 2 2 6 2 2 6 38 38 38
40926 -218 218 218 253 253 253 253 253 253 253 253 253
40927 -253 253 253 253 253 253 253 253 253 253 253 253
40928 -253 253 253 253 253 253 253 253 253 253 253 253
40929 -253 253 253 253 253 253 253 253 253 253 253 253
40930 -250 250 250 206 206 206 198 198 198 202 162 69
40931 -226 170 11 236 178 12 224 166 10 210 150 10
40932 -200 144 11 197 138 11 192 133 9 197 138 11
40933 -210 150 10 226 170 11 242 186 14 246 190 14
40934 -246 190 14 246 186 14 225 175 15 124 112 88
40935 - 62 62 62 30 30 30 14 14 14 6 6 6
40936 - 0 0 0 0 0 0 0 0 0 0 0 0
40937 - 0 0 0 0 0 0 0 0 0 0 0 0
40938 - 0 0 0 0 0 0 0 0 0 0 0 0
40939 - 0 0 0 0 0 0 0 0 0 10 10 10
40940 - 30 30 30 78 78 78 174 135 50 224 166 10
40941 -239 182 13 246 190 14 246 190 14 246 190 14
40942 -246 190 14 246 190 14 246 190 14 246 190 14
40943 -246 190 14 246 190 14 246 190 14 246 190 14
40944 -246 190 14 246 190 14 241 196 14 139 102 15
40945 - 2 2 6 2 2 6 2 2 6 2 2 6
40946 - 78 78 78 250 250 250 253 253 253 253 253 253
40947 -253 253 253 253 253 253 253 253 253 253 253 253
40948 -253 253 253 253 253 253 253 253 253 253 253 253
40949 -253 253 253 253 253 253 253 253 253 253 253 253
40950 -250 250 250 214 214 214 198 198 198 190 150 46
40951 -219 162 10 236 178 12 234 174 13 224 166 10
40952 -216 158 10 213 154 11 213 154 11 216 158 10
40953 -226 170 11 239 182 13 246 190 14 246 190 14
40954 -246 190 14 246 190 14 242 186 14 206 162 42
40955 -101 101 101 58 58 58 30 30 30 14 14 14
40956 - 6 6 6 0 0 0 0 0 0 0 0 0
40957 - 0 0 0 0 0 0 0 0 0 0 0 0
40958 - 0 0 0 0 0 0 0 0 0 0 0 0
40959 - 0 0 0 0 0 0 0 0 0 10 10 10
40960 - 30 30 30 74 74 74 174 135 50 216 158 10
40961 -236 178 12 246 190 14 246 190 14 246 190 14
40962 -246 190 14 246 190 14 246 190 14 246 190 14
40963 -246 190 14 246 190 14 246 190 14 246 190 14
40964 -246 190 14 246 190 14 241 196 14 226 184 13
40965 - 61 42 6 2 2 6 2 2 6 2 2 6
40966 - 22 22 22 238 238 238 253 253 253 253 253 253
40967 -253 253 253 253 253 253 253 253 253 253 253 253
40968 -253 253 253 253 253 253 253 253 253 253 253 253
40969 -253 253 253 253 253 253 253 253 253 253 253 253
40970 -253 253 253 226 226 226 187 187 187 180 133 36
40971 -216 158 10 236 178 12 239 182 13 236 178 12
40972 -230 174 11 226 170 11 226 170 11 230 174 11
40973 -236 178 12 242 186 14 246 190 14 246 190 14
40974 -246 190 14 246 190 14 246 186 14 239 182 13
40975 -206 162 42 106 106 106 66 66 66 34 34 34
40976 - 14 14 14 6 6 6 0 0 0 0 0 0
40977 - 0 0 0 0 0 0 0 0 0 0 0 0
40978 - 0 0 0 0 0 0 0 0 0 0 0 0
40979 - 0 0 0 0 0 0 0 0 0 6 6 6
40980 - 26 26 26 70 70 70 163 133 67 213 154 11
40981 -236 178 12 246 190 14 246 190 14 246 190 14
40982 -246 190 14 246 190 14 246 190 14 246 190 14
40983 -246 190 14 246 190 14 246 190 14 246 190 14
40984 -246 190 14 246 190 14 246 190 14 241 196 14
40985 -190 146 13 18 14 6 2 2 6 2 2 6
40986 - 46 46 46 246 246 246 253 253 253 253 253 253
40987 -253 253 253 253 253 253 253 253 253 253 253 253
40988 -253 253 253 253 253 253 253 253 253 253 253 253
40989 -253 253 253 253 253 253 253 253 253 253 253 253
40990 -253 253 253 221 221 221 86 86 86 156 107 11
40991 -216 158 10 236 178 12 242 186 14 246 186 14
40992 -242 186 14 239 182 13 239 182 13 242 186 14
40993 -242 186 14 246 186 14 246 190 14 246 190 14
40994 -246 190 14 246 190 14 246 190 14 246 190 14
40995 -242 186 14 225 175 15 142 122 72 66 66 66
40996 - 30 30 30 10 10 10 0 0 0 0 0 0
40997 - 0 0 0 0 0 0 0 0 0 0 0 0
40998 - 0 0 0 0 0 0 0 0 0 0 0 0
40999 - 0 0 0 0 0 0 0 0 0 6 6 6
41000 - 26 26 26 70 70 70 163 133 67 210 150 10
41001 -236 178 12 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 246 190 14 246 190 14
41005 -232 195 16 121 92 8 34 34 34 106 106 106
41006 -221 221 221 253 253 253 253 253 253 253 253 253
41007 -253 253 253 253 253 253 253 253 253 253 253 253
41008 -253 253 253 253 253 253 253 253 253 253 253 253
41009 -253 253 253 253 253 253 253 253 253 253 253 253
41010 -242 242 242 82 82 82 18 14 6 163 110 8
41011 -216 158 10 236 178 12 242 186 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 -246 190 14 246 190 14 246 190 14 246 190 14
41015 -246 190 14 246 190 14 242 186 14 163 133 67
41016 - 46 46 46 18 18 18 6 6 6 0 0 0
41017 - 0 0 0 0 0 0 0 0 0 0 0 0
41018 - 0 0 0 0 0 0 0 0 0 0 0 0
41019 - 0 0 0 0 0 0 0 0 0 10 10 10
41020 - 30 30 30 78 78 78 163 133 67 210 150 10
41021 -236 178 12 246 186 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 190 14 246 190 14 246 190 14
41025 -241 196 14 215 174 15 190 178 144 253 253 253
41026 -253 253 253 253 253 253 253 253 253 253 253 253
41027 -253 253 253 253 253 253 253 253 253 253 253 253
41028 -253 253 253 253 253 253 253 253 253 253 253 253
41029 -253 253 253 253 253 253 253 253 253 218 218 218
41030 - 58 58 58 2 2 6 22 18 6 167 114 7
41031 -216 158 10 236 178 12 246 186 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 246 190 14 246 190 14 246 190 14
41035 -246 190 14 246 186 14 242 186 14 190 150 46
41036 - 54 54 54 22 22 22 6 6 6 0 0 0
41037 - 0 0 0 0 0 0 0 0 0 0 0 0
41038 - 0 0 0 0 0 0 0 0 0 0 0 0
41039 - 0 0 0 0 0 0 0 0 0 14 14 14
41040 - 38 38 38 86 86 86 180 133 36 213 154 11
41041 -236 178 12 246 186 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 190 14 246 190 14 246 190 14 246 190 14
41045 -246 190 14 232 195 16 190 146 13 214 214 214
41046 -253 253 253 253 253 253 253 253 253 253 253 253
41047 -253 253 253 253 253 253 253 253 253 253 253 253
41048 -253 253 253 253 253 253 253 253 253 253 253 253
41049 -253 253 253 250 250 250 170 170 170 26 26 26
41050 - 2 2 6 2 2 6 37 26 9 163 110 8
41051 -219 162 10 239 182 13 246 186 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 -246 190 14 246 190 14 246 190 14 246 190 14
41055 -246 186 14 236 178 12 224 166 10 142 122 72
41056 - 46 46 46 18 18 18 6 6 6 0 0 0
41057 - 0 0 0 0 0 0 0 0 0 0 0 0
41058 - 0 0 0 0 0 0 0 0 0 0 0 0
41059 - 0 0 0 0 0 0 6 6 6 18 18 18
41060 - 50 50 50 109 106 95 192 133 9 224 166 10
41061 -242 186 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 246 190 14
41064 -246 190 14 246 190 14 246 190 14 246 190 14
41065 -242 186 14 226 184 13 210 162 10 142 110 46
41066 -226 226 226 253 253 253 253 253 253 253 253 253
41067 -253 253 253 253 253 253 253 253 253 253 253 253
41068 -253 253 253 253 253 253 253 253 253 253 253 253
41069 -198 198 198 66 66 66 2 2 6 2 2 6
41070 - 2 2 6 2 2 6 50 34 6 156 107 11
41071 -219 162 10 239 182 13 246 186 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 190 14 246 190 14 246 190 14 242 186 14
41075 -234 174 13 213 154 11 154 122 46 66 66 66
41076 - 30 30 30 10 10 10 0 0 0 0 0 0
41077 - 0 0 0 0 0 0 0 0 0 0 0 0
41078 - 0 0 0 0 0 0 0 0 0 0 0 0
41079 - 0 0 0 0 0 0 6 6 6 22 22 22
41080 - 58 58 58 154 121 60 206 145 10 234 174 13
41081 -242 186 14 246 186 14 246 190 14 246 190 14
41082 -246 190 14 246 190 14 246 190 14 246 190 14
41083 -246 190 14 246 190 14 246 190 14 246 190 14
41084 -246 190 14 246 190 14 246 190 14 246 190 14
41085 -246 186 14 236 178 12 210 162 10 163 110 8
41086 - 61 42 6 138 138 138 218 218 218 250 250 250
41087 -253 253 253 253 253 253 253 253 253 250 250 250
41088 -242 242 242 210 210 210 144 144 144 66 66 66
41089 - 6 6 6 2 2 6 2 2 6 2 2 6
41090 - 2 2 6 2 2 6 61 42 6 163 110 8
41091 -216 158 10 236 178 12 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 239 182 13 230 174 11 216 158 10
41095 -190 142 34 124 112 88 70 70 70 38 38 38
41096 - 18 18 18 6 6 6 0 0 0 0 0 0
41097 - 0 0 0 0 0 0 0 0 0 0 0 0
41098 - 0 0 0 0 0 0 0 0 0 0 0 0
41099 - 0 0 0 0 0 0 6 6 6 22 22 22
41100 - 62 62 62 168 124 44 206 145 10 224 166 10
41101 -236 178 12 239 182 13 242 186 14 242 186 14
41102 -246 186 14 246 190 14 246 190 14 246 190 14
41103 -246 190 14 246 190 14 246 190 14 246 190 14
41104 -246 190 14 246 190 14 246 190 14 246 190 14
41105 -246 190 14 236 178 12 216 158 10 175 118 6
41106 - 80 54 7 2 2 6 6 6 6 30 30 30
41107 - 54 54 54 62 62 62 50 50 50 38 38 38
41108 - 14 14 14 2 2 6 2 2 6 2 2 6
41109 - 2 2 6 2 2 6 2 2 6 2 2 6
41110 - 2 2 6 6 6 6 80 54 7 167 114 7
41111 -213 154 11 236 178 12 246 190 14 246 190 14
41112 -246 190 14 246 190 14 246 190 14 246 190 14
41113 -246 190 14 242 186 14 239 182 13 239 182 13
41114 -230 174 11 210 150 10 174 135 50 124 112 88
41115 - 82 82 82 54 54 54 34 34 34 18 18 18
41116 - 6 6 6 0 0 0 0 0 0 0 0 0
41117 - 0 0 0 0 0 0 0 0 0 0 0 0
41118 - 0 0 0 0 0 0 0 0 0 0 0 0
41119 - 0 0 0 0 0 0 6 6 6 18 18 18
41120 - 50 50 50 158 118 36 192 133 9 200 144 11
41121 -216 158 10 219 162 10 224 166 10 226 170 11
41122 -230 174 11 236 178 12 239 182 13 239 182 13
41123 -242 186 14 246 186 14 246 190 14 246 190 14
41124 -246 190 14 246 190 14 246 190 14 246 190 14
41125 -246 186 14 230 174 11 210 150 10 163 110 8
41126 -104 69 6 10 10 10 2 2 6 2 2 6
41127 - 2 2 6 2 2 6 2 2 6 2 2 6
41128 - 2 2 6 2 2 6 2 2 6 2 2 6
41129 - 2 2 6 2 2 6 2 2 6 2 2 6
41130 - 2 2 6 6 6 6 91 60 6 167 114 7
41131 -206 145 10 230 174 11 242 186 14 246 190 14
41132 -246 190 14 246 190 14 246 186 14 242 186 14
41133 -239 182 13 230 174 11 224 166 10 213 154 11
41134 -180 133 36 124 112 88 86 86 86 58 58 58
41135 - 38 38 38 22 22 22 10 10 10 6 6 6
41136 - 0 0 0 0 0 0 0 0 0 0 0 0
41137 - 0 0 0 0 0 0 0 0 0 0 0 0
41138 - 0 0 0 0 0 0 0 0 0 0 0 0
41139 - 0 0 0 0 0 0 0 0 0 14 14 14
41140 - 34 34 34 70 70 70 138 110 50 158 118 36
41141 -167 114 7 180 123 7 192 133 9 197 138 11
41142 -200 144 11 206 145 10 213 154 11 219 162 10
41143 -224 166 10 230 174 11 239 182 13 242 186 14
41144 -246 186 14 246 186 14 246 186 14 246 186 14
41145 -239 182 13 216 158 10 185 133 11 152 99 6
41146 -104 69 6 18 14 6 2 2 6 2 2 6
41147 - 2 2 6 2 2 6 2 2 6 2 2 6
41148 - 2 2 6 2 2 6 2 2 6 2 2 6
41149 - 2 2 6 2 2 6 2 2 6 2 2 6
41150 - 2 2 6 6 6 6 80 54 7 152 99 6
41151 -192 133 9 219 162 10 236 178 12 239 182 13
41152 -246 186 14 242 186 14 239 182 13 236 178 12
41153 -224 166 10 206 145 10 192 133 9 154 121 60
41154 - 94 94 94 62 62 62 42 42 42 22 22 22
41155 - 14 14 14 6 6 6 0 0 0 0 0 0
41156 - 0 0 0 0 0 0 0 0 0 0 0 0
41157 - 0 0 0 0 0 0 0 0 0 0 0 0
41158 - 0 0 0 0 0 0 0 0 0 0 0 0
41159 - 0 0 0 0 0 0 0 0 0 6 6 6
41160 - 18 18 18 34 34 34 58 58 58 78 78 78
41161 -101 98 89 124 112 88 142 110 46 156 107 11
41162 -163 110 8 167 114 7 175 118 6 180 123 7
41163 -185 133 11 197 138 11 210 150 10 219 162 10
41164 -226 170 11 236 178 12 236 178 12 234 174 13
41165 -219 162 10 197 138 11 163 110 8 130 83 6
41166 - 91 60 6 10 10 10 2 2 6 2 2 6
41167 - 18 18 18 38 38 38 38 38 38 38 38 38
41168 - 38 38 38 38 38 38 38 38 38 38 38 38
41169 - 38 38 38 38 38 38 26 26 26 2 2 6
41170 - 2 2 6 6 6 6 70 47 6 137 92 6
41171 -175 118 6 200 144 11 219 162 10 230 174 11
41172 -234 174 13 230 174 11 219 162 10 210 150 10
41173 -192 133 9 163 110 8 124 112 88 82 82 82
41174 - 50 50 50 30 30 30 14 14 14 6 6 6
41175 - 0 0 0 0 0 0 0 0 0 0 0 0
41176 - 0 0 0 0 0 0 0 0 0 0 0 0
41177 - 0 0 0 0 0 0 0 0 0 0 0 0
41178 - 0 0 0 0 0 0 0 0 0 0 0 0
41179 - 0 0 0 0 0 0 0 0 0 0 0 0
41180 - 6 6 6 14 14 14 22 22 22 34 34 34
41181 - 42 42 42 58 58 58 74 74 74 86 86 86
41182 -101 98 89 122 102 70 130 98 46 121 87 25
41183 -137 92 6 152 99 6 163 110 8 180 123 7
41184 -185 133 11 197 138 11 206 145 10 200 144 11
41185 -180 123 7 156 107 11 130 83 6 104 69 6
41186 - 50 34 6 54 54 54 110 110 110 101 98 89
41187 - 86 86 86 82 82 82 78 78 78 78 78 78
41188 - 78 78 78 78 78 78 78 78 78 78 78 78
41189 - 78 78 78 82 82 82 86 86 86 94 94 94
41190 -106 106 106 101 101 101 86 66 34 124 80 6
41191 -156 107 11 180 123 7 192 133 9 200 144 11
41192 -206 145 10 200 144 11 192 133 9 175 118 6
41193 -139 102 15 109 106 95 70 70 70 42 42 42
41194 - 22 22 22 10 10 10 0 0 0 0 0 0
41195 - 0 0 0 0 0 0 0 0 0 0 0 0
41196 - 0 0 0 0 0 0 0 0 0 0 0 0
41197 - 0 0 0 0 0 0 0 0 0 0 0 0
41198 - 0 0 0 0 0 0 0 0 0 0 0 0
41199 - 0 0 0 0 0 0 0 0 0 0 0 0
41200 - 0 0 0 0 0 0 6 6 6 10 10 10
41201 - 14 14 14 22 22 22 30 30 30 38 38 38
41202 - 50 50 50 62 62 62 74 74 74 90 90 90
41203 -101 98 89 112 100 78 121 87 25 124 80 6
41204 -137 92 6 152 99 6 152 99 6 152 99 6
41205 -138 86 6 124 80 6 98 70 6 86 66 30
41206 -101 98 89 82 82 82 58 58 58 46 46 46
41207 - 38 38 38 34 34 34 34 34 34 34 34 34
41208 - 34 34 34 34 34 34 34 34 34 34 34 34
41209 - 34 34 34 34 34 34 38 38 38 42 42 42
41210 - 54 54 54 82 82 82 94 86 76 91 60 6
41211 -134 86 6 156 107 11 167 114 7 175 118 6
41212 -175 118 6 167 114 7 152 99 6 121 87 25
41213 -101 98 89 62 62 62 34 34 34 18 18 18
41214 - 6 6 6 0 0 0 0 0 0 0 0 0
41215 - 0 0 0 0 0 0 0 0 0 0 0 0
41216 - 0 0 0 0 0 0 0 0 0 0 0 0
41217 - 0 0 0 0 0 0 0 0 0 0 0 0
41218 - 0 0 0 0 0 0 0 0 0 0 0 0
41219 - 0 0 0 0 0 0 0 0 0 0 0 0
41220 - 0 0 0 0 0 0 0 0 0 0 0 0
41221 - 0 0 0 6 6 6 6 6 6 10 10 10
41222 - 18 18 18 22 22 22 30 30 30 42 42 42
41223 - 50 50 50 66 66 66 86 86 86 101 98 89
41224 -106 86 58 98 70 6 104 69 6 104 69 6
41225 -104 69 6 91 60 6 82 62 34 90 90 90
41226 - 62 62 62 38 38 38 22 22 22 14 14 14
41227 - 10 10 10 10 10 10 10 10 10 10 10 10
41228 - 10 10 10 10 10 10 6 6 6 10 10 10
41229 - 10 10 10 10 10 10 10 10 10 14 14 14
41230 - 22 22 22 42 42 42 70 70 70 89 81 66
41231 - 80 54 7 104 69 6 124 80 6 137 92 6
41232 -134 86 6 116 81 8 100 82 52 86 86 86
41233 - 58 58 58 30 30 30 14 14 14 6 6 6
41234 - 0 0 0 0 0 0 0 0 0 0 0 0
41235 - 0 0 0 0 0 0 0 0 0 0 0 0
41236 - 0 0 0 0 0 0 0 0 0 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 - 0 0 0 0 0 0 0 0 0 0 0 0
41240 - 0 0 0 0 0 0 0 0 0 0 0 0
41241 - 0 0 0 0 0 0 0 0 0 0 0 0
41242 - 0 0 0 6 6 6 10 10 10 14 14 14
41243 - 18 18 18 26 26 26 38 38 38 54 54 54
41244 - 70 70 70 86 86 86 94 86 76 89 81 66
41245 - 89 81 66 86 86 86 74 74 74 50 50 50
41246 - 30 30 30 14 14 14 6 6 6 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 - 6 6 6 18 18 18 34 34 34 58 58 58
41251 - 82 82 82 89 81 66 89 81 66 89 81 66
41252 - 94 86 66 94 86 76 74 74 74 50 50 50
41253 - 26 26 26 14 14 14 6 6 6 0 0 0
41254 - 0 0 0 0 0 0 0 0 0 0 0 0
41255 - 0 0 0 0 0 0 0 0 0 0 0 0
41256 - 0 0 0 0 0 0 0 0 0 0 0 0
41257 - 0 0 0 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 0 0 0 0 0 0 0 0 0
41260 - 0 0 0 0 0 0 0 0 0 0 0 0
41261 - 0 0 0 0 0 0 0 0 0 0 0 0
41262 - 0 0 0 0 0 0 0 0 0 0 0 0
41263 - 6 6 6 6 6 6 14 14 14 18 18 18
41264 - 30 30 30 38 38 38 46 46 46 54 54 54
41265 - 50 50 50 42 42 42 30 30 30 18 18 18
41266 - 10 10 10 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 6 6 6 14 14 14 26 26 26
41271 - 38 38 38 50 50 50 58 58 58 58 58 58
41272 - 54 54 54 42 42 42 30 30 30 18 18 18
41273 - 10 10 10 0 0 0 0 0 0 0 0 0
41274 - 0 0 0 0 0 0 0 0 0 0 0 0
41275 - 0 0 0 0 0 0 0 0 0 0 0 0
41276 - 0 0 0 0 0 0 0 0 0 0 0 0
41277 - 0 0 0 0 0 0 0 0 0 0 0 0
41278 - 0 0 0 0 0 0 0 0 0 0 0 0
41279 - 0 0 0 0 0 0 0 0 0 0 0 0
41280 - 0 0 0 0 0 0 0 0 0 0 0 0
41281 - 0 0 0 0 0 0 0 0 0 0 0 0
41282 - 0 0 0 0 0 0 0 0 0 0 0 0
41283 - 0 0 0 0 0 0 0 0 0 6 6 6
41284 - 6 6 6 10 10 10 14 14 14 18 18 18
41285 - 18 18 18 14 14 14 10 10 10 6 6 6
41286 - 0 0 0 0 0 0 0 0 0 0 0 0
41287 - 0 0 0 0 0 0 0 0 0 0 0 0
41288 - 0 0 0 0 0 0 0 0 0 0 0 0
41289 - 0 0 0 0 0 0 0 0 0 0 0 0
41290 - 0 0 0 0 0 0 0 0 0 6 6 6
41291 - 14 14 14 18 18 18 22 22 22 22 22 22
41292 - 18 18 18 14 14 14 10 10 10 6 6 6
41293 - 0 0 0 0 0 0 0 0 0 0 0 0
41294 - 0 0 0 0 0 0 0 0 0 0 0 0
41295 - 0 0 0 0 0 0 0 0 0 0 0 0
41296 - 0 0 0 0 0 0 0 0 0 0 0 0
41297 - 0 0 0 0 0 0 0 0 0 0 0 0
41298 +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 4 4 4 4 4 4 4 4 4 4 4 4
41301 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41302 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4
41315 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41316 +4 4 4 4 4 4 4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4
41329 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41330 +4 4 4 4 4 4 4 4 4 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
41340 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41341 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41342 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41343 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41344 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41345 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41346 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41347 +4 4 4 4 4 4 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
41354 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41355 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41356 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41357 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41358 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41359 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41360 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41361 +4 4 4 4 4 4 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
41368 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41369 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41370 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41371 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41372 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41373 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41374 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41375 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41376 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41377 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41378 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41379 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41380 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41381 +4 4 4 4 4 4
41382 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41383 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41384 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41385 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41386 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
41387 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
41390 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41391 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
41392 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41393 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
41394 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41395 +4 4 4 4 4 4
41396 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41397 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41398 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41399 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41400 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
41401 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
41402 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41403 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41404 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41405 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
41406 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
41407 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
41408 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41409 +4 4 4 4 4 4
41410 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41411 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41412 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41413 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41414 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
41415 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
41416 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41417 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41418 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41419 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
41420 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
41421 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
41422 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
41423 +4 4 4 4 4 4
41424 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41425 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41426 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41427 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
41428 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
41429 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
41430 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
41431 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41432 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41433 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
41434 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
41435 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
41436 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
41437 +4 4 4 4 4 4
41438 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41439 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41440 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41441 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
41442 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
41443 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
41444 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
41445 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41446 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
41447 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
41448 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
41449 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
41450 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
41451 +4 4 4 4 4 4
41452 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41453 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41454 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41455 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
41456 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
41457 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
41458 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
41459 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
41460 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
41461 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
41462 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
41463 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
41464 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
41465 +4 4 4 4 4 4
41466 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41467 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41468 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
41469 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
41470 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
41471 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
41472 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
41473 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
41474 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
41475 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
41476 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
41477 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
41478 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
41479 +4 4 4 4 4 4
41480 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41481 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41482 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
41483 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
41484 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
41485 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
41486 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
41487 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
41488 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
41489 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
41490 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
41491 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
41492 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
41493 +4 4 4 4 4 4
41494 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41495 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41496 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
41497 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
41498 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
41499 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
41500 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
41501 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
41502 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
41503 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
41504 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
41505 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
41506 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41507 +4 4 4 4 4 4
41508 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41509 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41510 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
41511 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
41512 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
41513 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
41514 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
41515 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
41516 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
41517 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
41518 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
41519 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
41520 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
41521 +4 4 4 4 4 4
41522 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41523 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
41524 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
41525 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
41526 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
41527 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
41528 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
41529 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
41530 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
41531 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
41532 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
41533 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
41534 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
41535 +4 4 4 4 4 4
41536 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41537 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
41538 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
41539 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
41540 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41541 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
41542 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
41543 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
41544 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
41545 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
41546 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
41547 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
41548 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
41549 +0 0 0 4 4 4
41550 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41551 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
41552 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
41553 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
41554 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
41555 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
41556 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
41557 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
41558 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
41559 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
41560 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
41561 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
41562 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
41563 +2 0 0 0 0 0
41564 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
41565 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
41566 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
41567 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
41568 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
41569 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
41570 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
41571 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
41572 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
41573 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
41574 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
41575 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
41576 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
41577 +37 38 37 0 0 0
41578 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41579 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
41580 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
41581 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
41582 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
41583 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
41584 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
41585 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
41586 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
41587 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
41588 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
41589 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
41590 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
41591 +85 115 134 4 0 0
41592 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
41593 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
41594 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
41595 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
41596 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
41597 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
41598 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
41599 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
41600 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
41601 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
41602 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
41603 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
41604 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
41605 +60 73 81 4 0 0
41606 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
41607 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
41608 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
41609 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
41610 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
41611 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
41612 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
41613 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
41614 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
41615 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
41616 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
41617 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
41618 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
41619 +16 19 21 4 0 0
41620 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
41621 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
41622 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
41623 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
41624 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
41625 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
41626 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
41627 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
41628 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
41629 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
41630 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
41631 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
41632 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
41633 +4 0 0 4 3 3
41634 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
41635 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
41636 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
41637 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
41638 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
41639 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
41640 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
41641 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
41642 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
41643 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
41644 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
41645 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
41646 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
41647 +3 2 2 4 4 4
41648 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
41649 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
41650 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
41651 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41652 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
41653 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
41654 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
41655 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
41656 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
41657 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
41658 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
41659 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
41660 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
41661 +4 4 4 4 4 4
41662 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
41663 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
41664 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
41665 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
41666 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
41667 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
41668 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
41669 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
41670 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
41671 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
41672 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
41673 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
41674 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
41675 +4 4 4 4 4 4
41676 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
41677 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
41678 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
41679 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
41680 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
41681 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41682 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
41683 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
41684 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
41685 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
41686 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
41687 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
41688 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
41689 +5 5 5 5 5 5
41690 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
41691 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
41692 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
41693 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
41694 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
41695 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41696 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
41697 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
41698 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
41699 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
41700 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
41701 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
41702 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41703 +5 5 5 4 4 4
41704 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
41705 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
41706 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
41707 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
41708 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41709 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
41710 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
41711 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
41712 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
41713 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
41714 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
41715 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41716 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41717 +4 4 4 4 4 4
41718 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
41719 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
41720 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
41721 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
41722 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
41723 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41724 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41725 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
41726 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
41727 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
41728 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
41729 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
41730 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41731 +4 4 4 4 4 4
41732 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
41733 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
41734 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
41735 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
41736 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41737 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
41738 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
41739 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
41740 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
41741 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
41742 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
41743 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41744 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41745 +4 4 4 4 4 4
41746 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
41747 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
41748 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
41749 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
41750 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41751 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41752 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41753 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
41754 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
41755 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
41756 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
41757 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41758 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41759 +4 4 4 4 4 4
41760 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
41761 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
41762 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
41763 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
41764 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41765 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
41766 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41767 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
41768 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
41769 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
41770 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41771 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41772 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41773 +4 4 4 4 4 4
41774 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
41775 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
41776 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
41777 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
41778 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41779 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
41780 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
41781 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
41782 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
41783 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
41784 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
41785 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41786 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41787 +4 4 4 4 4 4
41788 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
41789 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
41790 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
41791 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
41792 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41793 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
41794 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
41795 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
41796 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
41797 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
41798 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
41799 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41800 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41801 +4 4 4 4 4 4
41802 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
41803 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
41804 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
41805 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41806 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
41807 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
41808 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
41809 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
41810 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
41811 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
41812 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41813 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41814 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41815 +4 4 4 4 4 4
41816 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
41817 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
41818 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
41819 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41820 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41821 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
41822 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
41823 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
41824 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
41825 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
41826 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41827 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41828 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41829 +4 4 4 4 4 4
41830 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
41831 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
41832 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41833 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41834 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41835 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
41836 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
41837 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
41838 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
41839 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
41840 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41841 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41842 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41843 +4 4 4 4 4 4
41844 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
41845 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
41846 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41847 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41848 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41849 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
41850 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
41851 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
41852 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41853 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41854 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41855 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41856 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41857 +4 4 4 4 4 4
41858 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41859 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
41860 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41861 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
41862 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
41863 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
41864 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
41865 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
41866 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41867 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41868 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41869 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41870 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41871 +4 4 4 4 4 4
41872 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41873 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
41874 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41875 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
41876 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41877 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
41878 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
41879 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
41880 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41881 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41882 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41883 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41884 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41885 +4 4 4 4 4 4
41886 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
41887 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
41888 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41889 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
41890 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
41891 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
41892 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
41893 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
41894 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41895 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41896 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41897 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41898 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41899 +4 4 4 4 4 4
41900 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
41901 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
41902 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41903 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
41904 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
41905 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
41906 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
41907 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
41908 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41909 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41910 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41911 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41912 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41913 +4 4 4 4 4 4
41914 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41915 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
41916 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41917 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
41918 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
41919 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
41920 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
41921 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
41922 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41923 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41924 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41925 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41926 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41927 +4 4 4 4 4 4
41928 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
41929 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
41930 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41931 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
41932 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
41933 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
41934 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
41935 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
41936 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
41937 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41938 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41939 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41940 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41941 +4 4 4 4 4 4
41942 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41943 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
41944 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
41945 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
41946 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
41947 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
41948 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
41949 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
41950 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41951 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41952 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41953 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41954 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41955 +4 4 4 4 4 4
41956 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41957 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
41958 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41959 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
41960 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
41961 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
41962 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
41963 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
41964 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41965 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41966 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41967 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41968 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41969 +4 4 4 4 4 4
41970 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41971 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
41972 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
41973 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
41974 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
41975 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
41976 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41977 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
41978 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41979 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41980 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41981 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41982 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41983 +4 4 4 4 4 4
41984 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41985 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
41986 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
41987 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41988 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
41989 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
41990 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41991 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
41992 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41993 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41994 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41995 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41996 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41997 +4 4 4 4 4 4
41998 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41999 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
42000 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
42001 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
42002 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
42003 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
42004 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
42005 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
42006 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
42007 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42008 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42009 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42010 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42011 +4 4 4 4 4 4
42012 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
42013 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
42014 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
42015 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
42016 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
42017 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
42018 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
42019 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
42020 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
42021 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42022 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42023 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42024 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42025 +4 4 4 4 4 4
42026 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
42027 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
42028 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
42029 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
42030 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
42031 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
42032 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
42033 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
42034 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
42035 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42036 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42037 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42038 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42039 +4 4 4 4 4 4
42040 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
42041 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
42042 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
42043 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
42044 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
42045 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
42046 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
42047 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
42048 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
42049 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42050 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42051 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42052 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42053 +4 4 4 4 4 4
42054 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
42055 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
42056 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
42057 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
42058 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
42059 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
42060 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
42061 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
42062 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
42063 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
42064 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42065 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42066 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42067 +4 4 4 4 4 4
42068 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
42069 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
42070 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
42071 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
42072 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
42073 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
42074 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
42075 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
42076 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
42077 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
42078 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42079 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42080 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42081 +4 4 4 4 4 4
42082 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
42083 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
42084 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
42085 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
42086 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
42087 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
42088 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42089 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
42090 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
42091 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
42092 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42093 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42094 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42095 +4 4 4 4 4 4
42096 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
42097 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
42098 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
42099 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
42100 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
42101 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
42102 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
42103 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
42104 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
42105 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
42106 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42107 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42108 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42109 +4 4 4 4 4 4
42110 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
42111 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
42112 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
42113 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
42114 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
42115 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
42116 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
42117 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
42118 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
42119 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
42120 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42121 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42122 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42123 +4 4 4 4 4 4
42124 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42125 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
42126 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
42127 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
42128 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
42129 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
42130 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
42131 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
42132 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
42133 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
42134 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42135 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42136 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42137 +4 4 4 4 4 4
42138 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
42139 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
42140 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
42141 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
42142 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
42143 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
42144 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
42145 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
42146 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
42147 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
42148 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42149 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42150 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42151 +4 4 4 4 4 4
42152 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
42153 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
42154 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
42155 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
42156 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
42157 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
42158 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
42159 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
42160 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
42161 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42162 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42163 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42164 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42165 +4 4 4 4 4 4
42166 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
42167 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42168 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
42169 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
42170 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
42171 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
42172 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
42173 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
42174 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
42175 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42176 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42177 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42178 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42179 +4 4 4 4 4 4
42180 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
42181 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
42182 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
42183 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
42184 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
42185 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
42186 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
42187 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
42188 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
42189 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42190 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42191 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42192 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42193 +4 4 4 4 4 4
42194 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
42195 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
42196 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
42197 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
42198 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
42199 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
42200 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
42201 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
42202 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42203 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42204 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42205 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42206 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42207 +4 4 4 4 4 4
42208 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
42209 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
42210 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42211 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
42212 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
42213 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
42214 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
42215 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
42216 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42217 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42218 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42219 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42220 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42221 +4 4 4 4 4 4
42222 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
42223 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
42224 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
42225 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
42226 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
42227 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
42228 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
42229 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
42230 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42231 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42232 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42233 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42234 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42235 +4 4 4 4 4 4
42236 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42237 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
42238 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42239 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
42240 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
42241 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
42242 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
42243 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
42244 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42245 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42246 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42247 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42248 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42249 +4 4 4 4 4 4
42250 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42251 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
42252 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
42253 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
42254 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
42255 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
42256 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
42257 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
42258 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42259 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42260 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42261 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42262 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42263 +4 4 4 4 4 4
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 5 5 5 5 5 5 5 5 5
42266 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
42267 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42268 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
42269 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
42270 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
42271 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42272 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42273 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42274 +4 4 4 4 4 4 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
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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42281 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
42282 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
42283 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
42284 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
42285 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42286 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42287 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42288 +4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 5 5 5
42295 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42296 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
42297 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
42298 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
42299 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42300 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42301 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42302 +4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4
42309 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42310 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42311 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
42312 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
42313 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42314 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42315 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42316 +4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4
42323 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
42324 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42325 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42326 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
42327 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42328 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42329 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42330 +4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4
42337 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
42338 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
42339 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
42340 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
42341 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42342 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42343 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42344 +4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4
42351 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42352 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
42353 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42354 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42355 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42356 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42357 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42358 +4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4
42365 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42366 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
42367 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
42368 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
42369 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42370 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42371 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42372 +4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4
42379 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42380 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
42381 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
42382 +5 5 5 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 4 4 4 4 4 4 4 4 4
42384 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42385 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42386 +4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4
42393 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42394 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
42395 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
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 4 4 4 4 4 4
42398 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42399 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42400 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42401 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42402 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42403 +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 4 4 4 4 4 4 4 4 4 4 4 4
42407 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42408 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
42409 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
42410 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42411 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42412 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42413 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42414 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42415 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42416 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42417 +4 4 4 4 4 4
42418 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
42419 index 38fcfff..0072dcd 100644
42420 --- a/drivers/video/udlfb.c
42421 +++ b/drivers/video/udlfb.c
42422 @@ -620,11 +620,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
42423 dlfb_urb_completion(urb);
42424
42425 error:
42426 - atomic_add(bytes_sent, &dev->bytes_sent);
42427 - atomic_add(bytes_identical, &dev->bytes_identical);
42428 - atomic_add(width*height*2, &dev->bytes_rendered);
42429 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42430 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42431 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
42432 end_cycles = get_cycles();
42433 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
42434 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42435 >> 10)), /* Kcycles */
42436 &dev->cpu_kcycles_used);
42437
42438 @@ -745,11 +745,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
42439 dlfb_urb_completion(urb);
42440
42441 error:
42442 - atomic_add(bytes_sent, &dev->bytes_sent);
42443 - atomic_add(bytes_identical, &dev->bytes_identical);
42444 - atomic_add(bytes_rendered, &dev->bytes_rendered);
42445 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42446 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42447 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
42448 end_cycles = get_cycles();
42449 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
42450 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42451 >> 10)), /* Kcycles */
42452 &dev->cpu_kcycles_used);
42453 }
42454 @@ -1373,7 +1373,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
42455 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42456 struct dlfb_data *dev = fb_info->par;
42457 return snprintf(buf, PAGE_SIZE, "%u\n",
42458 - atomic_read(&dev->bytes_rendered));
42459 + atomic_read_unchecked(&dev->bytes_rendered));
42460 }
42461
42462 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42463 @@ -1381,7 +1381,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42464 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42465 struct dlfb_data *dev = fb_info->par;
42466 return snprintf(buf, PAGE_SIZE, "%u\n",
42467 - atomic_read(&dev->bytes_identical));
42468 + atomic_read_unchecked(&dev->bytes_identical));
42469 }
42470
42471 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42472 @@ -1389,7 +1389,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42473 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42474 struct dlfb_data *dev = fb_info->par;
42475 return snprintf(buf, PAGE_SIZE, "%u\n",
42476 - atomic_read(&dev->bytes_sent));
42477 + atomic_read_unchecked(&dev->bytes_sent));
42478 }
42479
42480 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42481 @@ -1397,7 +1397,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42482 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42483 struct dlfb_data *dev = fb_info->par;
42484 return snprintf(buf, PAGE_SIZE, "%u\n",
42485 - atomic_read(&dev->cpu_kcycles_used));
42486 + atomic_read_unchecked(&dev->cpu_kcycles_used));
42487 }
42488
42489 static ssize_t edid_show(
42490 @@ -1457,10 +1457,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
42491 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42492 struct dlfb_data *dev = fb_info->par;
42493
42494 - atomic_set(&dev->bytes_rendered, 0);
42495 - atomic_set(&dev->bytes_identical, 0);
42496 - atomic_set(&dev->bytes_sent, 0);
42497 - atomic_set(&dev->cpu_kcycles_used, 0);
42498 + atomic_set_unchecked(&dev->bytes_rendered, 0);
42499 + atomic_set_unchecked(&dev->bytes_identical, 0);
42500 + atomic_set_unchecked(&dev->bytes_sent, 0);
42501 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
42502
42503 return count;
42504 }
42505 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
42506 index b0e2a42..e2df3ad 100644
42507 --- a/drivers/video/uvesafb.c
42508 +++ b/drivers/video/uvesafb.c
42509 @@ -19,6 +19,7 @@
42510 #include <linux/io.h>
42511 #include <linux/mutex.h>
42512 #include <linux/slab.h>
42513 +#include <linux/moduleloader.h>
42514 #include <video/edid.h>
42515 #include <video/uvesafb.h>
42516 #ifdef CONFIG_X86
42517 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
42518 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
42519 par->pmi_setpal = par->ypan = 0;
42520 } else {
42521 +
42522 +#ifdef CONFIG_PAX_KERNEXEC
42523 +#ifdef CONFIG_MODULES
42524 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
42525 +#endif
42526 + if (!par->pmi_code) {
42527 + par->pmi_setpal = par->ypan = 0;
42528 + return 0;
42529 + }
42530 +#endif
42531 +
42532 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
42533 + task->t.regs.edi);
42534 +
42535 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42536 + pax_open_kernel();
42537 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
42538 + pax_close_kernel();
42539 +
42540 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
42541 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
42542 +#else
42543 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
42544 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
42545 +#endif
42546 +
42547 printk(KERN_INFO "uvesafb: protected mode interface info at "
42548 "%04x:%04x\n",
42549 (u16)task->t.regs.es, (u16)task->t.regs.edi);
42550 @@ -816,13 +839,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
42551 par->ypan = ypan;
42552
42553 if (par->pmi_setpal || par->ypan) {
42554 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
42555 if (__supported_pte_mask & _PAGE_NX) {
42556 par->pmi_setpal = par->ypan = 0;
42557 printk(KERN_WARNING "uvesafb: NX protection is actively."
42558 "We have better not to use the PMI.\n");
42559 - } else {
42560 + } else
42561 +#endif
42562 uvesafb_vbe_getpmi(task, par);
42563 - }
42564 }
42565 #else
42566 /* The protected mode interface is not available on non-x86. */
42567 @@ -1836,6 +1860,11 @@ out:
42568 if (par->vbe_modes)
42569 kfree(par->vbe_modes);
42570
42571 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42572 + if (par->pmi_code)
42573 + module_free_exec(NULL, par->pmi_code);
42574 +#endif
42575 +
42576 framebuffer_release(info);
42577 return err;
42578 }
42579 @@ -1862,6 +1891,12 @@ static int uvesafb_remove(struct platform_device *dev)
42580 kfree(par->vbe_state_orig);
42581 if (par->vbe_state_saved)
42582 kfree(par->vbe_state_saved);
42583 +
42584 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42585 + if (par->pmi_code)
42586 + module_free_exec(NULL, par->pmi_code);
42587 +#endif
42588 +
42589 }
42590
42591 framebuffer_release(info);
42592 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
42593 index 501b340..86bd4cf 100644
42594 --- a/drivers/video/vesafb.c
42595 +++ b/drivers/video/vesafb.c
42596 @@ -9,6 +9,7 @@
42597 */
42598
42599 #include <linux/module.h>
42600 +#include <linux/moduleloader.h>
42601 #include <linux/kernel.h>
42602 #include <linux/errno.h>
42603 #include <linux/string.h>
42604 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
42605 static int vram_total __initdata; /* Set total amount of memory */
42606 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
42607 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
42608 -static void (*pmi_start)(void) __read_mostly;
42609 -static void (*pmi_pal) (void) __read_mostly;
42610 +static void (*pmi_start)(void) __read_only;
42611 +static void (*pmi_pal) (void) __read_only;
42612 static int depth __read_mostly;
42613 static int vga_compat __read_mostly;
42614 /* --------------------------------------------------------------------- */
42615 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
42616 unsigned int size_vmode;
42617 unsigned int size_remap;
42618 unsigned int size_total;
42619 + void *pmi_code = NULL;
42620
42621 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
42622 return -ENODEV;
42623 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
42624 size_remap = size_total;
42625 vesafb_fix.smem_len = size_remap;
42626
42627 -#ifndef __i386__
42628 - screen_info.vesapm_seg = 0;
42629 -#endif
42630 -
42631 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
42632 printk(KERN_WARNING
42633 "vesafb: cannot reserve video memory at 0x%lx\n",
42634 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
42635 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
42636 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
42637
42638 +#ifdef __i386__
42639 +
42640 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42641 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
42642 + if (!pmi_code)
42643 +#elif !defined(CONFIG_PAX_KERNEXEC)
42644 + if (0)
42645 +#endif
42646 +
42647 +#endif
42648 + screen_info.vesapm_seg = 0;
42649 +
42650 if (screen_info.vesapm_seg) {
42651 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
42652 - screen_info.vesapm_seg,screen_info.vesapm_off);
42653 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
42654 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
42655 }
42656
42657 if (screen_info.vesapm_seg < 0xc000)
42658 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
42659
42660 if (ypan || pmi_setpal) {
42661 unsigned short *pmi_base;
42662 +
42663 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
42664 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
42665 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
42666 +
42667 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42668 + pax_open_kernel();
42669 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
42670 +#else
42671 + pmi_code = pmi_base;
42672 +#endif
42673 +
42674 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
42675 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
42676 +
42677 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42678 + pmi_start = ktva_ktla(pmi_start);
42679 + pmi_pal = ktva_ktla(pmi_pal);
42680 + pax_close_kernel();
42681 +#endif
42682 +
42683 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
42684 if (pmi_base[3]) {
42685 printk(KERN_INFO "vesafb: pmi: ports = ");
42686 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
42687 info->node, info->fix.id);
42688 return 0;
42689 err:
42690 +
42691 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42692 + module_free_exec(NULL, pmi_code);
42693 +#endif
42694 +
42695 if (info->screen_base)
42696 iounmap(info->screen_base);
42697 framebuffer_release(info);
42698 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
42699 index 88714ae..16c2e11 100644
42700 --- a/drivers/video/via/via_clock.h
42701 +++ b/drivers/video/via/via_clock.h
42702 @@ -56,7 +56,7 @@ struct via_clock {
42703
42704 void (*set_engine_pll_state)(u8 state);
42705 void (*set_engine_pll)(struct via_pll_config config);
42706 -};
42707 +} __no_const;
42708
42709
42710 static inline u32 get_pll_internal_frequency(u32 ref_freq,
42711 diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
42712 index 453db0c..604973e 100644
42713 --- a/drivers/virtio/virtio_mmio.c
42714 +++ b/drivers/virtio/virtio_mmio.c
42715 @@ -521,7 +521,7 @@ static int vm_cmdline_set(const char *device,
42716
42717 resources[0].end = memparse(device, &str) - 1;
42718
42719 - processed = sscanf(str, "@%lli:%u%n:%d%n",
42720 + processed = sscanf(str, "@%lli:%llu%n:%d%n",
42721 &base, &resources[1].start, &consumed,
42722 &vm_cmdline_id, &consumed);
42723
42724 diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
42725 index e56c934..fc22f4b 100644
42726 --- a/drivers/xen/xen-pciback/conf_space.h
42727 +++ b/drivers/xen/xen-pciback/conf_space.h
42728 @@ -44,15 +44,15 @@ struct config_field {
42729 struct {
42730 conf_dword_write write;
42731 conf_dword_read read;
42732 - } dw;
42733 + } __no_const dw;
42734 struct {
42735 conf_word_write write;
42736 conf_word_read read;
42737 - } w;
42738 + } __no_const w;
42739 struct {
42740 conf_byte_write write;
42741 conf_byte_read read;
42742 - } b;
42743 + } __no_const b;
42744 } u;
42745 struct list_head list;
42746 };
42747 diff --git a/drivers/xen/xenbus/xenbus_dev_frontend.c b/drivers/xen/xenbus/xenbus_dev_frontend.c
42748 index 89f7625..ac72702 100644
42749 --- a/drivers/xen/xenbus/xenbus_dev_frontend.c
42750 +++ b/drivers/xen/xenbus/xenbus_dev_frontend.c
42751 @@ -458,7 +458,7 @@ static ssize_t xenbus_file_write(struct file *filp,
42752 goto out;
42753
42754 /* Can't write a xenbus message larger we can buffer */
42755 - if ((len + u->len) > sizeof(u->u.buffer)) {
42756 + if (len > sizeof(u->u.buffer) - u->len) {
42757 /* On error, dump existing buffer */
42758 u->len = 0;
42759 rc = -EINVAL;
42760 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
42761 index fef20db..d28b1ab 100644
42762 --- a/drivers/xen/xenfs/xenstored.c
42763 +++ b/drivers/xen/xenfs/xenstored.c
42764 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
42765 static int xsd_kva_open(struct inode *inode, struct file *file)
42766 {
42767 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
42768 +#ifdef CONFIG_GRKERNSEC_HIDESYM
42769 + NULL);
42770 +#else
42771 xen_store_interface);
42772 +#endif
42773 +
42774 if (!file->private_data)
42775 return -ENOMEM;
42776 return 0;
42777 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
42778 index cbf9dbb..35c3af7 100644
42779 --- a/fs/9p/vfs_inode.c
42780 +++ b/fs/9p/vfs_inode.c
42781 @@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
42782 void
42783 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42784 {
42785 - char *s = nd_get_link(nd);
42786 + const char *s = nd_get_link(nd);
42787
42788 p9_debug(P9_DEBUG_VFS, " %s %s\n",
42789 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
42790 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
42791 index 0225742..1cd4732 100644
42792 --- a/fs/Kconfig.binfmt
42793 +++ b/fs/Kconfig.binfmt
42794 @@ -89,7 +89,7 @@ config HAVE_AOUT
42795
42796 config BINFMT_AOUT
42797 tristate "Kernel support for a.out and ECOFF binaries"
42798 - depends on HAVE_AOUT
42799 + depends on HAVE_AOUT && BROKEN
42800 ---help---
42801 A.out (Assembler.OUTput) is a set of formats for libraries and
42802 executables used in the earliest versions of UNIX. Linux used
42803 diff --git a/fs/aio.c b/fs/aio.c
42804 index 71f613c..9d01f1f 100644
42805 --- a/fs/aio.c
42806 +++ b/fs/aio.c
42807 @@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
42808 size += sizeof(struct io_event) * nr_events;
42809 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
42810
42811 - if (nr_pages < 0)
42812 + if (nr_pages <= 0)
42813 return -EINVAL;
42814
42815 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
42816 @@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
42817 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42818 {
42819 ssize_t ret;
42820 + struct iovec iovstack;
42821
42822 #ifdef CONFIG_COMPAT
42823 if (compat)
42824 ret = compat_rw_copy_check_uvector(type,
42825 (struct compat_iovec __user *)kiocb->ki_buf,
42826 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42827 + kiocb->ki_nbytes, 1, &iovstack,
42828 &kiocb->ki_iovec);
42829 else
42830 #endif
42831 ret = rw_copy_check_uvector(type,
42832 (struct iovec __user *)kiocb->ki_buf,
42833 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42834 + kiocb->ki_nbytes, 1, &iovstack,
42835 &kiocb->ki_iovec);
42836 if (ret < 0)
42837 goto out;
42838 @@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42839 if (ret < 0)
42840 goto out;
42841
42842 + if (kiocb->ki_iovec == &iovstack) {
42843 + kiocb->ki_inline_vec = iovstack;
42844 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
42845 + }
42846 kiocb->ki_nr_segs = kiocb->ki_nbytes;
42847 kiocb->ki_cur_seg = 0;
42848 /* ki_nbytes/left now reflect bytes instead of segs */
42849 diff --git a/fs/attr.c b/fs/attr.c
42850 index 29e38a1..2bc037b 100644
42851 --- a/fs/attr.c
42852 +++ b/fs/attr.c
42853 @@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
42854 unsigned long limit;
42855
42856 limit = rlimit(RLIMIT_FSIZE);
42857 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
42858 if (limit != RLIM_INFINITY && offset > limit)
42859 goto out_sig;
42860 if (offset > inode->i_sb->s_maxbytes)
42861 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
42862 index da8876d..4456166 100644
42863 --- a/fs/autofs4/waitq.c
42864 +++ b/fs/autofs4/waitq.c
42865 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
42866 {
42867 unsigned long sigpipe, flags;
42868 mm_segment_t fs;
42869 - const char *data = (const char *)addr;
42870 + const char __user *data = (const char __force_user *)addr;
42871 ssize_t wr = 0;
42872
42873 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
42874 @@ -348,6 +348,10 @@ static int validate_request(struct autofs_wait_queue **wait,
42875 return 1;
42876 }
42877
42878 +#ifdef CONFIG_GRKERNSEC_HIDESYM
42879 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
42880 +#endif
42881 +
42882 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
42883 enum autofs_notify notify)
42884 {
42885 @@ -381,7 +385,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
42886
42887 /* If this is a direct mount request create a dummy name */
42888 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
42889 +#ifdef CONFIG_GRKERNSEC_HIDESYM
42890 + /* this name does get written to userland via autofs4_write() */
42891 + qstr.len = sprintf(name, "%08lx", atomic_inc_return_unchecked(&autofs_dummy_name_id));
42892 +#else
42893 qstr.len = sprintf(name, "%p", dentry);
42894 +#endif
42895 else {
42896 qstr.len = autofs4_getpath(sbi, dentry, &name);
42897 if (!qstr.len) {
42898 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
42899 index cf7f3c6..f61080d 100644
42900 --- a/fs/befs/linuxvfs.c
42901 +++ b/fs/befs/linuxvfs.c
42902 @@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42903 {
42904 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
42905 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
42906 - char *link = nd_get_link(nd);
42907 + const char *link = nd_get_link(nd);
42908 if (!IS_ERR(link))
42909 kfree(link);
42910 }
42911 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
42912 index d146e18..12d1bd1 100644
42913 --- a/fs/binfmt_aout.c
42914 +++ b/fs/binfmt_aout.c
42915 @@ -16,6 +16,7 @@
42916 #include <linux/string.h>
42917 #include <linux/fs.h>
42918 #include <linux/file.h>
42919 +#include <linux/security.h>
42920 #include <linux/stat.h>
42921 #include <linux/fcntl.h>
42922 #include <linux/ptrace.h>
42923 @@ -83,6 +84,8 @@ static int aout_core_dump(struct coredump_params *cprm)
42924 #endif
42925 # define START_STACK(u) ((void __user *)u.start_stack)
42926
42927 + memset(&dump, 0, sizeof(dump));
42928 +
42929 fs = get_fs();
42930 set_fs(KERNEL_DS);
42931 has_dumped = 1;
42932 @@ -94,10 +97,12 @@ static int aout_core_dump(struct coredump_params *cprm)
42933
42934 /* If the size of the dump file exceeds the rlimit, then see what would happen
42935 if we wrote the stack, but not the data area. */
42936 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
42937 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
42938 dump.u_dsize = 0;
42939
42940 /* Make sure we have enough room to write the stack and data areas. */
42941 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
42942 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
42943 dump.u_ssize = 0;
42944
42945 @@ -231,6 +236,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42946 rlim = rlimit(RLIMIT_DATA);
42947 if (rlim >= RLIM_INFINITY)
42948 rlim = ~0;
42949 +
42950 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
42951 if (ex.a_data + ex.a_bss > rlim)
42952 return -ENOMEM;
42953
42954 @@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42955
42956 install_exec_creds(bprm);
42957
42958 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42959 + current->mm->pax_flags = 0UL;
42960 +#endif
42961 +
42962 +#ifdef CONFIG_PAX_PAGEEXEC
42963 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
42964 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
42965 +
42966 +#ifdef CONFIG_PAX_EMUTRAMP
42967 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
42968 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
42969 +#endif
42970 +
42971 +#ifdef CONFIG_PAX_MPROTECT
42972 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
42973 + current->mm->pax_flags |= MF_PAX_MPROTECT;
42974 +#endif
42975 +
42976 + }
42977 +#endif
42978 +
42979 if (N_MAGIC(ex) == OMAGIC) {
42980 unsigned long text_addr, map_size;
42981 loff_t pos;
42982 @@ -330,7 +358,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42983 }
42984
42985 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
42986 - PROT_READ | PROT_WRITE | PROT_EXEC,
42987 + PROT_READ | PROT_WRITE,
42988 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
42989 fd_offset + ex.a_text);
42990 if (error != N_DATADDR(ex)) {
42991 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
42992 index 0225fdd..08bda99 100644
42993 --- a/fs/binfmt_elf.c
42994 +++ b/fs/binfmt_elf.c
42995 @@ -32,6 +32,7 @@
42996 #include <linux/elf.h>
42997 #include <linux/utsname.h>
42998 #include <linux/coredump.h>
42999 +#include <linux/xattr.h>
43000 #include <asm/uaccess.h>
43001 #include <asm/param.h>
43002 #include <asm/page.h>
43003 @@ -52,6 +53,10 @@ static int elf_core_dump(struct coredump_params *cprm);
43004 #define elf_core_dump NULL
43005 #endif
43006
43007 +#ifdef CONFIG_PAX_MPROTECT
43008 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
43009 +#endif
43010 +
43011 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
43012 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
43013 #else
43014 @@ -71,6 +76,11 @@ static struct linux_binfmt elf_format = {
43015 .load_binary = load_elf_binary,
43016 .load_shlib = load_elf_library,
43017 .core_dump = elf_core_dump,
43018 +
43019 +#ifdef CONFIG_PAX_MPROTECT
43020 + .handle_mprotect= elf_handle_mprotect,
43021 +#endif
43022 +
43023 .min_coredump = ELF_EXEC_PAGESIZE,
43024 };
43025
43026 @@ -78,6 +88,8 @@ static struct linux_binfmt elf_format = {
43027
43028 static int set_brk(unsigned long start, unsigned long end)
43029 {
43030 + unsigned long e = end;
43031 +
43032 start = ELF_PAGEALIGN(start);
43033 end = ELF_PAGEALIGN(end);
43034 if (end > start) {
43035 @@ -86,7 +98,7 @@ static int set_brk(unsigned long start, unsigned long end)
43036 if (BAD_ADDR(addr))
43037 return addr;
43038 }
43039 - current->mm->start_brk = current->mm->brk = end;
43040 + current->mm->start_brk = current->mm->brk = e;
43041 return 0;
43042 }
43043
43044 @@ -147,12 +159,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
43045 elf_addr_t __user *u_rand_bytes;
43046 const char *k_platform = ELF_PLATFORM;
43047 const char *k_base_platform = ELF_BASE_PLATFORM;
43048 - unsigned char k_rand_bytes[16];
43049 + u32 k_rand_bytes[4];
43050 int items;
43051 elf_addr_t *elf_info;
43052 int ei_index = 0;
43053 const struct cred *cred = current_cred();
43054 struct vm_area_struct *vma;
43055 + unsigned long saved_auxv[AT_VECTOR_SIZE];
43056
43057 /*
43058 * In some cases (e.g. Hyper-Threading), we want to avoid L1
43059 @@ -194,8 +207,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
43060 * Generate 16 random bytes for userspace PRNG seeding.
43061 */
43062 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
43063 - u_rand_bytes = (elf_addr_t __user *)
43064 - STACK_ALLOC(p, sizeof(k_rand_bytes));
43065 + srandom32(k_rand_bytes[0] ^ random32());
43066 + srandom32(k_rand_bytes[1] ^ random32());
43067 + srandom32(k_rand_bytes[2] ^ random32());
43068 + srandom32(k_rand_bytes[3] ^ random32());
43069 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
43070 + u_rand_bytes = (elf_addr_t __user *) p;
43071 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
43072 return -EFAULT;
43073
43074 @@ -307,9 +324,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
43075 return -EFAULT;
43076 current->mm->env_end = p;
43077
43078 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
43079 +
43080 /* Put the elf_info on the stack in the right place. */
43081 sp = (elf_addr_t __user *)envp + 1;
43082 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
43083 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
43084 return -EFAULT;
43085 return 0;
43086 }
43087 @@ -373,15 +392,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
43088 an ELF header */
43089
43090 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43091 - struct file *interpreter, unsigned long *interp_map_addr,
43092 - unsigned long no_base)
43093 + struct file *interpreter, unsigned long no_base)
43094 {
43095 struct elf_phdr *elf_phdata;
43096 struct elf_phdr *eppnt;
43097 - unsigned long load_addr = 0;
43098 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
43099 int load_addr_set = 0;
43100 unsigned long last_bss = 0, elf_bss = 0;
43101 - unsigned long error = ~0UL;
43102 + unsigned long error = -EINVAL;
43103 unsigned long total_size;
43104 int retval, i, size;
43105
43106 @@ -427,6 +445,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43107 goto out_close;
43108 }
43109
43110 +#ifdef CONFIG_PAX_SEGMEXEC
43111 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
43112 + pax_task_size = SEGMEXEC_TASK_SIZE;
43113 +#endif
43114 +
43115 eppnt = elf_phdata;
43116 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
43117 if (eppnt->p_type == PT_LOAD) {
43118 @@ -450,8 +473,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43119 map_addr = elf_map(interpreter, load_addr + vaddr,
43120 eppnt, elf_prot, elf_type, total_size);
43121 total_size = 0;
43122 - if (!*interp_map_addr)
43123 - *interp_map_addr = map_addr;
43124 error = map_addr;
43125 if (BAD_ADDR(map_addr))
43126 goto out_close;
43127 @@ -470,8 +491,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43128 k = load_addr + eppnt->p_vaddr;
43129 if (BAD_ADDR(k) ||
43130 eppnt->p_filesz > eppnt->p_memsz ||
43131 - eppnt->p_memsz > TASK_SIZE ||
43132 - TASK_SIZE - eppnt->p_memsz < k) {
43133 + eppnt->p_memsz > pax_task_size ||
43134 + pax_task_size - eppnt->p_memsz < k) {
43135 error = -ENOMEM;
43136 goto out_close;
43137 }
43138 @@ -523,6 +544,311 @@ out:
43139 return error;
43140 }
43141
43142 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
43143 +#ifdef CONFIG_PAX_SOFTMODE
43144 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
43145 +{
43146 + unsigned long pax_flags = 0UL;
43147 +
43148 +#ifdef CONFIG_PAX_PAGEEXEC
43149 + if (elf_phdata->p_flags & PF_PAGEEXEC)
43150 + pax_flags |= MF_PAX_PAGEEXEC;
43151 +#endif
43152 +
43153 +#ifdef CONFIG_PAX_SEGMEXEC
43154 + if (elf_phdata->p_flags & PF_SEGMEXEC)
43155 + pax_flags |= MF_PAX_SEGMEXEC;
43156 +#endif
43157 +
43158 +#ifdef CONFIG_PAX_EMUTRAMP
43159 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
43160 + pax_flags |= MF_PAX_EMUTRAMP;
43161 +#endif
43162 +
43163 +#ifdef CONFIG_PAX_MPROTECT
43164 + if (elf_phdata->p_flags & PF_MPROTECT)
43165 + pax_flags |= MF_PAX_MPROTECT;
43166 +#endif
43167 +
43168 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43169 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
43170 + pax_flags |= MF_PAX_RANDMMAP;
43171 +#endif
43172 +
43173 + return pax_flags;
43174 +}
43175 +#endif
43176 +
43177 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
43178 +{
43179 + unsigned long pax_flags = 0UL;
43180 +
43181 +#ifdef CONFIG_PAX_PAGEEXEC
43182 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
43183 + pax_flags |= MF_PAX_PAGEEXEC;
43184 +#endif
43185 +
43186 +#ifdef CONFIG_PAX_SEGMEXEC
43187 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
43188 + pax_flags |= MF_PAX_SEGMEXEC;
43189 +#endif
43190 +
43191 +#ifdef CONFIG_PAX_EMUTRAMP
43192 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
43193 + pax_flags |= MF_PAX_EMUTRAMP;
43194 +#endif
43195 +
43196 +#ifdef CONFIG_PAX_MPROTECT
43197 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
43198 + pax_flags |= MF_PAX_MPROTECT;
43199 +#endif
43200 +
43201 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43202 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
43203 + pax_flags |= MF_PAX_RANDMMAP;
43204 +#endif
43205 +
43206 + return pax_flags;
43207 +}
43208 +#endif
43209 +
43210 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43211 +#ifdef CONFIG_PAX_SOFTMODE
43212 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
43213 +{
43214 + unsigned long pax_flags = 0UL;
43215 +
43216 +#ifdef CONFIG_PAX_PAGEEXEC
43217 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
43218 + pax_flags |= MF_PAX_PAGEEXEC;
43219 +#endif
43220 +
43221 +#ifdef CONFIG_PAX_SEGMEXEC
43222 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
43223 + pax_flags |= MF_PAX_SEGMEXEC;
43224 +#endif
43225 +
43226 +#ifdef CONFIG_PAX_EMUTRAMP
43227 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
43228 + pax_flags |= MF_PAX_EMUTRAMP;
43229 +#endif
43230 +
43231 +#ifdef CONFIG_PAX_MPROTECT
43232 + if (pax_flags_softmode & MF_PAX_MPROTECT)
43233 + pax_flags |= MF_PAX_MPROTECT;
43234 +#endif
43235 +
43236 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43237 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
43238 + pax_flags |= MF_PAX_RANDMMAP;
43239 +#endif
43240 +
43241 + return pax_flags;
43242 +}
43243 +#endif
43244 +
43245 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
43246 +{
43247 + unsigned long pax_flags = 0UL;
43248 +
43249 +#ifdef CONFIG_PAX_PAGEEXEC
43250 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
43251 + pax_flags |= MF_PAX_PAGEEXEC;
43252 +#endif
43253 +
43254 +#ifdef CONFIG_PAX_SEGMEXEC
43255 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
43256 + pax_flags |= MF_PAX_SEGMEXEC;
43257 +#endif
43258 +
43259 +#ifdef CONFIG_PAX_EMUTRAMP
43260 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
43261 + pax_flags |= MF_PAX_EMUTRAMP;
43262 +#endif
43263 +
43264 +#ifdef CONFIG_PAX_MPROTECT
43265 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
43266 + pax_flags |= MF_PAX_MPROTECT;
43267 +#endif
43268 +
43269 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43270 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
43271 + pax_flags |= MF_PAX_RANDMMAP;
43272 +#endif
43273 +
43274 + return pax_flags;
43275 +}
43276 +#endif
43277 +
43278 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43279 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
43280 +{
43281 + unsigned long pax_flags = 0UL;
43282 +
43283 +#ifdef CONFIG_PAX_EI_PAX
43284 +
43285 +#ifdef CONFIG_PAX_PAGEEXEC
43286 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
43287 + pax_flags |= MF_PAX_PAGEEXEC;
43288 +#endif
43289 +
43290 +#ifdef CONFIG_PAX_SEGMEXEC
43291 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
43292 + pax_flags |= MF_PAX_SEGMEXEC;
43293 +#endif
43294 +
43295 +#ifdef CONFIG_PAX_EMUTRAMP
43296 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
43297 + pax_flags |= MF_PAX_EMUTRAMP;
43298 +#endif
43299 +
43300 +#ifdef CONFIG_PAX_MPROTECT
43301 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
43302 + pax_flags |= MF_PAX_MPROTECT;
43303 +#endif
43304 +
43305 +#ifdef CONFIG_PAX_ASLR
43306 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
43307 + pax_flags |= MF_PAX_RANDMMAP;
43308 +#endif
43309 +
43310 +#else
43311 +
43312 +#ifdef CONFIG_PAX_PAGEEXEC
43313 + pax_flags |= MF_PAX_PAGEEXEC;
43314 +#endif
43315 +
43316 +#ifdef CONFIG_PAX_SEGMEXEC
43317 + pax_flags |= MF_PAX_SEGMEXEC;
43318 +#endif
43319 +
43320 +#ifdef CONFIG_PAX_MPROTECT
43321 + pax_flags |= MF_PAX_MPROTECT;
43322 +#endif
43323 +
43324 +#ifdef CONFIG_PAX_RANDMMAP
43325 + if (randomize_va_space)
43326 + pax_flags |= MF_PAX_RANDMMAP;
43327 +#endif
43328 +
43329 +#endif
43330 +
43331 + return pax_flags;
43332 +}
43333 +
43334 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
43335 +{
43336 +
43337 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
43338 + unsigned long i;
43339 +
43340 + for (i = 0UL; i < elf_ex->e_phnum; i++)
43341 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
43342 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
43343 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
43344 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
43345 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
43346 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
43347 + return ~0UL;
43348 +
43349 +#ifdef CONFIG_PAX_SOFTMODE
43350 + if (pax_softmode)
43351 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
43352 + else
43353 +#endif
43354 +
43355 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
43356 + break;
43357 + }
43358 +#endif
43359 +
43360 + return ~0UL;
43361 +}
43362 +
43363 +static unsigned long pax_parse_xattr_pax(struct file * const file)
43364 +{
43365 +
43366 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43367 + ssize_t xattr_size, i;
43368 + unsigned char xattr_value[5];
43369 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
43370 +
43371 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
43372 + if (xattr_size <= 0)
43373 + return ~0UL;
43374 +
43375 + for (i = 0; i < xattr_size; i++)
43376 + switch (xattr_value[i]) {
43377 + default:
43378 + return ~0UL;
43379 +
43380 +#define parse_flag(option1, option2, flag) \
43381 + case option1: \
43382 + pax_flags_hardmode |= MF_PAX_##flag; \
43383 + break; \
43384 + case option2: \
43385 + pax_flags_softmode |= MF_PAX_##flag; \
43386 + break;
43387 +
43388 + parse_flag('p', 'P', PAGEEXEC);
43389 + parse_flag('e', 'E', EMUTRAMP);
43390 + parse_flag('m', 'M', MPROTECT);
43391 + parse_flag('r', 'R', RANDMMAP);
43392 + parse_flag('s', 'S', SEGMEXEC);
43393 +
43394 +#undef parse_flag
43395 + }
43396 +
43397 + if (pax_flags_hardmode & pax_flags_softmode)
43398 + return ~0UL;
43399 +
43400 +#ifdef CONFIG_PAX_SOFTMODE
43401 + if (pax_softmode)
43402 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
43403 + else
43404 +#endif
43405 +
43406 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
43407 +#else
43408 + return ~0UL;
43409 +#endif
43410 +
43411 +}
43412 +
43413 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
43414 +{
43415 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
43416 +
43417 + pax_flags = pax_parse_ei_pax(elf_ex);
43418 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
43419 + xattr_pax_flags = pax_parse_xattr_pax(file);
43420 +
43421 + if (pt_pax_flags == ~0UL)
43422 + pt_pax_flags = xattr_pax_flags;
43423 + else if (xattr_pax_flags == ~0UL)
43424 + xattr_pax_flags = pt_pax_flags;
43425 + if (pt_pax_flags != xattr_pax_flags)
43426 + return -EINVAL;
43427 + if (pt_pax_flags != ~0UL)
43428 + pax_flags = pt_pax_flags;
43429 +
43430 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
43431 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43432 + if ((__supported_pte_mask & _PAGE_NX))
43433 + pax_flags &= ~MF_PAX_SEGMEXEC;
43434 + else
43435 + pax_flags &= ~MF_PAX_PAGEEXEC;
43436 + }
43437 +#endif
43438 +
43439 + if (0 > pax_check_flags(&pax_flags))
43440 + return -EINVAL;
43441 +
43442 + current->mm->pax_flags = pax_flags;
43443 + return 0;
43444 +}
43445 +#endif
43446 +
43447 /*
43448 * These are the functions used to load ELF style executables and shared
43449 * libraries. There is no binary dependent code anywhere else.
43450 @@ -539,6 +865,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
43451 {
43452 unsigned int random_variable = 0;
43453
43454 +#ifdef CONFIG_PAX_RANDUSTACK
43455 + if (randomize_va_space)
43456 + return stack_top - current->mm->delta_stack;
43457 +#endif
43458 +
43459 if ((current->flags & PF_RANDOMIZE) &&
43460 !(current->personality & ADDR_NO_RANDOMIZE)) {
43461 random_variable = get_random_int() & STACK_RND_MASK;
43462 @@ -557,7 +888,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43463 unsigned long load_addr = 0, load_bias = 0;
43464 int load_addr_set = 0;
43465 char * elf_interpreter = NULL;
43466 - unsigned long error;
43467 + unsigned long error = 0;
43468 struct elf_phdr *elf_ppnt, *elf_phdata;
43469 unsigned long elf_bss, elf_brk;
43470 int retval, i;
43471 @@ -567,11 +898,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43472 unsigned long start_code, end_code, start_data, end_data;
43473 unsigned long reloc_func_desc __maybe_unused = 0;
43474 int executable_stack = EXSTACK_DEFAULT;
43475 - unsigned long def_flags = 0;
43476 struct {
43477 struct elfhdr elf_ex;
43478 struct elfhdr interp_elf_ex;
43479 } *loc;
43480 + unsigned long pax_task_size = TASK_SIZE;
43481
43482 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
43483 if (!loc) {
43484 @@ -707,11 +1038,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43485 goto out_free_dentry;
43486
43487 /* OK, This is the point of no return */
43488 - current->mm->def_flags = def_flags;
43489 +
43490 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43491 + current->mm->pax_flags = 0UL;
43492 +#endif
43493 +
43494 +#ifdef CONFIG_PAX_DLRESOLVE
43495 + current->mm->call_dl_resolve = 0UL;
43496 +#endif
43497 +
43498 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
43499 + current->mm->call_syscall = 0UL;
43500 +#endif
43501 +
43502 +#ifdef CONFIG_PAX_ASLR
43503 + current->mm->delta_mmap = 0UL;
43504 + current->mm->delta_stack = 0UL;
43505 +#endif
43506 +
43507 + current->mm->def_flags = 0;
43508 +
43509 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43510 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
43511 + send_sig(SIGKILL, current, 0);
43512 + goto out_free_dentry;
43513 + }
43514 +#endif
43515 +
43516 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
43517 + pax_set_initial_flags(bprm);
43518 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
43519 + if (pax_set_initial_flags_func)
43520 + (pax_set_initial_flags_func)(bprm);
43521 +#endif
43522 +
43523 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
43524 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
43525 + current->mm->context.user_cs_limit = PAGE_SIZE;
43526 + current->mm->def_flags |= VM_PAGEEXEC;
43527 + }
43528 +#endif
43529 +
43530 +#ifdef CONFIG_PAX_SEGMEXEC
43531 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
43532 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
43533 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
43534 + pax_task_size = SEGMEXEC_TASK_SIZE;
43535 + current->mm->def_flags |= VM_NOHUGEPAGE;
43536 + }
43537 +#endif
43538 +
43539 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
43540 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43541 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
43542 + put_cpu();
43543 + }
43544 +#endif
43545
43546 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
43547 may depend on the personality. */
43548 SET_PERSONALITY(loc->elf_ex);
43549 +
43550 +#ifdef CONFIG_PAX_ASLR
43551 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43552 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
43553 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
43554 + }
43555 +#endif
43556 +
43557 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43558 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43559 + executable_stack = EXSTACK_DISABLE_X;
43560 + current->personality &= ~READ_IMPLIES_EXEC;
43561 + } else
43562 +#endif
43563 +
43564 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
43565 current->personality |= READ_IMPLIES_EXEC;
43566
43567 @@ -802,6 +1203,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43568 #else
43569 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
43570 #endif
43571 +
43572 +#ifdef CONFIG_PAX_RANDMMAP
43573 + /* PaX: randomize base address at the default exe base if requested */
43574 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
43575 +#ifdef CONFIG_SPARC64
43576 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
43577 +#else
43578 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
43579 +#endif
43580 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
43581 + elf_flags |= MAP_FIXED;
43582 + }
43583 +#endif
43584 +
43585 }
43586
43587 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
43588 @@ -834,9 +1249,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43589 * allowed task size. Note that p_filesz must always be
43590 * <= p_memsz so it is only necessary to check p_memsz.
43591 */
43592 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43593 - elf_ppnt->p_memsz > TASK_SIZE ||
43594 - TASK_SIZE - elf_ppnt->p_memsz < k) {
43595 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43596 + elf_ppnt->p_memsz > pax_task_size ||
43597 + pax_task_size - elf_ppnt->p_memsz < k) {
43598 /* set_brk can never work. Avoid overflows. */
43599 send_sig(SIGKILL, current, 0);
43600 retval = -EINVAL;
43601 @@ -875,17 +1290,44 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43602 goto out_free_dentry;
43603 }
43604 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
43605 - send_sig(SIGSEGV, current, 0);
43606 - retval = -EFAULT; /* Nobody gets to see this, but.. */
43607 - goto out_free_dentry;
43608 + /*
43609 + * This bss-zeroing can fail if the ELF
43610 + * file specifies odd protections. So
43611 + * we don't check the return value
43612 + */
43613 }
43614
43615 +#ifdef CONFIG_PAX_RANDMMAP
43616 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43617 + unsigned long start, size;
43618 +
43619 + start = ELF_PAGEALIGN(elf_brk);
43620 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
43621 + down_read(&current->mm->mmap_sem);
43622 + retval = -ENOMEM;
43623 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
43624 + unsigned long prot = PROT_NONE;
43625 +
43626 + up_read(&current->mm->mmap_sem);
43627 + current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
43628 +// if (current->personality & ADDR_NO_RANDOMIZE)
43629 +// prot = PROT_READ;
43630 + start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
43631 + retval = IS_ERR_VALUE(start) ? start : 0;
43632 + } else
43633 + up_read(&current->mm->mmap_sem);
43634 + if (retval == 0)
43635 + retval = set_brk(start + size, start + size + PAGE_SIZE);
43636 + if (retval < 0) {
43637 + send_sig(SIGKILL, current, 0);
43638 + goto out_free_dentry;
43639 + }
43640 + }
43641 +#endif
43642 +
43643 if (elf_interpreter) {
43644 - unsigned long uninitialized_var(interp_map_addr);
43645 -
43646 elf_entry = load_elf_interp(&loc->interp_elf_ex,
43647 interpreter,
43648 - &interp_map_addr,
43649 load_bias);
43650 if (!IS_ERR((void *)elf_entry)) {
43651 /*
43652 @@ -1107,7 +1549,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
43653 * Decide what to dump of a segment, part, all or none.
43654 */
43655 static unsigned long vma_dump_size(struct vm_area_struct *vma,
43656 - unsigned long mm_flags)
43657 + unsigned long mm_flags, long signr)
43658 {
43659 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
43660
43661 @@ -1144,7 +1586,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
43662 if (vma->vm_file == NULL)
43663 return 0;
43664
43665 - if (FILTER(MAPPED_PRIVATE))
43666 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
43667 goto whole;
43668
43669 /*
43670 @@ -1366,9 +1808,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
43671 {
43672 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
43673 int i = 0;
43674 - do
43675 + do {
43676 i += 2;
43677 - while (auxv[i - 2] != AT_NULL);
43678 + } while (auxv[i - 2] != AT_NULL);
43679 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
43680 }
43681
43682 @@ -1879,14 +2321,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
43683 }
43684
43685 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
43686 - unsigned long mm_flags)
43687 + struct coredump_params *cprm)
43688 {
43689 struct vm_area_struct *vma;
43690 size_t size = 0;
43691
43692 for (vma = first_vma(current, gate_vma); vma != NULL;
43693 vma = next_vma(vma, gate_vma))
43694 - size += vma_dump_size(vma, mm_flags);
43695 + size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43696 return size;
43697 }
43698
43699 @@ -1980,7 +2422,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43700
43701 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
43702
43703 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
43704 + offset += elf_core_vma_data_size(gate_vma, cprm);
43705 offset += elf_core_extra_data_size();
43706 e_shoff = offset;
43707
43708 @@ -1994,10 +2436,12 @@ static int elf_core_dump(struct coredump_params *cprm)
43709 offset = dataoff;
43710
43711 size += sizeof(*elf);
43712 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43713 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
43714 goto end_coredump;
43715
43716 size += sizeof(*phdr4note);
43717 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43718 if (size > cprm->limit
43719 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
43720 goto end_coredump;
43721 @@ -2011,7 +2455,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43722 phdr.p_offset = offset;
43723 phdr.p_vaddr = vma->vm_start;
43724 phdr.p_paddr = 0;
43725 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
43726 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43727 phdr.p_memsz = vma->vm_end - vma->vm_start;
43728 offset += phdr.p_filesz;
43729 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
43730 @@ -2022,6 +2466,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43731 phdr.p_align = ELF_EXEC_PAGESIZE;
43732
43733 size += sizeof(phdr);
43734 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43735 if (size > cprm->limit
43736 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
43737 goto end_coredump;
43738 @@ -2046,7 +2491,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43739 unsigned long addr;
43740 unsigned long end;
43741
43742 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
43743 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43744
43745 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
43746 struct page *page;
43747 @@ -2055,6 +2500,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43748 page = get_dump_page(addr);
43749 if (page) {
43750 void *kaddr = kmap(page);
43751 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
43752 stop = ((size += PAGE_SIZE) > cprm->limit) ||
43753 !dump_write(cprm->file, kaddr,
43754 PAGE_SIZE);
43755 @@ -2072,6 +2518,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43756
43757 if (e_phnum == PN_XNUM) {
43758 size += sizeof(*shdr4extnum);
43759 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43760 if (size > cprm->limit
43761 || !dump_write(cprm->file, shdr4extnum,
43762 sizeof(*shdr4extnum)))
43763 @@ -2092,6 +2539,97 @@ out:
43764
43765 #endif /* CONFIG_ELF_CORE */
43766
43767 +#ifdef CONFIG_PAX_MPROTECT
43768 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
43769 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
43770 + * we'll remove VM_MAYWRITE for good on RELRO segments.
43771 + *
43772 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
43773 + * basis because we want to allow the common case and not the special ones.
43774 + */
43775 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
43776 +{
43777 + struct elfhdr elf_h;
43778 + struct elf_phdr elf_p;
43779 + unsigned long i;
43780 + unsigned long oldflags;
43781 + bool is_textrel_rw, is_textrel_rx, is_relro;
43782 +
43783 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
43784 + return;
43785 +
43786 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
43787 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
43788 +
43789 +#ifdef CONFIG_PAX_ELFRELOCS
43790 + /* possible TEXTREL */
43791 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
43792 + 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);
43793 +#else
43794 + is_textrel_rw = false;
43795 + is_textrel_rx = false;
43796 +#endif
43797 +
43798 + /* possible RELRO */
43799 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
43800 +
43801 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
43802 + return;
43803 +
43804 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
43805 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
43806 +
43807 +#ifdef CONFIG_PAX_ETEXECRELOCS
43808 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43809 +#else
43810 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
43811 +#endif
43812 +
43813 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43814 + !elf_check_arch(&elf_h) ||
43815 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
43816 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
43817 + return;
43818 +
43819 + for (i = 0UL; i < elf_h.e_phnum; i++) {
43820 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
43821 + return;
43822 + switch (elf_p.p_type) {
43823 + case PT_DYNAMIC:
43824 + if (!is_textrel_rw && !is_textrel_rx)
43825 + continue;
43826 + i = 0UL;
43827 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
43828 + elf_dyn dyn;
43829 +
43830 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
43831 + return;
43832 + if (dyn.d_tag == DT_NULL)
43833 + return;
43834 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
43835 + gr_log_textrel(vma);
43836 + if (is_textrel_rw)
43837 + vma->vm_flags |= VM_MAYWRITE;
43838 + else
43839 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
43840 + vma->vm_flags &= ~VM_MAYWRITE;
43841 + return;
43842 + }
43843 + i++;
43844 + }
43845 + return;
43846 +
43847 + case PT_GNU_RELRO:
43848 + if (!is_relro)
43849 + continue;
43850 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
43851 + vma->vm_flags &= ~VM_MAYWRITE;
43852 + return;
43853 + }
43854 + }
43855 +}
43856 +#endif
43857 +
43858 static int __init init_elf_binfmt(void)
43859 {
43860 register_binfmt(&elf_format);
43861 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
43862 index 178cb70..8972997 100644
43863 --- a/fs/binfmt_flat.c
43864 +++ b/fs/binfmt_flat.c
43865 @@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
43866 realdatastart = (unsigned long) -ENOMEM;
43867 printk("Unable to allocate RAM for process data, errno %d\n",
43868 (int)-realdatastart);
43869 + down_write(&current->mm->mmap_sem);
43870 vm_munmap(textpos, text_len);
43871 + up_write(&current->mm->mmap_sem);
43872 ret = realdatastart;
43873 goto err;
43874 }
43875 @@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43876 }
43877 if (IS_ERR_VALUE(result)) {
43878 printk("Unable to read data+bss, errno %d\n", (int)-result);
43879 + down_write(&current->mm->mmap_sem);
43880 vm_munmap(textpos, text_len);
43881 vm_munmap(realdatastart, len);
43882 + up_write(&current->mm->mmap_sem);
43883 ret = result;
43884 goto err;
43885 }
43886 @@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43887 }
43888 if (IS_ERR_VALUE(result)) {
43889 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
43890 + down_write(&current->mm->mmap_sem);
43891 vm_munmap(textpos, text_len + data_len + extra +
43892 MAX_SHARED_LIBS * sizeof(unsigned long));
43893 + up_write(&current->mm->mmap_sem);
43894 ret = result;
43895 goto err;
43896 }
43897 diff --git a/fs/bio.c b/fs/bio.c
43898 index 71072ab..439851b 100644
43899 --- a/fs/bio.c
43900 +++ b/fs/bio.c
43901 @@ -842,7 +842,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
43902 /*
43903 * Overflow, abort
43904 */
43905 - if (end < start)
43906 + if (end < start || end - start > INT_MAX - nr_pages)
43907 return ERR_PTR(-EINVAL);
43908
43909 nr_pages += end - start;
43910 @@ -976,7 +976,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
43911 /*
43912 * Overflow, abort
43913 */
43914 - if (end < start)
43915 + if (end < start || end - start > INT_MAX - nr_pages)
43916 return ERR_PTR(-EINVAL);
43917
43918 nr_pages += end - start;
43919 @@ -1238,7 +1238,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
43920 const int read = bio_data_dir(bio) == READ;
43921 struct bio_map_data *bmd = bio->bi_private;
43922 int i;
43923 - char *p = bmd->sgvecs[0].iov_base;
43924 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
43925
43926 __bio_for_each_segment(bvec, bio, i, 0) {
43927 char *addr = page_address(bvec->bv_page);
43928 diff --git a/fs/block_dev.c b/fs/block_dev.c
43929 index 38e721b..7a9c5bc 100644
43930 --- a/fs/block_dev.c
43931 +++ b/fs/block_dev.c
43932 @@ -704,7 +704,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
43933 else if (bdev->bd_contains == bdev)
43934 return true; /* is a whole device which isn't held */
43935
43936 - else if (whole->bd_holder == bd_may_claim)
43937 + else if (whole->bd_holder == (void *)bd_may_claim)
43938 return true; /* is a partition of a device that is being partitioned */
43939 else if (whole->bd_holder != NULL)
43940 return false; /* is a partition of a held device */
43941 diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
43942 index 9197e2e..7f731f8 100644
43943 --- a/fs/btrfs/check-integrity.c
43944 +++ b/fs/btrfs/check-integrity.c
43945 @@ -155,7 +155,7 @@ struct btrfsic_block {
43946 union {
43947 bio_end_io_t *bio;
43948 bh_end_io_t *bh;
43949 - } orig_bio_bh_end_io;
43950 + } __no_const orig_bio_bh_end_io;
43951 int submit_bio_bh_rw;
43952 u64 flush_gen; /* only valid if !never_written */
43953 };
43954 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
43955 index 6d183f6..f47cc7a 100644
43956 --- a/fs/btrfs/ctree.c
43957 +++ b/fs/btrfs/ctree.c
43958 @@ -1037,9 +1037,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
43959 free_extent_buffer(buf);
43960 add_root_to_dirty_list(root);
43961 } else {
43962 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
43963 - parent_start = parent->start;
43964 - else
43965 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
43966 + if (parent)
43967 + parent_start = parent->start;
43968 + else
43969 + parent_start = 0;
43970 + } else
43971 parent_start = 0;
43972
43973 WARN_ON(trans->transid != btrfs_header_generation(parent));
43974 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
43975 index ec154f9..bf617a7 100644
43976 --- a/fs/btrfs/inode.c
43977 +++ b/fs/btrfs/inode.c
43978 @@ -7126,7 +7126,7 @@ fail:
43979 return -ENOMEM;
43980 }
43981
43982 -static int btrfs_getattr(struct vfsmount *mnt,
43983 +int btrfs_getattr(struct vfsmount *mnt,
43984 struct dentry *dentry, struct kstat *stat)
43985 {
43986 struct inode *inode = dentry->d_inode;
43987 @@ -7140,6 +7140,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
43988 return 0;
43989 }
43990
43991 +EXPORT_SYMBOL(btrfs_getattr);
43992 +
43993 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
43994 +{
43995 + return BTRFS_I(inode)->root->anon_dev;
43996 +}
43997 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
43998 +
43999 /*
44000 * If a file is moved, it will inherit the cow and compression flags of the new
44001 * directory.
44002 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
44003 index 9df50fa..6cd20d0 100644
44004 --- a/fs/btrfs/ioctl.c
44005 +++ b/fs/btrfs/ioctl.c
44006 @@ -2942,9 +2942,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
44007 for (i = 0; i < num_types; i++) {
44008 struct btrfs_space_info *tmp;
44009
44010 + /* Don't copy in more than we allocated */
44011 if (!slot_count)
44012 break;
44013
44014 + slot_count--;
44015 +
44016 info = NULL;
44017 rcu_read_lock();
44018 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
44019 @@ -2966,10 +2969,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
44020 memcpy(dest, &space, sizeof(space));
44021 dest++;
44022 space_args.total_spaces++;
44023 - slot_count--;
44024 }
44025 - if (!slot_count)
44026 - break;
44027 }
44028 up_read(&info->groups_sem);
44029 }
44030 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
44031 index 4da0865..01c4778 100644
44032 --- a/fs/btrfs/relocation.c
44033 +++ b/fs/btrfs/relocation.c
44034 @@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
44035 }
44036 spin_unlock(&rc->reloc_root_tree.lock);
44037
44038 - BUG_ON((struct btrfs_root *)node->data != root);
44039 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
44040
44041 if (!del) {
44042 spin_lock(&rc->reloc_root_tree.lock);
44043 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
44044 index 622f469..e8d2d55 100644
44045 --- a/fs/cachefiles/bind.c
44046 +++ b/fs/cachefiles/bind.c
44047 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
44048 args);
44049
44050 /* start by checking things over */
44051 - ASSERT(cache->fstop_percent >= 0 &&
44052 - cache->fstop_percent < cache->fcull_percent &&
44053 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
44054 cache->fcull_percent < cache->frun_percent &&
44055 cache->frun_percent < 100);
44056
44057 - ASSERT(cache->bstop_percent >= 0 &&
44058 - cache->bstop_percent < cache->bcull_percent &&
44059 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
44060 cache->bcull_percent < cache->brun_percent &&
44061 cache->brun_percent < 100);
44062
44063 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
44064 index 0a1467b..6a53245 100644
44065 --- a/fs/cachefiles/daemon.c
44066 +++ b/fs/cachefiles/daemon.c
44067 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
44068 if (n > buflen)
44069 return -EMSGSIZE;
44070
44071 - if (copy_to_user(_buffer, buffer, n) != 0)
44072 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
44073 return -EFAULT;
44074
44075 return n;
44076 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
44077 if (test_bit(CACHEFILES_DEAD, &cache->flags))
44078 return -EIO;
44079
44080 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
44081 + if (datalen > PAGE_SIZE - 1)
44082 return -EOPNOTSUPP;
44083
44084 /* drag the command string into the kernel so we can parse it */
44085 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
44086 if (args[0] != '%' || args[1] != '\0')
44087 return -EINVAL;
44088
44089 - if (fstop < 0 || fstop >= cache->fcull_percent)
44090 + if (fstop >= cache->fcull_percent)
44091 return cachefiles_daemon_range_error(cache, args);
44092
44093 cache->fstop_percent = fstop;
44094 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
44095 if (args[0] != '%' || args[1] != '\0')
44096 return -EINVAL;
44097
44098 - if (bstop < 0 || bstop >= cache->bcull_percent)
44099 + if (bstop >= cache->bcull_percent)
44100 return cachefiles_daemon_range_error(cache, args);
44101
44102 cache->bstop_percent = bstop;
44103 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
44104 index bd6bc1b..b627b53 100644
44105 --- a/fs/cachefiles/internal.h
44106 +++ b/fs/cachefiles/internal.h
44107 @@ -57,7 +57,7 @@ struct cachefiles_cache {
44108 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
44109 struct rb_root active_nodes; /* active nodes (can't be culled) */
44110 rwlock_t active_lock; /* lock for active_nodes */
44111 - atomic_t gravecounter; /* graveyard uniquifier */
44112 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
44113 unsigned frun_percent; /* when to stop culling (% files) */
44114 unsigned fcull_percent; /* when to start culling (% files) */
44115 unsigned fstop_percent; /* when to stop allocating (% files) */
44116 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
44117 * proc.c
44118 */
44119 #ifdef CONFIG_CACHEFILES_HISTOGRAM
44120 -extern atomic_t cachefiles_lookup_histogram[HZ];
44121 -extern atomic_t cachefiles_mkdir_histogram[HZ];
44122 -extern atomic_t cachefiles_create_histogram[HZ];
44123 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
44124 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
44125 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
44126
44127 extern int __init cachefiles_proc_init(void);
44128 extern void cachefiles_proc_cleanup(void);
44129 static inline
44130 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
44131 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
44132 {
44133 unsigned long jif = jiffies - start_jif;
44134 if (jif >= HZ)
44135 jif = HZ - 1;
44136 - atomic_inc(&histogram[jif]);
44137 + atomic_inc_unchecked(&histogram[jif]);
44138 }
44139
44140 #else
44141 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
44142 index b0b5f7c..039bb26 100644
44143 --- a/fs/cachefiles/namei.c
44144 +++ b/fs/cachefiles/namei.c
44145 @@ -318,7 +318,7 @@ try_again:
44146 /* first step is to make up a grave dentry in the graveyard */
44147 sprintf(nbuffer, "%08x%08x",
44148 (uint32_t) get_seconds(),
44149 - (uint32_t) atomic_inc_return(&cache->gravecounter));
44150 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
44151
44152 /* do the multiway lock magic */
44153 trap = lock_rename(cache->graveyard, dir);
44154 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
44155 index eccd339..4c1d995 100644
44156 --- a/fs/cachefiles/proc.c
44157 +++ b/fs/cachefiles/proc.c
44158 @@ -14,9 +14,9 @@
44159 #include <linux/seq_file.h>
44160 #include "internal.h"
44161
44162 -atomic_t cachefiles_lookup_histogram[HZ];
44163 -atomic_t cachefiles_mkdir_histogram[HZ];
44164 -atomic_t cachefiles_create_histogram[HZ];
44165 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
44166 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
44167 +atomic_unchecked_t cachefiles_create_histogram[HZ];
44168
44169 /*
44170 * display the latency histogram
44171 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
44172 return 0;
44173 default:
44174 index = (unsigned long) v - 3;
44175 - x = atomic_read(&cachefiles_lookup_histogram[index]);
44176 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
44177 - z = atomic_read(&cachefiles_create_histogram[index]);
44178 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
44179 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
44180 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
44181 if (x == 0 && y == 0 && z == 0)
44182 return 0;
44183
44184 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
44185 index c994691..2a1537f 100644
44186 --- a/fs/cachefiles/rdwr.c
44187 +++ b/fs/cachefiles/rdwr.c
44188 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
44189 old_fs = get_fs();
44190 set_fs(KERNEL_DS);
44191 ret = file->f_op->write(
44192 - file, (const void __user *) data, len, &pos);
44193 + file, (const void __force_user *) data, len, &pos);
44194 set_fs(old_fs);
44195 kunmap(page);
44196 if (ret != len)
44197 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
44198 index e5b7731..b9c59fb 100644
44199 --- a/fs/ceph/dir.c
44200 +++ b/fs/ceph/dir.c
44201 @@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
44202 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
44203 struct ceph_mds_client *mdsc = fsc->mdsc;
44204 unsigned frag = fpos_frag(filp->f_pos);
44205 - int off = fpos_off(filp->f_pos);
44206 + unsigned int off = fpos_off(filp->f_pos);
44207 int err;
44208 u32 ftype;
44209 struct ceph_mds_reply_info_parsed *rinfo;
44210 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
44211 index d9ea6ed..1e6c8ac 100644
44212 --- a/fs/cifs/cifs_debug.c
44213 +++ b/fs/cifs/cifs_debug.c
44214 @@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44215
44216 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
44217 #ifdef CONFIG_CIFS_STATS2
44218 - atomic_set(&totBufAllocCount, 0);
44219 - atomic_set(&totSmBufAllocCount, 0);
44220 + atomic_set_unchecked(&totBufAllocCount, 0);
44221 + atomic_set_unchecked(&totSmBufAllocCount, 0);
44222 #endif /* CONFIG_CIFS_STATS2 */
44223 spin_lock(&cifs_tcp_ses_lock);
44224 list_for_each(tmp1, &cifs_tcp_ses_list) {
44225 @@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44226 tcon = list_entry(tmp3,
44227 struct cifs_tcon,
44228 tcon_list);
44229 - atomic_set(&tcon->num_smbs_sent, 0);
44230 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
44231 if (server->ops->clear_stats)
44232 server->ops->clear_stats(tcon);
44233 }
44234 @@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44235 smBufAllocCount.counter, cifs_min_small);
44236 #ifdef CONFIG_CIFS_STATS2
44237 seq_printf(m, "Total Large %d Small %d Allocations\n",
44238 - atomic_read(&totBufAllocCount),
44239 - atomic_read(&totSmBufAllocCount));
44240 + atomic_read_unchecked(&totBufAllocCount),
44241 + atomic_read_unchecked(&totSmBufAllocCount));
44242 #endif /* CONFIG_CIFS_STATS2 */
44243
44244 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
44245 @@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44246 if (tcon->need_reconnect)
44247 seq_puts(m, "\tDISCONNECTED ");
44248 seq_printf(m, "\nSMBs: %d",
44249 - atomic_read(&tcon->num_smbs_sent));
44250 + atomic_read_unchecked(&tcon->num_smbs_sent));
44251 if (server->ops->print_stats)
44252 server->ops->print_stats(m, tcon);
44253 }
44254 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
44255 index db8a404..c712e2e 100644
44256 --- a/fs/cifs/cifsfs.c
44257 +++ b/fs/cifs/cifsfs.c
44258 @@ -1003,7 +1003,7 @@ cifs_init_request_bufs(void)
44259 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
44260 cifs_req_cachep = kmem_cache_create("cifs_request",
44261 CIFSMaxBufSize + max_hdr_size, 0,
44262 - SLAB_HWCACHE_ALIGN, NULL);
44263 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
44264 if (cifs_req_cachep == NULL)
44265 return -ENOMEM;
44266
44267 @@ -1030,7 +1030,7 @@ cifs_init_request_bufs(void)
44268 efficient to alloc 1 per page off the slab compared to 17K (5page)
44269 alloc of large cifs buffers even when page debugging is on */
44270 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
44271 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
44272 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
44273 NULL);
44274 if (cifs_sm_req_cachep == NULL) {
44275 mempool_destroy(cifs_req_poolp);
44276 @@ -1115,8 +1115,8 @@ init_cifs(void)
44277 atomic_set(&bufAllocCount, 0);
44278 atomic_set(&smBufAllocCount, 0);
44279 #ifdef CONFIG_CIFS_STATS2
44280 - atomic_set(&totBufAllocCount, 0);
44281 - atomic_set(&totSmBufAllocCount, 0);
44282 + atomic_set_unchecked(&totBufAllocCount, 0);
44283 + atomic_set_unchecked(&totSmBufAllocCount, 0);
44284 #endif /* CONFIG_CIFS_STATS2 */
44285
44286 atomic_set(&midCount, 0);
44287 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
44288 index 977dc0e..ba48ab9 100644
44289 --- a/fs/cifs/cifsglob.h
44290 +++ b/fs/cifs/cifsglob.h
44291 @@ -590,35 +590,35 @@ struct cifs_tcon {
44292 __u16 Flags; /* optional support bits */
44293 enum statusEnum tidStatus;
44294 #ifdef CONFIG_CIFS_STATS
44295 - atomic_t num_smbs_sent;
44296 + atomic_unchecked_t num_smbs_sent;
44297 union {
44298 struct {
44299 - atomic_t num_writes;
44300 - atomic_t num_reads;
44301 - atomic_t num_flushes;
44302 - atomic_t num_oplock_brks;
44303 - atomic_t num_opens;
44304 - atomic_t num_closes;
44305 - atomic_t num_deletes;
44306 - atomic_t num_mkdirs;
44307 - atomic_t num_posixopens;
44308 - atomic_t num_posixmkdirs;
44309 - atomic_t num_rmdirs;
44310 - atomic_t num_renames;
44311 - atomic_t num_t2renames;
44312 - atomic_t num_ffirst;
44313 - atomic_t num_fnext;
44314 - atomic_t num_fclose;
44315 - atomic_t num_hardlinks;
44316 - atomic_t num_symlinks;
44317 - atomic_t num_locks;
44318 - atomic_t num_acl_get;
44319 - atomic_t num_acl_set;
44320 + atomic_unchecked_t num_writes;
44321 + atomic_unchecked_t num_reads;
44322 + atomic_unchecked_t num_flushes;
44323 + atomic_unchecked_t num_oplock_brks;
44324 + atomic_unchecked_t num_opens;
44325 + atomic_unchecked_t num_closes;
44326 + atomic_unchecked_t num_deletes;
44327 + atomic_unchecked_t num_mkdirs;
44328 + atomic_unchecked_t num_posixopens;
44329 + atomic_unchecked_t num_posixmkdirs;
44330 + atomic_unchecked_t num_rmdirs;
44331 + atomic_unchecked_t num_renames;
44332 + atomic_unchecked_t num_t2renames;
44333 + atomic_unchecked_t num_ffirst;
44334 + atomic_unchecked_t num_fnext;
44335 + atomic_unchecked_t num_fclose;
44336 + atomic_unchecked_t num_hardlinks;
44337 + atomic_unchecked_t num_symlinks;
44338 + atomic_unchecked_t num_locks;
44339 + atomic_unchecked_t num_acl_get;
44340 + atomic_unchecked_t num_acl_set;
44341 } cifs_stats;
44342 #ifdef CONFIG_CIFS_SMB2
44343 struct {
44344 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
44345 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
44346 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
44347 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
44348 } smb2_stats;
44349 #endif /* CONFIG_CIFS_SMB2 */
44350 } stats;
44351 @@ -862,7 +862,7 @@ build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
44352 }
44353
44354 #ifdef CONFIG_CIFS_STATS
44355 -#define cifs_stats_inc atomic_inc
44356 +#define cifs_stats_inc atomic_inc_unchecked
44357
44358 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
44359 unsigned int bytes)
44360 @@ -1227,8 +1227,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
44361 /* Various Debug counters */
44362 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
44363 #ifdef CONFIG_CIFS_STATS2
44364 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
44365 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
44366 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
44367 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
44368 #endif
44369 GLOBAL_EXTERN atomic_t smBufAllocCount;
44370 GLOBAL_EXTERN atomic_t midCount;
44371 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
44372 index e6ce3b1..adc21fd 100644
44373 --- a/fs/cifs/link.c
44374 +++ b/fs/cifs/link.c
44375 @@ -602,7 +602,7 @@ symlink_exit:
44376
44377 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
44378 {
44379 - char *p = nd_get_link(nd);
44380 + const char *p = nd_get_link(nd);
44381 if (!IS_ERR(p))
44382 kfree(p);
44383 }
44384 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
44385 index ce41fee..ac0d27a 100644
44386 --- a/fs/cifs/misc.c
44387 +++ b/fs/cifs/misc.c
44388 @@ -169,7 +169,7 @@ cifs_buf_get(void)
44389 memset(ret_buf, 0, buf_size + 3);
44390 atomic_inc(&bufAllocCount);
44391 #ifdef CONFIG_CIFS_STATS2
44392 - atomic_inc(&totBufAllocCount);
44393 + atomic_inc_unchecked(&totBufAllocCount);
44394 #endif /* CONFIG_CIFS_STATS2 */
44395 }
44396
44397 @@ -204,7 +204,7 @@ cifs_small_buf_get(void)
44398 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
44399 atomic_inc(&smBufAllocCount);
44400 #ifdef CONFIG_CIFS_STATS2
44401 - atomic_inc(&totSmBufAllocCount);
44402 + atomic_inc_unchecked(&totSmBufAllocCount);
44403 #endif /* CONFIG_CIFS_STATS2 */
44404
44405 }
44406 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
44407 index 3129ac7..cc4a948 100644
44408 --- a/fs/cifs/smb1ops.c
44409 +++ b/fs/cifs/smb1ops.c
44410 @@ -524,27 +524,27 @@ static void
44411 cifs_clear_stats(struct cifs_tcon *tcon)
44412 {
44413 #ifdef CONFIG_CIFS_STATS
44414 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
44415 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
44416 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
44417 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
44418 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
44419 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
44420 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
44421 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
44422 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
44423 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
44424 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
44425 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
44426 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
44427 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
44428 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
44429 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
44430 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
44431 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
44432 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
44433 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
44434 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
44435 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
44436 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
44437 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
44438 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
44439 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
44440 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
44441 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
44442 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
44443 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
44444 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
44445 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
44446 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
44447 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
44448 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
44449 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
44450 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
44451 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
44452 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
44453 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
44454 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
44455 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
44456 #endif
44457 }
44458
44459 @@ -553,36 +553,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
44460 {
44461 #ifdef CONFIG_CIFS_STATS
44462 seq_printf(m, " Oplocks breaks: %d",
44463 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
44464 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
44465 seq_printf(m, "\nReads: %d Bytes: %llu",
44466 - atomic_read(&tcon->stats.cifs_stats.num_reads),
44467 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
44468 (long long)(tcon->bytes_read));
44469 seq_printf(m, "\nWrites: %d Bytes: %llu",
44470 - atomic_read(&tcon->stats.cifs_stats.num_writes),
44471 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
44472 (long long)(tcon->bytes_written));
44473 seq_printf(m, "\nFlushes: %d",
44474 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
44475 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
44476 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
44477 - atomic_read(&tcon->stats.cifs_stats.num_locks),
44478 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
44479 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
44480 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
44481 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
44482 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
44483 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
44484 - atomic_read(&tcon->stats.cifs_stats.num_opens),
44485 - atomic_read(&tcon->stats.cifs_stats.num_closes),
44486 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
44487 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
44488 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
44489 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
44490 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
44491 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
44492 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
44493 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
44494 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
44495 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
44496 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
44497 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
44498 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
44499 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
44500 seq_printf(m, "\nRenames: %d T2 Renames %d",
44501 - atomic_read(&tcon->stats.cifs_stats.num_renames),
44502 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
44503 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
44504 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
44505 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
44506 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
44507 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
44508 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
44509 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
44510 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
44511 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
44512 #endif
44513 }
44514
44515 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
44516 index 826209b..fa460f4 100644
44517 --- a/fs/cifs/smb2ops.c
44518 +++ b/fs/cifs/smb2ops.c
44519 @@ -219,8 +219,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
44520 #ifdef CONFIG_CIFS_STATS
44521 int i;
44522 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
44523 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
44524 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
44525 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
44526 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
44527 }
44528 #endif
44529 }
44530 @@ -229,66 +229,66 @@ static void
44531 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
44532 {
44533 #ifdef CONFIG_CIFS_STATS
44534 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
44535 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
44536 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
44537 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
44538 seq_printf(m, "\nNegotiates: %d sent %d failed",
44539 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
44540 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
44541 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
44542 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
44543 seq_printf(m, "\nSessionSetups: %d sent %d failed",
44544 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
44545 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
44546 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
44547 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
44548 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
44549 seq_printf(m, "\nLogoffs: %d sent %d failed",
44550 - atomic_read(&sent[SMB2_LOGOFF_HE]),
44551 - atomic_read(&failed[SMB2_LOGOFF_HE]));
44552 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
44553 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
44554 seq_printf(m, "\nTreeConnects: %d sent %d failed",
44555 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
44556 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
44557 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
44558 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
44559 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
44560 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
44561 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
44562 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
44563 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
44564 seq_printf(m, "\nCreates: %d sent %d failed",
44565 - atomic_read(&sent[SMB2_CREATE_HE]),
44566 - atomic_read(&failed[SMB2_CREATE_HE]));
44567 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
44568 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
44569 seq_printf(m, "\nCloses: %d sent %d failed",
44570 - atomic_read(&sent[SMB2_CLOSE_HE]),
44571 - atomic_read(&failed[SMB2_CLOSE_HE]));
44572 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
44573 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
44574 seq_printf(m, "\nFlushes: %d sent %d failed",
44575 - atomic_read(&sent[SMB2_FLUSH_HE]),
44576 - atomic_read(&failed[SMB2_FLUSH_HE]));
44577 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
44578 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
44579 seq_printf(m, "\nReads: %d sent %d failed",
44580 - atomic_read(&sent[SMB2_READ_HE]),
44581 - atomic_read(&failed[SMB2_READ_HE]));
44582 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
44583 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
44584 seq_printf(m, "\nWrites: %d sent %d failed",
44585 - atomic_read(&sent[SMB2_WRITE_HE]),
44586 - atomic_read(&failed[SMB2_WRITE_HE]));
44587 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
44588 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
44589 seq_printf(m, "\nLocks: %d sent %d failed",
44590 - atomic_read(&sent[SMB2_LOCK_HE]),
44591 - atomic_read(&failed[SMB2_LOCK_HE]));
44592 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
44593 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
44594 seq_printf(m, "\nIOCTLs: %d sent %d failed",
44595 - atomic_read(&sent[SMB2_IOCTL_HE]),
44596 - atomic_read(&failed[SMB2_IOCTL_HE]));
44597 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
44598 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
44599 seq_printf(m, "\nCancels: %d sent %d failed",
44600 - atomic_read(&sent[SMB2_CANCEL_HE]),
44601 - atomic_read(&failed[SMB2_CANCEL_HE]));
44602 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
44603 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
44604 seq_printf(m, "\nEchos: %d sent %d failed",
44605 - atomic_read(&sent[SMB2_ECHO_HE]),
44606 - atomic_read(&failed[SMB2_ECHO_HE]));
44607 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
44608 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
44609 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
44610 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
44611 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
44612 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
44613 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
44614 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
44615 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
44616 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
44617 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
44618 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
44619 seq_printf(m, "\nQueryInfos: %d sent %d failed",
44620 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
44621 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
44622 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
44623 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
44624 seq_printf(m, "\nSetInfos: %d sent %d failed",
44625 - atomic_read(&sent[SMB2_SET_INFO_HE]),
44626 - atomic_read(&failed[SMB2_SET_INFO_HE]));
44627 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
44628 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
44629 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
44630 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
44631 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
44632 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
44633 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
44634 #endif
44635 }
44636
44637 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
44638 index 958ae0e..505c9d0 100644
44639 --- a/fs/coda/cache.c
44640 +++ b/fs/coda/cache.c
44641 @@ -24,7 +24,7 @@
44642 #include "coda_linux.h"
44643 #include "coda_cache.h"
44644
44645 -static atomic_t permission_epoch = ATOMIC_INIT(0);
44646 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
44647
44648 /* replace or extend an acl cache hit */
44649 void coda_cache_enter(struct inode *inode, int mask)
44650 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
44651 struct coda_inode_info *cii = ITOC(inode);
44652
44653 spin_lock(&cii->c_lock);
44654 - cii->c_cached_epoch = atomic_read(&permission_epoch);
44655 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
44656 if (cii->c_uid != current_fsuid()) {
44657 cii->c_uid = current_fsuid();
44658 cii->c_cached_perm = mask;
44659 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
44660 {
44661 struct coda_inode_info *cii = ITOC(inode);
44662 spin_lock(&cii->c_lock);
44663 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
44664 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
44665 spin_unlock(&cii->c_lock);
44666 }
44667
44668 /* remove all acl caches */
44669 void coda_cache_clear_all(struct super_block *sb)
44670 {
44671 - atomic_inc(&permission_epoch);
44672 + atomic_inc_unchecked(&permission_epoch);
44673 }
44674
44675
44676 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
44677 spin_lock(&cii->c_lock);
44678 hit = (mask & cii->c_cached_perm) == mask &&
44679 cii->c_uid == current_fsuid() &&
44680 - cii->c_cached_epoch == atomic_read(&permission_epoch);
44681 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
44682 spin_unlock(&cii->c_lock);
44683
44684 return hit;
44685 diff --git a/fs/compat.c b/fs/compat.c
44686 index 1bdb350..9f28287 100644
44687 --- a/fs/compat.c
44688 +++ b/fs/compat.c
44689 @@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
44690
44691 set_fs(KERNEL_DS);
44692 /* The __user pointer cast is valid because of the set_fs() */
44693 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
44694 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
44695 set_fs(oldfs);
44696 /* truncating is ok because it's a user address */
44697 if (!ret)
44698 @@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
44699 goto out;
44700
44701 ret = -EINVAL;
44702 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
44703 + if (nr_segs > UIO_MAXIOV)
44704 goto out;
44705 if (nr_segs > fast_segs) {
44706 ret = -ENOMEM;
44707 @@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
44708
44709 struct compat_readdir_callback {
44710 struct compat_old_linux_dirent __user *dirent;
44711 + struct file * file;
44712 int result;
44713 };
44714
44715 @@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
44716 buf->result = -EOVERFLOW;
44717 return -EOVERFLOW;
44718 }
44719 +
44720 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44721 + return 0;
44722 +
44723 buf->result++;
44724 dirent = buf->dirent;
44725 if (!access_ok(VERIFY_WRITE, dirent,
44726 @@ -880,6 +885,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
44727
44728 buf.result = 0;
44729 buf.dirent = dirent;
44730 + buf.file = file;
44731
44732 error = vfs_readdir(file, compat_fillonedir, &buf);
44733 if (buf.result)
44734 @@ -899,6 +905,7 @@ struct compat_linux_dirent {
44735 struct compat_getdents_callback {
44736 struct compat_linux_dirent __user *current_dir;
44737 struct compat_linux_dirent __user *previous;
44738 + struct file * file;
44739 int count;
44740 int error;
44741 };
44742 @@ -920,6 +927,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
44743 buf->error = -EOVERFLOW;
44744 return -EOVERFLOW;
44745 }
44746 +
44747 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44748 + return 0;
44749 +
44750 dirent = buf->previous;
44751 if (dirent) {
44752 if (__put_user(offset, &dirent->d_off))
44753 @@ -966,6 +977,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44754 buf.previous = NULL;
44755 buf.count = count;
44756 buf.error = 0;
44757 + buf.file = file;
44758
44759 error = vfs_readdir(file, compat_filldir, &buf);
44760 if (error >= 0)
44761 @@ -986,6 +998,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44762 struct compat_getdents_callback64 {
44763 struct linux_dirent64 __user *current_dir;
44764 struct linux_dirent64 __user *previous;
44765 + struct file * file;
44766 int count;
44767 int error;
44768 };
44769 @@ -1002,6 +1015,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
44770 buf->error = -EINVAL; /* only used if we fail.. */
44771 if (reclen > buf->count)
44772 return -EINVAL;
44773 +
44774 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44775 + return 0;
44776 +
44777 dirent = buf->previous;
44778
44779 if (dirent) {
44780 @@ -1052,13 +1069,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
44781 buf.previous = NULL;
44782 buf.count = count;
44783 buf.error = 0;
44784 + buf.file = file;
44785
44786 error = vfs_readdir(file, compat_filldir64, &buf);
44787 if (error >= 0)
44788 error = buf.error;
44789 lastdirent = buf.previous;
44790 if (lastdirent) {
44791 - typeof(lastdirent->d_off) d_off = file->f_pos;
44792 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
44793 if (__put_user_unaligned(d_off, &lastdirent->d_off))
44794 error = -EFAULT;
44795 else
44796 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
44797 index 112e45a..b59845b 100644
44798 --- a/fs/compat_binfmt_elf.c
44799 +++ b/fs/compat_binfmt_elf.c
44800 @@ -30,11 +30,13 @@
44801 #undef elf_phdr
44802 #undef elf_shdr
44803 #undef elf_note
44804 +#undef elf_dyn
44805 #undef elf_addr_t
44806 #define elfhdr elf32_hdr
44807 #define elf_phdr elf32_phdr
44808 #define elf_shdr elf32_shdr
44809 #define elf_note elf32_note
44810 +#define elf_dyn Elf32_Dyn
44811 #define elf_addr_t Elf32_Addr
44812
44813 /*
44814 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
44815 index 5d2069f..75d31d4 100644
44816 --- a/fs/compat_ioctl.c
44817 +++ b/fs/compat_ioctl.c
44818 @@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
44819 return -EFAULT;
44820 if (__get_user(udata, &ss32->iomem_base))
44821 return -EFAULT;
44822 - ss.iomem_base = compat_ptr(udata);
44823 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
44824 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
44825 __get_user(ss.port_high, &ss32->port_high))
44826 return -EFAULT;
44827 @@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
44828 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
44829 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
44830 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
44831 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44832 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44833 return -EFAULT;
44834
44835 return ioctl_preallocate(file, p);
44836 @@ -1612,8 +1612,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
44837 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
44838 {
44839 unsigned int a, b;
44840 - a = *(unsigned int *)p;
44841 - b = *(unsigned int *)q;
44842 + a = *(const unsigned int *)p;
44843 + b = *(const unsigned int *)q;
44844 if (a > b)
44845 return 1;
44846 if (a < b)
44847 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
44848 index 7414ae2..d98ad6d 100644
44849 --- a/fs/configfs/dir.c
44850 +++ b/fs/configfs/dir.c
44851 @@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44852 }
44853 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
44854 struct configfs_dirent *next;
44855 - const char * name;
44856 + const unsigned char * name;
44857 + char d_name[sizeof(next->s_dentry->d_iname)];
44858 int len;
44859 struct inode *inode = NULL;
44860
44861 @@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44862 continue;
44863
44864 name = configfs_get_name(next);
44865 - len = strlen(name);
44866 + if (next->s_dentry && name == next->s_dentry->d_iname) {
44867 + len = next->s_dentry->d_name.len;
44868 + memcpy(d_name, name, len);
44869 + name = d_name;
44870 + } else
44871 + len = strlen(name);
44872
44873 /*
44874 * We'll have a dentry and an inode for
44875 diff --git a/fs/dcache.c b/fs/dcache.c
44876 index 693f95b..95f1223 100644
44877 --- a/fs/dcache.c
44878 +++ b/fs/dcache.c
44879 @@ -3164,7 +3164,7 @@ void __init vfs_caches_init(unsigned long mempages)
44880 mempages -= reserve;
44881
44882 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
44883 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
44884 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
44885
44886 dcache_init();
44887 inode_init();
44888 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
44889 index 4733eab..71ef6fa 100644
44890 --- a/fs/debugfs/inode.c
44891 +++ b/fs/debugfs/inode.c
44892 @@ -406,7 +406,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
44893 */
44894 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
44895 {
44896 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
44897 + return __create_file(name, S_IFDIR | S_IRWXU,
44898 +#else
44899 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
44900 +#endif
44901 parent, NULL, NULL);
44902 }
44903 EXPORT_SYMBOL_GPL(debugfs_create_dir);
44904 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
44905 index cc7709e..7e7211f 100644
44906 --- a/fs/ecryptfs/inode.c
44907 +++ b/fs/ecryptfs/inode.c
44908 @@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
44909 old_fs = get_fs();
44910 set_fs(get_ds());
44911 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
44912 - (char __user *)lower_buf,
44913 + (char __force_user *)lower_buf,
44914 PATH_MAX);
44915 set_fs(old_fs);
44916 if (rc < 0)
44917 @@ -706,7 +706,7 @@ out:
44918 static void
44919 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
44920 {
44921 - char *buf = nd_get_link(nd);
44922 + const char *buf = nd_get_link(nd);
44923 if (!IS_ERR(buf)) {
44924 /* Free the char* */
44925 kfree(buf);
44926 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
44927 index 412e6ed..4292d22 100644
44928 --- a/fs/ecryptfs/miscdev.c
44929 +++ b/fs/ecryptfs/miscdev.c
44930 @@ -315,7 +315,7 @@ check_list:
44931 goto out_unlock_msg_ctx;
44932 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
44933 if (msg_ctx->msg) {
44934 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
44935 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
44936 goto out_unlock_msg_ctx;
44937 i += packet_length_size;
44938 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
44939 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
44940 index b2a34a1..162fa69 100644
44941 --- a/fs/ecryptfs/read_write.c
44942 +++ b/fs/ecryptfs/read_write.c
44943 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
44944 return -EIO;
44945 fs_save = get_fs();
44946 set_fs(get_ds());
44947 - rc = vfs_write(lower_file, data, size, &offset);
44948 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
44949 set_fs(fs_save);
44950 mark_inode_dirty_sync(ecryptfs_inode);
44951 return rc;
44952 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
44953 return -EIO;
44954 fs_save = get_fs();
44955 set_fs(get_ds());
44956 - rc = vfs_read(lower_file, data, size, &offset);
44957 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
44958 set_fs(fs_save);
44959 return rc;
44960 }
44961 diff --git a/fs/exec.c b/fs/exec.c
44962 index fab2c6d..4fa20c0 100644
44963 --- a/fs/exec.c
44964 +++ b/fs/exec.c
44965 @@ -55,6 +55,15 @@
44966 #include <linux/pipe_fs_i.h>
44967 #include <linux/oom.h>
44968 #include <linux/compat.h>
44969 +#include <linux/random.h>
44970 +#include <linux/seq_file.h>
44971 +
44972 +#ifdef CONFIG_PAX_REFCOUNT
44973 +#include <linux/kallsyms.h>
44974 +#include <linux/kdebug.h>
44975 +#endif
44976 +
44977 +#include <trace/events/fs.h>
44978
44979 #include <asm/uaccess.h>
44980 #include <asm/mmu_context.h>
44981 @@ -66,6 +75,18 @@
44982
44983 #include <trace/events/sched.h>
44984
44985 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
44986 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
44987 +{
44988 + 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");
44989 +}
44990 +#endif
44991 +
44992 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
44993 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
44994 +EXPORT_SYMBOL(pax_set_initial_flags_func);
44995 +#endif
44996 +
44997 int core_uses_pid;
44998 char core_pattern[CORENAME_MAX_SIZE] = "core";
44999 unsigned int core_pipe_limit;
45000 @@ -75,7 +96,7 @@ struct core_name {
45001 char *corename;
45002 int used, size;
45003 };
45004 -static atomic_t call_count = ATOMIC_INIT(1);
45005 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
45006
45007 /* The maximal length of core_pattern is also specified in sysctl.c */
45008
45009 @@ -191,18 +212,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
45010 int write)
45011 {
45012 struct page *page;
45013 - int ret;
45014
45015 -#ifdef CONFIG_STACK_GROWSUP
45016 - if (write) {
45017 - ret = expand_downwards(bprm->vma, pos);
45018 - if (ret < 0)
45019 - return NULL;
45020 - }
45021 -#endif
45022 - ret = get_user_pages(current, bprm->mm, pos,
45023 - 1, write, 1, &page, NULL);
45024 - if (ret <= 0)
45025 + if (0 > expand_downwards(bprm->vma, pos))
45026 + return NULL;
45027 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
45028 return NULL;
45029
45030 if (write) {
45031 @@ -218,6 +231,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
45032 if (size <= ARG_MAX)
45033 return page;
45034
45035 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45036 + // only allow 512KB for argv+env on suid/sgid binaries
45037 + // to prevent easy ASLR exhaustion
45038 + if (((bprm->cred->euid != current_euid()) ||
45039 + (bprm->cred->egid != current_egid())) &&
45040 + (size > (512 * 1024))) {
45041 + put_page(page);
45042 + return NULL;
45043 + }
45044 +#endif
45045 +
45046 /*
45047 * Limit to 1/4-th the stack size for the argv+env strings.
45048 * This ensures that:
45049 @@ -277,6 +301,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
45050 vma->vm_end = STACK_TOP_MAX;
45051 vma->vm_start = vma->vm_end - PAGE_SIZE;
45052 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
45053 +
45054 +#ifdef CONFIG_PAX_SEGMEXEC
45055 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
45056 +#endif
45057 +
45058 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
45059 INIT_LIST_HEAD(&vma->anon_vma_chain);
45060
45061 @@ -287,6 +316,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
45062 mm->stack_vm = mm->total_vm = 1;
45063 up_write(&mm->mmap_sem);
45064 bprm->p = vma->vm_end - sizeof(void *);
45065 +
45066 +#ifdef CONFIG_PAX_RANDUSTACK
45067 + if (randomize_va_space)
45068 + bprm->p ^= random32() & ~PAGE_MASK;
45069 +#endif
45070 +
45071 return 0;
45072 err:
45073 up_write(&mm->mmap_sem);
45074 @@ -395,19 +430,7 @@ err:
45075 return err;
45076 }
45077
45078 -struct user_arg_ptr {
45079 -#ifdef CONFIG_COMPAT
45080 - bool is_compat;
45081 -#endif
45082 - union {
45083 - const char __user *const __user *native;
45084 -#ifdef CONFIG_COMPAT
45085 - compat_uptr_t __user *compat;
45086 -#endif
45087 - } ptr;
45088 -};
45089 -
45090 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
45091 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
45092 {
45093 const char __user *native;
45094
45095 @@ -416,14 +439,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
45096 compat_uptr_t compat;
45097
45098 if (get_user(compat, argv.ptr.compat + nr))
45099 - return ERR_PTR(-EFAULT);
45100 + return (const char __force_user *)ERR_PTR(-EFAULT);
45101
45102 return compat_ptr(compat);
45103 }
45104 #endif
45105
45106 if (get_user(native, argv.ptr.native + nr))
45107 - return ERR_PTR(-EFAULT);
45108 + return (const char __force_user *)ERR_PTR(-EFAULT);
45109
45110 return native;
45111 }
45112 @@ -442,7 +465,7 @@ static int count(struct user_arg_ptr argv, int max)
45113 if (!p)
45114 break;
45115
45116 - if (IS_ERR(p))
45117 + if (IS_ERR((const char __force_kernel *)p))
45118 return -EFAULT;
45119
45120 if (i++ >= max)
45121 @@ -476,7 +499,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
45122
45123 ret = -EFAULT;
45124 str = get_user_arg_ptr(argv, argc);
45125 - if (IS_ERR(str))
45126 + if (IS_ERR((const char __force_kernel *)str))
45127 goto out;
45128
45129 len = strnlen_user(str, MAX_ARG_STRLEN);
45130 @@ -558,7 +581,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
45131 int r;
45132 mm_segment_t oldfs = get_fs();
45133 struct user_arg_ptr argv = {
45134 - .ptr.native = (const char __user *const __user *)__argv,
45135 + .ptr.native = (const char __force_user *const __force_user *)__argv,
45136 };
45137
45138 set_fs(KERNEL_DS);
45139 @@ -593,7 +616,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
45140 unsigned long new_end = old_end - shift;
45141 struct mmu_gather tlb;
45142
45143 - BUG_ON(new_start > new_end);
45144 + if (new_start >= new_end || new_start < mmap_min_addr)
45145 + return -ENOMEM;
45146
45147 /*
45148 * ensure there are no vmas between where we want to go
45149 @@ -602,6 +626,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
45150 if (vma != find_vma(mm, new_start))
45151 return -EFAULT;
45152
45153 +#ifdef CONFIG_PAX_SEGMEXEC
45154 + BUG_ON(pax_find_mirror_vma(vma));
45155 +#endif
45156 +
45157 /*
45158 * cover the whole range: [new_start, old_end)
45159 */
45160 @@ -682,10 +710,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
45161 stack_top = arch_align_stack(stack_top);
45162 stack_top = PAGE_ALIGN(stack_top);
45163
45164 - if (unlikely(stack_top < mmap_min_addr) ||
45165 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
45166 - return -ENOMEM;
45167 -
45168 stack_shift = vma->vm_end - stack_top;
45169
45170 bprm->p -= stack_shift;
45171 @@ -697,8 +721,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
45172 bprm->exec -= stack_shift;
45173
45174 down_write(&mm->mmap_sem);
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 vm_flags = VM_STACK_FLAGS;
45184
45185 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45186 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45187 + vm_flags &= ~VM_EXEC;
45188 +
45189 +#ifdef CONFIG_PAX_MPROTECT
45190 + if (mm->pax_flags & MF_PAX_MPROTECT)
45191 + vm_flags &= ~VM_MAYEXEC;
45192 +#endif
45193 +
45194 + }
45195 +#endif
45196 +
45197 /*
45198 * Adjust stack execute permissions; explicitly enable for
45199 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
45200 @@ -717,13 +761,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
45201 goto out_unlock;
45202 BUG_ON(prev != vma);
45203
45204 - /* Move stack pages down in memory. */
45205 - if (stack_shift) {
45206 - ret = shift_arg_pages(vma, stack_shift);
45207 - if (ret)
45208 - goto out_unlock;
45209 - }
45210 -
45211 /* mprotect_fixup is overkill to remove the temporary stack flags */
45212 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
45213
45214 @@ -781,6 +818,8 @@ struct file *open_exec(const char *name)
45215
45216 fsnotify_open(file);
45217
45218 + trace_open_exec(name);
45219 +
45220 err = deny_write_access(file);
45221 if (err)
45222 goto exit;
45223 @@ -804,7 +843,7 @@ int kernel_read(struct file *file, loff_t offset,
45224 old_fs = get_fs();
45225 set_fs(get_ds());
45226 /* The cast to a user pointer is valid due to the set_fs() */
45227 - result = vfs_read(file, (void __user *)addr, count, &pos);
45228 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
45229 set_fs(old_fs);
45230 return result;
45231 }
45232 @@ -1258,7 +1297,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
45233 }
45234 rcu_read_unlock();
45235
45236 - if (p->fs->users > n_fs) {
45237 + if (atomic_read(&p->fs->users) > n_fs) {
45238 bprm->unsafe |= LSM_UNSAFE_SHARE;
45239 } else {
45240 res = -EAGAIN;
45241 @@ -1461,6 +1500,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
45242
45243 EXPORT_SYMBOL(search_binary_handler);
45244
45245 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45246 +static DEFINE_PER_CPU(u64, exec_counter);
45247 +static int __init init_exec_counters(void)
45248 +{
45249 + unsigned int cpu;
45250 +
45251 + for_each_possible_cpu(cpu) {
45252 + per_cpu(exec_counter, cpu) = (u64)cpu;
45253 + }
45254 +
45255 + return 0;
45256 +}
45257 +early_initcall(init_exec_counters);
45258 +static inline void increment_exec_counter(void)
45259 +{
45260 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
45261 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
45262 +}
45263 +#else
45264 +static inline void increment_exec_counter(void) {}
45265 +#endif
45266 +
45267 /*
45268 * sys_execve() executes a new program.
45269 */
45270 @@ -1469,6 +1530,11 @@ static int do_execve_common(const char *filename,
45271 struct user_arg_ptr envp,
45272 struct pt_regs *regs)
45273 {
45274 +#ifdef CONFIG_GRKERNSEC
45275 + struct file *old_exec_file;
45276 + struct acl_subject_label *old_acl;
45277 + struct rlimit old_rlim[RLIM_NLIMITS];
45278 +#endif
45279 struct linux_binprm *bprm;
45280 struct file *file;
45281 struct files_struct *displaced;
45282 @@ -1476,6 +1542,8 @@ static int do_execve_common(const char *filename,
45283 int retval;
45284 const struct cred *cred = current_cred();
45285
45286 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
45287 +
45288 /*
45289 * We move the actual failure in case of RLIMIT_NPROC excess from
45290 * set*uid() to execve() because too many poorly written programs
45291 @@ -1516,12 +1584,27 @@ static int do_execve_common(const char *filename,
45292 if (IS_ERR(file))
45293 goto out_unmark;
45294
45295 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
45296 + retval = -EPERM;
45297 + goto out_file;
45298 + }
45299 +
45300 sched_exec();
45301
45302 bprm->file = file;
45303 bprm->filename = filename;
45304 bprm->interp = filename;
45305
45306 + if (gr_process_user_ban()) {
45307 + retval = -EPERM;
45308 + goto out_file;
45309 + }
45310 +
45311 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
45312 + retval = -EACCES;
45313 + goto out_file;
45314 + }
45315 +
45316 retval = bprm_mm_init(bprm);
45317 if (retval)
45318 goto out_file;
45319 @@ -1538,24 +1621,65 @@ static int do_execve_common(const char *filename,
45320 if (retval < 0)
45321 goto out;
45322
45323 +#ifdef CONFIG_GRKERNSEC
45324 + old_acl = current->acl;
45325 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
45326 + old_exec_file = current->exec_file;
45327 + get_file(file);
45328 + current->exec_file = file;
45329 +#endif
45330 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45331 + /* limit suid stack to 8MB
45332 + we saved the old limits above and will restore them if this exec fails
45333 + */
45334 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
45335 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
45336 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
45337 +#endif
45338 +
45339 + if (!gr_tpe_allow(file)) {
45340 + retval = -EACCES;
45341 + goto out_fail;
45342 + }
45343 +
45344 + if (gr_check_crash_exec(file)) {
45345 + retval = -EACCES;
45346 + goto out_fail;
45347 + }
45348 +
45349 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
45350 + bprm->unsafe);
45351 + if (retval < 0)
45352 + goto out_fail;
45353 +
45354 retval = copy_strings_kernel(1, &bprm->filename, bprm);
45355 if (retval < 0)
45356 - goto out;
45357 + goto out_fail;
45358
45359 bprm->exec = bprm->p;
45360 retval = copy_strings(bprm->envc, envp, bprm);
45361 if (retval < 0)
45362 - goto out;
45363 + goto out_fail;
45364
45365 retval = copy_strings(bprm->argc, argv, bprm);
45366 if (retval < 0)
45367 - goto out;
45368 + goto out_fail;
45369 +
45370 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
45371 +
45372 + gr_handle_exec_args(bprm, argv);
45373
45374 retval = search_binary_handler(bprm,regs);
45375 if (retval < 0)
45376 - goto out;
45377 + goto out_fail;
45378 +#ifdef CONFIG_GRKERNSEC
45379 + if (old_exec_file)
45380 + fput(old_exec_file);
45381 +#endif
45382
45383 /* execve succeeded */
45384 +
45385 + increment_exec_counter();
45386 current->fs->in_exec = 0;
45387 current->in_execve = 0;
45388 acct_update_integrals(current);
45389 @@ -1564,6 +1688,14 @@ static int do_execve_common(const char *filename,
45390 put_files_struct(displaced);
45391 return retval;
45392
45393 +out_fail:
45394 +#ifdef CONFIG_GRKERNSEC
45395 + current->acl = old_acl;
45396 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
45397 + fput(current->exec_file);
45398 + current->exec_file = old_exec_file;
45399 +#endif
45400 +
45401 out:
45402 if (bprm->mm) {
45403 acct_arg_size(bprm, 0);
45404 @@ -1637,7 +1769,7 @@ static int expand_corename(struct core_name *cn)
45405 {
45406 char *old_corename = cn->corename;
45407
45408 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
45409 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
45410 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
45411
45412 if (!cn->corename) {
45413 @@ -1734,7 +1866,7 @@ static int format_corename(struct core_name *cn, long signr)
45414 int pid_in_pattern = 0;
45415 int err = 0;
45416
45417 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
45418 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
45419 cn->corename = kmalloc(cn->size, GFP_KERNEL);
45420 cn->used = 0;
45421
45422 @@ -1831,6 +1963,250 @@ out:
45423 return ispipe;
45424 }
45425
45426 +int pax_check_flags(unsigned long *flags)
45427 +{
45428 + int retval = 0;
45429 +
45430 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
45431 + if (*flags & MF_PAX_SEGMEXEC)
45432 + {
45433 + *flags &= ~MF_PAX_SEGMEXEC;
45434 + retval = -EINVAL;
45435 + }
45436 +#endif
45437 +
45438 + if ((*flags & MF_PAX_PAGEEXEC)
45439 +
45440 +#ifdef CONFIG_PAX_PAGEEXEC
45441 + && (*flags & MF_PAX_SEGMEXEC)
45442 +#endif
45443 +
45444 + )
45445 + {
45446 + *flags &= ~MF_PAX_PAGEEXEC;
45447 + retval = -EINVAL;
45448 + }
45449 +
45450 + if ((*flags & MF_PAX_MPROTECT)
45451 +
45452 +#ifdef CONFIG_PAX_MPROTECT
45453 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45454 +#endif
45455 +
45456 + )
45457 + {
45458 + *flags &= ~MF_PAX_MPROTECT;
45459 + retval = -EINVAL;
45460 + }
45461 +
45462 + if ((*flags & MF_PAX_EMUTRAMP)
45463 +
45464 +#ifdef CONFIG_PAX_EMUTRAMP
45465 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45466 +#endif
45467 +
45468 + )
45469 + {
45470 + *flags &= ~MF_PAX_EMUTRAMP;
45471 + retval = -EINVAL;
45472 + }
45473 +
45474 + return retval;
45475 +}
45476 +
45477 +EXPORT_SYMBOL(pax_check_flags);
45478 +
45479 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45480 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
45481 +{
45482 + struct task_struct *tsk = current;
45483 + struct mm_struct *mm = current->mm;
45484 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
45485 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
45486 + char *path_exec = NULL;
45487 + char *path_fault = NULL;
45488 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
45489 +
45490 + if (buffer_exec && buffer_fault) {
45491 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
45492 +
45493 + down_read(&mm->mmap_sem);
45494 + vma = mm->mmap;
45495 + while (vma && (!vma_exec || !vma_fault)) {
45496 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
45497 + vma_exec = vma;
45498 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
45499 + vma_fault = vma;
45500 + vma = vma->vm_next;
45501 + }
45502 + if (vma_exec) {
45503 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
45504 + if (IS_ERR(path_exec))
45505 + path_exec = "<path too long>";
45506 + else {
45507 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
45508 + if (path_exec) {
45509 + *path_exec = 0;
45510 + path_exec = buffer_exec;
45511 + } else
45512 + path_exec = "<path too long>";
45513 + }
45514 + }
45515 + if (vma_fault) {
45516 + start = vma_fault->vm_start;
45517 + end = vma_fault->vm_end;
45518 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
45519 + if (vma_fault->vm_file) {
45520 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
45521 + if (IS_ERR(path_fault))
45522 + path_fault = "<path too long>";
45523 + else {
45524 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
45525 + if (path_fault) {
45526 + *path_fault = 0;
45527 + path_fault = buffer_fault;
45528 + } else
45529 + path_fault = "<path too long>";
45530 + }
45531 + } else
45532 + path_fault = "<anonymous mapping>";
45533 + }
45534 + up_read(&mm->mmap_sem);
45535 + }
45536 + if (tsk->signal->curr_ip)
45537 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
45538 + else
45539 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
45540 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
45541 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
45542 + task_uid(tsk), task_euid(tsk), pc, sp);
45543 + free_page((unsigned long)buffer_exec);
45544 + free_page((unsigned long)buffer_fault);
45545 + pax_report_insns(regs, pc, sp);
45546 + do_coredump(SIGKILL, SIGKILL, regs);
45547 +}
45548 +#endif
45549 +
45550 +#ifdef CONFIG_PAX_REFCOUNT
45551 +void pax_report_refcount_overflow(struct pt_regs *regs)
45552 +{
45553 + if (current->signal->curr_ip)
45554 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45555 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
45556 + else
45557 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45558 + current->comm, task_pid_nr(current), current_uid(), current_euid());
45559 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
45560 + show_regs(regs);
45561 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
45562 +}
45563 +#endif
45564 +
45565 +#ifdef CONFIG_PAX_USERCOPY
45566 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
45567 +static noinline int check_stack_object(const void *obj, unsigned long len)
45568 +{
45569 + const void * const stack = task_stack_page(current);
45570 + const void * const stackend = stack + THREAD_SIZE;
45571 +
45572 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45573 + const void *frame = NULL;
45574 + const void *oldframe;
45575 +#endif
45576 +
45577 + if (obj + len < obj)
45578 + return -1;
45579 +
45580 + if (obj + len <= stack || stackend <= obj)
45581 + return 0;
45582 +
45583 + if (obj < stack || stackend < obj + len)
45584 + return -1;
45585 +
45586 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45587 + oldframe = __builtin_frame_address(1);
45588 + if (oldframe)
45589 + frame = __builtin_frame_address(2);
45590 + /*
45591 + low ----------------------------------------------> high
45592 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
45593 + ^----------------^
45594 + allow copies only within here
45595 + */
45596 + while (stack <= frame && frame < stackend) {
45597 + /* if obj + len extends past the last frame, this
45598 + check won't pass and the next frame will be 0,
45599 + causing us to bail out and correctly report
45600 + the copy as invalid
45601 + */
45602 + if (obj + len <= frame)
45603 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
45604 + oldframe = frame;
45605 + frame = *(const void * const *)frame;
45606 + }
45607 + return -1;
45608 +#else
45609 + return 1;
45610 +#endif
45611 +}
45612 +
45613 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
45614 +{
45615 + if (current->signal->curr_ip)
45616 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45617 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45618 + else
45619 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45620 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45621 + dump_stack();
45622 + gr_handle_kernel_exploit();
45623 + do_group_exit(SIGKILL);
45624 +}
45625 +#endif
45626 +
45627 +void check_object_size(const void *ptr, unsigned long n, bool to)
45628 +{
45629 +
45630 +#ifdef CONFIG_PAX_USERCOPY
45631 + const char *type;
45632 +
45633 + if (!n)
45634 + return;
45635 +
45636 + type = check_heap_object(ptr, n, to);
45637 + if (!type) {
45638 + if (check_stack_object(ptr, n) != -1)
45639 + return;
45640 + type = "<process stack>";
45641 + }
45642 +
45643 + pax_report_usercopy(ptr, n, to, type);
45644 +#endif
45645 +
45646 +}
45647 +EXPORT_SYMBOL(check_object_size);
45648 +
45649 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
45650 +void pax_track_stack(void)
45651 +{
45652 + unsigned long sp = (unsigned long)&sp;
45653 + if (sp < current_thread_info()->lowest_stack &&
45654 + sp > (unsigned long)task_stack_page(current))
45655 + current_thread_info()->lowest_stack = sp;
45656 +}
45657 +EXPORT_SYMBOL(pax_track_stack);
45658 +#endif
45659 +
45660 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
45661 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
45662 +{
45663 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
45664 + dump_stack();
45665 + do_group_exit(SIGKILL);
45666 +}
45667 +EXPORT_SYMBOL(report_size_overflow);
45668 +#endif
45669 +
45670 static int zap_process(struct task_struct *start, int exit_code)
45671 {
45672 struct task_struct *t;
45673 @@ -2041,17 +2417,17 @@ static void wait_for_dump_helpers(struct file *file)
45674 pipe = file->f_path.dentry->d_inode->i_pipe;
45675
45676 pipe_lock(pipe);
45677 - pipe->readers++;
45678 - pipe->writers--;
45679 + atomic_inc(&pipe->readers);
45680 + atomic_dec(&pipe->writers);
45681
45682 - while ((pipe->readers > 1) && (!signal_pending(current))) {
45683 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
45684 wake_up_interruptible_sync(&pipe->wait);
45685 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
45686 pipe_wait(pipe);
45687 }
45688
45689 - pipe->readers--;
45690 - pipe->writers++;
45691 + atomic_dec(&pipe->readers);
45692 + atomic_inc(&pipe->writers);
45693 pipe_unlock(pipe);
45694
45695 }
45696 @@ -2106,7 +2482,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45697 int flag = 0;
45698 int ispipe;
45699 bool need_nonrelative = false;
45700 - static atomic_t core_dump_count = ATOMIC_INIT(0);
45701 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
45702 struct coredump_params cprm = {
45703 .signr = signr,
45704 .regs = regs,
45705 @@ -2121,6 +2497,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45706
45707 audit_core_dumps(signr);
45708
45709 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
45710 + gr_handle_brute_attach(current, cprm.mm_flags);
45711 +
45712 binfmt = mm->binfmt;
45713 if (!binfmt || !binfmt->core_dump)
45714 goto fail;
45715 @@ -2191,7 +2570,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45716 }
45717 cprm.limit = RLIM_INFINITY;
45718
45719 - dump_count = atomic_inc_return(&core_dump_count);
45720 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
45721 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
45722 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
45723 task_tgid_vnr(current), current->comm);
45724 @@ -2218,6 +2597,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45725 } else {
45726 struct inode *inode;
45727
45728 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
45729 +
45730 if (cprm.limit < binfmt->min_coredump)
45731 goto fail_unlock;
45732
45733 @@ -2269,7 +2650,7 @@ close_fail:
45734 filp_close(cprm.file, NULL);
45735 fail_dropcount:
45736 if (ispipe)
45737 - atomic_dec(&core_dump_count);
45738 + atomic_dec_unchecked(&core_dump_count);
45739 fail_unlock:
45740 kfree(cn.corename);
45741 fail_corename:
45742 @@ -2288,7 +2669,7 @@ fail:
45743 */
45744 int dump_write(struct file *file, const void *addr, int nr)
45745 {
45746 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
45747 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
45748 }
45749 EXPORT_SYMBOL(dump_write);
45750
45751 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
45752 index 376aa77..59a129c 100644
45753 --- a/fs/ext2/balloc.c
45754 +++ b/fs/ext2/balloc.c
45755 @@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
45756
45757 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45758 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45759 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45760 + if (free_blocks < root_blocks + 1 &&
45761 !uid_eq(sbi->s_resuid, current_fsuid()) &&
45762 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45763 - !in_group_p (sbi->s_resgid))) {
45764 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45765 return 0;
45766 }
45767 return 1;
45768 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
45769 index 90d901f..159975f 100644
45770 --- a/fs/ext3/balloc.c
45771 +++ b/fs/ext3/balloc.c
45772 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
45773
45774 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45775 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45776 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45777 + if (free_blocks < root_blocks + 1 &&
45778 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
45779 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45780 - !in_group_p (sbi->s_resgid))) {
45781 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45782 return 0;
45783 }
45784 return 1;
45785 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
45786 index cf18217..8f6b9c3 100644
45787 --- a/fs/ext4/balloc.c
45788 +++ b/fs/ext4/balloc.c
45789 @@ -498,8 +498,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
45790 /* Hm, nope. Are (enough) root reserved clusters available? */
45791 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
45792 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
45793 - capable(CAP_SYS_RESOURCE) ||
45794 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
45795 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
45796 + capable_nolog(CAP_SYS_RESOURCE)) {
45797
45798 if (free_clusters >= (nclusters + dirty_clusters))
45799 return 1;
45800 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
45801 index 5c69f2b..05dec7f 100644
45802 --- a/fs/ext4/ext4.h
45803 +++ b/fs/ext4/ext4.h
45804 @@ -1248,19 +1248,19 @@ struct ext4_sb_info {
45805 unsigned long s_mb_last_start;
45806
45807 /* stats for buddy allocator */
45808 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
45809 - atomic_t s_bal_success; /* we found long enough chunks */
45810 - atomic_t s_bal_allocated; /* in blocks */
45811 - atomic_t s_bal_ex_scanned; /* total extents scanned */
45812 - atomic_t s_bal_goals; /* goal hits */
45813 - atomic_t s_bal_breaks; /* too long searches */
45814 - atomic_t s_bal_2orders; /* 2^order hits */
45815 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
45816 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
45817 + atomic_unchecked_t s_bal_allocated; /* in blocks */
45818 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
45819 + atomic_unchecked_t s_bal_goals; /* goal hits */
45820 + atomic_unchecked_t s_bal_breaks; /* too long searches */
45821 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
45822 spinlock_t s_bal_lock;
45823 unsigned long s_mb_buddies_generated;
45824 unsigned long long s_mb_generation_time;
45825 - atomic_t s_mb_lost_chunks;
45826 - atomic_t s_mb_preallocated;
45827 - atomic_t s_mb_discarded;
45828 + atomic_unchecked_t s_mb_lost_chunks;
45829 + atomic_unchecked_t s_mb_preallocated;
45830 + atomic_unchecked_t s_mb_discarded;
45831 atomic_t s_lock_busy;
45832
45833 /* locality groups */
45834 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
45835 index b26410c..7383d90 100644
45836 --- a/fs/ext4/mballoc.c
45837 +++ b/fs/ext4/mballoc.c
45838 @@ -1746,7 +1746,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
45839 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
45840
45841 if (EXT4_SB(sb)->s_mb_stats)
45842 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
45843 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
45844
45845 break;
45846 }
45847 @@ -2040,7 +2040,7 @@ repeat:
45848 ac->ac_status = AC_STATUS_CONTINUE;
45849 ac->ac_flags |= EXT4_MB_HINT_FIRST;
45850 cr = 3;
45851 - atomic_inc(&sbi->s_mb_lost_chunks);
45852 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
45853 goto repeat;
45854 }
45855 }
45856 @@ -2551,25 +2551,25 @@ int ext4_mb_release(struct super_block *sb)
45857 if (sbi->s_mb_stats) {
45858 ext4_msg(sb, KERN_INFO,
45859 "mballoc: %u blocks %u reqs (%u success)",
45860 - atomic_read(&sbi->s_bal_allocated),
45861 - atomic_read(&sbi->s_bal_reqs),
45862 - atomic_read(&sbi->s_bal_success));
45863 + atomic_read_unchecked(&sbi->s_bal_allocated),
45864 + atomic_read_unchecked(&sbi->s_bal_reqs),
45865 + atomic_read_unchecked(&sbi->s_bal_success));
45866 ext4_msg(sb, KERN_INFO,
45867 "mballoc: %u extents scanned, %u goal hits, "
45868 "%u 2^N hits, %u breaks, %u lost",
45869 - atomic_read(&sbi->s_bal_ex_scanned),
45870 - atomic_read(&sbi->s_bal_goals),
45871 - atomic_read(&sbi->s_bal_2orders),
45872 - atomic_read(&sbi->s_bal_breaks),
45873 - atomic_read(&sbi->s_mb_lost_chunks));
45874 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
45875 + atomic_read_unchecked(&sbi->s_bal_goals),
45876 + atomic_read_unchecked(&sbi->s_bal_2orders),
45877 + atomic_read_unchecked(&sbi->s_bal_breaks),
45878 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
45879 ext4_msg(sb, KERN_INFO,
45880 "mballoc: %lu generated and it took %Lu",
45881 sbi->s_mb_buddies_generated,
45882 sbi->s_mb_generation_time);
45883 ext4_msg(sb, KERN_INFO,
45884 "mballoc: %u preallocated, %u discarded",
45885 - atomic_read(&sbi->s_mb_preallocated),
45886 - atomic_read(&sbi->s_mb_discarded));
45887 + atomic_read_unchecked(&sbi->s_mb_preallocated),
45888 + atomic_read_unchecked(&sbi->s_mb_discarded));
45889 }
45890
45891 free_percpu(sbi->s_locality_groups);
45892 @@ -3051,16 +3051,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
45893 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
45894
45895 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
45896 - atomic_inc(&sbi->s_bal_reqs);
45897 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45898 + atomic_inc_unchecked(&sbi->s_bal_reqs);
45899 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45900 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
45901 - atomic_inc(&sbi->s_bal_success);
45902 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
45903 + atomic_inc_unchecked(&sbi->s_bal_success);
45904 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
45905 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
45906 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
45907 - atomic_inc(&sbi->s_bal_goals);
45908 + atomic_inc_unchecked(&sbi->s_bal_goals);
45909 if (ac->ac_found > sbi->s_mb_max_to_scan)
45910 - atomic_inc(&sbi->s_bal_breaks);
45911 + atomic_inc_unchecked(&sbi->s_bal_breaks);
45912 }
45913
45914 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
45915 @@ -3460,7 +3460,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
45916 trace_ext4_mb_new_inode_pa(ac, pa);
45917
45918 ext4_mb_use_inode_pa(ac, pa);
45919 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
45920 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
45921
45922 ei = EXT4_I(ac->ac_inode);
45923 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45924 @@ -3520,7 +3520,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
45925 trace_ext4_mb_new_group_pa(ac, pa);
45926
45927 ext4_mb_use_group_pa(ac, pa);
45928 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45929 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45930
45931 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45932 lg = ac->ac_lg;
45933 @@ -3609,7 +3609,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
45934 * from the bitmap and continue.
45935 */
45936 }
45937 - atomic_add(free, &sbi->s_mb_discarded);
45938 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
45939
45940 return err;
45941 }
45942 @@ -3627,7 +3627,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
45943 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
45944 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
45945 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
45946 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45947 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45948 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
45949
45950 return 0;
45951 diff --git a/fs/fcntl.c b/fs/fcntl.c
45952 index 887b5ba..0e3f2c3 100644
45953 --- a/fs/fcntl.c
45954 +++ b/fs/fcntl.c
45955 @@ -225,6 +225,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
45956 if (err)
45957 return err;
45958
45959 + if (gr_handle_chroot_fowner(pid, type))
45960 + return -ENOENT;
45961 + if (gr_check_protected_task_fowner(pid, type))
45962 + return -EACCES;
45963 +
45964 f_modown(filp, pid, type, force);
45965 return 0;
45966 }
45967 @@ -267,7 +272,7 @@ pid_t f_getown(struct file *filp)
45968
45969 static int f_setown_ex(struct file *filp, unsigned long arg)
45970 {
45971 - struct f_owner_ex * __user owner_p = (void * __user)arg;
45972 + struct f_owner_ex __user *owner_p = (void __user *)arg;
45973 struct f_owner_ex owner;
45974 struct pid *pid;
45975 int type;
45976 @@ -307,7 +312,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
45977
45978 static int f_getown_ex(struct file *filp, unsigned long arg)
45979 {
45980 - struct f_owner_ex * __user owner_p = (void * __user)arg;
45981 + struct f_owner_ex __user *owner_p = (void __user *)arg;
45982 struct f_owner_ex owner;
45983 int ret = 0;
45984
45985 @@ -374,6 +379,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
45986 switch (cmd) {
45987 case F_DUPFD:
45988 case F_DUPFD_CLOEXEC:
45989 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
45990 if (arg >= rlimit(RLIMIT_NOFILE))
45991 break;
45992 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
45993 diff --git a/fs/fifo.c b/fs/fifo.c
45994 index cf6f434..3d7942c 100644
45995 --- a/fs/fifo.c
45996 +++ b/fs/fifo.c
45997 @@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
45998 */
45999 filp->f_op = &read_pipefifo_fops;
46000 pipe->r_counter++;
46001 - if (pipe->readers++ == 0)
46002 + if (atomic_inc_return(&pipe->readers) == 1)
46003 wake_up_partner(inode);
46004
46005 - if (!pipe->writers) {
46006 + if (!atomic_read(&pipe->writers)) {
46007 if ((filp->f_flags & O_NONBLOCK)) {
46008 /* suppress POLLHUP until we have
46009 * seen a writer */
46010 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
46011 * errno=ENXIO when there is no process reading the FIFO.
46012 */
46013 ret = -ENXIO;
46014 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
46015 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
46016 goto err;
46017
46018 filp->f_op = &write_pipefifo_fops;
46019 pipe->w_counter++;
46020 - if (!pipe->writers++)
46021 + if (atomic_inc_return(&pipe->writers) == 1)
46022 wake_up_partner(inode);
46023
46024 - if (!pipe->readers) {
46025 + if (!atomic_read(&pipe->readers)) {
46026 if (wait_for_partner(inode, &pipe->r_counter))
46027 goto err_wr;
46028 }
46029 @@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
46030 */
46031 filp->f_op = &rdwr_pipefifo_fops;
46032
46033 - pipe->readers++;
46034 - pipe->writers++;
46035 + atomic_inc(&pipe->readers);
46036 + atomic_inc(&pipe->writers);
46037 pipe->r_counter++;
46038 pipe->w_counter++;
46039 - if (pipe->readers == 1 || pipe->writers == 1)
46040 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
46041 wake_up_partner(inode);
46042 break;
46043
46044 @@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
46045 return 0;
46046
46047 err_rd:
46048 - if (!--pipe->readers)
46049 + if (atomic_dec_and_test(&pipe->readers))
46050 wake_up_interruptible(&pipe->wait);
46051 ret = -ERESTARTSYS;
46052 goto err;
46053
46054 err_wr:
46055 - if (!--pipe->writers)
46056 + if (atomic_dec_and_test(&pipe->writers))
46057 wake_up_interruptible(&pipe->wait);
46058 ret = -ERESTARTSYS;
46059 goto err;
46060
46061 err:
46062 - if (!pipe->readers && !pipe->writers)
46063 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
46064 free_pipe_info(inode);
46065
46066 err_nocleanup:
46067 diff --git a/fs/file.c b/fs/file.c
46068 index ba3f605..fade102 100644
46069 --- a/fs/file.c
46070 +++ b/fs/file.c
46071 @@ -15,6 +15,7 @@
46072 #include <linux/slab.h>
46073 #include <linux/vmalloc.h>
46074 #include <linux/file.h>
46075 +#include <linux/security.h>
46076 #include <linux/fdtable.h>
46077 #include <linux/bitops.h>
46078 #include <linux/interrupt.h>
46079 @@ -255,6 +256,7 @@ int expand_files(struct files_struct *files, int nr)
46080 * N.B. For clone tasks sharing a files structure, this test
46081 * will limit the total number of files that can be opened.
46082 */
46083 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
46084 if (nr >= rlimit(RLIMIT_NOFILE))
46085 return -EMFILE;
46086
46087 diff --git a/fs/filesystems.c b/fs/filesystems.c
46088 index 96f2428..f5eeb8e 100644
46089 --- a/fs/filesystems.c
46090 +++ b/fs/filesystems.c
46091 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
46092 int len = dot ? dot - name : strlen(name);
46093
46094 fs = __get_fs_type(name, len);
46095 +
46096 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
46097 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
46098 +#else
46099 if (!fs && (request_module("%.*s", len, name) == 0))
46100 +#endif
46101 fs = __get_fs_type(name, len);
46102
46103 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
46104 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
46105 index 5df4775..9d9336f 100644
46106 --- a/fs/fs_struct.c
46107 +++ b/fs/fs_struct.c
46108 @@ -4,6 +4,7 @@
46109 #include <linux/path.h>
46110 #include <linux/slab.h>
46111 #include <linux/fs_struct.h>
46112 +#include <linux/grsecurity.h>
46113 #include "internal.h"
46114
46115 /*
46116 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
46117 write_seqcount_begin(&fs->seq);
46118 old_root = fs->root;
46119 fs->root = *path;
46120 + gr_set_chroot_entries(current, path);
46121 write_seqcount_end(&fs->seq);
46122 spin_unlock(&fs->lock);
46123 if (old_root.dentry)
46124 @@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
46125 return 1;
46126 }
46127
46128 +static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
46129 +{
46130 + if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
46131 + return 0;
46132 + *p = *new;
46133 +
46134 + /* This function is only called from pivot_root(). Leave our
46135 + gr_chroot_dentry and is_chrooted flags as-is, so that a
46136 + pivoted root isn't treated as a chroot
46137 + */
46138 + //gr_set_chroot_entries(task, new);
46139 +
46140 + return 1;
46141 +}
46142 +
46143 void chroot_fs_refs(struct path *old_root, struct path *new_root)
46144 {
46145 struct task_struct *g, *p;
46146 @@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
46147 int hits = 0;
46148 spin_lock(&fs->lock);
46149 write_seqcount_begin(&fs->seq);
46150 - hits += replace_path(&fs->root, old_root, new_root);
46151 + hits += replace_root_path(p, &fs->root, old_root, new_root);
46152 hits += replace_path(&fs->pwd, old_root, new_root);
46153 write_seqcount_end(&fs->seq);
46154 while (hits--) {
46155 @@ -99,7 +116,8 @@ void exit_fs(struct task_struct *tsk)
46156 task_lock(tsk);
46157 spin_lock(&fs->lock);
46158 tsk->fs = NULL;
46159 - kill = !--fs->users;
46160 + gr_clear_chroot_entries(tsk);
46161 + kill = !atomic_dec_return(&fs->users);
46162 spin_unlock(&fs->lock);
46163 task_unlock(tsk);
46164 if (kill)
46165 @@ -112,7 +130,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
46166 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
46167 /* We don't need to lock fs - think why ;-) */
46168 if (fs) {
46169 - fs->users = 1;
46170 + atomic_set(&fs->users, 1);
46171 fs->in_exec = 0;
46172 spin_lock_init(&fs->lock);
46173 seqcount_init(&fs->seq);
46174 @@ -121,6 +139,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
46175 spin_lock(&old->lock);
46176 fs->root = old->root;
46177 path_get(&fs->root);
46178 + /* instead of calling gr_set_chroot_entries here,
46179 + we call it from every caller of this function
46180 + */
46181 fs->pwd = old->pwd;
46182 path_get(&fs->pwd);
46183 spin_unlock(&old->lock);
46184 @@ -139,8 +160,9 @@ int unshare_fs_struct(void)
46185
46186 task_lock(current);
46187 spin_lock(&fs->lock);
46188 - kill = !--fs->users;
46189 + kill = !atomic_dec_return(&fs->users);
46190 current->fs = new_fs;
46191 + gr_set_chroot_entries(current, &new_fs->root);
46192 spin_unlock(&fs->lock);
46193 task_unlock(current);
46194
46195 @@ -153,13 +175,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
46196
46197 int current_umask(void)
46198 {
46199 - return current->fs->umask;
46200 + return current->fs->umask | gr_acl_umask();
46201 }
46202 EXPORT_SYMBOL(current_umask);
46203
46204 /* to be mentioned only in INIT_TASK */
46205 struct fs_struct init_fs = {
46206 - .users = 1,
46207 + .users = ATOMIC_INIT(1),
46208 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
46209 .seq = SEQCNT_ZERO,
46210 .umask = 0022,
46211 @@ -175,12 +197,13 @@ void daemonize_fs_struct(void)
46212 task_lock(current);
46213
46214 spin_lock(&init_fs.lock);
46215 - init_fs.users++;
46216 + atomic_inc(&init_fs.users);
46217 spin_unlock(&init_fs.lock);
46218
46219 spin_lock(&fs->lock);
46220 current->fs = &init_fs;
46221 - kill = !--fs->users;
46222 + gr_set_chroot_entries(current, &current->fs->root);
46223 + kill = !atomic_dec_return(&fs->users);
46224 spin_unlock(&fs->lock);
46225
46226 task_unlock(current);
46227 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
46228 index 9905350..02eaec4 100644
46229 --- a/fs/fscache/cookie.c
46230 +++ b/fs/fscache/cookie.c
46231 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
46232 parent ? (char *) parent->def->name : "<no-parent>",
46233 def->name, netfs_data);
46234
46235 - fscache_stat(&fscache_n_acquires);
46236 + fscache_stat_unchecked(&fscache_n_acquires);
46237
46238 /* if there's no parent cookie, then we don't create one here either */
46239 if (!parent) {
46240 - fscache_stat(&fscache_n_acquires_null);
46241 + fscache_stat_unchecked(&fscache_n_acquires_null);
46242 _leave(" [no parent]");
46243 return NULL;
46244 }
46245 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
46246 /* allocate and initialise a cookie */
46247 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
46248 if (!cookie) {
46249 - fscache_stat(&fscache_n_acquires_oom);
46250 + fscache_stat_unchecked(&fscache_n_acquires_oom);
46251 _leave(" [ENOMEM]");
46252 return NULL;
46253 }
46254 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46255
46256 switch (cookie->def->type) {
46257 case FSCACHE_COOKIE_TYPE_INDEX:
46258 - fscache_stat(&fscache_n_cookie_index);
46259 + fscache_stat_unchecked(&fscache_n_cookie_index);
46260 break;
46261 case FSCACHE_COOKIE_TYPE_DATAFILE:
46262 - fscache_stat(&fscache_n_cookie_data);
46263 + fscache_stat_unchecked(&fscache_n_cookie_data);
46264 break;
46265 default:
46266 - fscache_stat(&fscache_n_cookie_special);
46267 + fscache_stat_unchecked(&fscache_n_cookie_special);
46268 break;
46269 }
46270
46271 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46272 if (fscache_acquire_non_index_cookie(cookie) < 0) {
46273 atomic_dec(&parent->n_children);
46274 __fscache_cookie_put(cookie);
46275 - fscache_stat(&fscache_n_acquires_nobufs);
46276 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
46277 _leave(" = NULL");
46278 return NULL;
46279 }
46280 }
46281
46282 - fscache_stat(&fscache_n_acquires_ok);
46283 + fscache_stat_unchecked(&fscache_n_acquires_ok);
46284 _leave(" = %p", cookie);
46285 return cookie;
46286 }
46287 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
46288 cache = fscache_select_cache_for_object(cookie->parent);
46289 if (!cache) {
46290 up_read(&fscache_addremove_sem);
46291 - fscache_stat(&fscache_n_acquires_no_cache);
46292 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
46293 _leave(" = -ENOMEDIUM [no cache]");
46294 return -ENOMEDIUM;
46295 }
46296 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
46297 object = cache->ops->alloc_object(cache, cookie);
46298 fscache_stat_d(&fscache_n_cop_alloc_object);
46299 if (IS_ERR(object)) {
46300 - fscache_stat(&fscache_n_object_no_alloc);
46301 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
46302 ret = PTR_ERR(object);
46303 goto error;
46304 }
46305
46306 - fscache_stat(&fscache_n_object_alloc);
46307 + fscache_stat_unchecked(&fscache_n_object_alloc);
46308
46309 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
46310
46311 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
46312 struct fscache_object *object;
46313 struct hlist_node *_p;
46314
46315 - fscache_stat(&fscache_n_updates);
46316 + fscache_stat_unchecked(&fscache_n_updates);
46317
46318 if (!cookie) {
46319 - fscache_stat(&fscache_n_updates_null);
46320 + fscache_stat_unchecked(&fscache_n_updates_null);
46321 _leave(" [no cookie]");
46322 return;
46323 }
46324 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46325 struct fscache_object *object;
46326 unsigned long event;
46327
46328 - fscache_stat(&fscache_n_relinquishes);
46329 + fscache_stat_unchecked(&fscache_n_relinquishes);
46330 if (retire)
46331 - fscache_stat(&fscache_n_relinquishes_retire);
46332 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
46333
46334 if (!cookie) {
46335 - fscache_stat(&fscache_n_relinquishes_null);
46336 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
46337 _leave(" [no cookie]");
46338 return;
46339 }
46340 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46341
46342 /* wait for the cookie to finish being instantiated (or to fail) */
46343 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
46344 - fscache_stat(&fscache_n_relinquishes_waitcrt);
46345 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
46346 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
46347 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
46348 }
46349 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
46350 index f6aad48..88dcf26 100644
46351 --- a/fs/fscache/internal.h
46352 +++ b/fs/fscache/internal.h
46353 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
46354 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
46355 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
46356
46357 -extern atomic_t fscache_n_op_pend;
46358 -extern atomic_t fscache_n_op_run;
46359 -extern atomic_t fscache_n_op_enqueue;
46360 -extern atomic_t fscache_n_op_deferred_release;
46361 -extern atomic_t fscache_n_op_release;
46362 -extern atomic_t fscache_n_op_gc;
46363 -extern atomic_t fscache_n_op_cancelled;
46364 -extern atomic_t fscache_n_op_rejected;
46365 +extern atomic_unchecked_t fscache_n_op_pend;
46366 +extern atomic_unchecked_t fscache_n_op_run;
46367 +extern atomic_unchecked_t fscache_n_op_enqueue;
46368 +extern atomic_unchecked_t fscache_n_op_deferred_release;
46369 +extern atomic_unchecked_t fscache_n_op_release;
46370 +extern atomic_unchecked_t fscache_n_op_gc;
46371 +extern atomic_unchecked_t fscache_n_op_cancelled;
46372 +extern atomic_unchecked_t fscache_n_op_rejected;
46373
46374 -extern atomic_t fscache_n_attr_changed;
46375 -extern atomic_t fscache_n_attr_changed_ok;
46376 -extern atomic_t fscache_n_attr_changed_nobufs;
46377 -extern atomic_t fscache_n_attr_changed_nomem;
46378 -extern atomic_t fscache_n_attr_changed_calls;
46379 +extern atomic_unchecked_t fscache_n_attr_changed;
46380 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
46381 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
46382 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
46383 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
46384
46385 -extern atomic_t fscache_n_allocs;
46386 -extern atomic_t fscache_n_allocs_ok;
46387 -extern atomic_t fscache_n_allocs_wait;
46388 -extern atomic_t fscache_n_allocs_nobufs;
46389 -extern atomic_t fscache_n_allocs_intr;
46390 -extern atomic_t fscache_n_allocs_object_dead;
46391 -extern atomic_t fscache_n_alloc_ops;
46392 -extern atomic_t fscache_n_alloc_op_waits;
46393 +extern atomic_unchecked_t fscache_n_allocs;
46394 +extern atomic_unchecked_t fscache_n_allocs_ok;
46395 +extern atomic_unchecked_t fscache_n_allocs_wait;
46396 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
46397 +extern atomic_unchecked_t fscache_n_allocs_intr;
46398 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
46399 +extern atomic_unchecked_t fscache_n_alloc_ops;
46400 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
46401
46402 -extern atomic_t fscache_n_retrievals;
46403 -extern atomic_t fscache_n_retrievals_ok;
46404 -extern atomic_t fscache_n_retrievals_wait;
46405 -extern atomic_t fscache_n_retrievals_nodata;
46406 -extern atomic_t fscache_n_retrievals_nobufs;
46407 -extern atomic_t fscache_n_retrievals_intr;
46408 -extern atomic_t fscache_n_retrievals_nomem;
46409 -extern atomic_t fscache_n_retrievals_object_dead;
46410 -extern atomic_t fscache_n_retrieval_ops;
46411 -extern atomic_t fscache_n_retrieval_op_waits;
46412 +extern atomic_unchecked_t fscache_n_retrievals;
46413 +extern atomic_unchecked_t fscache_n_retrievals_ok;
46414 +extern atomic_unchecked_t fscache_n_retrievals_wait;
46415 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
46416 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
46417 +extern atomic_unchecked_t fscache_n_retrievals_intr;
46418 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
46419 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
46420 +extern atomic_unchecked_t fscache_n_retrieval_ops;
46421 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
46422
46423 -extern atomic_t fscache_n_stores;
46424 -extern atomic_t fscache_n_stores_ok;
46425 -extern atomic_t fscache_n_stores_again;
46426 -extern atomic_t fscache_n_stores_nobufs;
46427 -extern atomic_t fscache_n_stores_oom;
46428 -extern atomic_t fscache_n_store_ops;
46429 -extern atomic_t fscache_n_store_calls;
46430 -extern atomic_t fscache_n_store_pages;
46431 -extern atomic_t fscache_n_store_radix_deletes;
46432 -extern atomic_t fscache_n_store_pages_over_limit;
46433 +extern atomic_unchecked_t fscache_n_stores;
46434 +extern atomic_unchecked_t fscache_n_stores_ok;
46435 +extern atomic_unchecked_t fscache_n_stores_again;
46436 +extern atomic_unchecked_t fscache_n_stores_nobufs;
46437 +extern atomic_unchecked_t fscache_n_stores_oom;
46438 +extern atomic_unchecked_t fscache_n_store_ops;
46439 +extern atomic_unchecked_t fscache_n_store_calls;
46440 +extern atomic_unchecked_t fscache_n_store_pages;
46441 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
46442 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
46443
46444 -extern atomic_t fscache_n_store_vmscan_not_storing;
46445 -extern atomic_t fscache_n_store_vmscan_gone;
46446 -extern atomic_t fscache_n_store_vmscan_busy;
46447 -extern atomic_t fscache_n_store_vmscan_cancelled;
46448 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46449 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
46450 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
46451 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46452
46453 -extern atomic_t fscache_n_marks;
46454 -extern atomic_t fscache_n_uncaches;
46455 +extern atomic_unchecked_t fscache_n_marks;
46456 +extern atomic_unchecked_t fscache_n_uncaches;
46457
46458 -extern atomic_t fscache_n_acquires;
46459 -extern atomic_t fscache_n_acquires_null;
46460 -extern atomic_t fscache_n_acquires_no_cache;
46461 -extern atomic_t fscache_n_acquires_ok;
46462 -extern atomic_t fscache_n_acquires_nobufs;
46463 -extern atomic_t fscache_n_acquires_oom;
46464 +extern atomic_unchecked_t fscache_n_acquires;
46465 +extern atomic_unchecked_t fscache_n_acquires_null;
46466 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
46467 +extern atomic_unchecked_t fscache_n_acquires_ok;
46468 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
46469 +extern atomic_unchecked_t fscache_n_acquires_oom;
46470
46471 -extern atomic_t fscache_n_updates;
46472 -extern atomic_t fscache_n_updates_null;
46473 -extern atomic_t fscache_n_updates_run;
46474 +extern atomic_unchecked_t fscache_n_updates;
46475 +extern atomic_unchecked_t fscache_n_updates_null;
46476 +extern atomic_unchecked_t fscache_n_updates_run;
46477
46478 -extern atomic_t fscache_n_relinquishes;
46479 -extern atomic_t fscache_n_relinquishes_null;
46480 -extern atomic_t fscache_n_relinquishes_waitcrt;
46481 -extern atomic_t fscache_n_relinquishes_retire;
46482 +extern atomic_unchecked_t fscache_n_relinquishes;
46483 +extern atomic_unchecked_t fscache_n_relinquishes_null;
46484 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46485 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
46486
46487 -extern atomic_t fscache_n_cookie_index;
46488 -extern atomic_t fscache_n_cookie_data;
46489 -extern atomic_t fscache_n_cookie_special;
46490 +extern atomic_unchecked_t fscache_n_cookie_index;
46491 +extern atomic_unchecked_t fscache_n_cookie_data;
46492 +extern atomic_unchecked_t fscache_n_cookie_special;
46493
46494 -extern atomic_t fscache_n_object_alloc;
46495 -extern atomic_t fscache_n_object_no_alloc;
46496 -extern atomic_t fscache_n_object_lookups;
46497 -extern atomic_t fscache_n_object_lookups_negative;
46498 -extern atomic_t fscache_n_object_lookups_positive;
46499 -extern atomic_t fscache_n_object_lookups_timed_out;
46500 -extern atomic_t fscache_n_object_created;
46501 -extern atomic_t fscache_n_object_avail;
46502 -extern atomic_t fscache_n_object_dead;
46503 +extern atomic_unchecked_t fscache_n_object_alloc;
46504 +extern atomic_unchecked_t fscache_n_object_no_alloc;
46505 +extern atomic_unchecked_t fscache_n_object_lookups;
46506 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
46507 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
46508 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
46509 +extern atomic_unchecked_t fscache_n_object_created;
46510 +extern atomic_unchecked_t fscache_n_object_avail;
46511 +extern atomic_unchecked_t fscache_n_object_dead;
46512
46513 -extern atomic_t fscache_n_checkaux_none;
46514 -extern atomic_t fscache_n_checkaux_okay;
46515 -extern atomic_t fscache_n_checkaux_update;
46516 -extern atomic_t fscache_n_checkaux_obsolete;
46517 +extern atomic_unchecked_t fscache_n_checkaux_none;
46518 +extern atomic_unchecked_t fscache_n_checkaux_okay;
46519 +extern atomic_unchecked_t fscache_n_checkaux_update;
46520 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
46521
46522 extern atomic_t fscache_n_cop_alloc_object;
46523 extern atomic_t fscache_n_cop_lookup_object;
46524 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
46525 atomic_inc(stat);
46526 }
46527
46528 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
46529 +{
46530 + atomic_inc_unchecked(stat);
46531 +}
46532 +
46533 static inline void fscache_stat_d(atomic_t *stat)
46534 {
46535 atomic_dec(stat);
46536 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
46537
46538 #define __fscache_stat(stat) (NULL)
46539 #define fscache_stat(stat) do {} while (0)
46540 +#define fscache_stat_unchecked(stat) do {} while (0)
46541 #define fscache_stat_d(stat) do {} while (0)
46542 #endif
46543
46544 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
46545 index b6b897c..0ffff9c 100644
46546 --- a/fs/fscache/object.c
46547 +++ b/fs/fscache/object.c
46548 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46549 /* update the object metadata on disk */
46550 case FSCACHE_OBJECT_UPDATING:
46551 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
46552 - fscache_stat(&fscache_n_updates_run);
46553 + fscache_stat_unchecked(&fscache_n_updates_run);
46554 fscache_stat(&fscache_n_cop_update_object);
46555 object->cache->ops->update_object(object);
46556 fscache_stat_d(&fscache_n_cop_update_object);
46557 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46558 spin_lock(&object->lock);
46559 object->state = FSCACHE_OBJECT_DEAD;
46560 spin_unlock(&object->lock);
46561 - fscache_stat(&fscache_n_object_dead);
46562 + fscache_stat_unchecked(&fscache_n_object_dead);
46563 goto terminal_transit;
46564
46565 /* handle the parent cache of this object being withdrawn from
46566 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46567 spin_lock(&object->lock);
46568 object->state = FSCACHE_OBJECT_DEAD;
46569 spin_unlock(&object->lock);
46570 - fscache_stat(&fscache_n_object_dead);
46571 + fscache_stat_unchecked(&fscache_n_object_dead);
46572 goto terminal_transit;
46573
46574 /* complain about the object being woken up once it is
46575 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46576 parent->cookie->def->name, cookie->def->name,
46577 object->cache->tag->name);
46578
46579 - fscache_stat(&fscache_n_object_lookups);
46580 + fscache_stat_unchecked(&fscache_n_object_lookups);
46581 fscache_stat(&fscache_n_cop_lookup_object);
46582 ret = object->cache->ops->lookup_object(object);
46583 fscache_stat_d(&fscache_n_cop_lookup_object);
46584 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46585 if (ret == -ETIMEDOUT) {
46586 /* probably stuck behind another object, so move this one to
46587 * the back of the queue */
46588 - fscache_stat(&fscache_n_object_lookups_timed_out);
46589 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
46590 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46591 }
46592
46593 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
46594
46595 spin_lock(&object->lock);
46596 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46597 - fscache_stat(&fscache_n_object_lookups_negative);
46598 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
46599
46600 /* transit here to allow write requests to begin stacking up
46601 * and read requests to begin returning ENODATA */
46602 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
46603 * result, in which case there may be data available */
46604 spin_lock(&object->lock);
46605 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46606 - fscache_stat(&fscache_n_object_lookups_positive);
46607 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
46608
46609 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
46610
46611 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
46612 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46613 } else {
46614 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
46615 - fscache_stat(&fscache_n_object_created);
46616 + fscache_stat_unchecked(&fscache_n_object_created);
46617
46618 object->state = FSCACHE_OBJECT_AVAILABLE;
46619 spin_unlock(&object->lock);
46620 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
46621 fscache_enqueue_dependents(object);
46622
46623 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
46624 - fscache_stat(&fscache_n_object_avail);
46625 + fscache_stat_unchecked(&fscache_n_object_avail);
46626
46627 _leave("");
46628 }
46629 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46630 enum fscache_checkaux result;
46631
46632 if (!object->cookie->def->check_aux) {
46633 - fscache_stat(&fscache_n_checkaux_none);
46634 + fscache_stat_unchecked(&fscache_n_checkaux_none);
46635 return FSCACHE_CHECKAUX_OKAY;
46636 }
46637
46638 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46639 switch (result) {
46640 /* entry okay as is */
46641 case FSCACHE_CHECKAUX_OKAY:
46642 - fscache_stat(&fscache_n_checkaux_okay);
46643 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
46644 break;
46645
46646 /* entry requires update */
46647 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
46648 - fscache_stat(&fscache_n_checkaux_update);
46649 + fscache_stat_unchecked(&fscache_n_checkaux_update);
46650 break;
46651
46652 /* entry requires deletion */
46653 case FSCACHE_CHECKAUX_OBSOLETE:
46654 - fscache_stat(&fscache_n_checkaux_obsolete);
46655 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
46656 break;
46657
46658 default:
46659 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
46660 index 30afdfa..2256596 100644
46661 --- a/fs/fscache/operation.c
46662 +++ b/fs/fscache/operation.c
46663 @@ -17,7 +17,7 @@
46664 #include <linux/slab.h>
46665 #include "internal.h"
46666
46667 -atomic_t fscache_op_debug_id;
46668 +atomic_unchecked_t fscache_op_debug_id;
46669 EXPORT_SYMBOL(fscache_op_debug_id);
46670
46671 /**
46672 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
46673 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
46674 ASSERTCMP(atomic_read(&op->usage), >, 0);
46675
46676 - fscache_stat(&fscache_n_op_enqueue);
46677 + fscache_stat_unchecked(&fscache_n_op_enqueue);
46678 switch (op->flags & FSCACHE_OP_TYPE) {
46679 case FSCACHE_OP_ASYNC:
46680 _debug("queue async");
46681 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
46682 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
46683 if (op->processor)
46684 fscache_enqueue_operation(op);
46685 - fscache_stat(&fscache_n_op_run);
46686 + fscache_stat_unchecked(&fscache_n_op_run);
46687 }
46688
46689 /*
46690 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46691 if (object->n_ops > 1) {
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 } else if (!list_empty(&object->pending_ops)) {
46697 atomic_inc(&op->usage);
46698 list_add_tail(&op->pend_link, &object->pending_ops);
46699 - fscache_stat(&fscache_n_op_pend);
46700 + fscache_stat_unchecked(&fscache_n_op_pend);
46701 fscache_start_operations(object);
46702 } else {
46703 ASSERTCMP(object->n_in_progress, ==, 0);
46704 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46705 object->n_exclusive++; /* reads and writes must wait */
46706 atomic_inc(&op->usage);
46707 list_add_tail(&op->pend_link, &object->pending_ops);
46708 - fscache_stat(&fscache_n_op_pend);
46709 + fscache_stat_unchecked(&fscache_n_op_pend);
46710 ret = 0;
46711 } else {
46712 /* not allowed to submit ops in any other state */
46713 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
46714 if (object->n_exclusive > 0) {
46715 atomic_inc(&op->usage);
46716 list_add_tail(&op->pend_link, &object->pending_ops);
46717 - fscache_stat(&fscache_n_op_pend);
46718 + fscache_stat_unchecked(&fscache_n_op_pend);
46719 } else if (!list_empty(&object->pending_ops)) {
46720 atomic_inc(&op->usage);
46721 list_add_tail(&op->pend_link, &object->pending_ops);
46722 - fscache_stat(&fscache_n_op_pend);
46723 + fscache_stat_unchecked(&fscache_n_op_pend);
46724 fscache_start_operations(object);
46725 } else {
46726 ASSERTCMP(object->n_exclusive, ==, 0);
46727 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
46728 object->n_ops++;
46729 atomic_inc(&op->usage);
46730 list_add_tail(&op->pend_link, &object->pending_ops);
46731 - fscache_stat(&fscache_n_op_pend);
46732 + fscache_stat_unchecked(&fscache_n_op_pend);
46733 ret = 0;
46734 } else if (object->state == FSCACHE_OBJECT_DYING ||
46735 object->state == FSCACHE_OBJECT_LC_DYING ||
46736 object->state == FSCACHE_OBJECT_WITHDRAWING) {
46737 - fscache_stat(&fscache_n_op_rejected);
46738 + fscache_stat_unchecked(&fscache_n_op_rejected);
46739 ret = -ENOBUFS;
46740 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
46741 fscache_report_unexpected_submission(object, op, ostate);
46742 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
46743
46744 ret = -EBUSY;
46745 if (!list_empty(&op->pend_link)) {
46746 - fscache_stat(&fscache_n_op_cancelled);
46747 + fscache_stat_unchecked(&fscache_n_op_cancelled);
46748 list_del_init(&op->pend_link);
46749 object->n_ops--;
46750 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
46751 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
46752 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
46753 BUG();
46754
46755 - fscache_stat(&fscache_n_op_release);
46756 + fscache_stat_unchecked(&fscache_n_op_release);
46757
46758 if (op->release) {
46759 op->release(op);
46760 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
46761 * lock, and defer it otherwise */
46762 if (!spin_trylock(&object->lock)) {
46763 _debug("defer put");
46764 - fscache_stat(&fscache_n_op_deferred_release);
46765 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
46766
46767 cache = object->cache;
46768 spin_lock(&cache->op_gc_list_lock);
46769 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
46770
46771 _debug("GC DEFERRED REL OBJ%x OP%x",
46772 object->debug_id, op->debug_id);
46773 - fscache_stat(&fscache_n_op_gc);
46774 + fscache_stat_unchecked(&fscache_n_op_gc);
46775
46776 ASSERTCMP(atomic_read(&op->usage), ==, 0);
46777
46778 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
46779 index 3f7a59b..cf196cc 100644
46780 --- a/fs/fscache/page.c
46781 +++ b/fs/fscache/page.c
46782 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46783 val = radix_tree_lookup(&cookie->stores, page->index);
46784 if (!val) {
46785 rcu_read_unlock();
46786 - fscache_stat(&fscache_n_store_vmscan_not_storing);
46787 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
46788 __fscache_uncache_page(cookie, page);
46789 return true;
46790 }
46791 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46792 spin_unlock(&cookie->stores_lock);
46793
46794 if (xpage) {
46795 - fscache_stat(&fscache_n_store_vmscan_cancelled);
46796 - fscache_stat(&fscache_n_store_radix_deletes);
46797 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
46798 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46799 ASSERTCMP(xpage, ==, page);
46800 } else {
46801 - fscache_stat(&fscache_n_store_vmscan_gone);
46802 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
46803 }
46804
46805 wake_up_bit(&cookie->flags, 0);
46806 @@ -107,7 +107,7 @@ page_busy:
46807 /* we might want to wait here, but that could deadlock the allocator as
46808 * the work threads writing to the cache may all end up sleeping
46809 * on memory allocation */
46810 - fscache_stat(&fscache_n_store_vmscan_busy);
46811 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
46812 return false;
46813 }
46814 EXPORT_SYMBOL(__fscache_maybe_release_page);
46815 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
46816 FSCACHE_COOKIE_STORING_TAG);
46817 if (!radix_tree_tag_get(&cookie->stores, page->index,
46818 FSCACHE_COOKIE_PENDING_TAG)) {
46819 - fscache_stat(&fscache_n_store_radix_deletes);
46820 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46821 xpage = radix_tree_delete(&cookie->stores, page->index);
46822 }
46823 spin_unlock(&cookie->stores_lock);
46824 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
46825
46826 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
46827
46828 - fscache_stat(&fscache_n_attr_changed_calls);
46829 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
46830
46831 if (fscache_object_is_active(object)) {
46832 fscache_stat(&fscache_n_cop_attr_changed);
46833 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46834
46835 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46836
46837 - fscache_stat(&fscache_n_attr_changed);
46838 + fscache_stat_unchecked(&fscache_n_attr_changed);
46839
46840 op = kzalloc(sizeof(*op), GFP_KERNEL);
46841 if (!op) {
46842 - fscache_stat(&fscache_n_attr_changed_nomem);
46843 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
46844 _leave(" = -ENOMEM");
46845 return -ENOMEM;
46846 }
46847 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46848 if (fscache_submit_exclusive_op(object, op) < 0)
46849 goto nobufs;
46850 spin_unlock(&cookie->lock);
46851 - fscache_stat(&fscache_n_attr_changed_ok);
46852 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
46853 fscache_put_operation(op);
46854 _leave(" = 0");
46855 return 0;
46856 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46857 nobufs:
46858 spin_unlock(&cookie->lock);
46859 kfree(op);
46860 - fscache_stat(&fscache_n_attr_changed_nobufs);
46861 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
46862 _leave(" = %d", -ENOBUFS);
46863 return -ENOBUFS;
46864 }
46865 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
46866 /* allocate a retrieval operation and attempt to submit it */
46867 op = kzalloc(sizeof(*op), GFP_NOIO);
46868 if (!op) {
46869 - fscache_stat(&fscache_n_retrievals_nomem);
46870 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46871 return NULL;
46872 }
46873
46874 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46875 return 0;
46876 }
46877
46878 - fscache_stat(&fscache_n_retrievals_wait);
46879 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
46880
46881 jif = jiffies;
46882 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
46883 fscache_wait_bit_interruptible,
46884 TASK_INTERRUPTIBLE) != 0) {
46885 - fscache_stat(&fscache_n_retrievals_intr);
46886 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46887 _leave(" = -ERESTARTSYS");
46888 return -ERESTARTSYS;
46889 }
46890 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46891 */
46892 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46893 struct fscache_retrieval *op,
46894 - atomic_t *stat_op_waits,
46895 - atomic_t *stat_object_dead)
46896 + atomic_unchecked_t *stat_op_waits,
46897 + atomic_unchecked_t *stat_object_dead)
46898 {
46899 int ret;
46900
46901 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46902 goto check_if_dead;
46903
46904 _debug(">>> WT");
46905 - fscache_stat(stat_op_waits);
46906 + fscache_stat_unchecked(stat_op_waits);
46907 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
46908 fscache_wait_bit_interruptible,
46909 TASK_INTERRUPTIBLE) < 0) {
46910 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46911
46912 check_if_dead:
46913 if (unlikely(fscache_object_is_dead(object))) {
46914 - fscache_stat(stat_object_dead);
46915 + fscache_stat_unchecked(stat_object_dead);
46916 return -ENOBUFS;
46917 }
46918 return 0;
46919 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46920
46921 _enter("%p,%p,,,", cookie, page);
46922
46923 - fscache_stat(&fscache_n_retrievals);
46924 + fscache_stat_unchecked(&fscache_n_retrievals);
46925
46926 if (hlist_empty(&cookie->backing_objects))
46927 goto nobufs;
46928 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46929 goto nobufs_unlock;
46930 spin_unlock(&cookie->lock);
46931
46932 - fscache_stat(&fscache_n_retrieval_ops);
46933 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46934
46935 /* pin the netfs read context in case we need to do the actual netfs
46936 * read because we've encountered a cache read failure */
46937 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46938
46939 error:
46940 if (ret == -ENOMEM)
46941 - fscache_stat(&fscache_n_retrievals_nomem);
46942 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46943 else if (ret == -ERESTARTSYS)
46944 - fscache_stat(&fscache_n_retrievals_intr);
46945 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46946 else if (ret == -ENODATA)
46947 - fscache_stat(&fscache_n_retrievals_nodata);
46948 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46949 else if (ret < 0)
46950 - fscache_stat(&fscache_n_retrievals_nobufs);
46951 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46952 else
46953 - fscache_stat(&fscache_n_retrievals_ok);
46954 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46955
46956 fscache_put_retrieval(op);
46957 _leave(" = %d", ret);
46958 @@ -429,7 +429,7 @@ nobufs_unlock:
46959 spin_unlock(&cookie->lock);
46960 kfree(op);
46961 nobufs:
46962 - fscache_stat(&fscache_n_retrievals_nobufs);
46963 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46964 _leave(" = -ENOBUFS");
46965 return -ENOBUFS;
46966 }
46967 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46968
46969 _enter("%p,,%d,,,", cookie, *nr_pages);
46970
46971 - fscache_stat(&fscache_n_retrievals);
46972 + fscache_stat_unchecked(&fscache_n_retrievals);
46973
46974 if (hlist_empty(&cookie->backing_objects))
46975 goto nobufs;
46976 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46977 goto nobufs_unlock;
46978 spin_unlock(&cookie->lock);
46979
46980 - fscache_stat(&fscache_n_retrieval_ops);
46981 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46982
46983 /* pin the netfs read context in case we need to do the actual netfs
46984 * read because we've encountered a cache read failure */
46985 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46986
46987 error:
46988 if (ret == -ENOMEM)
46989 - fscache_stat(&fscache_n_retrievals_nomem);
46990 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46991 else if (ret == -ERESTARTSYS)
46992 - fscache_stat(&fscache_n_retrievals_intr);
46993 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46994 else if (ret == -ENODATA)
46995 - fscache_stat(&fscache_n_retrievals_nodata);
46996 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46997 else if (ret < 0)
46998 - fscache_stat(&fscache_n_retrievals_nobufs);
46999 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
47000 else
47001 - fscache_stat(&fscache_n_retrievals_ok);
47002 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
47003
47004 fscache_put_retrieval(op);
47005 _leave(" = %d", ret);
47006 @@ -545,7 +545,7 @@ nobufs_unlock:
47007 spin_unlock(&cookie->lock);
47008 kfree(op);
47009 nobufs:
47010 - fscache_stat(&fscache_n_retrievals_nobufs);
47011 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
47012 _leave(" = -ENOBUFS");
47013 return -ENOBUFS;
47014 }
47015 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
47016
47017 _enter("%p,%p,,,", cookie, page);
47018
47019 - fscache_stat(&fscache_n_allocs);
47020 + fscache_stat_unchecked(&fscache_n_allocs);
47021
47022 if (hlist_empty(&cookie->backing_objects))
47023 goto nobufs;
47024 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
47025 goto nobufs_unlock;
47026 spin_unlock(&cookie->lock);
47027
47028 - fscache_stat(&fscache_n_alloc_ops);
47029 + fscache_stat_unchecked(&fscache_n_alloc_ops);
47030
47031 ret = fscache_wait_for_retrieval_activation(
47032 object, op,
47033 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
47034
47035 error:
47036 if (ret == -ERESTARTSYS)
47037 - fscache_stat(&fscache_n_allocs_intr);
47038 + fscache_stat_unchecked(&fscache_n_allocs_intr);
47039 else if (ret < 0)
47040 - fscache_stat(&fscache_n_allocs_nobufs);
47041 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
47042 else
47043 - fscache_stat(&fscache_n_allocs_ok);
47044 + fscache_stat_unchecked(&fscache_n_allocs_ok);
47045
47046 fscache_put_retrieval(op);
47047 _leave(" = %d", ret);
47048 @@ -625,7 +625,7 @@ nobufs_unlock:
47049 spin_unlock(&cookie->lock);
47050 kfree(op);
47051 nobufs:
47052 - fscache_stat(&fscache_n_allocs_nobufs);
47053 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
47054 _leave(" = -ENOBUFS");
47055 return -ENOBUFS;
47056 }
47057 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
47058
47059 spin_lock(&cookie->stores_lock);
47060
47061 - fscache_stat(&fscache_n_store_calls);
47062 + fscache_stat_unchecked(&fscache_n_store_calls);
47063
47064 /* find a page to store */
47065 page = NULL;
47066 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
47067 page = results[0];
47068 _debug("gang %d [%lx]", n, page->index);
47069 if (page->index > op->store_limit) {
47070 - fscache_stat(&fscache_n_store_pages_over_limit);
47071 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
47072 goto superseded;
47073 }
47074
47075 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
47076 spin_unlock(&cookie->stores_lock);
47077 spin_unlock(&object->lock);
47078
47079 - fscache_stat(&fscache_n_store_pages);
47080 + fscache_stat_unchecked(&fscache_n_store_pages);
47081 fscache_stat(&fscache_n_cop_write_page);
47082 ret = object->cache->ops->write_page(op, page);
47083 fscache_stat_d(&fscache_n_cop_write_page);
47084 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
47085 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
47086 ASSERT(PageFsCache(page));
47087
47088 - fscache_stat(&fscache_n_stores);
47089 + fscache_stat_unchecked(&fscache_n_stores);
47090
47091 op = kzalloc(sizeof(*op), GFP_NOIO);
47092 if (!op)
47093 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
47094 spin_unlock(&cookie->stores_lock);
47095 spin_unlock(&object->lock);
47096
47097 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
47098 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
47099 op->store_limit = object->store_limit;
47100
47101 if (fscache_submit_op(object, &op->op) < 0)
47102 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
47103
47104 spin_unlock(&cookie->lock);
47105 radix_tree_preload_end();
47106 - fscache_stat(&fscache_n_store_ops);
47107 - fscache_stat(&fscache_n_stores_ok);
47108 + fscache_stat_unchecked(&fscache_n_store_ops);
47109 + fscache_stat_unchecked(&fscache_n_stores_ok);
47110
47111 /* the work queue now carries its own ref on the object */
47112 fscache_put_operation(&op->op);
47113 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
47114 return 0;
47115
47116 already_queued:
47117 - fscache_stat(&fscache_n_stores_again);
47118 + fscache_stat_unchecked(&fscache_n_stores_again);
47119 already_pending:
47120 spin_unlock(&cookie->stores_lock);
47121 spin_unlock(&object->lock);
47122 spin_unlock(&cookie->lock);
47123 radix_tree_preload_end();
47124 kfree(op);
47125 - fscache_stat(&fscache_n_stores_ok);
47126 + fscache_stat_unchecked(&fscache_n_stores_ok);
47127 _leave(" = 0");
47128 return 0;
47129
47130 @@ -851,14 +851,14 @@ nobufs:
47131 spin_unlock(&cookie->lock);
47132 radix_tree_preload_end();
47133 kfree(op);
47134 - fscache_stat(&fscache_n_stores_nobufs);
47135 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
47136 _leave(" = -ENOBUFS");
47137 return -ENOBUFS;
47138
47139 nomem_free:
47140 kfree(op);
47141 nomem:
47142 - fscache_stat(&fscache_n_stores_oom);
47143 + fscache_stat_unchecked(&fscache_n_stores_oom);
47144 _leave(" = -ENOMEM");
47145 return -ENOMEM;
47146 }
47147 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
47148 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
47149 ASSERTCMP(page, !=, NULL);
47150
47151 - fscache_stat(&fscache_n_uncaches);
47152 + fscache_stat_unchecked(&fscache_n_uncaches);
47153
47154 /* cache withdrawal may beat us to it */
47155 if (!PageFsCache(page))
47156 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
47157 unsigned long loop;
47158
47159 #ifdef CONFIG_FSCACHE_STATS
47160 - atomic_add(pagevec->nr, &fscache_n_marks);
47161 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
47162 #endif
47163
47164 for (loop = 0; loop < pagevec->nr; loop++) {
47165 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
47166 index 4765190..2a067f2 100644
47167 --- a/fs/fscache/stats.c
47168 +++ b/fs/fscache/stats.c
47169 @@ -18,95 +18,95 @@
47170 /*
47171 * operation counters
47172 */
47173 -atomic_t fscache_n_op_pend;
47174 -atomic_t fscache_n_op_run;
47175 -atomic_t fscache_n_op_enqueue;
47176 -atomic_t fscache_n_op_requeue;
47177 -atomic_t fscache_n_op_deferred_release;
47178 -atomic_t fscache_n_op_release;
47179 -atomic_t fscache_n_op_gc;
47180 -atomic_t fscache_n_op_cancelled;
47181 -atomic_t fscache_n_op_rejected;
47182 +atomic_unchecked_t fscache_n_op_pend;
47183 +atomic_unchecked_t fscache_n_op_run;
47184 +atomic_unchecked_t fscache_n_op_enqueue;
47185 +atomic_unchecked_t fscache_n_op_requeue;
47186 +atomic_unchecked_t fscache_n_op_deferred_release;
47187 +atomic_unchecked_t fscache_n_op_release;
47188 +atomic_unchecked_t fscache_n_op_gc;
47189 +atomic_unchecked_t fscache_n_op_cancelled;
47190 +atomic_unchecked_t fscache_n_op_rejected;
47191
47192 -atomic_t fscache_n_attr_changed;
47193 -atomic_t fscache_n_attr_changed_ok;
47194 -atomic_t fscache_n_attr_changed_nobufs;
47195 -atomic_t fscache_n_attr_changed_nomem;
47196 -atomic_t fscache_n_attr_changed_calls;
47197 +atomic_unchecked_t fscache_n_attr_changed;
47198 +atomic_unchecked_t fscache_n_attr_changed_ok;
47199 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
47200 +atomic_unchecked_t fscache_n_attr_changed_nomem;
47201 +atomic_unchecked_t fscache_n_attr_changed_calls;
47202
47203 -atomic_t fscache_n_allocs;
47204 -atomic_t fscache_n_allocs_ok;
47205 -atomic_t fscache_n_allocs_wait;
47206 -atomic_t fscache_n_allocs_nobufs;
47207 -atomic_t fscache_n_allocs_intr;
47208 -atomic_t fscache_n_allocs_object_dead;
47209 -atomic_t fscache_n_alloc_ops;
47210 -atomic_t fscache_n_alloc_op_waits;
47211 +atomic_unchecked_t fscache_n_allocs;
47212 +atomic_unchecked_t fscache_n_allocs_ok;
47213 +atomic_unchecked_t fscache_n_allocs_wait;
47214 +atomic_unchecked_t fscache_n_allocs_nobufs;
47215 +atomic_unchecked_t fscache_n_allocs_intr;
47216 +atomic_unchecked_t fscache_n_allocs_object_dead;
47217 +atomic_unchecked_t fscache_n_alloc_ops;
47218 +atomic_unchecked_t fscache_n_alloc_op_waits;
47219
47220 -atomic_t fscache_n_retrievals;
47221 -atomic_t fscache_n_retrievals_ok;
47222 -atomic_t fscache_n_retrievals_wait;
47223 -atomic_t fscache_n_retrievals_nodata;
47224 -atomic_t fscache_n_retrievals_nobufs;
47225 -atomic_t fscache_n_retrievals_intr;
47226 -atomic_t fscache_n_retrievals_nomem;
47227 -atomic_t fscache_n_retrievals_object_dead;
47228 -atomic_t fscache_n_retrieval_ops;
47229 -atomic_t fscache_n_retrieval_op_waits;
47230 +atomic_unchecked_t fscache_n_retrievals;
47231 +atomic_unchecked_t fscache_n_retrievals_ok;
47232 +atomic_unchecked_t fscache_n_retrievals_wait;
47233 +atomic_unchecked_t fscache_n_retrievals_nodata;
47234 +atomic_unchecked_t fscache_n_retrievals_nobufs;
47235 +atomic_unchecked_t fscache_n_retrievals_intr;
47236 +atomic_unchecked_t fscache_n_retrievals_nomem;
47237 +atomic_unchecked_t fscache_n_retrievals_object_dead;
47238 +atomic_unchecked_t fscache_n_retrieval_ops;
47239 +atomic_unchecked_t fscache_n_retrieval_op_waits;
47240
47241 -atomic_t fscache_n_stores;
47242 -atomic_t fscache_n_stores_ok;
47243 -atomic_t fscache_n_stores_again;
47244 -atomic_t fscache_n_stores_nobufs;
47245 -atomic_t fscache_n_stores_oom;
47246 -atomic_t fscache_n_store_ops;
47247 -atomic_t fscache_n_store_calls;
47248 -atomic_t fscache_n_store_pages;
47249 -atomic_t fscache_n_store_radix_deletes;
47250 -atomic_t fscache_n_store_pages_over_limit;
47251 +atomic_unchecked_t fscache_n_stores;
47252 +atomic_unchecked_t fscache_n_stores_ok;
47253 +atomic_unchecked_t fscache_n_stores_again;
47254 +atomic_unchecked_t fscache_n_stores_nobufs;
47255 +atomic_unchecked_t fscache_n_stores_oom;
47256 +atomic_unchecked_t fscache_n_store_ops;
47257 +atomic_unchecked_t fscache_n_store_calls;
47258 +atomic_unchecked_t fscache_n_store_pages;
47259 +atomic_unchecked_t fscache_n_store_radix_deletes;
47260 +atomic_unchecked_t fscache_n_store_pages_over_limit;
47261
47262 -atomic_t fscache_n_store_vmscan_not_storing;
47263 -atomic_t fscache_n_store_vmscan_gone;
47264 -atomic_t fscache_n_store_vmscan_busy;
47265 -atomic_t fscache_n_store_vmscan_cancelled;
47266 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
47267 +atomic_unchecked_t fscache_n_store_vmscan_gone;
47268 +atomic_unchecked_t fscache_n_store_vmscan_busy;
47269 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
47270
47271 -atomic_t fscache_n_marks;
47272 -atomic_t fscache_n_uncaches;
47273 +atomic_unchecked_t fscache_n_marks;
47274 +atomic_unchecked_t fscache_n_uncaches;
47275
47276 -atomic_t fscache_n_acquires;
47277 -atomic_t fscache_n_acquires_null;
47278 -atomic_t fscache_n_acquires_no_cache;
47279 -atomic_t fscache_n_acquires_ok;
47280 -atomic_t fscache_n_acquires_nobufs;
47281 -atomic_t fscache_n_acquires_oom;
47282 +atomic_unchecked_t fscache_n_acquires;
47283 +atomic_unchecked_t fscache_n_acquires_null;
47284 +atomic_unchecked_t fscache_n_acquires_no_cache;
47285 +atomic_unchecked_t fscache_n_acquires_ok;
47286 +atomic_unchecked_t fscache_n_acquires_nobufs;
47287 +atomic_unchecked_t fscache_n_acquires_oom;
47288
47289 -atomic_t fscache_n_updates;
47290 -atomic_t fscache_n_updates_null;
47291 -atomic_t fscache_n_updates_run;
47292 +atomic_unchecked_t fscache_n_updates;
47293 +atomic_unchecked_t fscache_n_updates_null;
47294 +atomic_unchecked_t fscache_n_updates_run;
47295
47296 -atomic_t fscache_n_relinquishes;
47297 -atomic_t fscache_n_relinquishes_null;
47298 -atomic_t fscache_n_relinquishes_waitcrt;
47299 -atomic_t fscache_n_relinquishes_retire;
47300 +atomic_unchecked_t fscache_n_relinquishes;
47301 +atomic_unchecked_t fscache_n_relinquishes_null;
47302 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
47303 +atomic_unchecked_t fscache_n_relinquishes_retire;
47304
47305 -atomic_t fscache_n_cookie_index;
47306 -atomic_t fscache_n_cookie_data;
47307 -atomic_t fscache_n_cookie_special;
47308 +atomic_unchecked_t fscache_n_cookie_index;
47309 +atomic_unchecked_t fscache_n_cookie_data;
47310 +atomic_unchecked_t fscache_n_cookie_special;
47311
47312 -atomic_t fscache_n_object_alloc;
47313 -atomic_t fscache_n_object_no_alloc;
47314 -atomic_t fscache_n_object_lookups;
47315 -atomic_t fscache_n_object_lookups_negative;
47316 -atomic_t fscache_n_object_lookups_positive;
47317 -atomic_t fscache_n_object_lookups_timed_out;
47318 -atomic_t fscache_n_object_created;
47319 -atomic_t fscache_n_object_avail;
47320 -atomic_t fscache_n_object_dead;
47321 +atomic_unchecked_t fscache_n_object_alloc;
47322 +atomic_unchecked_t fscache_n_object_no_alloc;
47323 +atomic_unchecked_t fscache_n_object_lookups;
47324 +atomic_unchecked_t fscache_n_object_lookups_negative;
47325 +atomic_unchecked_t fscache_n_object_lookups_positive;
47326 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
47327 +atomic_unchecked_t fscache_n_object_created;
47328 +atomic_unchecked_t fscache_n_object_avail;
47329 +atomic_unchecked_t fscache_n_object_dead;
47330
47331 -atomic_t fscache_n_checkaux_none;
47332 -atomic_t fscache_n_checkaux_okay;
47333 -atomic_t fscache_n_checkaux_update;
47334 -atomic_t fscache_n_checkaux_obsolete;
47335 +atomic_unchecked_t fscache_n_checkaux_none;
47336 +atomic_unchecked_t fscache_n_checkaux_okay;
47337 +atomic_unchecked_t fscache_n_checkaux_update;
47338 +atomic_unchecked_t fscache_n_checkaux_obsolete;
47339
47340 atomic_t fscache_n_cop_alloc_object;
47341 atomic_t fscache_n_cop_lookup_object;
47342 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
47343 seq_puts(m, "FS-Cache statistics\n");
47344
47345 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
47346 - atomic_read(&fscache_n_cookie_index),
47347 - atomic_read(&fscache_n_cookie_data),
47348 - atomic_read(&fscache_n_cookie_special));
47349 + atomic_read_unchecked(&fscache_n_cookie_index),
47350 + atomic_read_unchecked(&fscache_n_cookie_data),
47351 + atomic_read_unchecked(&fscache_n_cookie_special));
47352
47353 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
47354 - atomic_read(&fscache_n_object_alloc),
47355 - atomic_read(&fscache_n_object_no_alloc),
47356 - atomic_read(&fscache_n_object_avail),
47357 - atomic_read(&fscache_n_object_dead));
47358 + atomic_read_unchecked(&fscache_n_object_alloc),
47359 + atomic_read_unchecked(&fscache_n_object_no_alloc),
47360 + atomic_read_unchecked(&fscache_n_object_avail),
47361 + atomic_read_unchecked(&fscache_n_object_dead));
47362 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
47363 - atomic_read(&fscache_n_checkaux_none),
47364 - atomic_read(&fscache_n_checkaux_okay),
47365 - atomic_read(&fscache_n_checkaux_update),
47366 - atomic_read(&fscache_n_checkaux_obsolete));
47367 + atomic_read_unchecked(&fscache_n_checkaux_none),
47368 + atomic_read_unchecked(&fscache_n_checkaux_okay),
47369 + atomic_read_unchecked(&fscache_n_checkaux_update),
47370 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
47371
47372 seq_printf(m, "Pages : mrk=%u unc=%u\n",
47373 - atomic_read(&fscache_n_marks),
47374 - atomic_read(&fscache_n_uncaches));
47375 + atomic_read_unchecked(&fscache_n_marks),
47376 + atomic_read_unchecked(&fscache_n_uncaches));
47377
47378 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
47379 " oom=%u\n",
47380 - atomic_read(&fscache_n_acquires),
47381 - atomic_read(&fscache_n_acquires_null),
47382 - atomic_read(&fscache_n_acquires_no_cache),
47383 - atomic_read(&fscache_n_acquires_ok),
47384 - atomic_read(&fscache_n_acquires_nobufs),
47385 - atomic_read(&fscache_n_acquires_oom));
47386 + atomic_read_unchecked(&fscache_n_acquires),
47387 + atomic_read_unchecked(&fscache_n_acquires_null),
47388 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
47389 + atomic_read_unchecked(&fscache_n_acquires_ok),
47390 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
47391 + atomic_read_unchecked(&fscache_n_acquires_oom));
47392
47393 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
47394 - atomic_read(&fscache_n_object_lookups),
47395 - atomic_read(&fscache_n_object_lookups_negative),
47396 - atomic_read(&fscache_n_object_lookups_positive),
47397 - atomic_read(&fscache_n_object_created),
47398 - atomic_read(&fscache_n_object_lookups_timed_out));
47399 + atomic_read_unchecked(&fscache_n_object_lookups),
47400 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
47401 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
47402 + atomic_read_unchecked(&fscache_n_object_created),
47403 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
47404
47405 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
47406 - atomic_read(&fscache_n_updates),
47407 - atomic_read(&fscache_n_updates_null),
47408 - atomic_read(&fscache_n_updates_run));
47409 + atomic_read_unchecked(&fscache_n_updates),
47410 + atomic_read_unchecked(&fscache_n_updates_null),
47411 + atomic_read_unchecked(&fscache_n_updates_run));
47412
47413 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
47414 - atomic_read(&fscache_n_relinquishes),
47415 - atomic_read(&fscache_n_relinquishes_null),
47416 - atomic_read(&fscache_n_relinquishes_waitcrt),
47417 - atomic_read(&fscache_n_relinquishes_retire));
47418 + atomic_read_unchecked(&fscache_n_relinquishes),
47419 + atomic_read_unchecked(&fscache_n_relinquishes_null),
47420 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
47421 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
47422
47423 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
47424 - atomic_read(&fscache_n_attr_changed),
47425 - atomic_read(&fscache_n_attr_changed_ok),
47426 - atomic_read(&fscache_n_attr_changed_nobufs),
47427 - atomic_read(&fscache_n_attr_changed_nomem),
47428 - atomic_read(&fscache_n_attr_changed_calls));
47429 + atomic_read_unchecked(&fscache_n_attr_changed),
47430 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
47431 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
47432 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
47433 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
47434
47435 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
47436 - atomic_read(&fscache_n_allocs),
47437 - atomic_read(&fscache_n_allocs_ok),
47438 - atomic_read(&fscache_n_allocs_wait),
47439 - atomic_read(&fscache_n_allocs_nobufs),
47440 - atomic_read(&fscache_n_allocs_intr));
47441 + atomic_read_unchecked(&fscache_n_allocs),
47442 + atomic_read_unchecked(&fscache_n_allocs_ok),
47443 + atomic_read_unchecked(&fscache_n_allocs_wait),
47444 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
47445 + atomic_read_unchecked(&fscache_n_allocs_intr));
47446 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
47447 - atomic_read(&fscache_n_alloc_ops),
47448 - atomic_read(&fscache_n_alloc_op_waits),
47449 - atomic_read(&fscache_n_allocs_object_dead));
47450 + atomic_read_unchecked(&fscache_n_alloc_ops),
47451 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
47452 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
47453
47454 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
47455 " int=%u oom=%u\n",
47456 - atomic_read(&fscache_n_retrievals),
47457 - atomic_read(&fscache_n_retrievals_ok),
47458 - atomic_read(&fscache_n_retrievals_wait),
47459 - atomic_read(&fscache_n_retrievals_nodata),
47460 - atomic_read(&fscache_n_retrievals_nobufs),
47461 - atomic_read(&fscache_n_retrievals_intr),
47462 - atomic_read(&fscache_n_retrievals_nomem));
47463 + atomic_read_unchecked(&fscache_n_retrievals),
47464 + atomic_read_unchecked(&fscache_n_retrievals_ok),
47465 + atomic_read_unchecked(&fscache_n_retrievals_wait),
47466 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
47467 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
47468 + atomic_read_unchecked(&fscache_n_retrievals_intr),
47469 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
47470 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
47471 - atomic_read(&fscache_n_retrieval_ops),
47472 - atomic_read(&fscache_n_retrieval_op_waits),
47473 - atomic_read(&fscache_n_retrievals_object_dead));
47474 + atomic_read_unchecked(&fscache_n_retrieval_ops),
47475 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
47476 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
47477
47478 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
47479 - atomic_read(&fscache_n_stores),
47480 - atomic_read(&fscache_n_stores_ok),
47481 - atomic_read(&fscache_n_stores_again),
47482 - atomic_read(&fscache_n_stores_nobufs),
47483 - atomic_read(&fscache_n_stores_oom));
47484 + atomic_read_unchecked(&fscache_n_stores),
47485 + atomic_read_unchecked(&fscache_n_stores_ok),
47486 + atomic_read_unchecked(&fscache_n_stores_again),
47487 + atomic_read_unchecked(&fscache_n_stores_nobufs),
47488 + atomic_read_unchecked(&fscache_n_stores_oom));
47489 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
47490 - atomic_read(&fscache_n_store_ops),
47491 - atomic_read(&fscache_n_store_calls),
47492 - atomic_read(&fscache_n_store_pages),
47493 - atomic_read(&fscache_n_store_radix_deletes),
47494 - atomic_read(&fscache_n_store_pages_over_limit));
47495 + atomic_read_unchecked(&fscache_n_store_ops),
47496 + atomic_read_unchecked(&fscache_n_store_calls),
47497 + atomic_read_unchecked(&fscache_n_store_pages),
47498 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
47499 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
47500
47501 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
47502 - atomic_read(&fscache_n_store_vmscan_not_storing),
47503 - atomic_read(&fscache_n_store_vmscan_gone),
47504 - atomic_read(&fscache_n_store_vmscan_busy),
47505 - atomic_read(&fscache_n_store_vmscan_cancelled));
47506 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
47507 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
47508 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
47509 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
47510
47511 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
47512 - atomic_read(&fscache_n_op_pend),
47513 - atomic_read(&fscache_n_op_run),
47514 - atomic_read(&fscache_n_op_enqueue),
47515 - atomic_read(&fscache_n_op_cancelled),
47516 - atomic_read(&fscache_n_op_rejected));
47517 + atomic_read_unchecked(&fscache_n_op_pend),
47518 + atomic_read_unchecked(&fscache_n_op_run),
47519 + atomic_read_unchecked(&fscache_n_op_enqueue),
47520 + atomic_read_unchecked(&fscache_n_op_cancelled),
47521 + atomic_read_unchecked(&fscache_n_op_rejected));
47522 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
47523 - atomic_read(&fscache_n_op_deferred_release),
47524 - atomic_read(&fscache_n_op_release),
47525 - atomic_read(&fscache_n_op_gc));
47526 + atomic_read_unchecked(&fscache_n_op_deferred_release),
47527 + atomic_read_unchecked(&fscache_n_op_release),
47528 + atomic_read_unchecked(&fscache_n_op_gc));
47529
47530 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
47531 atomic_read(&fscache_n_cop_alloc_object),
47532 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
47533 index ee8d550..7189d8c 100644
47534 --- a/fs/fuse/cuse.c
47535 +++ b/fs/fuse/cuse.c
47536 @@ -585,10 +585,12 @@ static int __init cuse_init(void)
47537 INIT_LIST_HEAD(&cuse_conntbl[i]);
47538
47539 /* inherit and extend fuse_dev_operations */
47540 - cuse_channel_fops = fuse_dev_operations;
47541 - cuse_channel_fops.owner = THIS_MODULE;
47542 - cuse_channel_fops.open = cuse_channel_open;
47543 - cuse_channel_fops.release = cuse_channel_release;
47544 + pax_open_kernel();
47545 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
47546 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
47547 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
47548 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
47549 + pax_close_kernel();
47550
47551 cuse_class = class_create(THIS_MODULE, "cuse");
47552 if (IS_ERR(cuse_class))
47553 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
47554 index f4246cf..b4aed1d 100644
47555 --- a/fs/fuse/dev.c
47556 +++ b/fs/fuse/dev.c
47557 @@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
47558 ret = 0;
47559 pipe_lock(pipe);
47560
47561 - if (!pipe->readers) {
47562 + if (!atomic_read(&pipe->readers)) {
47563 send_sig(SIGPIPE, current, 0);
47564 if (!ret)
47565 ret = -EPIPE;
47566 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
47567 index 324bc08..4fdd56e 100644
47568 --- a/fs/fuse/dir.c
47569 +++ b/fs/fuse/dir.c
47570 @@ -1226,7 +1226,7 @@ static char *read_link(struct dentry *dentry)
47571 return link;
47572 }
47573
47574 -static void free_link(char *link)
47575 +static void free_link(const char *link)
47576 {
47577 if (!IS_ERR(link))
47578 free_page((unsigned long) link);
47579 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
47580 index 753af3d..f7b021a 100644
47581 --- a/fs/gfs2/inode.c
47582 +++ b/fs/gfs2/inode.c
47583 @@ -1498,7 +1498,7 @@ out:
47584
47585 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47586 {
47587 - char *s = nd_get_link(nd);
47588 + const char *s = nd_get_link(nd);
47589 if (!IS_ERR(s))
47590 kfree(s);
47591 }
47592 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
47593 index 8349a89..51a0254 100644
47594 --- a/fs/hugetlbfs/inode.c
47595 +++ b/fs/hugetlbfs/inode.c
47596 @@ -920,7 +920,7 @@ static struct file_system_type hugetlbfs_fs_type = {
47597 .kill_sb = kill_litter_super,
47598 };
47599
47600 -static struct vfsmount *hugetlbfs_vfsmount;
47601 +struct vfsmount *hugetlbfs_vfsmount;
47602
47603 static int can_do_hugetlb_shm(void)
47604 {
47605 diff --git a/fs/inode.c b/fs/inode.c
47606 index ac8d904..9f45d40 100644
47607 --- a/fs/inode.c
47608 +++ b/fs/inode.c
47609 @@ -867,8 +867,8 @@ unsigned int get_next_ino(void)
47610
47611 #ifdef CONFIG_SMP
47612 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
47613 - static atomic_t shared_last_ino;
47614 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
47615 + static atomic_unchecked_t shared_last_ino;
47616 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
47617
47618 res = next - LAST_INO_BATCH;
47619 }
47620 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
47621 index 4a6cf28..d3a29d3 100644
47622 --- a/fs/jffs2/erase.c
47623 +++ b/fs/jffs2/erase.c
47624 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
47625 struct jffs2_unknown_node marker = {
47626 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
47627 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47628 - .totlen = cpu_to_je32(c->cleanmarker_size)
47629 + .totlen = cpu_to_je32(c->cleanmarker_size),
47630 + .hdr_crc = cpu_to_je32(0)
47631 };
47632
47633 jffs2_prealloc_raw_node_refs(c, jeb, 1);
47634 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
47635 index a6597d6..41b30ec 100644
47636 --- a/fs/jffs2/wbuf.c
47637 +++ b/fs/jffs2/wbuf.c
47638 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
47639 {
47640 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
47641 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47642 - .totlen = constant_cpu_to_je32(8)
47643 + .totlen = constant_cpu_to_je32(8),
47644 + .hdr_crc = constant_cpu_to_je32(0)
47645 };
47646
47647 /*
47648 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
47649 index c55c745..f67ee56 100644
47650 --- a/fs/jfs/super.c
47651 +++ b/fs/jfs/super.c
47652 @@ -806,7 +806,7 @@ static int __init init_jfs_fs(void)
47653
47654 jfs_inode_cachep =
47655 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
47656 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
47657 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
47658 init_once);
47659 if (jfs_inode_cachep == NULL)
47660 return -ENOMEM;
47661 diff --git a/fs/libfs.c b/fs/libfs.c
47662 index a74cb17..37fcbe4 100644
47663 --- a/fs/libfs.c
47664 +++ b/fs/libfs.c
47665 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47666
47667 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
47668 struct dentry *next;
47669 + char d_name[sizeof(next->d_iname)];
47670 + const unsigned char *name;
47671 +
47672 next = list_entry(p, struct dentry, d_u.d_child);
47673 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
47674 if (!simple_positive(next)) {
47675 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47676
47677 spin_unlock(&next->d_lock);
47678 spin_unlock(&dentry->d_lock);
47679 - if (filldir(dirent, next->d_name.name,
47680 + name = next->d_name.name;
47681 + if (name == next->d_iname) {
47682 + memcpy(d_name, name, next->d_name.len);
47683 + name = d_name;
47684 + }
47685 + if (filldir(dirent, name,
47686 next->d_name.len, filp->f_pos,
47687 next->d_inode->i_ino,
47688 dt_type(next->d_inode)) < 0)
47689 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
47690 index 05d2912..760abfa 100644
47691 --- a/fs/lockd/clntproc.c
47692 +++ b/fs/lockd/clntproc.c
47693 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
47694 /*
47695 * Cookie counter for NLM requests
47696 */
47697 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
47698 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
47699
47700 void nlmclnt_next_cookie(struct nlm_cookie *c)
47701 {
47702 - u32 cookie = atomic_inc_return(&nlm_cookie);
47703 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
47704
47705 memcpy(c->data, &cookie, 4);
47706 c->len=4;
47707 diff --git a/fs/locks.c b/fs/locks.c
47708 index 7e81bfc..c3649aa 100644
47709 --- a/fs/locks.c
47710 +++ b/fs/locks.c
47711 @@ -2066,16 +2066,16 @@ void locks_remove_flock(struct file *filp)
47712 return;
47713
47714 if (filp->f_op && filp->f_op->flock) {
47715 - struct file_lock fl = {
47716 + struct file_lock flock = {
47717 .fl_pid = current->tgid,
47718 .fl_file = filp,
47719 .fl_flags = FL_FLOCK,
47720 .fl_type = F_UNLCK,
47721 .fl_end = OFFSET_MAX,
47722 };
47723 - filp->f_op->flock(filp, F_SETLKW, &fl);
47724 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
47725 - fl.fl_ops->fl_release_private(&fl);
47726 + filp->f_op->flock(filp, F_SETLKW, &flock);
47727 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
47728 + flock.fl_ops->fl_release_private(&flock);
47729 }
47730
47731 lock_flocks();
47732 diff --git a/fs/namei.c b/fs/namei.c
47733 index 091c4b7..fbcb268 100644
47734 --- a/fs/namei.c
47735 +++ b/fs/namei.c
47736 @@ -265,16 +265,32 @@ int generic_permission(struct inode *inode, int mask)
47737 if (ret != -EACCES)
47738 return ret;
47739
47740 +#ifdef CONFIG_GRKERNSEC
47741 + /* we'll block if we have to log due to a denied capability use */
47742 + if (mask & MAY_NOT_BLOCK)
47743 + return -ECHILD;
47744 +#endif
47745 +
47746 if (S_ISDIR(inode->i_mode)) {
47747 /* DACs are overridable for directories */
47748 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
47749 - return 0;
47750 if (!(mask & MAY_WRITE))
47751 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47752 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47753 + inode_capable(inode, CAP_DAC_READ_SEARCH))
47754 return 0;
47755 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
47756 + return 0;
47757 return -EACCES;
47758 }
47759 /*
47760 + * Searching includes executable on directories, else just read.
47761 + */
47762 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47763 + if (mask == MAY_READ)
47764 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47765 + inode_capable(inode, CAP_DAC_READ_SEARCH))
47766 + return 0;
47767 +
47768 + /*
47769 * Read/write DACs are always overridable.
47770 * Executable DACs are overridable when there is
47771 * at least one exec bit set.
47772 @@ -283,14 +299,6 @@ int generic_permission(struct inode *inode, int mask)
47773 if (inode_capable(inode, CAP_DAC_OVERRIDE))
47774 return 0;
47775
47776 - /*
47777 - * Searching includes executable on directories, else just read.
47778 - */
47779 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47780 - if (mask == MAY_READ)
47781 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47782 - return 0;
47783 -
47784 return -EACCES;
47785 }
47786
47787 @@ -772,7 +780,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47788 {
47789 struct dentry *dentry = link->dentry;
47790 int error;
47791 - char *s;
47792 + const char *s;
47793
47794 BUG_ON(nd->flags & LOOKUP_RCU);
47795
47796 @@ -793,6 +801,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47797 if (error)
47798 goto out_put_nd_path;
47799
47800 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
47801 + dentry->d_inode, dentry, nd->path.mnt)) {
47802 + error = -EACCES;
47803 + goto out_put_nd_path;
47804 + }
47805 +
47806 nd->last_type = LAST_BIND;
47807 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
47808 error = PTR_ERR(*p);
47809 @@ -1550,6 +1564,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
47810 break;
47811 res = walk_component(nd, path, &nd->last,
47812 nd->last_type, LOOKUP_FOLLOW);
47813 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
47814 + res = -EACCES;
47815 put_link(nd, &link, cookie);
47816 } while (res > 0);
47817
47818 @@ -1648,7 +1664,7 @@ EXPORT_SYMBOL(full_name_hash);
47819 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
47820 {
47821 unsigned long a, b, adata, bdata, mask, hash, len;
47822 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
47823 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
47824
47825 hash = a = 0;
47826 len = -sizeof(unsigned long);
47827 @@ -1943,6 +1959,8 @@ static int path_lookupat(int dfd, const char *name,
47828 if (err)
47829 break;
47830 err = lookup_last(nd, &path);
47831 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
47832 + err = -EACCES;
47833 put_link(nd, &link, cookie);
47834 }
47835 }
47836 @@ -1950,6 +1968,21 @@ static int path_lookupat(int dfd, const char *name,
47837 if (!err)
47838 err = complete_walk(nd);
47839
47840 + if (!(nd->flags & LOOKUP_PARENT)) {
47841 +#ifdef CONFIG_GRKERNSEC
47842 + if (flags & LOOKUP_RCU) {
47843 + if (!err)
47844 + path_put(&nd->path);
47845 + err = -ECHILD;
47846 + } else
47847 +#endif
47848 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47849 + if (!err)
47850 + path_put(&nd->path);
47851 + err = -ENOENT;
47852 + }
47853 + }
47854 +
47855 if (!err && nd->flags & LOOKUP_DIRECTORY) {
47856 if (!nd->inode->i_op->lookup) {
47857 path_put(&nd->path);
47858 @@ -1977,6 +2010,15 @@ static int do_path_lookup(int dfd, const char *name,
47859 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
47860
47861 if (likely(!retval)) {
47862 + if (*name != '/' && nd->path.dentry && nd->inode) {
47863 +#ifdef CONFIG_GRKERNSEC
47864 + if (flags & LOOKUP_RCU)
47865 + return -ECHILD;
47866 +#endif
47867 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
47868 + return -ENOENT;
47869 + }
47870 +
47871 if (unlikely(!audit_dummy_context())) {
47872 if (nd->path.dentry && nd->inode)
47873 audit_inode(name, nd->path.dentry);
47874 @@ -2336,6 +2378,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
47875 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
47876 return -EPERM;
47877
47878 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
47879 + return -EPERM;
47880 + if (gr_handle_rawio(inode))
47881 + return -EPERM;
47882 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
47883 + return -EACCES;
47884 +
47885 return 0;
47886 }
47887
47888 @@ -2557,7 +2606,7 @@ looked_up:
47889 * cleared otherwise prior to returning.
47890 */
47891 static int lookup_open(struct nameidata *nd, struct path *path,
47892 - struct file *file,
47893 + struct path *link, struct file *file,
47894 const struct open_flags *op,
47895 bool got_write, int *opened)
47896 {
47897 @@ -2592,6 +2641,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
47898 /* Negative dentry, just create the file */
47899 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
47900 umode_t mode = op->mode;
47901 +
47902 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
47903 + error = -EACCES;
47904 + goto out_dput;
47905 + }
47906 +
47907 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
47908 + error = -EACCES;
47909 + goto out_dput;
47910 + }
47911 +
47912 if (!IS_POSIXACL(dir->d_inode))
47913 mode &= ~current_umask();
47914 /*
47915 @@ -2613,6 +2673,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
47916 nd->flags & LOOKUP_EXCL);
47917 if (error)
47918 goto out_dput;
47919 + else
47920 + gr_handle_create(dentry, nd->path.mnt);
47921 }
47922 out_no_open:
47923 path->dentry = dentry;
47924 @@ -2627,7 +2689,7 @@ out_dput:
47925 /*
47926 * Handle the last step of open()
47927 */
47928 -static int do_last(struct nameidata *nd, struct path *path,
47929 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
47930 struct file *file, const struct open_flags *op,
47931 int *opened, const char *pathname)
47932 {
47933 @@ -2656,16 +2718,44 @@ static int do_last(struct nameidata *nd, struct path *path,
47934 error = complete_walk(nd);
47935 if (error)
47936 return error;
47937 +#ifdef CONFIG_GRKERNSEC
47938 + if (nd->flags & LOOKUP_RCU) {
47939 + error = -ECHILD;
47940 + goto out;
47941 + }
47942 +#endif
47943 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47944 + error = -ENOENT;
47945 + goto out;
47946 + }
47947 audit_inode(pathname, nd->path.dentry);
47948 if (open_flag & O_CREAT) {
47949 error = -EISDIR;
47950 goto out;
47951 }
47952 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
47953 + error = -EACCES;
47954 + goto out;
47955 + }
47956 goto finish_open;
47957 case LAST_BIND:
47958 error = complete_walk(nd);
47959 if (error)
47960 return error;
47961 +#ifdef CONFIG_GRKERNSEC
47962 + if (nd->flags & LOOKUP_RCU) {
47963 + error = -ECHILD;
47964 + goto out;
47965 + }
47966 +#endif
47967 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
47968 + error = -ENOENT;
47969 + goto out;
47970 + }
47971 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
47972 + error = -EACCES;
47973 + goto out;
47974 + }
47975 audit_inode(pathname, dir);
47976 goto finish_open;
47977 }
47978 @@ -2714,7 +2804,7 @@ retry_lookup:
47979 */
47980 }
47981 mutex_lock(&dir->d_inode->i_mutex);
47982 - error = lookup_open(nd, path, file, op, got_write, opened);
47983 + error = lookup_open(nd, path, link, file, op, got_write, opened);
47984 mutex_unlock(&dir->d_inode->i_mutex);
47985
47986 if (error <= 0) {
47987 @@ -2738,11 +2828,28 @@ retry_lookup:
47988 goto finish_open_created;
47989 }
47990
47991 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
47992 + error = -ENOENT;
47993 + goto exit_dput;
47994 + }
47995 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
47996 + error = -EACCES;
47997 + goto exit_dput;
47998 + }
47999 +
48000 /*
48001 * create/update audit record if it already exists.
48002 */
48003 - if (path->dentry->d_inode)
48004 + if (path->dentry->d_inode) {
48005 + /* only check if O_CREAT is specified, all other checks need to go
48006 + into may_open */
48007 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
48008 + error = -EACCES;
48009 + goto exit_dput;
48010 + }
48011 +
48012 audit_inode(pathname, path->dentry);
48013 + }
48014
48015 /*
48016 * If atomic_open() acquired write access it is dropped now due to
48017 @@ -2783,6 +2890,11 @@ finish_lookup:
48018 }
48019 }
48020 BUG_ON(inode != path->dentry->d_inode);
48021 + /* if we're resolving a symlink to another symlink */
48022 + if (link && gr_handle_symlink_owner(link, inode)) {
48023 + error = -EACCES;
48024 + goto out;
48025 + }
48026 return 1;
48027 }
48028
48029 @@ -2792,7 +2904,6 @@ finish_lookup:
48030 save_parent.dentry = nd->path.dentry;
48031 save_parent.mnt = mntget(path->mnt);
48032 nd->path.dentry = path->dentry;
48033 -
48034 }
48035 nd->inode = inode;
48036 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
48037 @@ -2801,6 +2912,22 @@ finish_lookup:
48038 path_put(&save_parent);
48039 return error;
48040 }
48041 +
48042 +#ifdef CONFIG_GRKERNSEC
48043 + if (nd->flags & LOOKUP_RCU) {
48044 + error = -ECHILD;
48045 + goto out;
48046 + }
48047 +#endif
48048 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
48049 + error = -ENOENT;
48050 + goto out;
48051 + }
48052 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
48053 + error = -EACCES;
48054 + goto out;
48055 + }
48056 +
48057 error = -EISDIR;
48058 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
48059 goto out;
48060 @@ -2899,7 +3026,7 @@ static struct file *path_openat(int dfd, const char *pathname,
48061 if (unlikely(error))
48062 goto out;
48063
48064 - error = do_last(nd, &path, file, op, &opened, pathname);
48065 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
48066 while (unlikely(error > 0)) { /* trailing symlink */
48067 struct path link = path;
48068 void *cookie;
48069 @@ -2917,7 +3044,7 @@ static struct file *path_openat(int dfd, const char *pathname,
48070 error = follow_link(&link, nd, &cookie);
48071 if (unlikely(error))
48072 break;
48073 - error = do_last(nd, &path, file, op, &opened, pathname);
48074 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
48075 put_link(nd, &link, cookie);
48076 }
48077 out:
48078 @@ -3006,8 +3133,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
48079 goto unlock;
48080
48081 error = -EEXIST;
48082 - if (dentry->d_inode)
48083 + if (dentry->d_inode) {
48084 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
48085 + error = -ENOENT;
48086 + }
48087 goto fail;
48088 + }
48089 /*
48090 * Special case - lookup gave negative, but... we had foo/bar/
48091 * From the vfs_mknod() POV we just have a negative dentry -
48092 @@ -3058,6 +3189,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
48093 }
48094 EXPORT_SYMBOL(user_path_create);
48095
48096 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
48097 +{
48098 + char *tmp = getname(pathname);
48099 + struct dentry *res;
48100 + if (IS_ERR(tmp))
48101 + return ERR_CAST(tmp);
48102 + res = kern_path_create(dfd, tmp, path, is_dir);
48103 + if (IS_ERR(res))
48104 + putname(tmp);
48105 + else
48106 + *to = tmp;
48107 + return res;
48108 +}
48109 +
48110 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
48111 {
48112 int error = may_create(dir, dentry);
48113 @@ -3119,6 +3264,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
48114
48115 if (!IS_POSIXACL(path.dentry->d_inode))
48116 mode &= ~current_umask();
48117 +
48118 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
48119 + error = -EPERM;
48120 + goto out;
48121 + }
48122 +
48123 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
48124 + error = -EACCES;
48125 + goto out;
48126 + }
48127 +
48128 error = security_path_mknod(&path, dentry, mode, dev);
48129 if (error)
48130 goto out;
48131 @@ -3135,6 +3291,8 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
48132 break;
48133 }
48134 out:
48135 + if (!error)
48136 + gr_handle_create(dentry, path.mnt);
48137 done_path_create(&path, dentry);
48138 return error;
48139 }
48140 @@ -3181,9 +3339,18 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
48141
48142 if (!IS_POSIXACL(path.dentry->d_inode))
48143 mode &= ~current_umask();
48144 +
48145 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
48146 + error = -EACCES;
48147 + goto out;
48148 + }
48149 +
48150 error = security_path_mkdir(&path, dentry, mode);
48151 if (!error)
48152 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
48153 + if (!error)
48154 + gr_handle_create(dentry, path.mnt);
48155 +out:
48156 done_path_create(&path, dentry);
48157 return error;
48158 }
48159 @@ -3260,6 +3427,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
48160 char * name;
48161 struct dentry *dentry;
48162 struct nameidata nd;
48163 + ino_t saved_ino = 0;
48164 + dev_t saved_dev = 0;
48165
48166 error = user_path_parent(dfd, pathname, &nd, &name);
48167 if (error)
48168 @@ -3291,10 +3460,21 @@ static long do_rmdir(int dfd, const char __user *pathname)
48169 error = -ENOENT;
48170 goto exit3;
48171 }
48172 +
48173 + saved_ino = dentry->d_inode->i_ino;
48174 + saved_dev = gr_get_dev_from_dentry(dentry);
48175 +
48176 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
48177 + error = -EACCES;
48178 + goto exit3;
48179 + }
48180 +
48181 error = security_path_rmdir(&nd.path, dentry);
48182 if (error)
48183 goto exit3;
48184 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
48185 + if (!error && (saved_dev || saved_ino))
48186 + gr_handle_delete(saved_ino, saved_dev);
48187 exit3:
48188 dput(dentry);
48189 exit2:
48190 @@ -3356,6 +3536,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
48191 struct dentry *dentry;
48192 struct nameidata nd;
48193 struct inode *inode = NULL;
48194 + ino_t saved_ino = 0;
48195 + dev_t saved_dev = 0;
48196
48197 error = user_path_parent(dfd, pathname, &nd, &name);
48198 if (error)
48199 @@ -3381,10 +3563,22 @@ static long do_unlinkat(int dfd, const char __user *pathname)
48200 if (!inode)
48201 goto slashes;
48202 ihold(inode);
48203 +
48204 + if (inode->i_nlink <= 1) {
48205 + saved_ino = inode->i_ino;
48206 + saved_dev = gr_get_dev_from_dentry(dentry);
48207 + }
48208 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
48209 + error = -EACCES;
48210 + goto exit2;
48211 + }
48212 +
48213 error = security_path_unlink(&nd.path, dentry);
48214 if (error)
48215 goto exit2;
48216 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
48217 + if (!error && (saved_ino || saved_dev))
48218 + gr_handle_delete(saved_ino, saved_dev);
48219 exit2:
48220 dput(dentry);
48221 }
48222 @@ -3456,9 +3650,17 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
48223 if (IS_ERR(dentry))
48224 goto out_putname;
48225
48226 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
48227 + error = -EACCES;
48228 + goto out;
48229 + }
48230 +
48231 error = security_path_symlink(&path, dentry, from);
48232 if (!error)
48233 error = vfs_symlink(path.dentry->d_inode, dentry, from);
48234 + if (!error)
48235 + gr_handle_create(dentry, path.mnt);
48236 +out:
48237 done_path_create(&path, dentry);
48238 out_putname:
48239 putname(from);
48240 @@ -3528,6 +3730,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48241 {
48242 struct dentry *new_dentry;
48243 struct path old_path, new_path;
48244 + char *to = NULL;
48245 int how = 0;
48246 int error;
48247
48248 @@ -3551,7 +3754,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48249 if (error)
48250 return error;
48251
48252 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
48253 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
48254 error = PTR_ERR(new_dentry);
48255 if (IS_ERR(new_dentry))
48256 goto out;
48257 @@ -3562,11 +3765,28 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48258 error = may_linkat(&old_path);
48259 if (unlikely(error))
48260 goto out_dput;
48261 +
48262 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
48263 + old_path.dentry->d_inode,
48264 + old_path.dentry->d_inode->i_mode, to)) {
48265 + error = -EACCES;
48266 + goto out_dput;
48267 + }
48268 +
48269 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
48270 + old_path.dentry, old_path.mnt, to)) {
48271 + error = -EACCES;
48272 + goto out_dput;
48273 + }
48274 +
48275 error = security_path_link(old_path.dentry, &new_path, new_dentry);
48276 if (error)
48277 goto out_dput;
48278 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
48279 + if (!error)
48280 + gr_handle_create(new_dentry, new_path.mnt);
48281 out_dput:
48282 + putname(to);
48283 done_path_create(&new_path, new_dentry);
48284 out:
48285 path_put(&old_path);
48286 @@ -3802,12 +4022,21 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
48287 if (new_dentry == trap)
48288 goto exit5;
48289
48290 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
48291 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
48292 + to);
48293 + if (error)
48294 + goto exit5;
48295 +
48296 error = security_path_rename(&oldnd.path, old_dentry,
48297 &newnd.path, new_dentry);
48298 if (error)
48299 goto exit5;
48300 error = vfs_rename(old_dir->d_inode, old_dentry,
48301 new_dir->d_inode, new_dentry);
48302 + if (!error)
48303 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
48304 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
48305 exit5:
48306 dput(new_dentry);
48307 exit4:
48308 @@ -3832,6 +4061,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
48309
48310 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
48311 {
48312 + char tmpbuf[64];
48313 + const char *newlink;
48314 int len;
48315
48316 len = PTR_ERR(link);
48317 @@ -3841,7 +4072,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
48318 len = strlen(link);
48319 if (len > (unsigned) buflen)
48320 len = buflen;
48321 - if (copy_to_user(buffer, link, len))
48322 +
48323 + if (len < sizeof(tmpbuf)) {
48324 + memcpy(tmpbuf, link, len);
48325 + newlink = tmpbuf;
48326 + } else
48327 + newlink = link;
48328 +
48329 + if (copy_to_user(buffer, newlink, len))
48330 len = -EFAULT;
48331 out:
48332 return len;
48333 diff --git a/fs/namespace.c b/fs/namespace.c
48334 index 7bdf790..eb79c4b 100644
48335 --- a/fs/namespace.c
48336 +++ b/fs/namespace.c
48337 @@ -1212,6 +1212,9 @@ static int do_umount(struct mount *mnt, int flags)
48338 if (!(sb->s_flags & MS_RDONLY))
48339 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
48340 up_write(&sb->s_umount);
48341 +
48342 + gr_log_remount(mnt->mnt_devname, retval);
48343 +
48344 return retval;
48345 }
48346
48347 @@ -1231,6 +1234,9 @@ static int do_umount(struct mount *mnt, int flags)
48348 br_write_unlock(&vfsmount_lock);
48349 up_write(&namespace_sem);
48350 release_mounts(&umount_list);
48351 +
48352 + gr_log_unmount(mnt->mnt_devname, retval);
48353 +
48354 return retval;
48355 }
48356
48357 @@ -2244,6 +2250,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
48358 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
48359 MS_STRICTATIME);
48360
48361 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
48362 + retval = -EPERM;
48363 + goto dput_out;
48364 + }
48365 +
48366 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
48367 + retval = -EPERM;
48368 + goto dput_out;
48369 + }
48370 +
48371 if (flags & MS_REMOUNT)
48372 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
48373 data_page);
48374 @@ -2258,6 +2274,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
48375 dev_name, data_page);
48376 dput_out:
48377 path_put(&path);
48378 +
48379 + gr_log_mount(dev_name, dir_name, retval);
48380 +
48381 return retval;
48382 }
48383
48384 @@ -2516,6 +2535,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
48385 if (error)
48386 goto out2;
48387
48388 + if (gr_handle_chroot_pivot()) {
48389 + error = -EPERM;
48390 + goto out2;
48391 + }
48392 +
48393 get_fs_root(current->fs, &root);
48394 error = lock_mount(&old);
48395 if (error)
48396 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
48397 index 9b47610..066975e 100644
48398 --- a/fs/nfs/inode.c
48399 +++ b/fs/nfs/inode.c
48400 @@ -1026,16 +1026,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
48401 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
48402 }
48403
48404 -static atomic_long_t nfs_attr_generation_counter;
48405 +static atomic_long_unchecked_t nfs_attr_generation_counter;
48406
48407 static unsigned long nfs_read_attr_generation_counter(void)
48408 {
48409 - return atomic_long_read(&nfs_attr_generation_counter);
48410 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
48411 }
48412
48413 unsigned long nfs_inc_attr_generation_counter(void)
48414 {
48415 - return atomic_long_inc_return(&nfs_attr_generation_counter);
48416 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
48417 }
48418
48419 void nfs_fattr_init(struct nfs_fattr *fattr)
48420 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
48421 index a9269f1..5490437 100644
48422 --- a/fs/nfsd/vfs.c
48423 +++ b/fs/nfsd/vfs.c
48424 @@ -941,7 +941,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
48425 } else {
48426 oldfs = get_fs();
48427 set_fs(KERNEL_DS);
48428 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
48429 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
48430 set_fs(oldfs);
48431 }
48432
48433 @@ -1045,7 +1045,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
48434
48435 /* Write the data. */
48436 oldfs = get_fs(); set_fs(KERNEL_DS);
48437 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
48438 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
48439 set_fs(oldfs);
48440 if (host_err < 0)
48441 goto out_nfserr;
48442 @@ -1581,7 +1581,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
48443 */
48444
48445 oldfs = get_fs(); set_fs(KERNEL_DS);
48446 - host_err = inode->i_op->readlink(path.dentry, buf, *lenp);
48447 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
48448 set_fs(oldfs);
48449
48450 if (host_err < 0)
48451 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
48452 index d438036..0ecadde 100644
48453 --- a/fs/notify/fanotify/fanotify_user.c
48454 +++ b/fs/notify/fanotify/fanotify_user.c
48455 @@ -274,7 +274,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
48456 goto out_close_fd;
48457
48458 ret = -EFAULT;
48459 - if (copy_to_user(buf, &fanotify_event_metadata,
48460 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
48461 + copy_to_user(buf, &fanotify_event_metadata,
48462 fanotify_event_metadata.event_len))
48463 goto out_kill_access_response;
48464
48465 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
48466 index c887b13..0fdf472 100644
48467 --- a/fs/notify/notification.c
48468 +++ b/fs/notify/notification.c
48469 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
48470 * get set to 0 so it will never get 'freed'
48471 */
48472 static struct fsnotify_event *q_overflow_event;
48473 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48474 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48475
48476 /**
48477 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
48478 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48479 */
48480 u32 fsnotify_get_cookie(void)
48481 {
48482 - return atomic_inc_return(&fsnotify_sync_cookie);
48483 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
48484 }
48485 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
48486
48487 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
48488 index 99e3610..02c1068 100644
48489 --- a/fs/ntfs/dir.c
48490 +++ b/fs/ntfs/dir.c
48491 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
48492 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
48493 ~(s64)(ndir->itype.index.block_size - 1)));
48494 /* Bounds checks. */
48495 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48496 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48497 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
48498 "inode 0x%lx or driver bug.", vdir->i_ino);
48499 goto err_out;
48500 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
48501 index 1ecf464..e1ff8bf 100644
48502 --- a/fs/ntfs/file.c
48503 +++ b/fs/ntfs/file.c
48504 @@ -2232,6 +2232,6 @@ const struct inode_operations ntfs_file_inode_ops = {
48505 #endif /* NTFS_RW */
48506 };
48507
48508 -const struct file_operations ntfs_empty_file_ops = {};
48509 +const struct file_operations ntfs_empty_file_ops __read_only;
48510
48511 -const struct inode_operations ntfs_empty_inode_ops = {};
48512 +const struct inode_operations ntfs_empty_inode_ops __read_only;
48513 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
48514 index a9f78c7..ed8a381 100644
48515 --- a/fs/ocfs2/localalloc.c
48516 +++ b/fs/ocfs2/localalloc.c
48517 @@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
48518 goto bail;
48519 }
48520
48521 - atomic_inc(&osb->alloc_stats.moves);
48522 + atomic_inc_unchecked(&osb->alloc_stats.moves);
48523
48524 bail:
48525 if (handle)
48526 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
48527 index d355e6e..578d905 100644
48528 --- a/fs/ocfs2/ocfs2.h
48529 +++ b/fs/ocfs2/ocfs2.h
48530 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
48531
48532 struct ocfs2_alloc_stats
48533 {
48534 - atomic_t moves;
48535 - atomic_t local_data;
48536 - atomic_t bitmap_data;
48537 - atomic_t bg_allocs;
48538 - atomic_t bg_extends;
48539 + atomic_unchecked_t moves;
48540 + atomic_unchecked_t local_data;
48541 + atomic_unchecked_t bitmap_data;
48542 + atomic_unchecked_t bg_allocs;
48543 + atomic_unchecked_t bg_extends;
48544 };
48545
48546 enum ocfs2_local_alloc_state
48547 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
48548 index f169da4..9112253 100644
48549 --- a/fs/ocfs2/suballoc.c
48550 +++ b/fs/ocfs2/suballoc.c
48551 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
48552 mlog_errno(status);
48553 goto bail;
48554 }
48555 - atomic_inc(&osb->alloc_stats.bg_extends);
48556 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
48557
48558 /* You should never ask for this much metadata */
48559 BUG_ON(bits_wanted >
48560 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
48561 mlog_errno(status);
48562 goto bail;
48563 }
48564 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48565 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48566
48567 *suballoc_loc = res.sr_bg_blkno;
48568 *suballoc_bit_start = res.sr_bit_offset;
48569 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
48570 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
48571 res->sr_bits);
48572
48573 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48574 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48575
48576 BUG_ON(res->sr_bits != 1);
48577
48578 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
48579 mlog_errno(status);
48580 goto bail;
48581 }
48582 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48583 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48584
48585 BUG_ON(res.sr_bits != 1);
48586
48587 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48588 cluster_start,
48589 num_clusters);
48590 if (!status)
48591 - atomic_inc(&osb->alloc_stats.local_data);
48592 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
48593 } else {
48594 if (min_clusters > (osb->bitmap_cpg - 1)) {
48595 /* The only paths asking for contiguousness
48596 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48597 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
48598 res.sr_bg_blkno,
48599 res.sr_bit_offset);
48600 - atomic_inc(&osb->alloc_stats.bitmap_data);
48601 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
48602 *num_clusters = res.sr_bits;
48603 }
48604 }
48605 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
48606 index 68f4541..89cfe6a 100644
48607 --- a/fs/ocfs2/super.c
48608 +++ b/fs/ocfs2/super.c
48609 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
48610 "%10s => GlobalAllocs: %d LocalAllocs: %d "
48611 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
48612 "Stats",
48613 - atomic_read(&osb->alloc_stats.bitmap_data),
48614 - atomic_read(&osb->alloc_stats.local_data),
48615 - atomic_read(&osb->alloc_stats.bg_allocs),
48616 - atomic_read(&osb->alloc_stats.moves),
48617 - atomic_read(&osb->alloc_stats.bg_extends));
48618 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
48619 + atomic_read_unchecked(&osb->alloc_stats.local_data),
48620 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
48621 + atomic_read_unchecked(&osb->alloc_stats.moves),
48622 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
48623
48624 out += snprintf(buf + out, len - out,
48625 "%10s => State: %u Descriptor: %llu Size: %u bits "
48626 @@ -2116,11 +2116,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
48627 spin_lock_init(&osb->osb_xattr_lock);
48628 ocfs2_init_steal_slots(osb);
48629
48630 - atomic_set(&osb->alloc_stats.moves, 0);
48631 - atomic_set(&osb->alloc_stats.local_data, 0);
48632 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
48633 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
48634 - atomic_set(&osb->alloc_stats.bg_extends, 0);
48635 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
48636 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
48637 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
48638 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
48639 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
48640
48641 /* Copy the blockcheck stats from the superblock probe */
48642 osb->osb_ecc_stats = *stats;
48643 diff --git a/fs/open.c b/fs/open.c
48644 index e1f2cdb..3bd5f39 100644
48645 --- a/fs/open.c
48646 +++ b/fs/open.c
48647 @@ -31,6 +31,8 @@
48648 #include <linux/ima.h>
48649 #include <linux/dnotify.h>
48650
48651 +#define CREATE_TRACE_POINTS
48652 +#include <trace/events/fs.h>
48653 #include "internal.h"
48654
48655 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
48656 @@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
48657 error = locks_verify_truncate(inode, NULL, length);
48658 if (!error)
48659 error = security_path_truncate(&path);
48660 +
48661 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
48662 + error = -EACCES;
48663 +
48664 if (!error)
48665 error = do_truncate(path.dentry, length, 0, NULL);
48666
48667 @@ -364,6 +370,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
48668 if (__mnt_is_readonly(path.mnt))
48669 res = -EROFS;
48670
48671 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
48672 + res = -EACCES;
48673 +
48674 out_path_release:
48675 path_put(&path);
48676 out:
48677 @@ -390,6 +399,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
48678 if (error)
48679 goto dput_and_out;
48680
48681 + gr_log_chdir(path.dentry, path.mnt);
48682 +
48683 set_fs_pwd(current->fs, &path);
48684
48685 dput_and_out:
48686 @@ -416,6 +427,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
48687 goto out_putf;
48688
48689 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
48690 +
48691 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
48692 + error = -EPERM;
48693 +
48694 + if (!error)
48695 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
48696 +
48697 if (!error)
48698 set_fs_pwd(current->fs, &file->f_path);
48699 out_putf:
48700 @@ -444,7 +462,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
48701 if (error)
48702 goto dput_and_out;
48703
48704 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
48705 + goto dput_and_out;
48706 +
48707 set_fs_root(current->fs, &path);
48708 +
48709 + gr_handle_chroot_chdir(&path);
48710 +
48711 error = 0;
48712 dput_and_out:
48713 path_put(&path);
48714 @@ -462,6 +486,16 @@ static int chmod_common(struct path *path, umode_t mode)
48715 if (error)
48716 return error;
48717 mutex_lock(&inode->i_mutex);
48718 +
48719 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
48720 + error = -EACCES;
48721 + goto out_unlock;
48722 + }
48723 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
48724 + error = -EACCES;
48725 + goto out_unlock;
48726 + }
48727 +
48728 error = security_path_chmod(path, mode);
48729 if (error)
48730 goto out_unlock;
48731 @@ -517,6 +551,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
48732 uid = make_kuid(current_user_ns(), user);
48733 gid = make_kgid(current_user_ns(), group);
48734
48735 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
48736 + return -EACCES;
48737 +
48738 newattrs.ia_valid = ATTR_CTIME;
48739 if (user != (uid_t) -1) {
48740 if (!uid_valid(uid))
48741 @@ -958,6 +995,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
48742 } else {
48743 fsnotify_open(f);
48744 fd_install(fd, f);
48745 + trace_do_sys_open(tmp, flags, mode);
48746 }
48747 }
48748 putname(tmp);
48749 diff --git a/fs/pipe.c b/fs/pipe.c
48750 index 8d85d70..581036b 100644
48751 --- a/fs/pipe.c
48752 +++ b/fs/pipe.c
48753 @@ -438,9 +438,9 @@ redo:
48754 }
48755 if (bufs) /* More to do? */
48756 continue;
48757 - if (!pipe->writers)
48758 + if (!atomic_read(&pipe->writers))
48759 break;
48760 - if (!pipe->waiting_writers) {
48761 + if (!atomic_read(&pipe->waiting_writers)) {
48762 /* syscall merging: Usually we must not sleep
48763 * if O_NONBLOCK is set, or if we got some data.
48764 * But if a writer sleeps in kernel space, then
48765 @@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
48766 mutex_lock(&inode->i_mutex);
48767 pipe = inode->i_pipe;
48768
48769 - if (!pipe->readers) {
48770 + if (!atomic_read(&pipe->readers)) {
48771 send_sig(SIGPIPE, current, 0);
48772 ret = -EPIPE;
48773 goto out;
48774 @@ -553,7 +553,7 @@ redo1:
48775 for (;;) {
48776 int bufs;
48777
48778 - if (!pipe->readers) {
48779 + if (!atomic_read(&pipe->readers)) {
48780 send_sig(SIGPIPE, current, 0);
48781 if (!ret)
48782 ret = -EPIPE;
48783 @@ -644,9 +644,9 @@ redo2:
48784 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
48785 do_wakeup = 0;
48786 }
48787 - pipe->waiting_writers++;
48788 + atomic_inc(&pipe->waiting_writers);
48789 pipe_wait(pipe);
48790 - pipe->waiting_writers--;
48791 + atomic_dec(&pipe->waiting_writers);
48792 }
48793 out:
48794 mutex_unlock(&inode->i_mutex);
48795 @@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48796 mask = 0;
48797 if (filp->f_mode & FMODE_READ) {
48798 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
48799 - if (!pipe->writers && filp->f_version != pipe->w_counter)
48800 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
48801 mask |= POLLHUP;
48802 }
48803
48804 @@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48805 * Most Unices do not set POLLERR for FIFOs but on Linux they
48806 * behave exactly like pipes for poll().
48807 */
48808 - if (!pipe->readers)
48809 + if (!atomic_read(&pipe->readers))
48810 mask |= POLLERR;
48811 }
48812
48813 @@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
48814
48815 mutex_lock(&inode->i_mutex);
48816 pipe = inode->i_pipe;
48817 - pipe->readers -= decr;
48818 - pipe->writers -= decw;
48819 + atomic_sub(decr, &pipe->readers);
48820 + atomic_sub(decw, &pipe->writers);
48821
48822 - if (!pipe->readers && !pipe->writers) {
48823 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
48824 free_pipe_info(inode);
48825 } else {
48826 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
48827 @@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
48828
48829 if (inode->i_pipe) {
48830 ret = 0;
48831 - inode->i_pipe->readers++;
48832 + atomic_inc(&inode->i_pipe->readers);
48833 }
48834
48835 mutex_unlock(&inode->i_mutex);
48836 @@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
48837
48838 if (inode->i_pipe) {
48839 ret = 0;
48840 - inode->i_pipe->writers++;
48841 + atomic_inc(&inode->i_pipe->writers);
48842 }
48843
48844 mutex_unlock(&inode->i_mutex);
48845 @@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
48846 if (inode->i_pipe) {
48847 ret = 0;
48848 if (filp->f_mode & FMODE_READ)
48849 - inode->i_pipe->readers++;
48850 + atomic_inc(&inode->i_pipe->readers);
48851 if (filp->f_mode & FMODE_WRITE)
48852 - inode->i_pipe->writers++;
48853 + atomic_inc(&inode->i_pipe->writers);
48854 }
48855
48856 mutex_unlock(&inode->i_mutex);
48857 @@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
48858 inode->i_pipe = NULL;
48859 }
48860
48861 -static struct vfsmount *pipe_mnt __read_mostly;
48862 +struct vfsmount *pipe_mnt __read_mostly;
48863
48864 /*
48865 * pipefs_dname() is called from d_path().
48866 @@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
48867 goto fail_iput;
48868 inode->i_pipe = pipe;
48869
48870 - pipe->readers = pipe->writers = 1;
48871 + atomic_set(&pipe->readers, 1);
48872 + atomic_set(&pipe->writers, 1);
48873 inode->i_fop = &rdwr_pipefifo_fops;
48874
48875 /*
48876 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
48877 index 15af622..0e9f4467 100644
48878 --- a/fs/proc/Kconfig
48879 +++ b/fs/proc/Kconfig
48880 @@ -30,12 +30,12 @@ config PROC_FS
48881
48882 config PROC_KCORE
48883 bool "/proc/kcore support" if !ARM
48884 - depends on PROC_FS && MMU
48885 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
48886
48887 config PROC_VMCORE
48888 bool "/proc/vmcore support"
48889 - depends on PROC_FS && CRASH_DUMP
48890 - default y
48891 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
48892 + default n
48893 help
48894 Exports the dump image of crashed kernel in ELF format.
48895
48896 @@ -59,8 +59,8 @@ config PROC_SYSCTL
48897 limited in memory.
48898
48899 config PROC_PAGE_MONITOR
48900 - default y
48901 - depends on PROC_FS && MMU
48902 + default n
48903 + depends on PROC_FS && MMU && !GRKERNSEC
48904 bool "Enable /proc page monitoring" if EXPERT
48905 help
48906 Various /proc files exist to monitor process memory utilization:
48907 diff --git a/fs/proc/array.c b/fs/proc/array.c
48908 index c1c207c..01ce725 100644
48909 --- a/fs/proc/array.c
48910 +++ b/fs/proc/array.c
48911 @@ -60,6 +60,7 @@
48912 #include <linux/tty.h>
48913 #include <linux/string.h>
48914 #include <linux/mman.h>
48915 +#include <linux/grsecurity.h>
48916 #include <linux/proc_fs.h>
48917 #include <linux/ioport.h>
48918 #include <linux/uaccess.h>
48919 @@ -346,6 +347,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
48920 seq_putc(m, '\n');
48921 }
48922
48923 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48924 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
48925 +{
48926 + if (p->mm)
48927 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
48928 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
48929 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
48930 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
48931 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
48932 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
48933 + else
48934 + seq_printf(m, "PaX:\t-----\n");
48935 +}
48936 +#endif
48937 +
48938 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48939 struct pid *pid, struct task_struct *task)
48940 {
48941 @@ -363,9 +379,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48942 task_cpus_allowed(m, task);
48943 cpuset_task_status_allowed(m, task);
48944 task_context_switch_counts(m, task);
48945 +
48946 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48947 + task_pax(m, task);
48948 +#endif
48949 +
48950 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
48951 + task_grsec_rbac(m, task);
48952 +#endif
48953 +
48954 return 0;
48955 }
48956
48957 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48958 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48959 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48960 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48961 +#endif
48962 +
48963 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48964 struct pid *pid, struct task_struct *task, int whole)
48965 {
48966 @@ -387,6 +418,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48967 char tcomm[sizeof(task->comm)];
48968 unsigned long flags;
48969
48970 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48971 + if (current->exec_id != m->exec_id) {
48972 + gr_log_badprocpid("stat");
48973 + return 0;
48974 + }
48975 +#endif
48976 +
48977 state = *get_task_state(task);
48978 vsize = eip = esp = 0;
48979 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48980 @@ -458,6 +496,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48981 gtime = task->gtime;
48982 }
48983
48984 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48985 + if (PAX_RAND_FLAGS(mm)) {
48986 + eip = 0;
48987 + esp = 0;
48988 + wchan = 0;
48989 + }
48990 +#endif
48991 +#ifdef CONFIG_GRKERNSEC_HIDESYM
48992 + wchan = 0;
48993 + eip =0;
48994 + esp =0;
48995 +#endif
48996 +
48997 /* scale priority and nice values from timeslices to -20..20 */
48998 /* to make it look like a "normal" Unix priority/nice value */
48999 priority = task_prio(task);
49000 @@ -494,9 +545,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49001 seq_put_decimal_ull(m, ' ', vsize);
49002 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
49003 seq_put_decimal_ull(m, ' ', rsslim);
49004 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49005 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
49006 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
49007 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
49008 +#else
49009 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
49010 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
49011 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
49012 +#endif
49013 seq_put_decimal_ull(m, ' ', esp);
49014 seq_put_decimal_ull(m, ' ', eip);
49015 /* The signal information here is obsolete.
49016 @@ -518,7 +575,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49017 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
49018 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
49019
49020 - if (mm && permitted) {
49021 + if (mm && permitted
49022 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49023 + && !PAX_RAND_FLAGS(mm)
49024 +#endif
49025 + ) {
49026 seq_put_decimal_ull(m, ' ', mm->start_data);
49027 seq_put_decimal_ull(m, ' ', mm->end_data);
49028 seq_put_decimal_ull(m, ' ', mm->start_brk);
49029 @@ -556,8 +617,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49030 struct pid *pid, struct task_struct *task)
49031 {
49032 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
49033 - struct mm_struct *mm = get_task_mm(task);
49034 + struct mm_struct *mm;
49035
49036 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49037 + if (current->exec_id != m->exec_id) {
49038 + gr_log_badprocpid("statm");
49039 + return 0;
49040 + }
49041 +#endif
49042 + mm = get_task_mm(task);
49043 if (mm) {
49044 size = task_statm(mm, &shared, &text, &data, &resident);
49045 mmput(mm);
49046 @@ -580,6 +648,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49047 return 0;
49048 }
49049
49050 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49051 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
49052 +{
49053 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
49054 +}
49055 +#endif
49056 +
49057 #ifdef CONFIG_CHECKPOINT_RESTORE
49058 static struct pid *
49059 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
49060 diff --git a/fs/proc/base.c b/fs/proc/base.c
49061 index 1b6c84c..66b738b 100644
49062 --- a/fs/proc/base.c
49063 +++ b/fs/proc/base.c
49064 @@ -110,6 +110,14 @@ struct pid_entry {
49065 union proc_op op;
49066 };
49067
49068 +struct getdents_callback {
49069 + struct linux_dirent __user * current_dir;
49070 + struct linux_dirent __user * previous;
49071 + struct file * file;
49072 + int count;
49073 + int error;
49074 +};
49075 +
49076 #define NOD(NAME, MODE, IOP, FOP, OP) { \
49077 .name = (NAME), \
49078 .len = sizeof(NAME) - 1, \
49079 @@ -209,6 +217,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
49080 if (!mm->arg_end)
49081 goto out_mm; /* Shh! No looking before we're done */
49082
49083 + if (gr_acl_handle_procpidmem(task))
49084 + goto out_mm;
49085 +
49086 len = mm->arg_end - mm->arg_start;
49087
49088 if (len > PAGE_SIZE)
49089 @@ -236,12 +247,28 @@ out:
49090 return res;
49091 }
49092
49093 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49094 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49095 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
49096 + _mm->pax_flags & MF_PAX_SEGMEXEC))
49097 +#endif
49098 +
49099 static int proc_pid_auxv(struct task_struct *task, char *buffer)
49100 {
49101 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
49102 int res = PTR_ERR(mm);
49103 if (mm && !IS_ERR(mm)) {
49104 unsigned int nwords = 0;
49105 +
49106 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49107 + /* allow if we're currently ptracing this task */
49108 + if (PAX_RAND_FLAGS(mm) &&
49109 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
49110 + mmput(mm);
49111 + return 0;
49112 + }
49113 +#endif
49114 +
49115 do {
49116 nwords += 2;
49117 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
49118 @@ -255,7 +282,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
49119 }
49120
49121
49122 -#ifdef CONFIG_KALLSYMS
49123 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49124 /*
49125 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
49126 * Returns the resolved symbol. If that fails, simply return the address.
49127 @@ -294,7 +321,7 @@ static void unlock_trace(struct task_struct *task)
49128 mutex_unlock(&task->signal->cred_guard_mutex);
49129 }
49130
49131 -#ifdef CONFIG_STACKTRACE
49132 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49133
49134 #define MAX_STACK_TRACE_DEPTH 64
49135
49136 @@ -486,7 +513,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
49137 return count;
49138 }
49139
49140 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49141 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49142 static int proc_pid_syscall(struct task_struct *task, char *buffer)
49143 {
49144 long nr;
49145 @@ -515,7 +542,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
49146 /************************************************************************/
49147
49148 /* permission checks */
49149 -static int proc_fd_access_allowed(struct inode *inode)
49150 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
49151 {
49152 struct task_struct *task;
49153 int allowed = 0;
49154 @@ -525,7 +552,10 @@ static int proc_fd_access_allowed(struct inode *inode)
49155 */
49156 task = get_proc_task(inode);
49157 if (task) {
49158 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
49159 + if (log)
49160 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
49161 + else
49162 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
49163 put_task_struct(task);
49164 }
49165 return allowed;
49166 @@ -563,10 +593,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
49167 struct task_struct *task,
49168 int hide_pid_min)
49169 {
49170 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49171 + return false;
49172 +
49173 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49174 + rcu_read_lock();
49175 + {
49176 + const struct cred *tmpcred = current_cred();
49177 + const struct cred *cred = __task_cred(task);
49178 +
49179 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
49180 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49181 + || in_group_p(grsec_proc_gid)
49182 +#endif
49183 + ) {
49184 + rcu_read_unlock();
49185 + return true;
49186 + }
49187 + }
49188 + rcu_read_unlock();
49189 +
49190 + if (!pid->hide_pid)
49191 + return false;
49192 +#endif
49193 +
49194 if (pid->hide_pid < hide_pid_min)
49195 return true;
49196 if (in_group_p(pid->pid_gid))
49197 return true;
49198 +
49199 return ptrace_may_access(task, PTRACE_MODE_READ);
49200 }
49201
49202 @@ -584,7 +639,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
49203 put_task_struct(task);
49204
49205 if (!has_perms) {
49206 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49207 + {
49208 +#else
49209 if (pid->hide_pid == 2) {
49210 +#endif
49211 /*
49212 * Let's make getdents(), stat(), and open()
49213 * consistent with each other. If a process
49214 @@ -682,6 +741,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
49215 if (!task)
49216 return -ESRCH;
49217
49218 + if (gr_acl_handle_procpidmem(task)) {
49219 + put_task_struct(task);
49220 + return -EPERM;
49221 + }
49222 +
49223 mm = mm_access(task, mode);
49224 put_task_struct(task);
49225
49226 @@ -697,6 +761,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
49227
49228 file->private_data = mm;
49229
49230 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49231 + file->f_version = current->exec_id;
49232 +#endif
49233 +
49234 return 0;
49235 }
49236
49237 @@ -718,6 +786,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
49238 ssize_t copied;
49239 char *page;
49240
49241 +#ifdef CONFIG_GRKERNSEC
49242 + if (write)
49243 + return -EPERM;
49244 +#endif
49245 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49246 + if (file->f_version != current->exec_id) {
49247 + gr_log_badprocpid("mem");
49248 + return 0;
49249 + }
49250 +#endif
49251 +
49252 if (!mm)
49253 return 0;
49254
49255 @@ -822,6 +901,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
49256 if (!mm)
49257 return 0;
49258
49259 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49260 + if (file->f_version != current->exec_id) {
49261 + gr_log_badprocpid("environ");
49262 + return 0;
49263 + }
49264 +#endif
49265 +
49266 page = (char *)__get_free_page(GFP_TEMPORARY);
49267 if (!page)
49268 return -ENOMEM;
49269 @@ -1435,7 +1521,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
49270 int error = -EACCES;
49271
49272 /* Are we allowed to snoop on the tasks file descriptors? */
49273 - if (!proc_fd_access_allowed(inode))
49274 + if (!proc_fd_access_allowed(inode, 0))
49275 goto out;
49276
49277 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
49278 @@ -1479,8 +1565,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
49279 struct path path;
49280
49281 /* Are we allowed to snoop on the tasks file descriptors? */
49282 - if (!proc_fd_access_allowed(inode))
49283 - goto out;
49284 + /* logging this is needed for learning on chromium to work properly,
49285 + but we don't want to flood the logs from 'ps' which does a readlink
49286 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
49287 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
49288 + */
49289 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
49290 + if (!proc_fd_access_allowed(inode,0))
49291 + goto out;
49292 + } else {
49293 + if (!proc_fd_access_allowed(inode,1))
49294 + goto out;
49295 + }
49296
49297 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
49298 if (error)
49299 @@ -1545,7 +1641,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
49300 rcu_read_lock();
49301 cred = __task_cred(task);
49302 inode->i_uid = cred->euid;
49303 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49304 + inode->i_gid = grsec_proc_gid;
49305 +#else
49306 inode->i_gid = cred->egid;
49307 +#endif
49308 rcu_read_unlock();
49309 }
49310 security_task_to_inode(task, inode);
49311 @@ -1581,10 +1681,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
49312 return -ENOENT;
49313 }
49314 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49315 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49316 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49317 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49318 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49319 +#endif
49320 task_dumpable(task)) {
49321 cred = __task_cred(task);
49322 stat->uid = cred->euid;
49323 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49324 + stat->gid = grsec_proc_gid;
49325 +#else
49326 stat->gid = cred->egid;
49327 +#endif
49328 }
49329 }
49330 rcu_read_unlock();
49331 @@ -1622,11 +1731,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
49332
49333 if (task) {
49334 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49335 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49336 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49337 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49338 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49339 +#endif
49340 task_dumpable(task)) {
49341 rcu_read_lock();
49342 cred = __task_cred(task);
49343 inode->i_uid = cred->euid;
49344 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49345 + inode->i_gid = grsec_proc_gid;
49346 +#else
49347 inode->i_gid = cred->egid;
49348 +#endif
49349 rcu_read_unlock();
49350 } else {
49351 inode->i_uid = GLOBAL_ROOT_UID;
49352 @@ -1744,7 +1862,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
49353 int fd = proc_fd(inode);
49354
49355 if (task) {
49356 - files = get_files_struct(task);
49357 + if (!gr_acl_handle_procpidmem(task))
49358 + files = get_files_struct(task);
49359 put_task_struct(task);
49360 }
49361 if (files) {
49362 @@ -2343,11 +2462,21 @@ static const struct file_operations proc_map_files_operations = {
49363 */
49364 static int proc_fd_permission(struct inode *inode, int mask)
49365 {
49366 + struct task_struct *task;
49367 int rv = generic_permission(inode, mask);
49368 - if (rv == 0)
49369 - return 0;
49370 +
49371 if (task_pid(current) == proc_pid(inode))
49372 rv = 0;
49373 +
49374 + task = get_proc_task(inode);
49375 + if (task == NULL)
49376 + return rv;
49377 +
49378 + if (gr_acl_handle_procpidmem(task))
49379 + rv = -EACCES;
49380 +
49381 + put_task_struct(task);
49382 +
49383 return rv;
49384 }
49385
49386 @@ -2457,6 +2586,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
49387 if (!task)
49388 goto out_no_task;
49389
49390 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49391 + goto out;
49392 +
49393 /*
49394 * Yes, it does not scale. And it should not. Don't add
49395 * new entries into /proc/<tgid>/ without very good reasons.
49396 @@ -2501,6 +2633,9 @@ static int proc_pident_readdir(struct file *filp,
49397 if (!task)
49398 goto out_no_task;
49399
49400 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49401 + goto out;
49402 +
49403 ret = 0;
49404 i = filp->f_pos;
49405 switch (i) {
49406 @@ -2771,7 +2906,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
49407 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
49408 void *cookie)
49409 {
49410 - char *s = nd_get_link(nd);
49411 + const char *s = nd_get_link(nd);
49412 if (!IS_ERR(s))
49413 __putname(s);
49414 }
49415 @@ -3040,7 +3175,7 @@ static const struct pid_entry tgid_base_stuff[] = {
49416 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
49417 #endif
49418 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49419 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49420 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49421 INF("syscall", S_IRUGO, proc_pid_syscall),
49422 #endif
49423 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49424 @@ -3065,10 +3200,10 @@ static const struct pid_entry tgid_base_stuff[] = {
49425 #ifdef CONFIG_SECURITY
49426 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49427 #endif
49428 -#ifdef CONFIG_KALLSYMS
49429 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49430 INF("wchan", S_IRUGO, proc_pid_wchan),
49431 #endif
49432 -#ifdef CONFIG_STACKTRACE
49433 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49434 ONE("stack", S_IRUGO, proc_pid_stack),
49435 #endif
49436 #ifdef CONFIG_SCHEDSTATS
49437 @@ -3102,6 +3237,9 @@ static const struct pid_entry tgid_base_stuff[] = {
49438 #ifdef CONFIG_HARDWALL
49439 INF("hardwall", S_IRUGO, proc_pid_hardwall),
49440 #endif
49441 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49442 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
49443 +#endif
49444 #ifdef CONFIG_USER_NS
49445 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
49446 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
49447 @@ -3233,7 +3371,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
49448 if (!inode)
49449 goto out;
49450
49451 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49452 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
49453 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49454 + inode->i_gid = grsec_proc_gid;
49455 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
49456 +#else
49457 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
49458 +#endif
49459 inode->i_op = &proc_tgid_base_inode_operations;
49460 inode->i_fop = &proc_tgid_base_operations;
49461 inode->i_flags|=S_IMMUTABLE;
49462 @@ -3275,7 +3420,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
49463 if (!task)
49464 goto out;
49465
49466 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49467 + goto out_put_task;
49468 +
49469 result = proc_pid_instantiate(dir, dentry, task, NULL);
49470 +out_put_task:
49471 put_task_struct(task);
49472 out:
49473 return result;
49474 @@ -3338,6 +3487,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
49475 static int fake_filldir(void *buf, const char *name, int namelen,
49476 loff_t offset, u64 ino, unsigned d_type)
49477 {
49478 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
49479 + __buf->error = -EINVAL;
49480 return 0;
49481 }
49482
49483 @@ -3404,7 +3555,7 @@ static const struct pid_entry tid_base_stuff[] = {
49484 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
49485 #endif
49486 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49487 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49488 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49489 INF("syscall", S_IRUGO, proc_pid_syscall),
49490 #endif
49491 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49492 @@ -3431,10 +3582,10 @@ static const struct pid_entry tid_base_stuff[] = {
49493 #ifdef CONFIG_SECURITY
49494 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49495 #endif
49496 -#ifdef CONFIG_KALLSYMS
49497 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49498 INF("wchan", S_IRUGO, proc_pid_wchan),
49499 #endif
49500 -#ifdef CONFIG_STACKTRACE
49501 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49502 ONE("stack", S_IRUGO, proc_pid_stack),
49503 #endif
49504 #ifdef CONFIG_SCHEDSTATS
49505 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
49506 index 82676e3..5f8518a 100644
49507 --- a/fs/proc/cmdline.c
49508 +++ b/fs/proc/cmdline.c
49509 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
49510
49511 static int __init proc_cmdline_init(void)
49512 {
49513 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49514 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
49515 +#else
49516 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
49517 +#endif
49518 return 0;
49519 }
49520 module_init(proc_cmdline_init);
49521 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
49522 index b143471..bb105e5 100644
49523 --- a/fs/proc/devices.c
49524 +++ b/fs/proc/devices.c
49525 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
49526
49527 static int __init proc_devices_init(void)
49528 {
49529 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49530 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
49531 +#else
49532 proc_create("devices", 0, NULL, &proc_devinfo_operations);
49533 +#endif
49534 return 0;
49535 }
49536 module_init(proc_devices_init);
49537 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
49538 index 7ac817b..c5c9eb0 100644
49539 --- a/fs/proc/inode.c
49540 +++ b/fs/proc/inode.c
49541 @@ -21,11 +21,17 @@
49542 #include <linux/seq_file.h>
49543 #include <linux/slab.h>
49544 #include <linux/mount.h>
49545 +#include <linux/grsecurity.h>
49546
49547 #include <asm/uaccess.h>
49548
49549 #include "internal.h"
49550
49551 +#ifdef CONFIG_PROC_SYSCTL
49552 +extern const struct inode_operations proc_sys_inode_operations;
49553 +extern const struct inode_operations proc_sys_dir_operations;
49554 +#endif
49555 +
49556 static void proc_evict_inode(struct inode *inode)
49557 {
49558 struct proc_dir_entry *de;
49559 @@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
49560 ns_ops = PROC_I(inode)->ns_ops;
49561 if (ns_ops && ns_ops->put)
49562 ns_ops->put(PROC_I(inode)->ns);
49563 +
49564 +#ifdef CONFIG_PROC_SYSCTL
49565 + if (inode->i_op == &proc_sys_inode_operations ||
49566 + inode->i_op == &proc_sys_dir_operations)
49567 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
49568 +#endif
49569 +
49570 }
49571
49572 static struct kmem_cache * proc_inode_cachep;
49573 @@ -456,7 +469,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
49574 if (de->mode) {
49575 inode->i_mode = de->mode;
49576 inode->i_uid = de->uid;
49577 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49578 + inode->i_gid = grsec_proc_gid;
49579 +#else
49580 inode->i_gid = de->gid;
49581 +#endif
49582 }
49583 if (de->size)
49584 inode->i_size = de->size;
49585 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
49586 index e1167a1..bd24f20 100644
49587 --- a/fs/proc/internal.h
49588 +++ b/fs/proc/internal.h
49589 @@ -52,6 +52,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
49590 struct pid *pid, struct task_struct *task);
49591 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49592 struct pid *pid, struct task_struct *task);
49593 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49594 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
49595 +#endif
49596 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
49597
49598 extern const struct file_operations proc_tid_children_operations;
49599 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
49600 index 86c67ee..cdca321 100644
49601 --- a/fs/proc/kcore.c
49602 +++ b/fs/proc/kcore.c
49603 @@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49604 * the addresses in the elf_phdr on our list.
49605 */
49606 start = kc_offset_to_vaddr(*fpos - elf_buflen);
49607 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
49608 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
49609 + if (tsz > buflen)
49610 tsz = buflen;
49611 -
49612 +
49613 while (buflen) {
49614 struct kcore_list *m;
49615
49616 @@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49617 kfree(elf_buf);
49618 } else {
49619 if (kern_addr_valid(start)) {
49620 - unsigned long n;
49621 + char *elf_buf;
49622 + mm_segment_t oldfs;
49623
49624 - n = copy_to_user(buffer, (char *)start, tsz);
49625 - /*
49626 - * We cannot distinguish between fault on source
49627 - * and fault on destination. When this happens
49628 - * we clear too and hope it will trigger the
49629 - * EFAULT again.
49630 - */
49631 - if (n) {
49632 - if (clear_user(buffer + tsz - n,
49633 - n))
49634 + elf_buf = kmalloc(tsz, GFP_KERNEL);
49635 + if (!elf_buf)
49636 + return -ENOMEM;
49637 + oldfs = get_fs();
49638 + set_fs(KERNEL_DS);
49639 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
49640 + set_fs(oldfs);
49641 + if (copy_to_user(buffer, elf_buf, tsz)) {
49642 + kfree(elf_buf);
49643 return -EFAULT;
49644 + }
49645 }
49646 + set_fs(oldfs);
49647 + kfree(elf_buf);
49648 } else {
49649 if (clear_user(buffer, tsz))
49650 return -EFAULT;
49651 @@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49652
49653 static int open_kcore(struct inode *inode, struct file *filp)
49654 {
49655 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
49656 + return -EPERM;
49657 +#endif
49658 if (!capable(CAP_SYS_RAWIO))
49659 return -EPERM;
49660 if (kcore_need_update)
49661 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
49662 index 80e4645..53e5fcf 100644
49663 --- a/fs/proc/meminfo.c
49664 +++ b/fs/proc/meminfo.c
49665 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
49666 vmi.used >> 10,
49667 vmi.largest_chunk >> 10
49668 #ifdef CONFIG_MEMORY_FAILURE
49669 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
49670 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
49671 #endif
49672 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
49673 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
49674 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
49675 index b1822dd..df622cb 100644
49676 --- a/fs/proc/nommu.c
49677 +++ b/fs/proc/nommu.c
49678 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
49679 if (len < 1)
49680 len = 1;
49681 seq_printf(m, "%*c", len, ' ');
49682 - seq_path(m, &file->f_path, "");
49683 + seq_path(m, &file->f_path, "\n\\");
49684 }
49685
49686 seq_putc(m, '\n');
49687 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
49688 index fe72cd0..cb9b67d 100644
49689 --- a/fs/proc/proc_net.c
49690 +++ b/fs/proc/proc_net.c
49691 @@ -23,6 +23,7 @@
49692 #include <linux/nsproxy.h>
49693 #include <net/net_namespace.h>
49694 #include <linux/seq_file.h>
49695 +#include <linux/grsecurity.h>
49696
49697 #include "internal.h"
49698
49699 @@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
49700 struct task_struct *task;
49701 struct nsproxy *ns;
49702 struct net *net = NULL;
49703 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49704 + const struct cred *cred = current_cred();
49705 +#endif
49706 +
49707 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49708 + if (cred->fsuid)
49709 + return net;
49710 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49711 + if (cred->fsuid && !in_group_p(grsec_proc_gid))
49712 + return net;
49713 +#endif
49714
49715 rcu_read_lock();
49716 task = pid_task(proc_pid(dir), PIDTYPE_PID);
49717 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
49718 index eb7cc91..7327a46 100644
49719 --- a/fs/proc/proc_sysctl.c
49720 +++ b/fs/proc/proc_sysctl.c
49721 @@ -12,11 +12,15 @@
49722 #include <linux/module.h>
49723 #include "internal.h"
49724
49725 +extern int gr_handle_chroot_sysctl(const int op);
49726 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
49727 + const int op);
49728 +
49729 static const struct dentry_operations proc_sys_dentry_operations;
49730 static const struct file_operations proc_sys_file_operations;
49731 -static const struct inode_operations proc_sys_inode_operations;
49732 +const struct inode_operations proc_sys_inode_operations;
49733 static const struct file_operations proc_sys_dir_file_operations;
49734 -static const struct inode_operations proc_sys_dir_operations;
49735 +const struct inode_operations proc_sys_dir_operations;
49736
49737 void proc_sys_poll_notify(struct ctl_table_poll *poll)
49738 {
49739 @@ -467,6 +471,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
49740
49741 err = NULL;
49742 d_set_d_op(dentry, &proc_sys_dentry_operations);
49743 +
49744 + gr_handle_proc_create(dentry, inode);
49745 +
49746 d_add(dentry, inode);
49747
49748 out:
49749 @@ -482,18 +489,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49750 struct inode *inode = filp->f_path.dentry->d_inode;
49751 struct ctl_table_header *head = grab_header(inode);
49752 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
49753 + int op = write ? MAY_WRITE : MAY_READ;
49754 ssize_t error;
49755 size_t res;
49756
49757 if (IS_ERR(head))
49758 return PTR_ERR(head);
49759
49760 +
49761 /*
49762 * At this point we know that the sysctl was not unregistered
49763 * and won't be until we finish.
49764 */
49765 error = -EPERM;
49766 - if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
49767 + if (sysctl_perm(head->root, table, op))
49768 goto out;
49769
49770 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
49771 @@ -501,6 +510,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49772 if (!table->proc_handler)
49773 goto out;
49774
49775 +#ifdef CONFIG_GRKERNSEC
49776 + error = -EPERM;
49777 + if (gr_handle_chroot_sysctl(op))
49778 + goto out;
49779 + dget(filp->f_path.dentry);
49780 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
49781 + dput(filp->f_path.dentry);
49782 + goto out;
49783 + }
49784 + dput(filp->f_path.dentry);
49785 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
49786 + goto out;
49787 + if (write && !capable(CAP_SYS_ADMIN))
49788 + goto out;
49789 +#endif
49790 +
49791 /* careful: calling conventions are nasty here */
49792 res = count;
49793 error = table->proc_handler(table, write, buf, &res, ppos);
49794 @@ -598,6 +623,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
49795 return -ENOMEM;
49796 } else {
49797 d_set_d_op(child, &proc_sys_dentry_operations);
49798 +
49799 + gr_handle_proc_create(child, inode);
49800 +
49801 d_add(child, inode);
49802 }
49803 } else {
49804 @@ -641,6 +669,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
49805 if ((*pos)++ < file->f_pos)
49806 return 0;
49807
49808 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
49809 + return 0;
49810 +
49811 if (unlikely(S_ISLNK(table->mode)))
49812 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
49813 else
49814 @@ -758,6 +789,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
49815 if (IS_ERR(head))
49816 return PTR_ERR(head);
49817
49818 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
49819 + return -ENOENT;
49820 +
49821 generic_fillattr(inode, stat);
49822 if (table)
49823 stat->mode = (stat->mode & S_IFMT) | table->mode;
49824 @@ -780,13 +814,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
49825 .llseek = generic_file_llseek,
49826 };
49827
49828 -static const struct inode_operations proc_sys_inode_operations = {
49829 +const struct inode_operations proc_sys_inode_operations = {
49830 .permission = proc_sys_permission,
49831 .setattr = proc_sys_setattr,
49832 .getattr = proc_sys_getattr,
49833 };
49834
49835 -static const struct inode_operations proc_sys_dir_operations = {
49836 +const struct inode_operations proc_sys_dir_operations = {
49837 .lookup = proc_sys_lookup,
49838 .permission = proc_sys_permission,
49839 .setattr = proc_sys_setattr,
49840 diff --git a/fs/proc/root.c b/fs/proc/root.c
49841 index 9a2d9fd..ddfc92a 100644
49842 --- a/fs/proc/root.c
49843 +++ b/fs/proc/root.c
49844 @@ -187,7 +187,15 @@ void __init proc_root_init(void)
49845 #ifdef CONFIG_PROC_DEVICETREE
49846 proc_device_tree_init();
49847 #endif
49848 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49849 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49850 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
49851 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49852 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
49853 +#endif
49854 +#else
49855 proc_mkdir("bus", NULL);
49856 +#endif
49857 proc_sys_init();
49858 }
49859
49860 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
49861 index 4540b8f..1b9772f 100644
49862 --- a/fs/proc/task_mmu.c
49863 +++ b/fs/proc/task_mmu.c
49864 @@ -11,12 +11,19 @@
49865 #include <linux/rmap.h>
49866 #include <linux/swap.h>
49867 #include <linux/swapops.h>
49868 +#include <linux/grsecurity.h>
49869
49870 #include <asm/elf.h>
49871 #include <asm/uaccess.h>
49872 #include <asm/tlbflush.h>
49873 #include "internal.h"
49874
49875 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49876 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49877 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
49878 + _mm->pax_flags & MF_PAX_SEGMEXEC))
49879 +#endif
49880 +
49881 void task_mem(struct seq_file *m, struct mm_struct *mm)
49882 {
49883 unsigned long data, text, lib, swap;
49884 @@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49885 "VmExe:\t%8lu kB\n"
49886 "VmLib:\t%8lu kB\n"
49887 "VmPTE:\t%8lu kB\n"
49888 - "VmSwap:\t%8lu kB\n",
49889 - hiwater_vm << (PAGE_SHIFT-10),
49890 + "VmSwap:\t%8lu kB\n"
49891 +
49892 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49893 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
49894 +#endif
49895 +
49896 + ,hiwater_vm << (PAGE_SHIFT-10),
49897 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
49898 mm->locked_vm << (PAGE_SHIFT-10),
49899 mm->pinned_vm << (PAGE_SHIFT-10),
49900 @@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49901 data << (PAGE_SHIFT-10),
49902 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
49903 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
49904 - swap << (PAGE_SHIFT-10));
49905 + swap << (PAGE_SHIFT-10)
49906 +
49907 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49908 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49909 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
49910 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
49911 +#else
49912 + , mm->context.user_cs_base
49913 + , mm->context.user_cs_limit
49914 +#endif
49915 +#endif
49916 +
49917 + );
49918 }
49919
49920 unsigned long task_vsize(struct mm_struct *mm)
49921 @@ -231,13 +255,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49922 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
49923 }
49924
49925 - /* We don't show the stack guard page in /proc/maps */
49926 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49927 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
49928 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
49929 +#else
49930 start = vma->vm_start;
49931 - if (stack_guard_page_start(vma, start))
49932 - start += PAGE_SIZE;
49933 end = vma->vm_end;
49934 - if (stack_guard_page_end(vma, end))
49935 - end -= PAGE_SIZE;
49936 +#endif
49937
49938 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
49939 start,
49940 @@ -246,7 +270,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49941 flags & VM_WRITE ? 'w' : '-',
49942 flags & VM_EXEC ? 'x' : '-',
49943 flags & VM_MAYSHARE ? 's' : 'p',
49944 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49945 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
49946 +#else
49947 pgoff,
49948 +#endif
49949 MAJOR(dev), MINOR(dev), ino, &len);
49950
49951 /*
49952 @@ -255,7 +283,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49953 */
49954 if (file) {
49955 pad_len_spaces(m, len);
49956 - seq_path(m, &file->f_path, "\n");
49957 + seq_path(m, &file->f_path, "\n\\");
49958 goto done;
49959 }
49960
49961 @@ -281,8 +309,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49962 * Thread stack in /proc/PID/task/TID/maps or
49963 * the main process stack.
49964 */
49965 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
49966 - vma->vm_end >= mm->start_stack)) {
49967 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
49968 + (vma->vm_start <= mm->start_stack &&
49969 + vma->vm_end >= mm->start_stack)) {
49970 name = "[stack]";
49971 } else {
49972 /* Thread stack in /proc/PID/maps */
49973 @@ -306,6 +335,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
49974 struct proc_maps_private *priv = m->private;
49975 struct task_struct *task = priv->task;
49976
49977 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49978 + if (current->exec_id != m->exec_id) {
49979 + gr_log_badprocpid("maps");
49980 + return 0;
49981 + }
49982 +#endif
49983 +
49984 show_map_vma(m, vma, is_pid);
49985
49986 if (m->count < m->size) /* vma is copied successfully */
49987 @@ -492,12 +528,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49988 .private = &mss,
49989 };
49990
49991 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49992 + if (current->exec_id != m->exec_id) {
49993 + gr_log_badprocpid("smaps");
49994 + return 0;
49995 + }
49996 +#endif
49997 memset(&mss, 0, sizeof mss);
49998 - mss.vma = vma;
49999 - /* mmap_sem is held in m_start */
50000 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
50001 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
50002 -
50003 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50004 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
50005 +#endif
50006 + mss.vma = vma;
50007 + /* mmap_sem is held in m_start */
50008 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
50009 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
50010 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50011 + }
50012 +#endif
50013 show_map_vma(m, vma, is_pid);
50014
50015 seq_printf(m,
50016 @@ -515,7 +562,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
50017 "KernelPageSize: %8lu kB\n"
50018 "MMUPageSize: %8lu kB\n"
50019 "Locked: %8lu kB\n",
50020 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50021 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
50022 +#else
50023 (vma->vm_end - vma->vm_start) >> 10,
50024 +#endif
50025 mss.resident >> 10,
50026 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
50027 mss.shared_clean >> 10,
50028 @@ -1164,6 +1215,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
50029 int n;
50030 char buffer[50];
50031
50032 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50033 + if (current->exec_id != m->exec_id) {
50034 + gr_log_badprocpid("numa_maps");
50035 + return 0;
50036 + }
50037 +#endif
50038 +
50039 if (!mm)
50040 return 0;
50041
50042 @@ -1181,11 +1239,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
50043 mpol_to_str(buffer, sizeof(buffer), pol, 0);
50044 mpol_cond_put(pol);
50045
50046 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50047 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
50048 +#else
50049 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
50050 +#endif
50051
50052 if (file) {
50053 seq_printf(m, " file=");
50054 - seq_path(m, &file->f_path, "\n\t= ");
50055 + seq_path(m, &file->f_path, "\n\t\\= ");
50056 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
50057 seq_printf(m, " heap");
50058 } else {
50059 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
50060 index 1ccfa53..0848f95 100644
50061 --- a/fs/proc/task_nommu.c
50062 +++ b/fs/proc/task_nommu.c
50063 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
50064 else
50065 bytes += kobjsize(mm);
50066
50067 - if (current->fs && current->fs->users > 1)
50068 + if (current->fs && atomic_read(&current->fs->users) > 1)
50069 sbytes += kobjsize(current->fs);
50070 else
50071 bytes += kobjsize(current->fs);
50072 @@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
50073
50074 if (file) {
50075 pad_len_spaces(m, len);
50076 - seq_path(m, &file->f_path, "");
50077 + seq_path(m, &file->f_path, "\n\\");
50078 } else if (mm) {
50079 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
50080
50081 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
50082 index d67908b..d13f6a6 100644
50083 --- a/fs/quota/netlink.c
50084 +++ b/fs/quota/netlink.c
50085 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
50086 void quota_send_warning(short type, unsigned int id, dev_t dev,
50087 const char warntype)
50088 {
50089 - static atomic_t seq;
50090 + static atomic_unchecked_t seq;
50091 struct sk_buff *skb;
50092 void *msg_head;
50093 int ret;
50094 @@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
50095 "VFS: Not enough memory to send quota warning.\n");
50096 return;
50097 }
50098 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
50099 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
50100 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
50101 if (!msg_head) {
50102 printk(KERN_ERR
50103 diff --git a/fs/readdir.c b/fs/readdir.c
50104 index 39e3370..20d446d 100644
50105 --- a/fs/readdir.c
50106 +++ b/fs/readdir.c
50107 @@ -17,6 +17,7 @@
50108 #include <linux/security.h>
50109 #include <linux/syscalls.h>
50110 #include <linux/unistd.h>
50111 +#include <linux/namei.h>
50112
50113 #include <asm/uaccess.h>
50114
50115 @@ -67,6 +68,7 @@ struct old_linux_dirent {
50116
50117 struct readdir_callback {
50118 struct old_linux_dirent __user * dirent;
50119 + struct file * file;
50120 int result;
50121 };
50122
50123 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
50124 buf->result = -EOVERFLOW;
50125 return -EOVERFLOW;
50126 }
50127 +
50128 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50129 + return 0;
50130 +
50131 buf->result++;
50132 dirent = buf->dirent;
50133 if (!access_ok(VERIFY_WRITE, dirent,
50134 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
50135
50136 buf.result = 0;
50137 buf.dirent = dirent;
50138 + buf.file = file;
50139
50140 error = vfs_readdir(file, fillonedir, &buf);
50141 if (buf.result)
50142 @@ -141,6 +148,7 @@ struct linux_dirent {
50143 struct getdents_callback {
50144 struct linux_dirent __user * current_dir;
50145 struct linux_dirent __user * previous;
50146 + struct file * file;
50147 int count;
50148 int error;
50149 };
50150 @@ -162,6 +170,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
50151 buf->error = -EOVERFLOW;
50152 return -EOVERFLOW;
50153 }
50154 +
50155 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50156 + return 0;
50157 +
50158 dirent = buf->previous;
50159 if (dirent) {
50160 if (__put_user(offset, &dirent->d_off))
50161 @@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
50162 buf.previous = NULL;
50163 buf.count = count;
50164 buf.error = 0;
50165 + buf.file = file;
50166
50167 error = vfs_readdir(file, filldir, &buf);
50168 if (error >= 0)
50169 @@ -226,6 +239,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
50170 struct getdents_callback64 {
50171 struct linux_dirent64 __user * current_dir;
50172 struct linux_dirent64 __user * previous;
50173 + struct file *file;
50174 int count;
50175 int error;
50176 };
50177 @@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
50178 buf->error = -EINVAL; /* only used if we fail.. */
50179 if (reclen > buf->count)
50180 return -EINVAL;
50181 +
50182 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50183 + return 0;
50184 +
50185 dirent = buf->previous;
50186 if (dirent) {
50187 if (__put_user(offset, &dirent->d_off))
50188 @@ -287,6 +305,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
50189
50190 buf.current_dir = dirent;
50191 buf.previous = NULL;
50192 + buf.file = file;
50193 buf.count = count;
50194 buf.error = 0;
50195
50196 @@ -295,7 +314,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
50197 error = buf.error;
50198 lastdirent = buf.previous;
50199 if (lastdirent) {
50200 - typeof(lastdirent->d_off) d_off = file->f_pos;
50201 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
50202 if (__put_user(d_off, &lastdirent->d_off))
50203 error = -EFAULT;
50204 else
50205 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
50206 index 2b7882b..1c5ef48 100644
50207 --- a/fs/reiserfs/do_balan.c
50208 +++ b/fs/reiserfs/do_balan.c
50209 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
50210 return;
50211 }
50212
50213 - atomic_inc(&(fs_generation(tb->tb_sb)));
50214 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
50215 do_balance_starts(tb);
50216
50217 /* balance leaf returns 0 except if combining L R and S into
50218 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
50219 index e60e870..f40ac16 100644
50220 --- a/fs/reiserfs/procfs.c
50221 +++ b/fs/reiserfs/procfs.c
50222 @@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
50223 "SMALL_TAILS " : "NO_TAILS ",
50224 replay_only(sb) ? "REPLAY_ONLY " : "",
50225 convert_reiserfs(sb) ? "CONV " : "",
50226 - atomic_read(&r->s_generation_counter),
50227 + atomic_read_unchecked(&r->s_generation_counter),
50228 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
50229 SF(s_do_balance), SF(s_unneeded_left_neighbor),
50230 SF(s_good_search_by_key_reada), SF(s_bmaps),
50231 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
50232 index 33215f5..c5d427a 100644
50233 --- a/fs/reiserfs/reiserfs.h
50234 +++ b/fs/reiserfs/reiserfs.h
50235 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
50236 /* Comment? -Hans */
50237 wait_queue_head_t s_wait;
50238 /* To be obsoleted soon by per buffer seals.. -Hans */
50239 - atomic_t s_generation_counter; // increased by one every time the
50240 + atomic_unchecked_t s_generation_counter; // increased by one every time the
50241 // tree gets re-balanced
50242 unsigned long s_properties; /* File system properties. Currently holds
50243 on-disk FS format */
50244 @@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
50245 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
50246
50247 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
50248 -#define get_generation(s) atomic_read (&fs_generation(s))
50249 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
50250 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
50251 #define __fs_changed(gen,s) (gen != get_generation (s))
50252 #define fs_changed(gen,s) \
50253 diff --git a/fs/select.c b/fs/select.c
50254 index db14c78..3aae1bd 100644
50255 --- a/fs/select.c
50256 +++ b/fs/select.c
50257 @@ -20,6 +20,7 @@
50258 #include <linux/export.h>
50259 #include <linux/slab.h>
50260 #include <linux/poll.h>
50261 +#include <linux/security.h>
50262 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
50263 #include <linux/file.h>
50264 #include <linux/fdtable.h>
50265 @@ -831,6 +832,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
50266 struct poll_list *walk = head;
50267 unsigned long todo = nfds;
50268
50269 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
50270 if (nfds > rlimit(RLIMIT_NOFILE))
50271 return -EINVAL;
50272
50273 diff --git a/fs/seq_file.c b/fs/seq_file.c
50274 index 14cf9de..adc4d5b 100644
50275 --- a/fs/seq_file.c
50276 +++ b/fs/seq_file.c
50277 @@ -9,6 +9,7 @@
50278 #include <linux/export.h>
50279 #include <linux/seq_file.h>
50280 #include <linux/slab.h>
50281 +#include <linux/sched.h>
50282
50283 #include <asm/uaccess.h>
50284 #include <asm/page.h>
50285 @@ -56,6 +57,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
50286 memset(p, 0, sizeof(*p));
50287 mutex_init(&p->lock);
50288 p->op = op;
50289 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50290 + p->exec_id = current->exec_id;
50291 +#endif
50292
50293 /*
50294 * Wrappers around seq_open(e.g. swaps_open) need to be
50295 @@ -92,7 +96,7 @@ static int traverse(struct seq_file *m, loff_t offset)
50296 return 0;
50297 }
50298 if (!m->buf) {
50299 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50300 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
50301 if (!m->buf)
50302 return -ENOMEM;
50303 }
50304 @@ -132,7 +136,7 @@ static int traverse(struct seq_file *m, loff_t offset)
50305 Eoverflow:
50306 m->op->stop(m, p);
50307 kfree(m->buf);
50308 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50309 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
50310 return !m->buf ? -ENOMEM : -EAGAIN;
50311 }
50312
50313 @@ -187,7 +191,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
50314
50315 /* grab buffer if we didn't have one */
50316 if (!m->buf) {
50317 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50318 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
50319 if (!m->buf)
50320 goto Enomem;
50321 }
50322 @@ -228,7 +232,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
50323 goto Fill;
50324 m->op->stop(m, p);
50325 kfree(m->buf);
50326 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50327 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
50328 if (!m->buf)
50329 goto Enomem;
50330 m->count = 0;
50331 @@ -577,7 +581,7 @@ static void single_stop(struct seq_file *p, void *v)
50332 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
50333 void *data)
50334 {
50335 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
50336 + seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
50337 int res = -ENOMEM;
50338
50339 if (op) {
50340 diff --git a/fs/splice.c b/fs/splice.c
50341 index 41514dd..6564a93 100644
50342 --- a/fs/splice.c
50343 +++ b/fs/splice.c
50344 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50345 pipe_lock(pipe);
50346
50347 for (;;) {
50348 - if (!pipe->readers) {
50349 + if (!atomic_read(&pipe->readers)) {
50350 send_sig(SIGPIPE, current, 0);
50351 if (!ret)
50352 ret = -EPIPE;
50353 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50354 do_wakeup = 0;
50355 }
50356
50357 - pipe->waiting_writers++;
50358 + atomic_inc(&pipe->waiting_writers);
50359 pipe_wait(pipe);
50360 - pipe->waiting_writers--;
50361 + atomic_dec(&pipe->waiting_writers);
50362 }
50363
50364 pipe_unlock(pipe);
50365 @@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
50366 old_fs = get_fs();
50367 set_fs(get_ds());
50368 /* The cast to a user pointer is valid due to the set_fs() */
50369 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
50370 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
50371 set_fs(old_fs);
50372
50373 return res;
50374 @@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
50375 old_fs = get_fs();
50376 set_fs(get_ds());
50377 /* The cast to a user pointer is valid due to the set_fs() */
50378 - res = vfs_write(file, (const char __user *)buf, count, &pos);
50379 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
50380 set_fs(old_fs);
50381
50382 return res;
50383 @@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
50384 goto err;
50385
50386 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
50387 - vec[i].iov_base = (void __user *) page_address(page);
50388 + vec[i].iov_base = (void __force_user *) page_address(page);
50389 vec[i].iov_len = this_len;
50390 spd.pages[i] = page;
50391 spd.nr_pages++;
50392 @@ -849,10 +849,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
50393 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
50394 {
50395 while (!pipe->nrbufs) {
50396 - if (!pipe->writers)
50397 + if (!atomic_read(&pipe->writers))
50398 return 0;
50399
50400 - if (!pipe->waiting_writers && sd->num_spliced)
50401 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
50402 return 0;
50403
50404 if (sd->flags & SPLICE_F_NONBLOCK)
50405 @@ -1190,7 +1190,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
50406 * out of the pipe right after the splice_to_pipe(). So set
50407 * PIPE_READERS appropriately.
50408 */
50409 - pipe->readers = 1;
50410 + atomic_set(&pipe->readers, 1);
50411
50412 current->splice_pipe = pipe;
50413 }
50414 @@ -1743,9 +1743,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50415 ret = -ERESTARTSYS;
50416 break;
50417 }
50418 - if (!pipe->writers)
50419 + if (!atomic_read(&pipe->writers))
50420 break;
50421 - if (!pipe->waiting_writers) {
50422 + if (!atomic_read(&pipe->waiting_writers)) {
50423 if (flags & SPLICE_F_NONBLOCK) {
50424 ret = -EAGAIN;
50425 break;
50426 @@ -1777,7 +1777,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50427 pipe_lock(pipe);
50428
50429 while (pipe->nrbufs >= pipe->buffers) {
50430 - if (!pipe->readers) {
50431 + if (!atomic_read(&pipe->readers)) {
50432 send_sig(SIGPIPE, current, 0);
50433 ret = -EPIPE;
50434 break;
50435 @@ -1790,9 +1790,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50436 ret = -ERESTARTSYS;
50437 break;
50438 }
50439 - pipe->waiting_writers++;
50440 + atomic_inc(&pipe->waiting_writers);
50441 pipe_wait(pipe);
50442 - pipe->waiting_writers--;
50443 + atomic_dec(&pipe->waiting_writers);
50444 }
50445
50446 pipe_unlock(pipe);
50447 @@ -1828,14 +1828,14 @@ retry:
50448 pipe_double_lock(ipipe, opipe);
50449
50450 do {
50451 - if (!opipe->readers) {
50452 + if (!atomic_read(&opipe->readers)) {
50453 send_sig(SIGPIPE, current, 0);
50454 if (!ret)
50455 ret = -EPIPE;
50456 break;
50457 }
50458
50459 - if (!ipipe->nrbufs && !ipipe->writers)
50460 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
50461 break;
50462
50463 /*
50464 @@ -1932,7 +1932,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50465 pipe_double_lock(ipipe, opipe);
50466
50467 do {
50468 - if (!opipe->readers) {
50469 + if (!atomic_read(&opipe->readers)) {
50470 send_sig(SIGPIPE, current, 0);
50471 if (!ret)
50472 ret = -EPIPE;
50473 @@ -1977,7 +1977,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50474 * return EAGAIN if we have the potential of some data in the
50475 * future, otherwise just return 0
50476 */
50477 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
50478 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
50479 ret = -EAGAIN;
50480
50481 pipe_unlock(ipipe);
50482 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
50483 index 2fbdff6..5530a61 100644
50484 --- a/fs/sysfs/dir.c
50485 +++ b/fs/sysfs/dir.c
50486 @@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
50487 struct sysfs_dirent *sd;
50488 int rc;
50489
50490 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
50491 + const char *parent_name = parent_sd->s_name;
50492 +
50493 + mode = S_IFDIR | S_IRWXU;
50494 +
50495 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
50496 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
50497 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
50498 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
50499 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
50500 +#endif
50501 +
50502 /* allocate */
50503 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
50504 if (!sd)
50505 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
50506 index 00012e3..8392349 100644
50507 --- a/fs/sysfs/file.c
50508 +++ b/fs/sysfs/file.c
50509 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
50510
50511 struct sysfs_open_dirent {
50512 atomic_t refcnt;
50513 - atomic_t event;
50514 + atomic_unchecked_t event;
50515 wait_queue_head_t poll;
50516 struct list_head buffers; /* goes through sysfs_buffer.list */
50517 };
50518 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
50519 if (!sysfs_get_active(attr_sd))
50520 return -ENODEV;
50521
50522 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
50523 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
50524 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
50525
50526 sysfs_put_active(attr_sd);
50527 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
50528 return -ENOMEM;
50529
50530 atomic_set(&new_od->refcnt, 0);
50531 - atomic_set(&new_od->event, 1);
50532 + atomic_set_unchecked(&new_od->event, 1);
50533 init_waitqueue_head(&new_od->poll);
50534 INIT_LIST_HEAD(&new_od->buffers);
50535 goto retry;
50536 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
50537
50538 sysfs_put_active(attr_sd);
50539
50540 - if (buffer->event != atomic_read(&od->event))
50541 + if (buffer->event != atomic_read_unchecked(&od->event))
50542 goto trigger;
50543
50544 return DEFAULT_POLLMASK;
50545 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
50546
50547 od = sd->s_attr.open;
50548 if (od) {
50549 - atomic_inc(&od->event);
50550 + atomic_inc_unchecked(&od->event);
50551 wake_up_interruptible(&od->poll);
50552 }
50553
50554 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
50555 index a7ac78f..02158e1 100644
50556 --- a/fs/sysfs/symlink.c
50557 +++ b/fs/sysfs/symlink.c
50558 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
50559
50560 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
50561 {
50562 - char *page = nd_get_link(nd);
50563 + const char *page = nd_get_link(nd);
50564 if (!IS_ERR(page))
50565 free_page((unsigned long)page);
50566 }
50567 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
50568 index c175b4d..8f36a16 100644
50569 --- a/fs/udf/misc.c
50570 +++ b/fs/udf/misc.c
50571 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
50572
50573 u8 udf_tag_checksum(const struct tag *t)
50574 {
50575 - u8 *data = (u8 *)t;
50576 + const u8 *data = (const u8 *)t;
50577 u8 checksum = 0;
50578 int i;
50579 for (i = 0; i < sizeof(struct tag); ++i)
50580 diff --git a/fs/utimes.c b/fs/utimes.c
50581 index fa4dbe4..e12d1b9 100644
50582 --- a/fs/utimes.c
50583 +++ b/fs/utimes.c
50584 @@ -1,6 +1,7 @@
50585 #include <linux/compiler.h>
50586 #include <linux/file.h>
50587 #include <linux/fs.h>
50588 +#include <linux/security.h>
50589 #include <linux/linkage.h>
50590 #include <linux/mount.h>
50591 #include <linux/namei.h>
50592 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
50593 goto mnt_drop_write_and_out;
50594 }
50595 }
50596 +
50597 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
50598 + error = -EACCES;
50599 + goto mnt_drop_write_and_out;
50600 + }
50601 +
50602 mutex_lock(&inode->i_mutex);
50603 error = notify_change(path->dentry, &newattrs);
50604 mutex_unlock(&inode->i_mutex);
50605 diff --git a/fs/xattr.c b/fs/xattr.c
50606 index 4d45b71..2ec08e10 100644
50607 --- a/fs/xattr.c
50608 +++ b/fs/xattr.c
50609 @@ -316,7 +316,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
50610 * Extended attribute SET operations
50611 */
50612 static long
50613 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
50614 +setxattr(struct path *path, const char __user *name, const void __user *value,
50615 size_t size, int flags)
50616 {
50617 int error;
50618 @@ -349,7 +349,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
50619 }
50620 }
50621
50622 - error = vfs_setxattr(d, kname, kvalue, size, flags);
50623 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
50624 + error = -EACCES;
50625 + goto out;
50626 + }
50627 +
50628 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
50629 out:
50630 if (vvalue)
50631 vfree(vvalue);
50632 @@ -370,7 +375,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
50633 return error;
50634 error = mnt_want_write(path.mnt);
50635 if (!error) {
50636 - error = setxattr(path.dentry, name, value, size, flags);
50637 + error = setxattr(&path, name, value, size, flags);
50638 mnt_drop_write(path.mnt);
50639 }
50640 path_put(&path);
50641 @@ -389,7 +394,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
50642 return error;
50643 error = mnt_want_write(path.mnt);
50644 if (!error) {
50645 - error = setxattr(path.dentry, name, value, size, flags);
50646 + error = setxattr(&path, name, value, size, flags);
50647 mnt_drop_write(path.mnt);
50648 }
50649 path_put(&path);
50650 @@ -401,17 +406,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
50651 {
50652 int fput_needed;
50653 struct file *f;
50654 - struct dentry *dentry;
50655 int error = -EBADF;
50656
50657 f = fget_light(fd, &fput_needed);
50658 if (!f)
50659 return error;
50660 - dentry = f->f_path.dentry;
50661 - audit_inode(NULL, dentry);
50662 + audit_inode(NULL, f->f_path.dentry);
50663 error = mnt_want_write_file(f);
50664 if (!error) {
50665 - error = setxattr(dentry, name, value, size, flags);
50666 + error = setxattr(&f->f_path, name, value, size, flags);
50667 mnt_drop_write_file(f);
50668 }
50669 fput_light(f, fput_needed);
50670 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
50671 index 69d06b0..c0996e5 100644
50672 --- a/fs/xattr_acl.c
50673 +++ b/fs/xattr_acl.c
50674 @@ -17,8 +17,8 @@
50675 struct posix_acl *
50676 posix_acl_from_xattr(const void *value, size_t size)
50677 {
50678 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
50679 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
50680 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
50681 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
50682 int count;
50683 struct posix_acl *acl;
50684 struct posix_acl_entry *acl_e;
50685 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
50686 index 848ffa7..1f249bf 100644
50687 --- a/fs/xfs/xfs_bmap.c
50688 +++ b/fs/xfs/xfs_bmap.c
50689 @@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
50690 int nmap,
50691 int ret_nmap);
50692 #else
50693 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
50694 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
50695 #endif /* DEBUG */
50696
50697 STATIC int
50698 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
50699 index 1b9fc3e..e1bdde0 100644
50700 --- a/fs/xfs/xfs_dir2_sf.c
50701 +++ b/fs/xfs/xfs_dir2_sf.c
50702 @@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
50703 }
50704
50705 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
50706 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50707 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
50708 + char name[sfep->namelen];
50709 + memcpy(name, sfep->name, sfep->namelen);
50710 + if (filldir(dirent, name, sfep->namelen,
50711 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
50712 + *offset = off & 0x7fffffff;
50713 + return 0;
50714 + }
50715 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50716 off & 0x7fffffff, ino, DT_UNKNOWN)) {
50717 *offset = off & 0x7fffffff;
50718 return 0;
50719 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
50720 index 0e0232c..fa5c3fe 100644
50721 --- a/fs/xfs/xfs_ioctl.c
50722 +++ b/fs/xfs/xfs_ioctl.c
50723 @@ -126,7 +126,7 @@ xfs_find_handle(
50724 }
50725
50726 error = -EFAULT;
50727 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
50728 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
50729 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
50730 goto out_put;
50731
50732 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
50733 index 4e00cf0..3374374 100644
50734 --- a/fs/xfs/xfs_iops.c
50735 +++ b/fs/xfs/xfs_iops.c
50736 @@ -394,7 +394,7 @@ xfs_vn_put_link(
50737 struct nameidata *nd,
50738 void *p)
50739 {
50740 - char *s = nd_get_link(nd);
50741 + const char *s = nd_get_link(nd);
50742
50743 if (!IS_ERR(s))
50744 kfree(s);
50745 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
50746 new file mode 100644
50747 index 0000000..d38b430
50748 --- /dev/null
50749 +++ b/grsecurity/Kconfig
50750 @@ -0,0 +1,947 @@
50751 +#
50752 +# grecurity configuration
50753 +#
50754 +menu "Memory Protections"
50755 +depends on GRKERNSEC
50756 +
50757 +config GRKERNSEC_KMEM
50758 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
50759 + default y if GRKERNSEC_CONFIG_AUTO
50760 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
50761 + help
50762 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
50763 + be written to or read from to modify or leak the contents of the running
50764 + kernel. /dev/port will also not be allowed to be opened. If you have module
50765 + support disabled, enabling this will close up four ways that are
50766 + currently used to insert malicious code into the running kernel.
50767 + Even with all these features enabled, we still highly recommend that
50768 + you use the RBAC system, as it is still possible for an attacker to
50769 + modify the running kernel through privileged I/O granted by ioperm/iopl.
50770 + If you are not using XFree86, you may be able to stop this additional
50771 + case by enabling the 'Disable privileged I/O' option. Though nothing
50772 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
50773 + but only to video memory, which is the only writing we allow in this
50774 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
50775 + not be allowed to mprotect it with PROT_WRITE later.
50776 + It is highly recommended that you say Y here if you meet all the
50777 + conditions above.
50778 +
50779 +config GRKERNSEC_VM86
50780 + bool "Restrict VM86 mode"
50781 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50782 + depends on X86_32
50783 +
50784 + help
50785 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
50786 + make use of a special execution mode on 32bit x86 processors called
50787 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
50788 + video cards and will still work with this option enabled. The purpose
50789 + of the option is to prevent exploitation of emulation errors in
50790 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
50791 + Nearly all users should be able to enable this option.
50792 +
50793 +config GRKERNSEC_IO
50794 + bool "Disable privileged I/O"
50795 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50796 + depends on X86
50797 + select RTC_CLASS
50798 + select RTC_INTF_DEV
50799 + select RTC_DRV_CMOS
50800 +
50801 + help
50802 + If you say Y here, all ioperm and iopl calls will return an error.
50803 + Ioperm and iopl can be used to modify the running kernel.
50804 + Unfortunately, some programs need this access to operate properly,
50805 + the most notable of which are XFree86 and hwclock. hwclock can be
50806 + remedied by having RTC support in the kernel, so real-time
50807 + clock support is enabled if this option is enabled, to ensure
50808 + that hwclock operates correctly. XFree86 still will not
50809 + operate correctly with this option enabled, so DO NOT CHOOSE Y
50810 + IF YOU USE XFree86. If you use XFree86 and you still want to
50811 + protect your kernel against modification, use the RBAC system.
50812 +
50813 +config GRKERNSEC_PROC_MEMMAP
50814 + bool "Harden ASLR against information leaks and entropy reduction"
50815 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
50816 + depends on PAX_NOEXEC || PAX_ASLR
50817 + help
50818 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
50819 + give no information about the addresses of its mappings if
50820 + PaX features that rely on random addresses are enabled on the task.
50821 + In addition to sanitizing this information and disabling other
50822 + dangerous sources of information, this option causes reads of sensitive
50823 + /proc/<pid> entries where the file descriptor was opened in a different
50824 + task than the one performing the read. Such attempts are logged.
50825 + This option also limits argv/env strings for suid/sgid binaries
50826 + to 512KB to prevent a complete exhaustion of the stack entropy provided
50827 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
50828 + binaries to prevent alternative mmap layouts from being abused.
50829 +
50830 + If you use PaX it is essential that you say Y here as it closes up
50831 + several holes that make full ASLR useless locally.
50832 +
50833 +config GRKERNSEC_BRUTE
50834 + bool "Deter exploit bruteforcing"
50835 + default y if GRKERNSEC_CONFIG_AUTO
50836 + help
50837 + If you say Y here, attempts to bruteforce exploits against forking
50838 + daemons such as apache or sshd, as well as against suid/sgid binaries
50839 + will be deterred. When a child of a forking daemon is killed by PaX
50840 + or crashes due to an illegal instruction or other suspicious signal,
50841 + the parent process will be delayed 30 seconds upon every subsequent
50842 + fork until the administrator is able to assess the situation and
50843 + restart the daemon.
50844 + In the suid/sgid case, the attempt is logged, the user has all their
50845 + processes terminated, and they are prevented from executing any further
50846 + processes for 15 minutes.
50847 + It is recommended that you also enable signal logging in the auditing
50848 + section so that logs are generated when a process triggers a suspicious
50849 + signal.
50850 + If the sysctl option is enabled, a sysctl option with name
50851 + "deter_bruteforce" is created.
50852 +
50853 +
50854 +config GRKERNSEC_MODHARDEN
50855 + bool "Harden module auto-loading"
50856 + default y if GRKERNSEC_CONFIG_AUTO
50857 + depends on MODULES
50858 + help
50859 + If you say Y here, module auto-loading in response to use of some
50860 + feature implemented by an unloaded module will be restricted to
50861 + root users. Enabling this option helps defend against attacks
50862 + by unprivileged users who abuse the auto-loading behavior to
50863 + cause a vulnerable module to load that is then exploited.
50864 +
50865 + If this option prevents a legitimate use of auto-loading for a
50866 + non-root user, the administrator can execute modprobe manually
50867 + with the exact name of the module mentioned in the alert log.
50868 + Alternatively, the administrator can add the module to the list
50869 + of modules loaded at boot by modifying init scripts.
50870 +
50871 + Modification of init scripts will most likely be needed on
50872 + Ubuntu servers with encrypted home directory support enabled,
50873 + as the first non-root user logging in will cause the ecb(aes),
50874 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
50875 +
50876 +config GRKERNSEC_HIDESYM
50877 + bool "Hide kernel symbols"
50878 + default y if GRKERNSEC_CONFIG_AUTO
50879 + select PAX_USERCOPY_SLABS
50880 + help
50881 + If you say Y here, getting information on loaded modules, and
50882 + displaying all kernel symbols through a syscall will be restricted
50883 + to users with CAP_SYS_MODULE. For software compatibility reasons,
50884 + /proc/kallsyms will be restricted to the root user. The RBAC
50885 + system can hide that entry even from root.
50886 +
50887 + This option also prevents leaking of kernel addresses through
50888 + several /proc entries.
50889 +
50890 + Note that this option is only effective provided the following
50891 + conditions are met:
50892 + 1) The kernel using grsecurity is not precompiled by some distribution
50893 + 2) You have also enabled GRKERNSEC_DMESG
50894 + 3) You are using the RBAC system and hiding other files such as your
50895 + kernel image and System.map. Alternatively, enabling this option
50896 + causes the permissions on /boot, /lib/modules, and the kernel
50897 + source directory to change at compile time to prevent
50898 + reading by non-root users.
50899 + If the above conditions are met, this option will aid in providing a
50900 + useful protection against local kernel exploitation of overflows
50901 + and arbitrary read/write vulnerabilities.
50902 +
50903 +config GRKERNSEC_KERN_LOCKOUT
50904 + bool "Active kernel exploit response"
50905 + default y if GRKERNSEC_CONFIG_AUTO
50906 + depends on X86 || ARM || PPC || SPARC
50907 + help
50908 + If you say Y here, when a PaX alert is triggered due to suspicious
50909 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
50910 + or an OOPS occurs due to bad memory accesses, instead of just
50911 + terminating the offending process (and potentially allowing
50912 + a subsequent exploit from the same user), we will take one of two
50913 + actions:
50914 + If the user was root, we will panic the system
50915 + If the user was non-root, we will log the attempt, terminate
50916 + all processes owned by the user, then prevent them from creating
50917 + any new processes until the system is restarted
50918 + This deters repeated kernel exploitation/bruteforcing attempts
50919 + and is useful for later forensics.
50920 +
50921 +endmenu
50922 +menu "Role Based Access Control Options"
50923 +depends on GRKERNSEC
50924 +
50925 +config GRKERNSEC_RBAC_DEBUG
50926 + bool
50927 +
50928 +config GRKERNSEC_NO_RBAC
50929 + bool "Disable RBAC system"
50930 + help
50931 + If you say Y here, the /dev/grsec device will be removed from the kernel,
50932 + preventing the RBAC system from being enabled. You should only say Y
50933 + here if you have no intention of using the RBAC system, so as to prevent
50934 + an attacker with root access from misusing the RBAC system to hide files
50935 + and processes when loadable module support and /dev/[k]mem have been
50936 + locked down.
50937 +
50938 +config GRKERNSEC_ACL_HIDEKERN
50939 + bool "Hide kernel processes"
50940 + help
50941 + If you say Y here, all kernel threads will be hidden to all
50942 + processes but those whose subject has the "view hidden processes"
50943 + flag.
50944 +
50945 +config GRKERNSEC_ACL_MAXTRIES
50946 + int "Maximum tries before password lockout"
50947 + default 3
50948 + help
50949 + This option enforces the maximum number of times a user can attempt
50950 + to authorize themselves with the grsecurity RBAC system before being
50951 + denied the ability to attempt authorization again for a specified time.
50952 + The lower the number, the harder it will be to brute-force a password.
50953 +
50954 +config GRKERNSEC_ACL_TIMEOUT
50955 + int "Time to wait after max password tries, in seconds"
50956 + default 30
50957 + help
50958 + This option specifies the time the user must wait after attempting to
50959 + authorize to the RBAC system with the maximum number of invalid
50960 + passwords. The higher the number, the harder it will be to brute-force
50961 + a password.
50962 +
50963 +endmenu
50964 +menu "Filesystem Protections"
50965 +depends on GRKERNSEC
50966 +
50967 +config GRKERNSEC_PROC
50968 + bool "Proc restrictions"
50969 + default y if GRKERNSEC_CONFIG_AUTO
50970 + help
50971 + If you say Y here, the permissions of the /proc filesystem
50972 + will be altered to enhance system security and privacy. You MUST
50973 + choose either a user only restriction or a user and group restriction.
50974 + Depending upon the option you choose, you can either restrict users to
50975 + see only the processes they themselves run, or choose a group that can
50976 + view all processes and files normally restricted to root if you choose
50977 + the "restrict to user only" option. NOTE: If you're running identd or
50978 + ntpd as a non-root user, you will have to run it as the group you
50979 + specify here.
50980 +
50981 +config GRKERNSEC_PROC_USER
50982 + bool "Restrict /proc to user only"
50983 + depends on GRKERNSEC_PROC
50984 + help
50985 + If you say Y here, non-root users will only be able to view their own
50986 + processes, and restricts them from viewing network-related information,
50987 + and viewing kernel symbol and module information.
50988 +
50989 +config GRKERNSEC_PROC_USERGROUP
50990 + bool "Allow special group"
50991 + default y if GRKERNSEC_CONFIG_AUTO
50992 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
50993 + help
50994 + If you say Y here, you will be able to select a group that will be
50995 + able to view all processes and network-related information. If you've
50996 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
50997 + remain hidden. This option is useful if you want to run identd as
50998 + a non-root user. The group you select may also be chosen at boot time
50999 + via "grsec_proc_gid=" on the kernel commandline.
51000 +
51001 +config GRKERNSEC_PROC_GID
51002 + int "GID for special group"
51003 + depends on GRKERNSEC_PROC_USERGROUP
51004 + default 1001
51005 +
51006 +config GRKERNSEC_PROC_ADD
51007 + bool "Additional restrictions"
51008 + default y if GRKERNSEC_CONFIG_AUTO
51009 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
51010 + help
51011 + If you say Y here, additional restrictions will be placed on
51012 + /proc that keep normal users from viewing device information and
51013 + slabinfo information that could be useful for exploits.
51014 +
51015 +config GRKERNSEC_LINK
51016 + bool "Linking restrictions"
51017 + default y if GRKERNSEC_CONFIG_AUTO
51018 + help
51019 + If you say Y here, /tmp race exploits will be prevented, since users
51020 + will no longer be able to follow symlinks owned by other users in
51021 + world-writable +t directories (e.g. /tmp), unless the owner of the
51022 + symlink is the owner of the directory. users will also not be
51023 + able to hardlink to files they do not own. If the sysctl option is
51024 + enabled, a sysctl option with name "linking_restrictions" is created.
51025 +
51026 +config GRKERNSEC_SYMLINKOWN
51027 + bool "Kernel-enforced SymlinksIfOwnerMatch"
51028 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
51029 + help
51030 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
51031 + that prevents it from being used as a security feature. As Apache
51032 + verifies the symlink by performing a stat() against the target of
51033 + the symlink before it is followed, an attacker can setup a symlink
51034 + to point to a same-owned file, then replace the symlink with one
51035 + that targets another user's file just after Apache "validates" the
51036 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
51037 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
51038 + will be in place for the group you specify. If the sysctl option
51039 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
51040 + created.
51041 +
51042 +config GRKERNSEC_SYMLINKOWN_GID
51043 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
51044 + depends on GRKERNSEC_SYMLINKOWN
51045 + default 1006
51046 + help
51047 + Setting this GID determines what group kernel-enforced
51048 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
51049 + is enabled, a sysctl option with name "symlinkown_gid" is created.
51050 +
51051 +config GRKERNSEC_FIFO
51052 + bool "FIFO restrictions"
51053 + default y if GRKERNSEC_CONFIG_AUTO
51054 + help
51055 + If you say Y here, users will not be able to write to FIFOs they don't
51056 + own in world-writable +t directories (e.g. /tmp), unless the owner of
51057 + the FIFO is the same owner of the directory it's held in. If the sysctl
51058 + option is enabled, a sysctl option with name "fifo_restrictions" is
51059 + created.
51060 +
51061 +config GRKERNSEC_SYSFS_RESTRICT
51062 + bool "Sysfs/debugfs restriction"
51063 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
51064 + depends on SYSFS
51065 + help
51066 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
51067 + any filesystem normally mounted under it (e.g. debugfs) will be
51068 + mostly accessible only by root. These filesystems generally provide access
51069 + to hardware and debug information that isn't appropriate for unprivileged
51070 + users of the system. Sysfs and debugfs have also become a large source
51071 + of new vulnerabilities, ranging from infoleaks to local compromise.
51072 + There has been very little oversight with an eye toward security involved
51073 + in adding new exporters of information to these filesystems, so their
51074 + use is discouraged.
51075 + For reasons of compatibility, a few directories have been whitelisted
51076 + for access by non-root users:
51077 + /sys/fs/selinux
51078 + /sys/fs/fuse
51079 + /sys/devices/system/cpu
51080 +
51081 +config GRKERNSEC_ROFS
51082 + bool "Runtime read-only mount protection"
51083 + help
51084 + If you say Y here, a sysctl option with name "romount_protect" will
51085 + be created. By setting this option to 1 at runtime, filesystems
51086 + will be protected in the following ways:
51087 + * No new writable mounts will be allowed
51088 + * Existing read-only mounts won't be able to be remounted read/write
51089 + * Write operations will be denied on all block devices
51090 + This option acts independently of grsec_lock: once it is set to 1,
51091 + it cannot be turned off. Therefore, please be mindful of the resulting
51092 + behavior if this option is enabled in an init script on a read-only
51093 + filesystem. This feature is mainly intended for secure embedded systems.
51094 +
51095 +config GRKERNSEC_CHROOT
51096 + bool "Chroot jail restrictions"
51097 + default y if GRKERNSEC_CONFIG_AUTO
51098 + help
51099 + If you say Y here, you will be able to choose several options that will
51100 + make breaking out of a chrooted jail much more difficult. If you
51101 + encounter no software incompatibilities with the following options, it
51102 + is recommended that you enable each one.
51103 +
51104 +config GRKERNSEC_CHROOT_MOUNT
51105 + bool "Deny mounts"
51106 + default y if GRKERNSEC_CONFIG_AUTO
51107 + depends on GRKERNSEC_CHROOT
51108 + help
51109 + If you say Y here, processes inside a chroot will not be able to
51110 + mount or remount filesystems. If the sysctl option is enabled, a
51111 + sysctl option with name "chroot_deny_mount" is created.
51112 +
51113 +config GRKERNSEC_CHROOT_DOUBLE
51114 + bool "Deny double-chroots"
51115 + default y if GRKERNSEC_CONFIG_AUTO
51116 + depends on GRKERNSEC_CHROOT
51117 + help
51118 + If you say Y here, processes inside a chroot will not be able to chroot
51119 + again outside the chroot. This is a widely used method of breaking
51120 + out of a chroot jail and should not be allowed. If the sysctl
51121 + option is enabled, a sysctl option with name
51122 + "chroot_deny_chroot" is created.
51123 +
51124 +config GRKERNSEC_CHROOT_PIVOT
51125 + bool "Deny pivot_root in chroot"
51126 + default y if GRKERNSEC_CONFIG_AUTO
51127 + depends on GRKERNSEC_CHROOT
51128 + help
51129 + If you say Y here, processes inside a chroot will not be able to use
51130 + a function called pivot_root() that was introduced in Linux 2.3.41. It
51131 + works similar to chroot in that it changes the root filesystem. This
51132 + function could be misused in a chrooted process to attempt to break out
51133 + of the chroot, and therefore should not be allowed. If the sysctl
51134 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
51135 + created.
51136 +
51137 +config GRKERNSEC_CHROOT_CHDIR
51138 + bool "Enforce chdir(\"/\") on all chroots"
51139 + default y if GRKERNSEC_CONFIG_AUTO
51140 + depends on GRKERNSEC_CHROOT
51141 + help
51142 + If you say Y here, the current working directory of all newly-chrooted
51143 + applications will be set to the the root directory of the chroot.
51144 + The man page on chroot(2) states:
51145 + Note that this call does not change the current working
51146 + directory, so that `.' can be outside the tree rooted at
51147 + `/'. In particular, the super-user can escape from a
51148 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
51149 +
51150 + It is recommended that you say Y here, since it's not known to break
51151 + any software. If the sysctl option is enabled, a sysctl option with
51152 + name "chroot_enforce_chdir" is created.
51153 +
51154 +config GRKERNSEC_CHROOT_CHMOD
51155 + bool "Deny (f)chmod +s"
51156 + default y if GRKERNSEC_CONFIG_AUTO
51157 + depends on GRKERNSEC_CHROOT
51158 + help
51159 + If you say Y here, processes inside a chroot will not be able to chmod
51160 + or fchmod files to make them have suid or sgid bits. This protects
51161 + against another published method of breaking a chroot. If the sysctl
51162 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
51163 + created.
51164 +
51165 +config GRKERNSEC_CHROOT_FCHDIR
51166 + bool "Deny fchdir out of chroot"
51167 + default y if GRKERNSEC_CONFIG_AUTO
51168 + depends on GRKERNSEC_CHROOT
51169 + help
51170 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
51171 + to a file descriptor of the chrooting process that points to a directory
51172 + outside the filesystem will be stopped. If the sysctl option
51173 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
51174 +
51175 +config GRKERNSEC_CHROOT_MKNOD
51176 + bool "Deny mknod"
51177 + default y if GRKERNSEC_CONFIG_AUTO
51178 + depends on GRKERNSEC_CHROOT
51179 + help
51180 + If you say Y here, processes inside a chroot will not be allowed to
51181 + mknod. The problem with using mknod inside a chroot is that it
51182 + would allow an attacker to create a device entry that is the same
51183 + as one on the physical root of your system, which could range from
51184 + anything from the console device to a device for your harddrive (which
51185 + they could then use to wipe the drive or steal data). It is recommended
51186 + that you say Y here, unless you run into software incompatibilities.
51187 + If the sysctl option is enabled, a sysctl option with name
51188 + "chroot_deny_mknod" is created.
51189 +
51190 +config GRKERNSEC_CHROOT_SHMAT
51191 + bool "Deny shmat() out of chroot"
51192 + default y if GRKERNSEC_CONFIG_AUTO
51193 + depends on GRKERNSEC_CHROOT
51194 + help
51195 + If you say Y here, processes inside a chroot will not be able to attach
51196 + to shared memory segments that were created outside of the chroot jail.
51197 + It is recommended that you say Y here. If the sysctl option is enabled,
51198 + a sysctl option with name "chroot_deny_shmat" is created.
51199 +
51200 +config GRKERNSEC_CHROOT_UNIX
51201 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
51202 + default y if GRKERNSEC_CONFIG_AUTO
51203 + depends on GRKERNSEC_CHROOT
51204 + help
51205 + If you say Y here, processes inside a chroot will not be able to
51206 + connect to abstract (meaning not belonging to a filesystem) Unix
51207 + domain sockets that were bound outside of a chroot. It is recommended
51208 + that you say Y here. If the sysctl option is enabled, a sysctl option
51209 + with name "chroot_deny_unix" is created.
51210 +
51211 +config GRKERNSEC_CHROOT_FINDTASK
51212 + bool "Protect outside processes"
51213 + default y if GRKERNSEC_CONFIG_AUTO
51214 + depends on GRKERNSEC_CHROOT
51215 + help
51216 + If you say Y here, processes inside a chroot will not be able to
51217 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
51218 + getsid, or view any process outside of the chroot. If the sysctl
51219 + option is enabled, a sysctl option with name "chroot_findtask" is
51220 + created.
51221 +
51222 +config GRKERNSEC_CHROOT_NICE
51223 + bool "Restrict priority changes"
51224 + default y if GRKERNSEC_CONFIG_AUTO
51225 + depends on GRKERNSEC_CHROOT
51226 + help
51227 + If you say Y here, processes inside a chroot will not be able to raise
51228 + the priority of processes in the chroot, or alter the priority of
51229 + processes outside the chroot. This provides more security than simply
51230 + removing CAP_SYS_NICE from the process' capability set. If the
51231 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
51232 + is created.
51233 +
51234 +config GRKERNSEC_CHROOT_SYSCTL
51235 + bool "Deny sysctl writes"
51236 + default y if GRKERNSEC_CONFIG_AUTO
51237 + depends on GRKERNSEC_CHROOT
51238 + help
51239 + If you say Y here, an attacker in a chroot will not be able to
51240 + write to sysctl entries, either by sysctl(2) or through a /proc
51241 + interface. It is strongly recommended that you say Y here. If the
51242 + sysctl option is enabled, a sysctl option with name
51243 + "chroot_deny_sysctl" is created.
51244 +
51245 +config GRKERNSEC_CHROOT_CAPS
51246 + bool "Capability restrictions"
51247 + default y if GRKERNSEC_CONFIG_AUTO
51248 + depends on GRKERNSEC_CHROOT
51249 + help
51250 + If you say Y here, the capabilities on all processes within a
51251 + chroot jail will be lowered to stop module insertion, raw i/o,
51252 + system and net admin tasks, rebooting the system, modifying immutable
51253 + files, modifying IPC owned by another, and changing the system time.
51254 + This is left an option because it can break some apps. Disable this
51255 + if your chrooted apps are having problems performing those kinds of
51256 + tasks. If the sysctl option is enabled, a sysctl option with
51257 + name "chroot_caps" is created.
51258 +
51259 +endmenu
51260 +menu "Kernel Auditing"
51261 +depends on GRKERNSEC
51262 +
51263 +config GRKERNSEC_AUDIT_GROUP
51264 + bool "Single group for auditing"
51265 + help
51266 + If you say Y here, the exec, chdir, and (un)mount logging features
51267 + will only operate on a group you specify. This option is recommended
51268 + if you only want to watch certain users instead of having a large
51269 + amount of logs from the entire system. If the sysctl option is enabled,
51270 + a sysctl option with name "audit_group" is created.
51271 +
51272 +config GRKERNSEC_AUDIT_GID
51273 + int "GID for auditing"
51274 + depends on GRKERNSEC_AUDIT_GROUP
51275 + default 1007
51276 +
51277 +config GRKERNSEC_EXECLOG
51278 + bool "Exec logging"
51279 + help
51280 + If you say Y here, all execve() calls will be logged (since the
51281 + other exec*() calls are frontends to execve(), all execution
51282 + will be logged). Useful for shell-servers that like to keep track
51283 + of their users. If the sysctl option is enabled, a sysctl option with
51284 + name "exec_logging" is created.
51285 + WARNING: This option when enabled will produce a LOT of logs, especially
51286 + on an active system.
51287 +
51288 +config GRKERNSEC_RESLOG
51289 + bool "Resource logging"
51290 + default y if GRKERNSEC_CONFIG_AUTO
51291 + help
51292 + If you say Y here, all attempts to overstep resource limits will
51293 + be logged with the resource name, the requested size, and the current
51294 + limit. It is highly recommended that you say Y here. If the sysctl
51295 + option is enabled, a sysctl option with name "resource_logging" is
51296 + created. If the RBAC system is enabled, the sysctl value is ignored.
51297 +
51298 +config GRKERNSEC_CHROOT_EXECLOG
51299 + bool "Log execs within chroot"
51300 + help
51301 + If you say Y here, all executions inside a chroot jail will be logged
51302 + to syslog. This can cause a large amount of logs if certain
51303 + applications (eg. djb's daemontools) are installed on the system, and
51304 + is therefore left as an option. If the sysctl option is enabled, a
51305 + sysctl option with name "chroot_execlog" is created.
51306 +
51307 +config GRKERNSEC_AUDIT_PTRACE
51308 + bool "Ptrace logging"
51309 + help
51310 + If you say Y here, all attempts to attach to a process via ptrace
51311 + will be logged. If the sysctl option is enabled, a sysctl option
51312 + with name "audit_ptrace" is created.
51313 +
51314 +config GRKERNSEC_AUDIT_CHDIR
51315 + bool "Chdir logging"
51316 + help
51317 + If you say Y here, all chdir() calls will be logged. If the sysctl
51318 + option is enabled, a sysctl option with name "audit_chdir" is created.
51319 +
51320 +config GRKERNSEC_AUDIT_MOUNT
51321 + bool "(Un)Mount logging"
51322 + help
51323 + If you say Y here, all mounts and unmounts will be logged. If the
51324 + sysctl option is enabled, a sysctl option with name "audit_mount" is
51325 + created.
51326 +
51327 +config GRKERNSEC_SIGNAL
51328 + bool "Signal logging"
51329 + default y if GRKERNSEC_CONFIG_AUTO
51330 + help
51331 + If you say Y here, certain important signals will be logged, such as
51332 + SIGSEGV, which will as a result inform you of when a error in a program
51333 + occurred, which in some cases could mean a possible exploit attempt.
51334 + If the sysctl option is enabled, a sysctl option with name
51335 + "signal_logging" is created.
51336 +
51337 +config GRKERNSEC_FORKFAIL
51338 + bool "Fork failure logging"
51339 + help
51340 + If you say Y here, all failed fork() attempts will be logged.
51341 + This could suggest a fork bomb, or someone attempting to overstep
51342 + their process limit. If the sysctl option is enabled, a sysctl option
51343 + with name "forkfail_logging" is created.
51344 +
51345 +config GRKERNSEC_TIME
51346 + bool "Time change logging"
51347 + default y if GRKERNSEC_CONFIG_AUTO
51348 + help
51349 + If you say Y here, any changes of the system clock will be logged.
51350 + If the sysctl option is enabled, a sysctl option with name
51351 + "timechange_logging" is created.
51352 +
51353 +config GRKERNSEC_PROC_IPADDR
51354 + bool "/proc/<pid>/ipaddr support"
51355 + default y if GRKERNSEC_CONFIG_AUTO
51356 + help
51357 + If you say Y here, a new entry will be added to each /proc/<pid>
51358 + directory that contains the IP address of the person using the task.
51359 + The IP is carried across local TCP and AF_UNIX stream sockets.
51360 + This information can be useful for IDS/IPSes to perform remote response
51361 + to a local attack. The entry is readable by only the owner of the
51362 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
51363 + the RBAC system), and thus does not create privacy concerns.
51364 +
51365 +config GRKERNSEC_RWXMAP_LOG
51366 + bool 'Denied RWX mmap/mprotect logging'
51367 + default y if GRKERNSEC_CONFIG_AUTO
51368 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
51369 + help
51370 + If you say Y here, calls to mmap() and mprotect() with explicit
51371 + usage of PROT_WRITE and PROT_EXEC together will be logged when
51372 + denied by the PAX_MPROTECT feature. If the sysctl option is
51373 + enabled, a sysctl option with name "rwxmap_logging" is created.
51374 +
51375 +config GRKERNSEC_AUDIT_TEXTREL
51376 + bool 'ELF text relocations logging (READ HELP)'
51377 + depends on PAX_MPROTECT
51378 + help
51379 + If you say Y here, text relocations will be logged with the filename
51380 + of the offending library or binary. The purpose of the feature is
51381 + to help Linux distribution developers get rid of libraries and
51382 + binaries that need text relocations which hinder the future progress
51383 + of PaX. Only Linux distribution developers should say Y here, and
51384 + never on a production machine, as this option creates an information
51385 + leak that could aid an attacker in defeating the randomization of
51386 + a single memory region. If the sysctl option is enabled, a sysctl
51387 + option with name "audit_textrel" is created.
51388 +
51389 +endmenu
51390 +
51391 +menu "Executable Protections"
51392 +depends on GRKERNSEC
51393 +
51394 +config GRKERNSEC_DMESG
51395 + bool "Dmesg(8) restriction"
51396 + default y if GRKERNSEC_CONFIG_AUTO
51397 + help
51398 + If you say Y here, non-root users will not be able to use dmesg(8)
51399 + to view up to the last 4kb of messages in the kernel's log buffer.
51400 + The kernel's log buffer often contains kernel addresses and other
51401 + identifying information useful to an attacker in fingerprinting a
51402 + system for a targeted exploit.
51403 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
51404 + created.
51405 +
51406 +config GRKERNSEC_HARDEN_PTRACE
51407 + bool "Deter ptrace-based process snooping"
51408 + default y if GRKERNSEC_CONFIG_AUTO
51409 + help
51410 + If you say Y here, TTY sniffers and other malicious monitoring
51411 + programs implemented through ptrace will be defeated. If you
51412 + have been using the RBAC system, this option has already been
51413 + enabled for several years for all users, with the ability to make
51414 + fine-grained exceptions.
51415 +
51416 + This option only affects the ability of non-root users to ptrace
51417 + processes that are not a descendent of the ptracing process.
51418 + This means that strace ./binary and gdb ./binary will still work,
51419 + but attaching to arbitrary processes will not. If the sysctl
51420 + option is enabled, a sysctl option with name "harden_ptrace" is
51421 + created.
51422 +
51423 +config GRKERNSEC_PTRACE_READEXEC
51424 + bool "Require read access to ptrace sensitive binaries"
51425 + default y if GRKERNSEC_CONFIG_AUTO
51426 + help
51427 + If you say Y here, unprivileged users will not be able to ptrace unreadable
51428 + binaries. This option is useful in environments that
51429 + remove the read bits (e.g. file mode 4711) from suid binaries to
51430 + prevent infoleaking of their contents. This option adds
51431 + consistency to the use of that file mode, as the binary could normally
51432 + be read out when run without privileges while ptracing.
51433 +
51434 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
51435 + is created.
51436 +
51437 +config GRKERNSEC_SETXID
51438 + bool "Enforce consistent multithreaded privileges"
51439 + default y if GRKERNSEC_CONFIG_AUTO
51440 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
51441 + help
51442 + If you say Y here, a change from a root uid to a non-root uid
51443 + in a multithreaded application will cause the resulting uids,
51444 + gids, supplementary groups, and capabilities in that thread
51445 + to be propagated to the other threads of the process. In most
51446 + cases this is unnecessary, as glibc will emulate this behavior
51447 + on behalf of the application. Other libcs do not act in the
51448 + same way, allowing the other threads of the process to continue
51449 + running with root privileges. If the sysctl option is enabled,
51450 + a sysctl option with name "consistent_setxid" is created.
51451 +
51452 +config GRKERNSEC_TPE
51453 + bool "Trusted Path Execution (TPE)"
51454 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
51455 + help
51456 + If you say Y here, you will be able to choose a gid to add to the
51457 + supplementary groups of users you want to mark as "untrusted."
51458 + These users will not be able to execute any files that are not in
51459 + root-owned directories writable only by root. If the sysctl option
51460 + is enabled, a sysctl option with name "tpe" is created.
51461 +
51462 +config GRKERNSEC_TPE_ALL
51463 + bool "Partially restrict all non-root users"
51464 + depends on GRKERNSEC_TPE
51465 + help
51466 + If you say Y here, all non-root users will be covered under
51467 + a weaker TPE restriction. This is separate from, and in addition to,
51468 + the main TPE options that you have selected elsewhere. Thus, if a
51469 + "trusted" GID is chosen, this restriction applies to even that GID.
51470 + Under this restriction, all non-root users will only be allowed to
51471 + execute files in directories they own that are not group or
51472 + world-writable, or in directories owned by root and writable only by
51473 + root. If the sysctl option is enabled, a sysctl option with name
51474 + "tpe_restrict_all" is created.
51475 +
51476 +config GRKERNSEC_TPE_INVERT
51477 + bool "Invert GID option"
51478 + depends on GRKERNSEC_TPE
51479 + help
51480 + If you say Y here, the group you specify in the TPE configuration will
51481 + decide what group TPE restrictions will be *disabled* for. This
51482 + option is useful if you want TPE restrictions to be applied to most
51483 + users on the system. If the sysctl option is enabled, a sysctl option
51484 + with name "tpe_invert" is created. Unlike other sysctl options, this
51485 + entry will default to on for backward-compatibility.
51486 +
51487 +config GRKERNSEC_TPE_GID
51488 + int
51489 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
51490 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
51491 +
51492 +config GRKERNSEC_TPE_UNTRUSTED_GID
51493 + int "GID for TPE-untrusted users"
51494 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
51495 + default 1005
51496 + help
51497 + Setting this GID determines what group TPE restrictions will be
51498 + *enabled* for. If the sysctl option is enabled, a sysctl option
51499 + with name "tpe_gid" is created.
51500 +
51501 +config GRKERNSEC_TPE_TRUSTED_GID
51502 + int "GID for TPE-trusted users"
51503 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
51504 + default 1005
51505 + help
51506 + Setting this GID determines what group TPE restrictions will be
51507 + *disabled* for. If the sysctl option is enabled, a sysctl option
51508 + with name "tpe_gid" is created.
51509 +
51510 +endmenu
51511 +menu "Network Protections"
51512 +depends on GRKERNSEC
51513 +
51514 +config GRKERNSEC_RANDNET
51515 + bool "Larger entropy pools"
51516 + default y if GRKERNSEC_CONFIG_AUTO
51517 + help
51518 + If you say Y here, the entropy pools used for many features of Linux
51519 + and grsecurity will be doubled in size. Since several grsecurity
51520 + features use additional randomness, it is recommended that you say Y
51521 + here. Saying Y here has a similar effect as modifying
51522 + /proc/sys/kernel/random/poolsize.
51523 +
51524 +config GRKERNSEC_BLACKHOLE
51525 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
51526 + default y if GRKERNSEC_CONFIG_AUTO
51527 + depends on NET
51528 + help
51529 + If you say Y here, neither TCP resets nor ICMP
51530 + destination-unreachable packets will be sent in response to packets
51531 + sent to ports for which no associated listening process exists.
51532 + This feature supports both IPV4 and IPV6 and exempts the
51533 + loopback interface from blackholing. Enabling this feature
51534 + makes a host more resilient to DoS attacks and reduces network
51535 + visibility against scanners.
51536 +
51537 + The blackhole feature as-implemented is equivalent to the FreeBSD
51538 + blackhole feature, as it prevents RST responses to all packets, not
51539 + just SYNs. Under most application behavior this causes no
51540 + problems, but applications (like haproxy) may not close certain
51541 + connections in a way that cleanly terminates them on the remote
51542 + end, leaving the remote host in LAST_ACK state. Because of this
51543 + side-effect and to prevent intentional LAST_ACK DoSes, this
51544 + feature also adds automatic mitigation against such attacks.
51545 + The mitigation drastically reduces the amount of time a socket
51546 + can spend in LAST_ACK state. If you're using haproxy and not
51547 + all servers it connects to have this option enabled, consider
51548 + disabling this feature on the haproxy host.
51549 +
51550 + If the sysctl option is enabled, two sysctl options with names
51551 + "ip_blackhole" and "lastack_retries" will be created.
51552 + While "ip_blackhole" takes the standard zero/non-zero on/off
51553 + toggle, "lastack_retries" uses the same kinds of values as
51554 + "tcp_retries1" and "tcp_retries2". The default value of 4
51555 + prevents a socket from lasting more than 45 seconds in LAST_ACK
51556 + state.
51557 +
51558 +config GRKERNSEC_SOCKET
51559 + bool "Socket restrictions"
51560 + depends on NET
51561 + help
51562 + If you say Y here, you will be able to choose from several options.
51563 + If you assign a GID on your system and add it to the supplementary
51564 + groups of users you want to restrict socket access to, this patch
51565 + will perform up to three things, based on the option(s) you choose.
51566 +
51567 +config GRKERNSEC_SOCKET_ALL
51568 + bool "Deny any sockets to group"
51569 + depends on GRKERNSEC_SOCKET
51570 + help
51571 + If you say Y here, you will be able to choose a GID of whose users will
51572 + be unable to connect to other hosts from your machine or run server
51573 + applications from your machine. If the sysctl option is enabled, a
51574 + sysctl option with name "socket_all" is created.
51575 +
51576 +config GRKERNSEC_SOCKET_ALL_GID
51577 + int "GID to deny all sockets for"
51578 + depends on GRKERNSEC_SOCKET_ALL
51579 + default 1004
51580 + help
51581 + Here you can choose the GID to disable socket access for. Remember to
51582 + add the users you want socket access disabled for to the GID
51583 + specified here. If the sysctl option is enabled, a sysctl option
51584 + with name "socket_all_gid" is created.
51585 +
51586 +config GRKERNSEC_SOCKET_CLIENT
51587 + bool "Deny client sockets to group"
51588 + depends on GRKERNSEC_SOCKET
51589 + help
51590 + If you say Y here, you will be able to choose a GID of whose users will
51591 + be unable to connect to other hosts from your machine, but will be
51592 + able to run servers. If this option is enabled, all users in the group
51593 + you specify will have to use passive mode when initiating ftp transfers
51594 + from the shell on your machine. If the sysctl option is enabled, a
51595 + sysctl option with name "socket_client" is created.
51596 +
51597 +config GRKERNSEC_SOCKET_CLIENT_GID
51598 + int "GID to deny client sockets for"
51599 + depends on GRKERNSEC_SOCKET_CLIENT
51600 + default 1003
51601 + help
51602 + Here you can choose the GID to disable client socket access for.
51603 + Remember to add the users you want client socket access disabled for to
51604 + the GID specified here. If the sysctl option is enabled, a sysctl
51605 + option with name "socket_client_gid" is created.
51606 +
51607 +config GRKERNSEC_SOCKET_SERVER
51608 + bool "Deny server sockets to group"
51609 + depends on GRKERNSEC_SOCKET
51610 + help
51611 + If you say Y here, you will be able to choose a GID of whose users will
51612 + be unable to run server applications from your machine. If the sysctl
51613 + option is enabled, a sysctl option with name "socket_server" is created.
51614 +
51615 +config GRKERNSEC_SOCKET_SERVER_GID
51616 + int "GID to deny server sockets for"
51617 + depends on GRKERNSEC_SOCKET_SERVER
51618 + default 1002
51619 + help
51620 + Here you can choose the GID to disable server socket access for.
51621 + Remember to add the users you want server socket access disabled for to
51622 + the GID specified here. If the sysctl option is enabled, a sysctl
51623 + option with name "socket_server_gid" is created.
51624 +
51625 +endmenu
51626 +menu "Sysctl Support"
51627 +depends on GRKERNSEC && SYSCTL
51628 +
51629 +config GRKERNSEC_SYSCTL
51630 + bool "Sysctl support"
51631 + default y if GRKERNSEC_CONFIG_AUTO
51632 + help
51633 + If you say Y here, you will be able to change the options that
51634 + grsecurity runs with at bootup, without having to recompile your
51635 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
51636 + to enable (1) or disable (0) various features. All the sysctl entries
51637 + are mutable until the "grsec_lock" entry is set to a non-zero value.
51638 + All features enabled in the kernel configuration are disabled at boot
51639 + if you do not say Y to the "Turn on features by default" option.
51640 + All options should be set at startup, and the grsec_lock entry should
51641 + be set to a non-zero value after all the options are set.
51642 + *THIS IS EXTREMELY IMPORTANT*
51643 +
51644 +config GRKERNSEC_SYSCTL_DISTRO
51645 + bool "Extra sysctl support for distro makers (READ HELP)"
51646 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
51647 + help
51648 + If you say Y here, additional sysctl options will be created
51649 + for features that affect processes running as root. Therefore,
51650 + it is critical when using this option that the grsec_lock entry be
51651 + enabled after boot. Only distros with prebuilt kernel packages
51652 + with this option enabled that can ensure grsec_lock is enabled
51653 + after boot should use this option.
51654 + *Failure to set grsec_lock after boot makes all grsec features
51655 + this option covers useless*
51656 +
51657 + Currently this option creates the following sysctl entries:
51658 + "Disable Privileged I/O": "disable_priv_io"
51659 +
51660 +config GRKERNSEC_SYSCTL_ON
51661 + bool "Turn on features by default"
51662 + default y if GRKERNSEC_CONFIG_AUTO
51663 + depends on GRKERNSEC_SYSCTL
51664 + help
51665 + If you say Y here, instead of having all features enabled in the
51666 + kernel configuration disabled at boot time, the features will be
51667 + enabled at boot time. It is recommended you say Y here unless
51668 + there is some reason you would want all sysctl-tunable features to
51669 + be disabled by default. As mentioned elsewhere, it is important
51670 + to enable the grsec_lock entry once you have finished modifying
51671 + the sysctl entries.
51672 +
51673 +endmenu
51674 +menu "Logging Options"
51675 +depends on GRKERNSEC
51676 +
51677 +config GRKERNSEC_FLOODTIME
51678 + int "Seconds in between log messages (minimum)"
51679 + default 10
51680 + help
51681 + This option allows you to enforce the number of seconds between
51682 + grsecurity log messages. The default should be suitable for most
51683 + people, however, if you choose to change it, choose a value small enough
51684 + to allow informative logs to be produced, but large enough to
51685 + prevent flooding.
51686 +
51687 +config GRKERNSEC_FLOODBURST
51688 + int "Number of messages in a burst (maximum)"
51689 + default 6
51690 + help
51691 + This option allows you to choose the maximum number of messages allowed
51692 + within the flood time interval you chose in a separate option. The
51693 + default should be suitable for most people, however if you find that
51694 + many of your logs are being interpreted as flooding, you may want to
51695 + raise this value.
51696 +
51697 +endmenu
51698 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
51699 new file mode 100644
51700 index 0000000..1b9afa9
51701 --- /dev/null
51702 +++ b/grsecurity/Makefile
51703 @@ -0,0 +1,38 @@
51704 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
51705 +# during 2001-2009 it has been completely redesigned by Brad Spengler
51706 +# into an RBAC system
51707 +#
51708 +# All code in this directory and various hooks inserted throughout the kernel
51709 +# are copyright Brad Spengler - Open Source Security, Inc., and released
51710 +# under the GPL v2 or higher
51711 +
51712 +KBUILD_CFLAGS += -Werror
51713 +
51714 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
51715 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
51716 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
51717 +
51718 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
51719 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
51720 + gracl_learn.o grsec_log.o
51721 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
51722 +
51723 +ifdef CONFIG_NET
51724 +obj-y += grsec_sock.o
51725 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
51726 +endif
51727 +
51728 +ifndef CONFIG_GRKERNSEC
51729 +obj-y += grsec_disabled.o
51730 +endif
51731 +
51732 +ifdef CONFIG_GRKERNSEC_HIDESYM
51733 +extra-y := grsec_hidesym.o
51734 +$(obj)/grsec_hidesym.o:
51735 + @-chmod -f 500 /boot
51736 + @-chmod -f 500 /lib/modules
51737 + @-chmod -f 500 /lib64/modules
51738 + @-chmod -f 500 /lib32/modules
51739 + @-chmod -f 700 .
51740 + @echo ' grsec: protected kernel image paths'
51741 +endif
51742 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
51743 new file mode 100644
51744 index 0000000..3d58260
51745 --- /dev/null
51746 +++ b/grsecurity/gracl.c
51747 @@ -0,0 +1,4029 @@
51748 +#include <linux/kernel.h>
51749 +#include <linux/module.h>
51750 +#include <linux/sched.h>
51751 +#include <linux/mm.h>
51752 +#include <linux/file.h>
51753 +#include <linux/fs.h>
51754 +#include <linux/namei.h>
51755 +#include <linux/mount.h>
51756 +#include <linux/tty.h>
51757 +#include <linux/proc_fs.h>
51758 +#include <linux/lglock.h>
51759 +#include <linux/slab.h>
51760 +#include <linux/vmalloc.h>
51761 +#include <linux/types.h>
51762 +#include <linux/sysctl.h>
51763 +#include <linux/netdevice.h>
51764 +#include <linux/ptrace.h>
51765 +#include <linux/gracl.h>
51766 +#include <linux/gralloc.h>
51767 +#include <linux/security.h>
51768 +#include <linux/grinternal.h>
51769 +#include <linux/pid_namespace.h>
51770 +#include <linux/stop_machine.h>
51771 +#include <linux/fdtable.h>
51772 +#include <linux/percpu.h>
51773 +#include <linux/lglock.h>
51774 +#include "../fs/mount.h"
51775 +
51776 +#include <asm/uaccess.h>
51777 +#include <asm/errno.h>
51778 +#include <asm/mman.h>
51779 +
51780 +extern struct lglock vfsmount_lock;
51781 +
51782 +static struct acl_role_db acl_role_set;
51783 +static struct name_db name_set;
51784 +static struct inodev_db inodev_set;
51785 +
51786 +/* for keeping track of userspace pointers used for subjects, so we
51787 + can share references in the kernel as well
51788 +*/
51789 +
51790 +static struct path real_root;
51791 +
51792 +static struct acl_subj_map_db subj_map_set;
51793 +
51794 +static struct acl_role_label *default_role;
51795 +
51796 +static struct acl_role_label *role_list;
51797 +
51798 +static u16 acl_sp_role_value;
51799 +
51800 +extern char *gr_shared_page[4];
51801 +static DEFINE_MUTEX(gr_dev_mutex);
51802 +DEFINE_RWLOCK(gr_inode_lock);
51803 +
51804 +struct gr_arg *gr_usermode;
51805 +
51806 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
51807 +
51808 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
51809 +extern void gr_clear_learn_entries(void);
51810 +
51811 +#ifdef CONFIG_GRKERNSEC_RESLOG
51812 +extern void gr_log_resource(const struct task_struct *task,
51813 + const int res, const unsigned long wanted, const int gt);
51814 +#endif
51815 +
51816 +unsigned char *gr_system_salt;
51817 +unsigned char *gr_system_sum;
51818 +
51819 +static struct sprole_pw **acl_special_roles = NULL;
51820 +static __u16 num_sprole_pws = 0;
51821 +
51822 +static struct acl_role_label *kernel_role = NULL;
51823 +
51824 +static unsigned int gr_auth_attempts = 0;
51825 +static unsigned long gr_auth_expires = 0UL;
51826 +
51827 +#ifdef CONFIG_NET
51828 +extern struct vfsmount *sock_mnt;
51829 +#endif
51830 +
51831 +extern struct vfsmount *pipe_mnt;
51832 +extern struct vfsmount *shm_mnt;
51833 +#ifdef CONFIG_HUGETLBFS
51834 +extern struct vfsmount *hugetlbfs_vfsmount;
51835 +#endif
51836 +
51837 +static struct acl_object_label *fakefs_obj_rw;
51838 +static struct acl_object_label *fakefs_obj_rwx;
51839 +
51840 +extern int gr_init_uidset(void);
51841 +extern void gr_free_uidset(void);
51842 +extern void gr_remove_uid(uid_t uid);
51843 +extern int gr_find_uid(uid_t uid);
51844 +
51845 +__inline__ int
51846 +gr_acl_is_enabled(void)
51847 +{
51848 + return (gr_status & GR_READY);
51849 +}
51850 +
51851 +#ifdef CONFIG_BTRFS_FS
51852 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
51853 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
51854 +#endif
51855 +
51856 +static inline dev_t __get_dev(const struct dentry *dentry)
51857 +{
51858 +#ifdef CONFIG_BTRFS_FS
51859 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
51860 + return get_btrfs_dev_from_inode(dentry->d_inode);
51861 + else
51862 +#endif
51863 + return dentry->d_inode->i_sb->s_dev;
51864 +}
51865 +
51866 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
51867 +{
51868 + return __get_dev(dentry);
51869 +}
51870 +
51871 +static char gr_task_roletype_to_char(struct task_struct *task)
51872 +{
51873 + switch (task->role->roletype &
51874 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
51875 + GR_ROLE_SPECIAL)) {
51876 + case GR_ROLE_DEFAULT:
51877 + return 'D';
51878 + case GR_ROLE_USER:
51879 + return 'U';
51880 + case GR_ROLE_GROUP:
51881 + return 'G';
51882 + case GR_ROLE_SPECIAL:
51883 + return 'S';
51884 + }
51885 +
51886 + return 'X';
51887 +}
51888 +
51889 +char gr_roletype_to_char(void)
51890 +{
51891 + return gr_task_roletype_to_char(current);
51892 +}
51893 +
51894 +__inline__ int
51895 +gr_acl_tpe_check(void)
51896 +{
51897 + if (unlikely(!(gr_status & GR_READY)))
51898 + return 0;
51899 + if (current->role->roletype & GR_ROLE_TPE)
51900 + return 1;
51901 + else
51902 + return 0;
51903 +}
51904 +
51905 +int
51906 +gr_handle_rawio(const struct inode *inode)
51907 +{
51908 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
51909 + if (inode && S_ISBLK(inode->i_mode) &&
51910 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
51911 + !capable(CAP_SYS_RAWIO))
51912 + return 1;
51913 +#endif
51914 + return 0;
51915 +}
51916 +
51917 +static int
51918 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
51919 +{
51920 + if (likely(lena != lenb))
51921 + return 0;
51922 +
51923 + return !memcmp(a, b, lena);
51924 +}
51925 +
51926 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
51927 +{
51928 + *buflen -= namelen;
51929 + if (*buflen < 0)
51930 + return -ENAMETOOLONG;
51931 + *buffer -= namelen;
51932 + memcpy(*buffer, str, namelen);
51933 + return 0;
51934 +}
51935 +
51936 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
51937 +{
51938 + return prepend(buffer, buflen, name->name, name->len);
51939 +}
51940 +
51941 +static int prepend_path(const struct path *path, struct path *root,
51942 + char **buffer, int *buflen)
51943 +{
51944 + struct dentry *dentry = path->dentry;
51945 + struct vfsmount *vfsmnt = path->mnt;
51946 + struct mount *mnt = real_mount(vfsmnt);
51947 + bool slash = false;
51948 + int error = 0;
51949 +
51950 + while (dentry != root->dentry || vfsmnt != root->mnt) {
51951 + struct dentry * parent;
51952 +
51953 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
51954 + /* Global root? */
51955 + if (!mnt_has_parent(mnt)) {
51956 + goto out;
51957 + }
51958 + dentry = mnt->mnt_mountpoint;
51959 + mnt = mnt->mnt_parent;
51960 + vfsmnt = &mnt->mnt;
51961 + continue;
51962 + }
51963 + parent = dentry->d_parent;
51964 + prefetch(parent);
51965 + spin_lock(&dentry->d_lock);
51966 + error = prepend_name(buffer, buflen, &dentry->d_name);
51967 + spin_unlock(&dentry->d_lock);
51968 + if (!error)
51969 + error = prepend(buffer, buflen, "/", 1);
51970 + if (error)
51971 + break;
51972 +
51973 + slash = true;
51974 + dentry = parent;
51975 + }
51976 +
51977 +out:
51978 + if (!error && !slash)
51979 + error = prepend(buffer, buflen, "/", 1);
51980 +
51981 + return error;
51982 +}
51983 +
51984 +/* this must be called with vfsmount_lock and rename_lock held */
51985 +
51986 +static char *__our_d_path(const struct path *path, struct path *root,
51987 + char *buf, int buflen)
51988 +{
51989 + char *res = buf + buflen;
51990 + int error;
51991 +
51992 + prepend(&res, &buflen, "\0", 1);
51993 + error = prepend_path(path, root, &res, &buflen);
51994 + if (error)
51995 + return ERR_PTR(error);
51996 +
51997 + return res;
51998 +}
51999 +
52000 +static char *
52001 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
52002 +{
52003 + char *retval;
52004 +
52005 + retval = __our_d_path(path, root, buf, buflen);
52006 + if (unlikely(IS_ERR(retval)))
52007 + retval = strcpy(buf, "<path too long>");
52008 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
52009 + retval[1] = '\0';
52010 +
52011 + return retval;
52012 +}
52013 +
52014 +static char *
52015 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
52016 + char *buf, int buflen)
52017 +{
52018 + struct path path;
52019 + char *res;
52020 +
52021 + path.dentry = (struct dentry *)dentry;
52022 + path.mnt = (struct vfsmount *)vfsmnt;
52023 +
52024 + /* we can use real_root.dentry, real_root.mnt, because this is only called
52025 + by the RBAC system */
52026 + res = gen_full_path(&path, &real_root, buf, buflen);
52027 +
52028 + return res;
52029 +}
52030 +
52031 +static char *
52032 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
52033 + char *buf, int buflen)
52034 +{
52035 + char *res;
52036 + struct path path;
52037 + struct path root;
52038 + struct task_struct *reaper = init_pid_ns.child_reaper;
52039 +
52040 + path.dentry = (struct dentry *)dentry;
52041 + path.mnt = (struct vfsmount *)vfsmnt;
52042 +
52043 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
52044 + get_fs_root(reaper->fs, &root);
52045 +
52046 + write_seqlock(&rename_lock);
52047 + br_read_lock(&vfsmount_lock);
52048 + res = gen_full_path(&path, &root, buf, buflen);
52049 + br_read_unlock(&vfsmount_lock);
52050 + write_sequnlock(&rename_lock);
52051 +
52052 + path_put(&root);
52053 + return res;
52054 +}
52055 +
52056 +static char *
52057 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
52058 +{
52059 + char *ret;
52060 + write_seqlock(&rename_lock);
52061 + br_read_lock(&vfsmount_lock);
52062 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
52063 + PAGE_SIZE);
52064 + br_read_unlock(&vfsmount_lock);
52065 + write_sequnlock(&rename_lock);
52066 + return ret;
52067 +}
52068 +
52069 +static char *
52070 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
52071 +{
52072 + char *ret;
52073 + char *buf;
52074 + int buflen;
52075 +
52076 + write_seqlock(&rename_lock);
52077 + br_read_lock(&vfsmount_lock);
52078 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
52079 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
52080 + buflen = (int)(ret - buf);
52081 + if (buflen >= 5)
52082 + prepend(&ret, &buflen, "/proc", 5);
52083 + else
52084 + ret = strcpy(buf, "<path too long>");
52085 + br_read_unlock(&vfsmount_lock);
52086 + write_sequnlock(&rename_lock);
52087 + return ret;
52088 +}
52089 +
52090 +char *
52091 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
52092 +{
52093 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
52094 + PAGE_SIZE);
52095 +}
52096 +
52097 +char *
52098 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
52099 +{
52100 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
52101 + PAGE_SIZE);
52102 +}
52103 +
52104 +char *
52105 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
52106 +{
52107 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
52108 + PAGE_SIZE);
52109 +}
52110 +
52111 +char *
52112 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
52113 +{
52114 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
52115 + PAGE_SIZE);
52116 +}
52117 +
52118 +char *
52119 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
52120 +{
52121 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
52122 + PAGE_SIZE);
52123 +}
52124 +
52125 +__inline__ __u32
52126 +to_gr_audit(const __u32 reqmode)
52127 +{
52128 + /* masks off auditable permission flags, then shifts them to create
52129 + auditing flags, and adds the special case of append auditing if
52130 + we're requesting write */
52131 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
52132 +}
52133 +
52134 +struct acl_subject_label *
52135 +lookup_subject_map(const struct acl_subject_label *userp)
52136 +{
52137 + unsigned int index = shash(userp, subj_map_set.s_size);
52138 + struct subject_map *match;
52139 +
52140 + match = subj_map_set.s_hash[index];
52141 +
52142 + while (match && match->user != userp)
52143 + match = match->next;
52144 +
52145 + if (match != NULL)
52146 + return match->kernel;
52147 + else
52148 + return NULL;
52149 +}
52150 +
52151 +static void
52152 +insert_subj_map_entry(struct subject_map *subjmap)
52153 +{
52154 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
52155 + struct subject_map **curr;
52156 +
52157 + subjmap->prev = NULL;
52158 +
52159 + curr = &subj_map_set.s_hash[index];
52160 + if (*curr != NULL)
52161 + (*curr)->prev = subjmap;
52162 +
52163 + subjmap->next = *curr;
52164 + *curr = subjmap;
52165 +
52166 + return;
52167 +}
52168 +
52169 +static struct acl_role_label *
52170 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
52171 + const gid_t gid)
52172 +{
52173 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
52174 + struct acl_role_label *match;
52175 + struct role_allowed_ip *ipp;
52176 + unsigned int x;
52177 + u32 curr_ip = task->signal->curr_ip;
52178 +
52179 + task->signal->saved_ip = curr_ip;
52180 +
52181 + match = acl_role_set.r_hash[index];
52182 +
52183 + while (match) {
52184 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
52185 + for (x = 0; x < match->domain_child_num; x++) {
52186 + if (match->domain_children[x] == uid)
52187 + goto found;
52188 + }
52189 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
52190 + break;
52191 + match = match->next;
52192 + }
52193 +found:
52194 + if (match == NULL) {
52195 + try_group:
52196 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
52197 + match = acl_role_set.r_hash[index];
52198 +
52199 + while (match) {
52200 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
52201 + for (x = 0; x < match->domain_child_num; x++) {
52202 + if (match->domain_children[x] == gid)
52203 + goto found2;
52204 + }
52205 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
52206 + break;
52207 + match = match->next;
52208 + }
52209 +found2:
52210 + if (match == NULL)
52211 + match = default_role;
52212 + if (match->allowed_ips == NULL)
52213 + return match;
52214 + else {
52215 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52216 + if (likely
52217 + ((ntohl(curr_ip) & ipp->netmask) ==
52218 + (ntohl(ipp->addr) & ipp->netmask)))
52219 + return match;
52220 + }
52221 + match = default_role;
52222 + }
52223 + } else if (match->allowed_ips == NULL) {
52224 + return match;
52225 + } else {
52226 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52227 + if (likely
52228 + ((ntohl(curr_ip) & ipp->netmask) ==
52229 + (ntohl(ipp->addr) & ipp->netmask)))
52230 + return match;
52231 + }
52232 + goto try_group;
52233 + }
52234 +
52235 + return match;
52236 +}
52237 +
52238 +struct acl_subject_label *
52239 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
52240 + const struct acl_role_label *role)
52241 +{
52242 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
52243 + struct acl_subject_label *match;
52244 +
52245 + match = role->subj_hash[index];
52246 +
52247 + while (match && (match->inode != ino || match->device != dev ||
52248 + (match->mode & GR_DELETED))) {
52249 + match = match->next;
52250 + }
52251 +
52252 + if (match && !(match->mode & GR_DELETED))
52253 + return match;
52254 + else
52255 + return NULL;
52256 +}
52257 +
52258 +struct acl_subject_label *
52259 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
52260 + const struct acl_role_label *role)
52261 +{
52262 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
52263 + struct acl_subject_label *match;
52264 +
52265 + match = role->subj_hash[index];
52266 +
52267 + while (match && (match->inode != ino || match->device != dev ||
52268 + !(match->mode & GR_DELETED))) {
52269 + match = match->next;
52270 + }
52271 +
52272 + if (match && (match->mode & GR_DELETED))
52273 + return match;
52274 + else
52275 + return NULL;
52276 +}
52277 +
52278 +static struct acl_object_label *
52279 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
52280 + const struct acl_subject_label *subj)
52281 +{
52282 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
52283 + struct acl_object_label *match;
52284 +
52285 + match = subj->obj_hash[index];
52286 +
52287 + while (match && (match->inode != ino || match->device != dev ||
52288 + (match->mode & GR_DELETED))) {
52289 + match = match->next;
52290 + }
52291 +
52292 + if (match && !(match->mode & GR_DELETED))
52293 + return match;
52294 + else
52295 + return NULL;
52296 +}
52297 +
52298 +static struct acl_object_label *
52299 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
52300 + const struct acl_subject_label *subj)
52301 +{
52302 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
52303 + struct acl_object_label *match;
52304 +
52305 + match = subj->obj_hash[index];
52306 +
52307 + while (match && (match->inode != ino || match->device != dev ||
52308 + !(match->mode & GR_DELETED))) {
52309 + match = match->next;
52310 + }
52311 +
52312 + if (match && (match->mode & GR_DELETED))
52313 + return match;
52314 +
52315 + match = subj->obj_hash[index];
52316 +
52317 + while (match && (match->inode != ino || match->device != dev ||
52318 + (match->mode & GR_DELETED))) {
52319 + match = match->next;
52320 + }
52321 +
52322 + if (match && !(match->mode & GR_DELETED))
52323 + return match;
52324 + else
52325 + return NULL;
52326 +}
52327 +
52328 +static struct name_entry *
52329 +lookup_name_entry(const char *name)
52330 +{
52331 + unsigned int len = strlen(name);
52332 + unsigned int key = full_name_hash(name, len);
52333 + unsigned int index = key % name_set.n_size;
52334 + struct name_entry *match;
52335 +
52336 + match = name_set.n_hash[index];
52337 +
52338 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
52339 + match = match->next;
52340 +
52341 + return match;
52342 +}
52343 +
52344 +static struct name_entry *
52345 +lookup_name_entry_create(const char *name)
52346 +{
52347 + unsigned int len = strlen(name);
52348 + unsigned int key = full_name_hash(name, len);
52349 + unsigned int index = key % name_set.n_size;
52350 + struct name_entry *match;
52351 +
52352 + match = name_set.n_hash[index];
52353 +
52354 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52355 + !match->deleted))
52356 + match = match->next;
52357 +
52358 + if (match && match->deleted)
52359 + return match;
52360 +
52361 + match = name_set.n_hash[index];
52362 +
52363 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52364 + match->deleted))
52365 + match = match->next;
52366 +
52367 + if (match && !match->deleted)
52368 + return match;
52369 + else
52370 + return NULL;
52371 +}
52372 +
52373 +static struct inodev_entry *
52374 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
52375 +{
52376 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
52377 + struct inodev_entry *match;
52378 +
52379 + match = inodev_set.i_hash[index];
52380 +
52381 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
52382 + match = match->next;
52383 +
52384 + return match;
52385 +}
52386 +
52387 +static void
52388 +insert_inodev_entry(struct inodev_entry *entry)
52389 +{
52390 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
52391 + inodev_set.i_size);
52392 + struct inodev_entry **curr;
52393 +
52394 + entry->prev = NULL;
52395 +
52396 + curr = &inodev_set.i_hash[index];
52397 + if (*curr != NULL)
52398 + (*curr)->prev = entry;
52399 +
52400 + entry->next = *curr;
52401 + *curr = entry;
52402 +
52403 + return;
52404 +}
52405 +
52406 +static void
52407 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
52408 +{
52409 + unsigned int index =
52410 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
52411 + struct acl_role_label **curr;
52412 + struct acl_role_label *tmp, *tmp2;
52413 +
52414 + curr = &acl_role_set.r_hash[index];
52415 +
52416 + /* simple case, slot is empty, just set it to our role */
52417 + if (*curr == NULL) {
52418 + *curr = role;
52419 + } else {
52420 + /* example:
52421 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
52422 + 2 -> 3
52423 + */
52424 + /* first check to see if we can already be reached via this slot */
52425 + tmp = *curr;
52426 + while (tmp && tmp != role)
52427 + tmp = tmp->next;
52428 + if (tmp == role) {
52429 + /* we don't need to add ourselves to this slot's chain */
52430 + return;
52431 + }
52432 + /* we need to add ourselves to this chain, two cases */
52433 + if (role->next == NULL) {
52434 + /* simple case, append the current chain to our role */
52435 + role->next = *curr;
52436 + *curr = role;
52437 + } else {
52438 + /* 1 -> 2 -> 3 -> 4
52439 + 2 -> 3 -> 4
52440 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
52441 + */
52442 + /* trickier case: walk our role's chain until we find
52443 + the role for the start of the current slot's chain */
52444 + tmp = role;
52445 + tmp2 = *curr;
52446 + while (tmp->next && tmp->next != tmp2)
52447 + tmp = tmp->next;
52448 + if (tmp->next == tmp2) {
52449 + /* from example above, we found 3, so just
52450 + replace this slot's chain with ours */
52451 + *curr = role;
52452 + } else {
52453 + /* we didn't find a subset of our role's chain
52454 + in the current slot's chain, so append their
52455 + chain to ours, and set us as the first role in
52456 + the slot's chain
52457 +
52458 + we could fold this case with the case above,
52459 + but making it explicit for clarity
52460 + */
52461 + tmp->next = tmp2;
52462 + *curr = role;
52463 + }
52464 + }
52465 + }
52466 +
52467 + return;
52468 +}
52469 +
52470 +static void
52471 +insert_acl_role_label(struct acl_role_label *role)
52472 +{
52473 + int i;
52474 +
52475 + if (role_list == NULL) {
52476 + role_list = role;
52477 + role->prev = NULL;
52478 + } else {
52479 + role->prev = role_list;
52480 + role_list = role;
52481 + }
52482 +
52483 + /* used for hash chains */
52484 + role->next = NULL;
52485 +
52486 + if (role->roletype & GR_ROLE_DOMAIN) {
52487 + for (i = 0; i < role->domain_child_num; i++)
52488 + __insert_acl_role_label(role, role->domain_children[i]);
52489 + } else
52490 + __insert_acl_role_label(role, role->uidgid);
52491 +}
52492 +
52493 +static int
52494 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
52495 +{
52496 + struct name_entry **curr, *nentry;
52497 + struct inodev_entry *ientry;
52498 + unsigned int len = strlen(name);
52499 + unsigned int key = full_name_hash(name, len);
52500 + unsigned int index = key % name_set.n_size;
52501 +
52502 + curr = &name_set.n_hash[index];
52503 +
52504 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
52505 + curr = &((*curr)->next);
52506 +
52507 + if (*curr != NULL)
52508 + return 1;
52509 +
52510 + nentry = acl_alloc(sizeof (struct name_entry));
52511 + if (nentry == NULL)
52512 + return 0;
52513 + ientry = acl_alloc(sizeof (struct inodev_entry));
52514 + if (ientry == NULL)
52515 + return 0;
52516 + ientry->nentry = nentry;
52517 +
52518 + nentry->key = key;
52519 + nentry->name = name;
52520 + nentry->inode = inode;
52521 + nentry->device = device;
52522 + nentry->len = len;
52523 + nentry->deleted = deleted;
52524 +
52525 + nentry->prev = NULL;
52526 + curr = &name_set.n_hash[index];
52527 + if (*curr != NULL)
52528 + (*curr)->prev = nentry;
52529 + nentry->next = *curr;
52530 + *curr = nentry;
52531 +
52532 + /* insert us into the table searchable by inode/dev */
52533 + insert_inodev_entry(ientry);
52534 +
52535 + return 1;
52536 +}
52537 +
52538 +static void
52539 +insert_acl_obj_label(struct acl_object_label *obj,
52540 + struct acl_subject_label *subj)
52541 +{
52542 + unsigned int index =
52543 + fhash(obj->inode, obj->device, subj->obj_hash_size);
52544 + struct acl_object_label **curr;
52545 +
52546 +
52547 + obj->prev = NULL;
52548 +
52549 + curr = &subj->obj_hash[index];
52550 + if (*curr != NULL)
52551 + (*curr)->prev = obj;
52552 +
52553 + obj->next = *curr;
52554 + *curr = obj;
52555 +
52556 + return;
52557 +}
52558 +
52559 +static void
52560 +insert_acl_subj_label(struct acl_subject_label *obj,
52561 + struct acl_role_label *role)
52562 +{
52563 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
52564 + struct acl_subject_label **curr;
52565 +
52566 + obj->prev = NULL;
52567 +
52568 + curr = &role->subj_hash[index];
52569 + if (*curr != NULL)
52570 + (*curr)->prev = obj;
52571 +
52572 + obj->next = *curr;
52573 + *curr = obj;
52574 +
52575 + return;
52576 +}
52577 +
52578 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
52579 +
52580 +static void *
52581 +create_table(__u32 * len, int elementsize)
52582 +{
52583 + unsigned int table_sizes[] = {
52584 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
52585 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
52586 + 4194301, 8388593, 16777213, 33554393, 67108859
52587 + };
52588 + void *newtable = NULL;
52589 + unsigned int pwr = 0;
52590 +
52591 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
52592 + table_sizes[pwr] <= *len)
52593 + pwr++;
52594 +
52595 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
52596 + return newtable;
52597 +
52598 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
52599 + newtable =
52600 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
52601 + else
52602 + newtable = vmalloc(table_sizes[pwr] * elementsize);
52603 +
52604 + *len = table_sizes[pwr];
52605 +
52606 + return newtable;
52607 +}
52608 +
52609 +static int
52610 +init_variables(const struct gr_arg *arg)
52611 +{
52612 + struct task_struct *reaper = init_pid_ns.child_reaper;
52613 + unsigned int stacksize;
52614 +
52615 + subj_map_set.s_size = arg->role_db.num_subjects;
52616 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
52617 + name_set.n_size = arg->role_db.num_objects;
52618 + inodev_set.i_size = arg->role_db.num_objects;
52619 +
52620 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
52621 + !name_set.n_size || !inodev_set.i_size)
52622 + return 1;
52623 +
52624 + if (!gr_init_uidset())
52625 + return 1;
52626 +
52627 + /* set up the stack that holds allocation info */
52628 +
52629 + stacksize = arg->role_db.num_pointers + 5;
52630 +
52631 + if (!acl_alloc_stack_init(stacksize))
52632 + return 1;
52633 +
52634 + /* grab reference for the real root dentry and vfsmount */
52635 + get_fs_root(reaper->fs, &real_root);
52636 +
52637 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52638 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
52639 +#endif
52640 +
52641 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
52642 + if (fakefs_obj_rw == NULL)
52643 + return 1;
52644 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
52645 +
52646 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
52647 + if (fakefs_obj_rwx == NULL)
52648 + return 1;
52649 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
52650 +
52651 + subj_map_set.s_hash =
52652 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
52653 + acl_role_set.r_hash =
52654 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
52655 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
52656 + inodev_set.i_hash =
52657 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
52658 +
52659 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
52660 + !name_set.n_hash || !inodev_set.i_hash)
52661 + return 1;
52662 +
52663 + memset(subj_map_set.s_hash, 0,
52664 + sizeof(struct subject_map *) * subj_map_set.s_size);
52665 + memset(acl_role_set.r_hash, 0,
52666 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
52667 + memset(name_set.n_hash, 0,
52668 + sizeof (struct name_entry *) * name_set.n_size);
52669 + memset(inodev_set.i_hash, 0,
52670 + sizeof (struct inodev_entry *) * inodev_set.i_size);
52671 +
52672 + return 0;
52673 +}
52674 +
52675 +/* free information not needed after startup
52676 + currently contains user->kernel pointer mappings for subjects
52677 +*/
52678 +
52679 +static void
52680 +free_init_variables(void)
52681 +{
52682 + __u32 i;
52683 +
52684 + if (subj_map_set.s_hash) {
52685 + for (i = 0; i < subj_map_set.s_size; i++) {
52686 + if (subj_map_set.s_hash[i]) {
52687 + kfree(subj_map_set.s_hash[i]);
52688 + subj_map_set.s_hash[i] = NULL;
52689 + }
52690 + }
52691 +
52692 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
52693 + PAGE_SIZE)
52694 + kfree(subj_map_set.s_hash);
52695 + else
52696 + vfree(subj_map_set.s_hash);
52697 + }
52698 +
52699 + return;
52700 +}
52701 +
52702 +static void
52703 +free_variables(void)
52704 +{
52705 + struct acl_subject_label *s;
52706 + struct acl_role_label *r;
52707 + struct task_struct *task, *task2;
52708 + unsigned int x;
52709 +
52710 + gr_clear_learn_entries();
52711 +
52712 + read_lock(&tasklist_lock);
52713 + do_each_thread(task2, task) {
52714 + task->acl_sp_role = 0;
52715 + task->acl_role_id = 0;
52716 + task->acl = NULL;
52717 + task->role = NULL;
52718 + } while_each_thread(task2, task);
52719 + read_unlock(&tasklist_lock);
52720 +
52721 + /* release the reference to the real root dentry and vfsmount */
52722 + path_put(&real_root);
52723 + memset(&real_root, 0, sizeof(real_root));
52724 +
52725 + /* free all object hash tables */
52726 +
52727 + FOR_EACH_ROLE_START(r)
52728 + if (r->subj_hash == NULL)
52729 + goto next_role;
52730 + FOR_EACH_SUBJECT_START(r, s, x)
52731 + if (s->obj_hash == NULL)
52732 + break;
52733 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52734 + kfree(s->obj_hash);
52735 + else
52736 + vfree(s->obj_hash);
52737 + FOR_EACH_SUBJECT_END(s, x)
52738 + FOR_EACH_NESTED_SUBJECT_START(r, s)
52739 + if (s->obj_hash == NULL)
52740 + break;
52741 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52742 + kfree(s->obj_hash);
52743 + else
52744 + vfree(s->obj_hash);
52745 + FOR_EACH_NESTED_SUBJECT_END(s)
52746 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
52747 + kfree(r->subj_hash);
52748 + else
52749 + vfree(r->subj_hash);
52750 + r->subj_hash = NULL;
52751 +next_role:
52752 + FOR_EACH_ROLE_END(r)
52753 +
52754 + acl_free_all();
52755 +
52756 + if (acl_role_set.r_hash) {
52757 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
52758 + PAGE_SIZE)
52759 + kfree(acl_role_set.r_hash);
52760 + else
52761 + vfree(acl_role_set.r_hash);
52762 + }
52763 + if (name_set.n_hash) {
52764 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
52765 + PAGE_SIZE)
52766 + kfree(name_set.n_hash);
52767 + else
52768 + vfree(name_set.n_hash);
52769 + }
52770 +
52771 + if (inodev_set.i_hash) {
52772 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
52773 + PAGE_SIZE)
52774 + kfree(inodev_set.i_hash);
52775 + else
52776 + vfree(inodev_set.i_hash);
52777 + }
52778 +
52779 + gr_free_uidset();
52780 +
52781 + memset(&name_set, 0, sizeof (struct name_db));
52782 + memset(&inodev_set, 0, sizeof (struct inodev_db));
52783 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
52784 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
52785 +
52786 + default_role = NULL;
52787 + kernel_role = NULL;
52788 + role_list = NULL;
52789 +
52790 + return;
52791 +}
52792 +
52793 +static __u32
52794 +count_user_objs(struct acl_object_label *userp)
52795 +{
52796 + struct acl_object_label o_tmp;
52797 + __u32 num = 0;
52798 +
52799 + while (userp) {
52800 + if (copy_from_user(&o_tmp, userp,
52801 + sizeof (struct acl_object_label)))
52802 + break;
52803 +
52804 + userp = o_tmp.prev;
52805 + num++;
52806 + }
52807 +
52808 + return num;
52809 +}
52810 +
52811 +static struct acl_subject_label *
52812 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
52813 +
52814 +static int
52815 +copy_user_glob(struct acl_object_label *obj)
52816 +{
52817 + struct acl_object_label *g_tmp, **guser;
52818 + unsigned int len;
52819 + char *tmp;
52820 +
52821 + if (obj->globbed == NULL)
52822 + return 0;
52823 +
52824 + guser = &obj->globbed;
52825 + while (*guser) {
52826 + g_tmp = (struct acl_object_label *)
52827 + acl_alloc(sizeof (struct acl_object_label));
52828 + if (g_tmp == NULL)
52829 + return -ENOMEM;
52830 +
52831 + if (copy_from_user(g_tmp, *guser,
52832 + sizeof (struct acl_object_label)))
52833 + return -EFAULT;
52834 +
52835 + len = strnlen_user(g_tmp->filename, PATH_MAX);
52836 +
52837 + if (!len || len >= PATH_MAX)
52838 + return -EINVAL;
52839 +
52840 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52841 + return -ENOMEM;
52842 +
52843 + if (copy_from_user(tmp, g_tmp->filename, len))
52844 + return -EFAULT;
52845 + tmp[len-1] = '\0';
52846 + g_tmp->filename = tmp;
52847 +
52848 + *guser = g_tmp;
52849 + guser = &(g_tmp->next);
52850 + }
52851 +
52852 + return 0;
52853 +}
52854 +
52855 +static int
52856 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
52857 + struct acl_role_label *role)
52858 +{
52859 + struct acl_object_label *o_tmp;
52860 + unsigned int len;
52861 + int ret;
52862 + char *tmp;
52863 +
52864 + while (userp) {
52865 + if ((o_tmp = (struct acl_object_label *)
52866 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
52867 + return -ENOMEM;
52868 +
52869 + if (copy_from_user(o_tmp, userp,
52870 + sizeof (struct acl_object_label)))
52871 + return -EFAULT;
52872 +
52873 + userp = o_tmp->prev;
52874 +
52875 + len = strnlen_user(o_tmp->filename, PATH_MAX);
52876 +
52877 + if (!len || len >= PATH_MAX)
52878 + return -EINVAL;
52879 +
52880 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52881 + return -ENOMEM;
52882 +
52883 + if (copy_from_user(tmp, o_tmp->filename, len))
52884 + return -EFAULT;
52885 + tmp[len-1] = '\0';
52886 + o_tmp->filename = tmp;
52887 +
52888 + insert_acl_obj_label(o_tmp, subj);
52889 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
52890 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
52891 + return -ENOMEM;
52892 +
52893 + ret = copy_user_glob(o_tmp);
52894 + if (ret)
52895 + return ret;
52896 +
52897 + if (o_tmp->nested) {
52898 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
52899 + if (IS_ERR(o_tmp->nested))
52900 + return PTR_ERR(o_tmp->nested);
52901 +
52902 + /* insert into nested subject list */
52903 + o_tmp->nested->next = role->hash->first;
52904 + role->hash->first = o_tmp->nested;
52905 + }
52906 + }
52907 +
52908 + return 0;
52909 +}
52910 +
52911 +static __u32
52912 +count_user_subjs(struct acl_subject_label *userp)
52913 +{
52914 + struct acl_subject_label s_tmp;
52915 + __u32 num = 0;
52916 +
52917 + while (userp) {
52918 + if (copy_from_user(&s_tmp, userp,
52919 + sizeof (struct acl_subject_label)))
52920 + break;
52921 +
52922 + userp = s_tmp.prev;
52923 + /* do not count nested subjects against this count, since
52924 + they are not included in the hash table, but are
52925 + attached to objects. We have already counted
52926 + the subjects in userspace for the allocation
52927 + stack
52928 + */
52929 + if (!(s_tmp.mode & GR_NESTED))
52930 + num++;
52931 + }
52932 +
52933 + return num;
52934 +}
52935 +
52936 +static int
52937 +copy_user_allowedips(struct acl_role_label *rolep)
52938 +{
52939 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
52940 +
52941 + ruserip = rolep->allowed_ips;
52942 +
52943 + while (ruserip) {
52944 + rlast = rtmp;
52945 +
52946 + if ((rtmp = (struct role_allowed_ip *)
52947 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
52948 + return -ENOMEM;
52949 +
52950 + if (copy_from_user(rtmp, ruserip,
52951 + sizeof (struct role_allowed_ip)))
52952 + return -EFAULT;
52953 +
52954 + ruserip = rtmp->prev;
52955 +
52956 + if (!rlast) {
52957 + rtmp->prev = NULL;
52958 + rolep->allowed_ips = rtmp;
52959 + } else {
52960 + rlast->next = rtmp;
52961 + rtmp->prev = rlast;
52962 + }
52963 +
52964 + if (!ruserip)
52965 + rtmp->next = NULL;
52966 + }
52967 +
52968 + return 0;
52969 +}
52970 +
52971 +static int
52972 +copy_user_transitions(struct acl_role_label *rolep)
52973 +{
52974 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
52975 +
52976 + unsigned int len;
52977 + char *tmp;
52978 +
52979 + rusertp = rolep->transitions;
52980 +
52981 + while (rusertp) {
52982 + rlast = rtmp;
52983 +
52984 + if ((rtmp = (struct role_transition *)
52985 + acl_alloc(sizeof (struct role_transition))) == NULL)
52986 + return -ENOMEM;
52987 +
52988 + if (copy_from_user(rtmp, rusertp,
52989 + sizeof (struct role_transition)))
52990 + return -EFAULT;
52991 +
52992 + rusertp = rtmp->prev;
52993 +
52994 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
52995 +
52996 + if (!len || len >= GR_SPROLE_LEN)
52997 + return -EINVAL;
52998 +
52999 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53000 + return -ENOMEM;
53001 +
53002 + if (copy_from_user(tmp, rtmp->rolename, len))
53003 + return -EFAULT;
53004 + tmp[len-1] = '\0';
53005 + rtmp->rolename = tmp;
53006 +
53007 + if (!rlast) {
53008 + rtmp->prev = NULL;
53009 + rolep->transitions = rtmp;
53010 + } else {
53011 + rlast->next = rtmp;
53012 + rtmp->prev = rlast;
53013 + }
53014 +
53015 + if (!rusertp)
53016 + rtmp->next = NULL;
53017 + }
53018 +
53019 + return 0;
53020 +}
53021 +
53022 +static struct acl_subject_label *
53023 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
53024 +{
53025 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
53026 + unsigned int len;
53027 + char *tmp;
53028 + __u32 num_objs;
53029 + struct acl_ip_label **i_tmp, *i_utmp2;
53030 + struct gr_hash_struct ghash;
53031 + struct subject_map *subjmap;
53032 + unsigned int i_num;
53033 + int err;
53034 +
53035 + s_tmp = lookup_subject_map(userp);
53036 +
53037 + /* we've already copied this subject into the kernel, just return
53038 + the reference to it, and don't copy it over again
53039 + */
53040 + if (s_tmp)
53041 + return(s_tmp);
53042 +
53043 + if ((s_tmp = (struct acl_subject_label *)
53044 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
53045 + return ERR_PTR(-ENOMEM);
53046 +
53047 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
53048 + if (subjmap == NULL)
53049 + return ERR_PTR(-ENOMEM);
53050 +
53051 + subjmap->user = userp;
53052 + subjmap->kernel = s_tmp;
53053 + insert_subj_map_entry(subjmap);
53054 +
53055 + if (copy_from_user(s_tmp, userp,
53056 + sizeof (struct acl_subject_label)))
53057 + return ERR_PTR(-EFAULT);
53058 +
53059 + len = strnlen_user(s_tmp->filename, PATH_MAX);
53060 +
53061 + if (!len || len >= PATH_MAX)
53062 + return ERR_PTR(-EINVAL);
53063 +
53064 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53065 + return ERR_PTR(-ENOMEM);
53066 +
53067 + if (copy_from_user(tmp, s_tmp->filename, len))
53068 + return ERR_PTR(-EFAULT);
53069 + tmp[len-1] = '\0';
53070 + s_tmp->filename = tmp;
53071 +
53072 + if (!strcmp(s_tmp->filename, "/"))
53073 + role->root_label = s_tmp;
53074 +
53075 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
53076 + return ERR_PTR(-EFAULT);
53077 +
53078 + /* copy user and group transition tables */
53079 +
53080 + if (s_tmp->user_trans_num) {
53081 + uid_t *uidlist;
53082 +
53083 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
53084 + if (uidlist == NULL)
53085 + return ERR_PTR(-ENOMEM);
53086 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
53087 + return ERR_PTR(-EFAULT);
53088 +
53089 + s_tmp->user_transitions = uidlist;
53090 + }
53091 +
53092 + if (s_tmp->group_trans_num) {
53093 + gid_t *gidlist;
53094 +
53095 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
53096 + if (gidlist == NULL)
53097 + return ERR_PTR(-ENOMEM);
53098 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
53099 + return ERR_PTR(-EFAULT);
53100 +
53101 + s_tmp->group_transitions = gidlist;
53102 + }
53103 +
53104 + /* set up object hash table */
53105 + num_objs = count_user_objs(ghash.first);
53106 +
53107 + s_tmp->obj_hash_size = num_objs;
53108 + s_tmp->obj_hash =
53109 + (struct acl_object_label **)
53110 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
53111 +
53112 + if (!s_tmp->obj_hash)
53113 + return ERR_PTR(-ENOMEM);
53114 +
53115 + memset(s_tmp->obj_hash, 0,
53116 + s_tmp->obj_hash_size *
53117 + sizeof (struct acl_object_label *));
53118 +
53119 + /* add in objects */
53120 + err = copy_user_objs(ghash.first, s_tmp, role);
53121 +
53122 + if (err)
53123 + return ERR_PTR(err);
53124 +
53125 + /* set pointer for parent subject */
53126 + if (s_tmp->parent_subject) {
53127 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
53128 +
53129 + if (IS_ERR(s_tmp2))
53130 + return s_tmp2;
53131 +
53132 + s_tmp->parent_subject = s_tmp2;
53133 + }
53134 +
53135 + /* add in ip acls */
53136 +
53137 + if (!s_tmp->ip_num) {
53138 + s_tmp->ips = NULL;
53139 + goto insert;
53140 + }
53141 +
53142 + i_tmp =
53143 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
53144 + sizeof (struct acl_ip_label *));
53145 +
53146 + if (!i_tmp)
53147 + return ERR_PTR(-ENOMEM);
53148 +
53149 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
53150 + *(i_tmp + i_num) =
53151 + (struct acl_ip_label *)
53152 + acl_alloc(sizeof (struct acl_ip_label));
53153 + if (!*(i_tmp + i_num))
53154 + return ERR_PTR(-ENOMEM);
53155 +
53156 + if (copy_from_user
53157 + (&i_utmp2, s_tmp->ips + i_num,
53158 + sizeof (struct acl_ip_label *)))
53159 + return ERR_PTR(-EFAULT);
53160 +
53161 + if (copy_from_user
53162 + (*(i_tmp + i_num), i_utmp2,
53163 + sizeof (struct acl_ip_label)))
53164 + return ERR_PTR(-EFAULT);
53165 +
53166 + if ((*(i_tmp + i_num))->iface == NULL)
53167 + continue;
53168 +
53169 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
53170 + if (!len || len >= IFNAMSIZ)
53171 + return ERR_PTR(-EINVAL);
53172 + tmp = acl_alloc(len);
53173 + if (tmp == NULL)
53174 + return ERR_PTR(-ENOMEM);
53175 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
53176 + return ERR_PTR(-EFAULT);
53177 + (*(i_tmp + i_num))->iface = tmp;
53178 + }
53179 +
53180 + s_tmp->ips = i_tmp;
53181 +
53182 +insert:
53183 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
53184 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
53185 + return ERR_PTR(-ENOMEM);
53186 +
53187 + return s_tmp;
53188 +}
53189 +
53190 +static int
53191 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
53192 +{
53193 + struct acl_subject_label s_pre;
53194 + struct acl_subject_label * ret;
53195 + int err;
53196 +
53197 + while (userp) {
53198 + if (copy_from_user(&s_pre, userp,
53199 + sizeof (struct acl_subject_label)))
53200 + return -EFAULT;
53201 +
53202 + /* do not add nested subjects here, add
53203 + while parsing objects
53204 + */
53205 +
53206 + if (s_pre.mode & GR_NESTED) {
53207 + userp = s_pre.prev;
53208 + continue;
53209 + }
53210 +
53211 + ret = do_copy_user_subj(userp, role);
53212 +
53213 + err = PTR_ERR(ret);
53214 + if (IS_ERR(ret))
53215 + return err;
53216 +
53217 + insert_acl_subj_label(ret, role);
53218 +
53219 + userp = s_pre.prev;
53220 + }
53221 +
53222 + return 0;
53223 +}
53224 +
53225 +static int
53226 +copy_user_acl(struct gr_arg *arg)
53227 +{
53228 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
53229 + struct acl_subject_label *subj_list;
53230 + struct sprole_pw *sptmp;
53231 + struct gr_hash_struct *ghash;
53232 + uid_t *domainlist;
53233 + unsigned int r_num;
53234 + unsigned int len;
53235 + char *tmp;
53236 + int err = 0;
53237 + __u16 i;
53238 + __u32 num_subjs;
53239 +
53240 + /* we need a default and kernel role */
53241 + if (arg->role_db.num_roles < 2)
53242 + return -EINVAL;
53243 +
53244 + /* copy special role authentication info from userspace */
53245 +
53246 + num_sprole_pws = arg->num_sprole_pws;
53247 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
53248 +
53249 + if (!acl_special_roles && num_sprole_pws)
53250 + return -ENOMEM;
53251 +
53252 + for (i = 0; i < num_sprole_pws; i++) {
53253 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
53254 + if (!sptmp)
53255 + return -ENOMEM;
53256 + if (copy_from_user(sptmp, arg->sprole_pws + i,
53257 + sizeof (struct sprole_pw)))
53258 + return -EFAULT;
53259 +
53260 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
53261 +
53262 + if (!len || len >= GR_SPROLE_LEN)
53263 + return -EINVAL;
53264 +
53265 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53266 + return -ENOMEM;
53267 +
53268 + if (copy_from_user(tmp, sptmp->rolename, len))
53269 + return -EFAULT;
53270 +
53271 + tmp[len-1] = '\0';
53272 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53273 + printk(KERN_ALERT "Copying special role %s\n", tmp);
53274 +#endif
53275 + sptmp->rolename = tmp;
53276 + acl_special_roles[i] = sptmp;
53277 + }
53278 +
53279 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
53280 +
53281 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
53282 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
53283 +
53284 + if (!r_tmp)
53285 + return -ENOMEM;
53286 +
53287 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
53288 + sizeof (struct acl_role_label *)))
53289 + return -EFAULT;
53290 +
53291 + if (copy_from_user(r_tmp, r_utmp2,
53292 + sizeof (struct acl_role_label)))
53293 + return -EFAULT;
53294 +
53295 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
53296 +
53297 + if (!len || len >= PATH_MAX)
53298 + return -EINVAL;
53299 +
53300 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53301 + return -ENOMEM;
53302 +
53303 + if (copy_from_user(tmp, r_tmp->rolename, len))
53304 + return -EFAULT;
53305 +
53306 + tmp[len-1] = '\0';
53307 + r_tmp->rolename = tmp;
53308 +
53309 + if (!strcmp(r_tmp->rolename, "default")
53310 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
53311 + default_role = r_tmp;
53312 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
53313 + kernel_role = r_tmp;
53314 + }
53315 +
53316 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
53317 + return -ENOMEM;
53318 +
53319 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
53320 + return -EFAULT;
53321 +
53322 + r_tmp->hash = ghash;
53323 +
53324 + num_subjs = count_user_subjs(r_tmp->hash->first);
53325 +
53326 + r_tmp->subj_hash_size = num_subjs;
53327 + r_tmp->subj_hash =
53328 + (struct acl_subject_label **)
53329 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
53330 +
53331 + if (!r_tmp->subj_hash)
53332 + return -ENOMEM;
53333 +
53334 + err = copy_user_allowedips(r_tmp);
53335 + if (err)
53336 + return err;
53337 +
53338 + /* copy domain info */
53339 + if (r_tmp->domain_children != NULL) {
53340 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
53341 + if (domainlist == NULL)
53342 + return -ENOMEM;
53343 +
53344 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
53345 + return -EFAULT;
53346 +
53347 + r_tmp->domain_children = domainlist;
53348 + }
53349 +
53350 + err = copy_user_transitions(r_tmp);
53351 + if (err)
53352 + return err;
53353 +
53354 + memset(r_tmp->subj_hash, 0,
53355 + r_tmp->subj_hash_size *
53356 + sizeof (struct acl_subject_label *));
53357 +
53358 + /* acquire the list of subjects, then NULL out
53359 + the list prior to parsing the subjects for this role,
53360 + as during this parsing the list is replaced with a list
53361 + of *nested* subjects for the role
53362 + */
53363 + subj_list = r_tmp->hash->first;
53364 +
53365 + /* set nested subject list to null */
53366 + r_tmp->hash->first = NULL;
53367 +
53368 + err = copy_user_subjs(subj_list, r_tmp);
53369 +
53370 + if (err)
53371 + return err;
53372 +
53373 + insert_acl_role_label(r_tmp);
53374 + }
53375 +
53376 + if (default_role == NULL || kernel_role == NULL)
53377 + return -EINVAL;
53378 +
53379 + return err;
53380 +}
53381 +
53382 +static int
53383 +gracl_init(struct gr_arg *args)
53384 +{
53385 + int error = 0;
53386 +
53387 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
53388 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
53389 +
53390 + if (init_variables(args)) {
53391 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
53392 + error = -ENOMEM;
53393 + free_variables();
53394 + goto out;
53395 + }
53396 +
53397 + error = copy_user_acl(args);
53398 + free_init_variables();
53399 + if (error) {
53400 + free_variables();
53401 + goto out;
53402 + }
53403 +
53404 + if ((error = gr_set_acls(0))) {
53405 + free_variables();
53406 + goto out;
53407 + }
53408 +
53409 + pax_open_kernel();
53410 + gr_status |= GR_READY;
53411 + pax_close_kernel();
53412 +
53413 + out:
53414 + return error;
53415 +}
53416 +
53417 +/* derived from glibc fnmatch() 0: match, 1: no match*/
53418 +
53419 +static int
53420 +glob_match(const char *p, const char *n)
53421 +{
53422 + char c;
53423 +
53424 + while ((c = *p++) != '\0') {
53425 + switch (c) {
53426 + case '?':
53427 + if (*n == '\0')
53428 + return 1;
53429 + else if (*n == '/')
53430 + return 1;
53431 + break;
53432 + case '\\':
53433 + if (*n != c)
53434 + return 1;
53435 + break;
53436 + case '*':
53437 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
53438 + if (*n == '/')
53439 + return 1;
53440 + else if (c == '?') {
53441 + if (*n == '\0')
53442 + return 1;
53443 + else
53444 + ++n;
53445 + }
53446 + }
53447 + if (c == '\0') {
53448 + return 0;
53449 + } else {
53450 + const char *endp;
53451 +
53452 + if ((endp = strchr(n, '/')) == NULL)
53453 + endp = n + strlen(n);
53454 +
53455 + if (c == '[') {
53456 + for (--p; n < endp; ++n)
53457 + if (!glob_match(p, n))
53458 + return 0;
53459 + } else if (c == '/') {
53460 + while (*n != '\0' && *n != '/')
53461 + ++n;
53462 + if (*n == '/' && !glob_match(p, n + 1))
53463 + return 0;
53464 + } else {
53465 + for (--p; n < endp; ++n)
53466 + if (*n == c && !glob_match(p, n))
53467 + return 0;
53468 + }
53469 +
53470 + return 1;
53471 + }
53472 + case '[':
53473 + {
53474 + int not;
53475 + char cold;
53476 +
53477 + if (*n == '\0' || *n == '/')
53478 + return 1;
53479 +
53480 + not = (*p == '!' || *p == '^');
53481 + if (not)
53482 + ++p;
53483 +
53484 + c = *p++;
53485 + for (;;) {
53486 + unsigned char fn = (unsigned char)*n;
53487 +
53488 + if (c == '\0')
53489 + return 1;
53490 + else {
53491 + if (c == fn)
53492 + goto matched;
53493 + cold = c;
53494 + c = *p++;
53495 +
53496 + if (c == '-' && *p != ']') {
53497 + unsigned char cend = *p++;
53498 +
53499 + if (cend == '\0')
53500 + return 1;
53501 +
53502 + if (cold <= fn && fn <= cend)
53503 + goto matched;
53504 +
53505 + c = *p++;
53506 + }
53507 + }
53508 +
53509 + if (c == ']')
53510 + break;
53511 + }
53512 + if (!not)
53513 + return 1;
53514 + break;
53515 + matched:
53516 + while (c != ']') {
53517 + if (c == '\0')
53518 + return 1;
53519 +
53520 + c = *p++;
53521 + }
53522 + if (not)
53523 + return 1;
53524 + }
53525 + break;
53526 + default:
53527 + if (c != *n)
53528 + return 1;
53529 + }
53530 +
53531 + ++n;
53532 + }
53533 +
53534 + if (*n == '\0')
53535 + return 0;
53536 +
53537 + if (*n == '/')
53538 + return 0;
53539 +
53540 + return 1;
53541 +}
53542 +
53543 +static struct acl_object_label *
53544 +chk_glob_label(struct acl_object_label *globbed,
53545 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
53546 +{
53547 + struct acl_object_label *tmp;
53548 +
53549 + if (*path == NULL)
53550 + *path = gr_to_filename_nolock(dentry, mnt);
53551 +
53552 + tmp = globbed;
53553 +
53554 + while (tmp) {
53555 + if (!glob_match(tmp->filename, *path))
53556 + return tmp;
53557 + tmp = tmp->next;
53558 + }
53559 +
53560 + return NULL;
53561 +}
53562 +
53563 +static struct acl_object_label *
53564 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53565 + const ino_t curr_ino, const dev_t curr_dev,
53566 + const struct acl_subject_label *subj, char **path, const int checkglob)
53567 +{
53568 + struct acl_subject_label *tmpsubj;
53569 + struct acl_object_label *retval;
53570 + struct acl_object_label *retval2;
53571 +
53572 + tmpsubj = (struct acl_subject_label *) subj;
53573 + read_lock(&gr_inode_lock);
53574 + do {
53575 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
53576 + if (retval) {
53577 + if (checkglob && retval->globbed) {
53578 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
53579 + if (retval2)
53580 + retval = retval2;
53581 + }
53582 + break;
53583 + }
53584 + } while ((tmpsubj = tmpsubj->parent_subject));
53585 + read_unlock(&gr_inode_lock);
53586 +
53587 + return retval;
53588 +}
53589 +
53590 +static __inline__ struct acl_object_label *
53591 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53592 + struct dentry *curr_dentry,
53593 + const struct acl_subject_label *subj, char **path, const int checkglob)
53594 +{
53595 + int newglob = checkglob;
53596 + ino_t inode;
53597 + dev_t device;
53598 +
53599 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
53600 + as we don't want a / * rule to match instead of the / object
53601 + don't do this for create lookups that call this function though, since they're looking up
53602 + on the parent and thus need globbing checks on all paths
53603 + */
53604 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
53605 + newglob = GR_NO_GLOB;
53606 +
53607 + spin_lock(&curr_dentry->d_lock);
53608 + inode = curr_dentry->d_inode->i_ino;
53609 + device = __get_dev(curr_dentry);
53610 + spin_unlock(&curr_dentry->d_lock);
53611 +
53612 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
53613 +}
53614 +
53615 +static struct acl_object_label *
53616 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53617 + const struct acl_subject_label *subj, char *path, const int checkglob)
53618 +{
53619 + struct dentry *dentry = (struct dentry *) l_dentry;
53620 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53621 + struct mount *real_mnt = real_mount(mnt);
53622 + struct acl_object_label *retval;
53623 + struct dentry *parent;
53624 +
53625 + write_seqlock(&rename_lock);
53626 + br_read_lock(&vfsmount_lock);
53627 +
53628 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
53629 +#ifdef CONFIG_NET
53630 + mnt == sock_mnt ||
53631 +#endif
53632 +#ifdef CONFIG_HUGETLBFS
53633 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
53634 +#endif
53635 + /* ignore Eric Biederman */
53636 + IS_PRIVATE(l_dentry->d_inode))) {
53637 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
53638 + goto out;
53639 + }
53640 +
53641 + for (;;) {
53642 + if (dentry == real_root.dentry && mnt == real_root.mnt)
53643 + break;
53644 +
53645 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53646 + if (!mnt_has_parent(real_mnt))
53647 + break;
53648 +
53649 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53650 + if (retval != NULL)
53651 + goto out;
53652 +
53653 + dentry = real_mnt->mnt_mountpoint;
53654 + real_mnt = real_mnt->mnt_parent;
53655 + mnt = &real_mnt->mnt;
53656 + continue;
53657 + }
53658 +
53659 + parent = dentry->d_parent;
53660 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53661 + if (retval != NULL)
53662 + goto out;
53663 +
53664 + dentry = parent;
53665 + }
53666 +
53667 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53668 +
53669 + /* real_root is pinned so we don't have to hold a reference */
53670 + if (retval == NULL)
53671 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
53672 +out:
53673 + br_read_unlock(&vfsmount_lock);
53674 + write_sequnlock(&rename_lock);
53675 +
53676 + BUG_ON(retval == NULL);
53677 +
53678 + return retval;
53679 +}
53680 +
53681 +static __inline__ struct acl_object_label *
53682 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53683 + const struct acl_subject_label *subj)
53684 +{
53685 + char *path = NULL;
53686 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
53687 +}
53688 +
53689 +static __inline__ struct acl_object_label *
53690 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53691 + const struct acl_subject_label *subj)
53692 +{
53693 + char *path = NULL;
53694 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
53695 +}
53696 +
53697 +static __inline__ struct acl_object_label *
53698 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53699 + const struct acl_subject_label *subj, char *path)
53700 +{
53701 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
53702 +}
53703 +
53704 +static struct acl_subject_label *
53705 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53706 + const struct acl_role_label *role)
53707 +{
53708 + struct dentry *dentry = (struct dentry *) l_dentry;
53709 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53710 + struct mount *real_mnt = real_mount(mnt);
53711 + struct acl_subject_label *retval;
53712 + struct dentry *parent;
53713 +
53714 + write_seqlock(&rename_lock);
53715 + br_read_lock(&vfsmount_lock);
53716 +
53717 + for (;;) {
53718 + if (dentry == real_root.dentry && mnt == real_root.mnt)
53719 + break;
53720 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53721 + if (!mnt_has_parent(real_mnt))
53722 + break;
53723 +
53724 + spin_lock(&dentry->d_lock);
53725 + read_lock(&gr_inode_lock);
53726 + retval =
53727 + lookup_acl_subj_label(dentry->d_inode->i_ino,
53728 + __get_dev(dentry), role);
53729 + read_unlock(&gr_inode_lock);
53730 + spin_unlock(&dentry->d_lock);
53731 + if (retval != NULL)
53732 + goto out;
53733 +
53734 + dentry = real_mnt->mnt_mountpoint;
53735 + real_mnt = real_mnt->mnt_parent;
53736 + mnt = &real_mnt->mnt;
53737 + continue;
53738 + }
53739 +
53740 + spin_lock(&dentry->d_lock);
53741 + read_lock(&gr_inode_lock);
53742 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53743 + __get_dev(dentry), role);
53744 + read_unlock(&gr_inode_lock);
53745 + parent = dentry->d_parent;
53746 + spin_unlock(&dentry->d_lock);
53747 +
53748 + if (retval != NULL)
53749 + goto out;
53750 +
53751 + dentry = parent;
53752 + }
53753 +
53754 + spin_lock(&dentry->d_lock);
53755 + read_lock(&gr_inode_lock);
53756 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53757 + __get_dev(dentry), role);
53758 + read_unlock(&gr_inode_lock);
53759 + spin_unlock(&dentry->d_lock);
53760 +
53761 + if (unlikely(retval == NULL)) {
53762 + /* real_root is pinned, we don't need to hold a reference */
53763 + read_lock(&gr_inode_lock);
53764 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
53765 + __get_dev(real_root.dentry), role);
53766 + read_unlock(&gr_inode_lock);
53767 + }
53768 +out:
53769 + br_read_unlock(&vfsmount_lock);
53770 + write_sequnlock(&rename_lock);
53771 +
53772 + BUG_ON(retval == NULL);
53773 +
53774 + return retval;
53775 +}
53776 +
53777 +static void
53778 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
53779 +{
53780 + struct task_struct *task = current;
53781 + const struct cred *cred = current_cred();
53782 +
53783 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
53784 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53785 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53786 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
53787 +
53788 + return;
53789 +}
53790 +
53791 +static void
53792 +gr_log_learn_id_change(const char type, const unsigned int real,
53793 + const unsigned int effective, const unsigned int fs)
53794 +{
53795 + struct task_struct *task = current;
53796 + const struct cred *cred = current_cred();
53797 +
53798 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
53799 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53800 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53801 + type, real, effective, fs, &task->signal->saved_ip);
53802 +
53803 + return;
53804 +}
53805 +
53806 +__u32
53807 +gr_search_file(const struct dentry * dentry, const __u32 mode,
53808 + const struct vfsmount * mnt)
53809 +{
53810 + __u32 retval = mode;
53811 + struct acl_subject_label *curracl;
53812 + struct acl_object_label *currobj;
53813 +
53814 + if (unlikely(!(gr_status & GR_READY)))
53815 + return (mode & ~GR_AUDITS);
53816 +
53817 + curracl = current->acl;
53818 +
53819 + currobj = chk_obj_label(dentry, mnt, curracl);
53820 + retval = currobj->mode & mode;
53821 +
53822 + /* if we're opening a specified transfer file for writing
53823 + (e.g. /dev/initctl), then transfer our role to init
53824 + */
53825 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
53826 + current->role->roletype & GR_ROLE_PERSIST)) {
53827 + struct task_struct *task = init_pid_ns.child_reaper;
53828 +
53829 + if (task->role != current->role) {
53830 + task->acl_sp_role = 0;
53831 + task->acl_role_id = current->acl_role_id;
53832 + task->role = current->role;
53833 + rcu_read_lock();
53834 + read_lock(&grsec_exec_file_lock);
53835 + gr_apply_subject_to_task(task);
53836 + read_unlock(&grsec_exec_file_lock);
53837 + rcu_read_unlock();
53838 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
53839 + }
53840 + }
53841 +
53842 + if (unlikely
53843 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
53844 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
53845 + __u32 new_mode = mode;
53846 +
53847 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53848 +
53849 + retval = new_mode;
53850 +
53851 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
53852 + new_mode |= GR_INHERIT;
53853 +
53854 + if (!(mode & GR_NOLEARN))
53855 + gr_log_learn(dentry, mnt, new_mode);
53856 + }
53857 +
53858 + return retval;
53859 +}
53860 +
53861 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
53862 + const struct dentry *parent,
53863 + const struct vfsmount *mnt)
53864 +{
53865 + struct name_entry *match;
53866 + struct acl_object_label *matchpo;
53867 + struct acl_subject_label *curracl;
53868 + char *path;
53869 +
53870 + if (unlikely(!(gr_status & GR_READY)))
53871 + return NULL;
53872 +
53873 + preempt_disable();
53874 + path = gr_to_filename_rbac(new_dentry, mnt);
53875 + match = lookup_name_entry_create(path);
53876 +
53877 + curracl = current->acl;
53878 +
53879 + if (match) {
53880 + read_lock(&gr_inode_lock);
53881 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
53882 + read_unlock(&gr_inode_lock);
53883 +
53884 + if (matchpo) {
53885 + preempt_enable();
53886 + return matchpo;
53887 + }
53888 + }
53889 +
53890 + // lookup parent
53891 +
53892 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
53893 +
53894 + preempt_enable();
53895 + return matchpo;
53896 +}
53897 +
53898 +__u32
53899 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
53900 + const struct vfsmount * mnt, const __u32 mode)
53901 +{
53902 + struct acl_object_label *matchpo;
53903 + __u32 retval;
53904 +
53905 + if (unlikely(!(gr_status & GR_READY)))
53906 + return (mode & ~GR_AUDITS);
53907 +
53908 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
53909 +
53910 + retval = matchpo->mode & mode;
53911 +
53912 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
53913 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53914 + __u32 new_mode = mode;
53915 +
53916 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53917 +
53918 + gr_log_learn(new_dentry, mnt, new_mode);
53919 + return new_mode;
53920 + }
53921 +
53922 + return retval;
53923 +}
53924 +
53925 +__u32
53926 +gr_check_link(const struct dentry * new_dentry,
53927 + const struct dentry * parent_dentry,
53928 + const struct vfsmount * parent_mnt,
53929 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
53930 +{
53931 + struct acl_object_label *obj;
53932 + __u32 oldmode, newmode;
53933 + __u32 needmode;
53934 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
53935 + GR_DELETE | GR_INHERIT;
53936 +
53937 + if (unlikely(!(gr_status & GR_READY)))
53938 + return (GR_CREATE | GR_LINK);
53939 +
53940 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
53941 + oldmode = obj->mode;
53942 +
53943 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
53944 + newmode = obj->mode;
53945 +
53946 + needmode = newmode & checkmodes;
53947 +
53948 + // old name for hardlink must have at least the permissions of the new name
53949 + if ((oldmode & needmode) != needmode)
53950 + goto bad;
53951 +
53952 + // if old name had restrictions/auditing, make sure the new name does as well
53953 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
53954 +
53955 + // don't allow hardlinking of suid/sgid/fcapped files without permission
53956 + if (is_privileged_binary(old_dentry))
53957 + needmode |= GR_SETID;
53958 +
53959 + if ((newmode & needmode) != needmode)
53960 + goto bad;
53961 +
53962 + // enforce minimum permissions
53963 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
53964 + return newmode;
53965 +bad:
53966 + needmode = oldmode;
53967 + if (is_privileged_binary(old_dentry))
53968 + needmode |= GR_SETID;
53969 +
53970 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
53971 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
53972 + return (GR_CREATE | GR_LINK);
53973 + } else if (newmode & GR_SUPPRESS)
53974 + return GR_SUPPRESS;
53975 + else
53976 + return 0;
53977 +}
53978 +
53979 +int
53980 +gr_check_hidden_task(const struct task_struct *task)
53981 +{
53982 + if (unlikely(!(gr_status & GR_READY)))
53983 + return 0;
53984 +
53985 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
53986 + return 1;
53987 +
53988 + return 0;
53989 +}
53990 +
53991 +int
53992 +gr_check_protected_task(const struct task_struct *task)
53993 +{
53994 + if (unlikely(!(gr_status & GR_READY) || !task))
53995 + return 0;
53996 +
53997 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53998 + task->acl != current->acl)
53999 + return 1;
54000 +
54001 + return 0;
54002 +}
54003 +
54004 +int
54005 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
54006 +{
54007 + struct task_struct *p;
54008 + int ret = 0;
54009 +
54010 + if (unlikely(!(gr_status & GR_READY) || !pid))
54011 + return ret;
54012 +
54013 + read_lock(&tasklist_lock);
54014 + do_each_pid_task(pid, type, p) {
54015 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
54016 + p->acl != current->acl) {
54017 + ret = 1;
54018 + goto out;
54019 + }
54020 + } while_each_pid_task(pid, type, p);
54021 +out:
54022 + read_unlock(&tasklist_lock);
54023 +
54024 + return ret;
54025 +}
54026 +
54027 +void
54028 +gr_copy_label(struct task_struct *tsk)
54029 +{
54030 + tsk->signal->used_accept = 0;
54031 + tsk->acl_sp_role = 0;
54032 + tsk->acl_role_id = current->acl_role_id;
54033 + tsk->acl = current->acl;
54034 + tsk->role = current->role;
54035 + tsk->signal->curr_ip = current->signal->curr_ip;
54036 + tsk->signal->saved_ip = current->signal->saved_ip;
54037 + if (current->exec_file)
54038 + get_file(current->exec_file);
54039 + tsk->exec_file = current->exec_file;
54040 + tsk->is_writable = current->is_writable;
54041 + if (unlikely(current->signal->used_accept)) {
54042 + current->signal->curr_ip = 0;
54043 + current->signal->saved_ip = 0;
54044 + }
54045 +
54046 + return;
54047 +}
54048 +
54049 +static void
54050 +gr_set_proc_res(struct task_struct *task)
54051 +{
54052 + struct acl_subject_label *proc;
54053 + unsigned short i;
54054 +
54055 + proc = task->acl;
54056 +
54057 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
54058 + return;
54059 +
54060 + for (i = 0; i < RLIM_NLIMITS; i++) {
54061 + if (!(proc->resmask & (1 << i)))
54062 + continue;
54063 +
54064 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
54065 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
54066 + }
54067 +
54068 + return;
54069 +}
54070 +
54071 +extern int __gr_process_user_ban(struct user_struct *user);
54072 +
54073 +int
54074 +gr_check_user_change(int real, int effective, int fs)
54075 +{
54076 + unsigned int i;
54077 + __u16 num;
54078 + uid_t *uidlist;
54079 + int curuid;
54080 + int realok = 0;
54081 + int effectiveok = 0;
54082 + int fsok = 0;
54083 +
54084 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
54085 + struct user_struct *user;
54086 +
54087 + if (real == -1)
54088 + goto skipit;
54089 +
54090 + user = find_user(real);
54091 + if (user == NULL)
54092 + goto skipit;
54093 +
54094 + if (__gr_process_user_ban(user)) {
54095 + /* for find_user */
54096 + free_uid(user);
54097 + return 1;
54098 + }
54099 +
54100 + /* for find_user */
54101 + free_uid(user);
54102 +
54103 +skipit:
54104 +#endif
54105 +
54106 + if (unlikely(!(gr_status & GR_READY)))
54107 + return 0;
54108 +
54109 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54110 + gr_log_learn_id_change('u', real, effective, fs);
54111 +
54112 + num = current->acl->user_trans_num;
54113 + uidlist = current->acl->user_transitions;
54114 +
54115 + if (uidlist == NULL)
54116 + return 0;
54117 +
54118 + if (real == -1)
54119 + realok = 1;
54120 + if (effective == -1)
54121 + effectiveok = 1;
54122 + if (fs == -1)
54123 + fsok = 1;
54124 +
54125 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
54126 + for (i = 0; i < num; i++) {
54127 + curuid = (int)uidlist[i];
54128 + if (real == curuid)
54129 + realok = 1;
54130 + if (effective == curuid)
54131 + effectiveok = 1;
54132 + if (fs == curuid)
54133 + fsok = 1;
54134 + }
54135 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
54136 + for (i = 0; i < num; i++) {
54137 + curuid = (int)uidlist[i];
54138 + if (real == curuid)
54139 + break;
54140 + if (effective == curuid)
54141 + break;
54142 + if (fs == curuid)
54143 + break;
54144 + }
54145 + /* not in deny list */
54146 + if (i == num) {
54147 + realok = 1;
54148 + effectiveok = 1;
54149 + fsok = 1;
54150 + }
54151 + }
54152 +
54153 + if (realok && effectiveok && fsok)
54154 + return 0;
54155 + else {
54156 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
54157 + return 1;
54158 + }
54159 +}
54160 +
54161 +int
54162 +gr_check_group_change(int real, int effective, int fs)
54163 +{
54164 + unsigned int i;
54165 + __u16 num;
54166 + gid_t *gidlist;
54167 + int curgid;
54168 + int realok = 0;
54169 + int effectiveok = 0;
54170 + int fsok = 0;
54171 +
54172 + if (unlikely(!(gr_status & GR_READY)))
54173 + return 0;
54174 +
54175 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54176 + gr_log_learn_id_change('g', real, effective, fs);
54177 +
54178 + num = current->acl->group_trans_num;
54179 + gidlist = current->acl->group_transitions;
54180 +
54181 + if (gidlist == NULL)
54182 + return 0;
54183 +
54184 + if (real == -1)
54185 + realok = 1;
54186 + if (effective == -1)
54187 + effectiveok = 1;
54188 + if (fs == -1)
54189 + fsok = 1;
54190 +
54191 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
54192 + for (i = 0; i < num; i++) {
54193 + curgid = (int)gidlist[i];
54194 + if (real == curgid)
54195 + realok = 1;
54196 + if (effective == curgid)
54197 + effectiveok = 1;
54198 + if (fs == curgid)
54199 + fsok = 1;
54200 + }
54201 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
54202 + for (i = 0; i < num; i++) {
54203 + curgid = (int)gidlist[i];
54204 + if (real == curgid)
54205 + break;
54206 + if (effective == curgid)
54207 + break;
54208 + if (fs == curgid)
54209 + break;
54210 + }
54211 + /* not in deny list */
54212 + if (i == num) {
54213 + realok = 1;
54214 + effectiveok = 1;
54215 + fsok = 1;
54216 + }
54217 + }
54218 +
54219 + if (realok && effectiveok && fsok)
54220 + return 0;
54221 + else {
54222 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
54223 + return 1;
54224 + }
54225 +}
54226 +
54227 +extern int gr_acl_is_capable(const int cap);
54228 +
54229 +void
54230 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
54231 +{
54232 + struct acl_role_label *role = task->role;
54233 + struct acl_subject_label *subj = NULL;
54234 + struct acl_object_label *obj;
54235 + struct file *filp;
54236 +
54237 + if (unlikely(!(gr_status & GR_READY)))
54238 + return;
54239 +
54240 + filp = task->exec_file;
54241 +
54242 + /* kernel process, we'll give them the kernel role */
54243 + if (unlikely(!filp)) {
54244 + task->role = kernel_role;
54245 + task->acl = kernel_role->root_label;
54246 + return;
54247 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
54248 + role = lookup_acl_role_label(task, uid, gid);
54249 +
54250 + /* don't change the role if we're not a privileged process */
54251 + if (role && task->role != role &&
54252 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
54253 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
54254 + return;
54255 +
54256 + /* perform subject lookup in possibly new role
54257 + we can use this result below in the case where role == task->role
54258 + */
54259 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
54260 +
54261 + /* if we changed uid/gid, but result in the same role
54262 + and are using inheritance, don't lose the inherited subject
54263 + if current subject is other than what normal lookup
54264 + would result in, we arrived via inheritance, don't
54265 + lose subject
54266 + */
54267 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
54268 + (subj == task->acl)))
54269 + task->acl = subj;
54270 +
54271 + task->role = role;
54272 +
54273 + task->is_writable = 0;
54274 +
54275 + /* ignore additional mmap checks for processes that are writable
54276 + by the default ACL */
54277 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54278 + if (unlikely(obj->mode & GR_WRITE))
54279 + task->is_writable = 1;
54280 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54281 + if (unlikely(obj->mode & GR_WRITE))
54282 + task->is_writable = 1;
54283 +
54284 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54285 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54286 +#endif
54287 +
54288 + gr_set_proc_res(task);
54289 +
54290 + return;
54291 +}
54292 +
54293 +int
54294 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
54295 + const int unsafe_flags)
54296 +{
54297 + struct task_struct *task = current;
54298 + struct acl_subject_label *newacl;
54299 + struct acl_object_label *obj;
54300 + __u32 retmode;
54301 +
54302 + if (unlikely(!(gr_status & GR_READY)))
54303 + return 0;
54304 +
54305 + newacl = chk_subj_label(dentry, mnt, task->role);
54306 +
54307 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
54308 + did an exec
54309 + */
54310 + rcu_read_lock();
54311 + read_lock(&tasklist_lock);
54312 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
54313 + (task->parent->acl->mode & GR_POVERRIDE))) {
54314 + read_unlock(&tasklist_lock);
54315 + rcu_read_unlock();
54316 + goto skip_check;
54317 + }
54318 + read_unlock(&tasklist_lock);
54319 + rcu_read_unlock();
54320 +
54321 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
54322 + !(task->role->roletype & GR_ROLE_GOD) &&
54323 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
54324 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
54325 + if (unsafe_flags & LSM_UNSAFE_SHARE)
54326 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
54327 + else
54328 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
54329 + return -EACCES;
54330 + }
54331 +
54332 +skip_check:
54333 +
54334 + obj = chk_obj_label(dentry, mnt, task->acl);
54335 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
54336 +
54337 + if (!(task->acl->mode & GR_INHERITLEARN) &&
54338 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
54339 + if (obj->nested)
54340 + task->acl = obj->nested;
54341 + else
54342 + task->acl = newacl;
54343 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
54344 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
54345 +
54346 + task->is_writable = 0;
54347 +
54348 + /* ignore additional mmap checks for processes that are writable
54349 + by the default ACL */
54350 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
54351 + if (unlikely(obj->mode & GR_WRITE))
54352 + task->is_writable = 1;
54353 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
54354 + if (unlikely(obj->mode & GR_WRITE))
54355 + task->is_writable = 1;
54356 +
54357 + gr_set_proc_res(task);
54358 +
54359 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54360 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54361 +#endif
54362 + return 0;
54363 +}
54364 +
54365 +/* always called with valid inodev ptr */
54366 +static void
54367 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
54368 +{
54369 + struct acl_object_label *matchpo;
54370 + struct acl_subject_label *matchps;
54371 + struct acl_subject_label *subj;
54372 + struct acl_role_label *role;
54373 + unsigned int x;
54374 +
54375 + FOR_EACH_ROLE_START(role)
54376 + FOR_EACH_SUBJECT_START(role, subj, x)
54377 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
54378 + matchpo->mode |= GR_DELETED;
54379 + FOR_EACH_SUBJECT_END(subj,x)
54380 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
54381 + /* nested subjects aren't in the role's subj_hash table */
54382 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
54383 + matchpo->mode |= GR_DELETED;
54384 + FOR_EACH_NESTED_SUBJECT_END(subj)
54385 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
54386 + matchps->mode |= GR_DELETED;
54387 + FOR_EACH_ROLE_END(role)
54388 +
54389 + inodev->nentry->deleted = 1;
54390 +
54391 + return;
54392 +}
54393 +
54394 +void
54395 +gr_handle_delete(const ino_t ino, const dev_t dev)
54396 +{
54397 + struct inodev_entry *inodev;
54398 +
54399 + if (unlikely(!(gr_status & GR_READY)))
54400 + return;
54401 +
54402 + write_lock(&gr_inode_lock);
54403 + inodev = lookup_inodev_entry(ino, dev);
54404 + if (inodev != NULL)
54405 + do_handle_delete(inodev, ino, dev);
54406 + write_unlock(&gr_inode_lock);
54407 +
54408 + return;
54409 +}
54410 +
54411 +static void
54412 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
54413 + const ino_t newinode, const dev_t newdevice,
54414 + struct acl_subject_label *subj)
54415 +{
54416 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
54417 + struct acl_object_label *match;
54418 +
54419 + match = subj->obj_hash[index];
54420 +
54421 + while (match && (match->inode != oldinode ||
54422 + match->device != olddevice ||
54423 + !(match->mode & GR_DELETED)))
54424 + match = match->next;
54425 +
54426 + if (match && (match->inode == oldinode)
54427 + && (match->device == olddevice)
54428 + && (match->mode & GR_DELETED)) {
54429 + if (match->prev == NULL) {
54430 + subj->obj_hash[index] = match->next;
54431 + if (match->next != NULL)
54432 + match->next->prev = NULL;
54433 + } else {
54434 + match->prev->next = match->next;
54435 + if (match->next != NULL)
54436 + match->next->prev = match->prev;
54437 + }
54438 + match->prev = NULL;
54439 + match->next = NULL;
54440 + match->inode = newinode;
54441 + match->device = newdevice;
54442 + match->mode &= ~GR_DELETED;
54443 +
54444 + insert_acl_obj_label(match, subj);
54445 + }
54446 +
54447 + return;
54448 +}
54449 +
54450 +static void
54451 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
54452 + const ino_t newinode, const dev_t newdevice,
54453 + struct acl_role_label *role)
54454 +{
54455 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
54456 + struct acl_subject_label *match;
54457 +
54458 + match = role->subj_hash[index];
54459 +
54460 + while (match && (match->inode != oldinode ||
54461 + match->device != olddevice ||
54462 + !(match->mode & GR_DELETED)))
54463 + match = match->next;
54464 +
54465 + if (match && (match->inode == oldinode)
54466 + && (match->device == olddevice)
54467 + && (match->mode & GR_DELETED)) {
54468 + if (match->prev == NULL) {
54469 + role->subj_hash[index] = match->next;
54470 + if (match->next != NULL)
54471 + match->next->prev = NULL;
54472 + } else {
54473 + match->prev->next = match->next;
54474 + if (match->next != NULL)
54475 + match->next->prev = match->prev;
54476 + }
54477 + match->prev = NULL;
54478 + match->next = NULL;
54479 + match->inode = newinode;
54480 + match->device = newdevice;
54481 + match->mode &= ~GR_DELETED;
54482 +
54483 + insert_acl_subj_label(match, role);
54484 + }
54485 +
54486 + return;
54487 +}
54488 +
54489 +static void
54490 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
54491 + const ino_t newinode, const dev_t newdevice)
54492 +{
54493 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
54494 + struct inodev_entry *match;
54495 +
54496 + match = inodev_set.i_hash[index];
54497 +
54498 + while (match && (match->nentry->inode != oldinode ||
54499 + match->nentry->device != olddevice || !match->nentry->deleted))
54500 + match = match->next;
54501 +
54502 + if (match && (match->nentry->inode == oldinode)
54503 + && (match->nentry->device == olddevice) &&
54504 + match->nentry->deleted) {
54505 + if (match->prev == NULL) {
54506 + inodev_set.i_hash[index] = match->next;
54507 + if (match->next != NULL)
54508 + match->next->prev = NULL;
54509 + } else {
54510 + match->prev->next = match->next;
54511 + if (match->next != NULL)
54512 + match->next->prev = match->prev;
54513 + }
54514 + match->prev = NULL;
54515 + match->next = NULL;
54516 + match->nentry->inode = newinode;
54517 + match->nentry->device = newdevice;
54518 + match->nentry->deleted = 0;
54519 +
54520 + insert_inodev_entry(match);
54521 + }
54522 +
54523 + return;
54524 +}
54525 +
54526 +static void
54527 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
54528 +{
54529 + struct acl_subject_label *subj;
54530 + struct acl_role_label *role;
54531 + unsigned int x;
54532 +
54533 + FOR_EACH_ROLE_START(role)
54534 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
54535 +
54536 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
54537 + if ((subj->inode == ino) && (subj->device == dev)) {
54538 + subj->inode = ino;
54539 + subj->device = dev;
54540 + }
54541 + /* nested subjects aren't in the role's subj_hash table */
54542 + update_acl_obj_label(matchn->inode, matchn->device,
54543 + ino, dev, subj);
54544 + FOR_EACH_NESTED_SUBJECT_END(subj)
54545 + FOR_EACH_SUBJECT_START(role, subj, x)
54546 + update_acl_obj_label(matchn->inode, matchn->device,
54547 + ino, dev, subj);
54548 + FOR_EACH_SUBJECT_END(subj,x)
54549 + FOR_EACH_ROLE_END(role)
54550 +
54551 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
54552 +
54553 + return;
54554 +}
54555 +
54556 +static void
54557 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
54558 + const struct vfsmount *mnt)
54559 +{
54560 + ino_t ino = dentry->d_inode->i_ino;
54561 + dev_t dev = __get_dev(dentry);
54562 +
54563 + __do_handle_create(matchn, ino, dev);
54564 +
54565 + return;
54566 +}
54567 +
54568 +void
54569 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
54570 +{
54571 + struct name_entry *matchn;
54572 +
54573 + if (unlikely(!(gr_status & GR_READY)))
54574 + return;
54575 +
54576 + preempt_disable();
54577 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
54578 +
54579 + if (unlikely((unsigned long)matchn)) {
54580 + write_lock(&gr_inode_lock);
54581 + do_handle_create(matchn, dentry, mnt);
54582 + write_unlock(&gr_inode_lock);
54583 + }
54584 + preempt_enable();
54585 +
54586 + return;
54587 +}
54588 +
54589 +void
54590 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
54591 +{
54592 + struct name_entry *matchn;
54593 +
54594 + if (unlikely(!(gr_status & GR_READY)))
54595 + return;
54596 +
54597 + preempt_disable();
54598 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
54599 +
54600 + if (unlikely((unsigned long)matchn)) {
54601 + write_lock(&gr_inode_lock);
54602 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
54603 + write_unlock(&gr_inode_lock);
54604 + }
54605 + preempt_enable();
54606 +
54607 + return;
54608 +}
54609 +
54610 +void
54611 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
54612 + struct dentry *old_dentry,
54613 + struct dentry *new_dentry,
54614 + struct vfsmount *mnt, const __u8 replace)
54615 +{
54616 + struct name_entry *matchn;
54617 + struct inodev_entry *inodev;
54618 + struct inode *inode = new_dentry->d_inode;
54619 + ino_t old_ino = old_dentry->d_inode->i_ino;
54620 + dev_t old_dev = __get_dev(old_dentry);
54621 +
54622 + /* vfs_rename swaps the name and parent link for old_dentry and
54623 + new_dentry
54624 + at this point, old_dentry has the new name, parent link, and inode
54625 + for the renamed file
54626 + if a file is being replaced by a rename, new_dentry has the inode
54627 + and name for the replaced file
54628 + */
54629 +
54630 + if (unlikely(!(gr_status & GR_READY)))
54631 + return;
54632 +
54633 + preempt_disable();
54634 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
54635 +
54636 + /* we wouldn't have to check d_inode if it weren't for
54637 + NFS silly-renaming
54638 + */
54639 +
54640 + write_lock(&gr_inode_lock);
54641 + if (unlikely(replace && inode)) {
54642 + ino_t new_ino = inode->i_ino;
54643 + dev_t new_dev = __get_dev(new_dentry);
54644 +
54645 + inodev = lookup_inodev_entry(new_ino, new_dev);
54646 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
54647 + do_handle_delete(inodev, new_ino, new_dev);
54648 + }
54649 +
54650 + inodev = lookup_inodev_entry(old_ino, old_dev);
54651 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
54652 + do_handle_delete(inodev, old_ino, old_dev);
54653 +
54654 + if (unlikely((unsigned long)matchn))
54655 + do_handle_create(matchn, old_dentry, mnt);
54656 +
54657 + write_unlock(&gr_inode_lock);
54658 + preempt_enable();
54659 +
54660 + return;
54661 +}
54662 +
54663 +static int
54664 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
54665 + unsigned char **sum)
54666 +{
54667 + struct acl_role_label *r;
54668 + struct role_allowed_ip *ipp;
54669 + struct role_transition *trans;
54670 + unsigned int i;
54671 + int found = 0;
54672 + u32 curr_ip = current->signal->curr_ip;
54673 +
54674 + current->signal->saved_ip = curr_ip;
54675 +
54676 + /* check transition table */
54677 +
54678 + for (trans = current->role->transitions; trans; trans = trans->next) {
54679 + if (!strcmp(rolename, trans->rolename)) {
54680 + found = 1;
54681 + break;
54682 + }
54683 + }
54684 +
54685 + if (!found)
54686 + return 0;
54687 +
54688 + /* handle special roles that do not require authentication
54689 + and check ip */
54690 +
54691 + FOR_EACH_ROLE_START(r)
54692 + if (!strcmp(rolename, r->rolename) &&
54693 + (r->roletype & GR_ROLE_SPECIAL)) {
54694 + found = 0;
54695 + if (r->allowed_ips != NULL) {
54696 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
54697 + if ((ntohl(curr_ip) & ipp->netmask) ==
54698 + (ntohl(ipp->addr) & ipp->netmask))
54699 + found = 1;
54700 + }
54701 + } else
54702 + found = 2;
54703 + if (!found)
54704 + return 0;
54705 +
54706 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
54707 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
54708 + *salt = NULL;
54709 + *sum = NULL;
54710 + return 1;
54711 + }
54712 + }
54713 + FOR_EACH_ROLE_END(r)
54714 +
54715 + for (i = 0; i < num_sprole_pws; i++) {
54716 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
54717 + *salt = acl_special_roles[i]->salt;
54718 + *sum = acl_special_roles[i]->sum;
54719 + return 1;
54720 + }
54721 + }
54722 +
54723 + return 0;
54724 +}
54725 +
54726 +static void
54727 +assign_special_role(char *rolename)
54728 +{
54729 + struct acl_object_label *obj;
54730 + struct acl_role_label *r;
54731 + struct acl_role_label *assigned = NULL;
54732 + struct task_struct *tsk;
54733 + struct file *filp;
54734 +
54735 + FOR_EACH_ROLE_START(r)
54736 + if (!strcmp(rolename, r->rolename) &&
54737 + (r->roletype & GR_ROLE_SPECIAL)) {
54738 + assigned = r;
54739 + break;
54740 + }
54741 + FOR_EACH_ROLE_END(r)
54742 +
54743 + if (!assigned)
54744 + return;
54745 +
54746 + read_lock(&tasklist_lock);
54747 + read_lock(&grsec_exec_file_lock);
54748 +
54749 + tsk = current->real_parent;
54750 + if (tsk == NULL)
54751 + goto out_unlock;
54752 +
54753 + filp = tsk->exec_file;
54754 + if (filp == NULL)
54755 + goto out_unlock;
54756 +
54757 + tsk->is_writable = 0;
54758 +
54759 + tsk->acl_sp_role = 1;
54760 + tsk->acl_role_id = ++acl_sp_role_value;
54761 + tsk->role = assigned;
54762 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
54763 +
54764 + /* ignore additional mmap checks for processes that are writable
54765 + by the default ACL */
54766 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54767 + if (unlikely(obj->mode & GR_WRITE))
54768 + tsk->is_writable = 1;
54769 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
54770 + if (unlikely(obj->mode & GR_WRITE))
54771 + tsk->is_writable = 1;
54772 +
54773 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54774 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
54775 +#endif
54776 +
54777 +out_unlock:
54778 + read_unlock(&grsec_exec_file_lock);
54779 + read_unlock(&tasklist_lock);
54780 + return;
54781 +}
54782 +
54783 +int gr_check_secure_terminal(struct task_struct *task)
54784 +{
54785 + struct task_struct *p, *p2, *p3;
54786 + struct files_struct *files;
54787 + struct fdtable *fdt;
54788 + struct file *our_file = NULL, *file;
54789 + int i;
54790 +
54791 + if (task->signal->tty == NULL)
54792 + return 1;
54793 +
54794 + files = get_files_struct(task);
54795 + if (files != NULL) {
54796 + rcu_read_lock();
54797 + fdt = files_fdtable(files);
54798 + for (i=0; i < fdt->max_fds; i++) {
54799 + file = fcheck_files(files, i);
54800 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
54801 + get_file(file);
54802 + our_file = file;
54803 + }
54804 + }
54805 + rcu_read_unlock();
54806 + put_files_struct(files);
54807 + }
54808 +
54809 + if (our_file == NULL)
54810 + return 1;
54811 +
54812 + read_lock(&tasklist_lock);
54813 + do_each_thread(p2, p) {
54814 + files = get_files_struct(p);
54815 + if (files == NULL ||
54816 + (p->signal && p->signal->tty == task->signal->tty)) {
54817 + if (files != NULL)
54818 + put_files_struct(files);
54819 + continue;
54820 + }
54821 + rcu_read_lock();
54822 + fdt = files_fdtable(files);
54823 + for (i=0; i < fdt->max_fds; i++) {
54824 + file = fcheck_files(files, i);
54825 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
54826 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
54827 + p3 = task;
54828 + while (p3->pid > 0) {
54829 + if (p3 == p)
54830 + break;
54831 + p3 = p3->real_parent;
54832 + }
54833 + if (p3 == p)
54834 + break;
54835 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
54836 + gr_handle_alertkill(p);
54837 + rcu_read_unlock();
54838 + put_files_struct(files);
54839 + read_unlock(&tasklist_lock);
54840 + fput(our_file);
54841 + return 0;
54842 + }
54843 + }
54844 + rcu_read_unlock();
54845 + put_files_struct(files);
54846 + } while_each_thread(p2, p);
54847 + read_unlock(&tasklist_lock);
54848 +
54849 + fput(our_file);
54850 + return 1;
54851 +}
54852 +
54853 +static int gr_rbac_disable(void *unused)
54854 +{
54855 + pax_open_kernel();
54856 + gr_status &= ~GR_READY;
54857 + pax_close_kernel();
54858 +
54859 + return 0;
54860 +}
54861 +
54862 +ssize_t
54863 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
54864 +{
54865 + struct gr_arg_wrapper uwrap;
54866 + unsigned char *sprole_salt = NULL;
54867 + unsigned char *sprole_sum = NULL;
54868 + int error = sizeof (struct gr_arg_wrapper);
54869 + int error2 = 0;
54870 +
54871 + mutex_lock(&gr_dev_mutex);
54872 +
54873 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
54874 + error = -EPERM;
54875 + goto out;
54876 + }
54877 +
54878 + if (count != sizeof (struct gr_arg_wrapper)) {
54879 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
54880 + error = -EINVAL;
54881 + goto out;
54882 + }
54883 +
54884 +
54885 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
54886 + gr_auth_expires = 0;
54887 + gr_auth_attempts = 0;
54888 + }
54889 +
54890 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
54891 + error = -EFAULT;
54892 + goto out;
54893 + }
54894 +
54895 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
54896 + error = -EINVAL;
54897 + goto out;
54898 + }
54899 +
54900 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
54901 + error = -EFAULT;
54902 + goto out;
54903 + }
54904 +
54905 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54906 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54907 + time_after(gr_auth_expires, get_seconds())) {
54908 + error = -EBUSY;
54909 + goto out;
54910 + }
54911 +
54912 + /* if non-root trying to do anything other than use a special role,
54913 + do not attempt authentication, do not count towards authentication
54914 + locking
54915 + */
54916 +
54917 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
54918 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54919 + !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
54920 + error = -EPERM;
54921 + goto out;
54922 + }
54923 +
54924 + /* ensure pw and special role name are null terminated */
54925 +
54926 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
54927 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
54928 +
54929 + /* Okay.
54930 + * We have our enough of the argument structure..(we have yet
54931 + * to copy_from_user the tables themselves) . Copy the tables
54932 + * only if we need them, i.e. for loading operations. */
54933 +
54934 + switch (gr_usermode->mode) {
54935 + case GR_STATUS:
54936 + if (gr_status & GR_READY) {
54937 + error = 1;
54938 + if (!gr_check_secure_terminal(current))
54939 + error = 3;
54940 + } else
54941 + error = 2;
54942 + goto out;
54943 + case GR_SHUTDOWN:
54944 + if ((gr_status & GR_READY)
54945 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54946 + stop_machine(gr_rbac_disable, NULL, NULL);
54947 + free_variables();
54948 + memset(gr_usermode, 0, sizeof (struct gr_arg));
54949 + memset(gr_system_salt, 0, GR_SALT_LEN);
54950 + memset(gr_system_sum, 0, GR_SHA_LEN);
54951 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
54952 + } else if (gr_status & GR_READY) {
54953 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
54954 + error = -EPERM;
54955 + } else {
54956 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
54957 + error = -EAGAIN;
54958 + }
54959 + break;
54960 + case GR_ENABLE:
54961 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
54962 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
54963 + else {
54964 + if (gr_status & GR_READY)
54965 + error = -EAGAIN;
54966 + else
54967 + error = error2;
54968 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
54969 + }
54970 + break;
54971 + case GR_RELOAD:
54972 + if (!(gr_status & GR_READY)) {
54973 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
54974 + error = -EAGAIN;
54975 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54976 + stop_machine(gr_rbac_disable, NULL, NULL);
54977 + free_variables();
54978 + error2 = gracl_init(gr_usermode);
54979 + if (!error2)
54980 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
54981 + else {
54982 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54983 + error = error2;
54984 + }
54985 + } else {
54986 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54987 + error = -EPERM;
54988 + }
54989 + break;
54990 + case GR_SEGVMOD:
54991 + if (unlikely(!(gr_status & GR_READY))) {
54992 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
54993 + error = -EAGAIN;
54994 + break;
54995 + }
54996 +
54997 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54998 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
54999 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
55000 + struct acl_subject_label *segvacl;
55001 + segvacl =
55002 + lookup_acl_subj_label(gr_usermode->segv_inode,
55003 + gr_usermode->segv_device,
55004 + current->role);
55005 + if (segvacl) {
55006 + segvacl->crashes = 0;
55007 + segvacl->expires = 0;
55008 + }
55009 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
55010 + gr_remove_uid(gr_usermode->segv_uid);
55011 + }
55012 + } else {
55013 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
55014 + error = -EPERM;
55015 + }
55016 + break;
55017 + case GR_SPROLE:
55018 + case GR_SPROLEPAM:
55019 + if (unlikely(!(gr_status & GR_READY))) {
55020 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
55021 + error = -EAGAIN;
55022 + break;
55023 + }
55024 +
55025 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
55026 + current->role->expires = 0;
55027 + current->role->auth_attempts = 0;
55028 + }
55029 +
55030 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
55031 + time_after(current->role->expires, get_seconds())) {
55032 + error = -EBUSY;
55033 + goto out;
55034 + }
55035 +
55036 + if (lookup_special_role_auth
55037 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
55038 + && ((!sprole_salt && !sprole_sum)
55039 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
55040 + char *p = "";
55041 + assign_special_role(gr_usermode->sp_role);
55042 + read_lock(&tasklist_lock);
55043 + if (current->real_parent)
55044 + p = current->real_parent->role->rolename;
55045 + read_unlock(&tasklist_lock);
55046 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
55047 + p, acl_sp_role_value);
55048 + } else {
55049 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
55050 + error = -EPERM;
55051 + if(!(current->role->auth_attempts++))
55052 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
55053 +
55054 + goto out;
55055 + }
55056 + break;
55057 + case GR_UNSPROLE:
55058 + if (unlikely(!(gr_status & GR_READY))) {
55059 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
55060 + error = -EAGAIN;
55061 + break;
55062 + }
55063 +
55064 + if (current->role->roletype & GR_ROLE_SPECIAL) {
55065 + char *p = "";
55066 + int i = 0;
55067 +
55068 + read_lock(&tasklist_lock);
55069 + if (current->real_parent) {
55070 + p = current->real_parent->role->rolename;
55071 + i = current->real_parent->acl_role_id;
55072 + }
55073 + read_unlock(&tasklist_lock);
55074 +
55075 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
55076 + gr_set_acls(1);
55077 + } else {
55078 + error = -EPERM;
55079 + goto out;
55080 + }
55081 + break;
55082 + default:
55083 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
55084 + error = -EINVAL;
55085 + break;
55086 + }
55087 +
55088 + if (error != -EPERM)
55089 + goto out;
55090 +
55091 + if(!(gr_auth_attempts++))
55092 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
55093 +
55094 + out:
55095 + mutex_unlock(&gr_dev_mutex);
55096 + return error;
55097 +}
55098 +
55099 +/* must be called with
55100 + rcu_read_lock();
55101 + read_lock(&tasklist_lock);
55102 + read_lock(&grsec_exec_file_lock);
55103 +*/
55104 +int gr_apply_subject_to_task(struct task_struct *task)
55105 +{
55106 + struct acl_object_label *obj;
55107 + char *tmpname;
55108 + struct acl_subject_label *tmpsubj;
55109 + struct file *filp;
55110 + struct name_entry *nmatch;
55111 +
55112 + filp = task->exec_file;
55113 + if (filp == NULL)
55114 + return 0;
55115 +
55116 + /* the following is to apply the correct subject
55117 + on binaries running when the RBAC system
55118 + is enabled, when the binaries have been
55119 + replaced or deleted since their execution
55120 + -----
55121 + when the RBAC system starts, the inode/dev
55122 + from exec_file will be one the RBAC system
55123 + is unaware of. It only knows the inode/dev
55124 + of the present file on disk, or the absence
55125 + of it.
55126 + */
55127 + preempt_disable();
55128 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
55129 +
55130 + nmatch = lookup_name_entry(tmpname);
55131 + preempt_enable();
55132 + tmpsubj = NULL;
55133 + if (nmatch) {
55134 + if (nmatch->deleted)
55135 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
55136 + else
55137 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
55138 + if (tmpsubj != NULL)
55139 + task->acl = tmpsubj;
55140 + }
55141 + if (tmpsubj == NULL)
55142 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
55143 + task->role);
55144 + if (task->acl) {
55145 + task->is_writable = 0;
55146 + /* ignore additional mmap checks for processes that are writable
55147 + by the default ACL */
55148 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55149 + if (unlikely(obj->mode & GR_WRITE))
55150 + task->is_writable = 1;
55151 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
55152 + if (unlikely(obj->mode & GR_WRITE))
55153 + task->is_writable = 1;
55154 +
55155 + gr_set_proc_res(task);
55156 +
55157 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55158 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
55159 +#endif
55160 + } else {
55161 + return 1;
55162 + }
55163 +
55164 + return 0;
55165 +}
55166 +
55167 +int
55168 +gr_set_acls(const int type)
55169 +{
55170 + struct task_struct *task, *task2;
55171 + struct acl_role_label *role = current->role;
55172 + __u16 acl_role_id = current->acl_role_id;
55173 + const struct cred *cred;
55174 + int ret;
55175 +
55176 + rcu_read_lock();
55177 + read_lock(&tasklist_lock);
55178 + read_lock(&grsec_exec_file_lock);
55179 + do_each_thread(task2, task) {
55180 + /* check to see if we're called from the exit handler,
55181 + if so, only replace ACLs that have inherited the admin
55182 + ACL */
55183 +
55184 + if (type && (task->role != role ||
55185 + task->acl_role_id != acl_role_id))
55186 + continue;
55187 +
55188 + task->acl_role_id = 0;
55189 + task->acl_sp_role = 0;
55190 +
55191 + if (task->exec_file) {
55192 + cred = __task_cred(task);
55193 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
55194 + ret = gr_apply_subject_to_task(task);
55195 + if (ret) {
55196 + read_unlock(&grsec_exec_file_lock);
55197 + read_unlock(&tasklist_lock);
55198 + rcu_read_unlock();
55199 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
55200 + return ret;
55201 + }
55202 + } else {
55203 + // it's a kernel process
55204 + task->role = kernel_role;
55205 + task->acl = kernel_role->root_label;
55206 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
55207 + task->acl->mode &= ~GR_PROCFIND;
55208 +#endif
55209 + }
55210 + } while_each_thread(task2, task);
55211 + read_unlock(&grsec_exec_file_lock);
55212 + read_unlock(&tasklist_lock);
55213 + rcu_read_unlock();
55214 +
55215 + return 0;
55216 +}
55217 +
55218 +void
55219 +gr_learn_resource(const struct task_struct *task,
55220 + const int res, const unsigned long wanted, const int gt)
55221 +{
55222 + struct acl_subject_label *acl;
55223 + const struct cred *cred;
55224 +
55225 + if (unlikely((gr_status & GR_READY) &&
55226 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
55227 + goto skip_reslog;
55228 +
55229 +#ifdef CONFIG_GRKERNSEC_RESLOG
55230 + gr_log_resource(task, res, wanted, gt);
55231 +#endif
55232 + skip_reslog:
55233 +
55234 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
55235 + return;
55236 +
55237 + acl = task->acl;
55238 +
55239 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
55240 + !(acl->resmask & (1 << (unsigned short) res))))
55241 + return;
55242 +
55243 + if (wanted >= acl->res[res].rlim_cur) {
55244 + unsigned long res_add;
55245 +
55246 + res_add = wanted;
55247 + switch (res) {
55248 + case RLIMIT_CPU:
55249 + res_add += GR_RLIM_CPU_BUMP;
55250 + break;
55251 + case RLIMIT_FSIZE:
55252 + res_add += GR_RLIM_FSIZE_BUMP;
55253 + break;
55254 + case RLIMIT_DATA:
55255 + res_add += GR_RLIM_DATA_BUMP;
55256 + break;
55257 + case RLIMIT_STACK:
55258 + res_add += GR_RLIM_STACK_BUMP;
55259 + break;
55260 + case RLIMIT_CORE:
55261 + res_add += GR_RLIM_CORE_BUMP;
55262 + break;
55263 + case RLIMIT_RSS:
55264 + res_add += GR_RLIM_RSS_BUMP;
55265 + break;
55266 + case RLIMIT_NPROC:
55267 + res_add += GR_RLIM_NPROC_BUMP;
55268 + break;
55269 + case RLIMIT_NOFILE:
55270 + res_add += GR_RLIM_NOFILE_BUMP;
55271 + break;
55272 + case RLIMIT_MEMLOCK:
55273 + res_add += GR_RLIM_MEMLOCK_BUMP;
55274 + break;
55275 + case RLIMIT_AS:
55276 + res_add += GR_RLIM_AS_BUMP;
55277 + break;
55278 + case RLIMIT_LOCKS:
55279 + res_add += GR_RLIM_LOCKS_BUMP;
55280 + break;
55281 + case RLIMIT_SIGPENDING:
55282 + res_add += GR_RLIM_SIGPENDING_BUMP;
55283 + break;
55284 + case RLIMIT_MSGQUEUE:
55285 + res_add += GR_RLIM_MSGQUEUE_BUMP;
55286 + break;
55287 + case RLIMIT_NICE:
55288 + res_add += GR_RLIM_NICE_BUMP;
55289 + break;
55290 + case RLIMIT_RTPRIO:
55291 + res_add += GR_RLIM_RTPRIO_BUMP;
55292 + break;
55293 + case RLIMIT_RTTIME:
55294 + res_add += GR_RLIM_RTTIME_BUMP;
55295 + break;
55296 + }
55297 +
55298 + acl->res[res].rlim_cur = res_add;
55299 +
55300 + if (wanted > acl->res[res].rlim_max)
55301 + acl->res[res].rlim_max = res_add;
55302 +
55303 + /* only log the subject filename, since resource logging is supported for
55304 + single-subject learning only */
55305 + rcu_read_lock();
55306 + cred = __task_cred(task);
55307 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55308 + task->role->roletype, cred->uid, cred->gid, acl->filename,
55309 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
55310 + "", (unsigned long) res, &task->signal->saved_ip);
55311 + rcu_read_unlock();
55312 + }
55313 +
55314 + return;
55315 +}
55316 +
55317 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
55318 +void
55319 +pax_set_initial_flags(struct linux_binprm *bprm)
55320 +{
55321 + struct task_struct *task = current;
55322 + struct acl_subject_label *proc;
55323 + unsigned long flags;
55324 +
55325 + if (unlikely(!(gr_status & GR_READY)))
55326 + return;
55327 +
55328 + flags = pax_get_flags(task);
55329 +
55330 + proc = task->acl;
55331 +
55332 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
55333 + flags &= ~MF_PAX_PAGEEXEC;
55334 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
55335 + flags &= ~MF_PAX_SEGMEXEC;
55336 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
55337 + flags &= ~MF_PAX_RANDMMAP;
55338 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
55339 + flags &= ~MF_PAX_EMUTRAMP;
55340 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
55341 + flags &= ~MF_PAX_MPROTECT;
55342 +
55343 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
55344 + flags |= MF_PAX_PAGEEXEC;
55345 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
55346 + flags |= MF_PAX_SEGMEXEC;
55347 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
55348 + flags |= MF_PAX_RANDMMAP;
55349 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
55350 + flags |= MF_PAX_EMUTRAMP;
55351 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
55352 + flags |= MF_PAX_MPROTECT;
55353 +
55354 + pax_set_flags(task, flags);
55355 +
55356 + return;
55357 +}
55358 +#endif
55359 +
55360 +int
55361 +gr_handle_proc_ptrace(struct task_struct *task)
55362 +{
55363 + struct file *filp;
55364 + struct task_struct *tmp = task;
55365 + struct task_struct *curtemp = current;
55366 + __u32 retmode;
55367 +
55368 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55369 + if (unlikely(!(gr_status & GR_READY)))
55370 + return 0;
55371 +#endif
55372 +
55373 + read_lock(&tasklist_lock);
55374 + read_lock(&grsec_exec_file_lock);
55375 + filp = task->exec_file;
55376 +
55377 + while (tmp->pid > 0) {
55378 + if (tmp == curtemp)
55379 + break;
55380 + tmp = tmp->real_parent;
55381 + }
55382 +
55383 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
55384 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
55385 + read_unlock(&grsec_exec_file_lock);
55386 + read_unlock(&tasklist_lock);
55387 + return 1;
55388 + }
55389 +
55390 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55391 + if (!(gr_status & GR_READY)) {
55392 + read_unlock(&grsec_exec_file_lock);
55393 + read_unlock(&tasklist_lock);
55394 + return 0;
55395 + }
55396 +#endif
55397 +
55398 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
55399 + read_unlock(&grsec_exec_file_lock);
55400 + read_unlock(&tasklist_lock);
55401 +
55402 + if (retmode & GR_NOPTRACE)
55403 + return 1;
55404 +
55405 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
55406 + && (current->acl != task->acl || (current->acl != current->role->root_label
55407 + && current->pid != task->pid)))
55408 + return 1;
55409 +
55410 + return 0;
55411 +}
55412 +
55413 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
55414 +{
55415 + if (unlikely(!(gr_status & GR_READY)))
55416 + return;
55417 +
55418 + if (!(current->role->roletype & GR_ROLE_GOD))
55419 + return;
55420 +
55421 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
55422 + p->role->rolename, gr_task_roletype_to_char(p),
55423 + p->acl->filename);
55424 +}
55425 +
55426 +int
55427 +gr_handle_ptrace(struct task_struct *task, const long request)
55428 +{
55429 + struct task_struct *tmp = task;
55430 + struct task_struct *curtemp = current;
55431 + __u32 retmode;
55432 +
55433 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55434 + if (unlikely(!(gr_status & GR_READY)))
55435 + return 0;
55436 +#endif
55437 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
55438 + read_lock(&tasklist_lock);
55439 + while (tmp->pid > 0) {
55440 + if (tmp == curtemp)
55441 + break;
55442 + tmp = tmp->real_parent;
55443 + }
55444 +
55445 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
55446 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
55447 + read_unlock(&tasklist_lock);
55448 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55449 + return 1;
55450 + }
55451 + read_unlock(&tasklist_lock);
55452 + }
55453 +
55454 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55455 + if (!(gr_status & GR_READY))
55456 + return 0;
55457 +#endif
55458 +
55459 + read_lock(&grsec_exec_file_lock);
55460 + if (unlikely(!task->exec_file)) {
55461 + read_unlock(&grsec_exec_file_lock);
55462 + return 0;
55463 + }
55464 +
55465 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
55466 + read_unlock(&grsec_exec_file_lock);
55467 +
55468 + if (retmode & GR_NOPTRACE) {
55469 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55470 + return 1;
55471 + }
55472 +
55473 + if (retmode & GR_PTRACERD) {
55474 + switch (request) {
55475 + case PTRACE_SEIZE:
55476 + case PTRACE_POKETEXT:
55477 + case PTRACE_POKEDATA:
55478 + case PTRACE_POKEUSR:
55479 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
55480 + case PTRACE_SETREGS:
55481 + case PTRACE_SETFPREGS:
55482 +#endif
55483 +#ifdef CONFIG_X86
55484 + case PTRACE_SETFPXREGS:
55485 +#endif
55486 +#ifdef CONFIG_ALTIVEC
55487 + case PTRACE_SETVRREGS:
55488 +#endif
55489 + return 1;
55490 + default:
55491 + return 0;
55492 + }
55493 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
55494 + !(current->role->roletype & GR_ROLE_GOD) &&
55495 + (current->acl != task->acl)) {
55496 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55497 + return 1;
55498 + }
55499 +
55500 + return 0;
55501 +}
55502 +
55503 +static int is_writable_mmap(const struct file *filp)
55504 +{
55505 + struct task_struct *task = current;
55506 + struct acl_object_label *obj, *obj2;
55507 +
55508 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
55509 + !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))) {
55510 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55511 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
55512 + task->role->root_label);
55513 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
55514 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
55515 + return 1;
55516 + }
55517 + }
55518 + return 0;
55519 +}
55520 +
55521 +int
55522 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
55523 +{
55524 + __u32 mode;
55525 +
55526 + if (unlikely(!file || !(prot & PROT_EXEC)))
55527 + return 1;
55528 +
55529 + if (is_writable_mmap(file))
55530 + return 0;
55531 +
55532 + mode =
55533 + gr_search_file(file->f_path.dentry,
55534 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55535 + file->f_path.mnt);
55536 +
55537 + if (!gr_tpe_allow(file))
55538 + return 0;
55539 +
55540 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55541 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55542 + return 0;
55543 + } else if (unlikely(!(mode & GR_EXEC))) {
55544 + return 0;
55545 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55546 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55547 + return 1;
55548 + }
55549 +
55550 + return 1;
55551 +}
55552 +
55553 +int
55554 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
55555 +{
55556 + __u32 mode;
55557 +
55558 + if (unlikely(!file || !(prot & PROT_EXEC)))
55559 + return 1;
55560 +
55561 + if (is_writable_mmap(file))
55562 + return 0;
55563 +
55564 + mode =
55565 + gr_search_file(file->f_path.dentry,
55566 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55567 + file->f_path.mnt);
55568 +
55569 + if (!gr_tpe_allow(file))
55570 + return 0;
55571 +
55572 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55573 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55574 + return 0;
55575 + } else if (unlikely(!(mode & GR_EXEC))) {
55576 + return 0;
55577 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55578 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55579 + return 1;
55580 + }
55581 +
55582 + return 1;
55583 +}
55584 +
55585 +void
55586 +gr_acl_handle_psacct(struct task_struct *task, const long code)
55587 +{
55588 + unsigned long runtime;
55589 + unsigned long cputime;
55590 + unsigned int wday, cday;
55591 + __u8 whr, chr;
55592 + __u8 wmin, cmin;
55593 + __u8 wsec, csec;
55594 + struct timespec timeval;
55595 +
55596 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
55597 + !(task->acl->mode & GR_PROCACCT)))
55598 + return;
55599 +
55600 + do_posix_clock_monotonic_gettime(&timeval);
55601 + runtime = timeval.tv_sec - task->start_time.tv_sec;
55602 + wday = runtime / (3600 * 24);
55603 + runtime -= wday * (3600 * 24);
55604 + whr = runtime / 3600;
55605 + runtime -= whr * 3600;
55606 + wmin = runtime / 60;
55607 + runtime -= wmin * 60;
55608 + wsec = runtime;
55609 +
55610 + cputime = (task->utime + task->stime) / HZ;
55611 + cday = cputime / (3600 * 24);
55612 + cputime -= cday * (3600 * 24);
55613 + chr = cputime / 3600;
55614 + cputime -= chr * 3600;
55615 + cmin = cputime / 60;
55616 + cputime -= cmin * 60;
55617 + csec = cputime;
55618 +
55619 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
55620 +
55621 + return;
55622 +}
55623 +
55624 +void gr_set_kernel_label(struct task_struct *task)
55625 +{
55626 + if (gr_status & GR_READY) {
55627 + task->role = kernel_role;
55628 + task->acl = kernel_role->root_label;
55629 + }
55630 + return;
55631 +}
55632 +
55633 +#ifdef CONFIG_TASKSTATS
55634 +int gr_is_taskstats_denied(int pid)
55635 +{
55636 + struct task_struct *task;
55637 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55638 + const struct cred *cred;
55639 +#endif
55640 + int ret = 0;
55641 +
55642 + /* restrict taskstats viewing to un-chrooted root users
55643 + who have the 'view' subject flag if the RBAC system is enabled
55644 + */
55645 +
55646 + rcu_read_lock();
55647 + read_lock(&tasklist_lock);
55648 + task = find_task_by_vpid(pid);
55649 + if (task) {
55650 +#ifdef CONFIG_GRKERNSEC_CHROOT
55651 + if (proc_is_chrooted(task))
55652 + ret = -EACCES;
55653 +#endif
55654 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55655 + cred = __task_cred(task);
55656 +#ifdef CONFIG_GRKERNSEC_PROC_USER
55657 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
55658 + ret = -EACCES;
55659 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55660 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, grsec_proc_gid))
55661 + ret = -EACCES;
55662 +#endif
55663 +#endif
55664 + if (gr_status & GR_READY) {
55665 + if (!(task->acl->mode & GR_VIEW))
55666 + ret = -EACCES;
55667 + }
55668 + } else
55669 + ret = -ENOENT;
55670 +
55671 + read_unlock(&tasklist_lock);
55672 + rcu_read_unlock();
55673 +
55674 + return ret;
55675 +}
55676 +#endif
55677 +
55678 +/* AUXV entries are filled via a descendant of search_binary_handler
55679 + after we've already applied the subject for the target
55680 +*/
55681 +int gr_acl_enable_at_secure(void)
55682 +{
55683 + if (unlikely(!(gr_status & GR_READY)))
55684 + return 0;
55685 +
55686 + if (current->acl->mode & GR_ATSECURE)
55687 + return 1;
55688 +
55689 + return 0;
55690 +}
55691 +
55692 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
55693 +{
55694 + struct task_struct *task = current;
55695 + struct dentry *dentry = file->f_path.dentry;
55696 + struct vfsmount *mnt = file->f_path.mnt;
55697 + struct acl_object_label *obj, *tmp;
55698 + struct acl_subject_label *subj;
55699 + unsigned int bufsize;
55700 + int is_not_root;
55701 + char *path;
55702 + dev_t dev = __get_dev(dentry);
55703 +
55704 + if (unlikely(!(gr_status & GR_READY)))
55705 + return 1;
55706 +
55707 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55708 + return 1;
55709 +
55710 + /* ignore Eric Biederman */
55711 + if (IS_PRIVATE(dentry->d_inode))
55712 + return 1;
55713 +
55714 + subj = task->acl;
55715 + read_lock(&gr_inode_lock);
55716 + do {
55717 + obj = lookup_acl_obj_label(ino, dev, subj);
55718 + if (obj != NULL) {
55719 + read_unlock(&gr_inode_lock);
55720 + return (obj->mode & GR_FIND) ? 1 : 0;
55721 + }
55722 + } while ((subj = subj->parent_subject));
55723 + read_unlock(&gr_inode_lock);
55724 +
55725 + /* this is purely an optimization since we're looking for an object
55726 + for the directory we're doing a readdir on
55727 + if it's possible for any globbed object to match the entry we're
55728 + filling into the directory, then the object we find here will be
55729 + an anchor point with attached globbed objects
55730 + */
55731 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
55732 + if (obj->globbed == NULL)
55733 + return (obj->mode & GR_FIND) ? 1 : 0;
55734 +
55735 + is_not_root = ((obj->filename[0] == '/') &&
55736 + (obj->filename[1] == '\0')) ? 0 : 1;
55737 + bufsize = PAGE_SIZE - namelen - is_not_root;
55738 +
55739 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
55740 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
55741 + return 1;
55742 +
55743 + preempt_disable();
55744 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
55745 + bufsize);
55746 +
55747 + bufsize = strlen(path);
55748 +
55749 + /* if base is "/", don't append an additional slash */
55750 + if (is_not_root)
55751 + *(path + bufsize) = '/';
55752 + memcpy(path + bufsize + is_not_root, name, namelen);
55753 + *(path + bufsize + namelen + is_not_root) = '\0';
55754 +
55755 + tmp = obj->globbed;
55756 + while (tmp) {
55757 + if (!glob_match(tmp->filename, path)) {
55758 + preempt_enable();
55759 + return (tmp->mode & GR_FIND) ? 1 : 0;
55760 + }
55761 + tmp = tmp->next;
55762 + }
55763 + preempt_enable();
55764 + return (obj->mode & GR_FIND) ? 1 : 0;
55765 +}
55766 +
55767 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
55768 +EXPORT_SYMBOL(gr_acl_is_enabled);
55769 +#endif
55770 +EXPORT_SYMBOL(gr_learn_resource);
55771 +EXPORT_SYMBOL(gr_set_kernel_label);
55772 +#ifdef CONFIG_SECURITY
55773 +EXPORT_SYMBOL(gr_check_user_change);
55774 +EXPORT_SYMBOL(gr_check_group_change);
55775 +#endif
55776 +
55777 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
55778 new file mode 100644
55779 index 0000000..34fefda
55780 --- /dev/null
55781 +++ b/grsecurity/gracl_alloc.c
55782 @@ -0,0 +1,105 @@
55783 +#include <linux/kernel.h>
55784 +#include <linux/mm.h>
55785 +#include <linux/slab.h>
55786 +#include <linux/vmalloc.h>
55787 +#include <linux/gracl.h>
55788 +#include <linux/grsecurity.h>
55789 +
55790 +static unsigned long alloc_stack_next = 1;
55791 +static unsigned long alloc_stack_size = 1;
55792 +static void **alloc_stack;
55793 +
55794 +static __inline__ int
55795 +alloc_pop(void)
55796 +{
55797 + if (alloc_stack_next == 1)
55798 + return 0;
55799 +
55800 + kfree(alloc_stack[alloc_stack_next - 2]);
55801 +
55802 + alloc_stack_next--;
55803 +
55804 + return 1;
55805 +}
55806 +
55807 +static __inline__ int
55808 +alloc_push(void *buf)
55809 +{
55810 + if (alloc_stack_next >= alloc_stack_size)
55811 + return 1;
55812 +
55813 + alloc_stack[alloc_stack_next - 1] = buf;
55814 +
55815 + alloc_stack_next++;
55816 +
55817 + return 0;
55818 +}
55819 +
55820 +void *
55821 +acl_alloc(unsigned long len)
55822 +{
55823 + void *ret = NULL;
55824 +
55825 + if (!len || len > PAGE_SIZE)
55826 + goto out;
55827 +
55828 + ret = kmalloc(len, GFP_KERNEL);
55829 +
55830 + if (ret) {
55831 + if (alloc_push(ret)) {
55832 + kfree(ret);
55833 + ret = NULL;
55834 + }
55835 + }
55836 +
55837 +out:
55838 + return ret;
55839 +}
55840 +
55841 +void *
55842 +acl_alloc_num(unsigned long num, unsigned long len)
55843 +{
55844 + if (!len || (num > (PAGE_SIZE / len)))
55845 + return NULL;
55846 +
55847 + return acl_alloc(num * len);
55848 +}
55849 +
55850 +void
55851 +acl_free_all(void)
55852 +{
55853 + if (gr_acl_is_enabled() || !alloc_stack)
55854 + return;
55855 +
55856 + while (alloc_pop()) ;
55857 +
55858 + if (alloc_stack) {
55859 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
55860 + kfree(alloc_stack);
55861 + else
55862 + vfree(alloc_stack);
55863 + }
55864 +
55865 + alloc_stack = NULL;
55866 + alloc_stack_size = 1;
55867 + alloc_stack_next = 1;
55868 +
55869 + return;
55870 +}
55871 +
55872 +int
55873 +acl_alloc_stack_init(unsigned long size)
55874 +{
55875 + if ((size * sizeof (void *)) <= PAGE_SIZE)
55876 + alloc_stack =
55877 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
55878 + else
55879 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
55880 +
55881 + alloc_stack_size = size;
55882 +
55883 + if (!alloc_stack)
55884 + return 0;
55885 + else
55886 + return 1;
55887 +}
55888 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
55889 new file mode 100644
55890 index 0000000..6d21049
55891 --- /dev/null
55892 +++ b/grsecurity/gracl_cap.c
55893 @@ -0,0 +1,110 @@
55894 +#include <linux/kernel.h>
55895 +#include <linux/module.h>
55896 +#include <linux/sched.h>
55897 +#include <linux/gracl.h>
55898 +#include <linux/grsecurity.h>
55899 +#include <linux/grinternal.h>
55900 +
55901 +extern const char *captab_log[];
55902 +extern int captab_log_entries;
55903 +
55904 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
55905 +{
55906 + struct acl_subject_label *curracl;
55907 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55908 + kernel_cap_t cap_audit = __cap_empty_set;
55909 +
55910 + if (!gr_acl_is_enabled())
55911 + return 1;
55912 +
55913 + curracl = task->acl;
55914 +
55915 + cap_drop = curracl->cap_lower;
55916 + cap_mask = curracl->cap_mask;
55917 + cap_audit = curracl->cap_invert_audit;
55918 +
55919 + while ((curracl = curracl->parent_subject)) {
55920 + /* if the cap isn't specified in the current computed mask but is specified in the
55921 + current level subject, and is lowered in the current level subject, then add
55922 + it to the set of dropped capabilities
55923 + otherwise, add the current level subject's mask to the current computed mask
55924 + */
55925 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55926 + cap_raise(cap_mask, cap);
55927 + if (cap_raised(curracl->cap_lower, cap))
55928 + cap_raise(cap_drop, cap);
55929 + if (cap_raised(curracl->cap_invert_audit, cap))
55930 + cap_raise(cap_audit, cap);
55931 + }
55932 + }
55933 +
55934 + if (!cap_raised(cap_drop, cap)) {
55935 + if (cap_raised(cap_audit, cap))
55936 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
55937 + return 1;
55938 + }
55939 +
55940 + curracl = task->acl;
55941 +
55942 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
55943 + && cap_raised(cred->cap_effective, cap)) {
55944 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55945 + task->role->roletype, cred->uid,
55946 + cred->gid, task->exec_file ?
55947 + gr_to_filename(task->exec_file->f_path.dentry,
55948 + task->exec_file->f_path.mnt) : curracl->filename,
55949 + curracl->filename, 0UL,
55950 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
55951 + return 1;
55952 + }
55953 +
55954 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
55955 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
55956 +
55957 + return 0;
55958 +}
55959 +
55960 +int
55961 +gr_acl_is_capable(const int cap)
55962 +{
55963 + return gr_task_acl_is_capable(current, current_cred(), cap);
55964 +}
55965 +
55966 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
55967 +{
55968 + struct acl_subject_label *curracl;
55969 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55970 +
55971 + if (!gr_acl_is_enabled())
55972 + return 1;
55973 +
55974 + curracl = task->acl;
55975 +
55976 + cap_drop = curracl->cap_lower;
55977 + cap_mask = curracl->cap_mask;
55978 +
55979 + while ((curracl = curracl->parent_subject)) {
55980 + /* if the cap isn't specified in the current computed mask but is specified in the
55981 + current level subject, and is lowered in the current level subject, then add
55982 + it to the set of dropped capabilities
55983 + otherwise, add the current level subject's mask to the current computed mask
55984 + */
55985 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55986 + cap_raise(cap_mask, cap);
55987 + if (cap_raised(curracl->cap_lower, cap))
55988 + cap_raise(cap_drop, cap);
55989 + }
55990 + }
55991 +
55992 + if (!cap_raised(cap_drop, cap))
55993 + return 1;
55994 +
55995 + return 0;
55996 +}
55997 +
55998 +int
55999 +gr_acl_is_capable_nolog(const int cap)
56000 +{
56001 + return gr_task_acl_is_capable_nolog(current, cap);
56002 +}
56003 +
56004 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
56005 new file mode 100644
56006 index 0000000..d28e241
56007 --- /dev/null
56008 +++ b/grsecurity/gracl_fs.c
56009 @@ -0,0 +1,437 @@
56010 +#include <linux/kernel.h>
56011 +#include <linux/sched.h>
56012 +#include <linux/types.h>
56013 +#include <linux/fs.h>
56014 +#include <linux/file.h>
56015 +#include <linux/stat.h>
56016 +#include <linux/grsecurity.h>
56017 +#include <linux/grinternal.h>
56018 +#include <linux/gracl.h>
56019 +
56020 +umode_t
56021 +gr_acl_umask(void)
56022 +{
56023 + if (unlikely(!gr_acl_is_enabled()))
56024 + return 0;
56025 +
56026 + return current->role->umask;
56027 +}
56028 +
56029 +__u32
56030 +gr_acl_handle_hidden_file(const struct dentry * dentry,
56031 + const struct vfsmount * mnt)
56032 +{
56033 + __u32 mode;
56034 +
56035 + if (unlikely(!dentry->d_inode))
56036 + return GR_FIND;
56037 +
56038 + mode =
56039 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
56040 +
56041 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
56042 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
56043 + return mode;
56044 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
56045 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
56046 + return 0;
56047 + } else if (unlikely(!(mode & GR_FIND)))
56048 + return 0;
56049 +
56050 + return GR_FIND;
56051 +}
56052 +
56053 +__u32
56054 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
56055 + int acc_mode)
56056 +{
56057 + __u32 reqmode = GR_FIND;
56058 + __u32 mode;
56059 +
56060 + if (unlikely(!dentry->d_inode))
56061 + return reqmode;
56062 +
56063 + if (acc_mode & MAY_APPEND)
56064 + reqmode |= GR_APPEND;
56065 + else if (acc_mode & MAY_WRITE)
56066 + reqmode |= GR_WRITE;
56067 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
56068 + reqmode |= GR_READ;
56069 +
56070 + mode =
56071 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
56072 + mnt);
56073 +
56074 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56075 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
56076 + reqmode & GR_READ ? " reading" : "",
56077 + reqmode & GR_WRITE ? " writing" : reqmode &
56078 + GR_APPEND ? " appending" : "");
56079 + return reqmode;
56080 + } else
56081 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56082 + {
56083 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
56084 + reqmode & GR_READ ? " reading" : "",
56085 + reqmode & GR_WRITE ? " writing" : reqmode &
56086 + GR_APPEND ? " appending" : "");
56087 + return 0;
56088 + } else if (unlikely((mode & reqmode) != reqmode))
56089 + return 0;
56090 +
56091 + return reqmode;
56092 +}
56093 +
56094 +__u32
56095 +gr_acl_handle_creat(const struct dentry * dentry,
56096 + const struct dentry * p_dentry,
56097 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
56098 + const int imode)
56099 +{
56100 + __u32 reqmode = GR_WRITE | GR_CREATE;
56101 + __u32 mode;
56102 +
56103 + if (acc_mode & MAY_APPEND)
56104 + reqmode |= GR_APPEND;
56105 + // if a directory was required or the directory already exists, then
56106 + // don't count this open as a read
56107 + if ((acc_mode & MAY_READ) &&
56108 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
56109 + reqmode |= GR_READ;
56110 + if ((open_flags & O_CREAT) &&
56111 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
56112 + reqmode |= GR_SETID;
56113 +
56114 + mode =
56115 + gr_check_create(dentry, p_dentry, p_mnt,
56116 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
56117 +
56118 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56119 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
56120 + reqmode & GR_READ ? " reading" : "",
56121 + reqmode & GR_WRITE ? " writing" : reqmode &
56122 + GR_APPEND ? " appending" : "");
56123 + return reqmode;
56124 + } else
56125 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56126 + {
56127 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
56128 + reqmode & GR_READ ? " reading" : "",
56129 + reqmode & GR_WRITE ? " writing" : reqmode &
56130 + GR_APPEND ? " appending" : "");
56131 + return 0;
56132 + } else if (unlikely((mode & reqmode) != reqmode))
56133 + return 0;
56134 +
56135 + return reqmode;
56136 +}
56137 +
56138 +__u32
56139 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
56140 + const int fmode)
56141 +{
56142 + __u32 mode, reqmode = GR_FIND;
56143 +
56144 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
56145 + reqmode |= GR_EXEC;
56146 + if (fmode & S_IWOTH)
56147 + reqmode |= GR_WRITE;
56148 + if (fmode & S_IROTH)
56149 + reqmode |= GR_READ;
56150 +
56151 + mode =
56152 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
56153 + mnt);
56154 +
56155 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56156 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
56157 + reqmode & GR_READ ? " reading" : "",
56158 + reqmode & GR_WRITE ? " writing" : "",
56159 + reqmode & GR_EXEC ? " executing" : "");
56160 + return reqmode;
56161 + } else
56162 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56163 + {
56164 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
56165 + reqmode & GR_READ ? " reading" : "",
56166 + reqmode & GR_WRITE ? " writing" : "",
56167 + reqmode & GR_EXEC ? " executing" : "");
56168 + return 0;
56169 + } else if (unlikely((mode & reqmode) != reqmode))
56170 + return 0;
56171 +
56172 + return reqmode;
56173 +}
56174 +
56175 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
56176 +{
56177 + __u32 mode;
56178 +
56179 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
56180 +
56181 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
56182 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
56183 + return mode;
56184 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
56185 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
56186 + return 0;
56187 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
56188 + return 0;
56189 +
56190 + return (reqmode);
56191 +}
56192 +
56193 +__u32
56194 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
56195 +{
56196 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
56197 +}
56198 +
56199 +__u32
56200 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
56201 +{
56202 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
56203 +}
56204 +
56205 +__u32
56206 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
56207 +{
56208 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
56209 +}
56210 +
56211 +__u32
56212 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
56213 +{
56214 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
56215 +}
56216 +
56217 +__u32
56218 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
56219 + umode_t *modeptr)
56220 +{
56221 + umode_t mode;
56222 +
56223 + *modeptr &= ~gr_acl_umask();
56224 + mode = *modeptr;
56225 +
56226 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
56227 + return 1;
56228 +
56229 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
56230 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
56231 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
56232 + GR_CHMOD_ACL_MSG);
56233 + } else {
56234 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
56235 + }
56236 +}
56237 +
56238 +__u32
56239 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
56240 +{
56241 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
56242 +}
56243 +
56244 +__u32
56245 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
56246 +{
56247 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
56248 +}
56249 +
56250 +__u32
56251 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
56252 +{
56253 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
56254 +}
56255 +
56256 +__u32
56257 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
56258 +{
56259 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
56260 + GR_UNIXCONNECT_ACL_MSG);
56261 +}
56262 +
56263 +/* hardlinks require at minimum create and link permission,
56264 + any additional privilege required is based on the
56265 + privilege of the file being linked to
56266 +*/
56267 +__u32
56268 +gr_acl_handle_link(const struct dentry * new_dentry,
56269 + const struct dentry * parent_dentry,
56270 + const struct vfsmount * parent_mnt,
56271 + const struct dentry * old_dentry,
56272 + const struct vfsmount * old_mnt, const char *to)
56273 +{
56274 + __u32 mode;
56275 + __u32 needmode = GR_CREATE | GR_LINK;
56276 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
56277 +
56278 + mode =
56279 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
56280 + old_mnt);
56281 +
56282 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
56283 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
56284 + return mode;
56285 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56286 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
56287 + return 0;
56288 + } else if (unlikely((mode & needmode) != needmode))
56289 + return 0;
56290 +
56291 + return 1;
56292 +}
56293 +
56294 +__u32
56295 +gr_acl_handle_symlink(const struct dentry * new_dentry,
56296 + const struct dentry * parent_dentry,
56297 + const struct vfsmount * parent_mnt, const char *from)
56298 +{
56299 + __u32 needmode = GR_WRITE | GR_CREATE;
56300 + __u32 mode;
56301 +
56302 + mode =
56303 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
56304 + GR_CREATE | GR_AUDIT_CREATE |
56305 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
56306 +
56307 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
56308 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
56309 + return mode;
56310 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56311 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
56312 + return 0;
56313 + } else if (unlikely((mode & needmode) != needmode))
56314 + return 0;
56315 +
56316 + return (GR_WRITE | GR_CREATE);
56317 +}
56318 +
56319 +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)
56320 +{
56321 + __u32 mode;
56322 +
56323 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
56324 +
56325 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
56326 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
56327 + return mode;
56328 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
56329 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
56330 + return 0;
56331 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
56332 + return 0;
56333 +
56334 + return (reqmode);
56335 +}
56336 +
56337 +__u32
56338 +gr_acl_handle_mknod(const struct dentry * new_dentry,
56339 + const struct dentry * parent_dentry,
56340 + const struct vfsmount * parent_mnt,
56341 + const int mode)
56342 +{
56343 + __u32 reqmode = GR_WRITE | GR_CREATE;
56344 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
56345 + reqmode |= GR_SETID;
56346 +
56347 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56348 + reqmode, GR_MKNOD_ACL_MSG);
56349 +}
56350 +
56351 +__u32
56352 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
56353 + const struct dentry *parent_dentry,
56354 + const struct vfsmount *parent_mnt)
56355 +{
56356 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56357 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
56358 +}
56359 +
56360 +#define RENAME_CHECK_SUCCESS(old, new) \
56361 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
56362 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
56363 +
56364 +int
56365 +gr_acl_handle_rename(struct dentry *new_dentry,
56366 + struct dentry *parent_dentry,
56367 + const struct vfsmount *parent_mnt,
56368 + struct dentry *old_dentry,
56369 + struct inode *old_parent_inode,
56370 + struct vfsmount *old_mnt, const char *newname)
56371 +{
56372 + __u32 comp1, comp2;
56373 + int error = 0;
56374 +
56375 + if (unlikely(!gr_acl_is_enabled()))
56376 + return 0;
56377 +
56378 + if (!new_dentry->d_inode) {
56379 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
56380 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
56381 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
56382 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
56383 + GR_DELETE | GR_AUDIT_DELETE |
56384 + GR_AUDIT_READ | GR_AUDIT_WRITE |
56385 + GR_SUPPRESS, old_mnt);
56386 + } else {
56387 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
56388 + GR_CREATE | GR_DELETE |
56389 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
56390 + GR_AUDIT_READ | GR_AUDIT_WRITE |
56391 + GR_SUPPRESS, parent_mnt);
56392 + comp2 =
56393 + gr_search_file(old_dentry,
56394 + GR_READ | GR_WRITE | GR_AUDIT_READ |
56395 + GR_DELETE | GR_AUDIT_DELETE |
56396 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
56397 + }
56398 +
56399 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
56400 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
56401 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56402 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
56403 + && !(comp2 & GR_SUPPRESS)) {
56404 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56405 + error = -EACCES;
56406 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
56407 + error = -EACCES;
56408 +
56409 + return error;
56410 +}
56411 +
56412 +void
56413 +gr_acl_handle_exit(void)
56414 +{
56415 + u16 id;
56416 + char *rolename;
56417 + struct file *exec_file;
56418 +
56419 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
56420 + !(current->role->roletype & GR_ROLE_PERSIST))) {
56421 + id = current->acl_role_id;
56422 + rolename = current->role->rolename;
56423 + gr_set_acls(1);
56424 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
56425 + }
56426 +
56427 + write_lock(&grsec_exec_file_lock);
56428 + exec_file = current->exec_file;
56429 + current->exec_file = NULL;
56430 + write_unlock(&grsec_exec_file_lock);
56431 +
56432 + if (exec_file)
56433 + fput(exec_file);
56434 +}
56435 +
56436 +int
56437 +gr_acl_handle_procpidmem(const struct task_struct *task)
56438 +{
56439 + if (unlikely(!gr_acl_is_enabled()))
56440 + return 0;
56441 +
56442 + if (task != current && task->acl->mode & GR_PROTPROCFD)
56443 + return -EACCES;
56444 +
56445 + return 0;
56446 +}
56447 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
56448 new file mode 100644
56449 index 0000000..58800a7
56450 --- /dev/null
56451 +++ b/grsecurity/gracl_ip.c
56452 @@ -0,0 +1,384 @@
56453 +#include <linux/kernel.h>
56454 +#include <asm/uaccess.h>
56455 +#include <asm/errno.h>
56456 +#include <net/sock.h>
56457 +#include <linux/file.h>
56458 +#include <linux/fs.h>
56459 +#include <linux/net.h>
56460 +#include <linux/in.h>
56461 +#include <linux/skbuff.h>
56462 +#include <linux/ip.h>
56463 +#include <linux/udp.h>
56464 +#include <linux/types.h>
56465 +#include <linux/sched.h>
56466 +#include <linux/netdevice.h>
56467 +#include <linux/inetdevice.h>
56468 +#include <linux/gracl.h>
56469 +#include <linux/grsecurity.h>
56470 +#include <linux/grinternal.h>
56471 +
56472 +#define GR_BIND 0x01
56473 +#define GR_CONNECT 0x02
56474 +#define GR_INVERT 0x04
56475 +#define GR_BINDOVERRIDE 0x08
56476 +#define GR_CONNECTOVERRIDE 0x10
56477 +#define GR_SOCK_FAMILY 0x20
56478 +
56479 +static const char * gr_protocols[IPPROTO_MAX] = {
56480 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
56481 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
56482 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
56483 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
56484 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
56485 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
56486 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
56487 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
56488 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
56489 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
56490 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
56491 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
56492 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
56493 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
56494 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
56495 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
56496 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
56497 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
56498 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
56499 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
56500 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
56501 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
56502 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
56503 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
56504 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
56505 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
56506 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
56507 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
56508 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
56509 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
56510 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
56511 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
56512 + };
56513 +
56514 +static const char * gr_socktypes[SOCK_MAX] = {
56515 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
56516 + "unknown:7", "unknown:8", "unknown:9", "packet"
56517 + };
56518 +
56519 +static const char * gr_sockfamilies[AF_MAX+1] = {
56520 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
56521 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
56522 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
56523 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
56524 + };
56525 +
56526 +const char *
56527 +gr_proto_to_name(unsigned char proto)
56528 +{
56529 + return gr_protocols[proto];
56530 +}
56531 +
56532 +const char *
56533 +gr_socktype_to_name(unsigned char type)
56534 +{
56535 + return gr_socktypes[type];
56536 +}
56537 +
56538 +const char *
56539 +gr_sockfamily_to_name(unsigned char family)
56540 +{
56541 + return gr_sockfamilies[family];
56542 +}
56543 +
56544 +int
56545 +gr_search_socket(const int domain, const int type, const int protocol)
56546 +{
56547 + struct acl_subject_label *curr;
56548 + const struct cred *cred = current_cred();
56549 +
56550 + if (unlikely(!gr_acl_is_enabled()))
56551 + goto exit;
56552 +
56553 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
56554 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
56555 + goto exit; // let the kernel handle it
56556 +
56557 + curr = current->acl;
56558 +
56559 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
56560 + /* the family is allowed, if this is PF_INET allow it only if
56561 + the extra sock type/protocol checks pass */
56562 + if (domain == PF_INET)
56563 + goto inet_check;
56564 + goto exit;
56565 + } else {
56566 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
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, domain, 0, 0, GR_SOCK_FAMILY,
56575 + &current->signal->saved_ip);
56576 + goto exit;
56577 + }
56578 + goto exit_fail;
56579 + }
56580 +
56581 +inet_check:
56582 + /* the rest of this checking is for IPv4 only */
56583 + if (!curr->ips)
56584 + goto exit;
56585 +
56586 + if ((curr->ip_type & (1 << type)) &&
56587 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
56588 + goto exit;
56589 +
56590 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56591 + /* we don't place acls on raw sockets , and sometimes
56592 + dgram/ip sockets are opened for ioctl and not
56593 + bind/connect, so we'll fake a bind learn log */
56594 + if (type == SOCK_RAW || type == SOCK_PACKET) {
56595 + __u32 fakeip = 0;
56596 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56597 + current->role->roletype, cred->uid,
56598 + cred->gid, current->exec_file ?
56599 + gr_to_filename(current->exec_file->f_path.dentry,
56600 + current->exec_file->f_path.mnt) :
56601 + curr->filename, curr->filename,
56602 + &fakeip, 0, type,
56603 + protocol, GR_CONNECT, &current->signal->saved_ip);
56604 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
56605 + __u32 fakeip = 0;
56606 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56607 + current->role->roletype, cred->uid,
56608 + cred->gid, current->exec_file ?
56609 + gr_to_filename(current->exec_file->f_path.dentry,
56610 + current->exec_file->f_path.mnt) :
56611 + curr->filename, curr->filename,
56612 + &fakeip, 0, type,
56613 + protocol, GR_BIND, &current->signal->saved_ip);
56614 + }
56615 + /* we'll log when they use connect or bind */
56616 + goto exit;
56617 + }
56618 +
56619 +exit_fail:
56620 + if (domain == PF_INET)
56621 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
56622 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
56623 + else
56624 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
56625 + gr_socktype_to_name(type), protocol);
56626 +
56627 + return 0;
56628 +exit:
56629 + return 1;
56630 +}
56631 +
56632 +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)
56633 +{
56634 + if ((ip->mode & mode) &&
56635 + (ip_port >= ip->low) &&
56636 + (ip_port <= ip->high) &&
56637 + ((ntohl(ip_addr) & our_netmask) ==
56638 + (ntohl(our_addr) & our_netmask))
56639 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
56640 + && (ip->type & (1 << type))) {
56641 + if (ip->mode & GR_INVERT)
56642 + return 2; // specifically denied
56643 + else
56644 + return 1; // allowed
56645 + }
56646 +
56647 + return 0; // not specifically allowed, may continue parsing
56648 +}
56649 +
56650 +static int
56651 +gr_search_connectbind(const int full_mode, struct sock *sk,
56652 + struct sockaddr_in *addr, const int type)
56653 +{
56654 + char iface[IFNAMSIZ] = {0};
56655 + struct acl_subject_label *curr;
56656 + struct acl_ip_label *ip;
56657 + struct inet_sock *isk;
56658 + struct net_device *dev;
56659 + struct in_device *idev;
56660 + unsigned long i;
56661 + int ret;
56662 + int mode = full_mode & (GR_BIND | GR_CONNECT);
56663 + __u32 ip_addr = 0;
56664 + __u32 our_addr;
56665 + __u32 our_netmask;
56666 + char *p;
56667 + __u16 ip_port = 0;
56668 + const struct cred *cred = current_cred();
56669 +
56670 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
56671 + return 0;
56672 +
56673 + curr = current->acl;
56674 + isk = inet_sk(sk);
56675 +
56676 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
56677 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
56678 + addr->sin_addr.s_addr = curr->inaddr_any_override;
56679 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
56680 + struct sockaddr_in saddr;
56681 + int err;
56682 +
56683 + saddr.sin_family = AF_INET;
56684 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
56685 + saddr.sin_port = isk->inet_sport;
56686 +
56687 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56688 + if (err)
56689 + return err;
56690 +
56691 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56692 + if (err)
56693 + return err;
56694 + }
56695 +
56696 + if (!curr->ips)
56697 + return 0;
56698 +
56699 + ip_addr = addr->sin_addr.s_addr;
56700 + ip_port = ntohs(addr->sin_port);
56701 +
56702 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56703 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56704 + current->role->roletype, cred->uid,
56705 + cred->gid, current->exec_file ?
56706 + gr_to_filename(current->exec_file->f_path.dentry,
56707 + current->exec_file->f_path.mnt) :
56708 + curr->filename, curr->filename,
56709 + &ip_addr, ip_port, type,
56710 + sk->sk_protocol, mode, &current->signal->saved_ip);
56711 + return 0;
56712 + }
56713 +
56714 + for (i = 0; i < curr->ip_num; i++) {
56715 + ip = *(curr->ips + i);
56716 + if (ip->iface != NULL) {
56717 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
56718 + p = strchr(iface, ':');
56719 + if (p != NULL)
56720 + *p = '\0';
56721 + dev = dev_get_by_name(sock_net(sk), iface);
56722 + if (dev == NULL)
56723 + continue;
56724 + idev = in_dev_get(dev);
56725 + if (idev == NULL) {
56726 + dev_put(dev);
56727 + continue;
56728 + }
56729 + rcu_read_lock();
56730 + for_ifa(idev) {
56731 + if (!strcmp(ip->iface, ifa->ifa_label)) {
56732 + our_addr = ifa->ifa_address;
56733 + our_netmask = 0xffffffff;
56734 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56735 + if (ret == 1) {
56736 + rcu_read_unlock();
56737 + in_dev_put(idev);
56738 + dev_put(dev);
56739 + return 0;
56740 + } else if (ret == 2) {
56741 + rcu_read_unlock();
56742 + in_dev_put(idev);
56743 + dev_put(dev);
56744 + goto denied;
56745 + }
56746 + }
56747 + } endfor_ifa(idev);
56748 + rcu_read_unlock();
56749 + in_dev_put(idev);
56750 + dev_put(dev);
56751 + } else {
56752 + our_addr = ip->addr;
56753 + our_netmask = ip->netmask;
56754 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56755 + if (ret == 1)
56756 + return 0;
56757 + else if (ret == 2)
56758 + goto denied;
56759 + }
56760 + }
56761 +
56762 +denied:
56763 + if (mode == GR_BIND)
56764 + 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));
56765 + else if (mode == GR_CONNECT)
56766 + 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));
56767 +
56768 + return -EACCES;
56769 +}
56770 +
56771 +int
56772 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
56773 +{
56774 + /* always allow disconnection of dgram sockets with connect */
56775 + if (addr->sin_family == AF_UNSPEC)
56776 + return 0;
56777 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
56778 +}
56779 +
56780 +int
56781 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
56782 +{
56783 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
56784 +}
56785 +
56786 +int gr_search_listen(struct socket *sock)
56787 +{
56788 + struct sock *sk = sock->sk;
56789 + struct sockaddr_in addr;
56790 +
56791 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56792 + addr.sin_port = inet_sk(sk)->inet_sport;
56793 +
56794 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56795 +}
56796 +
56797 +int gr_search_accept(struct socket *sock)
56798 +{
56799 + struct sock *sk = sock->sk;
56800 + struct sockaddr_in addr;
56801 +
56802 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56803 + addr.sin_port = inet_sk(sk)->inet_sport;
56804 +
56805 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56806 +}
56807 +
56808 +int
56809 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
56810 +{
56811 + if (addr)
56812 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
56813 + else {
56814 + struct sockaddr_in sin;
56815 + const struct inet_sock *inet = inet_sk(sk);
56816 +
56817 + sin.sin_addr.s_addr = inet->inet_daddr;
56818 + sin.sin_port = inet->inet_dport;
56819 +
56820 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56821 + }
56822 +}
56823 +
56824 +int
56825 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
56826 +{
56827 + struct sockaddr_in sin;
56828 +
56829 + if (unlikely(skb->len < sizeof (struct udphdr)))
56830 + return 0; // skip this packet
56831 +
56832 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
56833 + sin.sin_port = udp_hdr(skb)->source;
56834 +
56835 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56836 +}
56837 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
56838 new file mode 100644
56839 index 0000000..25f54ef
56840 --- /dev/null
56841 +++ b/grsecurity/gracl_learn.c
56842 @@ -0,0 +1,207 @@
56843 +#include <linux/kernel.h>
56844 +#include <linux/mm.h>
56845 +#include <linux/sched.h>
56846 +#include <linux/poll.h>
56847 +#include <linux/string.h>
56848 +#include <linux/file.h>
56849 +#include <linux/types.h>
56850 +#include <linux/vmalloc.h>
56851 +#include <linux/grinternal.h>
56852 +
56853 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
56854 + size_t count, loff_t *ppos);
56855 +extern int gr_acl_is_enabled(void);
56856 +
56857 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
56858 +static int gr_learn_attached;
56859 +
56860 +/* use a 512k buffer */
56861 +#define LEARN_BUFFER_SIZE (512 * 1024)
56862 +
56863 +static DEFINE_SPINLOCK(gr_learn_lock);
56864 +static DEFINE_MUTEX(gr_learn_user_mutex);
56865 +
56866 +/* we need to maintain two buffers, so that the kernel context of grlearn
56867 + uses a semaphore around the userspace copying, and the other kernel contexts
56868 + use a spinlock when copying into the buffer, since they cannot sleep
56869 +*/
56870 +static char *learn_buffer;
56871 +static char *learn_buffer_user;
56872 +static int learn_buffer_len;
56873 +static int learn_buffer_user_len;
56874 +
56875 +static ssize_t
56876 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
56877 +{
56878 + DECLARE_WAITQUEUE(wait, current);
56879 + ssize_t retval = 0;
56880 +
56881 + add_wait_queue(&learn_wait, &wait);
56882 + set_current_state(TASK_INTERRUPTIBLE);
56883 + do {
56884 + mutex_lock(&gr_learn_user_mutex);
56885 + spin_lock(&gr_learn_lock);
56886 + if (learn_buffer_len)
56887 + break;
56888 + spin_unlock(&gr_learn_lock);
56889 + mutex_unlock(&gr_learn_user_mutex);
56890 + if (file->f_flags & O_NONBLOCK) {
56891 + retval = -EAGAIN;
56892 + goto out;
56893 + }
56894 + if (signal_pending(current)) {
56895 + retval = -ERESTARTSYS;
56896 + goto out;
56897 + }
56898 +
56899 + schedule();
56900 + } while (1);
56901 +
56902 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
56903 + learn_buffer_user_len = learn_buffer_len;
56904 + retval = learn_buffer_len;
56905 + learn_buffer_len = 0;
56906 +
56907 + spin_unlock(&gr_learn_lock);
56908 +
56909 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
56910 + retval = -EFAULT;
56911 +
56912 + mutex_unlock(&gr_learn_user_mutex);
56913 +out:
56914 + set_current_state(TASK_RUNNING);
56915 + remove_wait_queue(&learn_wait, &wait);
56916 + return retval;
56917 +}
56918 +
56919 +static unsigned int
56920 +poll_learn(struct file * file, poll_table * wait)
56921 +{
56922 + poll_wait(file, &learn_wait, wait);
56923 +
56924 + if (learn_buffer_len)
56925 + return (POLLIN | POLLRDNORM);
56926 +
56927 + return 0;
56928 +}
56929 +
56930 +void
56931 +gr_clear_learn_entries(void)
56932 +{
56933 + char *tmp;
56934 +
56935 + mutex_lock(&gr_learn_user_mutex);
56936 + spin_lock(&gr_learn_lock);
56937 + tmp = learn_buffer;
56938 + learn_buffer = NULL;
56939 + spin_unlock(&gr_learn_lock);
56940 + if (tmp)
56941 + vfree(tmp);
56942 + if (learn_buffer_user != NULL) {
56943 + vfree(learn_buffer_user);
56944 + learn_buffer_user = NULL;
56945 + }
56946 + learn_buffer_len = 0;
56947 + mutex_unlock(&gr_learn_user_mutex);
56948 +
56949 + return;
56950 +}
56951 +
56952 +void
56953 +gr_add_learn_entry(const char *fmt, ...)
56954 +{
56955 + va_list args;
56956 + unsigned int len;
56957 +
56958 + if (!gr_learn_attached)
56959 + return;
56960 +
56961 + spin_lock(&gr_learn_lock);
56962 +
56963 + /* leave a gap at the end so we know when it's "full" but don't have to
56964 + compute the exact length of the string we're trying to append
56965 + */
56966 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
56967 + spin_unlock(&gr_learn_lock);
56968 + wake_up_interruptible(&learn_wait);
56969 + return;
56970 + }
56971 + if (learn_buffer == NULL) {
56972 + spin_unlock(&gr_learn_lock);
56973 + return;
56974 + }
56975 +
56976 + va_start(args, fmt);
56977 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
56978 + va_end(args);
56979 +
56980 + learn_buffer_len += len + 1;
56981 +
56982 + spin_unlock(&gr_learn_lock);
56983 + wake_up_interruptible(&learn_wait);
56984 +
56985 + return;
56986 +}
56987 +
56988 +static int
56989 +open_learn(struct inode *inode, struct file *file)
56990 +{
56991 + if (file->f_mode & FMODE_READ && gr_learn_attached)
56992 + return -EBUSY;
56993 + if (file->f_mode & FMODE_READ) {
56994 + int retval = 0;
56995 + mutex_lock(&gr_learn_user_mutex);
56996 + if (learn_buffer == NULL)
56997 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
56998 + if (learn_buffer_user == NULL)
56999 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
57000 + if (learn_buffer == NULL) {
57001 + retval = -ENOMEM;
57002 + goto out_error;
57003 + }
57004 + if (learn_buffer_user == NULL) {
57005 + retval = -ENOMEM;
57006 + goto out_error;
57007 + }
57008 + learn_buffer_len = 0;
57009 + learn_buffer_user_len = 0;
57010 + gr_learn_attached = 1;
57011 +out_error:
57012 + mutex_unlock(&gr_learn_user_mutex);
57013 + return retval;
57014 + }
57015 + return 0;
57016 +}
57017 +
57018 +static int
57019 +close_learn(struct inode *inode, struct file *file)
57020 +{
57021 + if (file->f_mode & FMODE_READ) {
57022 + char *tmp = NULL;
57023 + mutex_lock(&gr_learn_user_mutex);
57024 + spin_lock(&gr_learn_lock);
57025 + tmp = learn_buffer;
57026 + learn_buffer = NULL;
57027 + spin_unlock(&gr_learn_lock);
57028 + if (tmp)
57029 + vfree(tmp);
57030 + if (learn_buffer_user != NULL) {
57031 + vfree(learn_buffer_user);
57032 + learn_buffer_user = NULL;
57033 + }
57034 + learn_buffer_len = 0;
57035 + learn_buffer_user_len = 0;
57036 + gr_learn_attached = 0;
57037 + mutex_unlock(&gr_learn_user_mutex);
57038 + }
57039 +
57040 + return 0;
57041 +}
57042 +
57043 +const struct file_operations grsec_fops = {
57044 + .read = read_learn,
57045 + .write = write_grsec_handler,
57046 + .open = open_learn,
57047 + .release = close_learn,
57048 + .poll = poll_learn,
57049 +};
57050 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
57051 new file mode 100644
57052 index 0000000..39645c9
57053 --- /dev/null
57054 +++ b/grsecurity/gracl_res.c
57055 @@ -0,0 +1,68 @@
57056 +#include <linux/kernel.h>
57057 +#include <linux/sched.h>
57058 +#include <linux/gracl.h>
57059 +#include <linux/grinternal.h>
57060 +
57061 +static const char *restab_log[] = {
57062 + [RLIMIT_CPU] = "RLIMIT_CPU",
57063 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
57064 + [RLIMIT_DATA] = "RLIMIT_DATA",
57065 + [RLIMIT_STACK] = "RLIMIT_STACK",
57066 + [RLIMIT_CORE] = "RLIMIT_CORE",
57067 + [RLIMIT_RSS] = "RLIMIT_RSS",
57068 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
57069 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
57070 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
57071 + [RLIMIT_AS] = "RLIMIT_AS",
57072 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
57073 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
57074 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
57075 + [RLIMIT_NICE] = "RLIMIT_NICE",
57076 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
57077 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
57078 + [GR_CRASH_RES] = "RLIMIT_CRASH"
57079 +};
57080 +
57081 +void
57082 +gr_log_resource(const struct task_struct *task,
57083 + const int res, const unsigned long wanted, const int gt)
57084 +{
57085 + const struct cred *cred;
57086 + unsigned long rlim;
57087 +
57088 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
57089 + return;
57090 +
57091 + // not yet supported resource
57092 + if (unlikely(!restab_log[res]))
57093 + return;
57094 +
57095 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
57096 + rlim = task_rlimit_max(task, res);
57097 + else
57098 + rlim = task_rlimit(task, res);
57099 +
57100 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
57101 + return;
57102 +
57103 + rcu_read_lock();
57104 + cred = __task_cred(task);
57105 +
57106 + if (res == RLIMIT_NPROC &&
57107 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
57108 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
57109 + goto out_rcu_unlock;
57110 + else if (res == RLIMIT_MEMLOCK &&
57111 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
57112 + goto out_rcu_unlock;
57113 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
57114 + goto out_rcu_unlock;
57115 + rcu_read_unlock();
57116 +
57117 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
57118 +
57119 + return;
57120 +out_rcu_unlock:
57121 + rcu_read_unlock();
57122 + return;
57123 +}
57124 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
57125 new file mode 100644
57126 index 0000000..25197e9
57127 --- /dev/null
57128 +++ b/grsecurity/gracl_segv.c
57129 @@ -0,0 +1,299 @@
57130 +#include <linux/kernel.h>
57131 +#include <linux/mm.h>
57132 +#include <asm/uaccess.h>
57133 +#include <asm/errno.h>
57134 +#include <asm/mman.h>
57135 +#include <net/sock.h>
57136 +#include <linux/file.h>
57137 +#include <linux/fs.h>
57138 +#include <linux/net.h>
57139 +#include <linux/in.h>
57140 +#include <linux/slab.h>
57141 +#include <linux/types.h>
57142 +#include <linux/sched.h>
57143 +#include <linux/timer.h>
57144 +#include <linux/gracl.h>
57145 +#include <linux/grsecurity.h>
57146 +#include <linux/grinternal.h>
57147 +
57148 +static struct crash_uid *uid_set;
57149 +static unsigned short uid_used;
57150 +static DEFINE_SPINLOCK(gr_uid_lock);
57151 +extern rwlock_t gr_inode_lock;
57152 +extern struct acl_subject_label *
57153 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
57154 + struct acl_role_label *role);
57155 +
57156 +#ifdef CONFIG_BTRFS_FS
57157 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
57158 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
57159 +#endif
57160 +
57161 +static inline dev_t __get_dev(const struct dentry *dentry)
57162 +{
57163 +#ifdef CONFIG_BTRFS_FS
57164 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
57165 + return get_btrfs_dev_from_inode(dentry->d_inode);
57166 + else
57167 +#endif
57168 + return dentry->d_inode->i_sb->s_dev;
57169 +}
57170 +
57171 +int
57172 +gr_init_uidset(void)
57173 +{
57174 + uid_set =
57175 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
57176 + uid_used = 0;
57177 +
57178 + return uid_set ? 1 : 0;
57179 +}
57180 +
57181 +void
57182 +gr_free_uidset(void)
57183 +{
57184 + if (uid_set)
57185 + kfree(uid_set);
57186 +
57187 + return;
57188 +}
57189 +
57190 +int
57191 +gr_find_uid(const uid_t uid)
57192 +{
57193 + struct crash_uid *tmp = uid_set;
57194 + uid_t buid;
57195 + int low = 0, high = uid_used - 1, mid;
57196 +
57197 + while (high >= low) {
57198 + mid = (low + high) >> 1;
57199 + buid = tmp[mid].uid;
57200 + if (buid == uid)
57201 + return mid;
57202 + if (buid > uid)
57203 + high = mid - 1;
57204 + if (buid < uid)
57205 + low = mid + 1;
57206 + }
57207 +
57208 + return -1;
57209 +}
57210 +
57211 +static __inline__ void
57212 +gr_insertsort(void)
57213 +{
57214 + unsigned short i, j;
57215 + struct crash_uid index;
57216 +
57217 + for (i = 1; i < uid_used; i++) {
57218 + index = uid_set[i];
57219 + j = i;
57220 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
57221 + uid_set[j] = uid_set[j - 1];
57222 + j--;
57223 + }
57224 + uid_set[j] = index;
57225 + }
57226 +
57227 + return;
57228 +}
57229 +
57230 +static __inline__ void
57231 +gr_insert_uid(const uid_t uid, const unsigned long expires)
57232 +{
57233 + int loc;
57234 +
57235 + if (uid_used == GR_UIDTABLE_MAX)
57236 + return;
57237 +
57238 + loc = gr_find_uid(uid);
57239 +
57240 + if (loc >= 0) {
57241 + uid_set[loc].expires = expires;
57242 + return;
57243 + }
57244 +
57245 + uid_set[uid_used].uid = uid;
57246 + uid_set[uid_used].expires = expires;
57247 + uid_used++;
57248 +
57249 + gr_insertsort();
57250 +
57251 + return;
57252 +}
57253 +
57254 +void
57255 +gr_remove_uid(const unsigned short loc)
57256 +{
57257 + unsigned short i;
57258 +
57259 + for (i = loc + 1; i < uid_used; i++)
57260 + uid_set[i - 1] = uid_set[i];
57261 +
57262 + uid_used--;
57263 +
57264 + return;
57265 +}
57266 +
57267 +int
57268 +gr_check_crash_uid(const uid_t uid)
57269 +{
57270 + int loc;
57271 + int ret = 0;
57272 +
57273 + if (unlikely(!gr_acl_is_enabled()))
57274 + return 0;
57275 +
57276 + spin_lock(&gr_uid_lock);
57277 + loc = gr_find_uid(uid);
57278 +
57279 + if (loc < 0)
57280 + goto out_unlock;
57281 +
57282 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
57283 + gr_remove_uid(loc);
57284 + else
57285 + ret = 1;
57286 +
57287 +out_unlock:
57288 + spin_unlock(&gr_uid_lock);
57289 + return ret;
57290 +}
57291 +
57292 +static __inline__ int
57293 +proc_is_setxid(const struct cred *cred)
57294 +{
57295 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
57296 + !uid_eq(cred->uid, cred->fsuid))
57297 + return 1;
57298 + if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
57299 + !uid_eq(cred->gid, cred->fsgid))
57300 + return 1;
57301 +
57302 + return 0;
57303 +}
57304 +
57305 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
57306 +
57307 +void
57308 +gr_handle_crash(struct task_struct *task, const int sig)
57309 +{
57310 + struct acl_subject_label *curr;
57311 + struct task_struct *tsk, *tsk2;
57312 + const struct cred *cred;
57313 + const struct cred *cred2;
57314 +
57315 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
57316 + return;
57317 +
57318 + if (unlikely(!gr_acl_is_enabled()))
57319 + return;
57320 +
57321 + curr = task->acl;
57322 +
57323 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
57324 + return;
57325 +
57326 + if (time_before_eq(curr->expires, get_seconds())) {
57327 + curr->expires = 0;
57328 + curr->crashes = 0;
57329 + }
57330 +
57331 + curr->crashes++;
57332 +
57333 + if (!curr->expires)
57334 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
57335 +
57336 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57337 + time_after(curr->expires, get_seconds())) {
57338 + rcu_read_lock();
57339 + cred = __task_cred(task);
57340 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
57341 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57342 + spin_lock(&gr_uid_lock);
57343 + gr_insert_uid(cred->uid, curr->expires);
57344 + spin_unlock(&gr_uid_lock);
57345 + curr->expires = 0;
57346 + curr->crashes = 0;
57347 + read_lock(&tasklist_lock);
57348 + do_each_thread(tsk2, tsk) {
57349 + cred2 = __task_cred(tsk);
57350 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
57351 + gr_fake_force_sig(SIGKILL, tsk);
57352 + } while_each_thread(tsk2, tsk);
57353 + read_unlock(&tasklist_lock);
57354 + } else {
57355 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57356 + read_lock(&tasklist_lock);
57357 + read_lock(&grsec_exec_file_lock);
57358 + do_each_thread(tsk2, tsk) {
57359 + if (likely(tsk != task)) {
57360 + // if this thread has the same subject as the one that triggered
57361 + // RES_CRASH and it's the same binary, kill it
57362 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
57363 + gr_fake_force_sig(SIGKILL, tsk);
57364 + }
57365 + } while_each_thread(tsk2, tsk);
57366 + read_unlock(&grsec_exec_file_lock);
57367 + read_unlock(&tasklist_lock);
57368 + }
57369 + rcu_read_unlock();
57370 + }
57371 +
57372 + return;
57373 +}
57374 +
57375 +int
57376 +gr_check_crash_exec(const struct file *filp)
57377 +{
57378 + struct acl_subject_label *curr;
57379 +
57380 + if (unlikely(!gr_acl_is_enabled()))
57381 + return 0;
57382 +
57383 + read_lock(&gr_inode_lock);
57384 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
57385 + __get_dev(filp->f_path.dentry),
57386 + current->role);
57387 + read_unlock(&gr_inode_lock);
57388 +
57389 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
57390 + (!curr->crashes && !curr->expires))
57391 + return 0;
57392 +
57393 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57394 + time_after(curr->expires, get_seconds()))
57395 + return 1;
57396 + else if (time_before_eq(curr->expires, get_seconds())) {
57397 + curr->crashes = 0;
57398 + curr->expires = 0;
57399 + }
57400 +
57401 + return 0;
57402 +}
57403 +
57404 +void
57405 +gr_handle_alertkill(struct task_struct *task)
57406 +{
57407 + struct acl_subject_label *curracl;
57408 + __u32 curr_ip;
57409 + struct task_struct *p, *p2;
57410 +
57411 + if (unlikely(!gr_acl_is_enabled()))
57412 + return;
57413 +
57414 + curracl = task->acl;
57415 + curr_ip = task->signal->curr_ip;
57416 +
57417 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
57418 + read_lock(&tasklist_lock);
57419 + do_each_thread(p2, p) {
57420 + if (p->signal->curr_ip == curr_ip)
57421 + gr_fake_force_sig(SIGKILL, p);
57422 + } while_each_thread(p2, p);
57423 + read_unlock(&tasklist_lock);
57424 + } else if (curracl->mode & GR_KILLPROC)
57425 + gr_fake_force_sig(SIGKILL, task);
57426 +
57427 + return;
57428 +}
57429 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
57430 new file mode 100644
57431 index 0000000..9d83a69
57432 --- /dev/null
57433 +++ b/grsecurity/gracl_shm.c
57434 @@ -0,0 +1,40 @@
57435 +#include <linux/kernel.h>
57436 +#include <linux/mm.h>
57437 +#include <linux/sched.h>
57438 +#include <linux/file.h>
57439 +#include <linux/ipc.h>
57440 +#include <linux/gracl.h>
57441 +#include <linux/grsecurity.h>
57442 +#include <linux/grinternal.h>
57443 +
57444 +int
57445 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57446 + const time_t shm_createtime, const uid_t cuid, const int shmid)
57447 +{
57448 + struct task_struct *task;
57449 +
57450 + if (!gr_acl_is_enabled())
57451 + return 1;
57452 +
57453 + rcu_read_lock();
57454 + read_lock(&tasklist_lock);
57455 +
57456 + task = find_task_by_vpid(shm_cprid);
57457 +
57458 + if (unlikely(!task))
57459 + task = find_task_by_vpid(shm_lapid);
57460 +
57461 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
57462 + (task->pid == shm_lapid)) &&
57463 + (task->acl->mode & GR_PROTSHM) &&
57464 + (task->acl != current->acl))) {
57465 + read_unlock(&tasklist_lock);
57466 + rcu_read_unlock();
57467 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
57468 + return 0;
57469 + }
57470 + read_unlock(&tasklist_lock);
57471 + rcu_read_unlock();
57472 +
57473 + return 1;
57474 +}
57475 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
57476 new file mode 100644
57477 index 0000000..bc0be01
57478 --- /dev/null
57479 +++ b/grsecurity/grsec_chdir.c
57480 @@ -0,0 +1,19 @@
57481 +#include <linux/kernel.h>
57482 +#include <linux/sched.h>
57483 +#include <linux/fs.h>
57484 +#include <linux/file.h>
57485 +#include <linux/grsecurity.h>
57486 +#include <linux/grinternal.h>
57487 +
57488 +void
57489 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
57490 +{
57491 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57492 + if ((grsec_enable_chdir && grsec_enable_group &&
57493 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
57494 + !grsec_enable_group)) {
57495 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
57496 + }
57497 +#endif
57498 + return;
57499 +}
57500 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
57501 new file mode 100644
57502 index 0000000..9807ee2
57503 --- /dev/null
57504 +++ b/grsecurity/grsec_chroot.c
57505 @@ -0,0 +1,368 @@
57506 +#include <linux/kernel.h>
57507 +#include <linux/module.h>
57508 +#include <linux/sched.h>
57509 +#include <linux/file.h>
57510 +#include <linux/fs.h>
57511 +#include <linux/mount.h>
57512 +#include <linux/types.h>
57513 +#include "../fs/mount.h"
57514 +#include <linux/grsecurity.h>
57515 +#include <linux/grinternal.h>
57516 +
57517 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
57518 +{
57519 +#ifdef CONFIG_GRKERNSEC
57520 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
57521 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
57522 + task->gr_is_chrooted = 1;
57523 + else
57524 + task->gr_is_chrooted = 0;
57525 +
57526 + task->gr_chroot_dentry = path->dentry;
57527 +#endif
57528 + return;
57529 +}
57530 +
57531 +void gr_clear_chroot_entries(struct task_struct *task)
57532 +{
57533 +#ifdef CONFIG_GRKERNSEC
57534 + task->gr_is_chrooted = 0;
57535 + task->gr_chroot_dentry = NULL;
57536 +#endif
57537 + return;
57538 +}
57539 +
57540 +int
57541 +gr_handle_chroot_unix(const pid_t pid)
57542 +{
57543 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57544 + struct task_struct *p;
57545 +
57546 + if (unlikely(!grsec_enable_chroot_unix))
57547 + return 1;
57548 +
57549 + if (likely(!proc_is_chrooted(current)))
57550 + return 1;
57551 +
57552 + rcu_read_lock();
57553 + read_lock(&tasklist_lock);
57554 + p = find_task_by_vpid_unrestricted(pid);
57555 + if (unlikely(p && !have_same_root(current, p))) {
57556 + read_unlock(&tasklist_lock);
57557 + rcu_read_unlock();
57558 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
57559 + return 0;
57560 + }
57561 + read_unlock(&tasklist_lock);
57562 + rcu_read_unlock();
57563 +#endif
57564 + return 1;
57565 +}
57566 +
57567 +int
57568 +gr_handle_chroot_nice(void)
57569 +{
57570 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57571 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
57572 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
57573 + return -EPERM;
57574 + }
57575 +#endif
57576 + return 0;
57577 +}
57578 +
57579 +int
57580 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
57581 +{
57582 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57583 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
57584 + && proc_is_chrooted(current)) {
57585 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
57586 + return -EACCES;
57587 + }
57588 +#endif
57589 + return 0;
57590 +}
57591 +
57592 +int
57593 +gr_handle_chroot_rawio(const struct inode *inode)
57594 +{
57595 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57596 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
57597 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
57598 + return 1;
57599 +#endif
57600 + return 0;
57601 +}
57602 +
57603 +int
57604 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
57605 +{
57606 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57607 + struct task_struct *p;
57608 + int ret = 0;
57609 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
57610 + return ret;
57611 +
57612 + read_lock(&tasklist_lock);
57613 + do_each_pid_task(pid, type, p) {
57614 + if (!have_same_root(current, p)) {
57615 + ret = 1;
57616 + goto out;
57617 + }
57618 + } while_each_pid_task(pid, type, p);
57619 +out:
57620 + read_unlock(&tasklist_lock);
57621 + return ret;
57622 +#endif
57623 + return 0;
57624 +}
57625 +
57626 +int
57627 +gr_pid_is_chrooted(struct task_struct *p)
57628 +{
57629 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57630 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
57631 + return 0;
57632 +
57633 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
57634 + !have_same_root(current, p)) {
57635 + return 1;
57636 + }
57637 +#endif
57638 + return 0;
57639 +}
57640 +
57641 +EXPORT_SYMBOL(gr_pid_is_chrooted);
57642 +
57643 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
57644 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
57645 +{
57646 + struct path path, currentroot;
57647 + int ret = 0;
57648 +
57649 + path.dentry = (struct dentry *)u_dentry;
57650 + path.mnt = (struct vfsmount *)u_mnt;
57651 + get_fs_root(current->fs, &currentroot);
57652 + if (path_is_under(&path, &currentroot))
57653 + ret = 1;
57654 + path_put(&currentroot);
57655 +
57656 + return ret;
57657 +}
57658 +#endif
57659 +
57660 +int
57661 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
57662 +{
57663 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57664 + if (!grsec_enable_chroot_fchdir)
57665 + return 1;
57666 +
57667 + if (!proc_is_chrooted(current))
57668 + return 1;
57669 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
57670 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
57671 + return 0;
57672 + }
57673 +#endif
57674 + return 1;
57675 +}
57676 +
57677 +int
57678 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57679 + const time_t shm_createtime)
57680 +{
57681 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57682 + struct task_struct *p;
57683 + time_t starttime;
57684 +
57685 + if (unlikely(!grsec_enable_chroot_shmat))
57686 + return 1;
57687 +
57688 + if (likely(!proc_is_chrooted(current)))
57689 + return 1;
57690 +
57691 + rcu_read_lock();
57692 + read_lock(&tasklist_lock);
57693 +
57694 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
57695 + starttime = p->start_time.tv_sec;
57696 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
57697 + if (have_same_root(current, p)) {
57698 + goto allow;
57699 + } else {
57700 + read_unlock(&tasklist_lock);
57701 + rcu_read_unlock();
57702 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57703 + return 0;
57704 + }
57705 + }
57706 + /* creator exited, pid reuse, fall through to next check */
57707 + }
57708 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
57709 + if (unlikely(!have_same_root(current, p))) {
57710 + read_unlock(&tasklist_lock);
57711 + rcu_read_unlock();
57712 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57713 + return 0;
57714 + }
57715 + }
57716 +
57717 +allow:
57718 + read_unlock(&tasklist_lock);
57719 + rcu_read_unlock();
57720 +#endif
57721 + return 1;
57722 +}
57723 +
57724 +void
57725 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
57726 +{
57727 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57728 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
57729 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
57730 +#endif
57731 + return;
57732 +}
57733 +
57734 +int
57735 +gr_handle_chroot_mknod(const struct dentry *dentry,
57736 + const struct vfsmount *mnt, const int mode)
57737 +{
57738 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57739 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
57740 + proc_is_chrooted(current)) {
57741 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
57742 + return -EPERM;
57743 + }
57744 +#endif
57745 + return 0;
57746 +}
57747 +
57748 +int
57749 +gr_handle_chroot_mount(const struct dentry *dentry,
57750 + const struct vfsmount *mnt, const char *dev_name)
57751 +{
57752 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57753 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
57754 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
57755 + return -EPERM;
57756 + }
57757 +#endif
57758 + return 0;
57759 +}
57760 +
57761 +int
57762 +gr_handle_chroot_pivot(void)
57763 +{
57764 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57765 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
57766 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
57767 + return -EPERM;
57768 + }
57769 +#endif
57770 + return 0;
57771 +}
57772 +
57773 +int
57774 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
57775 +{
57776 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57777 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
57778 + !gr_is_outside_chroot(dentry, mnt)) {
57779 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
57780 + return -EPERM;
57781 + }
57782 +#endif
57783 + return 0;
57784 +}
57785 +
57786 +extern const char *captab_log[];
57787 +extern int captab_log_entries;
57788 +
57789 +int
57790 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57791 +{
57792 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57793 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57794 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57795 + if (cap_raised(chroot_caps, cap)) {
57796 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
57797 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
57798 + }
57799 + return 0;
57800 + }
57801 + }
57802 +#endif
57803 + return 1;
57804 +}
57805 +
57806 +int
57807 +gr_chroot_is_capable(const int cap)
57808 +{
57809 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57810 + return gr_task_chroot_is_capable(current, current_cred(), cap);
57811 +#endif
57812 + return 1;
57813 +}
57814 +
57815 +int
57816 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
57817 +{
57818 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57819 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57820 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57821 + if (cap_raised(chroot_caps, cap)) {
57822 + return 0;
57823 + }
57824 + }
57825 +#endif
57826 + return 1;
57827 +}
57828 +
57829 +int
57830 +gr_chroot_is_capable_nolog(const int cap)
57831 +{
57832 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57833 + return gr_task_chroot_is_capable_nolog(current, cap);
57834 +#endif
57835 + return 1;
57836 +}
57837 +
57838 +int
57839 +gr_handle_chroot_sysctl(const int op)
57840 +{
57841 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57842 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
57843 + proc_is_chrooted(current))
57844 + return -EACCES;
57845 +#endif
57846 + return 0;
57847 +}
57848 +
57849 +void
57850 +gr_handle_chroot_chdir(struct path *path)
57851 +{
57852 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57853 + if (grsec_enable_chroot_chdir)
57854 + set_fs_pwd(current->fs, path);
57855 +#endif
57856 + return;
57857 +}
57858 +
57859 +int
57860 +gr_handle_chroot_chmod(const struct dentry *dentry,
57861 + const struct vfsmount *mnt, const int mode)
57862 +{
57863 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57864 + /* allow chmod +s on directories, but not files */
57865 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
57866 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
57867 + proc_is_chrooted(current)) {
57868 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
57869 + return -EPERM;
57870 + }
57871 +#endif
57872 + return 0;
57873 +}
57874 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
57875 new file mode 100644
57876 index 0000000..213ad8b
57877 --- /dev/null
57878 +++ b/grsecurity/grsec_disabled.c
57879 @@ -0,0 +1,437 @@
57880 +#include <linux/kernel.h>
57881 +#include <linux/module.h>
57882 +#include <linux/sched.h>
57883 +#include <linux/file.h>
57884 +#include <linux/fs.h>
57885 +#include <linux/kdev_t.h>
57886 +#include <linux/net.h>
57887 +#include <linux/in.h>
57888 +#include <linux/ip.h>
57889 +#include <linux/skbuff.h>
57890 +#include <linux/sysctl.h>
57891 +
57892 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57893 +void
57894 +pax_set_initial_flags(struct linux_binprm *bprm)
57895 +{
57896 + return;
57897 +}
57898 +#endif
57899 +
57900 +#ifdef CONFIG_SYSCTL
57901 +__u32
57902 +gr_handle_sysctl(const struct ctl_table * table, const int op)
57903 +{
57904 + return 0;
57905 +}
57906 +#endif
57907 +
57908 +#ifdef CONFIG_TASKSTATS
57909 +int gr_is_taskstats_denied(int pid)
57910 +{
57911 + return 0;
57912 +}
57913 +#endif
57914 +
57915 +int
57916 +gr_acl_is_enabled(void)
57917 +{
57918 + return 0;
57919 +}
57920 +
57921 +void
57922 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
57923 +{
57924 + return;
57925 +}
57926 +
57927 +int
57928 +gr_handle_rawio(const struct inode *inode)
57929 +{
57930 + return 0;
57931 +}
57932 +
57933 +void
57934 +gr_acl_handle_psacct(struct task_struct *task, const long code)
57935 +{
57936 + return;
57937 +}
57938 +
57939 +int
57940 +gr_handle_ptrace(struct task_struct *task, const long request)
57941 +{
57942 + return 0;
57943 +}
57944 +
57945 +int
57946 +gr_handle_proc_ptrace(struct task_struct *task)
57947 +{
57948 + return 0;
57949 +}
57950 +
57951 +void
57952 +gr_learn_resource(const struct task_struct *task,
57953 + const int res, const unsigned long wanted, const int gt)
57954 +{
57955 + return;
57956 +}
57957 +
57958 +int
57959 +gr_set_acls(const int type)
57960 +{
57961 + return 0;
57962 +}
57963 +
57964 +int
57965 +gr_check_hidden_task(const struct task_struct *tsk)
57966 +{
57967 + return 0;
57968 +}
57969 +
57970 +int
57971 +gr_check_protected_task(const struct task_struct *task)
57972 +{
57973 + return 0;
57974 +}
57975 +
57976 +int
57977 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
57978 +{
57979 + return 0;
57980 +}
57981 +
57982 +void
57983 +gr_copy_label(struct task_struct *tsk)
57984 +{
57985 + return;
57986 +}
57987 +
57988 +void
57989 +gr_set_pax_flags(struct task_struct *task)
57990 +{
57991 + return;
57992 +}
57993 +
57994 +int
57995 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
57996 + const int unsafe_share)
57997 +{
57998 + return 0;
57999 +}
58000 +
58001 +void
58002 +gr_handle_delete(const ino_t ino, const dev_t dev)
58003 +{
58004 + return;
58005 +}
58006 +
58007 +void
58008 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
58009 +{
58010 + return;
58011 +}
58012 +
58013 +void
58014 +gr_handle_crash(struct task_struct *task, const int sig)
58015 +{
58016 + return;
58017 +}
58018 +
58019 +int
58020 +gr_check_crash_exec(const struct file *filp)
58021 +{
58022 + return 0;
58023 +}
58024 +
58025 +int
58026 +gr_check_crash_uid(const uid_t uid)
58027 +{
58028 + return 0;
58029 +}
58030 +
58031 +void
58032 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
58033 + struct dentry *old_dentry,
58034 + struct dentry *new_dentry,
58035 + struct vfsmount *mnt, const __u8 replace)
58036 +{
58037 + return;
58038 +}
58039 +
58040 +int
58041 +gr_search_socket(const int family, const int type, const int protocol)
58042 +{
58043 + return 1;
58044 +}
58045 +
58046 +int
58047 +gr_search_connectbind(const int mode, const struct socket *sock,
58048 + const struct sockaddr_in *addr)
58049 +{
58050 + return 0;
58051 +}
58052 +
58053 +void
58054 +gr_handle_alertkill(struct task_struct *task)
58055 +{
58056 + return;
58057 +}
58058 +
58059 +__u32
58060 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
58061 +{
58062 + return 1;
58063 +}
58064 +
58065 +__u32
58066 +gr_acl_handle_hidden_file(const struct dentry * dentry,
58067 + const struct vfsmount * mnt)
58068 +{
58069 + return 1;
58070 +}
58071 +
58072 +__u32
58073 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
58074 + int acc_mode)
58075 +{
58076 + return 1;
58077 +}
58078 +
58079 +__u32
58080 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
58081 +{
58082 + return 1;
58083 +}
58084 +
58085 +__u32
58086 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
58087 +{
58088 + return 1;
58089 +}
58090 +
58091 +int
58092 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
58093 + unsigned int *vm_flags)
58094 +{
58095 + return 1;
58096 +}
58097 +
58098 +__u32
58099 +gr_acl_handle_truncate(const struct dentry * dentry,
58100 + const struct vfsmount * mnt)
58101 +{
58102 + return 1;
58103 +}
58104 +
58105 +__u32
58106 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
58107 +{
58108 + return 1;
58109 +}
58110 +
58111 +__u32
58112 +gr_acl_handle_access(const struct dentry * dentry,
58113 + const struct vfsmount * mnt, const int fmode)
58114 +{
58115 + return 1;
58116 +}
58117 +
58118 +__u32
58119 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
58120 + umode_t *mode)
58121 +{
58122 + return 1;
58123 +}
58124 +
58125 +__u32
58126 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
58127 +{
58128 + return 1;
58129 +}
58130 +
58131 +__u32
58132 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
58133 +{
58134 + return 1;
58135 +}
58136 +
58137 +void
58138 +grsecurity_init(void)
58139 +{
58140 + return;
58141 +}
58142 +
58143 +umode_t gr_acl_umask(void)
58144 +{
58145 + return 0;
58146 +}
58147 +
58148 +__u32
58149 +gr_acl_handle_mknod(const struct dentry * new_dentry,
58150 + const struct dentry * parent_dentry,
58151 + const struct vfsmount * parent_mnt,
58152 + const int mode)
58153 +{
58154 + return 1;
58155 +}
58156 +
58157 +__u32
58158 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
58159 + const struct dentry * parent_dentry,
58160 + const struct vfsmount * parent_mnt)
58161 +{
58162 + return 1;
58163 +}
58164 +
58165 +__u32
58166 +gr_acl_handle_symlink(const struct dentry * new_dentry,
58167 + const struct dentry * parent_dentry,
58168 + const struct vfsmount * parent_mnt, const char *from)
58169 +{
58170 + return 1;
58171 +}
58172 +
58173 +__u32
58174 +gr_acl_handle_link(const struct dentry * new_dentry,
58175 + const struct dentry * parent_dentry,
58176 + const struct vfsmount * parent_mnt,
58177 + const struct dentry * old_dentry,
58178 + const struct vfsmount * old_mnt, const char *to)
58179 +{
58180 + return 1;
58181 +}
58182 +
58183 +int
58184 +gr_acl_handle_rename(const struct dentry *new_dentry,
58185 + const struct dentry *parent_dentry,
58186 + const struct vfsmount *parent_mnt,
58187 + const struct dentry *old_dentry,
58188 + const struct inode *old_parent_inode,
58189 + const struct vfsmount *old_mnt, const char *newname)
58190 +{
58191 + return 0;
58192 +}
58193 +
58194 +int
58195 +gr_acl_handle_filldir(const struct file *file, const char *name,
58196 + const int namelen, const ino_t ino)
58197 +{
58198 + return 1;
58199 +}
58200 +
58201 +int
58202 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
58203 + const time_t shm_createtime, const uid_t cuid, const int shmid)
58204 +{
58205 + return 1;
58206 +}
58207 +
58208 +int
58209 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
58210 +{
58211 + return 0;
58212 +}
58213 +
58214 +int
58215 +gr_search_accept(const struct socket *sock)
58216 +{
58217 + return 0;
58218 +}
58219 +
58220 +int
58221 +gr_search_listen(const struct socket *sock)
58222 +{
58223 + return 0;
58224 +}
58225 +
58226 +int
58227 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
58228 +{
58229 + return 0;
58230 +}
58231 +
58232 +__u32
58233 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
58234 +{
58235 + return 1;
58236 +}
58237 +
58238 +__u32
58239 +gr_acl_handle_creat(const struct dentry * dentry,
58240 + const struct dentry * p_dentry,
58241 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
58242 + const int imode)
58243 +{
58244 + return 1;
58245 +}
58246 +
58247 +void
58248 +gr_acl_handle_exit(void)
58249 +{
58250 + return;
58251 +}
58252 +
58253 +int
58254 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
58255 +{
58256 + return 1;
58257 +}
58258 +
58259 +void
58260 +gr_set_role_label(const uid_t uid, const gid_t gid)
58261 +{
58262 + return;
58263 +}
58264 +
58265 +int
58266 +gr_acl_handle_procpidmem(const struct task_struct *task)
58267 +{
58268 + return 0;
58269 +}
58270 +
58271 +int
58272 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
58273 +{
58274 + return 0;
58275 +}
58276 +
58277 +int
58278 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
58279 +{
58280 + return 0;
58281 +}
58282 +
58283 +void
58284 +gr_set_kernel_label(struct task_struct *task)
58285 +{
58286 + return;
58287 +}
58288 +
58289 +int
58290 +gr_check_user_change(int real, int effective, int fs)
58291 +{
58292 + return 0;
58293 +}
58294 +
58295 +int
58296 +gr_check_group_change(int real, int effective, int fs)
58297 +{
58298 + return 0;
58299 +}
58300 +
58301 +int gr_acl_enable_at_secure(void)
58302 +{
58303 + return 0;
58304 +}
58305 +
58306 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
58307 +{
58308 + return dentry->d_inode->i_sb->s_dev;
58309 +}
58310 +
58311 +EXPORT_SYMBOL(gr_learn_resource);
58312 +EXPORT_SYMBOL(gr_set_kernel_label);
58313 +#ifdef CONFIG_SECURITY
58314 +EXPORT_SYMBOL(gr_check_user_change);
58315 +EXPORT_SYMBOL(gr_check_group_change);
58316 +#endif
58317 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
58318 new file mode 100644
58319 index 0000000..abfa971
58320 --- /dev/null
58321 +++ b/grsecurity/grsec_exec.c
58322 @@ -0,0 +1,174 @@
58323 +#include <linux/kernel.h>
58324 +#include <linux/sched.h>
58325 +#include <linux/file.h>
58326 +#include <linux/binfmts.h>
58327 +#include <linux/fs.h>
58328 +#include <linux/types.h>
58329 +#include <linux/grdefs.h>
58330 +#include <linux/grsecurity.h>
58331 +#include <linux/grinternal.h>
58332 +#include <linux/capability.h>
58333 +#include <linux/module.h>
58334 +
58335 +#include <asm/uaccess.h>
58336 +
58337 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58338 +static char gr_exec_arg_buf[132];
58339 +static DEFINE_MUTEX(gr_exec_arg_mutex);
58340 +#endif
58341 +
58342 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
58343 +
58344 +void
58345 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
58346 +{
58347 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58348 + char *grarg = gr_exec_arg_buf;
58349 + unsigned int i, x, execlen = 0;
58350 + char c;
58351 +
58352 + if (!((grsec_enable_execlog && grsec_enable_group &&
58353 + in_group_p(grsec_audit_gid))
58354 + || (grsec_enable_execlog && !grsec_enable_group)))
58355 + return;
58356 +
58357 + mutex_lock(&gr_exec_arg_mutex);
58358 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
58359 +
58360 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
58361 + const char __user *p;
58362 + unsigned int len;
58363 +
58364 + p = get_user_arg_ptr(argv, i);
58365 + if (IS_ERR(p))
58366 + goto log;
58367 +
58368 + len = strnlen_user(p, 128 - execlen);
58369 + if (len > 128 - execlen)
58370 + len = 128 - execlen;
58371 + else if (len > 0)
58372 + len--;
58373 + if (copy_from_user(grarg + execlen, p, len))
58374 + goto log;
58375 +
58376 + /* rewrite unprintable characters */
58377 + for (x = 0; x < len; x++) {
58378 + c = *(grarg + execlen + x);
58379 + if (c < 32 || c > 126)
58380 + *(grarg + execlen + x) = ' ';
58381 + }
58382 +
58383 + execlen += len;
58384 + *(grarg + execlen) = ' ';
58385 + *(grarg + execlen + 1) = '\0';
58386 + execlen++;
58387 + }
58388 +
58389 + log:
58390 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
58391 + bprm->file->f_path.mnt, grarg);
58392 + mutex_unlock(&gr_exec_arg_mutex);
58393 +#endif
58394 + return;
58395 +}
58396 +
58397 +#ifdef CONFIG_GRKERNSEC
58398 +extern int gr_acl_is_capable(const int cap);
58399 +extern int gr_acl_is_capable_nolog(const int cap);
58400 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58401 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
58402 +extern int gr_chroot_is_capable(const int cap);
58403 +extern int gr_chroot_is_capable_nolog(const int cap);
58404 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58405 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
58406 +#endif
58407 +
58408 +const char *captab_log[] = {
58409 + "CAP_CHOWN",
58410 + "CAP_DAC_OVERRIDE",
58411 + "CAP_DAC_READ_SEARCH",
58412 + "CAP_FOWNER",
58413 + "CAP_FSETID",
58414 + "CAP_KILL",
58415 + "CAP_SETGID",
58416 + "CAP_SETUID",
58417 + "CAP_SETPCAP",
58418 + "CAP_LINUX_IMMUTABLE",
58419 + "CAP_NET_BIND_SERVICE",
58420 + "CAP_NET_BROADCAST",
58421 + "CAP_NET_ADMIN",
58422 + "CAP_NET_RAW",
58423 + "CAP_IPC_LOCK",
58424 + "CAP_IPC_OWNER",
58425 + "CAP_SYS_MODULE",
58426 + "CAP_SYS_RAWIO",
58427 + "CAP_SYS_CHROOT",
58428 + "CAP_SYS_PTRACE",
58429 + "CAP_SYS_PACCT",
58430 + "CAP_SYS_ADMIN",
58431 + "CAP_SYS_BOOT",
58432 + "CAP_SYS_NICE",
58433 + "CAP_SYS_RESOURCE",
58434 + "CAP_SYS_TIME",
58435 + "CAP_SYS_TTY_CONFIG",
58436 + "CAP_MKNOD",
58437 + "CAP_LEASE",
58438 + "CAP_AUDIT_WRITE",
58439 + "CAP_AUDIT_CONTROL",
58440 + "CAP_SETFCAP",
58441 + "CAP_MAC_OVERRIDE",
58442 + "CAP_MAC_ADMIN",
58443 + "CAP_SYSLOG",
58444 + "CAP_WAKE_ALARM"
58445 +};
58446 +
58447 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
58448 +
58449 +int gr_is_capable(const int cap)
58450 +{
58451 +#ifdef CONFIG_GRKERNSEC
58452 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
58453 + return 1;
58454 + return 0;
58455 +#else
58456 + return 1;
58457 +#endif
58458 +}
58459 +
58460 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
58461 +{
58462 +#ifdef CONFIG_GRKERNSEC
58463 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
58464 + return 1;
58465 + return 0;
58466 +#else
58467 + return 1;
58468 +#endif
58469 +}
58470 +
58471 +int gr_is_capable_nolog(const int cap)
58472 +{
58473 +#ifdef CONFIG_GRKERNSEC
58474 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
58475 + return 1;
58476 + return 0;
58477 +#else
58478 + return 1;
58479 +#endif
58480 +}
58481 +
58482 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
58483 +{
58484 +#ifdef CONFIG_GRKERNSEC
58485 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
58486 + return 1;
58487 + return 0;
58488 +#else
58489 + return 1;
58490 +#endif
58491 +}
58492 +
58493 +EXPORT_SYMBOL(gr_is_capable);
58494 +EXPORT_SYMBOL(gr_is_capable_nolog);
58495 +EXPORT_SYMBOL(gr_task_is_capable);
58496 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
58497 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
58498 new file mode 100644
58499 index 0000000..d3ee748
58500 --- /dev/null
58501 +++ b/grsecurity/grsec_fifo.c
58502 @@ -0,0 +1,24 @@
58503 +#include <linux/kernel.h>
58504 +#include <linux/sched.h>
58505 +#include <linux/fs.h>
58506 +#include <linux/file.h>
58507 +#include <linux/grinternal.h>
58508 +
58509 +int
58510 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
58511 + const struct dentry *dir, const int flag, const int acc_mode)
58512 +{
58513 +#ifdef CONFIG_GRKERNSEC_FIFO
58514 + const struct cred *cred = current_cred();
58515 +
58516 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
58517 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
58518 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
58519 + (cred->fsuid != dentry->d_inode->i_uid)) {
58520 + if (!inode_permission(dentry->d_inode, acc_mode))
58521 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
58522 + return -EACCES;
58523 + }
58524 +#endif
58525 + return 0;
58526 +}
58527 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
58528 new file mode 100644
58529 index 0000000..8ca18bf
58530 --- /dev/null
58531 +++ b/grsecurity/grsec_fork.c
58532 @@ -0,0 +1,23 @@
58533 +#include <linux/kernel.h>
58534 +#include <linux/sched.h>
58535 +#include <linux/grsecurity.h>
58536 +#include <linux/grinternal.h>
58537 +#include <linux/errno.h>
58538 +
58539 +void
58540 +gr_log_forkfail(const int retval)
58541 +{
58542 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58543 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
58544 + switch (retval) {
58545 + case -EAGAIN:
58546 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
58547 + break;
58548 + case -ENOMEM:
58549 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
58550 + break;
58551 + }
58552 + }
58553 +#endif
58554 + return;
58555 +}
58556 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
58557 new file mode 100644
58558 index 0000000..05a6015
58559 --- /dev/null
58560 +++ b/grsecurity/grsec_init.c
58561 @@ -0,0 +1,283 @@
58562 +#include <linux/kernel.h>
58563 +#include <linux/sched.h>
58564 +#include <linux/mm.h>
58565 +#include <linux/gracl.h>
58566 +#include <linux/slab.h>
58567 +#include <linux/vmalloc.h>
58568 +#include <linux/percpu.h>
58569 +#include <linux/module.h>
58570 +
58571 +int grsec_enable_ptrace_readexec;
58572 +int grsec_enable_setxid;
58573 +int grsec_enable_symlinkown;
58574 +int grsec_symlinkown_gid;
58575 +int grsec_enable_brute;
58576 +int grsec_enable_link;
58577 +int grsec_enable_dmesg;
58578 +int grsec_enable_harden_ptrace;
58579 +int grsec_enable_fifo;
58580 +int grsec_enable_execlog;
58581 +int grsec_enable_signal;
58582 +int grsec_enable_forkfail;
58583 +int grsec_enable_audit_ptrace;
58584 +int grsec_enable_time;
58585 +int grsec_enable_audit_textrel;
58586 +int grsec_enable_group;
58587 +int grsec_audit_gid;
58588 +int grsec_enable_chdir;
58589 +int grsec_enable_mount;
58590 +int grsec_enable_rofs;
58591 +int grsec_enable_chroot_findtask;
58592 +int grsec_enable_chroot_mount;
58593 +int grsec_enable_chroot_shmat;
58594 +int grsec_enable_chroot_fchdir;
58595 +int grsec_enable_chroot_double;
58596 +int grsec_enable_chroot_pivot;
58597 +int grsec_enable_chroot_chdir;
58598 +int grsec_enable_chroot_chmod;
58599 +int grsec_enable_chroot_mknod;
58600 +int grsec_enable_chroot_nice;
58601 +int grsec_enable_chroot_execlog;
58602 +int grsec_enable_chroot_caps;
58603 +int grsec_enable_chroot_sysctl;
58604 +int grsec_enable_chroot_unix;
58605 +int grsec_enable_tpe;
58606 +int grsec_tpe_gid;
58607 +int grsec_enable_blackhole;
58608 +#ifdef CONFIG_IPV6_MODULE
58609 +EXPORT_SYMBOL(grsec_enable_blackhole);
58610 +#endif
58611 +int grsec_lastack_retries;
58612 +int grsec_enable_tpe_all;
58613 +int grsec_enable_tpe_invert;
58614 +int grsec_enable_socket_all;
58615 +int grsec_socket_all_gid;
58616 +int grsec_enable_socket_client;
58617 +int grsec_socket_client_gid;
58618 +int grsec_enable_socket_server;
58619 +int grsec_socket_server_gid;
58620 +int grsec_resource_logging;
58621 +int grsec_disable_privio;
58622 +int grsec_enable_log_rwxmaps;
58623 +int grsec_lock;
58624 +
58625 +DEFINE_SPINLOCK(grsec_alert_lock);
58626 +unsigned long grsec_alert_wtime = 0;
58627 +unsigned long grsec_alert_fyet = 0;
58628 +
58629 +DEFINE_SPINLOCK(grsec_audit_lock);
58630 +
58631 +DEFINE_RWLOCK(grsec_exec_file_lock);
58632 +
58633 +char *gr_shared_page[4];
58634 +
58635 +char *gr_alert_log_fmt;
58636 +char *gr_audit_log_fmt;
58637 +char *gr_alert_log_buf;
58638 +char *gr_audit_log_buf;
58639 +
58640 +extern struct gr_arg *gr_usermode;
58641 +extern unsigned char *gr_system_salt;
58642 +extern unsigned char *gr_system_sum;
58643 +
58644 +void __init
58645 +grsecurity_init(void)
58646 +{
58647 + int j;
58648 + /* create the per-cpu shared pages */
58649 +
58650 +#ifdef CONFIG_X86
58651 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
58652 +#endif
58653 +
58654 + for (j = 0; j < 4; j++) {
58655 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
58656 + if (gr_shared_page[j] == NULL) {
58657 + panic("Unable to allocate grsecurity shared page");
58658 + return;
58659 + }
58660 + }
58661 +
58662 + /* allocate log buffers */
58663 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
58664 + if (!gr_alert_log_fmt) {
58665 + panic("Unable to allocate grsecurity alert log format buffer");
58666 + return;
58667 + }
58668 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
58669 + if (!gr_audit_log_fmt) {
58670 + panic("Unable to allocate grsecurity audit log format buffer");
58671 + return;
58672 + }
58673 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58674 + if (!gr_alert_log_buf) {
58675 + panic("Unable to allocate grsecurity alert log buffer");
58676 + return;
58677 + }
58678 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58679 + if (!gr_audit_log_buf) {
58680 + panic("Unable to allocate grsecurity audit log buffer");
58681 + return;
58682 + }
58683 +
58684 + /* allocate memory for authentication structure */
58685 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
58686 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
58687 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
58688 +
58689 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
58690 + panic("Unable to allocate grsecurity authentication structure");
58691 + return;
58692 + }
58693 +
58694 +
58695 +#ifdef CONFIG_GRKERNSEC_IO
58696 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
58697 + grsec_disable_privio = 1;
58698 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58699 + grsec_disable_privio = 1;
58700 +#else
58701 + grsec_disable_privio = 0;
58702 +#endif
58703 +#endif
58704 +
58705 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58706 + /* for backward compatibility, tpe_invert always defaults to on if
58707 + enabled in the kernel
58708 + */
58709 + grsec_enable_tpe_invert = 1;
58710 +#endif
58711 +
58712 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58713 +#ifndef CONFIG_GRKERNSEC_SYSCTL
58714 + grsec_lock = 1;
58715 +#endif
58716 +
58717 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58718 + grsec_enable_audit_textrel = 1;
58719 +#endif
58720 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58721 + grsec_enable_log_rwxmaps = 1;
58722 +#endif
58723 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
58724 + grsec_enable_group = 1;
58725 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
58726 +#endif
58727 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58728 + grsec_enable_ptrace_readexec = 1;
58729 +#endif
58730 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
58731 + grsec_enable_chdir = 1;
58732 +#endif
58733 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58734 + grsec_enable_harden_ptrace = 1;
58735 +#endif
58736 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58737 + grsec_enable_mount = 1;
58738 +#endif
58739 +#ifdef CONFIG_GRKERNSEC_LINK
58740 + grsec_enable_link = 1;
58741 +#endif
58742 +#ifdef CONFIG_GRKERNSEC_BRUTE
58743 + grsec_enable_brute = 1;
58744 +#endif
58745 +#ifdef CONFIG_GRKERNSEC_DMESG
58746 + grsec_enable_dmesg = 1;
58747 +#endif
58748 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58749 + grsec_enable_blackhole = 1;
58750 + grsec_lastack_retries = 4;
58751 +#endif
58752 +#ifdef CONFIG_GRKERNSEC_FIFO
58753 + grsec_enable_fifo = 1;
58754 +#endif
58755 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58756 + grsec_enable_execlog = 1;
58757 +#endif
58758 +#ifdef CONFIG_GRKERNSEC_SETXID
58759 + grsec_enable_setxid = 1;
58760 +#endif
58761 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58762 + grsec_enable_signal = 1;
58763 +#endif
58764 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58765 + grsec_enable_forkfail = 1;
58766 +#endif
58767 +#ifdef CONFIG_GRKERNSEC_TIME
58768 + grsec_enable_time = 1;
58769 +#endif
58770 +#ifdef CONFIG_GRKERNSEC_RESLOG
58771 + grsec_resource_logging = 1;
58772 +#endif
58773 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58774 + grsec_enable_chroot_findtask = 1;
58775 +#endif
58776 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
58777 + grsec_enable_chroot_unix = 1;
58778 +#endif
58779 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58780 + grsec_enable_chroot_mount = 1;
58781 +#endif
58782 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58783 + grsec_enable_chroot_fchdir = 1;
58784 +#endif
58785 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58786 + grsec_enable_chroot_shmat = 1;
58787 +#endif
58788 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58789 + grsec_enable_audit_ptrace = 1;
58790 +#endif
58791 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58792 + grsec_enable_chroot_double = 1;
58793 +#endif
58794 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58795 + grsec_enable_chroot_pivot = 1;
58796 +#endif
58797 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58798 + grsec_enable_chroot_chdir = 1;
58799 +#endif
58800 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58801 + grsec_enable_chroot_chmod = 1;
58802 +#endif
58803 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58804 + grsec_enable_chroot_mknod = 1;
58805 +#endif
58806 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58807 + grsec_enable_chroot_nice = 1;
58808 +#endif
58809 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58810 + grsec_enable_chroot_execlog = 1;
58811 +#endif
58812 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58813 + grsec_enable_chroot_caps = 1;
58814 +#endif
58815 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58816 + grsec_enable_chroot_sysctl = 1;
58817 +#endif
58818 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58819 + grsec_enable_symlinkown = 1;
58820 + grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
58821 +#endif
58822 +#ifdef CONFIG_GRKERNSEC_TPE
58823 + grsec_enable_tpe = 1;
58824 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
58825 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
58826 + grsec_enable_tpe_all = 1;
58827 +#endif
58828 +#endif
58829 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58830 + grsec_enable_socket_all = 1;
58831 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
58832 +#endif
58833 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58834 + grsec_enable_socket_client = 1;
58835 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
58836 +#endif
58837 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58838 + grsec_enable_socket_server = 1;
58839 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
58840 +#endif
58841 +#endif
58842 +
58843 + return;
58844 +}
58845 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
58846 new file mode 100644
58847 index 0000000..589481f
58848 --- /dev/null
58849 +++ b/grsecurity/grsec_link.c
58850 @@ -0,0 +1,58 @@
58851 +#include <linux/kernel.h>
58852 +#include <linux/sched.h>
58853 +#include <linux/fs.h>
58854 +#include <linux/file.h>
58855 +#include <linux/grinternal.h>
58856 +
58857 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
58858 +{
58859 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58860 + const struct inode *link_inode = link->dentry->d_inode;
58861 +
58862 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
58863 + /* ignore root-owned links, e.g. /proc/self */
58864 + !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
58865 + !uid_eq(link_inode->i_uid, target->i_uid)) {
58866 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
58867 + return 1;
58868 + }
58869 +#endif
58870 + return 0;
58871 +}
58872 +
58873 +int
58874 +gr_handle_follow_link(const struct inode *parent,
58875 + const struct inode *inode,
58876 + const struct dentry *dentry, const struct vfsmount *mnt)
58877 +{
58878 +#ifdef CONFIG_GRKERNSEC_LINK
58879 + const struct cred *cred = current_cred();
58880 +
58881 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
58882 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
58883 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
58884 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
58885 + return -EACCES;
58886 + }
58887 +#endif
58888 + return 0;
58889 +}
58890 +
58891 +int
58892 +gr_handle_hardlink(const struct dentry *dentry,
58893 + const struct vfsmount *mnt,
58894 + struct inode *inode, const int mode, const char *to)
58895 +{
58896 +#ifdef CONFIG_GRKERNSEC_LINK
58897 + const struct cred *cred = current_cred();
58898 +
58899 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
58900 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
58901 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
58902 + !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
58903 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
58904 + return -EPERM;
58905 + }
58906 +#endif
58907 + return 0;
58908 +}
58909 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
58910 new file mode 100644
58911 index 0000000..a45d2e9
58912 --- /dev/null
58913 +++ b/grsecurity/grsec_log.c
58914 @@ -0,0 +1,322 @@
58915 +#include <linux/kernel.h>
58916 +#include <linux/sched.h>
58917 +#include <linux/file.h>
58918 +#include <linux/tty.h>
58919 +#include <linux/fs.h>
58920 +#include <linux/grinternal.h>
58921 +
58922 +#ifdef CONFIG_TREE_PREEMPT_RCU
58923 +#define DISABLE_PREEMPT() preempt_disable()
58924 +#define ENABLE_PREEMPT() preempt_enable()
58925 +#else
58926 +#define DISABLE_PREEMPT()
58927 +#define ENABLE_PREEMPT()
58928 +#endif
58929 +
58930 +#define BEGIN_LOCKS(x) \
58931 + DISABLE_PREEMPT(); \
58932 + rcu_read_lock(); \
58933 + read_lock(&tasklist_lock); \
58934 + read_lock(&grsec_exec_file_lock); \
58935 + if (x != GR_DO_AUDIT) \
58936 + spin_lock(&grsec_alert_lock); \
58937 + else \
58938 + spin_lock(&grsec_audit_lock)
58939 +
58940 +#define END_LOCKS(x) \
58941 + if (x != GR_DO_AUDIT) \
58942 + spin_unlock(&grsec_alert_lock); \
58943 + else \
58944 + spin_unlock(&grsec_audit_lock); \
58945 + read_unlock(&grsec_exec_file_lock); \
58946 + read_unlock(&tasklist_lock); \
58947 + rcu_read_unlock(); \
58948 + ENABLE_PREEMPT(); \
58949 + if (x == GR_DONT_AUDIT) \
58950 + gr_handle_alertkill(current)
58951 +
58952 +enum {
58953 + FLOODING,
58954 + NO_FLOODING
58955 +};
58956 +
58957 +extern char *gr_alert_log_fmt;
58958 +extern char *gr_audit_log_fmt;
58959 +extern char *gr_alert_log_buf;
58960 +extern char *gr_audit_log_buf;
58961 +
58962 +static int gr_log_start(int audit)
58963 +{
58964 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
58965 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
58966 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58967 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
58968 + unsigned long curr_secs = get_seconds();
58969 +
58970 + if (audit == GR_DO_AUDIT)
58971 + goto set_fmt;
58972 +
58973 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
58974 + grsec_alert_wtime = curr_secs;
58975 + grsec_alert_fyet = 0;
58976 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
58977 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
58978 + grsec_alert_fyet++;
58979 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
58980 + grsec_alert_wtime = curr_secs;
58981 + grsec_alert_fyet++;
58982 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
58983 + return FLOODING;
58984 + }
58985 + else return FLOODING;
58986 +
58987 +set_fmt:
58988 +#endif
58989 + memset(buf, 0, PAGE_SIZE);
58990 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
58991 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
58992 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58993 + } else if (current->signal->curr_ip) {
58994 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
58995 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
58996 + } else if (gr_acl_is_enabled()) {
58997 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
58998 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58999 + } else {
59000 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
59001 + strcpy(buf, fmt);
59002 + }
59003 +
59004 + return NO_FLOODING;
59005 +}
59006 +
59007 +static void gr_log_middle(int audit, const char *msg, va_list ap)
59008 + __attribute__ ((format (printf, 2, 0)));
59009 +
59010 +static void gr_log_middle(int audit, const char *msg, va_list ap)
59011 +{
59012 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59013 + unsigned int len = strlen(buf);
59014 +
59015 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
59016 +
59017 + return;
59018 +}
59019 +
59020 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
59021 + __attribute__ ((format (printf, 2, 3)));
59022 +
59023 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
59024 +{
59025 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59026 + unsigned int len = strlen(buf);
59027 + va_list ap;
59028 +
59029 + va_start(ap, msg);
59030 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
59031 + va_end(ap);
59032 +
59033 + return;
59034 +}
59035 +
59036 +static void gr_log_end(int audit, int append_default)
59037 +{
59038 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59039 +
59040 + if (append_default) {
59041 + unsigned int len = strlen(buf);
59042 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
59043 + }
59044 +
59045 + printk("%s\n", buf);
59046 +
59047 + return;
59048 +}
59049 +
59050 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
59051 +{
59052 + int logtype;
59053 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
59054 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
59055 + void *voidptr = NULL;
59056 + int num1 = 0, num2 = 0;
59057 + unsigned long ulong1 = 0, ulong2 = 0;
59058 + struct dentry *dentry = NULL;
59059 + struct vfsmount *mnt = NULL;
59060 + struct file *file = NULL;
59061 + struct task_struct *task = NULL;
59062 + const struct cred *cred, *pcred;
59063 + va_list ap;
59064 +
59065 + BEGIN_LOCKS(audit);
59066 + logtype = gr_log_start(audit);
59067 + if (logtype == FLOODING) {
59068 + END_LOCKS(audit);
59069 + return;
59070 + }
59071 + va_start(ap, argtypes);
59072 + switch (argtypes) {
59073 + case GR_TTYSNIFF:
59074 + task = va_arg(ap, struct task_struct *);
59075 + 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);
59076 + break;
59077 + case GR_SYSCTL_HIDDEN:
59078 + str1 = va_arg(ap, char *);
59079 + gr_log_middle_varargs(audit, msg, result, str1);
59080 + break;
59081 + case GR_RBAC:
59082 + dentry = va_arg(ap, struct dentry *);
59083 + mnt = va_arg(ap, struct vfsmount *);
59084 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
59085 + break;
59086 + case GR_RBAC_STR:
59087 + dentry = va_arg(ap, struct dentry *);
59088 + mnt = va_arg(ap, struct vfsmount *);
59089 + str1 = va_arg(ap, char *);
59090 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
59091 + break;
59092 + case GR_STR_RBAC:
59093 + str1 = va_arg(ap, char *);
59094 + dentry = va_arg(ap, struct dentry *);
59095 + mnt = va_arg(ap, struct vfsmount *);
59096 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
59097 + break;
59098 + case GR_RBAC_MODE2:
59099 + dentry = va_arg(ap, struct dentry *);
59100 + mnt = va_arg(ap, struct vfsmount *);
59101 + str1 = va_arg(ap, char *);
59102 + str2 = va_arg(ap, char *);
59103 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
59104 + break;
59105 + case GR_RBAC_MODE3:
59106 + dentry = va_arg(ap, struct dentry *);
59107 + mnt = va_arg(ap, struct vfsmount *);
59108 + str1 = va_arg(ap, char *);
59109 + str2 = va_arg(ap, char *);
59110 + str3 = va_arg(ap, char *);
59111 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
59112 + break;
59113 + case GR_FILENAME:
59114 + dentry = va_arg(ap, struct dentry *);
59115 + mnt = va_arg(ap, struct vfsmount *);
59116 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
59117 + break;
59118 + case GR_STR_FILENAME:
59119 + str1 = va_arg(ap, char *);
59120 + dentry = va_arg(ap, struct dentry *);
59121 + mnt = va_arg(ap, struct vfsmount *);
59122 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
59123 + break;
59124 + case GR_FILENAME_STR:
59125 + dentry = va_arg(ap, struct dentry *);
59126 + mnt = va_arg(ap, struct vfsmount *);
59127 + str1 = va_arg(ap, char *);
59128 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
59129 + break;
59130 + case GR_FILENAME_TWO_INT:
59131 + dentry = va_arg(ap, struct dentry *);
59132 + mnt = va_arg(ap, struct vfsmount *);
59133 + num1 = va_arg(ap, int);
59134 + num2 = va_arg(ap, int);
59135 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
59136 + break;
59137 + case GR_FILENAME_TWO_INT_STR:
59138 + dentry = va_arg(ap, struct dentry *);
59139 + mnt = va_arg(ap, struct vfsmount *);
59140 + num1 = va_arg(ap, int);
59141 + num2 = va_arg(ap, int);
59142 + str1 = va_arg(ap, char *);
59143 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
59144 + break;
59145 + case GR_TEXTREL:
59146 + file = va_arg(ap, struct file *);
59147 + ulong1 = va_arg(ap, unsigned long);
59148 + ulong2 = va_arg(ap, unsigned long);
59149 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
59150 + break;
59151 + case GR_PTRACE:
59152 + task = va_arg(ap, struct task_struct *);
59153 + 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);
59154 + break;
59155 + case GR_RESOURCE:
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 + str1 = va_arg(ap, char *);
59161 + ulong2 = va_arg(ap, unsigned long);
59162 + 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);
59163 + break;
59164 + case GR_CAP:
59165 + task = va_arg(ap, struct task_struct *);
59166 + cred = __task_cred(task);
59167 + pcred = __task_cred(task->real_parent);
59168 + str1 = va_arg(ap, char *);
59169 + 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);
59170 + break;
59171 + case GR_SIG:
59172 + str1 = va_arg(ap, char *);
59173 + voidptr = va_arg(ap, void *);
59174 + gr_log_middle_varargs(audit, msg, str1, voidptr);
59175 + break;
59176 + case GR_SIG2:
59177 + task = va_arg(ap, struct task_struct *);
59178 + cred = __task_cred(task);
59179 + pcred = __task_cred(task->real_parent);
59180 + num1 = va_arg(ap, int);
59181 + 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);
59182 + break;
59183 + case GR_CRASH1:
59184 + task = va_arg(ap, struct task_struct *);
59185 + cred = __task_cred(task);
59186 + pcred = __task_cred(task->real_parent);
59187 + ulong1 = va_arg(ap, unsigned long);
59188 + 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);
59189 + break;
59190 + case GR_CRASH2:
59191 + task = va_arg(ap, struct task_struct *);
59192 + cred = __task_cred(task);
59193 + pcred = __task_cred(task->real_parent);
59194 + ulong1 = va_arg(ap, unsigned long);
59195 + 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);
59196 + break;
59197 + case GR_RWXMAP:
59198 + file = va_arg(ap, struct file *);
59199 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
59200 + break;
59201 + case GR_PSACCT:
59202 + {
59203 + unsigned int wday, cday;
59204 + __u8 whr, chr;
59205 + __u8 wmin, cmin;
59206 + __u8 wsec, csec;
59207 + char cur_tty[64] = { 0 };
59208 + char parent_tty[64] = { 0 };
59209 +
59210 + task = va_arg(ap, struct task_struct *);
59211 + wday = va_arg(ap, unsigned int);
59212 + cday = va_arg(ap, unsigned int);
59213 + whr = va_arg(ap, int);
59214 + chr = va_arg(ap, int);
59215 + wmin = va_arg(ap, int);
59216 + cmin = va_arg(ap, int);
59217 + wsec = va_arg(ap, int);
59218 + csec = va_arg(ap, int);
59219 + ulong1 = va_arg(ap, unsigned long);
59220 + cred = __task_cred(task);
59221 + pcred = __task_cred(task->real_parent);
59222 +
59223 + 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);
59224 + }
59225 + break;
59226 + default:
59227 + gr_log_middle(audit, msg, ap);
59228 + }
59229 + va_end(ap);
59230 + // these don't need DEFAULTSECARGS printed on the end
59231 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
59232 + gr_log_end(audit, 0);
59233 + else
59234 + gr_log_end(audit, 1);
59235 + END_LOCKS(audit);
59236 +}
59237 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
59238 new file mode 100644
59239 index 0000000..f536303
59240 --- /dev/null
59241 +++ b/grsecurity/grsec_mem.c
59242 @@ -0,0 +1,40 @@
59243 +#include <linux/kernel.h>
59244 +#include <linux/sched.h>
59245 +#include <linux/mm.h>
59246 +#include <linux/mman.h>
59247 +#include <linux/grinternal.h>
59248 +
59249 +void
59250 +gr_handle_ioperm(void)
59251 +{
59252 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
59253 + return;
59254 +}
59255 +
59256 +void
59257 +gr_handle_iopl(void)
59258 +{
59259 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
59260 + return;
59261 +}
59262 +
59263 +void
59264 +gr_handle_mem_readwrite(u64 from, u64 to)
59265 +{
59266 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
59267 + return;
59268 +}
59269 +
59270 +void
59271 +gr_handle_vm86(void)
59272 +{
59273 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
59274 + return;
59275 +}
59276 +
59277 +void
59278 +gr_log_badprocpid(const char *entry)
59279 +{
59280 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
59281 + return;
59282 +}
59283 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
59284 new file mode 100644
59285 index 0000000..2131422
59286 --- /dev/null
59287 +++ b/grsecurity/grsec_mount.c
59288 @@ -0,0 +1,62 @@
59289 +#include <linux/kernel.h>
59290 +#include <linux/sched.h>
59291 +#include <linux/mount.h>
59292 +#include <linux/grsecurity.h>
59293 +#include <linux/grinternal.h>
59294 +
59295 +void
59296 +gr_log_remount(const char *devname, const int retval)
59297 +{
59298 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59299 + if (grsec_enable_mount && (retval >= 0))
59300 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
59301 +#endif
59302 + return;
59303 +}
59304 +
59305 +void
59306 +gr_log_unmount(const char *devname, const int retval)
59307 +{
59308 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59309 + if (grsec_enable_mount && (retval >= 0))
59310 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
59311 +#endif
59312 + return;
59313 +}
59314 +
59315 +void
59316 +gr_log_mount(const char *from, const char *to, const int retval)
59317 +{
59318 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59319 + if (grsec_enable_mount && (retval >= 0))
59320 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
59321 +#endif
59322 + return;
59323 +}
59324 +
59325 +int
59326 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
59327 +{
59328 +#ifdef CONFIG_GRKERNSEC_ROFS
59329 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
59330 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
59331 + return -EPERM;
59332 + } else
59333 + return 0;
59334 +#endif
59335 + return 0;
59336 +}
59337 +
59338 +int
59339 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
59340 +{
59341 +#ifdef CONFIG_GRKERNSEC_ROFS
59342 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
59343 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
59344 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
59345 + return -EPERM;
59346 + } else
59347 + return 0;
59348 +#endif
59349 + return 0;
59350 +}
59351 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
59352 new file mode 100644
59353 index 0000000..a3b12a0
59354 --- /dev/null
59355 +++ b/grsecurity/grsec_pax.c
59356 @@ -0,0 +1,36 @@
59357 +#include <linux/kernel.h>
59358 +#include <linux/sched.h>
59359 +#include <linux/mm.h>
59360 +#include <linux/file.h>
59361 +#include <linux/grinternal.h>
59362 +#include <linux/grsecurity.h>
59363 +
59364 +void
59365 +gr_log_textrel(struct vm_area_struct * vma)
59366 +{
59367 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59368 + if (grsec_enable_audit_textrel)
59369 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
59370 +#endif
59371 + return;
59372 +}
59373 +
59374 +void
59375 +gr_log_rwxmmap(struct file *file)
59376 +{
59377 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59378 + if (grsec_enable_log_rwxmaps)
59379 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
59380 +#endif
59381 + return;
59382 +}
59383 +
59384 +void
59385 +gr_log_rwxmprotect(struct file *file)
59386 +{
59387 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59388 + if (grsec_enable_log_rwxmaps)
59389 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
59390 +#endif
59391 + return;
59392 +}
59393 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
59394 new file mode 100644
59395 index 0000000..f7f29aa
59396 --- /dev/null
59397 +++ b/grsecurity/grsec_ptrace.c
59398 @@ -0,0 +1,30 @@
59399 +#include <linux/kernel.h>
59400 +#include <linux/sched.h>
59401 +#include <linux/grinternal.h>
59402 +#include <linux/security.h>
59403 +
59404 +void
59405 +gr_audit_ptrace(struct task_struct *task)
59406 +{
59407 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59408 + if (grsec_enable_audit_ptrace)
59409 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
59410 +#endif
59411 + return;
59412 +}
59413 +
59414 +int
59415 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
59416 +{
59417 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59418 + const struct dentry *dentry = file->f_path.dentry;
59419 + const struct vfsmount *mnt = file->f_path.mnt;
59420 +
59421 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
59422 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
59423 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
59424 + return -EACCES;
59425 + }
59426 +#endif
59427 + return 0;
59428 +}
59429 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
59430 new file mode 100644
59431 index 0000000..b4ac94c
59432 --- /dev/null
59433 +++ b/grsecurity/grsec_sig.c
59434 @@ -0,0 +1,209 @@
59435 +#include <linux/kernel.h>
59436 +#include <linux/sched.h>
59437 +#include <linux/delay.h>
59438 +#include <linux/grsecurity.h>
59439 +#include <linux/grinternal.h>
59440 +#include <linux/hardirq.h>
59441 +
59442 +char *signames[] = {
59443 + [SIGSEGV] = "Segmentation fault",
59444 + [SIGILL] = "Illegal instruction",
59445 + [SIGABRT] = "Abort",
59446 + [SIGBUS] = "Invalid alignment/Bus error"
59447 +};
59448 +
59449 +void
59450 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
59451 +{
59452 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59453 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
59454 + (sig == SIGABRT) || (sig == SIGBUS))) {
59455 + if (t->pid == current->pid) {
59456 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
59457 + } else {
59458 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
59459 + }
59460 + }
59461 +#endif
59462 + return;
59463 +}
59464 +
59465 +int
59466 +gr_handle_signal(const struct task_struct *p, const int sig)
59467 +{
59468 +#ifdef CONFIG_GRKERNSEC
59469 + /* ignore the 0 signal for protected task checks */
59470 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
59471 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
59472 + return -EPERM;
59473 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
59474 + return -EPERM;
59475 + }
59476 +#endif
59477 + return 0;
59478 +}
59479 +
59480 +#ifdef CONFIG_GRKERNSEC
59481 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
59482 +
59483 +int gr_fake_force_sig(int sig, struct task_struct *t)
59484 +{
59485 + unsigned long int flags;
59486 + int ret, blocked, ignored;
59487 + struct k_sigaction *action;
59488 +
59489 + spin_lock_irqsave(&t->sighand->siglock, flags);
59490 + action = &t->sighand->action[sig-1];
59491 + ignored = action->sa.sa_handler == SIG_IGN;
59492 + blocked = sigismember(&t->blocked, sig);
59493 + if (blocked || ignored) {
59494 + action->sa.sa_handler = SIG_DFL;
59495 + if (blocked) {
59496 + sigdelset(&t->blocked, sig);
59497 + recalc_sigpending_and_wake(t);
59498 + }
59499 + }
59500 + if (action->sa.sa_handler == SIG_DFL)
59501 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
59502 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
59503 +
59504 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
59505 +
59506 + return ret;
59507 +}
59508 +#endif
59509 +
59510 +#ifdef CONFIG_GRKERNSEC_BRUTE
59511 +#define GR_USER_BAN_TIME (15 * 60)
59512 +
59513 +static int __get_dumpable(unsigned long mm_flags)
59514 +{
59515 + int ret;
59516 +
59517 + ret = mm_flags & MMF_DUMPABLE_MASK;
59518 + return (ret >= 2) ? 2 : ret;
59519 +}
59520 +#endif
59521 +
59522 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
59523 +{
59524 +#ifdef CONFIG_GRKERNSEC_BRUTE
59525 + kuid_t uid = GLOBAL_ROOT_UID;
59526 +
59527 + if (!grsec_enable_brute)
59528 + return;
59529 +
59530 + rcu_read_lock();
59531 + read_lock(&tasklist_lock);
59532 + read_lock(&grsec_exec_file_lock);
59533 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
59534 + p->real_parent->brute = 1;
59535 + else {
59536 + const struct cred *cred = __task_cred(p), *cred2;
59537 + struct task_struct *tsk, *tsk2;
59538 +
59539 + if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
59540 + struct user_struct *user;
59541 +
59542 + uid = cred->uid;
59543 +
59544 + /* this is put upon execution past expiration */
59545 + user = find_user(uid);
59546 + if (user == NULL)
59547 + goto unlock;
59548 + user->banned = 1;
59549 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
59550 + if (user->ban_expires == ~0UL)
59551 + user->ban_expires--;
59552 +
59553 + do_each_thread(tsk2, tsk) {
59554 + cred2 = __task_cred(tsk);
59555 + if (tsk != p && uid_eq(cred2->uid, uid))
59556 + gr_fake_force_sig(SIGKILL, tsk);
59557 + } while_each_thread(tsk2, tsk);
59558 + }
59559 + }
59560 +unlock:
59561 + read_unlock(&grsec_exec_file_lock);
59562 + read_unlock(&tasklist_lock);
59563 + rcu_read_unlock();
59564 +
59565 + if (!uid_eq(uid, GLOBAL_ROOT_UID))
59566 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
59567 + from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
59568 +
59569 +#endif
59570 + return;
59571 +}
59572 +
59573 +void gr_handle_brute_check(void)
59574 +{
59575 +#ifdef CONFIG_GRKERNSEC_BRUTE
59576 + if (current->brute)
59577 + msleep(30 * 1000);
59578 +#endif
59579 + return;
59580 +}
59581 +
59582 +void gr_handle_kernel_exploit(void)
59583 +{
59584 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
59585 + const struct cred *cred;
59586 + struct task_struct *tsk, *tsk2;
59587 + struct user_struct *user;
59588 + kuid_t uid;
59589 +
59590 + if (in_irq() || in_serving_softirq() || in_nmi())
59591 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
59592 +
59593 + uid = current_uid();
59594 +
59595 + if (uid_eq(uid, GLOBAL_ROOT_UID))
59596 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
59597 + else {
59598 + /* kill all the processes of this user, hold a reference
59599 + to their creds struct, and prevent them from creating
59600 + another process until system reset
59601 + */
59602 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
59603 + from_kuid_munged(&init_user_ns, uid));
59604 + /* we intentionally leak this ref */
59605 + user = get_uid(current->cred->user);
59606 + if (user) {
59607 + user->banned = 1;
59608 + user->ban_expires = ~0UL;
59609 + }
59610 +
59611 + read_lock(&tasklist_lock);
59612 + do_each_thread(tsk2, tsk) {
59613 + cred = __task_cred(tsk);
59614 + if (uid_eq(cred->uid, uid))
59615 + gr_fake_force_sig(SIGKILL, tsk);
59616 + } while_each_thread(tsk2, tsk);
59617 + read_unlock(&tasklist_lock);
59618 + }
59619 +#endif
59620 +}
59621 +
59622 +int __gr_process_user_ban(struct user_struct *user)
59623 +{
59624 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59625 + if (unlikely(user->banned)) {
59626 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
59627 + user->banned = 0;
59628 + user->ban_expires = 0;
59629 + free_uid(user);
59630 + } else
59631 + return -EPERM;
59632 + }
59633 +#endif
59634 + return 0;
59635 +}
59636 +
59637 +int gr_process_user_ban(void)
59638 +{
59639 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59640 + return __gr_process_user_ban(current->cred->user);
59641 +#endif
59642 + return 0;
59643 +}
59644 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
59645 new file mode 100644
59646 index 0000000..4030d57
59647 --- /dev/null
59648 +++ b/grsecurity/grsec_sock.c
59649 @@ -0,0 +1,244 @@
59650 +#include <linux/kernel.h>
59651 +#include <linux/module.h>
59652 +#include <linux/sched.h>
59653 +#include <linux/file.h>
59654 +#include <linux/net.h>
59655 +#include <linux/in.h>
59656 +#include <linux/ip.h>
59657 +#include <net/sock.h>
59658 +#include <net/inet_sock.h>
59659 +#include <linux/grsecurity.h>
59660 +#include <linux/grinternal.h>
59661 +#include <linux/gracl.h>
59662 +
59663 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
59664 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
59665 +
59666 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
59667 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
59668 +
59669 +#ifdef CONFIG_UNIX_MODULE
59670 +EXPORT_SYMBOL(gr_acl_handle_unix);
59671 +EXPORT_SYMBOL(gr_acl_handle_mknod);
59672 +EXPORT_SYMBOL(gr_handle_chroot_unix);
59673 +EXPORT_SYMBOL(gr_handle_create);
59674 +#endif
59675 +
59676 +#ifdef CONFIG_GRKERNSEC
59677 +#define gr_conn_table_size 32749
59678 +struct conn_table_entry {
59679 + struct conn_table_entry *next;
59680 + struct signal_struct *sig;
59681 +};
59682 +
59683 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
59684 +DEFINE_SPINLOCK(gr_conn_table_lock);
59685 +
59686 +extern const char * gr_socktype_to_name(unsigned char type);
59687 +extern const char * gr_proto_to_name(unsigned char proto);
59688 +extern const char * gr_sockfamily_to_name(unsigned char family);
59689 +
59690 +static __inline__ int
59691 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
59692 +{
59693 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
59694 +}
59695 +
59696 +static __inline__ int
59697 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
59698 + __u16 sport, __u16 dport)
59699 +{
59700 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
59701 + sig->gr_sport == sport && sig->gr_dport == dport))
59702 + return 1;
59703 + else
59704 + return 0;
59705 +}
59706 +
59707 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
59708 +{
59709 + struct conn_table_entry **match;
59710 + unsigned int index;
59711 +
59712 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59713 + sig->gr_sport, sig->gr_dport,
59714 + gr_conn_table_size);
59715 +
59716 + newent->sig = sig;
59717 +
59718 + match = &gr_conn_table[index];
59719 + newent->next = *match;
59720 + *match = newent;
59721 +
59722 + return;
59723 +}
59724 +
59725 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
59726 +{
59727 + struct conn_table_entry *match, *last = NULL;
59728 + unsigned int index;
59729 +
59730 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59731 + sig->gr_sport, sig->gr_dport,
59732 + gr_conn_table_size);
59733 +
59734 + match = gr_conn_table[index];
59735 + while (match && !conn_match(match->sig,
59736 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
59737 + sig->gr_dport)) {
59738 + last = match;
59739 + match = match->next;
59740 + }
59741 +
59742 + if (match) {
59743 + if (last)
59744 + last->next = match->next;
59745 + else
59746 + gr_conn_table[index] = NULL;
59747 + kfree(match);
59748 + }
59749 +
59750 + return;
59751 +}
59752 +
59753 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
59754 + __u16 sport, __u16 dport)
59755 +{
59756 + struct conn_table_entry *match;
59757 + unsigned int index;
59758 +
59759 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
59760 +
59761 + match = gr_conn_table[index];
59762 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
59763 + match = match->next;
59764 +
59765 + if (match)
59766 + return match->sig;
59767 + else
59768 + return NULL;
59769 +}
59770 +
59771 +#endif
59772 +
59773 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
59774 +{
59775 +#ifdef CONFIG_GRKERNSEC
59776 + struct signal_struct *sig = task->signal;
59777 + struct conn_table_entry *newent;
59778 +
59779 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
59780 + if (newent == NULL)
59781 + return;
59782 + /* no bh lock needed since we are called with bh disabled */
59783 + spin_lock(&gr_conn_table_lock);
59784 + gr_del_task_from_ip_table_nolock(sig);
59785 + sig->gr_saddr = inet->inet_rcv_saddr;
59786 + sig->gr_daddr = inet->inet_daddr;
59787 + sig->gr_sport = inet->inet_sport;
59788 + sig->gr_dport = inet->inet_dport;
59789 + gr_add_to_task_ip_table_nolock(sig, newent);
59790 + spin_unlock(&gr_conn_table_lock);
59791 +#endif
59792 + return;
59793 +}
59794 +
59795 +void gr_del_task_from_ip_table(struct task_struct *task)
59796 +{
59797 +#ifdef CONFIG_GRKERNSEC
59798 + spin_lock_bh(&gr_conn_table_lock);
59799 + gr_del_task_from_ip_table_nolock(task->signal);
59800 + spin_unlock_bh(&gr_conn_table_lock);
59801 +#endif
59802 + return;
59803 +}
59804 +
59805 +void
59806 +gr_attach_curr_ip(const struct sock *sk)
59807 +{
59808 +#ifdef CONFIG_GRKERNSEC
59809 + struct signal_struct *p, *set;
59810 + const struct inet_sock *inet = inet_sk(sk);
59811 +
59812 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
59813 + return;
59814 +
59815 + set = current->signal;
59816 +
59817 + spin_lock_bh(&gr_conn_table_lock);
59818 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
59819 + inet->inet_dport, inet->inet_sport);
59820 + if (unlikely(p != NULL)) {
59821 + set->curr_ip = p->curr_ip;
59822 + set->used_accept = 1;
59823 + gr_del_task_from_ip_table_nolock(p);
59824 + spin_unlock_bh(&gr_conn_table_lock);
59825 + return;
59826 + }
59827 + spin_unlock_bh(&gr_conn_table_lock);
59828 +
59829 + set->curr_ip = inet->inet_daddr;
59830 + set->used_accept = 1;
59831 +#endif
59832 + return;
59833 +}
59834 +
59835 +int
59836 +gr_handle_sock_all(const int family, const int type, const int protocol)
59837 +{
59838 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59839 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
59840 + (family != AF_UNIX)) {
59841 + if (family == AF_INET)
59842 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
59843 + else
59844 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
59845 + return -EACCES;
59846 + }
59847 +#endif
59848 + return 0;
59849 +}
59850 +
59851 +int
59852 +gr_handle_sock_server(const struct sockaddr *sck)
59853 +{
59854 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59855 + if (grsec_enable_socket_server &&
59856 + in_group_p(grsec_socket_server_gid) &&
59857 + sck && (sck->sa_family != AF_UNIX) &&
59858 + (sck->sa_family != AF_LOCAL)) {
59859 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59860 + return -EACCES;
59861 + }
59862 +#endif
59863 + return 0;
59864 +}
59865 +
59866 +int
59867 +gr_handle_sock_server_other(const struct sock *sck)
59868 +{
59869 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59870 + if (grsec_enable_socket_server &&
59871 + in_group_p(grsec_socket_server_gid) &&
59872 + sck && (sck->sk_family != AF_UNIX) &&
59873 + (sck->sk_family != AF_LOCAL)) {
59874 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59875 + return -EACCES;
59876 + }
59877 +#endif
59878 + return 0;
59879 +}
59880 +
59881 +int
59882 +gr_handle_sock_client(const struct sockaddr *sck)
59883 +{
59884 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59885 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
59886 + sck && (sck->sa_family != AF_UNIX) &&
59887 + (sck->sa_family != AF_LOCAL)) {
59888 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
59889 + return -EACCES;
59890 + }
59891 +#endif
59892 + return 0;
59893 +}
59894 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
59895 new file mode 100644
59896 index 0000000..f55ef0f
59897 --- /dev/null
59898 +++ b/grsecurity/grsec_sysctl.c
59899 @@ -0,0 +1,469 @@
59900 +#include <linux/kernel.h>
59901 +#include <linux/sched.h>
59902 +#include <linux/sysctl.h>
59903 +#include <linux/grsecurity.h>
59904 +#include <linux/grinternal.h>
59905 +
59906 +int
59907 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
59908 +{
59909 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59910 + if (dirname == NULL || name == NULL)
59911 + return 0;
59912 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
59913 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
59914 + return -EACCES;
59915 + }
59916 +#endif
59917 + return 0;
59918 +}
59919 +
59920 +#ifdef CONFIG_GRKERNSEC_ROFS
59921 +static int __maybe_unused one = 1;
59922 +#endif
59923 +
59924 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
59925 +struct ctl_table grsecurity_table[] = {
59926 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59927 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
59928 +#ifdef CONFIG_GRKERNSEC_IO
59929 + {
59930 + .procname = "disable_priv_io",
59931 + .data = &grsec_disable_privio,
59932 + .maxlen = sizeof(int),
59933 + .mode = 0600,
59934 + .proc_handler = &proc_dointvec,
59935 + },
59936 +#endif
59937 +#endif
59938 +#ifdef CONFIG_GRKERNSEC_LINK
59939 + {
59940 + .procname = "linking_restrictions",
59941 + .data = &grsec_enable_link,
59942 + .maxlen = sizeof(int),
59943 + .mode = 0600,
59944 + .proc_handler = &proc_dointvec,
59945 + },
59946 +#endif
59947 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
59948 + {
59949 + .procname = "enforce_symlinksifowner",
59950 + .data = &grsec_enable_symlinkown,
59951 + .maxlen = sizeof(int),
59952 + .mode = 0600,
59953 + .proc_handler = &proc_dointvec,
59954 + },
59955 + {
59956 + .procname = "symlinkown_gid",
59957 + .data = &grsec_symlinkown_gid,
59958 + .maxlen = sizeof(int),
59959 + .mode = 0600,
59960 + .proc_handler = &proc_dointvec,
59961 + },
59962 +#endif
59963 +#ifdef CONFIG_GRKERNSEC_BRUTE
59964 + {
59965 + .procname = "deter_bruteforce",
59966 + .data = &grsec_enable_brute,
59967 + .maxlen = sizeof(int),
59968 + .mode = 0600,
59969 + .proc_handler = &proc_dointvec,
59970 + },
59971 +#endif
59972 +#ifdef CONFIG_GRKERNSEC_FIFO
59973 + {
59974 + .procname = "fifo_restrictions",
59975 + .data = &grsec_enable_fifo,
59976 + .maxlen = sizeof(int),
59977 + .mode = 0600,
59978 + .proc_handler = &proc_dointvec,
59979 + },
59980 +#endif
59981 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59982 + {
59983 + .procname = "ptrace_readexec",
59984 + .data = &grsec_enable_ptrace_readexec,
59985 + .maxlen = sizeof(int),
59986 + .mode = 0600,
59987 + .proc_handler = &proc_dointvec,
59988 + },
59989 +#endif
59990 +#ifdef CONFIG_GRKERNSEC_SETXID
59991 + {
59992 + .procname = "consistent_setxid",
59993 + .data = &grsec_enable_setxid,
59994 + .maxlen = sizeof(int),
59995 + .mode = 0600,
59996 + .proc_handler = &proc_dointvec,
59997 + },
59998 +#endif
59999 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
60000 + {
60001 + .procname = "ip_blackhole",
60002 + .data = &grsec_enable_blackhole,
60003 + .maxlen = sizeof(int),
60004 + .mode = 0600,
60005 + .proc_handler = &proc_dointvec,
60006 + },
60007 + {
60008 + .procname = "lastack_retries",
60009 + .data = &grsec_lastack_retries,
60010 + .maxlen = sizeof(int),
60011 + .mode = 0600,
60012 + .proc_handler = &proc_dointvec,
60013 + },
60014 +#endif
60015 +#ifdef CONFIG_GRKERNSEC_EXECLOG
60016 + {
60017 + .procname = "exec_logging",
60018 + .data = &grsec_enable_execlog,
60019 + .maxlen = sizeof(int),
60020 + .mode = 0600,
60021 + .proc_handler = &proc_dointvec,
60022 + },
60023 +#endif
60024 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
60025 + {
60026 + .procname = "rwxmap_logging",
60027 + .data = &grsec_enable_log_rwxmaps,
60028 + .maxlen = sizeof(int),
60029 + .mode = 0600,
60030 + .proc_handler = &proc_dointvec,
60031 + },
60032 +#endif
60033 +#ifdef CONFIG_GRKERNSEC_SIGNAL
60034 + {
60035 + .procname = "signal_logging",
60036 + .data = &grsec_enable_signal,
60037 + .maxlen = sizeof(int),
60038 + .mode = 0600,
60039 + .proc_handler = &proc_dointvec,
60040 + },
60041 +#endif
60042 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
60043 + {
60044 + .procname = "forkfail_logging",
60045 + .data = &grsec_enable_forkfail,
60046 + .maxlen = sizeof(int),
60047 + .mode = 0600,
60048 + .proc_handler = &proc_dointvec,
60049 + },
60050 +#endif
60051 +#ifdef CONFIG_GRKERNSEC_TIME
60052 + {
60053 + .procname = "timechange_logging",
60054 + .data = &grsec_enable_time,
60055 + .maxlen = sizeof(int),
60056 + .mode = 0600,
60057 + .proc_handler = &proc_dointvec,
60058 + },
60059 +#endif
60060 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
60061 + {
60062 + .procname = "chroot_deny_shmat",
60063 + .data = &grsec_enable_chroot_shmat,
60064 + .maxlen = sizeof(int),
60065 + .mode = 0600,
60066 + .proc_handler = &proc_dointvec,
60067 + },
60068 +#endif
60069 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
60070 + {
60071 + .procname = "chroot_deny_unix",
60072 + .data = &grsec_enable_chroot_unix,
60073 + .maxlen = sizeof(int),
60074 + .mode = 0600,
60075 + .proc_handler = &proc_dointvec,
60076 + },
60077 +#endif
60078 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
60079 + {
60080 + .procname = "chroot_deny_mount",
60081 + .data = &grsec_enable_chroot_mount,
60082 + .maxlen = sizeof(int),
60083 + .mode = 0600,
60084 + .proc_handler = &proc_dointvec,
60085 + },
60086 +#endif
60087 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
60088 + {
60089 + .procname = "chroot_deny_fchdir",
60090 + .data = &grsec_enable_chroot_fchdir,
60091 + .maxlen = sizeof(int),
60092 + .mode = 0600,
60093 + .proc_handler = &proc_dointvec,
60094 + },
60095 +#endif
60096 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
60097 + {
60098 + .procname = "chroot_deny_chroot",
60099 + .data = &grsec_enable_chroot_double,
60100 + .maxlen = sizeof(int),
60101 + .mode = 0600,
60102 + .proc_handler = &proc_dointvec,
60103 + },
60104 +#endif
60105 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
60106 + {
60107 + .procname = "chroot_deny_pivot",
60108 + .data = &grsec_enable_chroot_pivot,
60109 + .maxlen = sizeof(int),
60110 + .mode = 0600,
60111 + .proc_handler = &proc_dointvec,
60112 + },
60113 +#endif
60114 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
60115 + {
60116 + .procname = "chroot_enforce_chdir",
60117 + .data = &grsec_enable_chroot_chdir,
60118 + .maxlen = sizeof(int),
60119 + .mode = 0600,
60120 + .proc_handler = &proc_dointvec,
60121 + },
60122 +#endif
60123 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
60124 + {
60125 + .procname = "chroot_deny_chmod",
60126 + .data = &grsec_enable_chroot_chmod,
60127 + .maxlen = sizeof(int),
60128 + .mode = 0600,
60129 + .proc_handler = &proc_dointvec,
60130 + },
60131 +#endif
60132 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
60133 + {
60134 + .procname = "chroot_deny_mknod",
60135 + .data = &grsec_enable_chroot_mknod,
60136 + .maxlen = sizeof(int),
60137 + .mode = 0600,
60138 + .proc_handler = &proc_dointvec,
60139 + },
60140 +#endif
60141 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
60142 + {
60143 + .procname = "chroot_restrict_nice",
60144 + .data = &grsec_enable_chroot_nice,
60145 + .maxlen = sizeof(int),
60146 + .mode = 0600,
60147 + .proc_handler = &proc_dointvec,
60148 + },
60149 +#endif
60150 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
60151 + {
60152 + .procname = "chroot_execlog",
60153 + .data = &grsec_enable_chroot_execlog,
60154 + .maxlen = sizeof(int),
60155 + .mode = 0600,
60156 + .proc_handler = &proc_dointvec,
60157 + },
60158 +#endif
60159 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60160 + {
60161 + .procname = "chroot_caps",
60162 + .data = &grsec_enable_chroot_caps,
60163 + .maxlen = sizeof(int),
60164 + .mode = 0600,
60165 + .proc_handler = &proc_dointvec,
60166 + },
60167 +#endif
60168 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
60169 + {
60170 + .procname = "chroot_deny_sysctl",
60171 + .data = &grsec_enable_chroot_sysctl,
60172 + .maxlen = sizeof(int),
60173 + .mode = 0600,
60174 + .proc_handler = &proc_dointvec,
60175 + },
60176 +#endif
60177 +#ifdef CONFIG_GRKERNSEC_TPE
60178 + {
60179 + .procname = "tpe",
60180 + .data = &grsec_enable_tpe,
60181 + .maxlen = sizeof(int),
60182 + .mode = 0600,
60183 + .proc_handler = &proc_dointvec,
60184 + },
60185 + {
60186 + .procname = "tpe_gid",
60187 + .data = &grsec_tpe_gid,
60188 + .maxlen = sizeof(int),
60189 + .mode = 0600,
60190 + .proc_handler = &proc_dointvec,
60191 + },
60192 +#endif
60193 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60194 + {
60195 + .procname = "tpe_invert",
60196 + .data = &grsec_enable_tpe_invert,
60197 + .maxlen = sizeof(int),
60198 + .mode = 0600,
60199 + .proc_handler = &proc_dointvec,
60200 + },
60201 +#endif
60202 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
60203 + {
60204 + .procname = "tpe_restrict_all",
60205 + .data = &grsec_enable_tpe_all,
60206 + .maxlen = sizeof(int),
60207 + .mode = 0600,
60208 + .proc_handler = &proc_dointvec,
60209 + },
60210 +#endif
60211 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
60212 + {
60213 + .procname = "socket_all",
60214 + .data = &grsec_enable_socket_all,
60215 + .maxlen = sizeof(int),
60216 + .mode = 0600,
60217 + .proc_handler = &proc_dointvec,
60218 + },
60219 + {
60220 + .procname = "socket_all_gid",
60221 + .data = &grsec_socket_all_gid,
60222 + .maxlen = sizeof(int),
60223 + .mode = 0600,
60224 + .proc_handler = &proc_dointvec,
60225 + },
60226 +#endif
60227 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
60228 + {
60229 + .procname = "socket_client",
60230 + .data = &grsec_enable_socket_client,
60231 + .maxlen = sizeof(int),
60232 + .mode = 0600,
60233 + .proc_handler = &proc_dointvec,
60234 + },
60235 + {
60236 + .procname = "socket_client_gid",
60237 + .data = &grsec_socket_client_gid,
60238 + .maxlen = sizeof(int),
60239 + .mode = 0600,
60240 + .proc_handler = &proc_dointvec,
60241 + },
60242 +#endif
60243 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60244 + {
60245 + .procname = "socket_server",
60246 + .data = &grsec_enable_socket_server,
60247 + .maxlen = sizeof(int),
60248 + .mode = 0600,
60249 + .proc_handler = &proc_dointvec,
60250 + },
60251 + {
60252 + .procname = "socket_server_gid",
60253 + .data = &grsec_socket_server_gid,
60254 + .maxlen = sizeof(int),
60255 + .mode = 0600,
60256 + .proc_handler = &proc_dointvec,
60257 + },
60258 +#endif
60259 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
60260 + {
60261 + .procname = "audit_group",
60262 + .data = &grsec_enable_group,
60263 + .maxlen = sizeof(int),
60264 + .mode = 0600,
60265 + .proc_handler = &proc_dointvec,
60266 + },
60267 + {
60268 + .procname = "audit_gid",
60269 + .data = &grsec_audit_gid,
60270 + .maxlen = sizeof(int),
60271 + .mode = 0600,
60272 + .proc_handler = &proc_dointvec,
60273 + },
60274 +#endif
60275 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
60276 + {
60277 + .procname = "audit_chdir",
60278 + .data = &grsec_enable_chdir,
60279 + .maxlen = sizeof(int),
60280 + .mode = 0600,
60281 + .proc_handler = &proc_dointvec,
60282 + },
60283 +#endif
60284 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60285 + {
60286 + .procname = "audit_mount",
60287 + .data = &grsec_enable_mount,
60288 + .maxlen = sizeof(int),
60289 + .mode = 0600,
60290 + .proc_handler = &proc_dointvec,
60291 + },
60292 +#endif
60293 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
60294 + {
60295 + .procname = "audit_textrel",
60296 + .data = &grsec_enable_audit_textrel,
60297 + .maxlen = sizeof(int),
60298 + .mode = 0600,
60299 + .proc_handler = &proc_dointvec,
60300 + },
60301 +#endif
60302 +#ifdef CONFIG_GRKERNSEC_DMESG
60303 + {
60304 + .procname = "dmesg",
60305 + .data = &grsec_enable_dmesg,
60306 + .maxlen = sizeof(int),
60307 + .mode = 0600,
60308 + .proc_handler = &proc_dointvec,
60309 + },
60310 +#endif
60311 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60312 + {
60313 + .procname = "chroot_findtask",
60314 + .data = &grsec_enable_chroot_findtask,
60315 + .maxlen = sizeof(int),
60316 + .mode = 0600,
60317 + .proc_handler = &proc_dointvec,
60318 + },
60319 +#endif
60320 +#ifdef CONFIG_GRKERNSEC_RESLOG
60321 + {
60322 + .procname = "resource_logging",
60323 + .data = &grsec_resource_logging,
60324 + .maxlen = sizeof(int),
60325 + .mode = 0600,
60326 + .proc_handler = &proc_dointvec,
60327 + },
60328 +#endif
60329 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
60330 + {
60331 + .procname = "audit_ptrace",
60332 + .data = &grsec_enable_audit_ptrace,
60333 + .maxlen = sizeof(int),
60334 + .mode = 0600,
60335 + .proc_handler = &proc_dointvec,
60336 + },
60337 +#endif
60338 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60339 + {
60340 + .procname = "harden_ptrace",
60341 + .data = &grsec_enable_harden_ptrace,
60342 + .maxlen = sizeof(int),
60343 + .mode = 0600,
60344 + .proc_handler = &proc_dointvec,
60345 + },
60346 +#endif
60347 + {
60348 + .procname = "grsec_lock",
60349 + .data = &grsec_lock,
60350 + .maxlen = sizeof(int),
60351 + .mode = 0600,
60352 + .proc_handler = &proc_dointvec,
60353 + },
60354 +#endif
60355 +#ifdef CONFIG_GRKERNSEC_ROFS
60356 + {
60357 + .procname = "romount_protect",
60358 + .data = &grsec_enable_rofs,
60359 + .maxlen = sizeof(int),
60360 + .mode = 0600,
60361 + .proc_handler = &proc_dointvec_minmax,
60362 + .extra1 = &one,
60363 + .extra2 = &one,
60364 + },
60365 +#endif
60366 + { }
60367 +};
60368 +#endif
60369 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
60370 new file mode 100644
60371 index 0000000..0dc13c3
60372 --- /dev/null
60373 +++ b/grsecurity/grsec_time.c
60374 @@ -0,0 +1,16 @@
60375 +#include <linux/kernel.h>
60376 +#include <linux/sched.h>
60377 +#include <linux/grinternal.h>
60378 +#include <linux/module.h>
60379 +
60380 +void
60381 +gr_log_timechange(void)
60382 +{
60383 +#ifdef CONFIG_GRKERNSEC_TIME
60384 + if (grsec_enable_time)
60385 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
60386 +#endif
60387 + return;
60388 +}
60389 +
60390 +EXPORT_SYMBOL(gr_log_timechange);
60391 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
60392 new file mode 100644
60393 index 0000000..07e0dc0
60394 --- /dev/null
60395 +++ b/grsecurity/grsec_tpe.c
60396 @@ -0,0 +1,73 @@
60397 +#include <linux/kernel.h>
60398 +#include <linux/sched.h>
60399 +#include <linux/file.h>
60400 +#include <linux/fs.h>
60401 +#include <linux/grinternal.h>
60402 +
60403 +extern int gr_acl_tpe_check(void);
60404 +
60405 +int
60406 +gr_tpe_allow(const struct file *file)
60407 +{
60408 +#ifdef CONFIG_GRKERNSEC
60409 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
60410 + const struct cred *cred = current_cred();
60411 + char *msg = NULL;
60412 + char *msg2 = NULL;
60413 +
60414 + // never restrict root
60415 + if (!cred->uid)
60416 + return 1;
60417 +
60418 + if (grsec_enable_tpe) {
60419 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60420 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
60421 + msg = "not being in trusted group";
60422 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
60423 + msg = "being in untrusted group";
60424 +#else
60425 + if (in_group_p(grsec_tpe_gid))
60426 + msg = "being in untrusted group";
60427 +#endif
60428 + }
60429 + if (!msg && gr_acl_tpe_check())
60430 + msg = "being in untrusted role";
60431 +
60432 + // not in any affected group/role
60433 + if (!msg)
60434 + goto next_check;
60435 +
60436 + if (inode->i_uid)
60437 + msg2 = "file in non-root-owned directory";
60438 + else if (inode->i_mode & S_IWOTH)
60439 + msg2 = "file in world-writable directory";
60440 + else if (inode->i_mode & S_IWGRP)
60441 + msg2 = "file in group-writable directory";
60442 +
60443 + if (msg && msg2) {
60444 + char fullmsg[70] = {0};
60445 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
60446 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
60447 + return 0;
60448 + }
60449 + msg = NULL;
60450 +next_check:
60451 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
60452 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
60453 + return 1;
60454 +
60455 + if (inode->i_uid && (inode->i_uid != cred->uid))
60456 + msg = "directory not owned by user";
60457 + else if (inode->i_mode & S_IWOTH)
60458 + msg = "file in world-writable directory";
60459 + else if (inode->i_mode & S_IWGRP)
60460 + msg = "file in group-writable directory";
60461 +
60462 + if (msg) {
60463 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
60464 + return 0;
60465 + }
60466 +#endif
60467 +#endif
60468 + return 1;
60469 +}
60470 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
60471 new file mode 100644
60472 index 0000000..9f7b1ac
60473 --- /dev/null
60474 +++ b/grsecurity/grsum.c
60475 @@ -0,0 +1,61 @@
60476 +#include <linux/err.h>
60477 +#include <linux/kernel.h>
60478 +#include <linux/sched.h>
60479 +#include <linux/mm.h>
60480 +#include <linux/scatterlist.h>
60481 +#include <linux/crypto.h>
60482 +#include <linux/gracl.h>
60483 +
60484 +
60485 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
60486 +#error "crypto and sha256 must be built into the kernel"
60487 +#endif
60488 +
60489 +int
60490 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
60491 +{
60492 + char *p;
60493 + struct crypto_hash *tfm;
60494 + struct hash_desc desc;
60495 + struct scatterlist sg;
60496 + unsigned char temp_sum[GR_SHA_LEN];
60497 + volatile int retval = 0;
60498 + volatile int dummy = 0;
60499 + unsigned int i;
60500 +
60501 + sg_init_table(&sg, 1);
60502 +
60503 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
60504 + if (IS_ERR(tfm)) {
60505 + /* should never happen, since sha256 should be built in */
60506 + return 1;
60507 + }
60508 +
60509 + desc.tfm = tfm;
60510 + desc.flags = 0;
60511 +
60512 + crypto_hash_init(&desc);
60513 +
60514 + p = salt;
60515 + sg_set_buf(&sg, p, GR_SALT_LEN);
60516 + crypto_hash_update(&desc, &sg, sg.length);
60517 +
60518 + p = entry->pw;
60519 + sg_set_buf(&sg, p, strlen(p));
60520 +
60521 + crypto_hash_update(&desc, &sg, sg.length);
60522 +
60523 + crypto_hash_final(&desc, temp_sum);
60524 +
60525 + memset(entry->pw, 0, GR_PW_LEN);
60526 +
60527 + for (i = 0; i < GR_SHA_LEN; i++)
60528 + if (sum[i] != temp_sum[i])
60529 + retval = 1;
60530 + else
60531 + dummy = 1; // waste a cycle
60532 +
60533 + crypto_free_hash(tfm);
60534 +
60535 + return retval;
60536 +}
60537 diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
60538 index bde976e..a1cc32a 100644
60539 --- a/include/acpi/acpi_bus.h
60540 +++ b/include/acpi/acpi_bus.h
60541 @@ -136,7 +136,7 @@ struct acpi_device_ops {
60542 acpi_op_bind bind;
60543 acpi_op_unbind unbind;
60544 acpi_op_notify notify;
60545 -};
60546 +} __no_const;
60547
60548 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
60549
60550 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
60551 index 77ff547..181834f 100644
60552 --- a/include/asm-generic/4level-fixup.h
60553 +++ b/include/asm-generic/4level-fixup.h
60554 @@ -13,8 +13,10 @@
60555 #define pmd_alloc(mm, pud, address) \
60556 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
60557 NULL: pmd_offset(pud, address))
60558 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
60559
60560 #define pud_alloc(mm, pgd, address) (pgd)
60561 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
60562 #define pud_offset(pgd, start) (pgd)
60563 #define pud_none(pud) 0
60564 #define pud_bad(pud) 0
60565 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
60566 index b7babf0..3ba8aee 100644
60567 --- a/include/asm-generic/atomic-long.h
60568 +++ b/include/asm-generic/atomic-long.h
60569 @@ -22,6 +22,12 @@
60570
60571 typedef atomic64_t atomic_long_t;
60572
60573 +#ifdef CONFIG_PAX_REFCOUNT
60574 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
60575 +#else
60576 +typedef atomic64_t atomic_long_unchecked_t;
60577 +#endif
60578 +
60579 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
60580
60581 static inline long atomic_long_read(atomic_long_t *l)
60582 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60583 return (long)atomic64_read(v);
60584 }
60585
60586 +#ifdef CONFIG_PAX_REFCOUNT
60587 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60588 +{
60589 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60590 +
60591 + return (long)atomic64_read_unchecked(v);
60592 +}
60593 +#endif
60594 +
60595 static inline void atomic_long_set(atomic_long_t *l, long i)
60596 {
60597 atomic64_t *v = (atomic64_t *)l;
60598 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60599 atomic64_set(v, i);
60600 }
60601
60602 +#ifdef CONFIG_PAX_REFCOUNT
60603 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60604 +{
60605 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60606 +
60607 + atomic64_set_unchecked(v, i);
60608 +}
60609 +#endif
60610 +
60611 static inline void atomic_long_inc(atomic_long_t *l)
60612 {
60613 atomic64_t *v = (atomic64_t *)l;
60614 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60615 atomic64_inc(v);
60616 }
60617
60618 +#ifdef CONFIG_PAX_REFCOUNT
60619 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60620 +{
60621 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60622 +
60623 + atomic64_inc_unchecked(v);
60624 +}
60625 +#endif
60626 +
60627 static inline void atomic_long_dec(atomic_long_t *l)
60628 {
60629 atomic64_t *v = (atomic64_t *)l;
60630 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60631 atomic64_dec(v);
60632 }
60633
60634 +#ifdef CONFIG_PAX_REFCOUNT
60635 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60636 +{
60637 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60638 +
60639 + atomic64_dec_unchecked(v);
60640 +}
60641 +#endif
60642 +
60643 static inline void atomic_long_add(long i, atomic_long_t *l)
60644 {
60645 atomic64_t *v = (atomic64_t *)l;
60646 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60647 atomic64_add(i, v);
60648 }
60649
60650 +#ifdef CONFIG_PAX_REFCOUNT
60651 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60652 +{
60653 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60654 +
60655 + atomic64_add_unchecked(i, v);
60656 +}
60657 +#endif
60658 +
60659 static inline void atomic_long_sub(long i, atomic_long_t *l)
60660 {
60661 atomic64_t *v = (atomic64_t *)l;
60662 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60663 atomic64_sub(i, v);
60664 }
60665
60666 +#ifdef CONFIG_PAX_REFCOUNT
60667 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60668 +{
60669 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60670 +
60671 + atomic64_sub_unchecked(i, v);
60672 +}
60673 +#endif
60674 +
60675 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60676 {
60677 atomic64_t *v = (atomic64_t *)l;
60678 @@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60679 return (long)atomic64_inc_return(v);
60680 }
60681
60682 +#ifdef CONFIG_PAX_REFCOUNT
60683 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60684 +{
60685 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60686 +
60687 + return (long)atomic64_inc_return_unchecked(v);
60688 +}
60689 +#endif
60690 +
60691 static inline long atomic_long_dec_return(atomic_long_t *l)
60692 {
60693 atomic64_t *v = (atomic64_t *)l;
60694 @@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60695
60696 typedef atomic_t atomic_long_t;
60697
60698 +#ifdef CONFIG_PAX_REFCOUNT
60699 +typedef atomic_unchecked_t atomic_long_unchecked_t;
60700 +#else
60701 +typedef atomic_t atomic_long_unchecked_t;
60702 +#endif
60703 +
60704 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
60705 static inline long atomic_long_read(atomic_long_t *l)
60706 {
60707 @@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60708 return (long)atomic_read(v);
60709 }
60710
60711 +#ifdef CONFIG_PAX_REFCOUNT
60712 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60713 +{
60714 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60715 +
60716 + return (long)atomic_read_unchecked(v);
60717 +}
60718 +#endif
60719 +
60720 static inline void atomic_long_set(atomic_long_t *l, long i)
60721 {
60722 atomic_t *v = (atomic_t *)l;
60723 @@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60724 atomic_set(v, i);
60725 }
60726
60727 +#ifdef CONFIG_PAX_REFCOUNT
60728 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60729 +{
60730 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60731 +
60732 + atomic_set_unchecked(v, i);
60733 +}
60734 +#endif
60735 +
60736 static inline void atomic_long_inc(atomic_long_t *l)
60737 {
60738 atomic_t *v = (atomic_t *)l;
60739 @@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60740 atomic_inc(v);
60741 }
60742
60743 +#ifdef CONFIG_PAX_REFCOUNT
60744 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60745 +{
60746 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60747 +
60748 + atomic_inc_unchecked(v);
60749 +}
60750 +#endif
60751 +
60752 static inline void atomic_long_dec(atomic_long_t *l)
60753 {
60754 atomic_t *v = (atomic_t *)l;
60755 @@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60756 atomic_dec(v);
60757 }
60758
60759 +#ifdef CONFIG_PAX_REFCOUNT
60760 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60761 +{
60762 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60763 +
60764 + atomic_dec_unchecked(v);
60765 +}
60766 +#endif
60767 +
60768 static inline void atomic_long_add(long i, atomic_long_t *l)
60769 {
60770 atomic_t *v = (atomic_t *)l;
60771 @@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60772 atomic_add(i, v);
60773 }
60774
60775 +#ifdef CONFIG_PAX_REFCOUNT
60776 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60777 +{
60778 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60779 +
60780 + atomic_add_unchecked(i, v);
60781 +}
60782 +#endif
60783 +
60784 static inline void atomic_long_sub(long i, atomic_long_t *l)
60785 {
60786 atomic_t *v = (atomic_t *)l;
60787 @@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60788 atomic_sub(i, v);
60789 }
60790
60791 +#ifdef CONFIG_PAX_REFCOUNT
60792 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60793 +{
60794 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60795 +
60796 + atomic_sub_unchecked(i, v);
60797 +}
60798 +#endif
60799 +
60800 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60801 {
60802 atomic_t *v = (atomic_t *)l;
60803 @@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60804 return (long)atomic_inc_return(v);
60805 }
60806
60807 +#ifdef CONFIG_PAX_REFCOUNT
60808 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60809 +{
60810 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60811 +
60812 + return (long)atomic_inc_return_unchecked(v);
60813 +}
60814 +#endif
60815 +
60816 static inline long atomic_long_dec_return(atomic_long_t *l)
60817 {
60818 atomic_t *v = (atomic_t *)l;
60819 @@ -255,4 +393,55 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60820
60821 #endif /* BITS_PER_LONG == 64 */
60822
60823 +#ifdef CONFIG_PAX_REFCOUNT
60824 +static inline void pax_refcount_needs_these_functions(void)
60825 +{
60826 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
60827 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
60828 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
60829 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
60830 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
60831 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
60832 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
60833 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
60834 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
60835 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
60836 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
60837 +#ifdef CONFIG_X86
60838 + atomic_clear_mask_unchecked(0, NULL);
60839 + atomic_set_mask_unchecked(0, NULL);
60840 +#endif
60841 +
60842 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
60843 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
60844 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
60845 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
60846 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
60847 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
60848 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
60849 +}
60850 +#else
60851 +#define atomic_read_unchecked(v) atomic_read(v)
60852 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
60853 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
60854 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
60855 +#define atomic_inc_unchecked(v) atomic_inc(v)
60856 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
60857 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
60858 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
60859 +#define atomic_dec_unchecked(v) atomic_dec(v)
60860 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
60861 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
60862 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
60863 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
60864 +
60865 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
60866 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
60867 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
60868 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
60869 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
60870 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
60871 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
60872 +#endif
60873 +
60874 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
60875 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
60876 index 1ced641..c896ee8 100644
60877 --- a/include/asm-generic/atomic.h
60878 +++ b/include/asm-generic/atomic.h
60879 @@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
60880 * Atomically clears the bits set in @mask from @v
60881 */
60882 #ifndef atomic_clear_mask
60883 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
60884 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
60885 {
60886 unsigned long flags;
60887
60888 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
60889 index b18ce4f..2ee2843 100644
60890 --- a/include/asm-generic/atomic64.h
60891 +++ b/include/asm-generic/atomic64.h
60892 @@ -16,6 +16,8 @@ typedef struct {
60893 long long counter;
60894 } atomic64_t;
60895
60896 +typedef atomic64_t atomic64_unchecked_t;
60897 +
60898 #define ATOMIC64_INIT(i) { (i) }
60899
60900 extern long long atomic64_read(const atomic64_t *v);
60901 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
60902 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
60903 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
60904
60905 +#define atomic64_read_unchecked(v) atomic64_read(v)
60906 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
60907 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
60908 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
60909 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
60910 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
60911 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
60912 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
60913 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
60914 +
60915 #endif /* _ASM_GENERIC_ATOMIC64_H */
60916 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
60917 index 1bfcfe5..e04c5c9 100644
60918 --- a/include/asm-generic/cache.h
60919 +++ b/include/asm-generic/cache.h
60920 @@ -6,7 +6,7 @@
60921 * cache lines need to provide their own cache.h.
60922 */
60923
60924 -#define L1_CACHE_SHIFT 5
60925 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
60926 +#define L1_CACHE_SHIFT 5UL
60927 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
60928
60929 #endif /* __ASM_GENERIC_CACHE_H */
60930 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
60931 index 0d68a1e..b74a761 100644
60932 --- a/include/asm-generic/emergency-restart.h
60933 +++ b/include/asm-generic/emergency-restart.h
60934 @@ -1,7 +1,7 @@
60935 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
60936 #define _ASM_GENERIC_EMERGENCY_RESTART_H
60937
60938 -static inline void machine_emergency_restart(void)
60939 +static inline __noreturn void machine_emergency_restart(void)
60940 {
60941 machine_restart(NULL);
60942 }
60943 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
60944 index 90f99c7..00ce236 100644
60945 --- a/include/asm-generic/kmap_types.h
60946 +++ b/include/asm-generic/kmap_types.h
60947 @@ -2,9 +2,9 @@
60948 #define _ASM_GENERIC_KMAP_TYPES_H
60949
60950 #ifdef __WITH_KM_FENCE
60951 -# define KM_TYPE_NR 41
60952 +# define KM_TYPE_NR 42
60953 #else
60954 -# define KM_TYPE_NR 20
60955 +# define KM_TYPE_NR 21
60956 #endif
60957
60958 #endif
60959 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
60960 index 9ceb03b..2efbcbd 100644
60961 --- a/include/asm-generic/local.h
60962 +++ b/include/asm-generic/local.h
60963 @@ -39,6 +39,7 @@ typedef struct
60964 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
60965 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
60966 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
60967 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
60968
60969 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
60970 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
60971 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
60972 index 725612b..9cc513a 100644
60973 --- a/include/asm-generic/pgtable-nopmd.h
60974 +++ b/include/asm-generic/pgtable-nopmd.h
60975 @@ -1,14 +1,19 @@
60976 #ifndef _PGTABLE_NOPMD_H
60977 #define _PGTABLE_NOPMD_H
60978
60979 -#ifndef __ASSEMBLY__
60980 -
60981 #include <asm-generic/pgtable-nopud.h>
60982
60983 -struct mm_struct;
60984 -
60985 #define __PAGETABLE_PMD_FOLDED
60986
60987 +#define PMD_SHIFT PUD_SHIFT
60988 +#define PTRS_PER_PMD 1
60989 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
60990 +#define PMD_MASK (~(PMD_SIZE-1))
60991 +
60992 +#ifndef __ASSEMBLY__
60993 +
60994 +struct mm_struct;
60995 +
60996 /*
60997 * Having the pmd type consist of a pud gets the size right, and allows
60998 * us to conceptually access the pud entry that this pmd is folded into
60999 @@ -16,11 +21,6 @@ struct mm_struct;
61000 */
61001 typedef struct { pud_t pud; } pmd_t;
61002
61003 -#define PMD_SHIFT PUD_SHIFT
61004 -#define PTRS_PER_PMD 1
61005 -#define PMD_SIZE (1UL << PMD_SHIFT)
61006 -#define PMD_MASK (~(PMD_SIZE-1))
61007 -
61008 /*
61009 * The "pud_xxx()" functions here are trivial for a folded two-level
61010 * setup: the pmd is never bad, and a pmd always exists (as it's folded
61011 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
61012 index 810431d..0ec4804f 100644
61013 --- a/include/asm-generic/pgtable-nopud.h
61014 +++ b/include/asm-generic/pgtable-nopud.h
61015 @@ -1,10 +1,15 @@
61016 #ifndef _PGTABLE_NOPUD_H
61017 #define _PGTABLE_NOPUD_H
61018
61019 -#ifndef __ASSEMBLY__
61020 -
61021 #define __PAGETABLE_PUD_FOLDED
61022
61023 +#define PUD_SHIFT PGDIR_SHIFT
61024 +#define PTRS_PER_PUD 1
61025 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
61026 +#define PUD_MASK (~(PUD_SIZE-1))
61027 +
61028 +#ifndef __ASSEMBLY__
61029 +
61030 /*
61031 * Having the pud type consist of a pgd gets the size right, and allows
61032 * us to conceptually access the pgd entry that this pud is folded into
61033 @@ -12,11 +17,6 @@
61034 */
61035 typedef struct { pgd_t pgd; } pud_t;
61036
61037 -#define PUD_SHIFT PGDIR_SHIFT
61038 -#define PTRS_PER_PUD 1
61039 -#define PUD_SIZE (1UL << PUD_SHIFT)
61040 -#define PUD_MASK (~(PUD_SIZE-1))
61041 -
61042 /*
61043 * The "pgd_xxx()" functions here are trivial for a folded two-level
61044 * setup: the pud is never bad, and a pud always exists (as it's folded
61045 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
61046 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
61047
61048 #define pgd_populate(mm, pgd, pud) do { } while (0)
61049 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
61050 /*
61051 * (puds are folded into pgds so this doesn't get actually called,
61052 * but the define is needed for a generic inline function.)
61053 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
61054 index ff4947b..f48183f 100644
61055 --- a/include/asm-generic/pgtable.h
61056 +++ b/include/asm-generic/pgtable.h
61057 @@ -530,6 +530,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
61058 #endif
61059 }
61060
61061 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
61062 +static inline unsigned long pax_open_kernel(void) { return 0; }
61063 +#endif
61064 +
61065 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
61066 +static inline unsigned long pax_close_kernel(void) { return 0; }
61067 +#endif
61068 +
61069 #endif /* CONFIG_MMU */
61070
61071 #endif /* !__ASSEMBLY__ */
61072 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
61073 index 4e2e1cc..12c266b 100644
61074 --- a/include/asm-generic/vmlinux.lds.h
61075 +++ b/include/asm-generic/vmlinux.lds.h
61076 @@ -218,6 +218,7 @@
61077 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
61078 VMLINUX_SYMBOL(__start_rodata) = .; \
61079 *(.rodata) *(.rodata.*) \
61080 + *(.data..read_only) \
61081 *(__vermagic) /* Kernel version magic */ \
61082 . = ALIGN(8); \
61083 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
61084 @@ -716,17 +717,18 @@
61085 * section in the linker script will go there too. @phdr should have
61086 * a leading colon.
61087 *
61088 - * Note that this macros defines __per_cpu_load as an absolute symbol.
61089 + * Note that this macros defines per_cpu_load as an absolute symbol.
61090 * If there is no need to put the percpu section at a predetermined
61091 * address, use PERCPU_SECTION.
61092 */
61093 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
61094 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
61095 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
61096 + per_cpu_load = .; \
61097 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
61098 - LOAD_OFFSET) { \
61099 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
61100 PERCPU_INPUT(cacheline) \
61101 } phdr \
61102 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
61103 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
61104
61105 /**
61106 * PERCPU_SECTION - define output section for percpu area, simple version
61107 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
61108 index d6b67bb..a272c29 100644
61109 --- a/include/drm/drmP.h
61110 +++ b/include/drm/drmP.h
61111 @@ -72,6 +72,7 @@
61112 #include <linux/workqueue.h>
61113 #include <linux/poll.h>
61114 #include <asm/pgalloc.h>
61115 +#include <asm/local.h>
61116 #include "drm.h"
61117
61118 #include <linux/idr.h>
61119 @@ -1067,7 +1068,7 @@ struct drm_device {
61120
61121 /** \name Usage Counters */
61122 /*@{ */
61123 - int open_count; /**< Outstanding files open */
61124 + local_t open_count; /**< Outstanding files open */
61125 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
61126 atomic_t vma_count; /**< Outstanding vma areas open */
61127 int buf_use; /**< Buffers in use -- cannot alloc */
61128 @@ -1078,7 +1079,7 @@ struct drm_device {
61129 /*@{ */
61130 unsigned long counters;
61131 enum drm_stat_type types[15];
61132 - atomic_t counts[15];
61133 + atomic_unchecked_t counts[15];
61134 /*@} */
61135
61136 struct list_head filelist;
61137 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
61138 index e01cc80..319855d 100644
61139 --- a/include/drm/drm_crtc_helper.h
61140 +++ b/include/drm/drm_crtc_helper.h
61141 @@ -81,7 +81,7 @@ struct drm_crtc_helper_funcs {
61142
61143 /* disable crtc when not in use - more explicit than dpms off */
61144 void (*disable)(struct drm_crtc *crtc);
61145 -};
61146 +} __no_const;
61147
61148 /**
61149 * drm_encoder_helper_funcs - helper operations for encoders
61150 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
61151 struct drm_connector *connector);
61152 /* disable encoder when not in use - more explicit than dpms off */
61153 void (*disable)(struct drm_encoder *encoder);
61154 -};
61155 +} __no_const;
61156
61157 /**
61158 * drm_connector_helper_funcs - helper operations for connectors
61159 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
61160 index d6d1da4..fdd1ac5 100644
61161 --- a/include/drm/ttm/ttm_memory.h
61162 +++ b/include/drm/ttm/ttm_memory.h
61163 @@ -48,7 +48,7 @@
61164
61165 struct ttm_mem_shrink {
61166 int (*do_shrink) (struct ttm_mem_shrink *);
61167 -};
61168 +} __no_const;
61169
61170 /**
61171 * struct ttm_mem_global - Global memory accounting structure.
61172 diff --git a/include/linux/a.out.h b/include/linux/a.out.h
61173 index e86dfca..40cc55f 100644
61174 --- a/include/linux/a.out.h
61175 +++ b/include/linux/a.out.h
61176 @@ -39,6 +39,14 @@ enum machine_type {
61177 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
61178 };
61179
61180 +/* Constants for the N_FLAGS field */
61181 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
61182 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
61183 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
61184 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
61185 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
61186 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
61187 +
61188 #if !defined (N_MAGIC)
61189 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
61190 #endif
61191 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
61192 index 06fd4bb..1caec0d 100644
61193 --- a/include/linux/atmdev.h
61194 +++ b/include/linux/atmdev.h
61195 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
61196 #endif
61197
61198 struct k_atm_aal_stats {
61199 -#define __HANDLE_ITEM(i) atomic_t i
61200 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
61201 __AAL_STAT_ITEMS
61202 #undef __HANDLE_ITEM
61203 };
61204 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
61205 index 366422b..1fa7f84 100644
61206 --- a/include/linux/binfmts.h
61207 +++ b/include/linux/binfmts.h
61208 @@ -89,6 +89,7 @@ struct linux_binfmt {
61209 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
61210 int (*load_shlib)(struct file *);
61211 int (*core_dump)(struct coredump_params *cprm);
61212 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
61213 unsigned long min_coredump; /* minimal dump size */
61214 };
61215
61216 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
61217 index 4a2ab7c..a2de7a8 100644
61218 --- a/include/linux/blkdev.h
61219 +++ b/include/linux/blkdev.h
61220 @@ -1420,7 +1420,7 @@ struct block_device_operations {
61221 /* this callback is with swap_lock and sometimes page table lock held */
61222 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
61223 struct module *owner;
61224 -};
61225 +} __do_const;
61226
61227 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
61228 unsigned long);
61229 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
61230 index 4d1a074..88f929a 100644
61231 --- a/include/linux/blktrace_api.h
61232 +++ b/include/linux/blktrace_api.h
61233 @@ -162,7 +162,7 @@ struct blk_trace {
61234 struct dentry *dir;
61235 struct dentry *dropped_file;
61236 struct dentry *msg_file;
61237 - atomic_t dropped;
61238 + atomic_unchecked_t dropped;
61239 };
61240
61241 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
61242 diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
61243 index 83195fb..0b0f77d 100644
61244 --- a/include/linux/byteorder/little_endian.h
61245 +++ b/include/linux/byteorder/little_endian.h
61246 @@ -42,51 +42,51 @@
61247
61248 static inline __le64 __cpu_to_le64p(const __u64 *p)
61249 {
61250 - return (__force __le64)*p;
61251 + return (__force const __le64)*p;
61252 }
61253 static inline __u64 __le64_to_cpup(const __le64 *p)
61254 {
61255 - return (__force __u64)*p;
61256 + return (__force const __u64)*p;
61257 }
61258 static inline __le32 __cpu_to_le32p(const __u32 *p)
61259 {
61260 - return (__force __le32)*p;
61261 + return (__force const __le32)*p;
61262 }
61263 static inline __u32 __le32_to_cpup(const __le32 *p)
61264 {
61265 - return (__force __u32)*p;
61266 + return (__force const __u32)*p;
61267 }
61268 static inline __le16 __cpu_to_le16p(const __u16 *p)
61269 {
61270 - return (__force __le16)*p;
61271 + return (__force const __le16)*p;
61272 }
61273 static inline __u16 __le16_to_cpup(const __le16 *p)
61274 {
61275 - return (__force __u16)*p;
61276 + return (__force const __u16)*p;
61277 }
61278 static inline __be64 __cpu_to_be64p(const __u64 *p)
61279 {
61280 - return (__force __be64)__swab64p(p);
61281 + return (__force const __be64)__swab64p(p);
61282 }
61283 static inline __u64 __be64_to_cpup(const __be64 *p)
61284 {
61285 - return __swab64p((__u64 *)p);
61286 + return __swab64p((const __u64 *)p);
61287 }
61288 static inline __be32 __cpu_to_be32p(const __u32 *p)
61289 {
61290 - return (__force __be32)__swab32p(p);
61291 + return (__force const __be32)__swab32p(p);
61292 }
61293 static inline __u32 __be32_to_cpup(const __be32 *p)
61294 {
61295 - return __swab32p((__u32 *)p);
61296 + return __swab32p((const __u32 *)p);
61297 }
61298 static inline __be16 __cpu_to_be16p(const __u16 *p)
61299 {
61300 - return (__force __be16)__swab16p(p);
61301 + return (__force const __be16)__swab16p(p);
61302 }
61303 static inline __u16 __be16_to_cpup(const __be16 *p)
61304 {
61305 - return __swab16p((__u16 *)p);
61306 + return __swab16p((const __u16 *)p);
61307 }
61308 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
61309 #define __le64_to_cpus(x) do { (void)(x); } while (0)
61310 diff --git a/include/linux/cache.h b/include/linux/cache.h
61311 index 4c57065..4307975 100644
61312 --- a/include/linux/cache.h
61313 +++ b/include/linux/cache.h
61314 @@ -16,6 +16,10 @@
61315 #define __read_mostly
61316 #endif
61317
61318 +#ifndef __read_only
61319 +#define __read_only __read_mostly
61320 +#endif
61321 +
61322 #ifndef ____cacheline_aligned
61323 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
61324 #endif
61325 diff --git a/include/linux/capability.h b/include/linux/capability.h
61326 index d10b7ed..0288b79 100644
61327 --- a/include/linux/capability.h
61328 +++ b/include/linux/capability.h
61329 @@ -553,10 +553,15 @@ extern bool capable(int cap);
61330 extern bool ns_capable(struct user_namespace *ns, int cap);
61331 extern bool nsown_capable(int cap);
61332 extern bool inode_capable(const struct inode *inode, int cap);
61333 +extern bool capable_nolog(int cap);
61334 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
61335 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
61336
61337 /* audit system wants to get cap info from files as well */
61338 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
61339
61340 +extern int is_privileged_binary(const struct dentry *dentry);
61341 +
61342 #endif /* __KERNEL__ */
61343
61344 #endif /* !_LINUX_CAPABILITY_H */
61345 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
61346 index 42e55de..1cd0e66 100644
61347 --- a/include/linux/cleancache.h
61348 +++ b/include/linux/cleancache.h
61349 @@ -31,7 +31,7 @@ struct cleancache_ops {
61350 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
61351 void (*invalidate_inode)(int, struct cleancache_filekey);
61352 void (*invalidate_fs)(int);
61353 -};
61354 +} __no_const;
61355
61356 extern struct cleancache_ops
61357 cleancache_register_ops(struct cleancache_ops *ops);
61358 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
61359 index 77335fa..6cbe7dd 100644
61360 --- a/include/linux/clk-provider.h
61361 +++ b/include/linux/clk-provider.h
61362 @@ -111,6 +111,7 @@ struct clk_ops {
61363 unsigned long);
61364 void (*init)(struct clk_hw *hw);
61365 };
61366 +typedef struct clk_ops __no_const clk_ops_no_const;
61367
61368 /**
61369 * struct clk_init_data - holds init data that's common to all clocks and is
61370 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
61371 index 934bc34..1b47129 100644
61372 --- a/include/linux/compiler-gcc4.h
61373 +++ b/include/linux/compiler-gcc4.h
61374 @@ -32,6 +32,21 @@
61375 #define __linktime_error(message) __attribute__((__error__(message)))
61376
61377 #if __GNUC_MINOR__ >= 5
61378 +
61379 +#ifdef CONSTIFY_PLUGIN
61380 +#define __no_const __attribute__((no_const))
61381 +#define __do_const __attribute__((do_const))
61382 +#endif
61383 +
61384 +#ifdef SIZE_OVERFLOW_PLUGIN
61385 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
61386 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
61387 +#endif
61388 +
61389 +#ifdef LATENT_ENTROPY_PLUGIN
61390 +#define __latent_entropy __attribute__((latent_entropy))
61391 +#endif
61392 +
61393 /*
61394 * Mark a position in code as unreachable. This can be used to
61395 * suppress control flow warnings after asm blocks that transfer
61396 @@ -47,6 +62,11 @@
61397 #define __noclone __attribute__((__noclone__))
61398
61399 #endif
61400 +
61401 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
61402 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
61403 +#define __bos0(ptr) __bos((ptr), 0)
61404 +#define __bos1(ptr) __bos((ptr), 1)
61405 #endif
61406
61407 #if __GNUC_MINOR__ >= 6
61408 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
61409 index f430e41..38be90f 100644
61410 --- a/include/linux/compiler.h
61411 +++ b/include/linux/compiler.h
61412 @@ -5,31 +5,62 @@
61413
61414 #ifdef __CHECKER__
61415 # define __user __attribute__((noderef, address_space(1)))
61416 +# define __force_user __force __user
61417 # define __kernel __attribute__((address_space(0)))
61418 +# define __force_kernel __force __kernel
61419 # define __safe __attribute__((safe))
61420 # define __force __attribute__((force))
61421 # define __nocast __attribute__((nocast))
61422 # define __iomem __attribute__((noderef, address_space(2)))
61423 +# define __force_iomem __force __iomem
61424 # define __acquires(x) __attribute__((context(x,0,1)))
61425 # define __releases(x) __attribute__((context(x,1,0)))
61426 # define __acquire(x) __context__(x,1)
61427 # define __release(x) __context__(x,-1)
61428 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
61429 # define __percpu __attribute__((noderef, address_space(3)))
61430 +# define __force_percpu __force __percpu
61431 #ifdef CONFIG_SPARSE_RCU_POINTER
61432 # define __rcu __attribute__((noderef, address_space(4)))
61433 +# define __force_rcu __force __rcu
61434 #else
61435 # define __rcu
61436 +# define __force_rcu
61437 #endif
61438 extern void __chk_user_ptr(const volatile void __user *);
61439 extern void __chk_io_ptr(const volatile void __iomem *);
61440 +#elif defined(CHECKER_PLUGIN)
61441 +//# define __user
61442 +//# define __force_user
61443 +//# define __kernel
61444 +//# define __force_kernel
61445 +# define __safe
61446 +# define __force
61447 +# define __nocast
61448 +# define __iomem
61449 +# define __force_iomem
61450 +# define __chk_user_ptr(x) (void)0
61451 +# define __chk_io_ptr(x) (void)0
61452 +# define __builtin_warning(x, y...) (1)
61453 +# define __acquires(x)
61454 +# define __releases(x)
61455 +# define __acquire(x) (void)0
61456 +# define __release(x) (void)0
61457 +# define __cond_lock(x,c) (c)
61458 +# define __percpu
61459 +# define __force_percpu
61460 +# define __rcu
61461 +# define __force_rcu
61462 #else
61463 # define __user
61464 +# define __force_user
61465 # define __kernel
61466 +# define __force_kernel
61467 # define __safe
61468 # define __force
61469 # define __nocast
61470 # define __iomem
61471 +# define __force_iomem
61472 # define __chk_user_ptr(x) (void)0
61473 # define __chk_io_ptr(x) (void)0
61474 # define __builtin_warning(x, y...) (1)
61475 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
61476 # define __release(x) (void)0
61477 # define __cond_lock(x,c) (c)
61478 # define __percpu
61479 +# define __force_percpu
61480 # define __rcu
61481 +# define __force_rcu
61482 #endif
61483
61484 #ifdef __KERNEL__
61485 @@ -264,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61486 # define __attribute_const__ /* unimplemented */
61487 #endif
61488
61489 +#ifndef __no_const
61490 +# define __no_const
61491 +#endif
61492 +
61493 +#ifndef __do_const
61494 +# define __do_const
61495 +#endif
61496 +
61497 +#ifndef __size_overflow
61498 +# define __size_overflow(...)
61499 +#endif
61500 +
61501 +#ifndef __intentional_overflow
61502 +# define __intentional_overflow(...)
61503 +#endif
61504 +
61505 +#ifndef __latent_entropy
61506 +# define __latent_entropy
61507 +#endif
61508 +
61509 /*
61510 * Tell gcc if a function is cold. The compiler will assume any path
61511 * directly leading to the call is unlikely.
61512 @@ -273,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61513 #define __cold
61514 #endif
61515
61516 +#ifndef __alloc_size
61517 +#define __alloc_size(...)
61518 +#endif
61519 +
61520 +#ifndef __bos
61521 +#define __bos(ptr, arg)
61522 +#endif
61523 +
61524 +#ifndef __bos0
61525 +#define __bos0(ptr)
61526 +#endif
61527 +
61528 +#ifndef __bos1
61529 +#define __bos1(ptr)
61530 +#endif
61531 +
61532 /* Simple shorthand for a section definition */
61533 #ifndef __section
61534 # define __section(S) __attribute__ ((__section__(#S)))
61535 @@ -312,6 +381,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61536 * use is to mediate communication between process-level code and irq/NMI
61537 * handlers, all running on the same CPU.
61538 */
61539 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
61540 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
61541 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
61542
61543 #endif /* __LINUX_COMPILER_H */
61544 diff --git a/include/linux/cred.h b/include/linux/cred.h
61545 index ebbed2c..908cc2c 100644
61546 --- a/include/linux/cred.h
61547 +++ b/include/linux/cred.h
61548 @@ -208,6 +208,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
61549 static inline void validate_process_creds(void)
61550 {
61551 }
61552 +static inline void validate_task_creds(struct task_struct *task)
61553 +{
61554 +}
61555 #endif
61556
61557 /**
61558 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
61559 index b92eadf..b4ecdc1 100644
61560 --- a/include/linux/crypto.h
61561 +++ b/include/linux/crypto.h
61562 @@ -373,7 +373,7 @@ struct cipher_tfm {
61563 const u8 *key, unsigned int keylen);
61564 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61565 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61566 -};
61567 +} __no_const;
61568
61569 struct hash_tfm {
61570 int (*init)(struct hash_desc *desc);
61571 @@ -394,13 +394,13 @@ struct compress_tfm {
61572 int (*cot_decompress)(struct crypto_tfm *tfm,
61573 const u8 *src, unsigned int slen,
61574 u8 *dst, unsigned int *dlen);
61575 -};
61576 +} __no_const;
61577
61578 struct rng_tfm {
61579 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
61580 unsigned int dlen);
61581 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
61582 -};
61583 +} __no_const;
61584
61585 #define crt_ablkcipher crt_u.ablkcipher
61586 #define crt_aead crt_u.aead
61587 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
61588 index 7925bf0..d5143d2 100644
61589 --- a/include/linux/decompress/mm.h
61590 +++ b/include/linux/decompress/mm.h
61591 @@ -77,7 +77,7 @@ static void free(void *where)
61592 * warnings when not needed (indeed large_malloc / large_free are not
61593 * needed by inflate */
61594
61595 -#define malloc(a) kmalloc(a, GFP_KERNEL)
61596 +#define malloc(a) kmalloc((a), GFP_KERNEL)
61597 #define free(a) kfree(a)
61598
61599 #define large_malloc(a) vmalloc(a)
61600 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
61601 index 94af418..b1ca7a2 100644
61602 --- a/include/linux/dma-mapping.h
61603 +++ b/include/linux/dma-mapping.h
61604 @@ -54,7 +54,7 @@ struct dma_map_ops {
61605 u64 (*get_required_mask)(struct device *dev);
61606 #endif
61607 int is_phys;
61608 -};
61609 +} __do_const;
61610
61611 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
61612
61613 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
61614 index 9c02a45..89fdd73 100644
61615 --- a/include/linux/dmaengine.h
61616 +++ b/include/linux/dmaengine.h
61617 @@ -1017,9 +1017,9 @@ struct dma_pinned_list {
61618 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
61619 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
61620
61621 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
61622 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
61623 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
61624 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
61625 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
61626 struct dma_pinned_list *pinned_list, struct page *page,
61627 unsigned int offset, size_t len);
61628
61629 diff --git a/include/linux/efi.h b/include/linux/efi.h
61630 index 5782114..e9b1ba1 100644
61631 --- a/include/linux/efi.h
61632 +++ b/include/linux/efi.h
61633 @@ -640,7 +640,7 @@ struct efivar_operations {
61634 efi_get_variable_t *get_variable;
61635 efi_get_next_variable_t *get_next_variable;
61636 efi_set_variable_t *set_variable;
61637 -};
61638 +} __no_const;
61639
61640 struct efivars {
61641 /*
61642 diff --git a/include/linux/elf.h b/include/linux/elf.h
61643 index 999b4f5..57753b4 100644
61644 --- a/include/linux/elf.h
61645 +++ b/include/linux/elf.h
61646 @@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
61647 #define PT_GNU_EH_FRAME 0x6474e550
61648
61649 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
61650 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
61651 +
61652 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
61653 +
61654 +/* Constants for the e_flags field */
61655 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
61656 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
61657 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
61658 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
61659 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
61660 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
61661
61662 /*
61663 * Extended Numbering
61664 @@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
61665 #define DT_DEBUG 21
61666 #define DT_TEXTREL 22
61667 #define DT_JMPREL 23
61668 +#define DT_FLAGS 30
61669 + #define DF_TEXTREL 0x00000004
61670 #define DT_ENCODING 32
61671 #define OLD_DT_LOOS 0x60000000
61672 #define DT_LOOS 0x6000000d
61673 @@ -243,6 +256,19 @@ typedef struct elf64_hdr {
61674 #define PF_W 0x2
61675 #define PF_X 0x1
61676
61677 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
61678 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
61679 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
61680 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
61681 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
61682 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
61683 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
61684 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
61685 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
61686 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
61687 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
61688 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
61689 +
61690 typedef struct elf32_phdr{
61691 Elf32_Word p_type;
61692 Elf32_Off p_offset;
61693 @@ -335,6 +361,8 @@ typedef struct elf64_shdr {
61694 #define EI_OSABI 7
61695 #define EI_PAD 8
61696
61697 +#define EI_PAX 14
61698 +
61699 #define ELFMAG0 0x7f /* EI_MAG */
61700 #define ELFMAG1 'E'
61701 #define ELFMAG2 'L'
61702 @@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
61703 #define elf_note elf32_note
61704 #define elf_addr_t Elf32_Off
61705 #define Elf_Half Elf32_Half
61706 +#define elf_dyn Elf32_Dyn
61707
61708 #else
61709
61710 @@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
61711 #define elf_note elf64_note
61712 #define elf_addr_t Elf64_Off
61713 #define Elf_Half Elf64_Half
61714 +#define elf_dyn Elf64_Dyn
61715
61716 #endif
61717
61718 diff --git a/include/linux/filter.h b/include/linux/filter.h
61719 index 82b0135..917914d 100644
61720 --- a/include/linux/filter.h
61721 +++ b/include/linux/filter.h
61722 @@ -146,6 +146,7 @@ struct compat_sock_fprog {
61723
61724 struct sk_buff;
61725 struct sock;
61726 +struct bpf_jit_work;
61727
61728 struct sk_filter
61729 {
61730 @@ -153,6 +154,9 @@ struct sk_filter
61731 unsigned int len; /* Number of filter blocks */
61732 unsigned int (*bpf_func)(const struct sk_buff *skb,
61733 const struct sock_filter *filter);
61734 +#ifdef CONFIG_BPF_JIT
61735 + struct bpf_jit_work *work;
61736 +#endif
61737 struct rcu_head rcu;
61738 struct sock_filter insns[0];
61739 };
61740 diff --git a/include/linux/firewire.h b/include/linux/firewire.h
61741 index db04ec5..f6ed627 100644
61742 --- a/include/linux/firewire.h
61743 +++ b/include/linux/firewire.h
61744 @@ -430,7 +430,7 @@ struct fw_iso_context {
61745 union {
61746 fw_iso_callback_t sc;
61747 fw_iso_mc_callback_t mc;
61748 - } callback;
61749 + } __no_const callback;
61750 void *callback_data;
61751 };
61752
61753 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
61754 index 0e4e2ee..4ff4312 100644
61755 --- a/include/linux/frontswap.h
61756 +++ b/include/linux/frontswap.h
61757 @@ -11,7 +11,7 @@ struct frontswap_ops {
61758 int (*load)(unsigned, pgoff_t, struct page *);
61759 void (*invalidate_page)(unsigned, pgoff_t);
61760 void (*invalidate_area)(unsigned);
61761 -};
61762 +} __no_const;
61763
61764 extern bool frontswap_enabled;
61765 extern struct frontswap_ops
61766 diff --git a/include/linux/fs.h b/include/linux/fs.h
61767 index aa11047..7d046d0 100644
61768 --- a/include/linux/fs.h
61769 +++ b/include/linux/fs.h
61770 @@ -1802,7 +1802,8 @@ struct file_operations {
61771 int (*setlease)(struct file *, long, struct file_lock **);
61772 long (*fallocate)(struct file *file, int mode, loff_t offset,
61773 loff_t len);
61774 -};
61775 +} __do_const;
61776 +typedef struct file_operations __no_const file_operations_no_const;
61777
61778 struct inode_operations {
61779 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
61780 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
61781 index 003dc0f..3c4ea97 100644
61782 --- a/include/linux/fs_struct.h
61783 +++ b/include/linux/fs_struct.h
61784 @@ -6,7 +6,7 @@
61785 #include <linux/seqlock.h>
61786
61787 struct fs_struct {
61788 - int users;
61789 + atomic_t users;
61790 spinlock_t lock;
61791 seqcount_t seq;
61792 int umask;
61793 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
61794 index ce31408..b1ad003 100644
61795 --- a/include/linux/fscache-cache.h
61796 +++ b/include/linux/fscache-cache.h
61797 @@ -102,7 +102,7 @@ struct fscache_operation {
61798 fscache_operation_release_t release;
61799 };
61800
61801 -extern atomic_t fscache_op_debug_id;
61802 +extern atomic_unchecked_t fscache_op_debug_id;
61803 extern void fscache_op_work_func(struct work_struct *work);
61804
61805 extern void fscache_enqueue_operation(struct fscache_operation *);
61806 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
61807 {
61808 INIT_WORK(&op->work, fscache_op_work_func);
61809 atomic_set(&op->usage, 1);
61810 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
61811 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
61812 op->processor = processor;
61813 op->release = release;
61814 INIT_LIST_HEAD(&op->pend_link);
61815 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
61816 index a6dfe69..569586df 100644
61817 --- a/include/linux/fsnotify.h
61818 +++ b/include/linux/fsnotify.h
61819 @@ -315,7 +315,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
61820 */
61821 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
61822 {
61823 - return kstrdup(name, GFP_KERNEL);
61824 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
61825 }
61826
61827 /*
61828 diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
61829 index 63d966d..cdcb717 100644
61830 --- a/include/linux/fsnotify_backend.h
61831 +++ b/include/linux/fsnotify_backend.h
61832 @@ -105,6 +105,7 @@ struct fsnotify_ops {
61833 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
61834 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
61835 };
61836 +typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
61837
61838 /*
61839 * A group is a "thing" that wants to receive notification about filesystem
61840 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
61841 index 642928c..e6c83a7 100644
61842 --- a/include/linux/ftrace_event.h
61843 +++ b/include/linux/ftrace_event.h
61844 @@ -97,7 +97,7 @@ struct trace_event_functions {
61845 trace_print_func raw;
61846 trace_print_func hex;
61847 trace_print_func binary;
61848 -};
61849 +} __no_const;
61850
61851 struct trace_event {
61852 struct hlist_node node;
61853 @@ -266,7 +266,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
61854 extern int trace_add_event_call(struct ftrace_event_call *call);
61855 extern void trace_remove_event_call(struct ftrace_event_call *call);
61856
61857 -#define is_signed_type(type) (((type)(-1)) < 0)
61858 +#define is_signed_type(type) (((type)(-1)) < (type)1)
61859
61860 int trace_set_clr_event(const char *system, const char *event, int set);
61861
61862 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
61863 index 4f440b3..342233a 100644
61864 --- a/include/linux/genhd.h
61865 +++ b/include/linux/genhd.h
61866 @@ -190,7 +190,7 @@ struct gendisk {
61867 struct kobject *slave_dir;
61868
61869 struct timer_rand_state *random;
61870 - atomic_t sync_io; /* RAID */
61871 + atomic_unchecked_t sync_io; /* RAID */
61872 struct disk_events *ev;
61873 #ifdef CONFIG_BLK_DEV_INTEGRITY
61874 struct blk_integrity *integrity;
61875 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
61876 index 4883f39..26688a8 100644
61877 --- a/include/linux/gfp.h
61878 +++ b/include/linux/gfp.h
61879 @@ -39,6 +39,12 @@ struct vm_area_struct;
61880 #define ___GFP_OTHER_NODE 0x800000u
61881 #define ___GFP_WRITE 0x1000000u
61882
61883 +#ifdef CONFIG_PAX_USERCOPY_SLABS
61884 +#define ___GFP_USERCOPY 0x2000000u
61885 +#else
61886 +#define ___GFP_USERCOPY 0
61887 +#endif
61888 +
61889 /*
61890 * GFP bitmasks..
61891 *
61892 @@ -93,6 +99,7 @@ struct vm_area_struct;
61893 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
61894 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
61895 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
61896 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
61897
61898 /*
61899 * This may seem redundant, but it's a way of annotating false positives vs.
61900 @@ -100,7 +107,7 @@ struct vm_area_struct;
61901 */
61902 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
61903
61904 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
61905 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
61906 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
61907
61908 /* This equals 0, but use constants in case they ever change */
61909 @@ -154,6 +161,8 @@ struct vm_area_struct;
61910 /* 4GB DMA on some platforms */
61911 #define GFP_DMA32 __GFP_DMA32
61912
61913 +#define GFP_USERCOPY __GFP_USERCOPY
61914 +
61915 /* Convert GFP flags to their corresponding migrate type */
61916 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
61917 {
61918 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
61919 new file mode 100644
61920 index 0000000..c938b1f
61921 --- /dev/null
61922 +++ b/include/linux/gracl.h
61923 @@ -0,0 +1,319 @@
61924 +#ifndef GR_ACL_H
61925 +#define GR_ACL_H
61926 +
61927 +#include <linux/grdefs.h>
61928 +#include <linux/resource.h>
61929 +#include <linux/capability.h>
61930 +#include <linux/dcache.h>
61931 +#include <asm/resource.h>
61932 +
61933 +/* Major status information */
61934 +
61935 +#define GR_VERSION "grsecurity 2.9.1"
61936 +#define GRSECURITY_VERSION 0x2901
61937 +
61938 +enum {
61939 + GR_SHUTDOWN = 0,
61940 + GR_ENABLE = 1,
61941 + GR_SPROLE = 2,
61942 + GR_RELOAD = 3,
61943 + GR_SEGVMOD = 4,
61944 + GR_STATUS = 5,
61945 + GR_UNSPROLE = 6,
61946 + GR_PASSSET = 7,
61947 + GR_SPROLEPAM = 8,
61948 +};
61949 +
61950 +/* Password setup definitions
61951 + * kernel/grhash.c */
61952 +enum {
61953 + GR_PW_LEN = 128,
61954 + GR_SALT_LEN = 16,
61955 + GR_SHA_LEN = 32,
61956 +};
61957 +
61958 +enum {
61959 + GR_SPROLE_LEN = 64,
61960 +};
61961 +
61962 +enum {
61963 + GR_NO_GLOB = 0,
61964 + GR_REG_GLOB,
61965 + GR_CREATE_GLOB
61966 +};
61967 +
61968 +#define GR_NLIMITS 32
61969 +
61970 +/* Begin Data Structures */
61971 +
61972 +struct sprole_pw {
61973 + unsigned char *rolename;
61974 + unsigned char salt[GR_SALT_LEN];
61975 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
61976 +};
61977 +
61978 +struct name_entry {
61979 + __u32 key;
61980 + ino_t inode;
61981 + dev_t device;
61982 + char *name;
61983 + __u16 len;
61984 + __u8 deleted;
61985 + struct name_entry *prev;
61986 + struct name_entry *next;
61987 +};
61988 +
61989 +struct inodev_entry {
61990 + struct name_entry *nentry;
61991 + struct inodev_entry *prev;
61992 + struct inodev_entry *next;
61993 +};
61994 +
61995 +struct acl_role_db {
61996 + struct acl_role_label **r_hash;
61997 + __u32 r_size;
61998 +};
61999 +
62000 +struct inodev_db {
62001 + struct inodev_entry **i_hash;
62002 + __u32 i_size;
62003 +};
62004 +
62005 +struct name_db {
62006 + struct name_entry **n_hash;
62007 + __u32 n_size;
62008 +};
62009 +
62010 +struct crash_uid {
62011 + uid_t uid;
62012 + unsigned long expires;
62013 +};
62014 +
62015 +struct gr_hash_struct {
62016 + void **table;
62017 + void **nametable;
62018 + void *first;
62019 + __u32 table_size;
62020 + __u32 used_size;
62021 + int type;
62022 +};
62023 +
62024 +/* Userspace Grsecurity ACL data structures */
62025 +
62026 +struct acl_subject_label {
62027 + char *filename;
62028 + ino_t inode;
62029 + dev_t device;
62030 + __u32 mode;
62031 + kernel_cap_t cap_mask;
62032 + kernel_cap_t cap_lower;
62033 + kernel_cap_t cap_invert_audit;
62034 +
62035 + struct rlimit res[GR_NLIMITS];
62036 + __u32 resmask;
62037 +
62038 + __u8 user_trans_type;
62039 + __u8 group_trans_type;
62040 + uid_t *user_transitions;
62041 + gid_t *group_transitions;
62042 + __u16 user_trans_num;
62043 + __u16 group_trans_num;
62044 +
62045 + __u32 sock_families[2];
62046 + __u32 ip_proto[8];
62047 + __u32 ip_type;
62048 + struct acl_ip_label **ips;
62049 + __u32 ip_num;
62050 + __u32 inaddr_any_override;
62051 +
62052 + __u32 crashes;
62053 + unsigned long expires;
62054 +
62055 + struct acl_subject_label *parent_subject;
62056 + struct gr_hash_struct *hash;
62057 + struct acl_subject_label *prev;
62058 + struct acl_subject_label *next;
62059 +
62060 + struct acl_object_label **obj_hash;
62061 + __u32 obj_hash_size;
62062 + __u16 pax_flags;
62063 +};
62064 +
62065 +struct role_allowed_ip {
62066 + __u32 addr;
62067 + __u32 netmask;
62068 +
62069 + struct role_allowed_ip *prev;
62070 + struct role_allowed_ip *next;
62071 +};
62072 +
62073 +struct role_transition {
62074 + char *rolename;
62075 +
62076 + struct role_transition *prev;
62077 + struct role_transition *next;
62078 +};
62079 +
62080 +struct acl_role_label {
62081 + char *rolename;
62082 + uid_t uidgid;
62083 + __u16 roletype;
62084 +
62085 + __u16 auth_attempts;
62086 + unsigned long expires;
62087 +
62088 + struct acl_subject_label *root_label;
62089 + struct gr_hash_struct *hash;
62090 +
62091 + struct acl_role_label *prev;
62092 + struct acl_role_label *next;
62093 +
62094 + struct role_transition *transitions;
62095 + struct role_allowed_ip *allowed_ips;
62096 + uid_t *domain_children;
62097 + __u16 domain_child_num;
62098 +
62099 + umode_t umask;
62100 +
62101 + struct acl_subject_label **subj_hash;
62102 + __u32 subj_hash_size;
62103 +};
62104 +
62105 +struct user_acl_role_db {
62106 + struct acl_role_label **r_table;
62107 + __u32 num_pointers; /* Number of allocations to track */
62108 + __u32 num_roles; /* Number of roles */
62109 + __u32 num_domain_children; /* Number of domain children */
62110 + __u32 num_subjects; /* Number of subjects */
62111 + __u32 num_objects; /* Number of objects */
62112 +};
62113 +
62114 +struct acl_object_label {
62115 + char *filename;
62116 + ino_t inode;
62117 + dev_t device;
62118 + __u32 mode;
62119 +
62120 + struct acl_subject_label *nested;
62121 + struct acl_object_label *globbed;
62122 +
62123 + /* next two structures not used */
62124 +
62125 + struct acl_object_label *prev;
62126 + struct acl_object_label *next;
62127 +};
62128 +
62129 +struct acl_ip_label {
62130 + char *iface;
62131 + __u32 addr;
62132 + __u32 netmask;
62133 + __u16 low, high;
62134 + __u8 mode;
62135 + __u32 type;
62136 + __u32 proto[8];
62137 +
62138 + /* next two structures not used */
62139 +
62140 + struct acl_ip_label *prev;
62141 + struct acl_ip_label *next;
62142 +};
62143 +
62144 +struct gr_arg {
62145 + struct user_acl_role_db role_db;
62146 + unsigned char pw[GR_PW_LEN];
62147 + unsigned char salt[GR_SALT_LEN];
62148 + unsigned char sum[GR_SHA_LEN];
62149 + unsigned char sp_role[GR_SPROLE_LEN];
62150 + struct sprole_pw *sprole_pws;
62151 + dev_t segv_device;
62152 + ino_t segv_inode;
62153 + uid_t segv_uid;
62154 + __u16 num_sprole_pws;
62155 + __u16 mode;
62156 +};
62157 +
62158 +struct gr_arg_wrapper {
62159 + struct gr_arg *arg;
62160 + __u32 version;
62161 + __u32 size;
62162 +};
62163 +
62164 +struct subject_map {
62165 + struct acl_subject_label *user;
62166 + struct acl_subject_label *kernel;
62167 + struct subject_map *prev;
62168 + struct subject_map *next;
62169 +};
62170 +
62171 +struct acl_subj_map_db {
62172 + struct subject_map **s_hash;
62173 + __u32 s_size;
62174 +};
62175 +
62176 +/* End Data Structures Section */
62177 +
62178 +/* Hash functions generated by empirical testing by Brad Spengler
62179 + Makes good use of the low bits of the inode. Generally 0-1 times
62180 + in loop for successful match. 0-3 for unsuccessful match.
62181 + Shift/add algorithm with modulus of table size and an XOR*/
62182 +
62183 +static __inline__ unsigned int
62184 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
62185 +{
62186 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
62187 +}
62188 +
62189 + static __inline__ unsigned int
62190 +shash(const struct acl_subject_label *userp, const unsigned int sz)
62191 +{
62192 + return ((const unsigned long)userp % sz);
62193 +}
62194 +
62195 +static __inline__ unsigned int
62196 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
62197 +{
62198 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
62199 +}
62200 +
62201 +static __inline__ unsigned int
62202 +nhash(const char *name, const __u16 len, const unsigned int sz)
62203 +{
62204 + return full_name_hash((const unsigned char *)name, len) % sz;
62205 +}
62206 +
62207 +#define FOR_EACH_ROLE_START(role) \
62208 + role = role_list; \
62209 + while (role) {
62210 +
62211 +#define FOR_EACH_ROLE_END(role) \
62212 + role = role->prev; \
62213 + }
62214 +
62215 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
62216 + subj = NULL; \
62217 + iter = 0; \
62218 + while (iter < role->subj_hash_size) { \
62219 + if (subj == NULL) \
62220 + subj = role->subj_hash[iter]; \
62221 + if (subj == NULL) { \
62222 + iter++; \
62223 + continue; \
62224 + }
62225 +
62226 +#define FOR_EACH_SUBJECT_END(subj,iter) \
62227 + subj = subj->next; \
62228 + if (subj == NULL) \
62229 + iter++; \
62230 + }
62231 +
62232 +
62233 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
62234 + subj = role->hash->first; \
62235 + while (subj != NULL) {
62236 +
62237 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
62238 + subj = subj->next; \
62239 + }
62240 +
62241 +#endif
62242 +
62243 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
62244 new file mode 100644
62245 index 0000000..323ecf2
62246 --- /dev/null
62247 +++ b/include/linux/gralloc.h
62248 @@ -0,0 +1,9 @@
62249 +#ifndef __GRALLOC_H
62250 +#define __GRALLOC_H
62251 +
62252 +void acl_free_all(void);
62253 +int acl_alloc_stack_init(unsigned long size);
62254 +void *acl_alloc(unsigned long len);
62255 +void *acl_alloc_num(unsigned long num, unsigned long len);
62256 +
62257 +#endif
62258 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
62259 new file mode 100644
62260 index 0000000..b30e9bc
62261 --- /dev/null
62262 +++ b/include/linux/grdefs.h
62263 @@ -0,0 +1,140 @@
62264 +#ifndef GRDEFS_H
62265 +#define GRDEFS_H
62266 +
62267 +/* Begin grsecurity status declarations */
62268 +
62269 +enum {
62270 + GR_READY = 0x01,
62271 + GR_STATUS_INIT = 0x00 // disabled state
62272 +};
62273 +
62274 +/* Begin ACL declarations */
62275 +
62276 +/* Role flags */
62277 +
62278 +enum {
62279 + GR_ROLE_USER = 0x0001,
62280 + GR_ROLE_GROUP = 0x0002,
62281 + GR_ROLE_DEFAULT = 0x0004,
62282 + GR_ROLE_SPECIAL = 0x0008,
62283 + GR_ROLE_AUTH = 0x0010,
62284 + GR_ROLE_NOPW = 0x0020,
62285 + GR_ROLE_GOD = 0x0040,
62286 + GR_ROLE_LEARN = 0x0080,
62287 + GR_ROLE_TPE = 0x0100,
62288 + GR_ROLE_DOMAIN = 0x0200,
62289 + GR_ROLE_PAM = 0x0400,
62290 + GR_ROLE_PERSIST = 0x0800
62291 +};
62292 +
62293 +/* ACL Subject and Object mode flags */
62294 +enum {
62295 + GR_DELETED = 0x80000000
62296 +};
62297 +
62298 +/* ACL Object-only mode flags */
62299 +enum {
62300 + GR_READ = 0x00000001,
62301 + GR_APPEND = 0x00000002,
62302 + GR_WRITE = 0x00000004,
62303 + GR_EXEC = 0x00000008,
62304 + GR_FIND = 0x00000010,
62305 + GR_INHERIT = 0x00000020,
62306 + GR_SETID = 0x00000040,
62307 + GR_CREATE = 0x00000080,
62308 + GR_DELETE = 0x00000100,
62309 + GR_LINK = 0x00000200,
62310 + GR_AUDIT_READ = 0x00000400,
62311 + GR_AUDIT_APPEND = 0x00000800,
62312 + GR_AUDIT_WRITE = 0x00001000,
62313 + GR_AUDIT_EXEC = 0x00002000,
62314 + GR_AUDIT_FIND = 0x00004000,
62315 + GR_AUDIT_INHERIT= 0x00008000,
62316 + GR_AUDIT_SETID = 0x00010000,
62317 + GR_AUDIT_CREATE = 0x00020000,
62318 + GR_AUDIT_DELETE = 0x00040000,
62319 + GR_AUDIT_LINK = 0x00080000,
62320 + GR_PTRACERD = 0x00100000,
62321 + GR_NOPTRACE = 0x00200000,
62322 + GR_SUPPRESS = 0x00400000,
62323 + GR_NOLEARN = 0x00800000,
62324 + GR_INIT_TRANSFER= 0x01000000
62325 +};
62326 +
62327 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
62328 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
62329 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
62330 +
62331 +/* ACL subject-only mode flags */
62332 +enum {
62333 + GR_KILL = 0x00000001,
62334 + GR_VIEW = 0x00000002,
62335 + GR_PROTECTED = 0x00000004,
62336 + GR_LEARN = 0x00000008,
62337 + GR_OVERRIDE = 0x00000010,
62338 + /* just a placeholder, this mode is only used in userspace */
62339 + GR_DUMMY = 0x00000020,
62340 + GR_PROTSHM = 0x00000040,
62341 + GR_KILLPROC = 0x00000080,
62342 + GR_KILLIPPROC = 0x00000100,
62343 + /* just a placeholder, this mode is only used in userspace */
62344 + GR_NOTROJAN = 0x00000200,
62345 + GR_PROTPROCFD = 0x00000400,
62346 + GR_PROCACCT = 0x00000800,
62347 + GR_RELAXPTRACE = 0x00001000,
62348 + GR_NESTED = 0x00002000,
62349 + GR_INHERITLEARN = 0x00004000,
62350 + GR_PROCFIND = 0x00008000,
62351 + GR_POVERRIDE = 0x00010000,
62352 + GR_KERNELAUTH = 0x00020000,
62353 + GR_ATSECURE = 0x00040000,
62354 + GR_SHMEXEC = 0x00080000
62355 +};
62356 +
62357 +enum {
62358 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
62359 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
62360 + GR_PAX_ENABLE_MPROTECT = 0x0004,
62361 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
62362 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
62363 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
62364 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
62365 + GR_PAX_DISABLE_MPROTECT = 0x0400,
62366 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
62367 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
62368 +};
62369 +
62370 +enum {
62371 + GR_ID_USER = 0x01,
62372 + GR_ID_GROUP = 0x02,
62373 +};
62374 +
62375 +enum {
62376 + GR_ID_ALLOW = 0x01,
62377 + GR_ID_DENY = 0x02,
62378 +};
62379 +
62380 +#define GR_CRASH_RES 31
62381 +#define GR_UIDTABLE_MAX 500
62382 +
62383 +/* begin resource learning section */
62384 +enum {
62385 + GR_RLIM_CPU_BUMP = 60,
62386 + GR_RLIM_FSIZE_BUMP = 50000,
62387 + GR_RLIM_DATA_BUMP = 10000,
62388 + GR_RLIM_STACK_BUMP = 1000,
62389 + GR_RLIM_CORE_BUMP = 10000,
62390 + GR_RLIM_RSS_BUMP = 500000,
62391 + GR_RLIM_NPROC_BUMP = 1,
62392 + GR_RLIM_NOFILE_BUMP = 5,
62393 + GR_RLIM_MEMLOCK_BUMP = 50000,
62394 + GR_RLIM_AS_BUMP = 500000,
62395 + GR_RLIM_LOCKS_BUMP = 2,
62396 + GR_RLIM_SIGPENDING_BUMP = 5,
62397 + GR_RLIM_MSGQUEUE_BUMP = 10000,
62398 + GR_RLIM_NICE_BUMP = 1,
62399 + GR_RLIM_RTPRIO_BUMP = 1,
62400 + GR_RLIM_RTTIME_BUMP = 1000000
62401 +};
62402 +
62403 +#endif
62404 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
62405 new file mode 100644
62406 index 0000000..c9292f7
62407 --- /dev/null
62408 +++ b/include/linux/grinternal.h
62409 @@ -0,0 +1,223 @@
62410 +#ifndef __GRINTERNAL_H
62411 +#define __GRINTERNAL_H
62412 +
62413 +#ifdef CONFIG_GRKERNSEC
62414 +
62415 +#include <linux/fs.h>
62416 +#include <linux/mnt_namespace.h>
62417 +#include <linux/nsproxy.h>
62418 +#include <linux/gracl.h>
62419 +#include <linux/grdefs.h>
62420 +#include <linux/grmsg.h>
62421 +
62422 +void gr_add_learn_entry(const char *fmt, ...)
62423 + __attribute__ ((format (printf, 1, 2)));
62424 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
62425 + const struct vfsmount *mnt);
62426 +__u32 gr_check_create(const struct dentry *new_dentry,
62427 + const struct dentry *parent,
62428 + const struct vfsmount *mnt, const __u32 mode);
62429 +int gr_check_protected_task(const struct task_struct *task);
62430 +__u32 to_gr_audit(const __u32 reqmode);
62431 +int gr_set_acls(const int type);
62432 +int gr_apply_subject_to_task(struct task_struct *task);
62433 +int gr_acl_is_enabled(void);
62434 +char gr_roletype_to_char(void);
62435 +
62436 +void gr_handle_alertkill(struct task_struct *task);
62437 +char *gr_to_filename(const struct dentry *dentry,
62438 + const struct vfsmount *mnt);
62439 +char *gr_to_filename1(const struct dentry *dentry,
62440 + const struct vfsmount *mnt);
62441 +char *gr_to_filename2(const struct dentry *dentry,
62442 + const struct vfsmount *mnt);
62443 +char *gr_to_filename3(const struct dentry *dentry,
62444 + const struct vfsmount *mnt);
62445 +
62446 +extern int grsec_enable_ptrace_readexec;
62447 +extern int grsec_enable_harden_ptrace;
62448 +extern int grsec_enable_link;
62449 +extern int grsec_enable_fifo;
62450 +extern int grsec_enable_execve;
62451 +extern int grsec_enable_shm;
62452 +extern int grsec_enable_execlog;
62453 +extern int grsec_enable_signal;
62454 +extern int grsec_enable_audit_ptrace;
62455 +extern int grsec_enable_forkfail;
62456 +extern int grsec_enable_time;
62457 +extern int grsec_enable_rofs;
62458 +extern int grsec_enable_chroot_shmat;
62459 +extern int grsec_enable_chroot_mount;
62460 +extern int grsec_enable_chroot_double;
62461 +extern int grsec_enable_chroot_pivot;
62462 +extern int grsec_enable_chroot_chdir;
62463 +extern int grsec_enable_chroot_chmod;
62464 +extern int grsec_enable_chroot_mknod;
62465 +extern int grsec_enable_chroot_fchdir;
62466 +extern int grsec_enable_chroot_nice;
62467 +extern int grsec_enable_chroot_execlog;
62468 +extern int grsec_enable_chroot_caps;
62469 +extern int grsec_enable_chroot_sysctl;
62470 +extern int grsec_enable_chroot_unix;
62471 +extern int grsec_enable_symlinkown;
62472 +extern int grsec_symlinkown_gid;
62473 +extern int grsec_enable_tpe;
62474 +extern int grsec_tpe_gid;
62475 +extern int grsec_enable_tpe_all;
62476 +extern int grsec_enable_tpe_invert;
62477 +extern int grsec_enable_socket_all;
62478 +extern int grsec_socket_all_gid;
62479 +extern int grsec_enable_socket_client;
62480 +extern int grsec_socket_client_gid;
62481 +extern int grsec_enable_socket_server;
62482 +extern int grsec_socket_server_gid;
62483 +extern int grsec_audit_gid;
62484 +extern int grsec_enable_group;
62485 +extern int grsec_enable_audit_textrel;
62486 +extern int grsec_enable_log_rwxmaps;
62487 +extern int grsec_enable_mount;
62488 +extern int grsec_enable_chdir;
62489 +extern int grsec_resource_logging;
62490 +extern int grsec_enable_blackhole;
62491 +extern int grsec_lastack_retries;
62492 +extern int grsec_enable_brute;
62493 +extern int grsec_lock;
62494 +
62495 +extern spinlock_t grsec_alert_lock;
62496 +extern unsigned long grsec_alert_wtime;
62497 +extern unsigned long grsec_alert_fyet;
62498 +
62499 +extern spinlock_t grsec_audit_lock;
62500 +
62501 +extern rwlock_t grsec_exec_file_lock;
62502 +
62503 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
62504 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
62505 + (tsk)->exec_file->f_vfsmnt) : "/")
62506 +
62507 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
62508 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
62509 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62510 +
62511 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
62512 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
62513 + (tsk)->exec_file->f_vfsmnt) : "/")
62514 +
62515 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
62516 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
62517 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62518 +
62519 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
62520 +
62521 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
62522 +
62523 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
62524 + (task)->pid, (cred)->uid, \
62525 + (cred)->euid, (cred)->gid, (cred)->egid, \
62526 + gr_parent_task_fullpath(task), \
62527 + (task)->real_parent->comm, (task)->real_parent->pid, \
62528 + (pcred)->uid, (pcred)->euid, \
62529 + (pcred)->gid, (pcred)->egid
62530 +
62531 +#define GR_CHROOT_CAPS {{ \
62532 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
62533 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
62534 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
62535 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
62536 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
62537 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
62538 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
62539 +
62540 +#define security_learn(normal_msg,args...) \
62541 +({ \
62542 + read_lock(&grsec_exec_file_lock); \
62543 + gr_add_learn_entry(normal_msg "\n", ## args); \
62544 + read_unlock(&grsec_exec_file_lock); \
62545 +})
62546 +
62547 +enum {
62548 + GR_DO_AUDIT,
62549 + GR_DONT_AUDIT,
62550 + /* used for non-audit messages that we shouldn't kill the task on */
62551 + GR_DONT_AUDIT_GOOD
62552 +};
62553 +
62554 +enum {
62555 + GR_TTYSNIFF,
62556 + GR_RBAC,
62557 + GR_RBAC_STR,
62558 + GR_STR_RBAC,
62559 + GR_RBAC_MODE2,
62560 + GR_RBAC_MODE3,
62561 + GR_FILENAME,
62562 + GR_SYSCTL_HIDDEN,
62563 + GR_NOARGS,
62564 + GR_ONE_INT,
62565 + GR_ONE_INT_TWO_STR,
62566 + GR_ONE_STR,
62567 + GR_STR_INT,
62568 + GR_TWO_STR_INT,
62569 + GR_TWO_INT,
62570 + GR_TWO_U64,
62571 + GR_THREE_INT,
62572 + GR_FIVE_INT_TWO_STR,
62573 + GR_TWO_STR,
62574 + GR_THREE_STR,
62575 + GR_FOUR_STR,
62576 + GR_STR_FILENAME,
62577 + GR_FILENAME_STR,
62578 + GR_FILENAME_TWO_INT,
62579 + GR_FILENAME_TWO_INT_STR,
62580 + GR_TEXTREL,
62581 + GR_PTRACE,
62582 + GR_RESOURCE,
62583 + GR_CAP,
62584 + GR_SIG,
62585 + GR_SIG2,
62586 + GR_CRASH1,
62587 + GR_CRASH2,
62588 + GR_PSACCT,
62589 + GR_RWXMAP
62590 +};
62591 +
62592 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
62593 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
62594 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
62595 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
62596 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
62597 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
62598 +#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)
62599 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
62600 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
62601 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
62602 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
62603 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
62604 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
62605 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
62606 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
62607 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
62608 +#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)
62609 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
62610 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
62611 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
62612 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
62613 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
62614 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
62615 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
62616 +#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)
62617 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
62618 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
62619 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
62620 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
62621 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
62622 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
62623 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
62624 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
62625 +#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)
62626 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
62627 +
62628 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
62629 +
62630 +#endif
62631 +
62632 +#endif
62633 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
62634 new file mode 100644
62635 index 0000000..54f4e85
62636 --- /dev/null
62637 +++ b/include/linux/grmsg.h
62638 @@ -0,0 +1,110 @@
62639 +#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"
62640 +#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"
62641 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
62642 +#define GR_STOPMOD_MSG "denied modification of module state by "
62643 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
62644 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
62645 +#define GR_IOPERM_MSG "denied use of ioperm() by "
62646 +#define GR_IOPL_MSG "denied use of iopl() by "
62647 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
62648 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
62649 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
62650 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
62651 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
62652 +#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"
62653 +#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"
62654 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
62655 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
62656 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
62657 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
62658 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
62659 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
62660 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
62661 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
62662 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
62663 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
62664 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
62665 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
62666 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
62667 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
62668 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
62669 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
62670 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
62671 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
62672 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
62673 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
62674 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
62675 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
62676 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
62677 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
62678 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
62679 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
62680 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
62681 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
62682 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
62683 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
62684 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
62685 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
62686 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
62687 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
62688 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
62689 +#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"
62690 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
62691 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
62692 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
62693 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
62694 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
62695 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
62696 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
62697 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
62698 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
62699 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
62700 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
62701 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
62702 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
62703 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
62704 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
62705 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
62706 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
62707 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
62708 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
62709 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
62710 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
62711 +#define GR_NICE_CHROOT_MSG "denied priority change by "
62712 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
62713 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
62714 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
62715 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
62716 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
62717 +#define GR_TIME_MSG "time set by "
62718 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
62719 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
62720 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
62721 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
62722 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
62723 +#define GR_BIND_MSG "denied bind() by "
62724 +#define GR_CONNECT_MSG "denied connect() by "
62725 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
62726 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
62727 +#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"
62728 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
62729 +#define GR_CAP_ACL_MSG "use of %s denied for "
62730 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
62731 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
62732 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
62733 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
62734 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
62735 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
62736 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
62737 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
62738 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
62739 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
62740 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
62741 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
62742 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
62743 +#define GR_VM86_MSG "denied use of vm86 by "
62744 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
62745 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
62746 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
62747 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
62748 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
62749 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
62750 new file mode 100644
62751 index 0000000..f9b9a21
62752 --- /dev/null
62753 +++ b/include/linux/grsecurity.h
62754 @@ -0,0 +1,238 @@
62755 +#ifndef GR_SECURITY_H
62756 +#define GR_SECURITY_H
62757 +#include <linux/fs.h>
62758 +#include <linux/fs_struct.h>
62759 +#include <linux/binfmts.h>
62760 +#include <linux/gracl.h>
62761 +
62762 +/* notify of brain-dead configs */
62763 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62764 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
62765 +#endif
62766 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
62767 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
62768 +#endif
62769 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
62770 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
62771 +#endif
62772 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
62773 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
62774 +#endif
62775 +
62776 +#include <linux/compat.h>
62777 +
62778 +struct user_arg_ptr {
62779 +#ifdef CONFIG_COMPAT
62780 + bool is_compat;
62781 +#endif
62782 + union {
62783 + const char __user *const __user *native;
62784 +#ifdef CONFIG_COMPAT
62785 + compat_uptr_t __user *compat;
62786 +#endif
62787 + } ptr;
62788 +};
62789 +
62790 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
62791 +void gr_handle_brute_check(void);
62792 +void gr_handle_kernel_exploit(void);
62793 +int gr_process_user_ban(void);
62794 +
62795 +char gr_roletype_to_char(void);
62796 +
62797 +int gr_acl_enable_at_secure(void);
62798 +
62799 +int gr_check_user_change(int real, int effective, int fs);
62800 +int gr_check_group_change(int real, int effective, int fs);
62801 +
62802 +void gr_del_task_from_ip_table(struct task_struct *p);
62803 +
62804 +int gr_pid_is_chrooted(struct task_struct *p);
62805 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
62806 +int gr_handle_chroot_nice(void);
62807 +int gr_handle_chroot_sysctl(const int op);
62808 +int gr_handle_chroot_setpriority(struct task_struct *p,
62809 + const int niceval);
62810 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
62811 +int gr_handle_chroot_chroot(const struct dentry *dentry,
62812 + const struct vfsmount *mnt);
62813 +void gr_handle_chroot_chdir(struct path *path);
62814 +int gr_handle_chroot_chmod(const struct dentry *dentry,
62815 + const struct vfsmount *mnt, const int mode);
62816 +int gr_handle_chroot_mknod(const struct dentry *dentry,
62817 + const struct vfsmount *mnt, const int mode);
62818 +int gr_handle_chroot_mount(const struct dentry *dentry,
62819 + const struct vfsmount *mnt,
62820 + const char *dev_name);
62821 +int gr_handle_chroot_pivot(void);
62822 +int gr_handle_chroot_unix(const pid_t pid);
62823 +
62824 +int gr_handle_rawio(const struct inode *inode);
62825 +
62826 +void gr_handle_ioperm(void);
62827 +void gr_handle_iopl(void);
62828 +
62829 +umode_t gr_acl_umask(void);
62830 +
62831 +int gr_tpe_allow(const struct file *file);
62832 +
62833 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
62834 +void gr_clear_chroot_entries(struct task_struct *task);
62835 +
62836 +void gr_log_forkfail(const int retval);
62837 +void gr_log_timechange(void);
62838 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
62839 +void gr_log_chdir(const struct dentry *dentry,
62840 + const struct vfsmount *mnt);
62841 +void gr_log_chroot_exec(const struct dentry *dentry,
62842 + const struct vfsmount *mnt);
62843 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
62844 +void gr_log_remount(const char *devname, const int retval);
62845 +void gr_log_unmount(const char *devname, const int retval);
62846 +void gr_log_mount(const char *from, const char *to, const int retval);
62847 +void gr_log_textrel(struct vm_area_struct *vma);
62848 +void gr_log_rwxmmap(struct file *file);
62849 +void gr_log_rwxmprotect(struct file *file);
62850 +
62851 +int gr_handle_follow_link(const struct inode *parent,
62852 + const struct inode *inode,
62853 + const struct dentry *dentry,
62854 + const struct vfsmount *mnt);
62855 +int gr_handle_fifo(const struct dentry *dentry,
62856 + const struct vfsmount *mnt,
62857 + const struct dentry *dir, const int flag,
62858 + const int acc_mode);
62859 +int gr_handle_hardlink(const struct dentry *dentry,
62860 + const struct vfsmount *mnt,
62861 + struct inode *inode,
62862 + const int mode, const char *to);
62863 +
62864 +int gr_is_capable(const int cap);
62865 +int gr_is_capable_nolog(const int cap);
62866 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
62867 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
62868 +
62869 +void gr_learn_resource(const struct task_struct *task, const int limit,
62870 + const unsigned long wanted, const int gt);
62871 +void gr_copy_label(struct task_struct *tsk);
62872 +void gr_handle_crash(struct task_struct *task, const int sig);
62873 +int gr_handle_signal(const struct task_struct *p, const int sig);
62874 +int gr_check_crash_uid(const uid_t uid);
62875 +int gr_check_protected_task(const struct task_struct *task);
62876 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
62877 +int gr_acl_handle_mmap(const struct file *file,
62878 + const unsigned long prot);
62879 +int gr_acl_handle_mprotect(const struct file *file,
62880 + const unsigned long prot);
62881 +int gr_check_hidden_task(const struct task_struct *tsk);
62882 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
62883 + const struct vfsmount *mnt);
62884 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
62885 + const struct vfsmount *mnt);
62886 +__u32 gr_acl_handle_access(const struct dentry *dentry,
62887 + const struct vfsmount *mnt, const int fmode);
62888 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
62889 + const struct vfsmount *mnt, umode_t *mode);
62890 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
62891 + const struct vfsmount *mnt);
62892 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
62893 + const struct vfsmount *mnt);
62894 +int gr_handle_ptrace(struct task_struct *task, const long request);
62895 +int gr_handle_proc_ptrace(struct task_struct *task);
62896 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
62897 + const struct vfsmount *mnt);
62898 +int gr_check_crash_exec(const struct file *filp);
62899 +int gr_acl_is_enabled(void);
62900 +void gr_set_kernel_label(struct task_struct *task);
62901 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
62902 + const gid_t gid);
62903 +int gr_set_proc_label(const struct dentry *dentry,
62904 + const struct vfsmount *mnt,
62905 + const int unsafe_flags);
62906 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
62907 + const struct vfsmount *mnt);
62908 +__u32 gr_acl_handle_open(const struct dentry *dentry,
62909 + const struct vfsmount *mnt, int acc_mode);
62910 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
62911 + const struct dentry *p_dentry,
62912 + const struct vfsmount *p_mnt,
62913 + int open_flags, int acc_mode, const int imode);
62914 +void gr_handle_create(const struct dentry *dentry,
62915 + const struct vfsmount *mnt);
62916 +void gr_handle_proc_create(const struct dentry *dentry,
62917 + const struct inode *inode);
62918 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
62919 + const struct dentry *parent_dentry,
62920 + const struct vfsmount *parent_mnt,
62921 + const int mode);
62922 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
62923 + const struct dentry *parent_dentry,
62924 + const struct vfsmount *parent_mnt);
62925 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
62926 + const struct vfsmount *mnt);
62927 +void gr_handle_delete(const ino_t ino, const dev_t dev);
62928 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
62929 + const struct vfsmount *mnt);
62930 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
62931 + const struct dentry *parent_dentry,
62932 + const struct vfsmount *parent_mnt,
62933 + const char *from);
62934 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
62935 + const struct dentry *parent_dentry,
62936 + const struct vfsmount *parent_mnt,
62937 + const struct dentry *old_dentry,
62938 + const struct vfsmount *old_mnt, const char *to);
62939 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
62940 +int gr_acl_handle_rename(struct dentry *new_dentry,
62941 + struct dentry *parent_dentry,
62942 + const struct vfsmount *parent_mnt,
62943 + struct dentry *old_dentry,
62944 + struct inode *old_parent_inode,
62945 + struct vfsmount *old_mnt, const char *newname);
62946 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
62947 + struct dentry *old_dentry,
62948 + struct dentry *new_dentry,
62949 + struct vfsmount *mnt, const __u8 replace);
62950 +__u32 gr_check_link(const struct dentry *new_dentry,
62951 + const struct dentry *parent_dentry,
62952 + const struct vfsmount *parent_mnt,
62953 + const struct dentry *old_dentry,
62954 + const struct vfsmount *old_mnt);
62955 +int gr_acl_handle_filldir(const struct file *file, const char *name,
62956 + const unsigned int namelen, const ino_t ino);
62957 +
62958 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
62959 + const struct vfsmount *mnt);
62960 +void gr_acl_handle_exit(void);
62961 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
62962 +int gr_acl_handle_procpidmem(const struct task_struct *task);
62963 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
62964 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
62965 +void gr_audit_ptrace(struct task_struct *task);
62966 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
62967 +
62968 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
62969 +
62970 +#ifdef CONFIG_GRKERNSEC
62971 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
62972 +void gr_handle_vm86(void);
62973 +void gr_handle_mem_readwrite(u64 from, u64 to);
62974 +
62975 +void gr_log_badprocpid(const char *entry);
62976 +
62977 +extern int grsec_enable_dmesg;
62978 +extern int grsec_disable_privio;
62979 +
62980 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62981 +extern int grsec_proc_gid;
62982 +#endif
62983 +
62984 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62985 +extern int grsec_enable_chroot_findtask;
62986 +#endif
62987 +#ifdef CONFIG_GRKERNSEC_SETXID
62988 +extern int grsec_enable_setxid;
62989 +#endif
62990 +#endif
62991 +
62992 +#endif
62993 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
62994 new file mode 100644
62995 index 0000000..e7ffaaf
62996 --- /dev/null
62997 +++ b/include/linux/grsock.h
62998 @@ -0,0 +1,19 @@
62999 +#ifndef __GRSOCK_H
63000 +#define __GRSOCK_H
63001 +
63002 +extern void gr_attach_curr_ip(const struct sock *sk);
63003 +extern int gr_handle_sock_all(const int family, const int type,
63004 + const int protocol);
63005 +extern int gr_handle_sock_server(const struct sockaddr *sck);
63006 +extern int gr_handle_sock_server_other(const struct sock *sck);
63007 +extern int gr_handle_sock_client(const struct sockaddr *sck);
63008 +extern int gr_search_connect(struct socket * sock,
63009 + struct sockaddr_in * addr);
63010 +extern int gr_search_bind(struct socket * sock,
63011 + struct sockaddr_in * addr);
63012 +extern int gr_search_listen(struct socket * sock);
63013 +extern int gr_search_accept(struct socket * sock);
63014 +extern int gr_search_socket(const int domain, const int type,
63015 + const int protocol);
63016 +
63017 +#endif
63018 diff --git a/include/linux/hid.h b/include/linux/hid.h
63019 index 42970de..5db3c92 100644
63020 --- a/include/linux/hid.h
63021 +++ b/include/linux/hid.h
63022 @@ -705,7 +705,7 @@ struct hid_ll_driver {
63023 unsigned int code, int value);
63024
63025 int (*parse)(struct hid_device *hdev);
63026 -};
63027 +} __no_const;
63028
63029 #define PM_HINT_FULLON 1<<5
63030 #define PM_HINT_NORMAL 1<<1
63031 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
63032 index ef788b5..ac41b7b 100644
63033 --- a/include/linux/highmem.h
63034 +++ b/include/linux/highmem.h
63035 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
63036 kunmap_atomic(kaddr);
63037 }
63038
63039 +static inline void sanitize_highpage(struct page *page)
63040 +{
63041 + void *kaddr;
63042 + unsigned long flags;
63043 +
63044 + local_irq_save(flags);
63045 + kaddr = kmap_atomic(page);
63046 + clear_page(kaddr);
63047 + kunmap_atomic(kaddr);
63048 + local_irq_restore(flags);
63049 +}
63050 +
63051 static inline void zero_user_segments(struct page *page,
63052 unsigned start1, unsigned end1,
63053 unsigned start2, unsigned end2)
63054 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
63055 index 5970266..1c48c3b 100644
63056 --- a/include/linux/i2c.h
63057 +++ b/include/linux/i2c.h
63058 @@ -369,6 +369,7 @@ struct i2c_algorithm {
63059 /* To determine what the adapter supports */
63060 u32 (*functionality) (struct i2c_adapter *);
63061 };
63062 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
63063
63064 /*
63065 * i2c_adapter is the structure used to identify a physical i2c bus along
63066 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
63067 index d23c3c2..eb63c81 100644
63068 --- a/include/linux/i2o.h
63069 +++ b/include/linux/i2o.h
63070 @@ -565,7 +565,7 @@ struct i2o_controller {
63071 struct i2o_device *exec; /* Executive */
63072 #if BITS_PER_LONG == 64
63073 spinlock_t context_list_lock; /* lock for context_list */
63074 - atomic_t context_list_counter; /* needed for unique contexts */
63075 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
63076 struct list_head context_list; /* list of context id's
63077 and pointers */
63078 #endif
63079 diff --git a/include/linux/if_team.h b/include/linux/if_team.h
63080 index aa2e167..84024ce 100644
63081 --- a/include/linux/if_team.h
63082 +++ b/include/linux/if_team.h
63083 @@ -109,6 +109,7 @@ struct team_mode_ops {
63084 void (*port_enabled)(struct team *team, struct team_port *port);
63085 void (*port_disabled)(struct team *team, struct team_port *port);
63086 };
63087 +typedef struct team_mode_ops __no_const team_mode_ops_no_const;
63088
63089 enum team_option_type {
63090 TEAM_OPTION_TYPE_U32,
63091 @@ -181,7 +182,7 @@ struct team {
63092 struct list_head option_inst_list; /* list of option instances */
63093
63094 const struct team_mode *mode;
63095 - struct team_mode_ops ops;
63096 + team_mode_ops_no_const ops;
63097 long mode_priv[TEAM_MODE_PRIV_LONGS];
63098 };
63099
63100 diff --git a/include/linux/init.h b/include/linux/init.h
63101 index 5e664f6..0a1225c 100644
63102 --- a/include/linux/init.h
63103 +++ b/include/linux/init.h
63104 @@ -39,9 +39,15 @@
63105 * Also note, that this data cannot be "const".
63106 */
63107
63108 +#ifdef MODULE
63109 +#define add_latent_entropy
63110 +#else
63111 +#define add_latent_entropy __latent_entropy
63112 +#endif
63113 +
63114 /* These are for everybody (although not all archs will actually
63115 discard it in modules) */
63116 -#define __init __section(.init.text) __cold notrace
63117 +#define __init __section(.init.text) __cold notrace add_latent_entropy
63118 #define __initdata __section(.init.data)
63119 #define __initconst __section(.init.rodata)
63120 #define __exitdata __section(.exit.data)
63121 @@ -83,7 +89,7 @@
63122 #define __exit __section(.exit.text) __exitused __cold notrace
63123
63124 /* Used for HOTPLUG */
63125 -#define __devinit __section(.devinit.text) __cold notrace
63126 +#define __devinit __section(.devinit.text) __cold notrace add_latent_entropy
63127 #define __devinitdata __section(.devinit.data)
63128 #define __devinitconst __section(.devinit.rodata)
63129 #define __devexit __section(.devexit.text) __exitused __cold notrace
63130 @@ -91,7 +97,7 @@
63131 #define __devexitconst __section(.devexit.rodata)
63132
63133 /* Used for HOTPLUG_CPU */
63134 -#define __cpuinit __section(.cpuinit.text) __cold notrace
63135 +#define __cpuinit __section(.cpuinit.text) __cold notrace add_latent_entropy
63136 #define __cpuinitdata __section(.cpuinit.data)
63137 #define __cpuinitconst __section(.cpuinit.rodata)
63138 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
63139 @@ -99,7 +105,7 @@
63140 #define __cpuexitconst __section(.cpuexit.rodata)
63141
63142 /* Used for MEMORY_HOTPLUG */
63143 -#define __meminit __section(.meminit.text) __cold notrace
63144 +#define __meminit __section(.meminit.text) __cold notrace add_latent_entropy
63145 #define __meminitdata __section(.meminit.data)
63146 #define __meminitconst __section(.meminit.rodata)
63147 #define __memexit __section(.memexit.text) __exitused __cold notrace
63148 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
63149 index 89f1cb1..7986c0f 100644
63150 --- a/include/linux/init_task.h
63151 +++ b/include/linux/init_task.h
63152 @@ -143,6 +143,12 @@ extern struct task_group root_task_group;
63153
63154 #define INIT_TASK_COMM "swapper"
63155
63156 +#ifdef CONFIG_X86
63157 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
63158 +#else
63159 +#define INIT_TASK_THREAD_INFO
63160 +#endif
63161 +
63162 /*
63163 * INIT_TASK is used to set up the first task table, touch at
63164 * your own risk!. Base=0, limit=0x1fffff (=2MB)
63165 @@ -182,6 +188,7 @@ extern struct task_group root_task_group;
63166 RCU_POINTER_INITIALIZER(cred, &init_cred), \
63167 .comm = INIT_TASK_COMM, \
63168 .thread = INIT_THREAD, \
63169 + INIT_TASK_THREAD_INFO \
63170 .fs = &init_fs, \
63171 .files = &init_files, \
63172 .signal = &init_signals, \
63173 diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
63174 index 78e2ada..745564d 100644
63175 --- a/include/linux/intel-iommu.h
63176 +++ b/include/linux/intel-iommu.h
63177 @@ -296,7 +296,7 @@ struct iommu_flush {
63178 u8 fm, u64 type);
63179 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
63180 unsigned int size_order, u64 type);
63181 -};
63182 +} __no_const;
63183
63184 enum {
63185 SR_DMAR_FECTL_REG,
63186 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
63187 index c5f856a..d29c117 100644
63188 --- a/include/linux/interrupt.h
63189 +++ b/include/linux/interrupt.h
63190 @@ -433,7 +433,7 @@ enum
63191 /* map softirq index to softirq name. update 'softirq_to_name' in
63192 * kernel/softirq.c when adding a new softirq.
63193 */
63194 -extern char *softirq_to_name[NR_SOFTIRQS];
63195 +extern const char * const softirq_to_name[NR_SOFTIRQS];
63196
63197 /* softirq mask and active fields moved to irq_cpustat_t in
63198 * asm/hardirq.h to get better cache usage. KAO
63199 @@ -441,12 +441,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
63200
63201 struct softirq_action
63202 {
63203 - void (*action)(struct softirq_action *);
63204 + void (*action)(void);
63205 };
63206
63207 asmlinkage void do_softirq(void);
63208 asmlinkage void __do_softirq(void);
63209 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
63210 +extern void open_softirq(int nr, void (*action)(void));
63211 extern void softirq_init(void);
63212 extern void __raise_softirq_irqoff(unsigned int nr);
63213
63214 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
63215 index 6883e19..06992b1 100644
63216 --- a/include/linux/kallsyms.h
63217 +++ b/include/linux/kallsyms.h
63218 @@ -15,7 +15,8 @@
63219
63220 struct module;
63221
63222 -#ifdef CONFIG_KALLSYMS
63223 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
63224 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63225 /* Lookup the address for a symbol. Returns 0 if not found. */
63226 unsigned long kallsyms_lookup_name(const char *name);
63227
63228 @@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
63229 /* Stupid that this does nothing, but I didn't create this mess. */
63230 #define __print_symbol(fmt, addr)
63231 #endif /*CONFIG_KALLSYMS*/
63232 +#else /* when included by kallsyms.c, vsnprintf.c, or
63233 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
63234 +extern void __print_symbol(const char *fmt, unsigned long address);
63235 +extern int sprint_backtrace(char *buffer, unsigned long address);
63236 +extern int sprint_symbol(char *buffer, unsigned long address);
63237 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
63238 +const char *kallsyms_lookup(unsigned long addr,
63239 + unsigned long *symbolsize,
63240 + unsigned long *offset,
63241 + char **modname, char *namebuf);
63242 +#endif
63243
63244 /* This macro allows us to keep printk typechecking */
63245 static __printf(1, 2)
63246 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
63247 index c4d2fc1..5df9c19 100644
63248 --- a/include/linux/kgdb.h
63249 +++ b/include/linux/kgdb.h
63250 @@ -53,7 +53,7 @@ extern int kgdb_connected;
63251 extern int kgdb_io_module_registered;
63252
63253 extern atomic_t kgdb_setting_breakpoint;
63254 -extern atomic_t kgdb_cpu_doing_single_step;
63255 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
63256
63257 extern struct task_struct *kgdb_usethread;
63258 extern struct task_struct *kgdb_contthread;
63259 @@ -252,7 +252,7 @@ struct kgdb_arch {
63260 void (*disable_hw_break)(struct pt_regs *regs);
63261 void (*remove_all_hw_break)(void);
63262 void (*correct_hw_break)(void);
63263 -};
63264 +} __do_const;
63265
63266 /**
63267 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
63268 @@ -277,7 +277,7 @@ struct kgdb_io {
63269 void (*pre_exception) (void);
63270 void (*post_exception) (void);
63271 int is_console;
63272 -};
63273 +} __do_const;
63274
63275 extern struct kgdb_arch arch_kgdb_ops;
63276
63277 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
63278 index 5398d58..5883a34 100644
63279 --- a/include/linux/kmod.h
63280 +++ b/include/linux/kmod.h
63281 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
63282 * usually useless though. */
63283 extern __printf(2, 3)
63284 int __request_module(bool wait, const char *name, ...);
63285 +extern __printf(3, 4)
63286 +int ___request_module(bool wait, char *param_name, const char *name, ...);
63287 #define request_module(mod...) __request_module(true, mod)
63288 #define request_module_nowait(mod...) __request_module(false, mod)
63289 #define try_then_request_module(x, mod...) \
63290 diff --git a/include/linux/kref.h b/include/linux/kref.h
63291 index 65af688..0592677 100644
63292 --- a/include/linux/kref.h
63293 +++ b/include/linux/kref.h
63294 @@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
63295 static inline int kref_sub(struct kref *kref, unsigned int count,
63296 void (*release)(struct kref *kref))
63297 {
63298 - WARN_ON(release == NULL);
63299 + BUG_ON(release == NULL);
63300
63301 if (atomic_sub_and_test((int) count, &kref->refcount)) {
63302 release(kref);
63303 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
63304 index b70b48b..0d7153b 100644
63305 --- a/include/linux/kvm_host.h
63306 +++ b/include/linux/kvm_host.h
63307 @@ -351,7 +351,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
63308 void vcpu_load(struct kvm_vcpu *vcpu);
63309 void vcpu_put(struct kvm_vcpu *vcpu);
63310
63311 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63312 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63313 struct module *module);
63314 void kvm_exit(void);
63315
63316 @@ -517,7 +517,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
63317 struct kvm_guest_debug *dbg);
63318 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
63319
63320 -int kvm_arch_init(void *opaque);
63321 +int kvm_arch_init(const void *opaque);
63322 void kvm_arch_exit(void);
63323
63324 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
63325 diff --git a/include/linux/libata.h b/include/linux/libata.h
63326 index 64f90e1..32b945b 100644
63327 --- a/include/linux/libata.h
63328 +++ b/include/linux/libata.h
63329 @@ -909,7 +909,7 @@ struct ata_port_operations {
63330 * fields must be pointers.
63331 */
63332 const struct ata_port_operations *inherits;
63333 -};
63334 +} __do_const;
63335
63336 struct ata_port_info {
63337 unsigned long flags;
63338 diff --git a/include/linux/memory.h b/include/linux/memory.h
63339 index ff9a9f8..c715deb 100644
63340 --- a/include/linux/memory.h
63341 +++ b/include/linux/memory.h
63342 @@ -143,7 +143,7 @@ struct memory_accessor {
63343 size_t count);
63344 ssize_t (*write)(struct memory_accessor *, const char *buf,
63345 off_t offset, size_t count);
63346 -};
63347 +} __no_const;
63348
63349 /*
63350 * Kernel text modification mutex, used for code patching. Users of this lock
63351 diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
63352 index 1318ca6..7521340 100644
63353 --- a/include/linux/mfd/abx500.h
63354 +++ b/include/linux/mfd/abx500.h
63355 @@ -452,6 +452,7 @@ struct abx500_ops {
63356 int (*event_registers_startup_state_get) (struct device *, u8 *);
63357 int (*startup_irq_enabled) (struct device *, unsigned int);
63358 };
63359 +typedef struct abx500_ops __no_const abx500_ops_no_const;
63360
63361 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
63362 void abx500_remove_ops(struct device *dev);
63363 diff --git a/include/linux/mfd/abx500/ux500_chargalg.h b/include/linux/mfd/abx500/ux500_chargalg.h
63364 index 9b07725..3d55001 100644
63365 --- a/include/linux/mfd/abx500/ux500_chargalg.h
63366 +++ b/include/linux/mfd/abx500/ux500_chargalg.h
63367 @@ -19,7 +19,7 @@ struct ux500_charger_ops {
63368 int (*enable) (struct ux500_charger *, int, int, int);
63369 int (*kick_wd) (struct ux500_charger *);
63370 int (*update_curr) (struct ux500_charger *, int);
63371 -};
63372 +} __no_const;
63373
63374 /**
63375 * struct ux500_charger - power supply ux500 charger sub class
63376 diff --git a/include/linux/mm.h b/include/linux/mm.h
63377 index 311be90..5f1638c 100644
63378 --- a/include/linux/mm.h
63379 +++ b/include/linux/mm.h
63380 @@ -116,7 +116,14 @@ extern unsigned int kobjsize(const void *objp);
63381
63382 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
63383 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
63384 +
63385 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
63386 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
63387 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
63388 +#else
63389 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
63390 +#endif
63391 +
63392 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
63393 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
63394
63395 @@ -1038,34 +1045,6 @@ int set_page_dirty(struct page *page);
63396 int set_page_dirty_lock(struct page *page);
63397 int clear_page_dirty_for_io(struct page *page);
63398
63399 -/* Is the vma a continuation of the stack vma above it? */
63400 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
63401 -{
63402 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
63403 -}
63404 -
63405 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
63406 - unsigned long addr)
63407 -{
63408 - return (vma->vm_flags & VM_GROWSDOWN) &&
63409 - (vma->vm_start == addr) &&
63410 - !vma_growsdown(vma->vm_prev, addr);
63411 -}
63412 -
63413 -/* Is the vma a continuation of the stack vma below it? */
63414 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
63415 -{
63416 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
63417 -}
63418 -
63419 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
63420 - unsigned long addr)
63421 -{
63422 - return (vma->vm_flags & VM_GROWSUP) &&
63423 - (vma->vm_end == addr) &&
63424 - !vma_growsup(vma->vm_next, addr);
63425 -}
63426 -
63427 extern pid_t
63428 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
63429
63430 @@ -1164,6 +1143,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
63431 }
63432 #endif
63433
63434 +#ifdef CONFIG_MMU
63435 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
63436 +#else
63437 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
63438 +{
63439 + return __pgprot(0);
63440 +}
63441 +#endif
63442 +
63443 int vma_wants_writenotify(struct vm_area_struct *vma);
63444
63445 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
63446 @@ -1182,8 +1170,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
63447 {
63448 return 0;
63449 }
63450 +
63451 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
63452 + unsigned long address)
63453 +{
63454 + return 0;
63455 +}
63456 #else
63457 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63458 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63459 #endif
63460
63461 #ifdef __PAGETABLE_PMD_FOLDED
63462 @@ -1192,8 +1187,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
63463 {
63464 return 0;
63465 }
63466 +
63467 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
63468 + unsigned long address)
63469 +{
63470 + return 0;
63471 +}
63472 #else
63473 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
63474 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
63475 #endif
63476
63477 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
63478 @@ -1211,11 +1213,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
63479 NULL: pud_offset(pgd, address);
63480 }
63481
63482 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
63483 +{
63484 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
63485 + NULL: pud_offset(pgd, address);
63486 +}
63487 +
63488 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
63489 {
63490 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
63491 NULL: pmd_offset(pud, address);
63492 }
63493 +
63494 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
63495 +{
63496 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
63497 + NULL: pmd_offset(pud, address);
63498 +}
63499 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
63500
63501 #if USE_SPLIT_PTLOCKS
63502 @@ -1426,6 +1440,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
63503 unsigned long, unsigned long,
63504 unsigned long, unsigned long);
63505 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
63506 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
63507
63508 /* These take the mm semaphore themselves */
63509 extern unsigned long vm_brk(unsigned long, unsigned long);
63510 @@ -1489,6 +1504,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
63511 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
63512 struct vm_area_struct **pprev);
63513
63514 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
63515 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
63516 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
63517 +
63518 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
63519 NULL if none. Assume start_addr < end_addr. */
63520 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
63521 @@ -1517,15 +1536,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
63522 return vma;
63523 }
63524
63525 -#ifdef CONFIG_MMU
63526 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
63527 -#else
63528 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
63529 -{
63530 - return __pgprot(0);
63531 -}
63532 -#endif
63533 -
63534 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
63535 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
63536 unsigned long pfn, unsigned long size, pgprot_t);
63537 @@ -1631,7 +1641,7 @@ extern int unpoison_memory(unsigned long pfn);
63538 extern int sysctl_memory_failure_early_kill;
63539 extern int sysctl_memory_failure_recovery;
63540 extern void shake_page(struct page *p, int access);
63541 -extern atomic_long_t mce_bad_pages;
63542 +extern atomic_long_unchecked_t mce_bad_pages;
63543 extern int soft_offline_page(struct page *page, int flags);
63544
63545 extern void dump_page(struct page *page);
63546 @@ -1662,5 +1672,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
63547 static inline bool page_is_guard(struct page *page) { return false; }
63548 #endif /* CONFIG_DEBUG_PAGEALLOC */
63549
63550 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63551 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
63552 +#else
63553 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
63554 +#endif
63555 +
63556 #endif /* __KERNEL__ */
63557 #endif /* _LINUX_MM_H */
63558 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
63559 index bf78672..debc693 100644
63560 --- a/include/linux/mm_types.h
63561 +++ b/include/linux/mm_types.h
63562 @@ -279,6 +279,8 @@ struct vm_area_struct {
63563 #ifdef CONFIG_NUMA
63564 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
63565 #endif
63566 +
63567 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
63568 };
63569
63570 struct core_thread {
63571 @@ -353,7 +355,7 @@ struct mm_struct {
63572 unsigned long def_flags;
63573 unsigned long nr_ptes; /* Page table pages */
63574 unsigned long start_code, end_code, start_data, end_data;
63575 - unsigned long start_brk, brk, start_stack;
63576 + unsigned long brk_gap, start_brk, brk, start_stack;
63577 unsigned long arg_start, arg_end, env_start, env_end;
63578
63579 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
63580 @@ -405,6 +407,24 @@ struct mm_struct {
63581 struct cpumask cpumask_allocation;
63582 #endif
63583 struct uprobes_state uprobes_state;
63584 +
63585 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63586 + unsigned long pax_flags;
63587 +#endif
63588 +
63589 +#ifdef CONFIG_PAX_DLRESOLVE
63590 + unsigned long call_dl_resolve;
63591 +#endif
63592 +
63593 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
63594 + unsigned long call_syscall;
63595 +#endif
63596 +
63597 +#ifdef CONFIG_PAX_ASLR
63598 + unsigned long delta_mmap; /* randomized offset */
63599 + unsigned long delta_stack; /* randomized offset */
63600 +#endif
63601 +
63602 };
63603
63604 static inline void mm_init_cpumask(struct mm_struct *mm)
63605 diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
63606 index 1d1b1e1..2a13c78 100644
63607 --- a/include/linux/mmu_notifier.h
63608 +++ b/include/linux/mmu_notifier.h
63609 @@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
63610 */
63611 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
63612 ({ \
63613 - pte_t __pte; \
63614 + pte_t ___pte; \
63615 struct vm_area_struct *___vma = __vma; \
63616 unsigned long ___address = __address; \
63617 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
63618 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
63619 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
63620 - __pte; \
63621 + ___pte; \
63622 })
63623
63624 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
63625 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
63626 index 2daa54f..bfdf2f5 100644
63627 --- a/include/linux/mmzone.h
63628 +++ b/include/linux/mmzone.h
63629 @@ -414,7 +414,7 @@ struct zone {
63630 unsigned long flags; /* zone flags, see below */
63631
63632 /* Zone statistics */
63633 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63634 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63635
63636 /*
63637 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
63638 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
63639 index 6955045..ebdb7cd 100644
63640 --- a/include/linux/mod_devicetable.h
63641 +++ b/include/linux/mod_devicetable.h
63642 @@ -12,7 +12,7 @@
63643 typedef unsigned long kernel_ulong_t;
63644 #endif
63645
63646 -#define PCI_ANY_ID (~0)
63647 +#define PCI_ANY_ID ((__u16)~0)
63648
63649 struct pci_device_id {
63650 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
63651 @@ -139,7 +139,7 @@ struct usb_device_id {
63652 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
63653 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
63654
63655 -#define HID_ANY_ID (~0)
63656 +#define HID_ANY_ID (~0U)
63657 #define HID_BUS_ANY 0xffff
63658 #define HID_GROUP_ANY 0x0000
63659
63660 diff --git a/include/linux/module.h b/include/linux/module.h
63661 index fbcafe2..e5d9587 100644
63662 --- a/include/linux/module.h
63663 +++ b/include/linux/module.h
63664 @@ -17,6 +17,7 @@
63665 #include <linux/moduleparam.h>
63666 #include <linux/tracepoint.h>
63667 #include <linux/export.h>
63668 +#include <linux/fs.h>
63669
63670 #include <linux/percpu.h>
63671 #include <asm/module.h>
63672 @@ -273,19 +274,16 @@ struct module
63673 int (*init)(void);
63674
63675 /* If this is non-NULL, vfree after init() returns */
63676 - void *module_init;
63677 + void *module_init_rx, *module_init_rw;
63678
63679 /* Here is the actual code + data, vfree'd on unload. */
63680 - void *module_core;
63681 + void *module_core_rx, *module_core_rw;
63682
63683 /* Here are the sizes of the init and core sections */
63684 - unsigned int init_size, core_size;
63685 + unsigned int init_size_rw, core_size_rw;
63686
63687 /* The size of the executable code in each section. */
63688 - unsigned int init_text_size, core_text_size;
63689 -
63690 - /* Size of RO sections of the module (text+rodata) */
63691 - unsigned int init_ro_size, core_ro_size;
63692 + unsigned int init_size_rx, core_size_rx;
63693
63694 /* Arch-specific module values */
63695 struct mod_arch_specific arch;
63696 @@ -341,6 +339,10 @@ struct module
63697 #ifdef CONFIG_EVENT_TRACING
63698 struct ftrace_event_call **trace_events;
63699 unsigned int num_trace_events;
63700 + struct file_operations trace_id;
63701 + struct file_operations trace_enable;
63702 + struct file_operations trace_format;
63703 + struct file_operations trace_filter;
63704 #endif
63705 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
63706 unsigned int num_ftrace_callsites;
63707 @@ -388,16 +390,46 @@ bool is_module_address(unsigned long addr);
63708 bool is_module_percpu_address(unsigned long addr);
63709 bool is_module_text_address(unsigned long addr);
63710
63711 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
63712 +{
63713 +
63714 +#ifdef CONFIG_PAX_KERNEXEC
63715 + if (ktla_ktva(addr) >= (unsigned long)start &&
63716 + ktla_ktva(addr) < (unsigned long)start + size)
63717 + return 1;
63718 +#endif
63719 +
63720 + return ((void *)addr >= start && (void *)addr < start + size);
63721 +}
63722 +
63723 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
63724 +{
63725 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
63726 +}
63727 +
63728 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
63729 +{
63730 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
63731 +}
63732 +
63733 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
63734 +{
63735 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
63736 +}
63737 +
63738 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
63739 +{
63740 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
63741 +}
63742 +
63743 static inline int within_module_core(unsigned long addr, struct module *mod)
63744 {
63745 - return (unsigned long)mod->module_core <= addr &&
63746 - addr < (unsigned long)mod->module_core + mod->core_size;
63747 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
63748 }
63749
63750 static inline int within_module_init(unsigned long addr, struct module *mod)
63751 {
63752 - return (unsigned long)mod->module_init <= addr &&
63753 - addr < (unsigned long)mod->module_init + mod->init_size;
63754 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
63755 }
63756
63757 /* Search for module by name: must hold module_mutex. */
63758 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
63759 index b2be02e..72d2f78 100644
63760 --- a/include/linux/moduleloader.h
63761 +++ b/include/linux/moduleloader.h
63762 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
63763
63764 /* Allocator used for allocating struct module, core sections and init
63765 sections. Returns NULL on failure. */
63766 -void *module_alloc(unsigned long size);
63767 +void *module_alloc(unsigned long size) __size_overflow(1);
63768 +
63769 +#ifdef CONFIG_PAX_KERNEXEC
63770 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
63771 +#else
63772 +#define module_alloc_exec(x) module_alloc(x)
63773 +#endif
63774
63775 /* Free memory returned from module_alloc. */
63776 void module_free(struct module *mod, void *module_region);
63777
63778 +#ifdef CONFIG_PAX_KERNEXEC
63779 +void module_free_exec(struct module *mod, void *module_region);
63780 +#else
63781 +#define module_free_exec(x, y) module_free((x), (y))
63782 +#endif
63783 +
63784 /* Apply the given relocation to the (simplified) ELF. Return -error
63785 or 0. */
63786 int apply_relocate(Elf_Shdr *sechdrs,
63787 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
63788 index d6a5806..7c13347 100644
63789 --- a/include/linux/moduleparam.h
63790 +++ b/include/linux/moduleparam.h
63791 @@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
63792 * @len is usually just sizeof(string).
63793 */
63794 #define module_param_string(name, string, len, perm) \
63795 - static const struct kparam_string __param_string_##name \
63796 + static const struct kparam_string __param_string_##name __used \
63797 = { len, string }; \
63798 __module_param_call(MODULE_PARAM_PREFIX, name, \
63799 &param_ops_string, \
63800 @@ -425,7 +425,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
63801 */
63802 #define module_param_array_named(name, array, type, nump, perm) \
63803 param_check_##type(name, &(array)[0]); \
63804 - static const struct kparam_array __param_arr_##name \
63805 + static const struct kparam_array __param_arr_##name __used \
63806 = { .max = ARRAY_SIZE(array), .num = nump, \
63807 .ops = &param_ops_##type, \
63808 .elemsize = sizeof(array[0]), .elem = array }; \
63809 diff --git a/include/linux/namei.h b/include/linux/namei.h
63810 index 4bf19d8..5268cea 100644
63811 --- a/include/linux/namei.h
63812 +++ b/include/linux/namei.h
63813 @@ -18,7 +18,7 @@ struct nameidata {
63814 unsigned seq;
63815 int last_type;
63816 unsigned depth;
63817 - char *saved_names[MAX_NESTED_LINKS + 1];
63818 + const char *saved_names[MAX_NESTED_LINKS + 1];
63819 };
63820
63821 /*
63822 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
63823
63824 extern void nd_jump_link(struct nameidata *nd, struct path *path);
63825
63826 -static inline void nd_set_link(struct nameidata *nd, char *path)
63827 +static inline void nd_set_link(struct nameidata *nd, const char *path)
63828 {
63829 nd->saved_names[nd->depth] = path;
63830 }
63831
63832 -static inline char *nd_get_link(struct nameidata *nd)
63833 +static inline const char *nd_get_link(const struct nameidata *nd)
63834 {
63835 return nd->saved_names[nd->depth];
63836 }
63837 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
63838 index 59dc05f3..c905a34 100644
63839 --- a/include/linux/netdevice.h
63840 +++ b/include/linux/netdevice.h
63841 @@ -1027,6 +1027,7 @@ struct net_device_ops {
63842 struct net_device *dev,
63843 int idx);
63844 };
63845 +typedef struct net_device_ops __no_const net_device_ops_no_const;
63846
63847 /*
63848 * The DEVICE structure.
63849 @@ -1087,7 +1088,7 @@ struct net_device {
63850 int iflink;
63851
63852 struct net_device_stats stats;
63853 - atomic_long_t rx_dropped; /* dropped packets by core network
63854 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
63855 * Do not use this in drivers.
63856 */
63857
63858 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
63859 new file mode 100644
63860 index 0000000..33f4af8
63861 --- /dev/null
63862 +++ b/include/linux/netfilter/xt_gradm.h
63863 @@ -0,0 +1,9 @@
63864 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
63865 +#define _LINUX_NETFILTER_XT_GRADM_H 1
63866 +
63867 +struct xt_gradm_mtinfo {
63868 + __u16 flags;
63869 + __u16 invflags;
63870 +};
63871 +
63872 +#endif
63873 diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
63874 index c65a18a..0c05f3a 100644
63875 --- a/include/linux/of_pdt.h
63876 +++ b/include/linux/of_pdt.h
63877 @@ -32,7 +32,7 @@ struct of_pdt_ops {
63878
63879 /* return 0 on success; fill in 'len' with number of bytes in path */
63880 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
63881 -};
63882 +} __no_const;
63883
63884 extern void *prom_early_alloc(unsigned long size);
63885
63886 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
63887 index a4c5624..79d6d88 100644
63888 --- a/include/linux/oprofile.h
63889 +++ b/include/linux/oprofile.h
63890 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
63891 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
63892 char const * name, ulong * val);
63893
63894 -/** Create a file for read-only access to an atomic_t. */
63895 +/** Create a file for read-only access to an atomic_unchecked_t. */
63896 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
63897 - char const * name, atomic_t * val);
63898 + char const * name, atomic_unchecked_t * val);
63899
63900 /** create a directory */
63901 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
63902 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
63903 index bdb4161..f373d41 100644
63904 --- a/include/linux/perf_event.h
63905 +++ b/include/linux/perf_event.h
63906 @@ -882,8 +882,8 @@ struct perf_event {
63907
63908 enum perf_event_active_state state;
63909 unsigned int attach_state;
63910 - local64_t count;
63911 - atomic64_t child_count;
63912 + local64_t count; /* PaX: fix it one day */
63913 + atomic64_unchecked_t child_count;
63914
63915 /*
63916 * These are the total time in nanoseconds that the event
63917 @@ -934,8 +934,8 @@ struct perf_event {
63918 * These accumulate total time (in nanoseconds) that children
63919 * events have been enabled and running, respectively.
63920 */
63921 - atomic64_t child_total_time_enabled;
63922 - atomic64_t child_total_time_running;
63923 + atomic64_unchecked_t child_total_time_enabled;
63924 + atomic64_unchecked_t child_total_time_running;
63925
63926 /*
63927 * Protect attach/detach and child_list:
63928 diff --git a/include/linux/personality.h b/include/linux/personality.h
63929 index 8fc7dd1a..c19d89e 100644
63930 --- a/include/linux/personality.h
63931 +++ b/include/linux/personality.h
63932 @@ -44,6 +44,7 @@ enum {
63933 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
63934 ADDR_NO_RANDOMIZE | \
63935 ADDR_COMPAT_LAYOUT | \
63936 + ADDR_LIMIT_3GB | \
63937 MMAP_PAGE_ZERO)
63938
63939 /*
63940 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
63941 index ad1a427..6419649 100644
63942 --- a/include/linux/pipe_fs_i.h
63943 +++ b/include/linux/pipe_fs_i.h
63944 @@ -45,9 +45,9 @@ struct pipe_buffer {
63945 struct pipe_inode_info {
63946 wait_queue_head_t wait;
63947 unsigned int nrbufs, curbuf, buffers;
63948 - unsigned int readers;
63949 - unsigned int writers;
63950 - unsigned int waiting_writers;
63951 + atomic_t readers;
63952 + atomic_t writers;
63953 + atomic_t waiting_writers;
63954 unsigned int r_counter;
63955 unsigned int w_counter;
63956 struct page *tmp_page;
63957 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
63958 index f271860..6b3bec5 100644
63959 --- a/include/linux/pm_runtime.h
63960 +++ b/include/linux/pm_runtime.h
63961 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
63962
63963 static inline void pm_runtime_mark_last_busy(struct device *dev)
63964 {
63965 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
63966 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
63967 }
63968
63969 #else /* !CONFIG_PM_RUNTIME */
63970 diff --git a/include/linux/poison.h b/include/linux/poison.h
63971 index 2110a81..13a11bb 100644
63972 --- a/include/linux/poison.h
63973 +++ b/include/linux/poison.h
63974 @@ -19,8 +19,8 @@
63975 * under normal circumstances, used to verify that nobody uses
63976 * non-initialized list entries.
63977 */
63978 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
63979 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
63980 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
63981 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
63982
63983 /********** include/linux/timer.h **********/
63984 /*
63985 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
63986 index 5a710b9..0b0dab9 100644
63987 --- a/include/linux/preempt.h
63988 +++ b/include/linux/preempt.h
63989 @@ -126,7 +126,7 @@ struct preempt_ops {
63990 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
63991 void (*sched_out)(struct preempt_notifier *notifier,
63992 struct task_struct *next);
63993 -};
63994 +} __no_const;
63995
63996 /**
63997 * preempt_notifier - key for installing preemption notifiers
63998 diff --git a/include/linux/printk.h b/include/linux/printk.h
63999 index 9afc01e..92c32e8 100644
64000 --- a/include/linux/printk.h
64001 +++ b/include/linux/printk.h
64002 @@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
64003 extern int printk_needs_cpu(int cpu);
64004 extern void printk_tick(void);
64005
64006 +extern int kptr_restrict;
64007 +
64008 #ifdef CONFIG_PRINTK
64009 asmlinkage __printf(5, 0)
64010 int vprintk_emit(int facility, int level,
64011 @@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
64012
64013 extern int printk_delay_msec;
64014 extern int dmesg_restrict;
64015 -extern int kptr_restrict;
64016
64017 void log_buf_kexec_setup(void);
64018 void __init setup_log_buf(int early);
64019 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
64020 index 3fd2e87..d93a721 100644
64021 --- a/include/linux/proc_fs.h
64022 +++ b/include/linux/proc_fs.h
64023 @@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
64024 return proc_create_data(name, mode, parent, proc_fops, NULL);
64025 }
64026
64027 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
64028 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
64029 +{
64030 +#ifdef CONFIG_GRKERNSEC_PROC_USER
64031 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
64032 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64033 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
64034 +#else
64035 + return proc_create_data(name, mode, parent, proc_fops, NULL);
64036 +#endif
64037 +}
64038 +
64039 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
64040 umode_t mode, struct proc_dir_entry *base,
64041 read_proc_t *read_proc, void * data)
64042 @@ -258,7 +270,7 @@ union proc_op {
64043 int (*proc_show)(struct seq_file *m,
64044 struct pid_namespace *ns, struct pid *pid,
64045 struct task_struct *task);
64046 -};
64047 +} __no_const;
64048
64049 struct ctl_table_header;
64050 struct ctl_table;
64051 diff --git a/include/linux/random.h b/include/linux/random.h
64052 index ac621ce..c1215f3 100644
64053 --- a/include/linux/random.h
64054 +++ b/include/linux/random.h
64055 @@ -53,6 +53,10 @@ extern void add_input_randomness(unsigned int type, unsigned int code,
64056 unsigned int value);
64057 extern void add_interrupt_randomness(int irq, int irq_flags);
64058
64059 +#ifdef CONFIG_PAX_LATENT_ENTROPY
64060 +extern void transfer_latent_entropy(void);
64061 +#endif
64062 +
64063 extern void get_random_bytes(void *buf, int nbytes);
64064 extern void get_random_bytes_arch(void *buf, int nbytes);
64065 void generate_random_uuid(unsigned char uuid_out[16]);
64066 @@ -69,12 +73,17 @@ void srandom32(u32 seed);
64067
64068 u32 prandom32(struct rnd_state *);
64069
64070 +static inline unsigned long pax_get_random_long(void)
64071 +{
64072 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
64073 +}
64074 +
64075 /*
64076 * Handle minimum values for seeds
64077 */
64078 static inline u32 __seed(u32 x, u32 m)
64079 {
64080 - return (x < m) ? x + m : x;
64081 + return (x <= m) ? x + m + 1 : x;
64082 }
64083
64084 /**
64085 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
64086 index e0879a7..a12f962 100644
64087 --- a/include/linux/reboot.h
64088 +++ b/include/linux/reboot.h
64089 @@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
64090 * Architecture-specific implementations of sys_reboot commands.
64091 */
64092
64093 -extern void machine_restart(char *cmd);
64094 -extern void machine_halt(void);
64095 -extern void machine_power_off(void);
64096 +extern void machine_restart(char *cmd) __noreturn;
64097 +extern void machine_halt(void) __noreturn;
64098 +extern void machine_power_off(void) __noreturn;
64099
64100 extern void machine_shutdown(void);
64101 struct pt_regs;
64102 @@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
64103 */
64104
64105 extern void kernel_restart_prepare(char *cmd);
64106 -extern void kernel_restart(char *cmd);
64107 -extern void kernel_halt(void);
64108 -extern void kernel_power_off(void);
64109 +extern void kernel_restart(char *cmd) __noreturn;
64110 +extern void kernel_halt(void) __noreturn;
64111 +extern void kernel_power_off(void) __noreturn;
64112
64113 extern int C_A_D; /* for sysctl */
64114 void ctrl_alt_del(void);
64115 @@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
64116 * Emergency restart, callable from an interrupt handler.
64117 */
64118
64119 -extern void emergency_restart(void);
64120 +extern void emergency_restart(void) __noreturn;
64121 #include <asm/emergency-restart.h>
64122
64123 #endif
64124 diff --git a/include/linux/relay.h b/include/linux/relay.h
64125 index 91cacc3..b55ff74 100644
64126 --- a/include/linux/relay.h
64127 +++ b/include/linux/relay.h
64128 @@ -160,7 +160,7 @@ struct rchan_callbacks
64129 * The callback should return 0 if successful, negative if not.
64130 */
64131 int (*remove_buf_file)(struct dentry *dentry);
64132 -};
64133 +} __no_const;
64134
64135 /*
64136 * CONFIG_RELAY kernel API, kernel/relay.c
64137 diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
64138 index 6fdf027..ff72610 100644
64139 --- a/include/linux/rfkill.h
64140 +++ b/include/linux/rfkill.h
64141 @@ -147,6 +147,7 @@ struct rfkill_ops {
64142 void (*query)(struct rfkill *rfkill, void *data);
64143 int (*set_block)(void *data, bool blocked);
64144 };
64145 +typedef struct rfkill_ops __no_const rfkill_ops_no_const;
64146
64147 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
64148 /**
64149 diff --git a/include/linux/rio.h b/include/linux/rio.h
64150 index a90ebad..fd87b5d 100644
64151 --- a/include/linux/rio.h
64152 +++ b/include/linux/rio.h
64153 @@ -321,7 +321,7 @@ struct rio_ops {
64154 int mbox, void *buffer, size_t len);
64155 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
64156 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
64157 -};
64158 +} __no_const;
64159
64160 #define RIO_RESOURCE_MEM 0x00000100
64161 #define RIO_RESOURCE_DOORBELL 0x00000200
64162 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
64163 index 3fce545..b4fed6e 100644
64164 --- a/include/linux/rmap.h
64165 +++ b/include/linux/rmap.h
64166 @@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
64167 void anon_vma_init(void); /* create anon_vma_cachep */
64168 int anon_vma_prepare(struct vm_area_struct *);
64169 void unlink_anon_vmas(struct vm_area_struct *);
64170 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
64171 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
64172 void anon_vma_moveto_tail(struct vm_area_struct *);
64173 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
64174 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
64175
64176 static inline void anon_vma_merge(struct vm_area_struct *vma,
64177 struct vm_area_struct *next)
64178 diff --git a/include/linux/sched.h b/include/linux/sched.h
64179 index 23bddac..5976055 100644
64180 --- a/include/linux/sched.h
64181 +++ b/include/linux/sched.h
64182 @@ -101,6 +101,7 @@ struct bio_list;
64183 struct fs_struct;
64184 struct perf_event_context;
64185 struct blk_plug;
64186 +struct linux_binprm;
64187
64188 /*
64189 * List of flags we want to share for kernel threads,
64190 @@ -384,10 +385,13 @@ struct user_namespace;
64191 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
64192
64193 extern int sysctl_max_map_count;
64194 +extern unsigned long sysctl_heap_stack_gap;
64195
64196 #include <linux/aio.h>
64197
64198 #ifdef CONFIG_MMU
64199 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
64200 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
64201 extern void arch_pick_mmap_layout(struct mm_struct *mm);
64202 extern unsigned long
64203 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
64204 @@ -651,6 +655,17 @@ struct signal_struct {
64205 #ifdef CONFIG_TASKSTATS
64206 struct taskstats *stats;
64207 #endif
64208 +
64209 +#ifdef CONFIG_GRKERNSEC
64210 + u32 curr_ip;
64211 + u32 saved_ip;
64212 + u32 gr_saddr;
64213 + u32 gr_daddr;
64214 + u16 gr_sport;
64215 + u16 gr_dport;
64216 + u8 used_accept:1;
64217 +#endif
64218 +
64219 #ifdef CONFIG_AUDIT
64220 unsigned audit_tty;
64221 struct tty_audit_buf *tty_audit_buf;
64222 @@ -734,6 +749,11 @@ struct user_struct {
64223 struct key *session_keyring; /* UID's default session keyring */
64224 #endif
64225
64226 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
64227 + unsigned int banned;
64228 + unsigned long ban_expires;
64229 +#endif
64230 +
64231 /* Hash table maintenance information */
64232 struct hlist_node uidhash_node;
64233 kuid_t uid;
64234 @@ -1356,8 +1376,8 @@ struct task_struct {
64235 struct list_head thread_group;
64236
64237 struct completion *vfork_done; /* for vfork() */
64238 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
64239 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64240 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
64241 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64242
64243 cputime_t utime, stime, utimescaled, stimescaled;
64244 cputime_t gtime;
64245 @@ -1373,11 +1393,6 @@ struct task_struct {
64246 struct task_cputime cputime_expires;
64247 struct list_head cpu_timers[3];
64248
64249 -/* process credentials */
64250 - const struct cred __rcu *real_cred; /* objective and real subjective task
64251 - * credentials (COW) */
64252 - const struct cred __rcu *cred; /* effective (overridable) subjective task
64253 - * credentials (COW) */
64254 char comm[TASK_COMM_LEN]; /* executable name excluding path
64255 - access with [gs]et_task_comm (which lock
64256 it with task_lock())
64257 @@ -1394,6 +1409,10 @@ struct task_struct {
64258 #endif
64259 /* CPU-specific state of this task */
64260 struct thread_struct thread;
64261 +/* thread_info moved to task_struct */
64262 +#ifdef CONFIG_X86
64263 + struct thread_info tinfo;
64264 +#endif
64265 /* filesystem information */
64266 struct fs_struct *fs;
64267 /* open file information */
64268 @@ -1467,6 +1486,10 @@ struct task_struct {
64269 gfp_t lockdep_reclaim_gfp;
64270 #endif
64271
64272 +/* process credentials */
64273 + const struct cred __rcu *real_cred; /* objective and real subjective task
64274 + * credentials (COW) */
64275 +
64276 /* journalling filesystem info */
64277 void *journal_info;
64278
64279 @@ -1505,6 +1528,10 @@ struct task_struct {
64280 /* cg_list protected by css_set_lock and tsk->alloc_lock */
64281 struct list_head cg_list;
64282 #endif
64283 +
64284 + const struct cred __rcu *cred; /* effective (overridable) subjective task
64285 + * credentials (COW) */
64286 +
64287 #ifdef CONFIG_FUTEX
64288 struct robust_list_head __user *robust_list;
64289 #ifdef CONFIG_COMPAT
64290 @@ -1589,8 +1616,74 @@ struct task_struct {
64291 #ifdef CONFIG_UPROBES
64292 struct uprobe_task *utask;
64293 #endif
64294 +
64295 +#ifdef CONFIG_GRKERNSEC
64296 + /* grsecurity */
64297 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64298 + u64 exec_id;
64299 +#endif
64300 +#ifdef CONFIG_GRKERNSEC_SETXID
64301 + const struct cred *delayed_cred;
64302 +#endif
64303 + struct dentry *gr_chroot_dentry;
64304 + struct acl_subject_label *acl;
64305 + struct acl_role_label *role;
64306 + struct file *exec_file;
64307 + u16 acl_role_id;
64308 + /* is this the task that authenticated to the special role */
64309 + u8 acl_sp_role;
64310 + u8 is_writable;
64311 + u8 brute;
64312 + u8 gr_is_chrooted;
64313 +#endif
64314 +
64315 };
64316
64317 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
64318 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
64319 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
64320 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
64321 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
64322 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
64323 +
64324 +#ifdef CONFIG_PAX_SOFTMODE
64325 +extern int pax_softmode;
64326 +#endif
64327 +
64328 +extern int pax_check_flags(unsigned long *);
64329 +
64330 +/* if tsk != current then task_lock must be held on it */
64331 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
64332 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
64333 +{
64334 + if (likely(tsk->mm))
64335 + return tsk->mm->pax_flags;
64336 + else
64337 + return 0UL;
64338 +}
64339 +
64340 +/* if tsk != current then task_lock must be held on it */
64341 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
64342 +{
64343 + if (likely(tsk->mm)) {
64344 + tsk->mm->pax_flags = flags;
64345 + return 0;
64346 + }
64347 + return -EINVAL;
64348 +}
64349 +#endif
64350 +
64351 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
64352 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
64353 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
64354 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
64355 +#endif
64356 +
64357 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
64358 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
64359 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
64360 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
64361 +
64362 /* Future-safe accessor for struct task_struct's cpus_allowed. */
64363 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
64364
64365 @@ -2125,7 +2218,9 @@ void yield(void);
64366 extern struct exec_domain default_exec_domain;
64367
64368 union thread_union {
64369 +#ifndef CONFIG_X86
64370 struct thread_info thread_info;
64371 +#endif
64372 unsigned long stack[THREAD_SIZE/sizeof(long)];
64373 };
64374
64375 @@ -2158,6 +2253,7 @@ extern struct pid_namespace init_pid_ns;
64376 */
64377
64378 extern struct task_struct *find_task_by_vpid(pid_t nr);
64379 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
64380 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
64381 struct pid_namespace *ns);
64382
64383 @@ -2314,7 +2410,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
64384 extern void exit_itimers(struct signal_struct *);
64385 extern void flush_itimer_signals(void);
64386
64387 -extern void do_group_exit(int);
64388 +extern __noreturn void do_group_exit(int);
64389
64390 extern void daemonize(const char *, ...);
64391 extern int allow_signal(int);
64392 @@ -2515,9 +2611,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
64393
64394 #endif
64395
64396 -static inline int object_is_on_stack(void *obj)
64397 +static inline int object_starts_on_stack(void *obj)
64398 {
64399 - void *stack = task_stack_page(current);
64400 + const void *stack = task_stack_page(current);
64401
64402 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
64403 }
64404 diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
64405 index 899fbb4..1cb4138 100644
64406 --- a/include/linux/screen_info.h
64407 +++ b/include/linux/screen_info.h
64408 @@ -43,7 +43,8 @@ struct screen_info {
64409 __u16 pages; /* 0x32 */
64410 __u16 vesa_attributes; /* 0x34 */
64411 __u32 capabilities; /* 0x36 */
64412 - __u8 _reserved[6]; /* 0x3a */
64413 + __u16 vesapm_size; /* 0x3a */
64414 + __u8 _reserved[4]; /* 0x3c */
64415 } __attribute__((packed));
64416
64417 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
64418 diff --git a/include/linux/security.h b/include/linux/security.h
64419 index d143b8e..9f27b95 100644
64420 --- a/include/linux/security.h
64421 +++ b/include/linux/security.h
64422 @@ -26,6 +26,7 @@
64423 #include <linux/capability.h>
64424 #include <linux/slab.h>
64425 #include <linux/err.h>
64426 +#include <linux/grsecurity.h>
64427
64428 struct linux_binprm;
64429 struct cred;
64430 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
64431 index 83c44ee..e8a9eba 100644
64432 --- a/include/linux/seq_file.h
64433 +++ b/include/linux/seq_file.h
64434 @@ -25,6 +25,9 @@ struct seq_file {
64435 struct mutex lock;
64436 const struct seq_operations *op;
64437 int poll_event;
64438 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64439 + u64 exec_id;
64440 +#endif
64441 void *private;
64442 };
64443
64444 @@ -34,6 +37,7 @@ struct seq_operations {
64445 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
64446 int (*show) (struct seq_file *m, void *v);
64447 };
64448 +typedef struct seq_operations __no_const seq_operations_no_const;
64449
64450 #define SEQ_SKIP 1
64451
64452 diff --git a/include/linux/shm.h b/include/linux/shm.h
64453 index edd0868..f98feee 100644
64454 --- a/include/linux/shm.h
64455 +++ b/include/linux/shm.h
64456 @@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
64457
64458 /* The task created the shm object. NULL if the task is dead. */
64459 struct task_struct *shm_creator;
64460 +#ifdef CONFIG_GRKERNSEC
64461 + time_t shm_createtime;
64462 + pid_t shm_lapid;
64463 +#endif
64464 };
64465
64466 /* shm_mode upper byte flags */
64467 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
64468 index f3165d2..2cb3cb7 100644
64469 --- a/include/linux/skbuff.h
64470 +++ b/include/linux/skbuff.h
64471 @@ -577,7 +577,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
64472 extern struct sk_buff *__alloc_skb(unsigned int size,
64473 gfp_t priority, int flags, int node);
64474 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
64475 -static inline struct sk_buff *alloc_skb(unsigned int size,
64476 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
64477 gfp_t priority)
64478 {
64479 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
64480 @@ -687,7 +687,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
64481 */
64482 static inline int skb_queue_empty(const struct sk_buff_head *list)
64483 {
64484 - return list->next == (struct sk_buff *)list;
64485 + return list->next == (const struct sk_buff *)list;
64486 }
64487
64488 /**
64489 @@ -700,7 +700,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
64490 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64491 const struct sk_buff *skb)
64492 {
64493 - return skb->next == (struct sk_buff *)list;
64494 + return skb->next == (const struct sk_buff *)list;
64495 }
64496
64497 /**
64498 @@ -713,7 +713,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64499 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
64500 const struct sk_buff *skb)
64501 {
64502 - return skb->prev == (struct sk_buff *)list;
64503 + return skb->prev == (const struct sk_buff *)list;
64504 }
64505
64506 /**
64507 @@ -1623,7 +1623,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
64508 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
64509 */
64510 #ifndef NET_SKB_PAD
64511 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
64512 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
64513 #endif
64514
64515 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
64516 @@ -2201,7 +2201,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
64517 int noblock, int *err);
64518 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
64519 struct poll_table_struct *wait);
64520 -extern int skb_copy_datagram_iovec(const struct sk_buff *from,
64521 +extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
64522 int offset, struct iovec *to,
64523 int size);
64524 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
64525 diff --git a/include/linux/slab.h b/include/linux/slab.h
64526 index 0dd2dfa..2b8677c 100644
64527 --- a/include/linux/slab.h
64528 +++ b/include/linux/slab.h
64529 @@ -11,12 +11,20 @@
64530
64531 #include <linux/gfp.h>
64532 #include <linux/types.h>
64533 +#include <linux/err.h>
64534
64535 /*
64536 * Flags to pass to kmem_cache_create().
64537 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
64538 */
64539 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
64540 +
64541 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64542 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
64543 +#else
64544 +#define SLAB_USERCOPY 0x00000000UL
64545 +#endif
64546 +
64547 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
64548 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
64549 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
64550 @@ -87,10 +95,13 @@
64551 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
64552 * Both make kfree a no-op.
64553 */
64554 -#define ZERO_SIZE_PTR ((void *)16)
64555 +#define ZERO_SIZE_PTR \
64556 +({ \
64557 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
64558 + (void *)(-MAX_ERRNO-1L); \
64559 +})
64560
64561 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
64562 - (unsigned long)ZERO_SIZE_PTR)
64563 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
64564
64565 /*
64566 * Common fields provided in kmem_cache by all slab allocators
64567 @@ -185,6 +196,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
64568 void kfree(const void *);
64569 void kzfree(const void *);
64570 size_t ksize(const void *);
64571 +const char *check_heap_object(const void *ptr, unsigned long n, bool to);
64572 +bool is_usercopy_object(const void *ptr);
64573
64574 /*
64575 * Allocator specific definitions. These are mainly used to establish optimized
64576 @@ -322,7 +335,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
64577 */
64578 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64579 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
64580 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64581 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
64582 #define kmalloc_track_caller(size, flags) \
64583 __kmalloc_track_caller(size, flags, _RET_IP_)
64584 #else
64585 @@ -341,7 +354,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64586 */
64587 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64588 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
64589 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
64590 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
64591 #define kmalloc_node_track_caller(size, flags, node) \
64592 __kmalloc_node_track_caller(size, flags, node, \
64593 _RET_IP_)
64594 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
64595 index 0c634fa..8616300 100644
64596 --- a/include/linux/slab_def.h
64597 +++ b/include/linux/slab_def.h
64598 @@ -69,10 +69,10 @@ struct kmem_cache {
64599 unsigned long node_allocs;
64600 unsigned long node_frees;
64601 unsigned long node_overflow;
64602 - atomic_t allochit;
64603 - atomic_t allocmiss;
64604 - atomic_t freehit;
64605 - atomic_t freemiss;
64606 + atomic_unchecked_t allochit;
64607 + atomic_unchecked_t allocmiss;
64608 + atomic_unchecked_t freehit;
64609 + atomic_unchecked_t freemiss;
64610
64611 /*
64612 * If debugging is enabled, then the allocator can add additional
64613 @@ -105,11 +105,16 @@ struct cache_sizes {
64614 #ifdef CONFIG_ZONE_DMA
64615 struct kmem_cache *cs_dmacachep;
64616 #endif
64617 +
64618 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64619 + struct kmem_cache *cs_usercopycachep;
64620 +#endif
64621 +
64622 };
64623 extern struct cache_sizes malloc_sizes[];
64624
64625 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64626 -void *__kmalloc(size_t size, gfp_t flags);
64627 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
64628
64629 #ifdef CONFIG_TRACING
64630 extern void *kmem_cache_alloc_trace(size_t size,
64631 @@ -152,6 +157,13 @@ found:
64632 cachep = malloc_sizes[i].cs_dmacachep;
64633 else
64634 #endif
64635 +
64636 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64637 + if (flags & GFP_USERCOPY)
64638 + cachep = malloc_sizes[i].cs_usercopycachep;
64639 + else
64640 +#endif
64641 +
64642 cachep = malloc_sizes[i].cs_cachep;
64643
64644 ret = kmem_cache_alloc_trace(size, cachep, flags);
64645 @@ -162,7 +174,7 @@ found:
64646 }
64647
64648 #ifdef CONFIG_NUMA
64649 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
64650 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64651 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64652
64653 #ifdef CONFIG_TRACING
64654 @@ -205,6 +217,13 @@ found:
64655 cachep = malloc_sizes[i].cs_dmacachep;
64656 else
64657 #endif
64658 +
64659 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64660 + if (flags & GFP_USERCOPY)
64661 + cachep = malloc_sizes[i].cs_usercopycachep;
64662 + else
64663 +#endif
64664 +
64665 cachep = malloc_sizes[i].cs_cachep;
64666
64667 return kmem_cache_alloc_node_trace(size, cachep, flags, node);
64668 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
64669 index 0ec00b3..22b4715 100644
64670 --- a/include/linux/slob_def.h
64671 +++ b/include/linux/slob_def.h
64672 @@ -9,7 +9,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
64673 return kmem_cache_alloc_node(cachep, flags, -1);
64674 }
64675
64676 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
64677 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64678
64679 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
64680 {
64681 @@ -29,7 +29,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64682 return __kmalloc_node(size, flags, -1);
64683 }
64684
64685 -static __always_inline void *__kmalloc(size_t size, gfp_t flags)
64686 +static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
64687 {
64688 return kmalloc(size, flags);
64689 }
64690 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
64691 index df448ad..b99e7f6 100644
64692 --- a/include/linux/slub_def.h
64693 +++ b/include/linux/slub_def.h
64694 @@ -91,7 +91,7 @@ struct kmem_cache {
64695 struct kmem_cache_order_objects max;
64696 struct kmem_cache_order_objects min;
64697 gfp_t allocflags; /* gfp flags to use on each alloc */
64698 - int refcount; /* Refcount for slab cache destroy */
64699 + atomic_t refcount; /* Refcount for slab cache destroy */
64700 void (*ctor)(void *);
64701 int inuse; /* Offset to metadata */
64702 int align; /* Alignment */
64703 @@ -152,7 +152,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
64704 * Sorry that the following has to be that ugly but some versions of GCC
64705 * have trouble with constant propagation and loops.
64706 */
64707 -static __always_inline int kmalloc_index(size_t size)
64708 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
64709 {
64710 if (!size)
64711 return 0;
64712 @@ -217,7 +217,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
64713 }
64714
64715 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64716 -void *__kmalloc(size_t size, gfp_t flags);
64717 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
64718
64719 static __always_inline void *
64720 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
64721 @@ -258,7 +258,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
64722 }
64723 #endif
64724
64725 -static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
64726 +static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
64727 {
64728 unsigned int order = get_order(size);
64729 return kmalloc_order_trace(size, flags, order);
64730 @@ -283,7 +283,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64731 }
64732
64733 #ifdef CONFIG_NUMA
64734 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
64735 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64736 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64737
64738 #ifdef CONFIG_TRACING
64739 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
64740 index de8832d..0147b46 100644
64741 --- a/include/linux/sonet.h
64742 +++ b/include/linux/sonet.h
64743 @@ -61,7 +61,7 @@ struct sonet_stats {
64744 #include <linux/atomic.h>
64745
64746 struct k_sonet_stats {
64747 -#define __HANDLE_ITEM(i) atomic_t i
64748 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
64749 __SONET_ITEMS
64750 #undef __HANDLE_ITEM
64751 };
64752 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
64753 index 523547e..2cb7140 100644
64754 --- a/include/linux/sunrpc/clnt.h
64755 +++ b/include/linux/sunrpc/clnt.h
64756 @@ -174,9 +174,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
64757 {
64758 switch (sap->sa_family) {
64759 case AF_INET:
64760 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
64761 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
64762 case AF_INET6:
64763 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
64764 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
64765 }
64766 return 0;
64767 }
64768 @@ -209,7 +209,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
64769 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
64770 const struct sockaddr *src)
64771 {
64772 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
64773 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
64774 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
64775
64776 dsin->sin_family = ssin->sin_family;
64777 @@ -312,7 +312,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
64778 if (sa->sa_family != AF_INET6)
64779 return 0;
64780
64781 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
64782 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
64783 }
64784
64785 #endif /* __KERNEL__ */
64786 diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
64787 index dc0c3cc..8503fb6 100644
64788 --- a/include/linux/sunrpc/sched.h
64789 +++ b/include/linux/sunrpc/sched.h
64790 @@ -106,6 +106,7 @@ struct rpc_call_ops {
64791 void (*rpc_count_stats)(struct rpc_task *, void *);
64792 void (*rpc_release)(void *);
64793 };
64794 +typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
64795
64796 struct rpc_task_setup {
64797 struct rpc_task *task;
64798 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
64799 index 0b8e3e6..33e0a01 100644
64800 --- a/include/linux/sunrpc/svc_rdma.h
64801 +++ b/include/linux/sunrpc/svc_rdma.h
64802 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
64803 extern unsigned int svcrdma_max_requests;
64804 extern unsigned int svcrdma_max_req_size;
64805
64806 -extern atomic_t rdma_stat_recv;
64807 -extern atomic_t rdma_stat_read;
64808 -extern atomic_t rdma_stat_write;
64809 -extern atomic_t rdma_stat_sq_starve;
64810 -extern atomic_t rdma_stat_rq_starve;
64811 -extern atomic_t rdma_stat_rq_poll;
64812 -extern atomic_t rdma_stat_rq_prod;
64813 -extern atomic_t rdma_stat_sq_poll;
64814 -extern atomic_t rdma_stat_sq_prod;
64815 +extern atomic_unchecked_t rdma_stat_recv;
64816 +extern atomic_unchecked_t rdma_stat_read;
64817 +extern atomic_unchecked_t rdma_stat_write;
64818 +extern atomic_unchecked_t rdma_stat_sq_starve;
64819 +extern atomic_unchecked_t rdma_stat_rq_starve;
64820 +extern atomic_unchecked_t rdma_stat_rq_poll;
64821 +extern atomic_unchecked_t rdma_stat_rq_prod;
64822 +extern atomic_unchecked_t rdma_stat_sq_poll;
64823 +extern atomic_unchecked_t rdma_stat_sq_prod;
64824
64825 #define RPCRDMA_VERSION 1
64826
64827 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
64828 index c34b4c8..a65b67d 100644
64829 --- a/include/linux/sysctl.h
64830 +++ b/include/linux/sysctl.h
64831 @@ -155,7 +155,11 @@ enum
64832 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
64833 };
64834
64835 -
64836 +#ifdef CONFIG_PAX_SOFTMODE
64837 +enum {
64838 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
64839 +};
64840 +#endif
64841
64842 /* CTL_VM names: */
64843 enum
64844 @@ -948,6 +952,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
64845
64846 extern int proc_dostring(struct ctl_table *, int,
64847 void __user *, size_t *, loff_t *);
64848 +extern int proc_dostring_modpriv(struct ctl_table *, int,
64849 + void __user *, size_t *, loff_t *);
64850 extern int proc_dointvec(struct ctl_table *, int,
64851 void __user *, size_t *, loff_t *);
64852 extern int proc_dointvec_minmax(struct ctl_table *, int,
64853 diff --git a/include/linux/tty.h b/include/linux/tty.h
64854 index 9f47ab5..73da944 100644
64855 --- a/include/linux/tty.h
64856 +++ b/include/linux/tty.h
64857 @@ -225,7 +225,7 @@ struct tty_port {
64858 const struct tty_port_operations *ops; /* Port operations */
64859 spinlock_t lock; /* Lock protecting tty field */
64860 int blocked_open; /* Waiting to open */
64861 - int count; /* Usage count */
64862 + atomic_t count; /* Usage count */
64863 wait_queue_head_t open_wait; /* Open waiters */
64864 wait_queue_head_t close_wait; /* Close waiters */
64865 wait_queue_head_t delta_msr_wait; /* Modem status change */
64866 @@ -525,7 +525,7 @@ extern int tty_port_open(struct tty_port *port,
64867 struct tty_struct *tty, struct file *filp);
64868 static inline int tty_port_users(struct tty_port *port)
64869 {
64870 - return port->count + port->blocked_open;
64871 + return atomic_read(&port->count) + port->blocked_open;
64872 }
64873
64874 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
64875 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
64876 index fb79dd8d..07d4773 100644
64877 --- a/include/linux/tty_ldisc.h
64878 +++ b/include/linux/tty_ldisc.h
64879 @@ -149,7 +149,7 @@ struct tty_ldisc_ops {
64880
64881 struct module *owner;
64882
64883 - int refcount;
64884 + atomic_t refcount;
64885 };
64886
64887 struct tty_ldisc {
64888 diff --git a/include/linux/types.h b/include/linux/types.h
64889 index bf0dd75..a1f23aaa 100644
64890 --- a/include/linux/types.h
64891 +++ b/include/linux/types.h
64892 @@ -220,10 +220,26 @@ typedef struct {
64893 int counter;
64894 } atomic_t;
64895
64896 +#ifdef CONFIG_PAX_REFCOUNT
64897 +typedef struct {
64898 + int counter;
64899 +} atomic_unchecked_t;
64900 +#else
64901 +typedef atomic_t atomic_unchecked_t;
64902 +#endif
64903 +
64904 #ifdef CONFIG_64BIT
64905 typedef struct {
64906 long counter;
64907 } atomic64_t;
64908 +
64909 +#ifdef CONFIG_PAX_REFCOUNT
64910 +typedef struct {
64911 + long counter;
64912 +} atomic64_unchecked_t;
64913 +#else
64914 +typedef atomic64_t atomic64_unchecked_t;
64915 +#endif
64916 #endif
64917
64918 struct list_head {
64919 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
64920 index 5ca0951..ab496a5 100644
64921 --- a/include/linux/uaccess.h
64922 +++ b/include/linux/uaccess.h
64923 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
64924 long ret; \
64925 mm_segment_t old_fs = get_fs(); \
64926 \
64927 - set_fs(KERNEL_DS); \
64928 pagefault_disable(); \
64929 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
64930 - pagefault_enable(); \
64931 + set_fs(KERNEL_DS); \
64932 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
64933 set_fs(old_fs); \
64934 + pagefault_enable(); \
64935 ret; \
64936 })
64937
64938 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
64939 index 99c1b4d..bb94261 100644
64940 --- a/include/linux/unaligned/access_ok.h
64941 +++ b/include/linux/unaligned/access_ok.h
64942 @@ -6,32 +6,32 @@
64943
64944 static inline u16 get_unaligned_le16(const void *p)
64945 {
64946 - return le16_to_cpup((__le16 *)p);
64947 + return le16_to_cpup((const __le16 *)p);
64948 }
64949
64950 static inline u32 get_unaligned_le32(const void *p)
64951 {
64952 - return le32_to_cpup((__le32 *)p);
64953 + return le32_to_cpup((const __le32 *)p);
64954 }
64955
64956 static inline u64 get_unaligned_le64(const void *p)
64957 {
64958 - return le64_to_cpup((__le64 *)p);
64959 + return le64_to_cpup((const __le64 *)p);
64960 }
64961
64962 static inline u16 get_unaligned_be16(const void *p)
64963 {
64964 - return be16_to_cpup((__be16 *)p);
64965 + return be16_to_cpup((const __be16 *)p);
64966 }
64967
64968 static inline u32 get_unaligned_be32(const void *p)
64969 {
64970 - return be32_to_cpup((__be32 *)p);
64971 + return be32_to_cpup((const __be32 *)p);
64972 }
64973
64974 static inline u64 get_unaligned_be64(const void *p)
64975 {
64976 - return be64_to_cpup((__be64 *)p);
64977 + return be64_to_cpup((const __be64 *)p);
64978 }
64979
64980 static inline void put_unaligned_le16(u16 val, void *p)
64981 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
64982 index c5d36c6..8478c90 100644
64983 --- a/include/linux/usb/renesas_usbhs.h
64984 +++ b/include/linux/usb/renesas_usbhs.h
64985 @@ -39,7 +39,7 @@ enum {
64986 */
64987 struct renesas_usbhs_driver_callback {
64988 int (*notify_hotplug)(struct platform_device *pdev);
64989 -};
64990 +} __no_const;
64991
64992 /*
64993 * callback functions for platform
64994 @@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
64995 * VBUS control is needed for Host
64996 */
64997 int (*set_vbus)(struct platform_device *pdev, int enable);
64998 -};
64999 +} __no_const;
65000
65001 /*
65002 * parameters for renesas usbhs
65003 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
65004 index 6f8fbcf..8259001 100644
65005 --- a/include/linux/vermagic.h
65006 +++ b/include/linux/vermagic.h
65007 @@ -25,9 +25,35 @@
65008 #define MODULE_ARCH_VERMAGIC ""
65009 #endif
65010
65011 +#ifdef CONFIG_PAX_REFCOUNT
65012 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
65013 +#else
65014 +#define MODULE_PAX_REFCOUNT ""
65015 +#endif
65016 +
65017 +#ifdef CONSTIFY_PLUGIN
65018 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
65019 +#else
65020 +#define MODULE_CONSTIFY_PLUGIN ""
65021 +#endif
65022 +
65023 +#ifdef STACKLEAK_PLUGIN
65024 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
65025 +#else
65026 +#define MODULE_STACKLEAK_PLUGIN ""
65027 +#endif
65028 +
65029 +#ifdef CONFIG_GRKERNSEC
65030 +#define MODULE_GRSEC "GRSEC "
65031 +#else
65032 +#define MODULE_GRSEC ""
65033 +#endif
65034 +
65035 #define VERMAGIC_STRING \
65036 UTS_RELEASE " " \
65037 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
65038 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
65039 - MODULE_ARCH_VERMAGIC
65040 + MODULE_ARCH_VERMAGIC \
65041 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
65042 + MODULE_GRSEC
65043
65044 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
65045 index 6071e91..ca6a489 100644
65046 --- a/include/linux/vmalloc.h
65047 +++ b/include/linux/vmalloc.h
65048 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
65049 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
65050 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
65051 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
65052 +
65053 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
65054 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
65055 +#endif
65056 +
65057 /* bits [20..32] reserved for arch specific ioremap internals */
65058
65059 /*
65060 @@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
65061 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
65062 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
65063 unsigned long start, unsigned long end, gfp_t gfp_mask,
65064 - pgprot_t prot, int node, const void *caller);
65065 + pgprot_t prot, int node, const void *caller) __size_overflow(1);
65066 extern void vfree(const void *addr);
65067
65068 extern void *vmap(struct page **pages, unsigned int count,
65069 @@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
65070 extern void free_vm_area(struct vm_struct *area);
65071
65072 /* for /dev/kmem */
65073 -extern long vread(char *buf, char *addr, unsigned long count);
65074 -extern long vwrite(char *buf, char *addr, unsigned long count);
65075 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
65076 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
65077
65078 /*
65079 * Internals. Dont't use..
65080 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
65081 index ad2cfd5..74c94ad 100644
65082 --- a/include/linux/vmstat.h
65083 +++ b/include/linux/vmstat.h
65084 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
65085 /*
65086 * Zone based page accounting with per cpu differentials.
65087 */
65088 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65089 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65090
65091 static inline void zone_page_state_add(long x, struct zone *zone,
65092 enum zone_stat_item item)
65093 {
65094 - atomic_long_add(x, &zone->vm_stat[item]);
65095 - atomic_long_add(x, &vm_stat[item]);
65096 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
65097 + atomic_long_add_unchecked(x, &vm_stat[item]);
65098 }
65099
65100 static inline unsigned long global_page_state(enum zone_stat_item item)
65101 {
65102 - long x = atomic_long_read(&vm_stat[item]);
65103 + long x = atomic_long_read_unchecked(&vm_stat[item]);
65104 #ifdef CONFIG_SMP
65105 if (x < 0)
65106 x = 0;
65107 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
65108 static inline unsigned long zone_page_state(struct zone *zone,
65109 enum zone_stat_item item)
65110 {
65111 - long x = atomic_long_read(&zone->vm_stat[item]);
65112 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
65113 #ifdef CONFIG_SMP
65114 if (x < 0)
65115 x = 0;
65116 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
65117 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
65118 enum zone_stat_item item)
65119 {
65120 - long x = atomic_long_read(&zone->vm_stat[item]);
65121 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
65122
65123 #ifdef CONFIG_SMP
65124 int cpu;
65125 @@ -216,8 +216,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
65126
65127 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
65128 {
65129 - atomic_long_inc(&zone->vm_stat[item]);
65130 - atomic_long_inc(&vm_stat[item]);
65131 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
65132 + atomic_long_inc_unchecked(&vm_stat[item]);
65133 }
65134
65135 static inline void __inc_zone_page_state(struct page *page,
65136 @@ -228,8 +228,8 @@ static inline void __inc_zone_page_state(struct page *page,
65137
65138 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
65139 {
65140 - atomic_long_dec(&zone->vm_stat[item]);
65141 - atomic_long_dec(&vm_stat[item]);
65142 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
65143 + atomic_long_dec_unchecked(&vm_stat[item]);
65144 }
65145
65146 static inline void __dec_zone_page_state(struct page *page,
65147 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
65148 index e5d1220..ef6e406 100644
65149 --- a/include/linux/xattr.h
65150 +++ b/include/linux/xattr.h
65151 @@ -57,6 +57,11 @@
65152 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
65153 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
65154
65155 +/* User namespace */
65156 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
65157 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
65158 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
65159 +
65160 #ifdef __KERNEL__
65161
65162 #include <linux/types.h>
65163 diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
65164 index 944ecdf..a3994fc 100644
65165 --- a/include/media/saa7146_vv.h
65166 +++ b/include/media/saa7146_vv.h
65167 @@ -161,8 +161,8 @@ struct saa7146_ext_vv
65168 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
65169
65170 /* the extension can override this */
65171 - struct v4l2_ioctl_ops vid_ops;
65172 - struct v4l2_ioctl_ops vbi_ops;
65173 + v4l2_ioctl_ops_no_const vid_ops;
65174 + v4l2_ioctl_ops_no_const vbi_ops;
65175 /* pointer to the saa7146 core ops */
65176 const struct v4l2_ioctl_ops *core_ops;
65177
65178 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
65179 index 5c416cd..20021aa 100644
65180 --- a/include/media/v4l2-dev.h
65181 +++ b/include/media/v4l2-dev.h
65182 @@ -73,7 +73,8 @@ struct v4l2_file_operations {
65183 int (*mmap) (struct file *, struct vm_area_struct *);
65184 int (*open) (struct file *);
65185 int (*release) (struct file *);
65186 -};
65187 +} __do_const;
65188 +typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
65189
65190 /*
65191 * Newer version of video_device, handled by videodev2.c
65192 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
65193 index e614c9c..20602b7 100644
65194 --- a/include/media/v4l2-ioctl.h
65195 +++ b/include/media/v4l2-ioctl.h
65196 @@ -289,7 +289,7 @@ struct v4l2_ioctl_ops {
65197 long (*vidioc_default) (struct file *file, void *fh,
65198 bool valid_prio, int cmd, void *arg);
65199 };
65200 -
65201 +typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
65202
65203 /* v4l debugging and diagnostics */
65204
65205 diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
65206 index bcb9cc3..f4ec722e 100644
65207 --- a/include/net/caif/caif_hsi.h
65208 +++ b/include/net/caif/caif_hsi.h
65209 @@ -98,7 +98,7 @@ struct cfhsi_cb_ops {
65210 void (*rx_done_cb) (struct cfhsi_cb_ops *drv);
65211 void (*wake_up_cb) (struct cfhsi_cb_ops *drv);
65212 void (*wake_down_cb) (struct cfhsi_cb_ops *drv);
65213 -};
65214 +} __no_const;
65215
65216 /* Structure implemented by HSI device. */
65217 struct cfhsi_ops {
65218 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
65219 index 9e5425b..8136ffc 100644
65220 --- a/include/net/caif/cfctrl.h
65221 +++ b/include/net/caif/cfctrl.h
65222 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
65223 void (*radioset_rsp)(void);
65224 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
65225 struct cflayer *client_layer);
65226 -};
65227 +} __no_const;
65228
65229 /* Link Setup Parameters for CAIF-Links. */
65230 struct cfctrl_link_param {
65231 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
65232 struct cfctrl {
65233 struct cfsrvl serv;
65234 struct cfctrl_rsp res;
65235 - atomic_t req_seq_no;
65236 - atomic_t rsp_seq_no;
65237 + atomic_unchecked_t req_seq_no;
65238 + atomic_unchecked_t rsp_seq_no;
65239 struct list_head list;
65240 /* Protects from simultaneous access to first_req list */
65241 spinlock_t info_list_lock;
65242 diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
65243 index f10553c..fb5204b 100644
65244 --- a/include/net/cfg80211.h
65245 +++ b/include/net/cfg80211.h
65246 @@ -2633,6 +2633,15 @@ unsigned int ieee80211_get_hdrlen_from_skb(const struct sk_buff *skb);
65247 unsigned int __attribute_const__ ieee80211_hdrlen(__le16 fc);
65248
65249 /**
65250 + * ieee80211_get_mesh_hdrlen - get mesh extension header length
65251 + * @meshhdr: the mesh extension header, only the flags field
65252 + * (first byte) will be accessed
65253 + * Returns the length of the extension header, which is always at
65254 + * least 6 bytes and at most 18 if address 5 and 6 are present.
65255 + */
65256 +unsigned int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr);
65257 +
65258 +/**
65259 * DOC: Data path helpers
65260 *
65261 * In addition to generic utilities, cfg80211 also offers
65262 diff --git a/include/net/flow.h b/include/net/flow.h
65263 index 628e11b..4c475df 100644
65264 --- a/include/net/flow.h
65265 +++ b/include/net/flow.h
65266 @@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
65267
65268 extern void flow_cache_flush(void);
65269 extern void flow_cache_flush_deferred(void);
65270 -extern atomic_t flow_cache_genid;
65271 +extern atomic_unchecked_t flow_cache_genid;
65272
65273 #endif
65274 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
65275 index 53f464d..ba76aaa 100644
65276 --- a/include/net/inetpeer.h
65277 +++ b/include/net/inetpeer.h
65278 @@ -47,8 +47,8 @@ struct inet_peer {
65279 */
65280 union {
65281 struct {
65282 - atomic_t rid; /* Frag reception counter */
65283 - atomic_t ip_id_count; /* IP ID for the next packet */
65284 + atomic_unchecked_t rid; /* Frag reception counter */
65285 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
65286 };
65287 struct rcu_head rcu;
65288 struct inet_peer *gc_next;
65289 @@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
65290 more++;
65291 inet_peer_refcheck(p);
65292 do {
65293 - old = atomic_read(&p->ip_id_count);
65294 + old = atomic_read_unchecked(&p->ip_id_count);
65295 new = old + more;
65296 if (!new)
65297 new = 1;
65298 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
65299 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
65300 return new;
65301 }
65302
65303 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
65304 index 9497be1..5a4fafe 100644
65305 --- a/include/net/ip_fib.h
65306 +++ b/include/net/ip_fib.h
65307 @@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
65308
65309 #define FIB_RES_SADDR(net, res) \
65310 ((FIB_RES_NH(res).nh_saddr_genid == \
65311 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
65312 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
65313 FIB_RES_NH(res).nh_saddr : \
65314 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
65315 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
65316 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
65317 index 95374d1..2300e36 100644
65318 --- a/include/net/ip_vs.h
65319 +++ b/include/net/ip_vs.h
65320 @@ -510,7 +510,7 @@ struct ip_vs_conn {
65321 struct ip_vs_conn *control; /* Master control connection */
65322 atomic_t n_control; /* Number of controlled ones */
65323 struct ip_vs_dest *dest; /* real server */
65324 - atomic_t in_pkts; /* incoming packet counter */
65325 + atomic_unchecked_t in_pkts; /* incoming packet counter */
65326
65327 /* packet transmitter for different forwarding methods. If it
65328 mangles the packet, it must return NF_DROP or better NF_STOLEN,
65329 @@ -648,7 +648,7 @@ struct ip_vs_dest {
65330 __be16 port; /* port number of the server */
65331 union nf_inet_addr addr; /* IP address of the server */
65332 volatile unsigned int flags; /* dest status flags */
65333 - atomic_t conn_flags; /* flags to copy to conn */
65334 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
65335 atomic_t weight; /* server weight */
65336
65337 atomic_t refcnt; /* reference counter */
65338 diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
65339 index 69b610a..fe3962c 100644
65340 --- a/include/net/irda/ircomm_core.h
65341 +++ b/include/net/irda/ircomm_core.h
65342 @@ -51,7 +51,7 @@ typedef struct {
65343 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
65344 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
65345 struct ircomm_info *);
65346 -} call_t;
65347 +} __no_const call_t;
65348
65349 struct ircomm_cb {
65350 irda_queue_t queue;
65351 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
65352 index 59ba38bc..d515662 100644
65353 --- a/include/net/irda/ircomm_tty.h
65354 +++ b/include/net/irda/ircomm_tty.h
65355 @@ -35,6 +35,7 @@
65356 #include <linux/termios.h>
65357 #include <linux/timer.h>
65358 #include <linux/tty.h> /* struct tty_struct */
65359 +#include <asm/local.h>
65360
65361 #include <net/irda/irias_object.h>
65362 #include <net/irda/ircomm_core.h>
65363 @@ -105,8 +106,8 @@ struct ircomm_tty_cb {
65364 unsigned short close_delay;
65365 unsigned short closing_wait; /* time to wait before closing */
65366
65367 - int open_count;
65368 - int blocked_open; /* # of blocked opens */
65369 + local_t open_count;
65370 + local_t blocked_open; /* # of blocked opens */
65371
65372 /* Protect concurent access to :
65373 * o self->open_count
65374 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
65375 index cc7c197..9f2da2a 100644
65376 --- a/include/net/iucv/af_iucv.h
65377 +++ b/include/net/iucv/af_iucv.h
65378 @@ -141,7 +141,7 @@ struct iucv_sock {
65379 struct iucv_sock_list {
65380 struct hlist_head head;
65381 rwlock_t lock;
65382 - atomic_t autobind_name;
65383 + atomic_unchecked_t autobind_name;
65384 };
65385
65386 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
65387 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
65388 index 344d898..2ae1302 100644
65389 --- a/include/net/neighbour.h
65390 +++ b/include/net/neighbour.h
65391 @@ -123,7 +123,7 @@ struct neigh_ops {
65392 void (*error_report)(struct neighbour *, struct sk_buff *);
65393 int (*output)(struct neighbour *, struct sk_buff *);
65394 int (*connected_output)(struct neighbour *, struct sk_buff *);
65395 -};
65396 +} __do_const;
65397
65398 struct pneigh_entry {
65399 struct pneigh_entry *next;
65400 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
65401 index fd87963..312a11f 100644
65402 --- a/include/net/net_namespace.h
65403 +++ b/include/net/net_namespace.h
65404 @@ -102,7 +102,7 @@ struct net {
65405 #endif
65406 struct netns_ipvs *ipvs;
65407 struct sock *diag_nlsk;
65408 - atomic_t rt_genid;
65409 + atomic_unchecked_t rt_genid;
65410 };
65411
65412
65413 @@ -303,12 +303,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
65414
65415 static inline int rt_genid(struct net *net)
65416 {
65417 - return atomic_read(&net->rt_genid);
65418 + return atomic_read_unchecked(&net->rt_genid);
65419 }
65420
65421 static inline void rt_genid_bump(struct net *net)
65422 {
65423 - atomic_inc(&net->rt_genid);
65424 + atomic_inc_unchecked(&net->rt_genid);
65425 }
65426
65427 #endif /* __NET_NET_NAMESPACE_H */
65428 diff --git a/include/net/netdma.h b/include/net/netdma.h
65429 index 8ba8ce2..99b7fff 100644
65430 --- a/include/net/netdma.h
65431 +++ b/include/net/netdma.h
65432 @@ -24,7 +24,7 @@
65433 #include <linux/dmaengine.h>
65434 #include <linux/skbuff.h>
65435
65436 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
65437 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
65438 struct sk_buff *skb, int offset, struct iovec *to,
65439 size_t len, struct dma_pinned_list *pinned_list);
65440
65441 diff --git a/include/net/netlink.h b/include/net/netlink.h
65442 index 785f37a..c81dc0c 100644
65443 --- a/include/net/netlink.h
65444 +++ b/include/net/netlink.h
65445 @@ -520,7 +520,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
65446 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
65447 {
65448 if (mark)
65449 - skb_trim(skb, (unsigned char *) mark - skb->data);
65450 + skb_trim(skb, (const unsigned char *) mark - skb->data);
65451 }
65452
65453 /**
65454 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
65455 index eb24dbc..567d6ed 100644
65456 --- a/include/net/netns/ipv4.h
65457 +++ b/include/net/netns/ipv4.h
65458 @@ -65,7 +65,7 @@ struct netns_ipv4 {
65459 unsigned int sysctl_ping_group_range[2];
65460 long sysctl_tcp_mem[3];
65461
65462 - atomic_t dev_addr_genid;
65463 + atomic_unchecked_t dev_addr_genid;
65464
65465 #ifdef CONFIG_IP_MROUTE
65466 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
65467 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
65468 index ff49964..1411fee 100644
65469 --- a/include/net/sctp/sctp.h
65470 +++ b/include/net/sctp/sctp.h
65471 @@ -320,9 +320,9 @@ do { \
65472
65473 #else /* SCTP_DEBUG */
65474
65475 -#define SCTP_DEBUG_PRINTK(whatever...)
65476 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
65477 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
65478 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
65479 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
65480 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
65481 #define SCTP_ENABLE_DEBUG
65482 #define SCTP_DISABLE_DEBUG
65483 #define SCTP_ASSERT(expr, str, func)
65484 diff --git a/include/net/sock.h b/include/net/sock.h
65485 index adb7da2..1100002 100644
65486 --- a/include/net/sock.h
65487 +++ b/include/net/sock.h
65488 @@ -305,7 +305,7 @@ struct sock {
65489 #ifdef CONFIG_RPS
65490 __u32 sk_rxhash;
65491 #endif
65492 - atomic_t sk_drops;
65493 + atomic_unchecked_t sk_drops;
65494 int sk_rcvbuf;
65495
65496 struct sk_filter __rcu *sk_filter;
65497 @@ -1764,7 +1764,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
65498 }
65499
65500 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
65501 - char __user *from, char *to,
65502 + char __user *from, unsigned char *to,
65503 int copy, int offset)
65504 {
65505 if (skb->ip_summed == CHECKSUM_NONE) {
65506 @@ -2023,7 +2023,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
65507 }
65508 }
65509
65510 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
65511 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
65512
65513 static inline struct page *sk_stream_alloc_page(struct sock *sk)
65514 {
65515 diff --git a/include/net/tcp.h b/include/net/tcp.h
65516 index 1f000ff..e5a8dfb 100644
65517 --- a/include/net/tcp.h
65518 +++ b/include/net/tcp.h
65519 @@ -508,7 +508,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
65520 extern void tcp_xmit_retransmit_queue(struct sock *);
65521 extern void tcp_simple_retransmit(struct sock *);
65522 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
65523 -extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
65524 +extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
65525
65526 extern void tcp_send_probe0(struct sock *);
65527 extern void tcp_send_partial(struct sock *);
65528 @@ -677,8 +677,8 @@ struct tcp_skb_cb {
65529 struct inet6_skb_parm h6;
65530 #endif
65531 } header; /* For incoming frames */
65532 - __u32 seq; /* Starting sequence number */
65533 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
65534 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
65535 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
65536 __u32 when; /* used to compute rtt's */
65537 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
65538
65539 @@ -692,7 +692,7 @@ struct tcp_skb_cb {
65540
65541 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
65542 /* 1 byte hole */
65543 - __u32 ack_seq; /* Sequence number ACK'd */
65544 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
65545 };
65546
65547 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
65548 @@ -1502,7 +1502,7 @@ struct tcp_seq_afinfo {
65549 char *name;
65550 sa_family_t family;
65551 const struct file_operations *seq_fops;
65552 - struct seq_operations seq_ops;
65553 + seq_operations_no_const seq_ops;
65554 };
65555
65556 struct tcp_iter_state {
65557 diff --git a/include/net/udp.h b/include/net/udp.h
65558 index 065f379..b661b40 100644
65559 --- a/include/net/udp.h
65560 +++ b/include/net/udp.h
65561 @@ -244,7 +244,7 @@ struct udp_seq_afinfo {
65562 sa_family_t family;
65563 struct udp_table *udp_table;
65564 const struct file_operations *seq_fops;
65565 - struct seq_operations seq_ops;
65566 + seq_operations_no_const seq_ops;
65567 };
65568
65569 struct udp_iter_state {
65570 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
65571 index 639dd13..15b206c 100644
65572 --- a/include/net/xfrm.h
65573 +++ b/include/net/xfrm.h
65574 @@ -514,7 +514,7 @@ struct xfrm_policy {
65575 struct timer_list timer;
65576
65577 struct flow_cache_object flo;
65578 - atomic_t genid;
65579 + atomic_unchecked_t genid;
65580 u32 priority;
65581 u32 index;
65582 struct xfrm_mark mark;
65583 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
65584 index 1a046b1..ee0bef0 100644
65585 --- a/include/rdma/iw_cm.h
65586 +++ b/include/rdma/iw_cm.h
65587 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
65588 int backlog);
65589
65590 int (*destroy_listen)(struct iw_cm_id *cm_id);
65591 -};
65592 +} __no_const;
65593
65594 /**
65595 * iw_create_cm_id - Create an IW CM identifier.
65596 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
65597 index 399162b..b337f1a 100644
65598 --- a/include/scsi/libfc.h
65599 +++ b/include/scsi/libfc.h
65600 @@ -762,6 +762,7 @@ struct libfc_function_template {
65601 */
65602 void (*disc_stop_final) (struct fc_lport *);
65603 };
65604 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
65605
65606 /**
65607 * struct fc_disc - Discovery context
65608 @@ -866,7 +867,7 @@ struct fc_lport {
65609 struct fc_vport *vport;
65610
65611 /* Operational Information */
65612 - struct libfc_function_template tt;
65613 + libfc_function_template_no_const tt;
65614 u8 link_up;
65615 u8 qfull;
65616 enum fc_lport_state state;
65617 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
65618 index 9895f69..f1418f0 100644
65619 --- a/include/scsi/scsi_device.h
65620 +++ b/include/scsi/scsi_device.h
65621 @@ -166,9 +166,9 @@ struct scsi_device {
65622 unsigned int max_device_blocked; /* what device_blocked counts down from */
65623 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
65624
65625 - atomic_t iorequest_cnt;
65626 - atomic_t iodone_cnt;
65627 - atomic_t ioerr_cnt;
65628 + atomic_unchecked_t iorequest_cnt;
65629 + atomic_unchecked_t iodone_cnt;
65630 + atomic_unchecked_t ioerr_cnt;
65631
65632 struct device sdev_gendev,
65633 sdev_dev;
65634 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
65635 index b797e8f..8e2c3aa 100644
65636 --- a/include/scsi/scsi_transport_fc.h
65637 +++ b/include/scsi/scsi_transport_fc.h
65638 @@ -751,7 +751,8 @@ struct fc_function_template {
65639 unsigned long show_host_system_hostname:1;
65640
65641 unsigned long disable_target_scan:1;
65642 -};
65643 +} __do_const;
65644 +typedef struct fc_function_template __no_const fc_function_template_no_const;
65645
65646
65647 /**
65648 diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
65649 index 030b87c..98a6954 100644
65650 --- a/include/sound/ak4xxx-adda.h
65651 +++ b/include/sound/ak4xxx-adda.h
65652 @@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
65653 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
65654 unsigned char val);
65655 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
65656 -};
65657 +} __no_const;
65658
65659 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
65660
65661 diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
65662 index 8c05e47..2b5df97 100644
65663 --- a/include/sound/hwdep.h
65664 +++ b/include/sound/hwdep.h
65665 @@ -49,7 +49,7 @@ struct snd_hwdep_ops {
65666 struct snd_hwdep_dsp_status *status);
65667 int (*dsp_load)(struct snd_hwdep *hw,
65668 struct snd_hwdep_dsp_image *image);
65669 -};
65670 +} __no_const;
65671
65672 struct snd_hwdep {
65673 struct snd_card *card;
65674 diff --git a/include/sound/info.h b/include/sound/info.h
65675 index 9ca1a49..aba1728 100644
65676 --- a/include/sound/info.h
65677 +++ b/include/sound/info.h
65678 @@ -44,7 +44,7 @@ struct snd_info_entry_text {
65679 struct snd_info_buffer *buffer);
65680 void (*write)(struct snd_info_entry *entry,
65681 struct snd_info_buffer *buffer);
65682 -};
65683 +} __no_const;
65684
65685 struct snd_info_entry_ops {
65686 int (*open)(struct snd_info_entry *entry,
65687 diff --git a/include/sound/pcm.h b/include/sound/pcm.h
65688 index cdca2ab..10bbe05 100644
65689 --- a/include/sound/pcm.h
65690 +++ b/include/sound/pcm.h
65691 @@ -81,6 +81,7 @@ struct snd_pcm_ops {
65692 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
65693 int (*ack)(struct snd_pcm_substream *substream);
65694 };
65695 +typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
65696
65697 /*
65698 *
65699 diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
65700 index af1b49e..a5d55a5 100644
65701 --- a/include/sound/sb16_csp.h
65702 +++ b/include/sound/sb16_csp.h
65703 @@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
65704 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
65705 int (*csp_stop) (struct snd_sb_csp * p);
65706 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
65707 -};
65708 +} __no_const;
65709
65710 /*
65711 * CSP private data
65712 diff --git a/include/sound/soc.h b/include/sound/soc.h
65713 index e063380..e8077d5 100644
65714 --- a/include/sound/soc.h
65715 +++ b/include/sound/soc.h
65716 @@ -801,7 +801,7 @@ struct snd_soc_platform_driver {
65717 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
65718 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
65719 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
65720 -};
65721 +} __do_const;
65722
65723 struct snd_soc_platform {
65724 const char *name;
65725 @@ -1016,7 +1016,7 @@ struct snd_soc_pcm_runtime {
65726 struct snd_soc_dai_link *dai_link;
65727 struct mutex pcm_mutex;
65728 enum snd_soc_pcm_subclass pcm_subclass;
65729 - struct snd_pcm_ops ops;
65730 + snd_pcm_ops_no_const ops;
65731
65732 unsigned int dev_registered:1;
65733
65734 diff --git a/include/sound/tea575x-tuner.h b/include/sound/tea575x-tuner.h
65735 index fe8590c..aaed363 100644
65736 --- a/include/sound/tea575x-tuner.h
65737 +++ b/include/sound/tea575x-tuner.h
65738 @@ -48,7 +48,7 @@ struct snd_tea575x_ops {
65739
65740 struct snd_tea575x {
65741 struct v4l2_device *v4l2_dev;
65742 - struct v4l2_file_operations fops;
65743 + v4l2_file_operations_no_const fops;
65744 struct video_device vd; /* video device */
65745 int radio_nr; /* radio_nr */
65746 bool tea5759; /* 5759 chip is present */
65747 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
65748 index 5be8937..a8e46e9 100644
65749 --- a/include/target/target_core_base.h
65750 +++ b/include/target/target_core_base.h
65751 @@ -434,7 +434,7 @@ struct t10_reservation_ops {
65752 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
65753 int (*t10_pr_register)(struct se_cmd *);
65754 int (*t10_pr_clear)(struct se_cmd *);
65755 -};
65756 +} __no_const;
65757
65758 struct t10_reservation {
65759 /* Reservation effects all target ports */
65760 @@ -758,7 +758,7 @@ struct se_device {
65761 spinlock_t stats_lock;
65762 /* Active commands on this virtual SE device */
65763 atomic_t simple_cmds;
65764 - atomic_t dev_ordered_id;
65765 + atomic_unchecked_t dev_ordered_id;
65766 atomic_t dev_ordered_sync;
65767 atomic_t dev_qf_count;
65768 struct se_obj dev_obj;
65769 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
65770 new file mode 100644
65771 index 0000000..2efe49d
65772 --- /dev/null
65773 +++ b/include/trace/events/fs.h
65774 @@ -0,0 +1,53 @@
65775 +#undef TRACE_SYSTEM
65776 +#define TRACE_SYSTEM fs
65777 +
65778 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
65779 +#define _TRACE_FS_H
65780 +
65781 +#include <linux/fs.h>
65782 +#include <linux/tracepoint.h>
65783 +
65784 +TRACE_EVENT(do_sys_open,
65785 +
65786 + TP_PROTO(char *filename, int flags, int mode),
65787 +
65788 + TP_ARGS(filename, flags, mode),
65789 +
65790 + TP_STRUCT__entry(
65791 + __string( filename, filename )
65792 + __field( int, flags )
65793 + __field( int, mode )
65794 + ),
65795 +
65796 + TP_fast_assign(
65797 + __assign_str(filename, filename);
65798 + __entry->flags = flags;
65799 + __entry->mode = mode;
65800 + ),
65801 +
65802 + TP_printk("\"%s\" %x %o",
65803 + __get_str(filename), __entry->flags, __entry->mode)
65804 +);
65805 +
65806 +TRACE_EVENT(open_exec,
65807 +
65808 + TP_PROTO(const char *filename),
65809 +
65810 + TP_ARGS(filename),
65811 +
65812 + TP_STRUCT__entry(
65813 + __string( filename, filename )
65814 + ),
65815 +
65816 + TP_fast_assign(
65817 + __assign_str(filename, filename);
65818 + ),
65819 +
65820 + TP_printk("\"%s\"",
65821 + __get_str(filename))
65822 +);
65823 +
65824 +#endif /* _TRACE_FS_H */
65825 +
65826 +/* This part must be outside protection */
65827 +#include <trace/define_trace.h>
65828 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
65829 index 1c09820..7f5ec79 100644
65830 --- a/include/trace/events/irq.h
65831 +++ b/include/trace/events/irq.h
65832 @@ -36,7 +36,7 @@ struct softirq_action;
65833 */
65834 TRACE_EVENT(irq_handler_entry,
65835
65836 - TP_PROTO(int irq, struct irqaction *action),
65837 + TP_PROTO(int irq, const struct irqaction *action),
65838
65839 TP_ARGS(irq, action),
65840
65841 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
65842 */
65843 TRACE_EVENT(irq_handler_exit,
65844
65845 - TP_PROTO(int irq, struct irqaction *action, int ret),
65846 + TP_PROTO(int irq, const struct irqaction *action, int ret),
65847
65848 TP_ARGS(irq, action, ret),
65849
65850 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
65851 index f9466fa..f4e2b81 100644
65852 --- a/include/video/udlfb.h
65853 +++ b/include/video/udlfb.h
65854 @@ -53,10 +53,10 @@ struct dlfb_data {
65855 u32 pseudo_palette[256];
65856 int blank_mode; /*one of FB_BLANK_ */
65857 /* blit-only rendering path metrics, exposed through sysfs */
65858 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65859 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
65860 - atomic_t bytes_sent; /* to usb, after compression including overhead */
65861 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
65862 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65863 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
65864 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
65865 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
65866 };
65867
65868 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
65869 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
65870 index 0993a22..32ba2fe 100644
65871 --- a/include/video/uvesafb.h
65872 +++ b/include/video/uvesafb.h
65873 @@ -177,6 +177,7 @@ struct uvesafb_par {
65874 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
65875 u8 pmi_setpal; /* PMI for palette changes */
65876 u16 *pmi_base; /* protected mode interface location */
65877 + u8 *pmi_code; /* protected mode code location */
65878 void *pmi_start;
65879 void *pmi_pal;
65880 u8 *vbe_state_orig; /*
65881 diff --git a/init/Kconfig b/init/Kconfig
65882 index af6c7f8..5c188f8 100644
65883 --- a/init/Kconfig
65884 +++ b/init/Kconfig
65885 @@ -850,6 +850,7 @@ endif # CGROUPS
65886
65887 config CHECKPOINT_RESTORE
65888 bool "Checkpoint/restore support" if EXPERT
65889 + depends on !GRKERNSEC
65890 default n
65891 help
65892 Enables additional kernel features in a sake of checkpoint/restore.
65893 @@ -1029,6 +1030,7 @@ config UIDGID_CONVERTED
65894 # Security modules
65895 depends on SECURITY_TOMOYO = n
65896 depends on SECURITY_APPARMOR = n
65897 + depends on GRKERNSEC = n
65898
65899 config UIDGID_STRICT_TYPE_CHECKS
65900 bool "Require conversions between uid/gids and their internal representation"
65901 @@ -1416,7 +1418,7 @@ config SLUB_DEBUG
65902
65903 config COMPAT_BRK
65904 bool "Disable heap randomization"
65905 - default y
65906 + default n
65907 help
65908 Randomizing heap placement makes heap exploits harder, but it
65909 also breaks ancient binaries (including anything libc5 based).
65910 @@ -1599,7 +1601,7 @@ config INIT_ALL_POSSIBLE
65911 config STOP_MACHINE
65912 bool
65913 default y
65914 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
65915 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
65916 help
65917 Need stop_machine() primitive.
65918
65919 diff --git a/init/Makefile b/init/Makefile
65920 index 7bc47ee..6da2dc7 100644
65921 --- a/init/Makefile
65922 +++ b/init/Makefile
65923 @@ -2,6 +2,9 @@
65924 # Makefile for the linux kernel.
65925 #
65926
65927 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
65928 +asflags-y := $(GCC_PLUGINS_AFLAGS)
65929 +
65930 obj-y := main.o version.o mounts.o
65931 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
65932 obj-y += noinitramfs.o
65933 diff --git a/init/do_mounts.c b/init/do_mounts.c
65934 index d3f0aee..c9322f5 100644
65935 --- a/init/do_mounts.c
65936 +++ b/init/do_mounts.c
65937 @@ -336,11 +336,11 @@ static void __init get_fs_names(char *page)
65938 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
65939 {
65940 struct super_block *s;
65941 - int err = sys_mount(name, "/root", fs, flags, data);
65942 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
65943 if (err)
65944 return err;
65945
65946 - sys_chdir("/root");
65947 + sys_chdir((const char __force_user *)"/root");
65948 s = current->fs->pwd.dentry->d_sb;
65949 ROOT_DEV = s->s_dev;
65950 printk(KERN_INFO
65951 @@ -460,18 +460,18 @@ void __init change_floppy(char *fmt, ...)
65952 va_start(args, fmt);
65953 vsprintf(buf, fmt, args);
65954 va_end(args);
65955 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
65956 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
65957 if (fd >= 0) {
65958 sys_ioctl(fd, FDEJECT, 0);
65959 sys_close(fd);
65960 }
65961 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
65962 - fd = sys_open("/dev/console", O_RDWR, 0);
65963 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
65964 if (fd >= 0) {
65965 sys_ioctl(fd, TCGETS, (long)&termios);
65966 termios.c_lflag &= ~ICANON;
65967 sys_ioctl(fd, TCSETSF, (long)&termios);
65968 - sys_read(fd, &c, 1);
65969 + sys_read(fd, (char __user *)&c, 1);
65970 termios.c_lflag |= ICANON;
65971 sys_ioctl(fd, TCSETSF, (long)&termios);
65972 sys_close(fd);
65973 @@ -565,6 +565,6 @@ void __init prepare_namespace(void)
65974 mount_root();
65975 out:
65976 devtmpfs_mount("dev");
65977 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
65978 - sys_chroot(".");
65979 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65980 + sys_chroot((const char __force_user *)".");
65981 }
65982 diff --git a/init/do_mounts.h b/init/do_mounts.h
65983 index f5b978a..69dbfe8 100644
65984 --- a/init/do_mounts.h
65985 +++ b/init/do_mounts.h
65986 @@ -15,15 +15,15 @@ extern int root_mountflags;
65987
65988 static inline int create_dev(char *name, dev_t dev)
65989 {
65990 - sys_unlink(name);
65991 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
65992 + sys_unlink((char __force_user *)name);
65993 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
65994 }
65995
65996 #if BITS_PER_LONG == 32
65997 static inline u32 bstat(char *name)
65998 {
65999 struct stat64 stat;
66000 - if (sys_stat64(name, &stat) != 0)
66001 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
66002 return 0;
66003 if (!S_ISBLK(stat.st_mode))
66004 return 0;
66005 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
66006 static inline u32 bstat(char *name)
66007 {
66008 struct stat stat;
66009 - if (sys_newstat(name, &stat) != 0)
66010 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
66011 return 0;
66012 if (!S_ISBLK(stat.st_mode))
66013 return 0;
66014 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
66015 index 135959a2..28a3f43 100644
66016 --- a/init/do_mounts_initrd.c
66017 +++ b/init/do_mounts_initrd.c
66018 @@ -53,13 +53,13 @@ static void __init handle_initrd(void)
66019 create_dev("/dev/root.old", Root_RAM0);
66020 /* mount initrd on rootfs' /root */
66021 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
66022 - sys_mkdir("/old", 0700);
66023 - root_fd = sys_open("/", 0, 0);
66024 - old_fd = sys_open("/old", 0, 0);
66025 + sys_mkdir((const char __force_user *)"/old", 0700);
66026 + root_fd = sys_open((const char __force_user *)"/", 0, 0);
66027 + old_fd = sys_open((const char __force_user *)"/old", 0, 0);
66028 /* move initrd over / and chdir/chroot in initrd root */
66029 - sys_chdir("/root");
66030 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
66031 - sys_chroot(".");
66032 + sys_chdir((const char __force_user *)"/root");
66033 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
66034 + sys_chroot((const char __force_user *)".");
66035
66036 /*
66037 * In case that a resume from disk is carried out by linuxrc or one of
66038 @@ -76,15 +76,15 @@ static void __init handle_initrd(void)
66039
66040 /* move initrd to rootfs' /old */
66041 sys_fchdir(old_fd);
66042 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
66043 + sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
66044 /* switch root and cwd back to / of rootfs */
66045 sys_fchdir(root_fd);
66046 - sys_chroot(".");
66047 + sys_chroot((const char __force_user *)".");
66048 sys_close(old_fd);
66049 sys_close(root_fd);
66050
66051 if (new_decode_dev(real_root_dev) == Root_RAM0) {
66052 - sys_chdir("/old");
66053 + sys_chdir((const char __force_user *)"/old");
66054 return;
66055 }
66056
66057 @@ -92,17 +92,17 @@ static void __init handle_initrd(void)
66058 mount_root();
66059
66060 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
66061 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
66062 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
66063 if (!error)
66064 printk("okay\n");
66065 else {
66066 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
66067 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
66068 if (error == -ENOENT)
66069 printk("/initrd does not exist. Ignored.\n");
66070 else
66071 printk("failed\n");
66072 printk(KERN_NOTICE "Unmounting old root\n");
66073 - sys_umount("/old", MNT_DETACH);
66074 + sys_umount((char __force_user *)"/old", MNT_DETACH);
66075 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
66076 if (fd < 0) {
66077 error = fd;
66078 @@ -125,11 +125,11 @@ int __init initrd_load(void)
66079 * mounted in the normal path.
66080 */
66081 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
66082 - sys_unlink("/initrd.image");
66083 + sys_unlink((const char __force_user *)"/initrd.image");
66084 handle_initrd();
66085 return 1;
66086 }
66087 }
66088 - sys_unlink("/initrd.image");
66089 + sys_unlink((const char __force_user *)"/initrd.image");
66090 return 0;
66091 }
66092 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
66093 index 8cb6db5..d729f50 100644
66094 --- a/init/do_mounts_md.c
66095 +++ b/init/do_mounts_md.c
66096 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
66097 partitioned ? "_d" : "", minor,
66098 md_setup_args[ent].device_names);
66099
66100 - fd = sys_open(name, 0, 0);
66101 + fd = sys_open((char __force_user *)name, 0, 0);
66102 if (fd < 0) {
66103 printk(KERN_ERR "md: open failed - cannot start "
66104 "array %s\n", name);
66105 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
66106 * array without it
66107 */
66108 sys_close(fd);
66109 - fd = sys_open(name, 0, 0);
66110 + fd = sys_open((char __force_user *)name, 0, 0);
66111 sys_ioctl(fd, BLKRRPART, 0);
66112 }
66113 sys_close(fd);
66114 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
66115
66116 wait_for_device_probe();
66117
66118 - fd = sys_open("/dev/md0", 0, 0);
66119 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
66120 if (fd >= 0) {
66121 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
66122 sys_close(fd);
66123 diff --git a/init/init_task.c b/init/init_task.c
66124 index 8b2f399..f0797c9 100644
66125 --- a/init/init_task.c
66126 +++ b/init/init_task.c
66127 @@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
66128 * Initial thread structure. Alignment of this is handled by a special
66129 * linker map entry.
66130 */
66131 +#ifdef CONFIG_X86
66132 +union thread_union init_thread_union __init_task_data;
66133 +#else
66134 union thread_union init_thread_union __init_task_data =
66135 { INIT_THREAD_INFO(init_task) };
66136 +#endif
66137 diff --git a/init/initramfs.c b/init/initramfs.c
66138 index 84c6bf1..8899338 100644
66139 --- a/init/initramfs.c
66140 +++ b/init/initramfs.c
66141 @@ -84,7 +84,7 @@ static void __init free_hash(void)
66142 }
66143 }
66144
66145 -static long __init do_utime(char *filename, time_t mtime)
66146 +static long __init do_utime(char __force_user *filename, time_t mtime)
66147 {
66148 struct timespec t[2];
66149
66150 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
66151 struct dir_entry *de, *tmp;
66152 list_for_each_entry_safe(de, tmp, &dir_list, list) {
66153 list_del(&de->list);
66154 - do_utime(de->name, de->mtime);
66155 + do_utime((char __force_user *)de->name, de->mtime);
66156 kfree(de->name);
66157 kfree(de);
66158 }
66159 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
66160 if (nlink >= 2) {
66161 char *old = find_link(major, minor, ino, mode, collected);
66162 if (old)
66163 - return (sys_link(old, collected) < 0) ? -1 : 1;
66164 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
66165 }
66166 return 0;
66167 }
66168 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
66169 {
66170 struct stat st;
66171
66172 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
66173 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
66174 if (S_ISDIR(st.st_mode))
66175 - sys_rmdir(path);
66176 + sys_rmdir((char __force_user *)path);
66177 else
66178 - sys_unlink(path);
66179 + sys_unlink((char __force_user *)path);
66180 }
66181 }
66182
66183 @@ -315,7 +315,7 @@ static int __init do_name(void)
66184 int openflags = O_WRONLY|O_CREAT;
66185 if (ml != 1)
66186 openflags |= O_TRUNC;
66187 - wfd = sys_open(collected, openflags, mode);
66188 + wfd = sys_open((char __force_user *)collected, openflags, mode);
66189
66190 if (wfd >= 0) {
66191 sys_fchown(wfd, uid, gid);
66192 @@ -327,17 +327,17 @@ static int __init do_name(void)
66193 }
66194 }
66195 } else if (S_ISDIR(mode)) {
66196 - sys_mkdir(collected, mode);
66197 - sys_chown(collected, uid, gid);
66198 - sys_chmod(collected, mode);
66199 + sys_mkdir((char __force_user *)collected, mode);
66200 + sys_chown((char __force_user *)collected, uid, gid);
66201 + sys_chmod((char __force_user *)collected, mode);
66202 dir_add(collected, mtime);
66203 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
66204 S_ISFIFO(mode) || S_ISSOCK(mode)) {
66205 if (maybe_link() == 0) {
66206 - sys_mknod(collected, mode, rdev);
66207 - sys_chown(collected, uid, gid);
66208 - sys_chmod(collected, mode);
66209 - do_utime(collected, mtime);
66210 + sys_mknod((char __force_user *)collected, mode, rdev);
66211 + sys_chown((char __force_user *)collected, uid, gid);
66212 + sys_chmod((char __force_user *)collected, mode);
66213 + do_utime((char __force_user *)collected, mtime);
66214 }
66215 }
66216 return 0;
66217 @@ -346,15 +346,15 @@ static int __init do_name(void)
66218 static int __init do_copy(void)
66219 {
66220 if (count >= body_len) {
66221 - sys_write(wfd, victim, body_len);
66222 + sys_write(wfd, (char __force_user *)victim, body_len);
66223 sys_close(wfd);
66224 - do_utime(vcollected, mtime);
66225 + do_utime((char __force_user *)vcollected, mtime);
66226 kfree(vcollected);
66227 eat(body_len);
66228 state = SkipIt;
66229 return 0;
66230 } else {
66231 - sys_write(wfd, victim, count);
66232 + sys_write(wfd, (char __force_user *)victim, count);
66233 body_len -= count;
66234 eat(count);
66235 return 1;
66236 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
66237 {
66238 collected[N_ALIGN(name_len) + body_len] = '\0';
66239 clean_path(collected, 0);
66240 - sys_symlink(collected + N_ALIGN(name_len), collected);
66241 - sys_lchown(collected, uid, gid);
66242 - do_utime(collected, mtime);
66243 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
66244 + sys_lchown((char __force_user *)collected, uid, gid);
66245 + do_utime((char __force_user *)collected, mtime);
66246 state = SkipIt;
66247 next_state = Reset;
66248 return 0;
66249 diff --git a/init/main.c b/init/main.c
66250 index d61ec54..bd3144f 100644
66251 --- a/init/main.c
66252 +++ b/init/main.c
66253 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
66254 extern void tc_init(void);
66255 #endif
66256
66257 +extern void grsecurity_init(void);
66258 +
66259 /*
66260 * Debug helper: via this flag we know that we are in 'early bootup code'
66261 * where only the boot processor is running with IRQ disabled. This means
66262 @@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
66263
66264 __setup("reset_devices", set_reset_devices);
66265
66266 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66267 +int grsec_proc_gid = CONFIG_GRKERNSEC_PROC_GID;
66268 +static int __init setup_grsec_proc_gid(char *str)
66269 +{
66270 + grsec_proc_gid = (int)simple_strtol(str, NULL, 0);
66271 + return 1;
66272 +}
66273 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
66274 +#endif
66275 +
66276 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
66277 +extern char pax_enter_kernel_user[];
66278 +extern char pax_exit_kernel_user[];
66279 +extern pgdval_t clone_pgd_mask;
66280 +#endif
66281 +
66282 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
66283 +static int __init setup_pax_nouderef(char *str)
66284 +{
66285 +#ifdef CONFIG_X86_32
66286 + unsigned int cpu;
66287 + struct desc_struct *gdt;
66288 +
66289 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
66290 + gdt = get_cpu_gdt_table(cpu);
66291 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
66292 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
66293 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
66294 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
66295 + }
66296 + loadsegment(ds, __KERNEL_DS);
66297 + loadsegment(es, __KERNEL_DS);
66298 + loadsegment(ss, __KERNEL_DS);
66299 +#else
66300 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
66301 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
66302 + clone_pgd_mask = ~(pgdval_t)0UL;
66303 +#endif
66304 +
66305 + return 0;
66306 +}
66307 +early_param("pax_nouderef", setup_pax_nouderef);
66308 +#endif
66309 +
66310 +#ifdef CONFIG_PAX_SOFTMODE
66311 +int pax_softmode;
66312 +
66313 +static int __init setup_pax_softmode(char *str)
66314 +{
66315 + get_option(&str, &pax_softmode);
66316 + return 1;
66317 +}
66318 +__setup("pax_softmode=", setup_pax_softmode);
66319 +#endif
66320 +
66321 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
66322 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
66323 static const char *panic_later, *panic_param;
66324 @@ -678,6 +735,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
66325 {
66326 int count = preempt_count();
66327 int ret;
66328 + const char *msg1 = "", *msg2 = "";
66329
66330 if (initcall_debug)
66331 ret = do_one_initcall_debug(fn);
66332 @@ -690,15 +748,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
66333 sprintf(msgbuf, "error code %d ", ret);
66334
66335 if (preempt_count() != count) {
66336 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
66337 + msg1 = " preemption imbalance";
66338 preempt_count() = count;
66339 }
66340 if (irqs_disabled()) {
66341 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
66342 + msg2 = " disabled interrupts";
66343 local_irq_enable();
66344 }
66345 - if (msgbuf[0]) {
66346 - printk("initcall %pF returned with %s\n", fn, msgbuf);
66347 + if (msgbuf[0] || *msg1 || *msg2) {
66348 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
66349 }
66350
66351 return ret;
66352 @@ -752,8 +810,14 @@ static void __init do_initcall_level(int level)
66353 level, level,
66354 &repair_env_string);
66355
66356 - for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
66357 + for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
66358 do_one_initcall(*fn);
66359 +
66360 +#ifdef CONFIG_PAX_LATENT_ENTROPY
66361 + transfer_latent_entropy();
66362 +#endif
66363 +
66364 + }
66365 }
66366
66367 static void __init do_initcalls(void)
66368 @@ -787,8 +851,14 @@ static void __init do_pre_smp_initcalls(void)
66369 {
66370 initcall_t *fn;
66371
66372 - for (fn = __initcall_start; fn < __initcall0_start; fn++)
66373 + for (fn = __initcall_start; fn < __initcall0_start; fn++) {
66374 do_one_initcall(*fn);
66375 +
66376 +#ifdef CONFIG_PAX_LATENT_ENTROPY
66377 + transfer_latent_entropy();
66378 +#endif
66379 +
66380 + }
66381 }
66382
66383 static void run_init_process(const char *init_filename)
66384 @@ -870,7 +940,7 @@ static int __init kernel_init(void * unused)
66385 do_basic_setup();
66386
66387 /* Open the /dev/console on the rootfs, this should never fail */
66388 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
66389 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
66390 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
66391
66392 (void) sys_dup(0);
66393 @@ -883,11 +953,13 @@ static int __init kernel_init(void * unused)
66394 if (!ramdisk_execute_command)
66395 ramdisk_execute_command = "/init";
66396
66397 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
66398 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
66399 ramdisk_execute_command = NULL;
66400 prepare_namespace();
66401 }
66402
66403 + grsecurity_init();
66404 +
66405 /*
66406 * Ok, we have completed the initial bootup, and
66407 * we're essentially up and running. Get rid of the
66408 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
66409 index 9a08acc..e65ebe7 100644
66410 --- a/ipc/mqueue.c
66411 +++ b/ipc/mqueue.c
66412 @@ -279,6 +279,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
66413 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
66414 info->attr.mq_msgsize);
66415
66416 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
66417 spin_lock(&mq_lock);
66418 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
66419 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
66420 diff --git a/ipc/msg.c b/ipc/msg.c
66421 index 7385de2..a8180e08 100644
66422 --- a/ipc/msg.c
66423 +++ b/ipc/msg.c
66424 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
66425 return security_msg_queue_associate(msq, msgflg);
66426 }
66427
66428 +static struct ipc_ops msg_ops = {
66429 + .getnew = newque,
66430 + .associate = msg_security,
66431 + .more_checks = NULL
66432 +};
66433 +
66434 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
66435 {
66436 struct ipc_namespace *ns;
66437 - struct ipc_ops msg_ops;
66438 struct ipc_params msg_params;
66439
66440 ns = current->nsproxy->ipc_ns;
66441
66442 - msg_ops.getnew = newque;
66443 - msg_ops.associate = msg_security;
66444 - msg_ops.more_checks = NULL;
66445 -
66446 msg_params.key = key;
66447 msg_params.flg = msgflg;
66448
66449 diff --git a/ipc/sem.c b/ipc/sem.c
66450 index 5215a81..cfc0cac 100644
66451 --- a/ipc/sem.c
66452 +++ b/ipc/sem.c
66453 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
66454 return 0;
66455 }
66456
66457 +static struct ipc_ops sem_ops = {
66458 + .getnew = newary,
66459 + .associate = sem_security,
66460 + .more_checks = sem_more_checks
66461 +};
66462 +
66463 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66464 {
66465 struct ipc_namespace *ns;
66466 - struct ipc_ops sem_ops;
66467 struct ipc_params sem_params;
66468
66469 ns = current->nsproxy->ipc_ns;
66470 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66471 if (nsems < 0 || nsems > ns->sc_semmsl)
66472 return -EINVAL;
66473
66474 - sem_ops.getnew = newary;
66475 - sem_ops.associate = sem_security;
66476 - sem_ops.more_checks = sem_more_checks;
66477 -
66478 sem_params.key = key;
66479 sem_params.flg = semflg;
66480 sem_params.u.nsems = nsems;
66481 diff --git a/ipc/shm.c b/ipc/shm.c
66482 index 00faa05..7040960 100644
66483 --- a/ipc/shm.c
66484 +++ b/ipc/shm.c
66485 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
66486 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
66487 #endif
66488
66489 +#ifdef CONFIG_GRKERNSEC
66490 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66491 + const time_t shm_createtime, const uid_t cuid,
66492 + const int shmid);
66493 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66494 + const time_t shm_createtime);
66495 +#endif
66496 +
66497 void shm_init_ns(struct ipc_namespace *ns)
66498 {
66499 ns->shm_ctlmax = SHMMAX;
66500 @@ -520,6 +528,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
66501 shp->shm_lprid = 0;
66502 shp->shm_atim = shp->shm_dtim = 0;
66503 shp->shm_ctim = get_seconds();
66504 +#ifdef CONFIG_GRKERNSEC
66505 + {
66506 + struct timespec timeval;
66507 + do_posix_clock_monotonic_gettime(&timeval);
66508 +
66509 + shp->shm_createtime = timeval.tv_sec;
66510 + }
66511 +#endif
66512 shp->shm_segsz = size;
66513 shp->shm_nattch = 0;
66514 shp->shm_file = file;
66515 @@ -571,18 +587,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
66516 return 0;
66517 }
66518
66519 +static struct ipc_ops shm_ops = {
66520 + .getnew = newseg,
66521 + .associate = shm_security,
66522 + .more_checks = shm_more_checks
66523 +};
66524 +
66525 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
66526 {
66527 struct ipc_namespace *ns;
66528 - struct ipc_ops shm_ops;
66529 struct ipc_params shm_params;
66530
66531 ns = current->nsproxy->ipc_ns;
66532
66533 - shm_ops.getnew = newseg;
66534 - shm_ops.associate = shm_security;
66535 - shm_ops.more_checks = shm_more_checks;
66536 -
66537 shm_params.key = key;
66538 shm_params.flg = shmflg;
66539 shm_params.u.size = size;
66540 @@ -1001,6 +1018,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
66541 f_mode = FMODE_READ | FMODE_WRITE;
66542 }
66543 if (shmflg & SHM_EXEC) {
66544 +
66545 +#ifdef CONFIG_PAX_MPROTECT
66546 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
66547 + goto out;
66548 +#endif
66549 +
66550 prot |= PROT_EXEC;
66551 acc_mode |= S_IXUGO;
66552 }
66553 @@ -1024,9 +1047,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
66554 if (err)
66555 goto out_unlock;
66556
66557 +#ifdef CONFIG_GRKERNSEC
66558 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
66559 + shp->shm_perm.cuid, shmid) ||
66560 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
66561 + err = -EACCES;
66562 + goto out_unlock;
66563 + }
66564 +#endif
66565 +
66566 path = shp->shm_file->f_path;
66567 path_get(&path);
66568 shp->shm_nattch++;
66569 +#ifdef CONFIG_GRKERNSEC
66570 + shp->shm_lapid = current->pid;
66571 +#endif
66572 size = i_size_read(path.dentry->d_inode);
66573 shm_unlock(shp);
66574
66575 diff --git a/kernel/acct.c b/kernel/acct.c
66576 index 02e6167..54824f7 100644
66577 --- a/kernel/acct.c
66578 +++ b/kernel/acct.c
66579 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
66580 */
66581 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
66582 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
66583 - file->f_op->write(file, (char *)&ac,
66584 + file->f_op->write(file, (char __force_user *)&ac,
66585 sizeof(acct_t), &file->f_pos);
66586 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
66587 set_fs(fs);
66588 diff --git a/kernel/audit.c b/kernel/audit.c
66589 index a8c84be..8bd034c 100644
66590 --- a/kernel/audit.c
66591 +++ b/kernel/audit.c
66592 @@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
66593 3) suppressed due to audit_rate_limit
66594 4) suppressed due to audit_backlog_limit
66595 */
66596 -static atomic_t audit_lost = ATOMIC_INIT(0);
66597 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
66598
66599 /* The netlink socket. */
66600 static struct sock *audit_sock;
66601 @@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
66602 unsigned long now;
66603 int print;
66604
66605 - atomic_inc(&audit_lost);
66606 + atomic_inc_unchecked(&audit_lost);
66607
66608 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
66609
66610 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
66611 printk(KERN_WARNING
66612 "audit: audit_lost=%d audit_rate_limit=%d "
66613 "audit_backlog_limit=%d\n",
66614 - atomic_read(&audit_lost),
66615 + atomic_read_unchecked(&audit_lost),
66616 audit_rate_limit,
66617 audit_backlog_limit);
66618 audit_panic(message);
66619 @@ -690,7 +690,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
66620 status_set.pid = audit_pid;
66621 status_set.rate_limit = audit_rate_limit;
66622 status_set.backlog_limit = audit_backlog_limit;
66623 - status_set.lost = atomic_read(&audit_lost);
66624 + status_set.lost = atomic_read_unchecked(&audit_lost);
66625 status_set.backlog = skb_queue_len(&audit_skb_queue);
66626 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
66627 &status_set, sizeof(status_set));
66628 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
66629 index 4b96415..d8c16ee 100644
66630 --- a/kernel/auditsc.c
66631 +++ b/kernel/auditsc.c
66632 @@ -2289,7 +2289,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
66633 }
66634
66635 /* global counter which is incremented every time something logs in */
66636 -static atomic_t session_id = ATOMIC_INIT(0);
66637 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
66638
66639 /**
66640 * audit_set_loginuid - set current task's audit_context loginuid
66641 @@ -2313,7 +2313,7 @@ int audit_set_loginuid(uid_t loginuid)
66642 return -EPERM;
66643 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
66644
66645 - sessionid = atomic_inc_return(&session_id);
66646 + sessionid = atomic_inc_return_unchecked(&session_id);
66647 if (context && context->in_syscall) {
66648 struct audit_buffer *ab;
66649
66650 diff --git a/kernel/capability.c b/kernel/capability.c
66651 index 493d972..ea17248 100644
66652 --- a/kernel/capability.c
66653 +++ b/kernel/capability.c
66654 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
66655 * before modification is attempted and the application
66656 * fails.
66657 */
66658 + if (tocopy > ARRAY_SIZE(kdata))
66659 + return -EFAULT;
66660 +
66661 if (copy_to_user(dataptr, kdata, tocopy
66662 * sizeof(struct __user_cap_data_struct))) {
66663 return -EFAULT;
66664 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
66665 int ret;
66666
66667 rcu_read_lock();
66668 - ret = security_capable(__task_cred(t), ns, cap);
66669 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
66670 + gr_task_is_capable(t, __task_cred(t), cap);
66671 rcu_read_unlock();
66672
66673 - return (ret == 0);
66674 + return ret;
66675 }
66676
66677 /**
66678 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
66679 int ret;
66680
66681 rcu_read_lock();
66682 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
66683 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
66684 rcu_read_unlock();
66685
66686 - return (ret == 0);
66687 + return ret;
66688 }
66689
66690 /**
66691 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
66692 BUG();
66693 }
66694
66695 - if (security_capable(current_cred(), ns, cap) == 0) {
66696 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
66697 current->flags |= PF_SUPERPRIV;
66698 return true;
66699 }
66700 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
66701 }
66702 EXPORT_SYMBOL(ns_capable);
66703
66704 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
66705 +{
66706 + if (unlikely(!cap_valid(cap))) {
66707 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
66708 + BUG();
66709 + }
66710 +
66711 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
66712 + current->flags |= PF_SUPERPRIV;
66713 + return true;
66714 + }
66715 + return false;
66716 +}
66717 +EXPORT_SYMBOL(ns_capable_nolog);
66718 +
66719 /**
66720 * capable - Determine if the current task has a superior capability in effect
66721 * @cap: The capability to be tested for
66722 @@ -408,6 +427,12 @@ bool capable(int cap)
66723 }
66724 EXPORT_SYMBOL(capable);
66725
66726 +bool capable_nolog(int cap)
66727 +{
66728 + return ns_capable_nolog(&init_user_ns, cap);
66729 +}
66730 +EXPORT_SYMBOL(capable_nolog);
66731 +
66732 /**
66733 * nsown_capable - Check superior capability to one's own user_ns
66734 * @cap: The capability in question
66735 @@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
66736
66737 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
66738 }
66739 +
66740 +bool inode_capable_nolog(const struct inode *inode, int cap)
66741 +{
66742 + struct user_namespace *ns = current_user_ns();
66743 +
66744 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
66745 +}
66746 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
66747 index ff2bce5..a41e8f9 100644
66748 --- a/kernel/cgroup.c
66749 +++ b/kernel/cgroup.c
66750 @@ -5390,7 +5390,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
66751 struct css_set *cg = link->cg;
66752 struct task_struct *task;
66753 int count = 0;
66754 - seq_printf(seq, "css_set %p\n", cg);
66755 + seq_printf(seq, "css_set %pK\n", cg);
66756 list_for_each_entry(task, &cg->tasks, cg_list) {
66757 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
66758 seq_puts(seq, " ...\n");
66759 diff --git a/kernel/compat.c b/kernel/compat.c
66760 index c28a306..b4d0cf3 100644
66761 --- a/kernel/compat.c
66762 +++ b/kernel/compat.c
66763 @@ -13,6 +13,7 @@
66764
66765 #include <linux/linkage.h>
66766 #include <linux/compat.h>
66767 +#include <linux/module.h>
66768 #include <linux/errno.h>
66769 #include <linux/time.h>
66770 #include <linux/signal.h>
66771 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
66772 mm_segment_t oldfs;
66773 long ret;
66774
66775 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
66776 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
66777 oldfs = get_fs();
66778 set_fs(KERNEL_DS);
66779 ret = hrtimer_nanosleep_restart(restart);
66780 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
66781 oldfs = get_fs();
66782 set_fs(KERNEL_DS);
66783 ret = hrtimer_nanosleep(&tu,
66784 - rmtp ? (struct timespec __user *)&rmt : NULL,
66785 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
66786 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
66787 set_fs(oldfs);
66788
66789 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
66790 mm_segment_t old_fs = get_fs();
66791
66792 set_fs(KERNEL_DS);
66793 - ret = sys_sigpending((old_sigset_t __user *) &s);
66794 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
66795 set_fs(old_fs);
66796 if (ret == 0)
66797 ret = put_user(s, set);
66798 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
66799 mm_segment_t old_fs = get_fs();
66800
66801 set_fs(KERNEL_DS);
66802 - ret = sys_old_getrlimit(resource, &r);
66803 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
66804 set_fs(old_fs);
66805
66806 if (!ret) {
66807 @@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
66808 mm_segment_t old_fs = get_fs();
66809
66810 set_fs(KERNEL_DS);
66811 - ret = sys_getrusage(who, (struct rusage __user *) &r);
66812 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
66813 set_fs(old_fs);
66814
66815 if (ret)
66816 @@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
66817 set_fs (KERNEL_DS);
66818 ret = sys_wait4(pid,
66819 (stat_addr ?
66820 - (unsigned int __user *) &status : NULL),
66821 - options, (struct rusage __user *) &r);
66822 + (unsigned int __force_user *) &status : NULL),
66823 + options, (struct rusage __force_user *) &r);
66824 set_fs (old_fs);
66825
66826 if (ret > 0) {
66827 @@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
66828 memset(&info, 0, sizeof(info));
66829
66830 set_fs(KERNEL_DS);
66831 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
66832 - uru ? (struct rusage __user *)&ru : NULL);
66833 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
66834 + uru ? (struct rusage __force_user *)&ru : NULL);
66835 set_fs(old_fs);
66836
66837 if ((ret < 0) || (info.si_signo == 0))
66838 @@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
66839 oldfs = get_fs();
66840 set_fs(KERNEL_DS);
66841 err = sys_timer_settime(timer_id, flags,
66842 - (struct itimerspec __user *) &newts,
66843 - (struct itimerspec __user *) &oldts);
66844 + (struct itimerspec __force_user *) &newts,
66845 + (struct itimerspec __force_user *) &oldts);
66846 set_fs(oldfs);
66847 if (!err && old && put_compat_itimerspec(old, &oldts))
66848 return -EFAULT;
66849 @@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
66850 oldfs = get_fs();
66851 set_fs(KERNEL_DS);
66852 err = sys_timer_gettime(timer_id,
66853 - (struct itimerspec __user *) &ts);
66854 + (struct itimerspec __force_user *) &ts);
66855 set_fs(oldfs);
66856 if (!err && put_compat_itimerspec(setting, &ts))
66857 return -EFAULT;
66858 @@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
66859 oldfs = get_fs();
66860 set_fs(KERNEL_DS);
66861 err = sys_clock_settime(which_clock,
66862 - (struct timespec __user *) &ts);
66863 + (struct timespec __force_user *) &ts);
66864 set_fs(oldfs);
66865 return err;
66866 }
66867 @@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
66868 oldfs = get_fs();
66869 set_fs(KERNEL_DS);
66870 err = sys_clock_gettime(which_clock,
66871 - (struct timespec __user *) &ts);
66872 + (struct timespec __force_user *) &ts);
66873 set_fs(oldfs);
66874 if (!err && put_compat_timespec(&ts, tp))
66875 return -EFAULT;
66876 @@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
66877
66878 oldfs = get_fs();
66879 set_fs(KERNEL_DS);
66880 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
66881 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
66882 set_fs(oldfs);
66883
66884 err = compat_put_timex(utp, &txc);
66885 @@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
66886 oldfs = get_fs();
66887 set_fs(KERNEL_DS);
66888 err = sys_clock_getres(which_clock,
66889 - (struct timespec __user *) &ts);
66890 + (struct timespec __force_user *) &ts);
66891 set_fs(oldfs);
66892 if (!err && tp && put_compat_timespec(&ts, tp))
66893 return -EFAULT;
66894 @@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
66895 long err;
66896 mm_segment_t oldfs;
66897 struct timespec tu;
66898 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
66899 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
66900
66901 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
66902 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
66903 oldfs = get_fs();
66904 set_fs(KERNEL_DS);
66905 err = clock_nanosleep_restart(restart);
66906 @@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
66907 oldfs = get_fs();
66908 set_fs(KERNEL_DS);
66909 err = sys_clock_nanosleep(which_clock, flags,
66910 - (struct timespec __user *) &in,
66911 - (struct timespec __user *) &out);
66912 + (struct timespec __force_user *) &in,
66913 + (struct timespec __force_user *) &out);
66914 set_fs(oldfs);
66915
66916 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
66917 diff --git a/kernel/configs.c b/kernel/configs.c
66918 index 42e8fa0..9e7406b 100644
66919 --- a/kernel/configs.c
66920 +++ b/kernel/configs.c
66921 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
66922 struct proc_dir_entry *entry;
66923
66924 /* create the current config file */
66925 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
66926 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
66927 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
66928 + &ikconfig_file_ops);
66929 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66930 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
66931 + &ikconfig_file_ops);
66932 +#endif
66933 +#else
66934 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
66935 &ikconfig_file_ops);
66936 +#endif
66937 +
66938 if (!entry)
66939 return -ENOMEM;
66940
66941 diff --git a/kernel/cred.c b/kernel/cred.c
66942 index de728ac..e3c267c 100644
66943 --- a/kernel/cred.c
66944 +++ b/kernel/cred.c
66945 @@ -207,6 +207,16 @@ void exit_creds(struct task_struct *tsk)
66946 validate_creds(cred);
66947 alter_cred_subscribers(cred, -1);
66948 put_cred(cred);
66949 +
66950 +#ifdef CONFIG_GRKERNSEC_SETXID
66951 + cred = (struct cred *) tsk->delayed_cred;
66952 + if (cred != NULL) {
66953 + tsk->delayed_cred = NULL;
66954 + validate_creds(cred);
66955 + alter_cred_subscribers(cred, -1);
66956 + put_cred(cred);
66957 + }
66958 +#endif
66959 }
66960
66961 /**
66962 @@ -469,7 +479,7 @@ error_put:
66963 * Always returns 0 thus allowing this function to be tail-called at the end
66964 * of, say, sys_setgid().
66965 */
66966 -int commit_creds(struct cred *new)
66967 +static int __commit_creds(struct cred *new)
66968 {
66969 struct task_struct *task = current;
66970 const struct cred *old = task->real_cred;
66971 @@ -488,6 +498,8 @@ int commit_creds(struct cred *new)
66972
66973 get_cred(new); /* we will require a ref for the subj creds too */
66974
66975 + gr_set_role_label(task, new->uid, new->gid);
66976 +
66977 /* dumpability changes */
66978 if (!uid_eq(old->euid, new->euid) ||
66979 !gid_eq(old->egid, new->egid) ||
66980 @@ -537,6 +549,101 @@ int commit_creds(struct cred *new)
66981 put_cred(old);
66982 return 0;
66983 }
66984 +#ifdef CONFIG_GRKERNSEC_SETXID
66985 +extern int set_user(struct cred *new);
66986 +
66987 +void gr_delayed_cred_worker(void)
66988 +{
66989 + const struct cred *new = current->delayed_cred;
66990 + struct cred *ncred;
66991 +
66992 + current->delayed_cred = NULL;
66993 +
66994 + if (current_uid() && new != NULL) {
66995 + // from doing get_cred on it when queueing this
66996 + put_cred(new);
66997 + return;
66998 + } else if (new == NULL)
66999 + return;
67000 +
67001 + ncred = prepare_creds();
67002 + if (!ncred)
67003 + goto die;
67004 + // uids
67005 + ncred->uid = new->uid;
67006 + ncred->euid = new->euid;
67007 + ncred->suid = new->suid;
67008 + ncred->fsuid = new->fsuid;
67009 + // gids
67010 + ncred->gid = new->gid;
67011 + ncred->egid = new->egid;
67012 + ncred->sgid = new->sgid;
67013 + ncred->fsgid = new->fsgid;
67014 + // groups
67015 + if (set_groups(ncred, new->group_info) < 0) {
67016 + abort_creds(ncred);
67017 + goto die;
67018 + }
67019 + // caps
67020 + ncred->securebits = new->securebits;
67021 + ncred->cap_inheritable = new->cap_inheritable;
67022 + ncred->cap_permitted = new->cap_permitted;
67023 + ncred->cap_effective = new->cap_effective;
67024 + ncred->cap_bset = new->cap_bset;
67025 +
67026 + if (set_user(ncred)) {
67027 + abort_creds(ncred);
67028 + goto die;
67029 + }
67030 +
67031 + // from doing get_cred on it when queueing this
67032 + put_cred(new);
67033 +
67034 + __commit_creds(ncred);
67035 + return;
67036 +die:
67037 + // from doing get_cred on it when queueing this
67038 + put_cred(new);
67039 + do_group_exit(SIGKILL);
67040 +}
67041 +#endif
67042 +
67043 +int commit_creds(struct cred *new)
67044 +{
67045 +#ifdef CONFIG_GRKERNSEC_SETXID
67046 + int ret;
67047 + int schedule_it = 0;
67048 + struct task_struct *t;
67049 +
67050 + /* we won't get called with tasklist_lock held for writing
67051 + and interrupts disabled as the cred struct in that case is
67052 + init_cred
67053 + */
67054 + if (grsec_enable_setxid && !current_is_single_threaded() &&
67055 + !current_uid() && new->uid) {
67056 + schedule_it = 1;
67057 + }
67058 + ret = __commit_creds(new);
67059 + if (schedule_it) {
67060 + rcu_read_lock();
67061 + read_lock(&tasklist_lock);
67062 + for (t = next_thread(current); t != current;
67063 + t = next_thread(t)) {
67064 + if (t->delayed_cred == NULL) {
67065 + t->delayed_cred = get_cred(new);
67066 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
67067 + set_tsk_need_resched(t);
67068 + }
67069 + }
67070 + read_unlock(&tasklist_lock);
67071 + rcu_read_unlock();
67072 + }
67073 + return ret;
67074 +#else
67075 + return __commit_creds(new);
67076 +#endif
67077 +}
67078 +
67079 EXPORT_SYMBOL(commit_creds);
67080
67081 /**
67082 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
67083 index 0557f24..1a00d9a 100644
67084 --- a/kernel/debug/debug_core.c
67085 +++ b/kernel/debug/debug_core.c
67086 @@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
67087 */
67088 static atomic_t masters_in_kgdb;
67089 static atomic_t slaves_in_kgdb;
67090 -static atomic_t kgdb_break_tasklet_var;
67091 +static atomic_unchecked_t kgdb_break_tasklet_var;
67092 atomic_t kgdb_setting_breakpoint;
67093
67094 struct task_struct *kgdb_usethread;
67095 @@ -132,7 +132,7 @@ int kgdb_single_step;
67096 static pid_t kgdb_sstep_pid;
67097
67098 /* to keep track of the CPU which is doing the single stepping*/
67099 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
67100 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
67101
67102 /*
67103 * If you are debugging a problem where roundup (the collection of
67104 @@ -540,7 +540,7 @@ return_normal:
67105 * kernel will only try for the value of sstep_tries before
67106 * giving up and continuing on.
67107 */
67108 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
67109 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
67110 (kgdb_info[cpu].task &&
67111 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
67112 atomic_set(&kgdb_active, -1);
67113 @@ -634,8 +634,8 @@ cpu_master_loop:
67114 }
67115
67116 kgdb_restore:
67117 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
67118 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
67119 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
67120 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
67121 if (kgdb_info[sstep_cpu].task)
67122 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
67123 else
67124 @@ -861,18 +861,18 @@ static void kgdb_unregister_callbacks(void)
67125 static void kgdb_tasklet_bpt(unsigned long ing)
67126 {
67127 kgdb_breakpoint();
67128 - atomic_set(&kgdb_break_tasklet_var, 0);
67129 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
67130 }
67131
67132 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
67133
67134 void kgdb_schedule_breakpoint(void)
67135 {
67136 - if (atomic_read(&kgdb_break_tasklet_var) ||
67137 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
67138 atomic_read(&kgdb_active) != -1 ||
67139 atomic_read(&kgdb_setting_breakpoint))
67140 return;
67141 - atomic_inc(&kgdb_break_tasklet_var);
67142 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
67143 tasklet_schedule(&kgdb_tasklet_breakpoint);
67144 }
67145 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
67146 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
67147 index 31df170..bc98840 100644
67148 --- a/kernel/debug/kdb/kdb_main.c
67149 +++ b/kernel/debug/kdb/kdb_main.c
67150 @@ -1971,7 +1971,7 @@ static int kdb_lsmod(int argc, const char **argv)
67151 list_for_each_entry(mod, kdb_modules, list) {
67152
67153 kdb_printf("%-20s%8u 0x%p ", mod->name,
67154 - mod->core_size, (void *)mod);
67155 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
67156 #ifdef CONFIG_MODULE_UNLOAD
67157 kdb_printf("%4ld ", module_refcount(mod));
67158 #endif
67159 @@ -1981,7 +1981,7 @@ static int kdb_lsmod(int argc, const char **argv)
67160 kdb_printf(" (Loading)");
67161 else
67162 kdb_printf(" (Live)");
67163 - kdb_printf(" 0x%p", mod->module_core);
67164 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
67165
67166 #ifdef CONFIG_MODULE_UNLOAD
67167 {
67168 diff --git a/kernel/events/core.c b/kernel/events/core.c
67169 index 7fee567..8affa2c 100644
67170 --- a/kernel/events/core.c
67171 +++ b/kernel/events/core.c
67172 @@ -181,7 +181,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
67173 return 0;
67174 }
67175
67176 -static atomic64_t perf_event_id;
67177 +static atomic64_unchecked_t perf_event_id;
67178
67179 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
67180 enum event_type_t event_type);
67181 @@ -2665,7 +2665,7 @@ static void __perf_event_read(void *info)
67182
67183 static inline u64 perf_event_count(struct perf_event *event)
67184 {
67185 - return local64_read(&event->count) + atomic64_read(&event->child_count);
67186 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
67187 }
67188
67189 static u64 perf_event_read(struct perf_event *event)
67190 @@ -2995,9 +2995,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
67191 mutex_lock(&event->child_mutex);
67192 total += perf_event_read(event);
67193 *enabled += event->total_time_enabled +
67194 - atomic64_read(&event->child_total_time_enabled);
67195 + atomic64_read_unchecked(&event->child_total_time_enabled);
67196 *running += event->total_time_running +
67197 - atomic64_read(&event->child_total_time_running);
67198 + atomic64_read_unchecked(&event->child_total_time_running);
67199
67200 list_for_each_entry(child, &event->child_list, child_list) {
67201 total += perf_event_read(child);
67202 @@ -3406,10 +3406,10 @@ void perf_event_update_userpage(struct perf_event *event)
67203 userpg->offset -= local64_read(&event->hw.prev_count);
67204
67205 userpg->time_enabled = enabled +
67206 - atomic64_read(&event->child_total_time_enabled);
67207 + atomic64_read_unchecked(&event->child_total_time_enabled);
67208
67209 userpg->time_running = running +
67210 - atomic64_read(&event->child_total_time_running);
67211 + atomic64_read_unchecked(&event->child_total_time_running);
67212
67213 arch_perf_update_userpage(userpg, now);
67214
67215 @@ -3842,11 +3842,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
67216 values[n++] = perf_event_count(event);
67217 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
67218 values[n++] = enabled +
67219 - atomic64_read(&event->child_total_time_enabled);
67220 + atomic64_read_unchecked(&event->child_total_time_enabled);
67221 }
67222 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
67223 values[n++] = running +
67224 - atomic64_read(&event->child_total_time_running);
67225 + atomic64_read_unchecked(&event->child_total_time_running);
67226 }
67227 if (read_format & PERF_FORMAT_ID)
67228 values[n++] = primary_event_id(event);
67229 @@ -4524,12 +4524,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
67230 * need to add enough zero bytes after the string to handle
67231 * the 64bit alignment we do later.
67232 */
67233 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
67234 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
67235 if (!buf) {
67236 name = strncpy(tmp, "//enomem", sizeof(tmp));
67237 goto got_name;
67238 }
67239 - name = d_path(&file->f_path, buf, PATH_MAX);
67240 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
67241 if (IS_ERR(name)) {
67242 name = strncpy(tmp, "//toolong", sizeof(tmp));
67243 goto got_name;
67244 @@ -5968,7 +5968,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
67245 event->parent = parent_event;
67246
67247 event->ns = get_pid_ns(current->nsproxy->pid_ns);
67248 - event->id = atomic64_inc_return(&perf_event_id);
67249 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
67250
67251 event->state = PERF_EVENT_STATE_INACTIVE;
67252
67253 @@ -6567,10 +6567,10 @@ static void sync_child_event(struct perf_event *child_event,
67254 /*
67255 * Add back the child's count to the parent's count:
67256 */
67257 - atomic64_add(child_val, &parent_event->child_count);
67258 - atomic64_add(child_event->total_time_enabled,
67259 + atomic64_add_unchecked(child_val, &parent_event->child_count);
67260 + atomic64_add_unchecked(child_event->total_time_enabled,
67261 &parent_event->child_total_time_enabled);
67262 - atomic64_add(child_event->total_time_running,
67263 + atomic64_add_unchecked(child_event->total_time_running,
67264 &parent_event->child_total_time_running);
67265
67266 /*
67267 diff --git a/kernel/exit.c b/kernel/exit.c
67268 index f65345f9..9c28dab 100644
67269 --- a/kernel/exit.c
67270 +++ b/kernel/exit.c
67271 @@ -59,6 +59,10 @@
67272 #include <asm/pgtable.h>
67273 #include <asm/mmu_context.h>
67274
67275 +#ifdef CONFIG_GRKERNSEC
67276 +extern rwlock_t grsec_exec_file_lock;
67277 +#endif
67278 +
67279 static void exit_mm(struct task_struct * tsk);
67280
67281 static void __unhash_process(struct task_struct *p, bool group_dead)
67282 @@ -182,6 +186,10 @@ void release_task(struct task_struct * p)
67283 struct task_struct *leader;
67284 int zap_leader;
67285 repeat:
67286 +#ifdef CONFIG_NET
67287 + gr_del_task_from_ip_table(p);
67288 +#endif
67289 +
67290 /* don't need to get the RCU readlock here - the process is dead and
67291 * can't be modifying its own credentials. But shut RCU-lockdep up */
67292 rcu_read_lock();
67293 @@ -394,7 +402,7 @@ int allow_signal(int sig)
67294 * know it'll be handled, so that they don't get converted to
67295 * SIGKILL or just silently dropped.
67296 */
67297 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
67298 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
67299 recalc_sigpending();
67300 spin_unlock_irq(&current->sighand->siglock);
67301 return 0;
67302 @@ -430,6 +438,17 @@ void daemonize(const char *name, ...)
67303 vsnprintf(current->comm, sizeof(current->comm), name, args);
67304 va_end(args);
67305
67306 +#ifdef CONFIG_GRKERNSEC
67307 + write_lock(&grsec_exec_file_lock);
67308 + if (current->exec_file) {
67309 + fput(current->exec_file);
67310 + current->exec_file = NULL;
67311 + }
67312 + write_unlock(&grsec_exec_file_lock);
67313 +#endif
67314 +
67315 + gr_set_kernel_label(current);
67316 +
67317 /*
67318 * If we were started as result of loading a module, close all of the
67319 * user space pages. We don't need them, and if we didn't close them
67320 @@ -907,6 +926,8 @@ void do_exit(long code)
67321 struct task_struct *tsk = current;
67322 int group_dead;
67323
67324 + set_fs(USER_DS);
67325 +
67326 profile_task_exit(tsk);
67327
67328 WARN_ON(blk_needs_flush_plug(tsk));
67329 @@ -923,7 +944,6 @@ void do_exit(long code)
67330 * mm_release()->clear_child_tid() from writing to a user-controlled
67331 * kernel address.
67332 */
67333 - set_fs(USER_DS);
67334
67335 ptrace_event(PTRACE_EVENT_EXIT, code);
67336
67337 @@ -982,6 +1002,9 @@ void do_exit(long code)
67338 tsk->exit_code = code;
67339 taskstats_exit(tsk, group_dead);
67340
67341 + gr_acl_handle_psacct(tsk, code);
67342 + gr_acl_handle_exit();
67343 +
67344 exit_mm(tsk);
67345
67346 if (group_dead)
67347 @@ -1099,7 +1122,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
67348 * Take down every thread in the group. This is called by fatal signals
67349 * as well as by sys_exit_group (below).
67350 */
67351 -void
67352 +__noreturn void
67353 do_group_exit(int exit_code)
67354 {
67355 struct signal_struct *sig = current->signal;
67356 diff --git a/kernel/fork.c b/kernel/fork.c
67357 index 2c8857e..288c9c7 100644
67358 --- a/kernel/fork.c
67359 +++ b/kernel/fork.c
67360 @@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
67361 *stackend = STACK_END_MAGIC; /* for overflow detection */
67362
67363 #ifdef CONFIG_CC_STACKPROTECTOR
67364 - tsk->stack_canary = get_random_int();
67365 + tsk->stack_canary = pax_get_random_long();
67366 #endif
67367
67368 /*
67369 @@ -343,13 +343,78 @@ free_tsk:
67370 }
67371
67372 #ifdef CONFIG_MMU
67373 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
67374 +{
67375 + struct vm_area_struct *tmp;
67376 + unsigned long charge;
67377 + struct mempolicy *pol;
67378 + struct file *file;
67379 +
67380 + charge = 0;
67381 + if (mpnt->vm_flags & VM_ACCOUNT) {
67382 + unsigned long len = vma_pages(mpnt);
67383 +
67384 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
67385 + goto fail_nomem;
67386 + charge = len;
67387 + }
67388 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67389 + if (!tmp)
67390 + goto fail_nomem;
67391 + *tmp = *mpnt;
67392 + tmp->vm_mm = mm;
67393 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
67394 + pol = mpol_dup(vma_policy(mpnt));
67395 + if (IS_ERR(pol))
67396 + goto fail_nomem_policy;
67397 + vma_set_policy(tmp, pol);
67398 + if (anon_vma_fork(tmp, mpnt))
67399 + goto fail_nomem_anon_vma_fork;
67400 + tmp->vm_flags &= ~VM_LOCKED;
67401 + tmp->vm_next = tmp->vm_prev = NULL;
67402 + tmp->vm_mirror = NULL;
67403 + file = tmp->vm_file;
67404 + if (file) {
67405 + struct inode *inode = file->f_path.dentry->d_inode;
67406 + struct address_space *mapping = file->f_mapping;
67407 +
67408 + get_file(file);
67409 + if (tmp->vm_flags & VM_DENYWRITE)
67410 + atomic_dec(&inode->i_writecount);
67411 + mutex_lock(&mapping->i_mmap_mutex);
67412 + if (tmp->vm_flags & VM_SHARED)
67413 + mapping->i_mmap_writable++;
67414 + flush_dcache_mmap_lock(mapping);
67415 + /* insert tmp into the share list, just after mpnt */
67416 + vma_prio_tree_add(tmp, mpnt);
67417 + flush_dcache_mmap_unlock(mapping);
67418 + mutex_unlock(&mapping->i_mmap_mutex);
67419 + }
67420 +
67421 + /*
67422 + * Clear hugetlb-related page reserves for children. This only
67423 + * affects MAP_PRIVATE mappings. Faults generated by the child
67424 + * are not guaranteed to succeed, even if read-only
67425 + */
67426 + if (is_vm_hugetlb_page(tmp))
67427 + reset_vma_resv_huge_pages(tmp);
67428 +
67429 + return tmp;
67430 +
67431 +fail_nomem_anon_vma_fork:
67432 + mpol_put(pol);
67433 +fail_nomem_policy:
67434 + kmem_cache_free(vm_area_cachep, tmp);
67435 +fail_nomem:
67436 + vm_unacct_memory(charge);
67437 + return NULL;
67438 +}
67439 +
67440 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67441 {
67442 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
67443 struct rb_node **rb_link, *rb_parent;
67444 int retval;
67445 - unsigned long charge;
67446 - struct mempolicy *pol;
67447
67448 down_write(&oldmm->mmap_sem);
67449 flush_cache_dup_mm(oldmm);
67450 @@ -361,8 +426,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67451 mm->locked_vm = 0;
67452 mm->mmap = NULL;
67453 mm->mmap_cache = NULL;
67454 - mm->free_area_cache = oldmm->mmap_base;
67455 - mm->cached_hole_size = ~0UL;
67456 + mm->free_area_cache = oldmm->free_area_cache;
67457 + mm->cached_hole_size = oldmm->cached_hole_size;
67458 mm->map_count = 0;
67459 cpumask_clear(mm_cpumask(mm));
67460 mm->mm_rb = RB_ROOT;
67461 @@ -378,52 +443,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67462
67463 prev = NULL;
67464 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
67465 - struct file *file;
67466 -
67467 if (mpnt->vm_flags & VM_DONTCOPY) {
67468 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
67469 -vma_pages(mpnt));
67470 continue;
67471 }
67472 - charge = 0;
67473 - if (mpnt->vm_flags & VM_ACCOUNT) {
67474 - unsigned long len = vma_pages(mpnt);
67475 -
67476 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
67477 - goto fail_nomem;
67478 - charge = len;
67479 - }
67480 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67481 - if (!tmp)
67482 - goto fail_nomem;
67483 - *tmp = *mpnt;
67484 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
67485 - pol = mpol_dup(vma_policy(mpnt));
67486 - retval = PTR_ERR(pol);
67487 - if (IS_ERR(pol))
67488 - goto fail_nomem_policy;
67489 - vma_set_policy(tmp, pol);
67490 - tmp->vm_mm = mm;
67491 - if (anon_vma_fork(tmp, mpnt))
67492 - goto fail_nomem_anon_vma_fork;
67493 - tmp->vm_flags &= ~VM_LOCKED;
67494 - tmp->vm_next = tmp->vm_prev = NULL;
67495 - file = tmp->vm_file;
67496 - if (file) {
67497 - struct inode *inode = file->f_path.dentry->d_inode;
67498 - struct address_space *mapping = file->f_mapping;
67499 -
67500 - get_file(file);
67501 - if (tmp->vm_flags & VM_DENYWRITE)
67502 - atomic_dec(&inode->i_writecount);
67503 - mutex_lock(&mapping->i_mmap_mutex);
67504 - if (tmp->vm_flags & VM_SHARED)
67505 - mapping->i_mmap_writable++;
67506 - flush_dcache_mmap_lock(mapping);
67507 - /* insert tmp into the share list, just after mpnt */
67508 - vma_prio_tree_add(tmp, mpnt);
67509 - flush_dcache_mmap_unlock(mapping);
67510 - mutex_unlock(&mapping->i_mmap_mutex);
67511 + tmp = dup_vma(mm, oldmm, mpnt);
67512 + if (!tmp) {
67513 + retval = -ENOMEM;
67514 + goto out;
67515 }
67516
67517 /*
67518 @@ -455,9 +483,34 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67519 if (retval)
67520 goto out;
67521
67522 - if (file)
67523 + if (tmp->vm_file)
67524 uprobe_mmap(tmp);
67525 }
67526 +
67527 +#ifdef CONFIG_PAX_SEGMEXEC
67528 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
67529 + struct vm_area_struct *mpnt_m;
67530 +
67531 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
67532 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
67533 +
67534 + if (!mpnt->vm_mirror)
67535 + continue;
67536 +
67537 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
67538 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
67539 + mpnt->vm_mirror = mpnt_m;
67540 + } else {
67541 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
67542 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
67543 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
67544 + mpnt->vm_mirror->vm_mirror = mpnt;
67545 + }
67546 + }
67547 + BUG_ON(mpnt_m);
67548 + }
67549 +#endif
67550 +
67551 /* a new mm has just been created */
67552 arch_dup_mmap(oldmm, mm);
67553 retval = 0;
67554 @@ -466,14 +519,6 @@ out:
67555 flush_tlb_mm(oldmm);
67556 up_write(&oldmm->mmap_sem);
67557 return retval;
67558 -fail_nomem_anon_vma_fork:
67559 - mpol_put(pol);
67560 -fail_nomem_policy:
67561 - kmem_cache_free(vm_area_cachep, tmp);
67562 -fail_nomem:
67563 - retval = -ENOMEM;
67564 - vm_unacct_memory(charge);
67565 - goto out;
67566 }
67567
67568 static inline int mm_alloc_pgd(struct mm_struct *mm)
67569 @@ -710,8 +755,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
67570 return ERR_PTR(err);
67571
67572 mm = get_task_mm(task);
67573 - if (mm && mm != current->mm &&
67574 - !ptrace_may_access(task, mode)) {
67575 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
67576 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
67577 mmput(mm);
67578 mm = ERR_PTR(-EACCES);
67579 }
67580 @@ -932,13 +977,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
67581 spin_unlock(&fs->lock);
67582 return -EAGAIN;
67583 }
67584 - fs->users++;
67585 + atomic_inc(&fs->users);
67586 spin_unlock(&fs->lock);
67587 return 0;
67588 }
67589 tsk->fs = copy_fs_struct(fs);
67590 if (!tsk->fs)
67591 return -ENOMEM;
67592 + /* Carry through gr_chroot_dentry and is_chrooted instead
67593 + of recomputing it here. Already copied when the task struct
67594 + is duplicated. This allows pivot_root to not be treated as
67595 + a chroot
67596 + */
67597 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
67598 +
67599 return 0;
67600 }
67601
67602 @@ -1205,6 +1257,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
67603 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
67604 #endif
67605 retval = -EAGAIN;
67606 +
67607 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
67608 +
67609 if (atomic_read(&p->real_cred->user->processes) >=
67610 task_rlimit(p, RLIMIT_NPROC)) {
67611 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
67612 @@ -1427,6 +1482,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
67613 /* Need tasklist lock for parent etc handling! */
67614 write_lock_irq(&tasklist_lock);
67615
67616 + /* synchronizes with gr_set_acls() */
67617 + gr_copy_label(p);
67618 +
67619 /* CLONE_PARENT re-uses the old parent */
67620 if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) {
67621 p->real_parent = current->real_parent;
67622 @@ -1537,6 +1595,8 @@ bad_fork_cleanup_count:
67623 bad_fork_free:
67624 free_task(p);
67625 fork_out:
67626 + gr_log_forkfail(retval);
67627 +
67628 return ERR_PTR(retval);
67629 }
67630
67631 @@ -1637,6 +1697,8 @@ long do_fork(unsigned long clone_flags,
67632 if (clone_flags & CLONE_PARENT_SETTID)
67633 put_user(nr, parent_tidptr);
67634
67635 + gr_handle_brute_check();
67636 +
67637 if (clone_flags & CLONE_VFORK) {
67638 p->vfork_done = &vfork;
67639 init_completion(&vfork);
67640 @@ -1735,7 +1797,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
67641 return 0;
67642
67643 /* don't need lock here; in the worst case we'll do useless copy */
67644 - if (fs->users == 1)
67645 + if (atomic_read(&fs->users) == 1)
67646 return 0;
67647
67648 *new_fsp = copy_fs_struct(fs);
67649 @@ -1824,7 +1886,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
67650 fs = current->fs;
67651 spin_lock(&fs->lock);
67652 current->fs = new_fs;
67653 - if (--fs->users)
67654 + gr_set_chroot_entries(current, &current->fs->root);
67655 + if (atomic_dec_return(&fs->users))
67656 new_fs = NULL;
67657 else
67658 new_fs = fs;
67659 diff --git a/kernel/futex.c b/kernel/futex.c
67660 index 3717e7b..473c750 100644
67661 --- a/kernel/futex.c
67662 +++ b/kernel/futex.c
67663 @@ -54,6 +54,7 @@
67664 #include <linux/mount.h>
67665 #include <linux/pagemap.h>
67666 #include <linux/syscalls.h>
67667 +#include <linux/ptrace.h>
67668 #include <linux/signal.h>
67669 #include <linux/export.h>
67670 #include <linux/magic.h>
67671 @@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
67672 struct page *page, *page_head;
67673 int err, ro = 0;
67674
67675 +#ifdef CONFIG_PAX_SEGMEXEC
67676 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
67677 + return -EFAULT;
67678 +#endif
67679 +
67680 /*
67681 * The futex address must be "naturally" aligned.
67682 */
67683 @@ -2714,6 +2720,7 @@ static int __init futex_init(void)
67684 {
67685 u32 curval;
67686 int i;
67687 + mm_segment_t oldfs;
67688
67689 /*
67690 * This will fail and we want it. Some arch implementations do
67691 @@ -2725,8 +2732,11 @@ static int __init futex_init(void)
67692 * implementation, the non-functional ones will return
67693 * -ENOSYS.
67694 */
67695 + oldfs = get_fs();
67696 + set_fs(USER_DS);
67697 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
67698 futex_cmpxchg_enabled = 1;
67699 + set_fs(oldfs);
67700
67701 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
67702 plist_head_init(&futex_queues[i].chain);
67703 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
67704 index 9b22d03..6295b62 100644
67705 --- a/kernel/gcov/base.c
67706 +++ b/kernel/gcov/base.c
67707 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
67708 }
67709
67710 #ifdef CONFIG_MODULES
67711 -static inline int within(void *addr, void *start, unsigned long size)
67712 -{
67713 - return ((addr >= start) && (addr < start + size));
67714 -}
67715 -
67716 /* Update list and generate events when modules are unloaded. */
67717 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67718 void *data)
67719 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67720 prev = NULL;
67721 /* Remove entries located in module from linked list. */
67722 for (info = gcov_info_head; info; info = info->next) {
67723 - if (within(info, mod->module_core, mod->core_size)) {
67724 + if (within_module_core_rw((unsigned long)info, mod)) {
67725 if (prev)
67726 prev->next = info->next;
67727 else
67728 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
67729 index 6db7a5e..25b6648 100644
67730 --- a/kernel/hrtimer.c
67731 +++ b/kernel/hrtimer.c
67732 @@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
67733 local_irq_restore(flags);
67734 }
67735
67736 -static void run_hrtimer_softirq(struct softirq_action *h)
67737 +static void run_hrtimer_softirq(void)
67738 {
67739 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
67740
67741 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
67742 index 4304919..408c4c0 100644
67743 --- a/kernel/jump_label.c
67744 +++ b/kernel/jump_label.c
67745 @@ -13,6 +13,7 @@
67746 #include <linux/sort.h>
67747 #include <linux/err.h>
67748 #include <linux/static_key.h>
67749 +#include <linux/mm.h>
67750
67751 #ifdef HAVE_JUMP_LABEL
67752
67753 @@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
67754
67755 size = (((unsigned long)stop - (unsigned long)start)
67756 / sizeof(struct jump_entry));
67757 + pax_open_kernel();
67758 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
67759 + pax_close_kernel();
67760 }
67761
67762 static void jump_label_update(struct static_key *key, int enable);
67763 @@ -356,10 +359,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
67764 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
67765 struct jump_entry *iter;
67766
67767 + pax_open_kernel();
67768 for (iter = iter_start; iter < iter_stop; iter++) {
67769 if (within_module_init(iter->code, mod))
67770 iter->code = 0;
67771 }
67772 + pax_close_kernel();
67773 }
67774
67775 static int
67776 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
67777 index 2169fee..45c017a 100644
67778 --- a/kernel/kallsyms.c
67779 +++ b/kernel/kallsyms.c
67780 @@ -11,6 +11,9 @@
67781 * Changed the compression method from stem compression to "table lookup"
67782 * compression (see scripts/kallsyms.c for a more complete description)
67783 */
67784 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67785 +#define __INCLUDED_BY_HIDESYM 1
67786 +#endif
67787 #include <linux/kallsyms.h>
67788 #include <linux/module.h>
67789 #include <linux/init.h>
67790 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
67791
67792 static inline int is_kernel_inittext(unsigned long addr)
67793 {
67794 + if (system_state != SYSTEM_BOOTING)
67795 + return 0;
67796 +
67797 if (addr >= (unsigned long)_sinittext
67798 && addr <= (unsigned long)_einittext)
67799 return 1;
67800 return 0;
67801 }
67802
67803 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67804 +#ifdef CONFIG_MODULES
67805 +static inline int is_module_text(unsigned long addr)
67806 +{
67807 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
67808 + return 1;
67809 +
67810 + addr = ktla_ktva(addr);
67811 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
67812 +}
67813 +#else
67814 +static inline int is_module_text(unsigned long addr)
67815 +{
67816 + return 0;
67817 +}
67818 +#endif
67819 +#endif
67820 +
67821 static inline int is_kernel_text(unsigned long addr)
67822 {
67823 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
67824 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
67825
67826 static inline int is_kernel(unsigned long addr)
67827 {
67828 +
67829 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67830 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
67831 + return 1;
67832 +
67833 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
67834 +#else
67835 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
67836 +#endif
67837 +
67838 return 1;
67839 return in_gate_area_no_mm(addr);
67840 }
67841
67842 static int is_ksym_addr(unsigned long addr)
67843 {
67844 +
67845 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67846 + if (is_module_text(addr))
67847 + return 0;
67848 +#endif
67849 +
67850 if (all_var)
67851 return is_kernel(addr);
67852
67853 @@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
67854
67855 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
67856 {
67857 - iter->name[0] = '\0';
67858 iter->nameoff = get_symbol_offset(new_pos);
67859 iter->pos = new_pos;
67860 }
67861 @@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
67862 {
67863 struct kallsym_iter *iter = m->private;
67864
67865 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67866 + if (current_uid())
67867 + return 0;
67868 +#endif
67869 +
67870 /* Some debugging symbols have no name. Ignore them. */
67871 if (!iter->name[0])
67872 return 0;
67873 @@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
67874 */
67875 type = iter->exported ? toupper(iter->type) :
67876 tolower(iter->type);
67877 +
67878 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
67879 type, iter->name, iter->module_name);
67880 } else
67881 @@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
67882 struct kallsym_iter *iter;
67883 int ret;
67884
67885 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
67886 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
67887 if (!iter)
67888 return -ENOMEM;
67889 reset_iter(iter, 0);
67890 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
67891 index 30b7b22..c726387 100644
67892 --- a/kernel/kcmp.c
67893 +++ b/kernel/kcmp.c
67894 @@ -98,6 +98,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
67895 struct task_struct *task1, *task2;
67896 int ret;
67897
67898 +#ifdef CONFIG_GRKERNSEC
67899 + return -ENOSYS;
67900 +#endif
67901 +
67902 rcu_read_lock();
67903
67904 /*
67905 diff --git a/kernel/kexec.c b/kernel/kexec.c
67906 index 0668d58..591b6fc 100644
67907 --- a/kernel/kexec.c
67908 +++ b/kernel/kexec.c
67909 @@ -1046,7 +1046,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
67910 unsigned long flags)
67911 {
67912 struct compat_kexec_segment in;
67913 - struct kexec_segment out, __user *ksegments;
67914 + struct kexec_segment out;
67915 + struct kexec_segment __user *ksegments;
67916 unsigned long i, result;
67917
67918 /* Don't allow clients that don't understand the native
67919 diff --git a/kernel/kmod.c b/kernel/kmod.c
67920 index 6f99aea..eb6e3a0 100644
67921 --- a/kernel/kmod.c
67922 +++ b/kernel/kmod.c
67923 @@ -73,7 +73,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
67924 kfree(info->argv);
67925 }
67926
67927 -static int call_modprobe(char *module_name, int wait)
67928 +static int call_modprobe(char *module_name, char *module_param, int wait)
67929 {
67930 static char *envp[] = {
67931 "HOME=/",
67932 @@ -82,7 +82,7 @@ static int call_modprobe(char *module_name, int wait)
67933 NULL
67934 };
67935
67936 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
67937 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
67938 if (!argv)
67939 goto out;
67940
67941 @@ -94,7 +94,8 @@ static int call_modprobe(char *module_name, int wait)
67942 argv[1] = "-q";
67943 argv[2] = "--";
67944 argv[3] = module_name; /* check free_modprobe_argv() */
67945 - argv[4] = NULL;
67946 + argv[4] = module_param;
67947 + argv[5] = NULL;
67948
67949 return call_usermodehelper_fns(modprobe_path, argv, envp,
67950 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
67951 @@ -119,9 +120,8 @@ out:
67952 * If module auto-loading support is disabled then this function
67953 * becomes a no-operation.
67954 */
67955 -int __request_module(bool wait, const char *fmt, ...)
67956 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
67957 {
67958 - va_list args;
67959 char module_name[MODULE_NAME_LEN];
67960 unsigned int max_modprobes;
67961 int ret;
67962 @@ -129,9 +129,7 @@ int __request_module(bool wait, const char *fmt, ...)
67963 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
67964 static int kmod_loop_msg;
67965
67966 - va_start(args, fmt);
67967 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
67968 - va_end(args);
67969 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
67970 if (ret >= MODULE_NAME_LEN)
67971 return -ENAMETOOLONG;
67972
67973 @@ -139,6 +137,20 @@ int __request_module(bool wait, const char *fmt, ...)
67974 if (ret)
67975 return ret;
67976
67977 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67978 + if (!current_uid()) {
67979 + /* hack to workaround consolekit/udisks stupidity */
67980 + read_lock(&tasklist_lock);
67981 + if (!strcmp(current->comm, "mount") &&
67982 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
67983 + read_unlock(&tasklist_lock);
67984 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
67985 + return -EPERM;
67986 + }
67987 + read_unlock(&tasklist_lock);
67988 + }
67989 +#endif
67990 +
67991 /* If modprobe needs a service that is in a module, we get a recursive
67992 * loop. Limit the number of running kmod threads to max_threads/2 or
67993 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
67994 @@ -167,11 +179,52 @@ int __request_module(bool wait, const char *fmt, ...)
67995
67996 trace_module_request(module_name, wait, _RET_IP_);
67997
67998 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
67999 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
68000
68001 atomic_dec(&kmod_concurrent);
68002 return ret;
68003 }
68004 +
68005 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
68006 +{
68007 + va_list args;
68008 + int ret;
68009 +
68010 + va_start(args, fmt);
68011 + ret = ____request_module(wait, module_param, fmt, args);
68012 + va_end(args);
68013 +
68014 + return ret;
68015 +}
68016 +
68017 +int __request_module(bool wait, const char *fmt, ...)
68018 +{
68019 + va_list args;
68020 + int ret;
68021 +
68022 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68023 + if (current_uid()) {
68024 + char module_param[MODULE_NAME_LEN];
68025 +
68026 + memset(module_param, 0, sizeof(module_param));
68027 +
68028 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
68029 +
68030 + va_start(args, fmt);
68031 + ret = ____request_module(wait, module_param, fmt, args);
68032 + va_end(args);
68033 +
68034 + return ret;
68035 + }
68036 +#endif
68037 +
68038 + va_start(args, fmt);
68039 + ret = ____request_module(wait, NULL, fmt, args);
68040 + va_end(args);
68041 +
68042 + return ret;
68043 +}
68044 +
68045 EXPORT_SYMBOL(__request_module);
68046 #endif /* CONFIG_MODULES */
68047
68048 @@ -280,7 +333,7 @@ static int wait_for_helper(void *data)
68049 *
68050 * Thus the __user pointer cast is valid here.
68051 */
68052 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
68053 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
68054
68055 /*
68056 * If ret is 0, either ____call_usermodehelper failed and the
68057 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
68058 index c62b854..6fc810d 100644
68059 --- a/kernel/kprobes.c
68060 +++ b/kernel/kprobes.c
68061 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
68062 * kernel image and loaded module images reside. This is required
68063 * so x86_64 can correctly handle the %rip-relative fixups.
68064 */
68065 - kip->insns = module_alloc(PAGE_SIZE);
68066 + kip->insns = module_alloc_exec(PAGE_SIZE);
68067 if (!kip->insns) {
68068 kfree(kip);
68069 return NULL;
68070 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
68071 */
68072 if (!list_is_singular(&kip->list)) {
68073 list_del(&kip->list);
68074 - module_free(NULL, kip->insns);
68075 + module_free_exec(NULL, kip->insns);
68076 kfree(kip);
68077 }
68078 return 1;
68079 @@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
68080 {
68081 int i, err = 0;
68082 unsigned long offset = 0, size = 0;
68083 - char *modname, namebuf[128];
68084 + char *modname, namebuf[KSYM_NAME_LEN];
68085 const char *symbol_name;
68086 void *addr;
68087 struct kprobe_blackpoint *kb;
68088 @@ -2040,11 +2040,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
68089 kprobe_type = "k";
68090
68091 if (sym)
68092 - seq_printf(pi, "%p %s %s+0x%x %s ",
68093 + seq_printf(pi, "%pK %s %s+0x%x %s ",
68094 p->addr, kprobe_type, sym, offset,
68095 (modname ? modname : " "));
68096 else
68097 - seq_printf(pi, "%p %s %p ",
68098 + seq_printf(pi, "%pK %s %pK ",
68099 p->addr, kprobe_type, p->addr);
68100
68101 if (!pp)
68102 @@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
68103 const char *sym = NULL;
68104 unsigned int i = *(loff_t *) v;
68105 unsigned long offset = 0;
68106 - char *modname, namebuf[128];
68107 + char *modname, namebuf[KSYM_NAME_LEN];
68108
68109 head = &kprobe_table[i];
68110 preempt_disable();
68111 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
68112 index 4e316e1..5501eef 100644
68113 --- a/kernel/ksysfs.c
68114 +++ b/kernel/ksysfs.c
68115 @@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
68116 {
68117 if (count+1 > UEVENT_HELPER_PATH_LEN)
68118 return -ENOENT;
68119 + if (!capable(CAP_SYS_ADMIN))
68120 + return -EPERM;
68121 memcpy(uevent_helper, buf, count);
68122 uevent_helper[count] = '\0';
68123 if (count && uevent_helper[count-1] == '\n')
68124 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
68125 index ea9ee45..67ebc8f 100644
68126 --- a/kernel/lockdep.c
68127 +++ b/kernel/lockdep.c
68128 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
68129 end = (unsigned long) &_end,
68130 addr = (unsigned long) obj;
68131
68132 +#ifdef CONFIG_PAX_KERNEXEC
68133 + start = ktla_ktva(start);
68134 +#endif
68135 +
68136 /*
68137 * static variable?
68138 */
68139 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
68140 if (!static_obj(lock->key)) {
68141 debug_locks_off();
68142 printk("INFO: trying to register non-static key.\n");
68143 + printk("lock:%pS key:%pS.\n", lock, lock->key);
68144 printk("the code is fine but needs lockdep annotation.\n");
68145 printk("turning off the locking correctness validator.\n");
68146 dump_stack();
68147 @@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
68148 if (!class)
68149 return 0;
68150 }
68151 - atomic_inc((atomic_t *)&class->ops);
68152 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
68153 if (very_verbose(class)) {
68154 printk("\nacquire class [%p] %s", class->key, class->name);
68155 if (class->name_version > 1)
68156 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
68157 index 91c32a0..7b88d63 100644
68158 --- a/kernel/lockdep_proc.c
68159 +++ b/kernel/lockdep_proc.c
68160 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
68161
68162 static void print_name(struct seq_file *m, struct lock_class *class)
68163 {
68164 - char str[128];
68165 + char str[KSYM_NAME_LEN];
68166 const char *name = class->name;
68167
68168 if (!name) {
68169 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
68170 return 0;
68171 }
68172
68173 - seq_printf(m, "%p", class->key);
68174 + seq_printf(m, "%pK", class->key);
68175 #ifdef CONFIG_DEBUG_LOCKDEP
68176 seq_printf(m, " OPS:%8ld", class->ops);
68177 #endif
68178 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
68179
68180 list_for_each_entry(entry, &class->locks_after, entry) {
68181 if (entry->distance == 1) {
68182 - seq_printf(m, " -> [%p] ", entry->class->key);
68183 + seq_printf(m, " -> [%pK] ", entry->class->key);
68184 print_name(m, entry->class);
68185 seq_puts(m, "\n");
68186 }
68187 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
68188 if (!class->key)
68189 continue;
68190
68191 - seq_printf(m, "[%p] ", class->key);
68192 + seq_printf(m, "[%pK] ", class->key);
68193 print_name(m, class);
68194 seq_puts(m, "\n");
68195 }
68196 @@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
68197 if (!i)
68198 seq_line(m, '-', 40-namelen, namelen);
68199
68200 - snprintf(ip, sizeof(ip), "[<%p>]",
68201 + snprintf(ip, sizeof(ip), "[<%pK>]",
68202 (void *)class->contention_point[i]);
68203 seq_printf(m, "%40s %14lu %29s %pS\n",
68204 name, stats->contention_point[i],
68205 @@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
68206 if (!i)
68207 seq_line(m, '-', 40-namelen, namelen);
68208
68209 - snprintf(ip, sizeof(ip), "[<%p>]",
68210 + snprintf(ip, sizeof(ip), "[<%pK>]",
68211 (void *)class->contending_point[i]);
68212 seq_printf(m, "%40s %14lu %29s %pS\n",
68213 name, stats->contending_point[i],
68214 diff --git a/kernel/module.c b/kernel/module.c
68215 index 9ad9ee9..de7a157 100644
68216 --- a/kernel/module.c
68217 +++ b/kernel/module.c
68218 @@ -58,6 +58,7 @@
68219 #include <linux/jump_label.h>
68220 #include <linux/pfn.h>
68221 #include <linux/bsearch.h>
68222 +#include <linux/grsecurity.h>
68223
68224 #define CREATE_TRACE_POINTS
68225 #include <trace/events/module.h>
68226 @@ -114,7 +115,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
68227
68228 /* Bounds of module allocation, for speeding __module_address.
68229 * Protected by module_mutex. */
68230 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
68231 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
68232 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
68233
68234 int register_module_notifier(struct notifier_block * nb)
68235 {
68236 @@ -278,7 +280,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
68237 return true;
68238
68239 list_for_each_entry_rcu(mod, &modules, list) {
68240 - struct symsearch arr[] = {
68241 + struct symsearch modarr[] = {
68242 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
68243 NOT_GPL_ONLY, false },
68244 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
68245 @@ -300,7 +302,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
68246 #endif
68247 };
68248
68249 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
68250 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
68251 return true;
68252 }
68253 return false;
68254 @@ -432,7 +434,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
68255 static int percpu_modalloc(struct module *mod,
68256 unsigned long size, unsigned long align)
68257 {
68258 - if (align > PAGE_SIZE) {
68259 + if (align-1 >= PAGE_SIZE) {
68260 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
68261 mod->name, align, PAGE_SIZE);
68262 align = PAGE_SIZE;
68263 @@ -1032,7 +1034,7 @@ struct module_attribute module_uevent =
68264 static ssize_t show_coresize(struct module_attribute *mattr,
68265 struct module_kobject *mk, char *buffer)
68266 {
68267 - return sprintf(buffer, "%u\n", mk->mod->core_size);
68268 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
68269 }
68270
68271 static struct module_attribute modinfo_coresize =
68272 @@ -1041,7 +1043,7 @@ static struct module_attribute modinfo_coresize =
68273 static ssize_t show_initsize(struct module_attribute *mattr,
68274 struct module_kobject *mk, char *buffer)
68275 {
68276 - return sprintf(buffer, "%u\n", mk->mod->init_size);
68277 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
68278 }
68279
68280 static struct module_attribute modinfo_initsize =
68281 @@ -1255,7 +1257,7 @@ resolve_symbol_wait(struct module *mod,
68282 */
68283 #ifdef CONFIG_SYSFS
68284
68285 -#ifdef CONFIG_KALLSYMS
68286 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
68287 static inline bool sect_empty(const Elf_Shdr *sect)
68288 {
68289 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
68290 @@ -1721,21 +1723,21 @@ static void set_section_ro_nx(void *base,
68291
68292 static void unset_module_core_ro_nx(struct module *mod)
68293 {
68294 - set_page_attributes(mod->module_core + mod->core_text_size,
68295 - mod->module_core + mod->core_size,
68296 + set_page_attributes(mod->module_core_rw,
68297 + mod->module_core_rw + mod->core_size_rw,
68298 set_memory_x);
68299 - set_page_attributes(mod->module_core,
68300 - mod->module_core + mod->core_ro_size,
68301 + set_page_attributes(mod->module_core_rx,
68302 + mod->module_core_rx + mod->core_size_rx,
68303 set_memory_rw);
68304 }
68305
68306 static void unset_module_init_ro_nx(struct module *mod)
68307 {
68308 - set_page_attributes(mod->module_init + mod->init_text_size,
68309 - mod->module_init + mod->init_size,
68310 + set_page_attributes(mod->module_init_rw,
68311 + mod->module_init_rw + mod->init_size_rw,
68312 set_memory_x);
68313 - set_page_attributes(mod->module_init,
68314 - mod->module_init + mod->init_ro_size,
68315 + set_page_attributes(mod->module_init_rx,
68316 + mod->module_init_rx + mod->init_size_rx,
68317 set_memory_rw);
68318 }
68319
68320 @@ -1746,14 +1748,14 @@ void set_all_modules_text_rw(void)
68321
68322 mutex_lock(&module_mutex);
68323 list_for_each_entry_rcu(mod, &modules, list) {
68324 - if ((mod->module_core) && (mod->core_text_size)) {
68325 - set_page_attributes(mod->module_core,
68326 - mod->module_core + mod->core_text_size,
68327 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
68328 + set_page_attributes(mod->module_core_rx,
68329 + mod->module_core_rx + mod->core_size_rx,
68330 set_memory_rw);
68331 }
68332 - if ((mod->module_init) && (mod->init_text_size)) {
68333 - set_page_attributes(mod->module_init,
68334 - mod->module_init + mod->init_text_size,
68335 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
68336 + set_page_attributes(mod->module_init_rx,
68337 + mod->module_init_rx + mod->init_size_rx,
68338 set_memory_rw);
68339 }
68340 }
68341 @@ -1767,14 +1769,14 @@ void set_all_modules_text_ro(void)
68342
68343 mutex_lock(&module_mutex);
68344 list_for_each_entry_rcu(mod, &modules, list) {
68345 - if ((mod->module_core) && (mod->core_text_size)) {
68346 - set_page_attributes(mod->module_core,
68347 - mod->module_core + mod->core_text_size,
68348 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
68349 + set_page_attributes(mod->module_core_rx,
68350 + mod->module_core_rx + mod->core_size_rx,
68351 set_memory_ro);
68352 }
68353 - if ((mod->module_init) && (mod->init_text_size)) {
68354 - set_page_attributes(mod->module_init,
68355 - mod->module_init + mod->init_text_size,
68356 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
68357 + set_page_attributes(mod->module_init_rx,
68358 + mod->module_init_rx + mod->init_size_rx,
68359 set_memory_ro);
68360 }
68361 }
68362 @@ -1820,16 +1822,19 @@ static void free_module(struct module *mod)
68363
68364 /* This may be NULL, but that's OK */
68365 unset_module_init_ro_nx(mod);
68366 - module_free(mod, mod->module_init);
68367 + module_free(mod, mod->module_init_rw);
68368 + module_free_exec(mod, mod->module_init_rx);
68369 kfree(mod->args);
68370 percpu_modfree(mod);
68371
68372 /* Free lock-classes: */
68373 - lockdep_free_key_range(mod->module_core, mod->core_size);
68374 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
68375 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
68376
68377 /* Finally, free the core (containing the module structure) */
68378 unset_module_core_ro_nx(mod);
68379 - module_free(mod, mod->module_core);
68380 + module_free_exec(mod, mod->module_core_rx);
68381 + module_free(mod, mod->module_core_rw);
68382
68383 #ifdef CONFIG_MPU
68384 update_protections(current->mm);
68385 @@ -1899,9 +1904,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68386 int ret = 0;
68387 const struct kernel_symbol *ksym;
68388
68389 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68390 + int is_fs_load = 0;
68391 + int register_filesystem_found = 0;
68392 + char *p;
68393 +
68394 + p = strstr(mod->args, "grsec_modharden_fs");
68395 + if (p) {
68396 + char *endptr = p + strlen("grsec_modharden_fs");
68397 + /* copy \0 as well */
68398 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
68399 + is_fs_load = 1;
68400 + }
68401 +#endif
68402 +
68403 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
68404 const char *name = info->strtab + sym[i].st_name;
68405
68406 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68407 + /* it's a real shame this will never get ripped and copied
68408 + upstream! ;(
68409 + */
68410 + if (is_fs_load && !strcmp(name, "register_filesystem"))
68411 + register_filesystem_found = 1;
68412 +#endif
68413 +
68414 switch (sym[i].st_shndx) {
68415 case SHN_COMMON:
68416 /* We compiled with -fno-common. These are not
68417 @@ -1922,7 +1949,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68418 ksym = resolve_symbol_wait(mod, info, name);
68419 /* Ok if resolved. */
68420 if (ksym && !IS_ERR(ksym)) {
68421 + pax_open_kernel();
68422 sym[i].st_value = ksym->value;
68423 + pax_close_kernel();
68424 break;
68425 }
68426
68427 @@ -1941,11 +1970,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68428 secbase = (unsigned long)mod_percpu(mod);
68429 else
68430 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
68431 + pax_open_kernel();
68432 sym[i].st_value += secbase;
68433 + pax_close_kernel();
68434 break;
68435 }
68436 }
68437
68438 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68439 + if (is_fs_load && !register_filesystem_found) {
68440 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
68441 + ret = -EPERM;
68442 + }
68443 +#endif
68444 +
68445 return ret;
68446 }
68447
68448 @@ -2049,22 +2087,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
68449 || s->sh_entsize != ~0UL
68450 || strstarts(sname, ".init"))
68451 continue;
68452 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
68453 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68454 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
68455 + else
68456 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
68457 pr_debug("\t%s\n", sname);
68458 }
68459 - switch (m) {
68460 - case 0: /* executable */
68461 - mod->core_size = debug_align(mod->core_size);
68462 - mod->core_text_size = mod->core_size;
68463 - break;
68464 - case 1: /* RO: text and ro-data */
68465 - mod->core_size = debug_align(mod->core_size);
68466 - mod->core_ro_size = mod->core_size;
68467 - break;
68468 - case 3: /* whole core */
68469 - mod->core_size = debug_align(mod->core_size);
68470 - break;
68471 - }
68472 }
68473
68474 pr_debug("Init section allocation order:\n");
68475 @@ -2078,23 +2106,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
68476 || s->sh_entsize != ~0UL
68477 || !strstarts(sname, ".init"))
68478 continue;
68479 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
68480 - | INIT_OFFSET_MASK);
68481 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68482 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
68483 + else
68484 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
68485 + s->sh_entsize |= INIT_OFFSET_MASK;
68486 pr_debug("\t%s\n", sname);
68487 }
68488 - switch (m) {
68489 - case 0: /* executable */
68490 - mod->init_size = debug_align(mod->init_size);
68491 - mod->init_text_size = mod->init_size;
68492 - break;
68493 - case 1: /* RO: text and ro-data */
68494 - mod->init_size = debug_align(mod->init_size);
68495 - mod->init_ro_size = mod->init_size;
68496 - break;
68497 - case 3: /* whole init */
68498 - mod->init_size = debug_align(mod->init_size);
68499 - break;
68500 - }
68501 }
68502 }
68503
68504 @@ -2266,7 +2284,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
68505
68506 /* Put symbol section at end of init part of module. */
68507 symsect->sh_flags |= SHF_ALLOC;
68508 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
68509 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
68510 info->index.sym) | INIT_OFFSET_MASK;
68511 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
68512
68513 @@ -2281,13 +2299,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
68514 }
68515
68516 /* Append room for core symbols at end of core part. */
68517 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
68518 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
68519 - mod->core_size += strtab_size;
68520 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
68521 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
68522 + mod->core_size_rx += strtab_size;
68523
68524 /* Put string table section at end of init part of module. */
68525 strsect->sh_flags |= SHF_ALLOC;
68526 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
68527 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
68528 info->index.str) | INIT_OFFSET_MASK;
68529 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
68530 }
68531 @@ -2305,12 +2323,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
68532 /* Make sure we get permanent strtab: don't use info->strtab. */
68533 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
68534
68535 + pax_open_kernel();
68536 +
68537 /* Set types up while we still have access to sections. */
68538 for (i = 0; i < mod->num_symtab; i++)
68539 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
68540
68541 - mod->core_symtab = dst = mod->module_core + info->symoffs;
68542 - mod->core_strtab = s = mod->module_core + info->stroffs;
68543 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
68544 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
68545 src = mod->symtab;
68546 *dst = *src;
68547 *s++ = 0;
68548 @@ -2323,6 +2343,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
68549 s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1;
68550 }
68551 mod->core_num_syms = ndst;
68552 +
68553 + pax_close_kernel();
68554 }
68555 #else
68556 static inline void layout_symtab(struct module *mod, struct load_info *info)
68557 @@ -2356,17 +2378,33 @@ void * __weak module_alloc(unsigned long size)
68558 return size == 0 ? NULL : vmalloc_exec(size);
68559 }
68560
68561 -static void *module_alloc_update_bounds(unsigned long size)
68562 +static void *module_alloc_update_bounds_rw(unsigned long size)
68563 {
68564 void *ret = module_alloc(size);
68565
68566 if (ret) {
68567 mutex_lock(&module_mutex);
68568 /* Update module bounds. */
68569 - if ((unsigned long)ret < module_addr_min)
68570 - module_addr_min = (unsigned long)ret;
68571 - if ((unsigned long)ret + size > module_addr_max)
68572 - module_addr_max = (unsigned long)ret + size;
68573 + if ((unsigned long)ret < module_addr_min_rw)
68574 + module_addr_min_rw = (unsigned long)ret;
68575 + if ((unsigned long)ret + size > module_addr_max_rw)
68576 + module_addr_max_rw = (unsigned long)ret + size;
68577 + mutex_unlock(&module_mutex);
68578 + }
68579 + return ret;
68580 +}
68581 +
68582 +static void *module_alloc_update_bounds_rx(unsigned long size)
68583 +{
68584 + void *ret = module_alloc_exec(size);
68585 +
68586 + if (ret) {
68587 + mutex_lock(&module_mutex);
68588 + /* Update module bounds. */
68589 + if ((unsigned long)ret < module_addr_min_rx)
68590 + module_addr_min_rx = (unsigned long)ret;
68591 + if ((unsigned long)ret + size > module_addr_max_rx)
68592 + module_addr_max_rx = (unsigned long)ret + size;
68593 mutex_unlock(&module_mutex);
68594 }
68595 return ret;
68596 @@ -2544,8 +2582,14 @@ static struct module *setup_load_info(struct load_info *info)
68597 static int check_modinfo(struct module *mod, struct load_info *info)
68598 {
68599 const char *modmagic = get_modinfo(info, "vermagic");
68600 + const char *license = get_modinfo(info, "license");
68601 int err;
68602
68603 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
68604 + if (!license || !license_is_gpl_compatible(license))
68605 + return -ENOEXEC;
68606 +#endif
68607 +
68608 /* This is allowed: modprobe --force will invalidate it. */
68609 if (!modmagic) {
68610 err = try_to_force_load(mod, "bad vermagic");
68611 @@ -2568,7 +2612,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
68612 }
68613
68614 /* Set up license info based on the info section */
68615 - set_license(mod, get_modinfo(info, "license"));
68616 + set_license(mod, license);
68617
68618 return 0;
68619 }
68620 @@ -2662,7 +2706,7 @@ static int move_module(struct module *mod, struct load_info *info)
68621 void *ptr;
68622
68623 /* Do the allocs. */
68624 - ptr = module_alloc_update_bounds(mod->core_size);
68625 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
68626 /*
68627 * The pointer to this block is stored in the module structure
68628 * which is inside the block. Just mark it as not being a
68629 @@ -2672,23 +2716,50 @@ static int move_module(struct module *mod, struct load_info *info)
68630 if (!ptr)
68631 return -ENOMEM;
68632
68633 - memset(ptr, 0, mod->core_size);
68634 - mod->module_core = ptr;
68635 + memset(ptr, 0, mod->core_size_rw);
68636 + mod->module_core_rw = ptr;
68637
68638 - ptr = module_alloc_update_bounds(mod->init_size);
68639 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
68640 /*
68641 * The pointer to this block is stored in the module structure
68642 * which is inside the block. This block doesn't need to be
68643 * scanned as it contains data and code that will be freed
68644 * after the module is initialized.
68645 */
68646 - kmemleak_ignore(ptr);
68647 - if (!ptr && mod->init_size) {
68648 - module_free(mod, mod->module_core);
68649 + kmemleak_not_leak(ptr);
68650 + if (!ptr && mod->init_size_rw) {
68651 + module_free(mod, mod->module_core_rw);
68652 return -ENOMEM;
68653 }
68654 - memset(ptr, 0, mod->init_size);
68655 - mod->module_init = ptr;
68656 + memset(ptr, 0, mod->init_size_rw);
68657 + mod->module_init_rw = ptr;
68658 +
68659 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
68660 + kmemleak_not_leak(ptr);
68661 + if (!ptr) {
68662 + module_free(mod, mod->module_init_rw);
68663 + module_free(mod, mod->module_core_rw);
68664 + return -ENOMEM;
68665 + }
68666 +
68667 + pax_open_kernel();
68668 + memset(ptr, 0, mod->core_size_rx);
68669 + pax_close_kernel();
68670 + mod->module_core_rx = ptr;
68671 +
68672 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
68673 + kmemleak_not_leak(ptr);
68674 + if (!ptr && mod->init_size_rx) {
68675 + module_free_exec(mod, mod->module_core_rx);
68676 + module_free(mod, mod->module_init_rw);
68677 + module_free(mod, mod->module_core_rw);
68678 + return -ENOMEM;
68679 + }
68680 +
68681 + pax_open_kernel();
68682 + memset(ptr, 0, mod->init_size_rx);
68683 + pax_close_kernel();
68684 + mod->module_init_rx = ptr;
68685
68686 /* Transfer each section which specifies SHF_ALLOC */
68687 pr_debug("final section addresses:\n");
68688 @@ -2699,16 +2770,45 @@ static int move_module(struct module *mod, struct load_info *info)
68689 if (!(shdr->sh_flags & SHF_ALLOC))
68690 continue;
68691
68692 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
68693 - dest = mod->module_init
68694 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68695 - else
68696 - dest = mod->module_core + shdr->sh_entsize;
68697 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
68698 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68699 + dest = mod->module_init_rw
68700 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68701 + else
68702 + dest = mod->module_init_rx
68703 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68704 + } else {
68705 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68706 + dest = mod->module_core_rw + shdr->sh_entsize;
68707 + else
68708 + dest = mod->module_core_rx + shdr->sh_entsize;
68709 + }
68710 +
68711 + if (shdr->sh_type != SHT_NOBITS) {
68712 +
68713 +#ifdef CONFIG_PAX_KERNEXEC
68714 +#ifdef CONFIG_X86_64
68715 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
68716 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
68717 +#endif
68718 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
68719 + pax_open_kernel();
68720 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68721 + pax_close_kernel();
68722 + } else
68723 +#endif
68724
68725 - if (shdr->sh_type != SHT_NOBITS)
68726 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68727 + }
68728 /* Update sh_addr to point to copy in image. */
68729 - shdr->sh_addr = (unsigned long)dest;
68730 +
68731 +#ifdef CONFIG_PAX_KERNEXEC
68732 + if (shdr->sh_flags & SHF_EXECINSTR)
68733 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
68734 + else
68735 +#endif
68736 +
68737 + shdr->sh_addr = (unsigned long)dest;
68738 pr_debug("\t0x%lx %s\n",
68739 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
68740 }
68741 @@ -2763,12 +2863,12 @@ static void flush_module_icache(const struct module *mod)
68742 * Do it before processing of module parameters, so the module
68743 * can provide parameter accessor functions of its own.
68744 */
68745 - if (mod->module_init)
68746 - flush_icache_range((unsigned long)mod->module_init,
68747 - (unsigned long)mod->module_init
68748 - + mod->init_size);
68749 - flush_icache_range((unsigned long)mod->module_core,
68750 - (unsigned long)mod->module_core + mod->core_size);
68751 + if (mod->module_init_rx)
68752 + flush_icache_range((unsigned long)mod->module_init_rx,
68753 + (unsigned long)mod->module_init_rx
68754 + + mod->init_size_rx);
68755 + flush_icache_range((unsigned long)mod->module_core_rx,
68756 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
68757
68758 set_fs(old_fs);
68759 }
68760 @@ -2838,8 +2938,10 @@ out:
68761 static void module_deallocate(struct module *mod, struct load_info *info)
68762 {
68763 percpu_modfree(mod);
68764 - module_free(mod, mod->module_init);
68765 - module_free(mod, mod->module_core);
68766 + module_free_exec(mod, mod->module_init_rx);
68767 + module_free_exec(mod, mod->module_core_rx);
68768 + module_free(mod, mod->module_init_rw);
68769 + module_free(mod, mod->module_core_rw);
68770 }
68771
68772 int __weak module_finalize(const Elf_Ehdr *hdr,
68773 @@ -2852,7 +2954,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
68774 static int post_relocation(struct module *mod, const struct load_info *info)
68775 {
68776 /* Sort exception table now relocations are done. */
68777 + pax_open_kernel();
68778 sort_extable(mod->extable, mod->extable + mod->num_exentries);
68779 + pax_close_kernel();
68780
68781 /* Copy relocated percpu area over. */
68782 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
68783 @@ -2903,9 +3007,38 @@ static struct module *load_module(void __user *umod,
68784 if (err)
68785 goto free_unload;
68786
68787 + /* Now copy in args */
68788 + mod->args = strndup_user(uargs, ~0UL >> 1);
68789 + if (IS_ERR(mod->args)) {
68790 + err = PTR_ERR(mod->args);
68791 + goto free_unload;
68792 + }
68793 +
68794 /* Set up MODINFO_ATTR fields */
68795 setup_modinfo(mod, &info);
68796
68797 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68798 + {
68799 + char *p, *p2;
68800 +
68801 + if (strstr(mod->args, "grsec_modharden_netdev")) {
68802 + 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);
68803 + err = -EPERM;
68804 + goto free_modinfo;
68805 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
68806 + p += strlen("grsec_modharden_normal");
68807 + p2 = strstr(p, "_");
68808 + if (p2) {
68809 + *p2 = '\0';
68810 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
68811 + *p2 = '_';
68812 + }
68813 + err = -EPERM;
68814 + goto free_modinfo;
68815 + }
68816 + }
68817 +#endif
68818 +
68819 /* Fix up syms, so that st_value is a pointer to location. */
68820 err = simplify_symbols(mod, &info);
68821 if (err < 0)
68822 @@ -2921,13 +3054,6 @@ static struct module *load_module(void __user *umod,
68823
68824 flush_module_icache(mod);
68825
68826 - /* Now copy in args */
68827 - mod->args = strndup_user(uargs, ~0UL >> 1);
68828 - if (IS_ERR(mod->args)) {
68829 - err = PTR_ERR(mod->args);
68830 - goto free_arch_cleanup;
68831 - }
68832 -
68833 /* Mark state as coming so strong_try_module_get() ignores us. */
68834 mod->state = MODULE_STATE_COMING;
68835
68836 @@ -2985,11 +3111,10 @@ static struct module *load_module(void __user *umod,
68837 unlock:
68838 mutex_unlock(&module_mutex);
68839 synchronize_sched();
68840 - kfree(mod->args);
68841 - free_arch_cleanup:
68842 module_arch_cleanup(mod);
68843 free_modinfo:
68844 free_modinfo(mod);
68845 + kfree(mod->args);
68846 free_unload:
68847 module_unload_free(mod);
68848 free_module:
68849 @@ -3030,16 +3155,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
68850 MODULE_STATE_COMING, mod);
68851
68852 /* Set RO and NX regions for core */
68853 - set_section_ro_nx(mod->module_core,
68854 - mod->core_text_size,
68855 - mod->core_ro_size,
68856 - mod->core_size);
68857 + set_section_ro_nx(mod->module_core_rx,
68858 + mod->core_size_rx,
68859 + mod->core_size_rx,
68860 + mod->core_size_rx);
68861
68862 /* Set RO and NX regions for init */
68863 - set_section_ro_nx(mod->module_init,
68864 - mod->init_text_size,
68865 - mod->init_ro_size,
68866 - mod->init_size);
68867 + set_section_ro_nx(mod->module_init_rx,
68868 + mod->init_size_rx,
68869 + mod->init_size_rx,
68870 + mod->init_size_rx);
68871
68872 do_mod_ctors(mod);
68873 /* Start the module */
68874 @@ -3085,11 +3210,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
68875 mod->strtab = mod->core_strtab;
68876 #endif
68877 unset_module_init_ro_nx(mod);
68878 - module_free(mod, mod->module_init);
68879 - mod->module_init = NULL;
68880 - mod->init_size = 0;
68881 - mod->init_ro_size = 0;
68882 - mod->init_text_size = 0;
68883 + module_free(mod, mod->module_init_rw);
68884 + module_free_exec(mod, mod->module_init_rx);
68885 + mod->module_init_rw = NULL;
68886 + mod->module_init_rx = NULL;
68887 + mod->init_size_rw = 0;
68888 + mod->init_size_rx = 0;
68889 mutex_unlock(&module_mutex);
68890
68891 return 0;
68892 @@ -3120,10 +3246,16 @@ static const char *get_ksymbol(struct module *mod,
68893 unsigned long nextval;
68894
68895 /* At worse, next value is at end of module */
68896 - if (within_module_init(addr, mod))
68897 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
68898 + if (within_module_init_rx(addr, mod))
68899 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
68900 + else if (within_module_init_rw(addr, mod))
68901 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
68902 + else if (within_module_core_rx(addr, mod))
68903 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
68904 + else if (within_module_core_rw(addr, mod))
68905 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
68906 else
68907 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
68908 + return NULL;
68909
68910 /* Scan for closest preceding symbol, and next symbol. (ELF
68911 starts real symbols at 1). */
68912 @@ -3358,7 +3490,7 @@ static int m_show(struct seq_file *m, void *p)
68913 char buf[8];
68914
68915 seq_printf(m, "%s %u",
68916 - mod->name, mod->init_size + mod->core_size);
68917 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
68918 print_unload_info(m, mod);
68919
68920 /* Informative for users. */
68921 @@ -3367,7 +3499,7 @@ static int m_show(struct seq_file *m, void *p)
68922 mod->state == MODULE_STATE_COMING ? "Loading":
68923 "Live");
68924 /* Used by oprofile and other similar tools. */
68925 - seq_printf(m, " 0x%pK", mod->module_core);
68926 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
68927
68928 /* Taints info */
68929 if (mod->taints)
68930 @@ -3403,7 +3535,17 @@ static const struct file_operations proc_modules_operations = {
68931
68932 static int __init proc_modules_init(void)
68933 {
68934 +#ifndef CONFIG_GRKERNSEC_HIDESYM
68935 +#ifdef CONFIG_GRKERNSEC_PROC_USER
68936 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68937 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68938 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
68939 +#else
68940 proc_create("modules", 0, NULL, &proc_modules_operations);
68941 +#endif
68942 +#else
68943 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68944 +#endif
68945 return 0;
68946 }
68947 module_init(proc_modules_init);
68948 @@ -3462,12 +3604,12 @@ struct module *__module_address(unsigned long addr)
68949 {
68950 struct module *mod;
68951
68952 - if (addr < module_addr_min || addr > module_addr_max)
68953 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
68954 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
68955 return NULL;
68956
68957 list_for_each_entry_rcu(mod, &modules, list)
68958 - if (within_module_core(addr, mod)
68959 - || within_module_init(addr, mod))
68960 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
68961 return mod;
68962 return NULL;
68963 }
68964 @@ -3501,11 +3643,20 @@ bool is_module_text_address(unsigned long addr)
68965 */
68966 struct module *__module_text_address(unsigned long addr)
68967 {
68968 - struct module *mod = __module_address(addr);
68969 + struct module *mod;
68970 +
68971 +#ifdef CONFIG_X86_32
68972 + addr = ktla_ktva(addr);
68973 +#endif
68974 +
68975 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
68976 + return NULL;
68977 +
68978 + mod = __module_address(addr);
68979 +
68980 if (mod) {
68981 /* Make sure it's within the text section. */
68982 - if (!within(addr, mod->module_init, mod->init_text_size)
68983 - && !within(addr, mod->module_core, mod->core_text_size))
68984 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
68985 mod = NULL;
68986 }
68987 return mod;
68988 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
68989 index 7e3443f..b2a1e6b 100644
68990 --- a/kernel/mutex-debug.c
68991 +++ b/kernel/mutex-debug.c
68992 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
68993 }
68994
68995 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68996 - struct thread_info *ti)
68997 + struct task_struct *task)
68998 {
68999 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
69000
69001 /* Mark the current thread as blocked on the lock: */
69002 - ti->task->blocked_on = waiter;
69003 + task->blocked_on = waiter;
69004 }
69005
69006 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
69007 - struct thread_info *ti)
69008 + struct task_struct *task)
69009 {
69010 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
69011 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
69012 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
69013 - ti->task->blocked_on = NULL;
69014 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
69015 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
69016 + task->blocked_on = NULL;
69017
69018 list_del_init(&waiter->list);
69019 waiter->task = NULL;
69020 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
69021 index 0799fd3..d06ae3b 100644
69022 --- a/kernel/mutex-debug.h
69023 +++ b/kernel/mutex-debug.h
69024 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
69025 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
69026 extern void debug_mutex_add_waiter(struct mutex *lock,
69027 struct mutex_waiter *waiter,
69028 - struct thread_info *ti);
69029 + struct task_struct *task);
69030 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
69031 - struct thread_info *ti);
69032 + struct task_struct *task);
69033 extern void debug_mutex_unlock(struct mutex *lock);
69034 extern void debug_mutex_init(struct mutex *lock, const char *name,
69035 struct lock_class_key *key);
69036 diff --git a/kernel/mutex.c b/kernel/mutex.c
69037 index a307cc9..27fd2e9 100644
69038 --- a/kernel/mutex.c
69039 +++ b/kernel/mutex.c
69040 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
69041 spin_lock_mutex(&lock->wait_lock, flags);
69042
69043 debug_mutex_lock_common(lock, &waiter);
69044 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
69045 + debug_mutex_add_waiter(lock, &waiter, task);
69046
69047 /* add waiting tasks to the end of the waitqueue (FIFO): */
69048 list_add_tail(&waiter.list, &lock->wait_list);
69049 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
69050 * TASK_UNINTERRUPTIBLE case.)
69051 */
69052 if (unlikely(signal_pending_state(state, task))) {
69053 - mutex_remove_waiter(lock, &waiter,
69054 - task_thread_info(task));
69055 + mutex_remove_waiter(lock, &waiter, task);
69056 mutex_release(&lock->dep_map, 1, ip);
69057 spin_unlock_mutex(&lock->wait_lock, flags);
69058
69059 @@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
69060 done:
69061 lock_acquired(&lock->dep_map, ip);
69062 /* got the lock - rejoice! */
69063 - mutex_remove_waiter(lock, &waiter, current_thread_info());
69064 + mutex_remove_waiter(lock, &waiter, task);
69065 mutex_set_owner(lock);
69066
69067 /* set it to 0 if there are no waiters left: */
69068 diff --git a/kernel/panic.c b/kernel/panic.c
69069 index e1b2822..5edc1d9 100644
69070 --- a/kernel/panic.c
69071 +++ b/kernel/panic.c
69072 @@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
69073 const char *board;
69074
69075 printk(KERN_WARNING "------------[ cut here ]------------\n");
69076 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
69077 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
69078 board = dmi_get_system_info(DMI_PRODUCT_NAME);
69079 if (board)
69080 printk(KERN_WARNING "Hardware name: %s\n", board);
69081 @@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
69082 */
69083 void __stack_chk_fail(void)
69084 {
69085 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
69086 + dump_stack();
69087 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
69088 __builtin_return_address(0));
69089 }
69090 EXPORT_SYMBOL(__stack_chk_fail);
69091 diff --git a/kernel/pid.c b/kernel/pid.c
69092 index e86b291a..e8b0fb5 100644
69093 --- a/kernel/pid.c
69094 +++ b/kernel/pid.c
69095 @@ -33,6 +33,7 @@
69096 #include <linux/rculist.h>
69097 #include <linux/bootmem.h>
69098 #include <linux/hash.h>
69099 +#include <linux/security.h>
69100 #include <linux/pid_namespace.h>
69101 #include <linux/init_task.h>
69102 #include <linux/syscalls.h>
69103 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
69104
69105 int pid_max = PID_MAX_DEFAULT;
69106
69107 -#define RESERVED_PIDS 300
69108 +#define RESERVED_PIDS 500
69109
69110 int pid_max_min = RESERVED_PIDS + 1;
69111 int pid_max_max = PID_MAX_LIMIT;
69112 @@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
69113 */
69114 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
69115 {
69116 + struct task_struct *task;
69117 +
69118 rcu_lockdep_assert(rcu_read_lock_held(),
69119 "find_task_by_pid_ns() needs rcu_read_lock()"
69120 " protection");
69121 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
69122 +
69123 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
69124 +
69125 + if (gr_pid_is_chrooted(task))
69126 + return NULL;
69127 +
69128 + return task;
69129 }
69130
69131 struct task_struct *find_task_by_vpid(pid_t vnr)
69132 @@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
69133 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
69134 }
69135
69136 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
69137 +{
69138 + rcu_lockdep_assert(rcu_read_lock_held(),
69139 + "find_task_by_pid_ns() needs rcu_read_lock()"
69140 + " protection");
69141 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
69142 +}
69143 +
69144 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
69145 {
69146 struct pid *pid;
69147 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
69148 index 125cb67..a4d1c30 100644
69149 --- a/kernel/posix-cpu-timers.c
69150 +++ b/kernel/posix-cpu-timers.c
69151 @@ -6,6 +6,7 @@
69152 #include <linux/posix-timers.h>
69153 #include <linux/errno.h>
69154 #include <linux/math64.h>
69155 +#include <linux/security.h>
69156 #include <asm/uaccess.h>
69157 #include <linux/kernel_stat.h>
69158 #include <trace/events/timer.h>
69159 @@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
69160
69161 static __init int init_posix_cpu_timers(void)
69162 {
69163 - struct k_clock process = {
69164 + static struct k_clock process = {
69165 .clock_getres = process_cpu_clock_getres,
69166 .clock_get = process_cpu_clock_get,
69167 .timer_create = process_cpu_timer_create,
69168 .nsleep = process_cpu_nsleep,
69169 .nsleep_restart = process_cpu_nsleep_restart,
69170 };
69171 - struct k_clock thread = {
69172 + static struct k_clock thread = {
69173 .clock_getres = thread_cpu_clock_getres,
69174 .clock_get = thread_cpu_clock_get,
69175 .timer_create = thread_cpu_timer_create,
69176 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
69177 index 69185ae..cc2847a 100644
69178 --- a/kernel/posix-timers.c
69179 +++ b/kernel/posix-timers.c
69180 @@ -43,6 +43,7 @@
69181 #include <linux/idr.h>
69182 #include <linux/posix-clock.h>
69183 #include <linux/posix-timers.h>
69184 +#include <linux/grsecurity.h>
69185 #include <linux/syscalls.h>
69186 #include <linux/wait.h>
69187 #include <linux/workqueue.h>
69188 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
69189 * which we beg off on and pass to do_sys_settimeofday().
69190 */
69191
69192 -static struct k_clock posix_clocks[MAX_CLOCKS];
69193 +static struct k_clock *posix_clocks[MAX_CLOCKS];
69194
69195 /*
69196 * These ones are defined below.
69197 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
69198 */
69199 static __init int init_posix_timers(void)
69200 {
69201 - struct k_clock clock_realtime = {
69202 + static struct k_clock clock_realtime = {
69203 .clock_getres = hrtimer_get_res,
69204 .clock_get = posix_clock_realtime_get,
69205 .clock_set = posix_clock_realtime_set,
69206 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
69207 .timer_get = common_timer_get,
69208 .timer_del = common_timer_del,
69209 };
69210 - struct k_clock clock_monotonic = {
69211 + static struct k_clock clock_monotonic = {
69212 .clock_getres = hrtimer_get_res,
69213 .clock_get = posix_ktime_get_ts,
69214 .nsleep = common_nsleep,
69215 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
69216 .timer_get = common_timer_get,
69217 .timer_del = common_timer_del,
69218 };
69219 - struct k_clock clock_monotonic_raw = {
69220 + static struct k_clock clock_monotonic_raw = {
69221 .clock_getres = hrtimer_get_res,
69222 .clock_get = posix_get_monotonic_raw,
69223 };
69224 - struct k_clock clock_realtime_coarse = {
69225 + static struct k_clock clock_realtime_coarse = {
69226 .clock_getres = posix_get_coarse_res,
69227 .clock_get = posix_get_realtime_coarse,
69228 };
69229 - struct k_clock clock_monotonic_coarse = {
69230 + static struct k_clock clock_monotonic_coarse = {
69231 .clock_getres = posix_get_coarse_res,
69232 .clock_get = posix_get_monotonic_coarse,
69233 };
69234 - struct k_clock clock_boottime = {
69235 + static struct k_clock clock_boottime = {
69236 .clock_getres = hrtimer_get_res,
69237 .clock_get = posix_get_boottime,
69238 .nsleep = common_nsleep,
69239 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
69240 return;
69241 }
69242
69243 - posix_clocks[clock_id] = *new_clock;
69244 + posix_clocks[clock_id] = new_clock;
69245 }
69246 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
69247
69248 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
69249 return (id & CLOCKFD_MASK) == CLOCKFD ?
69250 &clock_posix_dynamic : &clock_posix_cpu;
69251
69252 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
69253 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
69254 return NULL;
69255 - return &posix_clocks[id];
69256 + return posix_clocks[id];
69257 }
69258
69259 static int common_timer_create(struct k_itimer *new_timer)
69260 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
69261 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
69262 return -EFAULT;
69263
69264 + /* only the CLOCK_REALTIME clock can be set, all other clocks
69265 + have their clock_set fptr set to a nosettime dummy function
69266 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
69267 + call common_clock_set, which calls do_sys_settimeofday, which
69268 + we hook
69269 + */
69270 +
69271 return kc->clock_set(which_clock, &new_tp);
69272 }
69273
69274 diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
69275 index d523593..68197a4 100644
69276 --- a/kernel/power/poweroff.c
69277 +++ b/kernel/power/poweroff.c
69278 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
69279 .enable_mask = SYSRQ_ENABLE_BOOT,
69280 };
69281
69282 -static int pm_sysrq_init(void)
69283 +static int __init pm_sysrq_init(void)
69284 {
69285 register_sysrq_key('o', &sysrq_poweroff_op);
69286 return 0;
69287 diff --git a/kernel/power/process.c b/kernel/power/process.c
69288 index 19db29f..33b52b6 100644
69289 --- a/kernel/power/process.c
69290 +++ b/kernel/power/process.c
69291 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
69292 u64 elapsed_csecs64;
69293 unsigned int elapsed_csecs;
69294 bool wakeup = false;
69295 + bool timedout = false;
69296
69297 do_gettimeofday(&start);
69298
69299 @@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
69300
69301 while (true) {
69302 todo = 0;
69303 + if (time_after(jiffies, end_time))
69304 + timedout = true;
69305 read_lock(&tasklist_lock);
69306 do_each_thread(g, p) {
69307 if (p == current || !freeze_task(p))
69308 @@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
69309 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
69310 * transition can't race with task state testing here.
69311 */
69312 - if (!task_is_stopped_or_traced(p) &&
69313 - !freezer_should_skip(p))
69314 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
69315 todo++;
69316 + if (timedout) {
69317 + printk(KERN_ERR "Task refusing to freeze:\n");
69318 + sched_show_task(p);
69319 + }
69320 + }
69321 } while_each_thread(g, p);
69322 read_unlock(&tasklist_lock);
69323
69324 @@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
69325 todo += wq_busy;
69326 }
69327
69328 - if (!todo || time_after(jiffies, end_time))
69329 + if (!todo || timedout)
69330 break;
69331
69332 if (pm_wakeup_pending()) {
69333 diff --git a/kernel/printk.c b/kernel/printk.c
69334 index 66a2ea3..10f3a01 100644
69335 --- a/kernel/printk.c
69336 +++ b/kernel/printk.c
69337 @@ -817,6 +817,11 @@ static int check_syslog_permissions(int type, bool from_file)
69338 if (from_file && type != SYSLOG_ACTION_OPEN)
69339 return 0;
69340
69341 +#ifdef CONFIG_GRKERNSEC_DMESG
69342 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
69343 + return -EPERM;
69344 +#endif
69345 +
69346 if (syslog_action_restricted(type)) {
69347 if (capable(CAP_SYSLOG))
69348 return 0;
69349 diff --git a/kernel/profile.c b/kernel/profile.c
69350 index 76b8e77..a2930e8 100644
69351 --- a/kernel/profile.c
69352 +++ b/kernel/profile.c
69353 @@ -39,7 +39,7 @@ struct profile_hit {
69354 /* Oprofile timer tick hook */
69355 static int (*timer_hook)(struct pt_regs *) __read_mostly;
69356
69357 -static atomic_t *prof_buffer;
69358 +static atomic_unchecked_t *prof_buffer;
69359 static unsigned long prof_len, prof_shift;
69360
69361 int prof_on __read_mostly;
69362 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
69363 hits[i].pc = 0;
69364 continue;
69365 }
69366 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69367 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69368 hits[i].hits = hits[i].pc = 0;
69369 }
69370 }
69371 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69372 * Add the current hit(s) and flush the write-queue out
69373 * to the global buffer:
69374 */
69375 - atomic_add(nr_hits, &prof_buffer[pc]);
69376 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
69377 for (i = 0; i < NR_PROFILE_HIT; ++i) {
69378 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69379 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69380 hits[i].pc = hits[i].hits = 0;
69381 }
69382 out:
69383 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69384 {
69385 unsigned long pc;
69386 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
69387 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69388 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69389 }
69390 #endif /* !CONFIG_SMP */
69391
69392 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
69393 return -EFAULT;
69394 buf++; p++; count--; read++;
69395 }
69396 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
69397 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
69398 if (copy_to_user(buf, (void *)pnt, count))
69399 return -EFAULT;
69400 read += count;
69401 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
69402 }
69403 #endif
69404 profile_discard_flip_buffers();
69405 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
69406 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
69407 return count;
69408 }
69409
69410 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
69411 index a232bb5..2a65ef9 100644
69412 --- a/kernel/ptrace.c
69413 +++ b/kernel/ptrace.c
69414 @@ -279,7 +279,7 @@ static int ptrace_attach(struct task_struct *task, long request,
69415
69416 if (seize)
69417 flags |= PT_SEIZED;
69418 - if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
69419 + if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
69420 flags |= PT_PTRACE_CAP;
69421 task->ptrace = flags;
69422
69423 @@ -486,7 +486,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
69424 break;
69425 return -EIO;
69426 }
69427 - if (copy_to_user(dst, buf, retval))
69428 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
69429 return -EFAULT;
69430 copied += retval;
69431 src += retval;
69432 @@ -671,7 +671,7 @@ int ptrace_request(struct task_struct *child, long request,
69433 bool seized = child->ptrace & PT_SEIZED;
69434 int ret = -EIO;
69435 siginfo_t siginfo, *si;
69436 - void __user *datavp = (void __user *) data;
69437 + void __user *datavp = (__force void __user *) data;
69438 unsigned long __user *datalp = datavp;
69439 unsigned long flags;
69440
69441 @@ -873,14 +873,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
69442 goto out;
69443 }
69444
69445 + if (gr_handle_ptrace(child, request)) {
69446 + ret = -EPERM;
69447 + goto out_put_task_struct;
69448 + }
69449 +
69450 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69451 ret = ptrace_attach(child, request, addr, data);
69452 /*
69453 * Some architectures need to do book-keeping after
69454 * a ptrace attach.
69455 */
69456 - if (!ret)
69457 + if (!ret) {
69458 arch_ptrace_attach(child);
69459 + gr_audit_ptrace(child);
69460 + }
69461 goto out_put_task_struct;
69462 }
69463
69464 @@ -906,7 +913,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
69465 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
69466 if (copied != sizeof(tmp))
69467 return -EIO;
69468 - return put_user(tmp, (unsigned long __user *)data);
69469 + return put_user(tmp, (__force unsigned long __user *)data);
69470 }
69471
69472 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
69473 @@ -1016,14 +1023,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
69474 goto out;
69475 }
69476
69477 + if (gr_handle_ptrace(child, request)) {
69478 + ret = -EPERM;
69479 + goto out_put_task_struct;
69480 + }
69481 +
69482 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69483 ret = ptrace_attach(child, request, addr, data);
69484 /*
69485 * Some architectures need to do book-keeping after
69486 * a ptrace attach.
69487 */
69488 - if (!ret)
69489 + if (!ret) {
69490 arch_ptrace_attach(child);
69491 + gr_audit_ptrace(child);
69492 + }
69493 goto out_put_task_struct;
69494 }
69495
69496 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
69497 index 547b1fe..65e874e 100644
69498 --- a/kernel/rcutiny.c
69499 +++ b/kernel/rcutiny.c
69500 @@ -46,7 +46,7 @@
69501 struct rcu_ctrlblk;
69502 static void invoke_rcu_callbacks(void);
69503 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
69504 -static void rcu_process_callbacks(struct softirq_action *unused);
69505 +static void rcu_process_callbacks(void);
69506 static void __call_rcu(struct rcu_head *head,
69507 void (*func)(struct rcu_head *rcu),
69508 struct rcu_ctrlblk *rcp);
69509 @@ -307,7 +307,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
69510 rcu_is_callbacks_kthread()));
69511 }
69512
69513 -static void rcu_process_callbacks(struct softirq_action *unused)
69514 +static void rcu_process_callbacks(void)
69515 {
69516 __rcu_process_callbacks(&rcu_sched_ctrlblk);
69517 __rcu_process_callbacks(&rcu_bh_ctrlblk);
69518 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
69519 index 918fd1e..85089bb 100644
69520 --- a/kernel/rcutiny_plugin.h
69521 +++ b/kernel/rcutiny_plugin.h
69522 @@ -893,7 +893,7 @@ static int rcu_kthread(void *arg)
69523 have_rcu_kthread_work = morework;
69524 local_irq_restore(flags);
69525 if (work)
69526 - rcu_process_callbacks(NULL);
69527 + rcu_process_callbacks();
69528 schedule_timeout_interruptible(1); /* Leave CPU for others. */
69529 }
69530
69531 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
69532 index 25b1503..1988a74 100644
69533 --- a/kernel/rcutorture.c
69534 +++ b/kernel/rcutorture.c
69535 @@ -162,12 +162,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
69536 { 0 };
69537 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
69538 { 0 };
69539 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69540 -static atomic_t n_rcu_torture_alloc;
69541 -static atomic_t n_rcu_torture_alloc_fail;
69542 -static atomic_t n_rcu_torture_free;
69543 -static atomic_t n_rcu_torture_mberror;
69544 -static atomic_t n_rcu_torture_error;
69545 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69546 +static atomic_unchecked_t n_rcu_torture_alloc;
69547 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
69548 +static atomic_unchecked_t n_rcu_torture_free;
69549 +static atomic_unchecked_t n_rcu_torture_mberror;
69550 +static atomic_unchecked_t n_rcu_torture_error;
69551 static long n_rcu_torture_barrier_error;
69552 static long n_rcu_torture_boost_ktrerror;
69553 static long n_rcu_torture_boost_rterror;
69554 @@ -265,11 +265,11 @@ rcu_torture_alloc(void)
69555
69556 spin_lock_bh(&rcu_torture_lock);
69557 if (list_empty(&rcu_torture_freelist)) {
69558 - atomic_inc(&n_rcu_torture_alloc_fail);
69559 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
69560 spin_unlock_bh(&rcu_torture_lock);
69561 return NULL;
69562 }
69563 - atomic_inc(&n_rcu_torture_alloc);
69564 + atomic_inc_unchecked(&n_rcu_torture_alloc);
69565 p = rcu_torture_freelist.next;
69566 list_del_init(p);
69567 spin_unlock_bh(&rcu_torture_lock);
69568 @@ -282,7 +282,7 @@ rcu_torture_alloc(void)
69569 static void
69570 rcu_torture_free(struct rcu_torture *p)
69571 {
69572 - atomic_inc(&n_rcu_torture_free);
69573 + atomic_inc_unchecked(&n_rcu_torture_free);
69574 spin_lock_bh(&rcu_torture_lock);
69575 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
69576 spin_unlock_bh(&rcu_torture_lock);
69577 @@ -403,7 +403,7 @@ rcu_torture_cb(struct rcu_head *p)
69578 i = rp->rtort_pipe_count;
69579 if (i > RCU_TORTURE_PIPE_LEN)
69580 i = RCU_TORTURE_PIPE_LEN;
69581 - atomic_inc(&rcu_torture_wcount[i]);
69582 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69583 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69584 rp->rtort_mbtest = 0;
69585 rcu_torture_free(rp);
69586 @@ -452,7 +452,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
69587 i = rp->rtort_pipe_count;
69588 if (i > RCU_TORTURE_PIPE_LEN)
69589 i = RCU_TORTURE_PIPE_LEN;
69590 - atomic_inc(&rcu_torture_wcount[i]);
69591 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69592 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69593 rp->rtort_mbtest = 0;
69594 list_del(&rp->rtort_free);
69595 @@ -995,7 +995,7 @@ rcu_torture_writer(void *arg)
69596 i = old_rp->rtort_pipe_count;
69597 if (i > RCU_TORTURE_PIPE_LEN)
69598 i = RCU_TORTURE_PIPE_LEN;
69599 - atomic_inc(&rcu_torture_wcount[i]);
69600 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69601 old_rp->rtort_pipe_count++;
69602 cur_ops->deferred_free(old_rp);
69603 }
69604 @@ -1080,7 +1080,7 @@ static void rcu_torture_timer(unsigned long unused)
69605 }
69606 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
69607 if (p->rtort_mbtest == 0)
69608 - atomic_inc(&n_rcu_torture_mberror);
69609 + atomic_inc_unchecked(&n_rcu_torture_mberror);
69610 spin_lock(&rand_lock);
69611 cur_ops->read_delay(&rand);
69612 n_rcu_torture_timers++;
69613 @@ -1144,7 +1144,7 @@ rcu_torture_reader(void *arg)
69614 }
69615 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
69616 if (p->rtort_mbtest == 0)
69617 - atomic_inc(&n_rcu_torture_mberror);
69618 + atomic_inc_unchecked(&n_rcu_torture_mberror);
69619 cur_ops->read_delay(&rand);
69620 preempt_disable();
69621 pipe_count = p->rtort_pipe_count;
69622 @@ -1203,11 +1203,11 @@ rcu_torture_printk(char *page)
69623 rcu_torture_current,
69624 rcu_torture_current_version,
69625 list_empty(&rcu_torture_freelist),
69626 - atomic_read(&n_rcu_torture_alloc),
69627 - atomic_read(&n_rcu_torture_alloc_fail),
69628 - atomic_read(&n_rcu_torture_free));
69629 + atomic_read_unchecked(&n_rcu_torture_alloc),
69630 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
69631 + atomic_read_unchecked(&n_rcu_torture_free));
69632 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
69633 - atomic_read(&n_rcu_torture_mberror),
69634 + atomic_read_unchecked(&n_rcu_torture_mberror),
69635 n_rcu_torture_boost_ktrerror,
69636 n_rcu_torture_boost_rterror);
69637 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
69638 @@ -1224,14 +1224,14 @@ rcu_torture_printk(char *page)
69639 n_barrier_attempts,
69640 n_rcu_torture_barrier_error);
69641 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
69642 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
69643 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
69644 n_rcu_torture_barrier_error != 0 ||
69645 n_rcu_torture_boost_ktrerror != 0 ||
69646 n_rcu_torture_boost_rterror != 0 ||
69647 n_rcu_torture_boost_failure != 0 ||
69648 i > 1) {
69649 cnt += sprintf(&page[cnt], "!!! ");
69650 - atomic_inc(&n_rcu_torture_error);
69651 + atomic_inc_unchecked(&n_rcu_torture_error);
69652 WARN_ON_ONCE(1);
69653 }
69654 cnt += sprintf(&page[cnt], "Reader Pipe: ");
69655 @@ -1245,7 +1245,7 @@ rcu_torture_printk(char *page)
69656 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
69657 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69658 cnt += sprintf(&page[cnt], " %d",
69659 - atomic_read(&rcu_torture_wcount[i]));
69660 + atomic_read_unchecked(&rcu_torture_wcount[i]));
69661 }
69662 cnt += sprintf(&page[cnt], "\n");
69663 if (cur_ops->stats)
69664 @@ -1905,7 +1905,7 @@ rcu_torture_cleanup(void)
69665
69666 if (cur_ops->cleanup)
69667 cur_ops->cleanup();
69668 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
69669 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
69670 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
69671 else if (n_online_successes != n_online_attempts ||
69672 n_offline_successes != n_offline_attempts)
69673 @@ -1974,18 +1974,18 @@ rcu_torture_init(void)
69674
69675 rcu_torture_current = NULL;
69676 rcu_torture_current_version = 0;
69677 - atomic_set(&n_rcu_torture_alloc, 0);
69678 - atomic_set(&n_rcu_torture_alloc_fail, 0);
69679 - atomic_set(&n_rcu_torture_free, 0);
69680 - atomic_set(&n_rcu_torture_mberror, 0);
69681 - atomic_set(&n_rcu_torture_error, 0);
69682 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
69683 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
69684 + atomic_set_unchecked(&n_rcu_torture_free, 0);
69685 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
69686 + atomic_set_unchecked(&n_rcu_torture_error, 0);
69687 n_rcu_torture_barrier_error = 0;
69688 n_rcu_torture_boost_ktrerror = 0;
69689 n_rcu_torture_boost_rterror = 0;
69690 n_rcu_torture_boost_failure = 0;
69691 n_rcu_torture_boosts = 0;
69692 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
69693 - atomic_set(&rcu_torture_wcount[i], 0);
69694 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
69695 for_each_possible_cpu(cpu) {
69696 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69697 per_cpu(rcu_torture_count, cpu)[i] = 0;
69698 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
69699 index f7bcd9e..8973e14 100644
69700 --- a/kernel/rcutree.c
69701 +++ b/kernel/rcutree.c
69702 @@ -369,9 +369,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
69703 rcu_prepare_for_idle(smp_processor_id());
69704 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
69705 smp_mb__before_atomic_inc(); /* See above. */
69706 - atomic_inc(&rdtp->dynticks);
69707 + atomic_inc_unchecked(&rdtp->dynticks);
69708 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
69709 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
69710 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
69711
69712 /*
69713 * The idle task is not permitted to enter the idle loop while
69714 @@ -460,10 +460,10 @@ void rcu_irq_exit(void)
69715 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
69716 {
69717 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
69718 - atomic_inc(&rdtp->dynticks);
69719 + atomic_inc_unchecked(&rdtp->dynticks);
69720 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
69721 smp_mb__after_atomic_inc(); /* See above. */
69722 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
69723 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
69724 rcu_cleanup_after_idle(smp_processor_id());
69725 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
69726 if (!is_idle_task(current)) {
69727 @@ -557,14 +557,14 @@ void rcu_nmi_enter(void)
69728 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
69729
69730 if (rdtp->dynticks_nmi_nesting == 0 &&
69731 - (atomic_read(&rdtp->dynticks) & 0x1))
69732 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
69733 return;
69734 rdtp->dynticks_nmi_nesting++;
69735 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
69736 - atomic_inc(&rdtp->dynticks);
69737 + atomic_inc_unchecked(&rdtp->dynticks);
69738 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
69739 smp_mb__after_atomic_inc(); /* See above. */
69740 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
69741 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
69742 }
69743
69744 /**
69745 @@ -583,9 +583,9 @@ void rcu_nmi_exit(void)
69746 return;
69747 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
69748 smp_mb__before_atomic_inc(); /* See above. */
69749 - atomic_inc(&rdtp->dynticks);
69750 + atomic_inc_unchecked(&rdtp->dynticks);
69751 smp_mb__after_atomic_inc(); /* Force delay to next write. */
69752 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
69753 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
69754 }
69755
69756 /**
69757 @@ -599,7 +599,7 @@ int rcu_is_cpu_idle(void)
69758 int ret;
69759
69760 preempt_disable();
69761 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
69762 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
69763 preempt_enable();
69764 return ret;
69765 }
69766 @@ -667,7 +667,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
69767 */
69768 static int dyntick_save_progress_counter(struct rcu_data *rdp)
69769 {
69770 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
69771 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
69772 return (rdp->dynticks_snap & 0x1) == 0;
69773 }
69774
69775 @@ -682,7 +682,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
69776 unsigned int curr;
69777 unsigned int snap;
69778
69779 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
69780 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
69781 snap = (unsigned int)rdp->dynticks_snap;
69782
69783 /*
69784 @@ -712,10 +712,10 @@ static int jiffies_till_stall_check(void)
69785 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
69786 */
69787 if (till_stall_check < 3) {
69788 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
69789 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
69790 till_stall_check = 3;
69791 } else if (till_stall_check > 300) {
69792 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
69793 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
69794 till_stall_check = 300;
69795 }
69796 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
69797 @@ -1351,7 +1351,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
69798 rsp->qlen += rdp->qlen;
69799 rdp->n_cbs_orphaned += rdp->qlen;
69800 rdp->qlen_lazy = 0;
69801 - ACCESS_ONCE(rdp->qlen) = 0;
69802 + ACCESS_ONCE_RW(rdp->qlen) = 0;
69803 }
69804
69805 /*
69806 @@ -1604,7 +1604,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
69807 }
69808 smp_mb(); /* List handling before counting for rcu_barrier(). */
69809 rdp->qlen_lazy -= count_lazy;
69810 - ACCESS_ONCE(rdp->qlen) -= count;
69811 + ACCESS_ONCE_RW(rdp->qlen) -= count;
69812 rdp->n_cbs_invoked += count;
69813
69814 /* Reinstate batch limit if we have worked down the excess. */
69815 @@ -1836,7 +1836,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
69816 /*
69817 * Do RCU core processing for the current CPU.
69818 */
69819 -static void rcu_process_callbacks(struct softirq_action *unused)
69820 +static void rcu_process_callbacks(void)
69821 {
69822 struct rcu_state *rsp;
69823
69824 @@ -1943,7 +1943,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
69825 rdp = this_cpu_ptr(rsp->rda);
69826
69827 /* Add the callback to our list. */
69828 - ACCESS_ONCE(rdp->qlen)++;
69829 + ACCESS_ONCE_RW(rdp->qlen)++;
69830 if (lazy)
69831 rdp->qlen_lazy++;
69832 else
69833 @@ -2057,8 +2057,8 @@ void synchronize_rcu_bh(void)
69834 }
69835 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
69836
69837 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
69838 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
69839 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
69840 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
69841
69842 static int synchronize_sched_expedited_cpu_stop(void *data)
69843 {
69844 @@ -2119,7 +2119,7 @@ void synchronize_sched_expedited(void)
69845 int firstsnap, s, snap, trycount = 0;
69846
69847 /* Note that atomic_inc_return() implies full memory barrier. */
69848 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
69849 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
69850 get_online_cpus();
69851 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
69852
69853 @@ -2141,7 +2141,7 @@ void synchronize_sched_expedited(void)
69854 }
69855
69856 /* Check to see if someone else did our work for us. */
69857 - s = atomic_read(&sync_sched_expedited_done);
69858 + s = atomic_read_unchecked(&sync_sched_expedited_done);
69859 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
69860 smp_mb(); /* ensure test happens before caller kfree */
69861 return;
69862 @@ -2156,7 +2156,7 @@ void synchronize_sched_expedited(void)
69863 * grace period works for us.
69864 */
69865 get_online_cpus();
69866 - snap = atomic_read(&sync_sched_expedited_started);
69867 + snap = atomic_read_unchecked(&sync_sched_expedited_started);
69868 smp_mb(); /* ensure read is before try_stop_cpus(). */
69869 }
69870
69871 @@ -2167,12 +2167,12 @@ void synchronize_sched_expedited(void)
69872 * than we did beat us to the punch.
69873 */
69874 do {
69875 - s = atomic_read(&sync_sched_expedited_done);
69876 + s = atomic_read_unchecked(&sync_sched_expedited_done);
69877 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
69878 smp_mb(); /* ensure test happens before caller kfree */
69879 break;
69880 }
69881 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
69882 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
69883
69884 put_online_cpus();
69885 }
69886 @@ -2366,7 +2366,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
69887 * ACCESS_ONCE() to prevent the compiler from speculating
69888 * the increment to precede the early-exit check.
69889 */
69890 - ACCESS_ONCE(rsp->n_barrier_done)++;
69891 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
69892 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
69893 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
69894 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
69895 @@ -2448,7 +2448,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
69896
69897 /* Increment ->n_barrier_done to prevent duplicate work. */
69898 smp_mb(); /* Keep increment after above mechanism. */
69899 - ACCESS_ONCE(rsp->n_barrier_done)++;
69900 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
69901 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
69902 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
69903 smp_mb(); /* Keep increment before caller's subsequent code. */
69904 @@ -2495,10 +2495,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
69905 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
69906 init_callback_list(rdp);
69907 rdp->qlen_lazy = 0;
69908 - ACCESS_ONCE(rdp->qlen) = 0;
69909 + ACCESS_ONCE_RW(rdp->qlen) = 0;
69910 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
69911 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
69912 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
69913 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
69914 rdp->cpu = cpu;
69915 rdp->rsp = rsp;
69916 raw_spin_unlock_irqrestore(&rnp->lock, flags);
69917 @@ -2526,8 +2526,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
69918 rdp->n_force_qs_snap = rsp->n_force_qs;
69919 rdp->blimit = blimit;
69920 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
69921 - atomic_set(&rdp->dynticks->dynticks,
69922 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
69923 + atomic_set_unchecked(&rdp->dynticks->dynticks,
69924 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
69925 rcu_prepare_for_idle_init(cpu);
69926 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
69927
69928 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
69929 index 4d29169..d104a3c 100644
69930 --- a/kernel/rcutree.h
69931 +++ b/kernel/rcutree.h
69932 @@ -86,7 +86,7 @@ struct rcu_dynticks {
69933 long long dynticks_nesting; /* Track irq/process nesting level. */
69934 /* Process level is worth LLONG_MAX/2. */
69935 int dynticks_nmi_nesting; /* Track NMI nesting level. */
69936 - atomic_t dynticks; /* Even value for idle, else odd. */
69937 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
69938 #ifdef CONFIG_RCU_FAST_NO_HZ
69939 int dyntick_drain; /* Prepare-for-idle state variable. */
69940 unsigned long dyntick_holdoff;
69941 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
69942 index 7f3244c..417d606 100644
69943 --- a/kernel/rcutree_plugin.h
69944 +++ b/kernel/rcutree_plugin.h
69945 @@ -843,7 +843,7 @@ void synchronize_rcu_expedited(void)
69946
69947 /* Clean up and exit. */
69948 smp_mb(); /* ensure expedited GP seen before counter increment. */
69949 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
69950 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
69951 unlock_mb_ret:
69952 mutex_unlock(&sync_rcu_preempt_exp_mutex);
69953 mb_ret:
69954 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
69955 index abffb48..cbfa6d3 100644
69956 --- a/kernel/rcutree_trace.c
69957 +++ b/kernel/rcutree_trace.c
69958 @@ -93,7 +93,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
69959 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
69960 rdp->qs_pending);
69961 seq_printf(m, " dt=%d/%llx/%d df=%lu",
69962 - atomic_read(&rdp->dynticks->dynticks),
69963 + atomic_read_unchecked(&rdp->dynticks->dynticks),
69964 rdp->dynticks->dynticks_nesting,
69965 rdp->dynticks->dynticks_nmi_nesting,
69966 rdp->dynticks_fqs);
69967 @@ -157,7 +157,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
69968 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
69969 rdp->qs_pending);
69970 seq_printf(m, ",%d,%llx,%d,%lu",
69971 - atomic_read(&rdp->dynticks->dynticks),
69972 + atomic_read_unchecked(&rdp->dynticks->dynticks),
69973 rdp->dynticks->dynticks_nesting,
69974 rdp->dynticks->dynticks_nmi_nesting,
69975 rdp->dynticks_fqs);
69976 diff --git a/kernel/resource.c b/kernel/resource.c
69977 index 34d4588..10baa6a 100644
69978 --- a/kernel/resource.c
69979 +++ b/kernel/resource.c
69980 @@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
69981
69982 static int __init ioresources_init(void)
69983 {
69984 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
69985 +#ifdef CONFIG_GRKERNSEC_PROC_USER
69986 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
69987 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
69988 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69989 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
69990 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
69991 +#endif
69992 +#else
69993 proc_create("ioports", 0, NULL, &proc_ioports_operations);
69994 proc_create("iomem", 0, NULL, &proc_iomem_operations);
69995 +#endif
69996 return 0;
69997 }
69998 __initcall(ioresources_init);
69999 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
70000 index 98ec494..4241d6d 100644
70001 --- a/kernel/rtmutex-tester.c
70002 +++ b/kernel/rtmutex-tester.c
70003 @@ -20,7 +20,7 @@
70004 #define MAX_RT_TEST_MUTEXES 8
70005
70006 static spinlock_t rttest_lock;
70007 -static atomic_t rttest_event;
70008 +static atomic_unchecked_t rttest_event;
70009
70010 struct test_thread_data {
70011 int opcode;
70012 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70013
70014 case RTTEST_LOCKCONT:
70015 td->mutexes[td->opdata] = 1;
70016 - td->event = atomic_add_return(1, &rttest_event);
70017 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70018 return 0;
70019
70020 case RTTEST_RESET:
70021 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70022 return 0;
70023
70024 case RTTEST_RESETEVENT:
70025 - atomic_set(&rttest_event, 0);
70026 + atomic_set_unchecked(&rttest_event, 0);
70027 return 0;
70028
70029 default:
70030 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70031 return ret;
70032
70033 td->mutexes[id] = 1;
70034 - td->event = atomic_add_return(1, &rttest_event);
70035 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70036 rt_mutex_lock(&mutexes[id]);
70037 - td->event = atomic_add_return(1, &rttest_event);
70038 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70039 td->mutexes[id] = 4;
70040 return 0;
70041
70042 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70043 return ret;
70044
70045 td->mutexes[id] = 1;
70046 - td->event = atomic_add_return(1, &rttest_event);
70047 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70048 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
70049 - td->event = atomic_add_return(1, &rttest_event);
70050 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70051 td->mutexes[id] = ret ? 0 : 4;
70052 return ret ? -EINTR : 0;
70053
70054 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70055 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
70056 return ret;
70057
70058 - td->event = atomic_add_return(1, &rttest_event);
70059 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70060 rt_mutex_unlock(&mutexes[id]);
70061 - td->event = atomic_add_return(1, &rttest_event);
70062 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70063 td->mutexes[id] = 0;
70064 return 0;
70065
70066 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
70067 break;
70068
70069 td->mutexes[dat] = 2;
70070 - td->event = atomic_add_return(1, &rttest_event);
70071 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70072 break;
70073
70074 default:
70075 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
70076 return;
70077
70078 td->mutexes[dat] = 3;
70079 - td->event = atomic_add_return(1, &rttest_event);
70080 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70081 break;
70082
70083 case RTTEST_LOCKNOWAIT:
70084 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
70085 return;
70086
70087 td->mutexes[dat] = 1;
70088 - td->event = atomic_add_return(1, &rttest_event);
70089 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70090 return;
70091
70092 default:
70093 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
70094 index 0984a21..939f183 100644
70095 --- a/kernel/sched/auto_group.c
70096 +++ b/kernel/sched/auto_group.c
70097 @@ -11,7 +11,7 @@
70098
70099 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
70100 static struct autogroup autogroup_default;
70101 -static atomic_t autogroup_seq_nr;
70102 +static atomic_unchecked_t autogroup_seq_nr;
70103
70104 void __init autogroup_init(struct task_struct *init_task)
70105 {
70106 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
70107
70108 kref_init(&ag->kref);
70109 init_rwsem(&ag->lock);
70110 - ag->id = atomic_inc_return(&autogroup_seq_nr);
70111 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
70112 ag->tg = tg;
70113 #ifdef CONFIG_RT_GROUP_SCHED
70114 /*
70115 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
70116 index 1a48cdb..d3949ff 100644
70117 --- a/kernel/sched/core.c
70118 +++ b/kernel/sched/core.c
70119 @@ -4103,6 +4103,8 @@ int can_nice(const struct task_struct *p, const int nice)
70120 /* convert nice value [19,-20] to rlimit style value [1,40] */
70121 int nice_rlim = 20 - nice;
70122
70123 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
70124 +
70125 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
70126 capable(CAP_SYS_NICE));
70127 }
70128 @@ -4136,7 +4138,8 @@ SYSCALL_DEFINE1(nice, int, increment)
70129 if (nice > 19)
70130 nice = 19;
70131
70132 - if (increment < 0 && !can_nice(current, nice))
70133 + if (increment < 0 && (!can_nice(current, nice) ||
70134 + gr_handle_chroot_nice()))
70135 return -EPERM;
70136
70137 retval = security_task_setnice(current, nice);
70138 @@ -4290,6 +4293,7 @@ recheck:
70139 unsigned long rlim_rtprio =
70140 task_rlimit(p, RLIMIT_RTPRIO);
70141
70142 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
70143 /* can't set/change the rt policy */
70144 if (policy != p->policy && !rlim_rtprio)
70145 return -EPERM;
70146 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
70147 index 96e2b18..bb31eec 100644
70148 --- a/kernel/sched/fair.c
70149 +++ b/kernel/sched/fair.c
70150 @@ -4923,7 +4923,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
70151 * run_rebalance_domains is triggered when needed from the scheduler tick.
70152 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
70153 */
70154 -static void run_rebalance_domains(struct softirq_action *h)
70155 +static void run_rebalance_domains(void)
70156 {
70157 int this_cpu = smp_processor_id();
70158 struct rq *this_rq = cpu_rq(this_cpu);
70159 diff --git a/kernel/signal.c b/kernel/signal.c
70160 index be4f856..453401c 100644
70161 --- a/kernel/signal.c
70162 +++ b/kernel/signal.c
70163 @@ -48,12 +48,12 @@ static struct kmem_cache *sigqueue_cachep;
70164
70165 int print_fatal_signals __read_mostly;
70166
70167 -static void __user *sig_handler(struct task_struct *t, int sig)
70168 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
70169 {
70170 return t->sighand->action[sig - 1].sa.sa_handler;
70171 }
70172
70173 -static int sig_handler_ignored(void __user *handler, int sig)
70174 +static int sig_handler_ignored(__sighandler_t handler, int sig)
70175 {
70176 /* Is it explicitly or implicitly ignored? */
70177 return handler == SIG_IGN ||
70178 @@ -62,7 +62,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
70179
70180 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
70181 {
70182 - void __user *handler;
70183 + __sighandler_t handler;
70184
70185 handler = sig_handler(t, sig);
70186
70187 @@ -366,6 +366,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
70188 atomic_inc(&user->sigpending);
70189 rcu_read_unlock();
70190
70191 + if (!override_rlimit)
70192 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
70193 +
70194 if (override_rlimit ||
70195 atomic_read(&user->sigpending) <=
70196 task_rlimit(t, RLIMIT_SIGPENDING)) {
70197 @@ -490,7 +493,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
70198
70199 int unhandled_signal(struct task_struct *tsk, int sig)
70200 {
70201 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
70202 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
70203 if (is_global_init(tsk))
70204 return 1;
70205 if (handler != SIG_IGN && handler != SIG_DFL)
70206 @@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
70207 }
70208 }
70209
70210 + /* allow glibc communication via tgkill to other threads in our
70211 + thread group */
70212 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
70213 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
70214 + && gr_handle_signal(t, sig))
70215 + return -EPERM;
70216 +
70217 return security_task_kill(t, info, sig, 0);
70218 }
70219
70220 @@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
70221 return send_signal(sig, info, p, 1);
70222 }
70223
70224 -static int
70225 +int
70226 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70227 {
70228 return send_signal(sig, info, t, 0);
70229 @@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70230 unsigned long int flags;
70231 int ret, blocked, ignored;
70232 struct k_sigaction *action;
70233 + int is_unhandled = 0;
70234
70235 spin_lock_irqsave(&t->sighand->siglock, flags);
70236 action = &t->sighand->action[sig-1];
70237 @@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70238 }
70239 if (action->sa.sa_handler == SIG_DFL)
70240 t->signal->flags &= ~SIGNAL_UNKILLABLE;
70241 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
70242 + is_unhandled = 1;
70243 ret = specific_send_sig_info(sig, info, t);
70244 spin_unlock_irqrestore(&t->sighand->siglock, flags);
70245
70246 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
70247 + normal operation */
70248 + if (is_unhandled) {
70249 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
70250 + gr_handle_crash(t, sig);
70251 + }
70252 +
70253 return ret;
70254 }
70255
70256 @@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
70257 ret = check_kill_permission(sig, info, p);
70258 rcu_read_unlock();
70259
70260 - if (!ret && sig)
70261 + if (!ret && sig) {
70262 ret = do_send_sig_info(sig, info, p, true);
70263 + if (!ret)
70264 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
70265 + }
70266
70267 return ret;
70268 }
70269 @@ -2873,7 +2896,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
70270 int error = -ESRCH;
70271
70272 rcu_read_lock();
70273 - p = find_task_by_vpid(pid);
70274 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
70275 + /* allow glibc communication via tgkill to other threads in our
70276 + thread group */
70277 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
70278 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
70279 + p = find_task_by_vpid_unrestricted(pid);
70280 + else
70281 +#endif
70282 + p = find_task_by_vpid(pid);
70283 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
70284 error = check_kill_permission(sig, info, p);
70285 /*
70286 diff --git a/kernel/softirq.c b/kernel/softirq.c
70287 index b73e681..645ab62 100644
70288 --- a/kernel/softirq.c
70289 +++ b/kernel/softirq.c
70290 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
70291
70292 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
70293
70294 -char *softirq_to_name[NR_SOFTIRQS] = {
70295 +const char * const softirq_to_name[NR_SOFTIRQS] = {
70296 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
70297 "TASKLET", "SCHED", "HRTIMER", "RCU"
70298 };
70299 @@ -243,7 +243,7 @@ restart:
70300 kstat_incr_softirqs_this_cpu(vec_nr);
70301
70302 trace_softirq_entry(vec_nr);
70303 - h->action(h);
70304 + h->action();
70305 trace_softirq_exit(vec_nr);
70306 if (unlikely(prev_count != preempt_count())) {
70307 printk(KERN_ERR "huh, entered softirq %u %s %p"
70308 @@ -390,9 +390,11 @@ void __raise_softirq_irqoff(unsigned int nr)
70309 or_softirq_pending(1UL << nr);
70310 }
70311
70312 -void open_softirq(int nr, void (*action)(struct softirq_action *))
70313 +void open_softirq(int nr, void (*action)(void))
70314 {
70315 - softirq_vec[nr].action = action;
70316 + pax_open_kernel();
70317 + *(void **)&softirq_vec[nr].action = action;
70318 + pax_close_kernel();
70319 }
70320
70321 /*
70322 @@ -446,7 +448,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
70323
70324 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
70325
70326 -static void tasklet_action(struct softirq_action *a)
70327 +static void tasklet_action(void)
70328 {
70329 struct tasklet_struct *list;
70330
70331 @@ -481,7 +483,7 @@ static void tasklet_action(struct softirq_action *a)
70332 }
70333 }
70334
70335 -static void tasklet_hi_action(struct softirq_action *a)
70336 +static void tasklet_hi_action(void)
70337 {
70338 struct tasklet_struct *list;
70339
70340 diff --git a/kernel/srcu.c b/kernel/srcu.c
70341 index 2095be3..9a5b89d 100644
70342 --- a/kernel/srcu.c
70343 +++ b/kernel/srcu.c
70344 @@ -302,9 +302,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
70345 preempt_disable();
70346 idx = rcu_dereference_index_check(sp->completed,
70347 rcu_read_lock_sched_held()) & 0x1;
70348 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
70349 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
70350 smp_mb(); /* B */ /* Avoid leaking the critical section. */
70351 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
70352 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
70353 preempt_enable();
70354 return idx;
70355 }
70356 @@ -320,7 +320,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
70357 {
70358 preempt_disable();
70359 smp_mb(); /* C */ /* Avoid leaking the critical section. */
70360 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
70361 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
70362 preempt_enable();
70363 }
70364 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
70365 diff --git a/kernel/sys.c b/kernel/sys.c
70366 index 909148a..cd51acf 100644
70367 --- a/kernel/sys.c
70368 +++ b/kernel/sys.c
70369 @@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
70370 error = -EACCES;
70371 goto out;
70372 }
70373 +
70374 + if (gr_handle_chroot_setpriority(p, niceval)) {
70375 + error = -EACCES;
70376 + goto out;
70377 + }
70378 +
70379 no_nice = security_task_setnice(p, niceval);
70380 if (no_nice) {
70381 error = no_nice;
70382 @@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
70383 goto error;
70384 }
70385
70386 + if (gr_check_group_change(new->gid, new->egid, -1))
70387 + goto error;
70388 +
70389 if (rgid != (gid_t) -1 ||
70390 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
70391 new->sgid = new->egid;
70392 @@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
70393 old = current_cred();
70394
70395 retval = -EPERM;
70396 +
70397 + if (gr_check_group_change(kgid, kgid, kgid))
70398 + goto error;
70399 +
70400 if (nsown_capable(CAP_SETGID))
70401 new->gid = new->egid = new->sgid = new->fsgid = kgid;
70402 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
70403 @@ -647,7 +660,7 @@ error:
70404 /*
70405 * change the user struct in a credentials set to match the new UID
70406 */
70407 -static int set_user(struct cred *new)
70408 +int set_user(struct cred *new)
70409 {
70410 struct user_struct *new_user;
70411
70412 @@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
70413 goto error;
70414 }
70415
70416 + if (gr_check_user_change(new->uid, new->euid, -1))
70417 + goto error;
70418 +
70419 if (!uid_eq(new->uid, old->uid)) {
70420 retval = set_user(new);
70421 if (retval < 0)
70422 @@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
70423 old = current_cred();
70424
70425 retval = -EPERM;
70426 +
70427 + if (gr_check_crash_uid(kuid))
70428 + goto error;
70429 + if (gr_check_user_change(kuid, kuid, kuid))
70430 + goto error;
70431 +
70432 if (nsown_capable(CAP_SETUID)) {
70433 new->suid = new->uid = kuid;
70434 if (!uid_eq(kuid, old->uid)) {
70435 @@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
70436 goto error;
70437 }
70438
70439 + if (gr_check_user_change(kruid, keuid, -1))
70440 + goto error;
70441 +
70442 if (ruid != (uid_t) -1) {
70443 new->uid = kruid;
70444 if (!uid_eq(kruid, old->uid)) {
70445 @@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
70446 goto error;
70447 }
70448
70449 + if (gr_check_group_change(krgid, kegid, -1))
70450 + goto error;
70451 +
70452 if (rgid != (gid_t) -1)
70453 new->gid = krgid;
70454 if (egid != (gid_t) -1)
70455 @@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70456 if (!uid_valid(kuid))
70457 return old_fsuid;
70458
70459 + if (gr_check_user_change(-1, -1, kuid))
70460 + goto error;
70461 +
70462 new = prepare_creds();
70463 if (!new)
70464 return old_fsuid;
70465 @@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70466 }
70467 }
70468
70469 +error:
70470 abort_creds(new);
70471 return old_fsuid;
70472
70473 @@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
70474 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
70475 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
70476 nsown_capable(CAP_SETGID)) {
70477 + if (gr_check_group_change(-1, -1, kgid))
70478 + goto error;
70479 +
70480 if (!gid_eq(kgid, old->fsgid)) {
70481 new->fsgid = kgid;
70482 goto change_okay;
70483 }
70484 }
70485
70486 +error:
70487 abort_creds(new);
70488 return old_fsgid;
70489
70490 @@ -1340,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
70491 return -EFAULT;
70492
70493 down_read(&uts_sem);
70494 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
70495 + error = __copy_to_user(name->sysname, &utsname()->sysname,
70496 __OLD_UTS_LEN);
70497 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
70498 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
70499 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
70500 __OLD_UTS_LEN);
70501 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
70502 - error |= __copy_to_user(&name->release, &utsname()->release,
70503 + error |= __copy_to_user(name->release, &utsname()->release,
70504 __OLD_UTS_LEN);
70505 error |= __put_user(0, name->release + __OLD_UTS_LEN);
70506 - error |= __copy_to_user(&name->version, &utsname()->version,
70507 + error |= __copy_to_user(name->version, &utsname()->version,
70508 __OLD_UTS_LEN);
70509 error |= __put_user(0, name->version + __OLD_UTS_LEN);
70510 - error |= __copy_to_user(&name->machine, &utsname()->machine,
70511 + error |= __copy_to_user(name->machine, &utsname()->machine,
70512 __OLD_UTS_LEN);
70513 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
70514 up_read(&uts_sem);
70515 @@ -2026,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
70516 error = get_dumpable(me->mm);
70517 break;
70518 case PR_SET_DUMPABLE:
70519 - if (arg2 < 0 || arg2 > 1) {
70520 + if (arg2 > 1) {
70521 error = -EINVAL;
70522 break;
70523 }
70524 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
70525 index 87174ef..68cbb82 100644
70526 --- a/kernel/sysctl.c
70527 +++ b/kernel/sysctl.c
70528 @@ -92,7 +92,6 @@
70529
70530
70531 #if defined(CONFIG_SYSCTL)
70532 -
70533 /* External variables not in a header file. */
70534 extern int sysctl_overcommit_memory;
70535 extern int sysctl_overcommit_ratio;
70536 @@ -170,10 +169,8 @@ static int proc_taint(struct ctl_table *table, int write,
70537 void __user *buffer, size_t *lenp, loff_t *ppos);
70538 #endif
70539
70540 -#ifdef CONFIG_PRINTK
70541 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70542 void __user *buffer, size_t *lenp, loff_t *ppos);
70543 -#endif
70544
70545 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
70546 void __user *buffer, size_t *lenp, loff_t *ppos);
70547 @@ -202,6 +199,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
70548
70549 #endif
70550
70551 +extern struct ctl_table grsecurity_table[];
70552 +
70553 static struct ctl_table kern_table[];
70554 static struct ctl_table vm_table[];
70555 static struct ctl_table fs_table[];
70556 @@ -216,6 +215,20 @@ extern struct ctl_table epoll_table[];
70557 int sysctl_legacy_va_layout;
70558 #endif
70559
70560 +#ifdef CONFIG_PAX_SOFTMODE
70561 +static ctl_table pax_table[] = {
70562 + {
70563 + .procname = "softmode",
70564 + .data = &pax_softmode,
70565 + .maxlen = sizeof(unsigned int),
70566 + .mode = 0600,
70567 + .proc_handler = &proc_dointvec,
70568 + },
70569 +
70570 + { }
70571 +};
70572 +#endif
70573 +
70574 /* The default sysctl tables: */
70575
70576 static struct ctl_table sysctl_base_table[] = {
70577 @@ -262,6 +275,22 @@ static int max_extfrag_threshold = 1000;
70578 #endif
70579
70580 static struct ctl_table kern_table[] = {
70581 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
70582 + {
70583 + .procname = "grsecurity",
70584 + .mode = 0500,
70585 + .child = grsecurity_table,
70586 + },
70587 +#endif
70588 +
70589 +#ifdef CONFIG_PAX_SOFTMODE
70590 + {
70591 + .procname = "pax",
70592 + .mode = 0500,
70593 + .child = pax_table,
70594 + },
70595 +#endif
70596 +
70597 {
70598 .procname = "sched_child_runs_first",
70599 .data = &sysctl_sched_child_runs_first,
70600 @@ -546,7 +575,7 @@ static struct ctl_table kern_table[] = {
70601 .data = &modprobe_path,
70602 .maxlen = KMOD_PATH_LEN,
70603 .mode = 0644,
70604 - .proc_handler = proc_dostring,
70605 + .proc_handler = proc_dostring_modpriv,
70606 },
70607 {
70608 .procname = "modules_disabled",
70609 @@ -713,16 +742,20 @@ static struct ctl_table kern_table[] = {
70610 .extra1 = &zero,
70611 .extra2 = &one,
70612 },
70613 +#endif
70614 {
70615 .procname = "kptr_restrict",
70616 .data = &kptr_restrict,
70617 .maxlen = sizeof(int),
70618 .mode = 0644,
70619 .proc_handler = proc_dointvec_minmax_sysadmin,
70620 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70621 + .extra1 = &two,
70622 +#else
70623 .extra1 = &zero,
70624 +#endif
70625 .extra2 = &two,
70626 },
70627 -#endif
70628 {
70629 .procname = "ngroups_max",
70630 .data = &ngroups_max,
70631 @@ -1219,6 +1252,13 @@ static struct ctl_table vm_table[] = {
70632 .proc_handler = proc_dointvec_minmax,
70633 .extra1 = &zero,
70634 },
70635 + {
70636 + .procname = "heap_stack_gap",
70637 + .data = &sysctl_heap_stack_gap,
70638 + .maxlen = sizeof(sysctl_heap_stack_gap),
70639 + .mode = 0644,
70640 + .proc_handler = proc_doulongvec_minmax,
70641 + },
70642 #else
70643 {
70644 .procname = "nr_trim_pages",
70645 @@ -1670,6 +1710,16 @@ int proc_dostring(struct ctl_table *table, int write,
70646 buffer, lenp, ppos);
70647 }
70648
70649 +int proc_dostring_modpriv(struct ctl_table *table, int write,
70650 + void __user *buffer, size_t *lenp, loff_t *ppos)
70651 +{
70652 + if (write && !capable(CAP_SYS_MODULE))
70653 + return -EPERM;
70654 +
70655 + return _proc_do_string(table->data, table->maxlen, write,
70656 + buffer, lenp, ppos);
70657 +}
70658 +
70659 static size_t proc_skip_spaces(char **buf)
70660 {
70661 size_t ret;
70662 @@ -1775,6 +1825,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
70663 len = strlen(tmp);
70664 if (len > *size)
70665 len = *size;
70666 + if (len > sizeof(tmp))
70667 + len = sizeof(tmp);
70668 if (copy_to_user(*buf, tmp, len))
70669 return -EFAULT;
70670 *size -= len;
70671 @@ -1967,7 +2019,6 @@ static int proc_taint(struct ctl_table *table, int write,
70672 return err;
70673 }
70674
70675 -#ifdef CONFIG_PRINTK
70676 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70677 void __user *buffer, size_t *lenp, loff_t *ppos)
70678 {
70679 @@ -1976,7 +2027,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70680
70681 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
70682 }
70683 -#endif
70684
70685 struct do_proc_dointvec_minmax_conv_param {
70686 int *min;
70687 @@ -2119,8 +2169,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
70688 *i = val;
70689 } else {
70690 val = convdiv * (*i) / convmul;
70691 - if (!first)
70692 + if (!first) {
70693 err = proc_put_char(&buffer, &left, '\t');
70694 + if (err)
70695 + break;
70696 + }
70697 err = proc_put_long(&buffer, &left, val, false);
70698 if (err)
70699 break;
70700 @@ -2512,6 +2565,12 @@ int proc_dostring(struct ctl_table *table, int write,
70701 return -ENOSYS;
70702 }
70703
70704 +int proc_dostring_modpriv(struct ctl_table *table, int write,
70705 + void __user *buffer, size_t *lenp, loff_t *ppos)
70706 +{
70707 + return -ENOSYS;
70708 +}
70709 +
70710 int proc_dointvec(struct ctl_table *table, int write,
70711 void __user *buffer, size_t *lenp, loff_t *ppos)
70712 {
70713 @@ -2568,5 +2627,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
70714 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
70715 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
70716 EXPORT_SYMBOL(proc_dostring);
70717 +EXPORT_SYMBOL(proc_dostring_modpriv);
70718 EXPORT_SYMBOL(proc_doulongvec_minmax);
70719 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
70720 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
70721 index 65bdcf1..21eb831 100644
70722 --- a/kernel/sysctl_binary.c
70723 +++ b/kernel/sysctl_binary.c
70724 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
70725 int i;
70726
70727 set_fs(KERNEL_DS);
70728 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
70729 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
70730 set_fs(old_fs);
70731 if (result < 0)
70732 goto out_kfree;
70733 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
70734 }
70735
70736 set_fs(KERNEL_DS);
70737 - result = vfs_write(file, buffer, str - buffer, &pos);
70738 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
70739 set_fs(old_fs);
70740 if (result < 0)
70741 goto out_kfree;
70742 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
70743 int i;
70744
70745 set_fs(KERNEL_DS);
70746 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
70747 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
70748 set_fs(old_fs);
70749 if (result < 0)
70750 goto out_kfree;
70751 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
70752 }
70753
70754 set_fs(KERNEL_DS);
70755 - result = vfs_write(file, buffer, str - buffer, &pos);
70756 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
70757 set_fs(old_fs);
70758 if (result < 0)
70759 goto out_kfree;
70760 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
70761 int i;
70762
70763 set_fs(KERNEL_DS);
70764 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
70765 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
70766 set_fs(old_fs);
70767 if (result < 0)
70768 goto out;
70769 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
70770 __le16 dnaddr;
70771
70772 set_fs(KERNEL_DS);
70773 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
70774 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
70775 set_fs(old_fs);
70776 if (result < 0)
70777 goto out;
70778 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
70779 le16_to_cpu(dnaddr) & 0x3ff);
70780
70781 set_fs(KERNEL_DS);
70782 - result = vfs_write(file, buf, len, &pos);
70783 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
70784 set_fs(old_fs);
70785 if (result < 0)
70786 goto out;
70787 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
70788 index d0a3279..db0ad99 100644
70789 --- a/kernel/taskstats.c
70790 +++ b/kernel/taskstats.c
70791 @@ -27,9 +27,12 @@
70792 #include <linux/cgroup.h>
70793 #include <linux/fs.h>
70794 #include <linux/file.h>
70795 +#include <linux/grsecurity.h>
70796 #include <net/genetlink.h>
70797 #include <linux/atomic.h>
70798
70799 +extern int gr_is_taskstats_denied(int pid);
70800 +
70801 /*
70802 * Maximum length of a cpumask that can be specified in
70803 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
70804 @@ -561,6 +564,9 @@ err:
70805
70806 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
70807 {
70808 + if (gr_is_taskstats_denied(current->pid))
70809 + return -EACCES;
70810 +
70811 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
70812 return cmd_attr_register_cpumask(info);
70813 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
70814 diff --git a/kernel/time.c b/kernel/time.c
70815 index ba744cf..267b7c5 100644
70816 --- a/kernel/time.c
70817 +++ b/kernel/time.c
70818 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
70819 return error;
70820
70821 if (tz) {
70822 + /* we log in do_settimeofday called below, so don't log twice
70823 + */
70824 + if (!tv)
70825 + gr_log_timechange();
70826 +
70827 sys_tz = *tz;
70828 update_vsyscall_tz();
70829 if (firsttime) {
70830 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
70831 index aa27d39..34d221c 100644
70832 --- a/kernel/time/alarmtimer.c
70833 +++ b/kernel/time/alarmtimer.c
70834 @@ -779,7 +779,7 @@ static int __init alarmtimer_init(void)
70835 struct platform_device *pdev;
70836 int error = 0;
70837 int i;
70838 - struct k_clock alarm_clock = {
70839 + static struct k_clock alarm_clock = {
70840 .clock_getres = alarm_clock_getres,
70841 .clock_get = alarm_clock_get,
70842 .timer_create = alarm_timer_create,
70843 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
70844 index f113755..ec24223 100644
70845 --- a/kernel/time/tick-broadcast.c
70846 +++ b/kernel/time/tick-broadcast.c
70847 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
70848 * then clear the broadcast bit.
70849 */
70850 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
70851 - int cpu = smp_processor_id();
70852 + cpu = smp_processor_id();
70853
70854 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
70855 tick_broadcast_clear_oneshot(cpu);
70856 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
70857 index f791637..00051de 100644
70858 --- a/kernel/time/timekeeping.c
70859 +++ b/kernel/time/timekeeping.c
70860 @@ -14,6 +14,7 @@
70861 #include <linux/init.h>
70862 #include <linux/mm.h>
70863 #include <linux/sched.h>
70864 +#include <linux/grsecurity.h>
70865 #include <linux/syscore_ops.h>
70866 #include <linux/clocksource.h>
70867 #include <linux/jiffies.h>
70868 @@ -434,6 +435,8 @@ int do_settimeofday(const struct timespec *tv)
70869 if (!timespec_valid_strict(tv))
70870 return -EINVAL;
70871
70872 + gr_log_timechange();
70873 +
70874 write_seqlock_irqsave(&tk->lock, flags);
70875
70876 timekeeping_forward_now(tk);
70877 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
70878 index af5a7e9..715611a 100644
70879 --- a/kernel/time/timer_list.c
70880 +++ b/kernel/time/timer_list.c
70881 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
70882
70883 static void print_name_offset(struct seq_file *m, void *sym)
70884 {
70885 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70886 + SEQ_printf(m, "<%p>", NULL);
70887 +#else
70888 char symname[KSYM_NAME_LEN];
70889
70890 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
70891 SEQ_printf(m, "<%pK>", sym);
70892 else
70893 SEQ_printf(m, "%s", symname);
70894 +#endif
70895 }
70896
70897 static void
70898 @@ -112,7 +116,11 @@ next_one:
70899 static void
70900 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
70901 {
70902 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70903 + SEQ_printf(m, " .base: %p\n", NULL);
70904 +#else
70905 SEQ_printf(m, " .base: %pK\n", base);
70906 +#endif
70907 SEQ_printf(m, " .index: %d\n",
70908 base->index);
70909 SEQ_printf(m, " .resolution: %Lu nsecs\n",
70910 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
70911 {
70912 struct proc_dir_entry *pe;
70913
70914 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70915 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
70916 +#else
70917 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
70918 +#endif
70919 if (!pe)
70920 return -ENOMEM;
70921 return 0;
70922 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
70923 index 0b537f2..40d6c20 100644
70924 --- a/kernel/time/timer_stats.c
70925 +++ b/kernel/time/timer_stats.c
70926 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
70927 static unsigned long nr_entries;
70928 static struct entry entries[MAX_ENTRIES];
70929
70930 -static atomic_t overflow_count;
70931 +static atomic_unchecked_t overflow_count;
70932
70933 /*
70934 * The entries are in a hash-table, for fast lookup:
70935 @@ -140,7 +140,7 @@ static void reset_entries(void)
70936 nr_entries = 0;
70937 memset(entries, 0, sizeof(entries));
70938 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
70939 - atomic_set(&overflow_count, 0);
70940 + atomic_set_unchecked(&overflow_count, 0);
70941 }
70942
70943 static struct entry *alloc_entry(void)
70944 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70945 if (likely(entry))
70946 entry->count++;
70947 else
70948 - atomic_inc(&overflow_count);
70949 + atomic_inc_unchecked(&overflow_count);
70950
70951 out_unlock:
70952 raw_spin_unlock_irqrestore(lock, flags);
70953 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70954
70955 static void print_name_offset(struct seq_file *m, unsigned long addr)
70956 {
70957 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70958 + seq_printf(m, "<%p>", NULL);
70959 +#else
70960 char symname[KSYM_NAME_LEN];
70961
70962 if (lookup_symbol_name(addr, symname) < 0)
70963 - seq_printf(m, "<%p>", (void *)addr);
70964 + seq_printf(m, "<%pK>", (void *)addr);
70965 else
70966 seq_printf(m, "%s", symname);
70967 +#endif
70968 }
70969
70970 static int tstats_show(struct seq_file *m, void *v)
70971 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
70972
70973 seq_puts(m, "Timer Stats Version: v0.2\n");
70974 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
70975 - if (atomic_read(&overflow_count))
70976 + if (atomic_read_unchecked(&overflow_count))
70977 seq_printf(m, "Overflow: %d entries\n",
70978 - atomic_read(&overflow_count));
70979 + atomic_read_unchecked(&overflow_count));
70980
70981 for (i = 0; i < nr_entries; i++) {
70982 entry = entries + i;
70983 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
70984 {
70985 struct proc_dir_entry *pe;
70986
70987 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70988 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
70989 +#else
70990 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
70991 +#endif
70992 if (!pe)
70993 return -ENOMEM;
70994 return 0;
70995 diff --git a/kernel/timer.c b/kernel/timer.c
70996 index 46ef2b1..ad081f144 100644
70997 --- a/kernel/timer.c
70998 +++ b/kernel/timer.c
70999 @@ -1377,7 +1377,7 @@ void update_process_times(int user_tick)
71000 /*
71001 * This function runs timers and the timer-tq in bottom half context.
71002 */
71003 -static void run_timer_softirq(struct softirq_action *h)
71004 +static void run_timer_softirq(void)
71005 {
71006 struct tvec_base *base = __this_cpu_read(tvec_bases);
71007
71008 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
71009 index c0bd030..62a1927 100644
71010 --- a/kernel/trace/blktrace.c
71011 +++ b/kernel/trace/blktrace.c
71012 @@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
71013 struct blk_trace *bt = filp->private_data;
71014 char buf[16];
71015
71016 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
71017 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
71018
71019 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
71020 }
71021 @@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
71022 return 1;
71023
71024 bt = buf->chan->private_data;
71025 - atomic_inc(&bt->dropped);
71026 + atomic_inc_unchecked(&bt->dropped);
71027 return 0;
71028 }
71029
71030 @@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
71031
71032 bt->dir = dir;
71033 bt->dev = dev;
71034 - atomic_set(&bt->dropped, 0);
71035 + atomic_set_unchecked(&bt->dropped, 0);
71036
71037 ret = -EIO;
71038 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
71039 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
71040 index b4f20fb..483c5fa 100644
71041 --- a/kernel/trace/ftrace.c
71042 +++ b/kernel/trace/ftrace.c
71043 @@ -1785,12 +1785,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
71044 if (unlikely(ftrace_disabled))
71045 return 0;
71046
71047 + ret = ftrace_arch_code_modify_prepare();
71048 + FTRACE_WARN_ON(ret);
71049 + if (ret)
71050 + return 0;
71051 +
71052 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
71053 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
71054 if (ret) {
71055 ftrace_bug(ret, ip);
71056 - return 0;
71057 }
71058 - return 1;
71059 + return ret ? 0 : 1;
71060 }
71061
71062 /*
71063 @@ -2885,7 +2890,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
71064
71065 int
71066 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
71067 - void *data)
71068 + void *data)
71069 {
71070 struct ftrace_func_probe *entry;
71071 struct ftrace_page *pg;
71072 @@ -3697,8 +3702,10 @@ static int ftrace_process_locs(struct module *mod,
71073 if (!count)
71074 return 0;
71075
71076 + pax_open_kernel();
71077 sort(start, count, sizeof(*start),
71078 ftrace_cmp_ips, ftrace_swap_ips);
71079 + pax_close_kernel();
71080
71081 start_pg = ftrace_allocate_pages(count);
71082 if (!start_pg)
71083 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
71084 index 5c38c81..88012af 100644
71085 --- a/kernel/trace/trace.c
71086 +++ b/kernel/trace/trace.c
71087 @@ -4437,10 +4437,9 @@ static const struct file_operations tracing_dyn_info_fops = {
71088 };
71089 #endif
71090
71091 -static struct dentry *d_tracer;
71092 -
71093 struct dentry *tracing_init_dentry(void)
71094 {
71095 + static struct dentry *d_tracer;
71096 static int once;
71097
71098 if (d_tracer)
71099 @@ -4460,10 +4459,9 @@ struct dentry *tracing_init_dentry(void)
71100 return d_tracer;
71101 }
71102
71103 -static struct dentry *d_percpu;
71104 -
71105 struct dentry *tracing_dentry_percpu(void)
71106 {
71107 + static struct dentry *d_percpu;
71108 static int once;
71109 struct dentry *d_tracer;
71110
71111 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
71112 index 29111da..d190fe2 100644
71113 --- a/kernel/trace/trace_events.c
71114 +++ b/kernel/trace/trace_events.c
71115 @@ -1308,10 +1308,6 @@ static LIST_HEAD(ftrace_module_file_list);
71116 struct ftrace_module_file_ops {
71117 struct list_head list;
71118 struct module *mod;
71119 - struct file_operations id;
71120 - struct file_operations enable;
71121 - struct file_operations format;
71122 - struct file_operations filter;
71123 };
71124
71125 static struct ftrace_module_file_ops *
71126 @@ -1332,17 +1328,12 @@ trace_create_file_ops(struct module *mod)
71127
71128 file_ops->mod = mod;
71129
71130 - file_ops->id = ftrace_event_id_fops;
71131 - file_ops->id.owner = mod;
71132 -
71133 - file_ops->enable = ftrace_enable_fops;
71134 - file_ops->enable.owner = mod;
71135 -
71136 - file_ops->filter = ftrace_event_filter_fops;
71137 - file_ops->filter.owner = mod;
71138 -
71139 - file_ops->format = ftrace_event_format_fops;
71140 - file_ops->format.owner = mod;
71141 + pax_open_kernel();
71142 + *(void **)&mod->trace_id.owner = mod;
71143 + *(void **)&mod->trace_enable.owner = mod;
71144 + *(void **)&mod->trace_filter.owner = mod;
71145 + *(void **)&mod->trace_format.owner = mod;
71146 + pax_close_kernel();
71147
71148 list_add(&file_ops->list, &ftrace_module_file_list);
71149
71150 @@ -1366,8 +1357,8 @@ static void trace_module_add_events(struct module *mod)
71151
71152 for_each_event(call, start, end) {
71153 __trace_add_event_call(*call, mod,
71154 - &file_ops->id, &file_ops->enable,
71155 - &file_ops->filter, &file_ops->format);
71156 + &mod->trace_id, &mod->trace_enable,
71157 + &mod->trace_filter, &mod->trace_format);
71158 }
71159 }
71160
71161 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
71162 index fd3c8aa..5f324a6 100644
71163 --- a/kernel/trace/trace_mmiotrace.c
71164 +++ b/kernel/trace/trace_mmiotrace.c
71165 @@ -24,7 +24,7 @@ struct header_iter {
71166 static struct trace_array *mmio_trace_array;
71167 static bool overrun_detected;
71168 static unsigned long prev_overruns;
71169 -static atomic_t dropped_count;
71170 +static atomic_unchecked_t dropped_count;
71171
71172 static void mmio_reset_data(struct trace_array *tr)
71173 {
71174 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
71175
71176 static unsigned long count_overruns(struct trace_iterator *iter)
71177 {
71178 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
71179 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
71180 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
71181
71182 if (over > prev_overruns)
71183 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
71184 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
71185 sizeof(*entry), 0, pc);
71186 if (!event) {
71187 - atomic_inc(&dropped_count);
71188 + atomic_inc_unchecked(&dropped_count);
71189 return;
71190 }
71191 entry = ring_buffer_event_data(event);
71192 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
71193 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
71194 sizeof(*entry), 0, pc);
71195 if (!event) {
71196 - atomic_inc(&dropped_count);
71197 + atomic_inc_unchecked(&dropped_count);
71198 return;
71199 }
71200 entry = ring_buffer_event_data(event);
71201 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
71202 index 123b189..97b81f5 100644
71203 --- a/kernel/trace/trace_output.c
71204 +++ b/kernel/trace/trace_output.c
71205 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
71206
71207 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
71208 if (!IS_ERR(p)) {
71209 - p = mangle_path(s->buffer + s->len, p, "\n");
71210 + p = mangle_path(s->buffer + s->len, p, "\n\\");
71211 if (p) {
71212 s->len = p - s->buffer;
71213 return 1;
71214 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
71215 index d4545f4..a9010a1 100644
71216 --- a/kernel/trace/trace_stack.c
71217 +++ b/kernel/trace/trace_stack.c
71218 @@ -53,7 +53,7 @@ static inline void check_stack(void)
71219 return;
71220
71221 /* we do not handle interrupt stacks yet */
71222 - if (!object_is_on_stack(&this_size))
71223 + if (!object_starts_on_stack(&this_size))
71224 return;
71225
71226 local_irq_save(flags);
71227 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
71228 index 872bd6d..31601a2 100644
71229 --- a/kernel/workqueue.c
71230 +++ b/kernel/workqueue.c
71231 @@ -1422,7 +1422,7 @@ retry:
71232 /* morph UNBOUND to REBIND atomically */
71233 worker_flags &= ~WORKER_UNBOUND;
71234 worker_flags |= WORKER_REBIND;
71235 - ACCESS_ONCE(worker->flags) = worker_flags;
71236 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
71237
71238 idle_rebind.cnt++;
71239 worker->idle_rebind = &idle_rebind;
71240 @@ -1448,7 +1448,7 @@ retry:
71241 /* morph UNBOUND to REBIND atomically */
71242 worker_flags &= ~WORKER_UNBOUND;
71243 worker_flags |= WORKER_REBIND;
71244 - ACCESS_ONCE(worker->flags) = worker_flags;
71245 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
71246
71247 if (test_and_set_bit(WORK_STRUCT_PENDING_BIT,
71248 work_data_bits(rebind_work)))
71249 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
71250 index 2403a63..5c4be4c 100644
71251 --- a/lib/Kconfig.debug
71252 +++ b/lib/Kconfig.debug
71253 @@ -1252,6 +1252,7 @@ config LATENCYTOP
71254 depends on DEBUG_KERNEL
71255 depends on STACKTRACE_SUPPORT
71256 depends on PROC_FS
71257 + depends on !GRKERNSEC_HIDESYM
71258 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
71259 select KALLSYMS
71260 select KALLSYMS_ALL
71261 @@ -1267,7 +1268,7 @@ source kernel/trace/Kconfig
71262
71263 config PROVIDE_OHCI1394_DMA_INIT
71264 bool "Remote debugging over FireWire early on boot"
71265 - depends on PCI && X86
71266 + depends on PCI && X86 && !GRKERNSEC
71267 help
71268 If you want to debug problems which hang or crash the kernel early
71269 on boot and the crashing machine has a FireWire port, you can use
71270 @@ -1296,7 +1297,7 @@ config PROVIDE_OHCI1394_DMA_INIT
71271
71272 config FIREWIRE_OHCI_REMOTE_DMA
71273 bool "Remote debugging over FireWire with firewire-ohci"
71274 - depends on FIREWIRE_OHCI
71275 + depends on FIREWIRE_OHCI && !GRKERNSEC
71276 help
71277 This option lets you use the FireWire bus for remote debugging
71278 with help of the firewire-ohci driver. It enables unfiltered
71279 diff --git a/lib/bitmap.c b/lib/bitmap.c
71280 index 06fdfa1..97c5c7d 100644
71281 --- a/lib/bitmap.c
71282 +++ b/lib/bitmap.c
71283 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
71284 {
71285 int c, old_c, totaldigits, ndigits, nchunks, nbits;
71286 u32 chunk;
71287 - const char __user __force *ubuf = (const char __user __force *)buf;
71288 + const char __user *ubuf = (const char __force_user *)buf;
71289
71290 bitmap_zero(maskp, nmaskbits);
71291
71292 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
71293 {
71294 if (!access_ok(VERIFY_READ, ubuf, ulen))
71295 return -EFAULT;
71296 - return __bitmap_parse((const char __force *)ubuf,
71297 + return __bitmap_parse((const char __force_kernel *)ubuf,
71298 ulen, 1, maskp, nmaskbits);
71299
71300 }
71301 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
71302 {
71303 unsigned a, b;
71304 int c, old_c, totaldigits;
71305 - const char __user __force *ubuf = (const char __user __force *)buf;
71306 + const char __user *ubuf = (const char __force_user *)buf;
71307 int exp_digit, in_range;
71308
71309 totaldigits = c = 0;
71310 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
71311 {
71312 if (!access_ok(VERIFY_READ, ubuf, ulen))
71313 return -EFAULT;
71314 - return __bitmap_parselist((const char __force *)ubuf,
71315 + return __bitmap_parselist((const char __force_kernel *)ubuf,
71316 ulen, 1, maskp, nmaskbits);
71317 }
71318 EXPORT_SYMBOL(bitmap_parselist_user);
71319 diff --git a/lib/bug.c b/lib/bug.c
71320 index a28c141..2bd3d95 100644
71321 --- a/lib/bug.c
71322 +++ b/lib/bug.c
71323 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
71324 return BUG_TRAP_TYPE_NONE;
71325
71326 bug = find_bug(bugaddr);
71327 + if (!bug)
71328 + return BUG_TRAP_TYPE_NONE;
71329
71330 file = NULL;
71331 line = 0;
71332 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
71333 index d11808c..dc2d6f8 100644
71334 --- a/lib/debugobjects.c
71335 +++ b/lib/debugobjects.c
71336 @@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
71337 if (limit > 4)
71338 return;
71339
71340 - is_on_stack = object_is_on_stack(addr);
71341 + is_on_stack = object_starts_on_stack(addr);
71342 if (is_on_stack == onstack)
71343 return;
71344
71345 diff --git a/lib/devres.c b/lib/devres.c
71346 index 80b9c76..9e32279 100644
71347 --- a/lib/devres.c
71348 +++ b/lib/devres.c
71349 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
71350 void devm_iounmap(struct device *dev, void __iomem *addr)
71351 {
71352 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
71353 - (void *)addr));
71354 + (void __force *)addr));
71355 iounmap(addr);
71356 }
71357 EXPORT_SYMBOL(devm_iounmap);
71358 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
71359 {
71360 ioport_unmap(addr);
71361 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
71362 - devm_ioport_map_match, (void *)addr));
71363 + devm_ioport_map_match, (void __force *)addr));
71364 }
71365 EXPORT_SYMBOL(devm_ioport_unmap);
71366
71367 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
71368 index 66ce414..6f0a0dd 100644
71369 --- a/lib/dma-debug.c
71370 +++ b/lib/dma-debug.c
71371 @@ -924,7 +924,7 @@ out:
71372
71373 static void check_for_stack(struct device *dev, void *addr)
71374 {
71375 - if (object_is_on_stack(addr))
71376 + if (object_starts_on_stack(addr))
71377 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
71378 "stack [addr=%p]\n", addr);
71379 }
71380 diff --git a/lib/inflate.c b/lib/inflate.c
71381 index 013a761..c28f3fc 100644
71382 --- a/lib/inflate.c
71383 +++ b/lib/inflate.c
71384 @@ -269,7 +269,7 @@ static void free(void *where)
71385 malloc_ptr = free_mem_ptr;
71386 }
71387 #else
71388 -#define malloc(a) kmalloc(a, GFP_KERNEL)
71389 +#define malloc(a) kmalloc((a), GFP_KERNEL)
71390 #define free(a) kfree(a)
71391 #endif
71392
71393 diff --git a/lib/ioremap.c b/lib/ioremap.c
71394 index 0c9216c..863bd89 100644
71395 --- a/lib/ioremap.c
71396 +++ b/lib/ioremap.c
71397 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
71398 unsigned long next;
71399
71400 phys_addr -= addr;
71401 - pmd = pmd_alloc(&init_mm, pud, addr);
71402 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
71403 if (!pmd)
71404 return -ENOMEM;
71405 do {
71406 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
71407 unsigned long next;
71408
71409 phys_addr -= addr;
71410 - pud = pud_alloc(&init_mm, pgd, addr);
71411 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
71412 if (!pud)
71413 return -ENOMEM;
71414 do {
71415 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
71416 index bd2bea9..6b3c95e 100644
71417 --- a/lib/is_single_threaded.c
71418 +++ b/lib/is_single_threaded.c
71419 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
71420 struct task_struct *p, *t;
71421 bool ret;
71422
71423 + if (!mm)
71424 + return true;
71425 +
71426 if (atomic_read(&task->signal->live) != 1)
71427 return false;
71428
71429 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
71430 index e796429..6e38f9f 100644
71431 --- a/lib/radix-tree.c
71432 +++ b/lib/radix-tree.c
71433 @@ -92,7 +92,7 @@ struct radix_tree_preload {
71434 int nr;
71435 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
71436 };
71437 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
71438 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
71439
71440 static inline void *ptr_to_indirect(void *ptr)
71441 {
71442 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
71443 index bb2b201..46abaf9 100644
71444 --- a/lib/strncpy_from_user.c
71445 +++ b/lib/strncpy_from_user.c
71446 @@ -21,7 +21,7 @@
71447 */
71448 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
71449 {
71450 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
71451 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
71452 long res = 0;
71453
71454 /*
71455 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
71456 index a28df52..3d55877 100644
71457 --- a/lib/strnlen_user.c
71458 +++ b/lib/strnlen_user.c
71459 @@ -26,7 +26,7 @@
71460 */
71461 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
71462 {
71463 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
71464 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
71465 long align, res = 0;
71466 unsigned long c;
71467
71468 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
71469 index 0e33754..50a0e63 100644
71470 --- a/lib/vsprintf.c
71471 +++ b/lib/vsprintf.c
71472 @@ -16,6 +16,9 @@
71473 * - scnprintf and vscnprintf
71474 */
71475
71476 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71477 +#define __INCLUDED_BY_HIDESYM 1
71478 +#endif
71479 #include <stdarg.h>
71480 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
71481 #include <linux/types.h>
71482 @@ -536,7 +539,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
71483 char sym[KSYM_SYMBOL_LEN];
71484 if (ext == 'B')
71485 sprint_backtrace(sym, value);
71486 - else if (ext != 'f' && ext != 's')
71487 + else if (ext != 'f' && ext != 's' && ext != 'a')
71488 sprint_symbol(sym, value);
71489 else
71490 sprint_symbol_no_offset(sym, value);
71491 @@ -969,7 +972,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
71492 return number(buf, end, *(const netdev_features_t *)addr, spec);
71493 }
71494
71495 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71496 +int kptr_restrict __read_mostly = 2;
71497 +#else
71498 int kptr_restrict __read_mostly;
71499 +#endif
71500
71501 /*
71502 * Show a '%p' thing. A kernel extension is that the '%p' is followed
71503 @@ -983,6 +990,8 @@ int kptr_restrict __read_mostly;
71504 * - 'S' For symbolic direct pointers with offset
71505 * - 's' For symbolic direct pointers without offset
71506 * - 'B' For backtraced symbolic direct pointers with offset
71507 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
71508 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
71509 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
71510 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
71511 * - 'M' For a 6-byte MAC address, it prints the address in the
71512 @@ -1038,12 +1047,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71513
71514 if (!ptr && *fmt != 'K') {
71515 /*
71516 - * Print (null) with the same width as a pointer so it makes
71517 + * Print (nil) with the same width as a pointer so it makes
71518 * tabular output look nice.
71519 */
71520 if (spec.field_width == -1)
71521 spec.field_width = default_width;
71522 - return string(buf, end, "(null)", spec);
71523 + return string(buf, end, "(nil)", spec);
71524 }
71525
71526 switch (*fmt) {
71527 @@ -1053,6 +1062,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71528 /* Fallthrough */
71529 case 'S':
71530 case 's':
71531 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71532 + break;
71533 +#else
71534 + return symbol_string(buf, end, ptr, spec, *fmt);
71535 +#endif
71536 + case 'A':
71537 + case 'a':
71538 case 'B':
71539 return symbol_string(buf, end, ptr, spec, *fmt);
71540 case 'R':
71541 @@ -1093,6 +1109,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71542 va_end(va);
71543 return buf;
71544 }
71545 + case 'P':
71546 + break;
71547 case 'K':
71548 /*
71549 * %pK cannot be used in IRQ context because its test
71550 @@ -1116,6 +1134,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71551 }
71552 break;
71553 }
71554 +
71555 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71556 + /* 'P' = approved pointers to copy to userland,
71557 + as in the /proc/kallsyms case, as we make it display nothing
71558 + for non-root users, and the real contents for root users
71559 + Also ignore 'K' pointers, since we force their NULLing for non-root users
71560 + above
71561 + */
71562 + if (ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
71563 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
71564 + dump_stack();
71565 + ptr = NULL;
71566 + }
71567 +#endif
71568 +
71569 spec.flags |= SMALL;
71570 if (spec.field_width == -1) {
71571 spec.field_width = default_width;
71572 @@ -1831,11 +1864,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
71573 typeof(type) value; \
71574 if (sizeof(type) == 8) { \
71575 args = PTR_ALIGN(args, sizeof(u32)); \
71576 - *(u32 *)&value = *(u32 *)args; \
71577 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
71578 + *(u32 *)&value = *(const u32 *)args; \
71579 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
71580 } else { \
71581 args = PTR_ALIGN(args, sizeof(type)); \
71582 - value = *(typeof(type) *)args; \
71583 + value = *(const typeof(type) *)args; \
71584 } \
71585 args += sizeof(type); \
71586 value; \
71587 @@ -1898,7 +1931,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
71588 case FORMAT_TYPE_STR: {
71589 const char *str_arg = args;
71590 args += strlen(str_arg) + 1;
71591 - str = string(str, end, (char *)str_arg, spec);
71592 + str = string(str, end, str_arg, spec);
71593 break;
71594 }
71595
71596 diff --git a/localversion-grsec b/localversion-grsec
71597 new file mode 100644
71598 index 0000000..7cd6065
71599 --- /dev/null
71600 +++ b/localversion-grsec
71601 @@ -0,0 +1 @@
71602 +-grsec
71603 diff --git a/mm/Kconfig b/mm/Kconfig
71604 index d5c8019..f513038 100644
71605 --- a/mm/Kconfig
71606 +++ b/mm/Kconfig
71607 @@ -251,10 +251,10 @@ config KSM
71608 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
71609
71610 config DEFAULT_MMAP_MIN_ADDR
71611 - int "Low address space to protect from user allocation"
71612 + int "Low address space to protect from user allocation"
71613 depends on MMU
71614 - default 4096
71615 - help
71616 + default 65536
71617 + help
71618 This is the portion of low virtual memory which should be protected
71619 from userspace allocation. Keeping a user from writing to low pages
71620 can help reduce the impact of kernel NULL pointer bugs.
71621 @@ -285,7 +285,7 @@ config MEMORY_FAILURE
71622
71623 config HWPOISON_INJECT
71624 tristate "HWPoison pages injector"
71625 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
71626 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
71627 select PROC_PAGE_MONITOR
71628
71629 config NOMMU_INITIAL_TRIM_EXCESS
71630 diff --git a/mm/filemap.c b/mm/filemap.c
71631 index 3843445..4fe6833 100644
71632 --- a/mm/filemap.c
71633 +++ b/mm/filemap.c
71634 @@ -1746,7 +1746,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
71635 struct address_space *mapping = file->f_mapping;
71636
71637 if (!mapping->a_ops->readpage)
71638 - return -ENOEXEC;
71639 + return -ENODEV;
71640 file_accessed(file);
71641 vma->vm_ops = &generic_file_vm_ops;
71642 vma->vm_flags |= VM_CAN_NONLINEAR;
71643 @@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
71644 *pos = i_size_read(inode);
71645
71646 if (limit != RLIM_INFINITY) {
71647 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
71648 if (*pos >= limit) {
71649 send_sig(SIGXFSZ, current, 0);
71650 return -EFBIG;
71651 diff --git a/mm/fremap.c b/mm/fremap.c
71652 index 9ed4fd4..c42648d 100644
71653 --- a/mm/fremap.c
71654 +++ b/mm/fremap.c
71655 @@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
71656 retry:
71657 vma = find_vma(mm, start);
71658
71659 +#ifdef CONFIG_PAX_SEGMEXEC
71660 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
71661 + goto out;
71662 +#endif
71663 +
71664 /*
71665 * Make sure the vma is shared, that it supports prefaulting,
71666 * and that the remapped range is valid and fully within
71667 diff --git a/mm/highmem.c b/mm/highmem.c
71668 index d517cd1..006a1c5 100644
71669 --- a/mm/highmem.c
71670 +++ b/mm/highmem.c
71671 @@ -137,9 +137,10 @@ static void flush_all_zero_pkmaps(void)
71672 * So no dangers, even with speculative execution.
71673 */
71674 page = pte_page(pkmap_page_table[i]);
71675 + pax_open_kernel();
71676 pte_clear(&init_mm, (unsigned long)page_address(page),
71677 &pkmap_page_table[i]);
71678 -
71679 + pax_close_kernel();
71680 set_page_address(page, NULL);
71681 need_flush = 1;
71682 }
71683 @@ -198,9 +199,11 @@ start:
71684 }
71685 }
71686 vaddr = PKMAP_ADDR(last_pkmap_nr);
71687 +
71688 + pax_open_kernel();
71689 set_pte_at(&init_mm, vaddr,
71690 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
71691 -
71692 + pax_close_kernel();
71693 pkmap_count[last_pkmap_nr] = 1;
71694 set_page_address(page, (void *)vaddr);
71695
71696 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
71697 index 141dbb6..ebff057 100644
71698 --- a/mm/huge_memory.c
71699 +++ b/mm/huge_memory.c
71700 @@ -735,7 +735,7 @@ out:
71701 * run pte_offset_map on the pmd, if an huge pmd could
71702 * materialize from under us from a different thread.
71703 */
71704 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
71705 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
71706 return VM_FAULT_OOM;
71707 /* if an huge pmd materialized from under us just retry later */
71708 if (unlikely(pmd_trans_huge(*pmd)))
71709 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
71710 index 3adceaf..dccfea3 100644
71711 --- a/mm/hugetlb.c
71712 +++ b/mm/hugetlb.c
71713 @@ -2512,6 +2512,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
71714 return 1;
71715 }
71716
71717 +#ifdef CONFIG_PAX_SEGMEXEC
71718 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
71719 +{
71720 + struct mm_struct *mm = vma->vm_mm;
71721 + struct vm_area_struct *vma_m;
71722 + unsigned long address_m;
71723 + pte_t *ptep_m;
71724 +
71725 + vma_m = pax_find_mirror_vma(vma);
71726 + if (!vma_m)
71727 + return;
71728 +
71729 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71730 + address_m = address + SEGMEXEC_TASK_SIZE;
71731 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
71732 + get_page(page_m);
71733 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
71734 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
71735 +}
71736 +#endif
71737 +
71738 /*
71739 * Hugetlb_cow() should be called with page lock of the original hugepage held.
71740 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
71741 @@ -2628,6 +2649,11 @@ retry_avoidcopy:
71742 make_huge_pte(vma, new_page, 1));
71743 page_remove_rmap(old_page);
71744 hugepage_add_new_anon_rmap(new_page, vma, address);
71745 +
71746 +#ifdef CONFIG_PAX_SEGMEXEC
71747 + pax_mirror_huge_pte(vma, address, new_page);
71748 +#endif
71749 +
71750 /* Make the old page be freed below */
71751 new_page = old_page;
71752 mmu_notifier_invalidate_range_end(mm,
71753 @@ -2786,6 +2812,10 @@ retry:
71754 && (vma->vm_flags & VM_SHARED)));
71755 set_huge_pte_at(mm, address, ptep, new_pte);
71756
71757 +#ifdef CONFIG_PAX_SEGMEXEC
71758 + pax_mirror_huge_pte(vma, address, page);
71759 +#endif
71760 +
71761 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
71762 /* Optimization, do the COW without a second fault */
71763 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
71764 @@ -2815,6 +2845,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71765 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
71766 struct hstate *h = hstate_vma(vma);
71767
71768 +#ifdef CONFIG_PAX_SEGMEXEC
71769 + struct vm_area_struct *vma_m;
71770 +#endif
71771 +
71772 address &= huge_page_mask(h);
71773
71774 ptep = huge_pte_offset(mm, address);
71775 @@ -2828,6 +2862,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71776 VM_FAULT_SET_HINDEX(hstate_index(h));
71777 }
71778
71779 +#ifdef CONFIG_PAX_SEGMEXEC
71780 + vma_m = pax_find_mirror_vma(vma);
71781 + if (vma_m) {
71782 + unsigned long address_m;
71783 +
71784 + if (vma->vm_start > vma_m->vm_start) {
71785 + address_m = address;
71786 + address -= SEGMEXEC_TASK_SIZE;
71787 + vma = vma_m;
71788 + h = hstate_vma(vma);
71789 + } else
71790 + address_m = address + SEGMEXEC_TASK_SIZE;
71791 +
71792 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
71793 + return VM_FAULT_OOM;
71794 + address_m &= HPAGE_MASK;
71795 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
71796 + }
71797 +#endif
71798 +
71799 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
71800 if (!ptep)
71801 return VM_FAULT_OOM;
71802 diff --git a/mm/internal.h b/mm/internal.h
71803 index b8c91b3..93e95a3 100644
71804 --- a/mm/internal.h
71805 +++ b/mm/internal.h
71806 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
71807 * in mm/page_alloc.c
71808 */
71809 extern void __free_pages_bootmem(struct page *page, unsigned int order);
71810 +extern void free_compound_page(struct page *page);
71811 extern void prep_compound_page(struct page *page, unsigned long order);
71812 #ifdef CONFIG_MEMORY_FAILURE
71813 extern bool is_free_buddy_page(struct page *page);
71814 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
71815 index 45eb621..6ccd8ea 100644
71816 --- a/mm/kmemleak.c
71817 +++ b/mm/kmemleak.c
71818 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
71819
71820 for (i = 0; i < object->trace_len; i++) {
71821 void *ptr = (void *)object->trace[i];
71822 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
71823 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
71824 }
71825 }
71826
71827 diff --git a/mm/maccess.c b/mm/maccess.c
71828 index d53adf9..03a24bf 100644
71829 --- a/mm/maccess.c
71830 +++ b/mm/maccess.c
71831 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
71832 set_fs(KERNEL_DS);
71833 pagefault_disable();
71834 ret = __copy_from_user_inatomic(dst,
71835 - (__force const void __user *)src, size);
71836 + (const void __force_user *)src, size);
71837 pagefault_enable();
71838 set_fs(old_fs);
71839
71840 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
71841
71842 set_fs(KERNEL_DS);
71843 pagefault_disable();
71844 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
71845 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
71846 pagefault_enable();
71847 set_fs(old_fs);
71848
71849 diff --git a/mm/madvise.c b/mm/madvise.c
71850 index 14d260f..b2a80fd 100644
71851 --- a/mm/madvise.c
71852 +++ b/mm/madvise.c
71853 @@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
71854 pgoff_t pgoff;
71855 unsigned long new_flags = vma->vm_flags;
71856
71857 +#ifdef CONFIG_PAX_SEGMEXEC
71858 + struct vm_area_struct *vma_m;
71859 +#endif
71860 +
71861 switch (behavior) {
71862 case MADV_NORMAL:
71863 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
71864 @@ -119,6 +123,13 @@ success:
71865 /*
71866 * vm_flags is protected by the mmap_sem held in write mode.
71867 */
71868 +
71869 +#ifdef CONFIG_PAX_SEGMEXEC
71870 + vma_m = pax_find_mirror_vma(vma);
71871 + if (vma_m)
71872 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
71873 +#endif
71874 +
71875 vma->vm_flags = new_flags;
71876
71877 out:
71878 @@ -177,6 +188,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
71879 struct vm_area_struct ** prev,
71880 unsigned long start, unsigned long end)
71881 {
71882 +
71883 +#ifdef CONFIG_PAX_SEGMEXEC
71884 + struct vm_area_struct *vma_m;
71885 +#endif
71886 +
71887 *prev = vma;
71888 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
71889 return -EINVAL;
71890 @@ -189,6 +205,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
71891 zap_page_range(vma, start, end - start, &details);
71892 } else
71893 zap_page_range(vma, start, end - start, NULL);
71894 +
71895 +#ifdef CONFIG_PAX_SEGMEXEC
71896 + vma_m = pax_find_mirror_vma(vma);
71897 + if (vma_m) {
71898 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
71899 + struct zap_details details = {
71900 + .nonlinear_vma = vma_m,
71901 + .last_index = ULONG_MAX,
71902 + };
71903 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
71904 + } else
71905 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
71906 + }
71907 +#endif
71908 +
71909 return 0;
71910 }
71911
71912 @@ -393,6 +424,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
71913 if (end < start)
71914 goto out;
71915
71916 +#ifdef CONFIG_PAX_SEGMEXEC
71917 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
71918 + if (end > SEGMEXEC_TASK_SIZE)
71919 + goto out;
71920 + } else
71921 +#endif
71922 +
71923 + if (end > TASK_SIZE)
71924 + goto out;
71925 +
71926 error = 0;
71927 if (end == start)
71928 goto out;
71929 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
71930 index a6e2141..eaf5aad 100644
71931 --- a/mm/memory-failure.c
71932 +++ b/mm/memory-failure.c
71933 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
71934
71935 int sysctl_memory_failure_recovery __read_mostly = 1;
71936
71937 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
71938 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
71939
71940 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
71941
71942 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
71943 pfn, t->comm, t->pid);
71944 si.si_signo = SIGBUS;
71945 si.si_errno = 0;
71946 - si.si_addr = (void *)addr;
71947 + si.si_addr = (void __user *)addr;
71948 #ifdef __ARCH_SI_TRAPNO
71949 si.si_trapno = trapno;
71950 #endif
71951 @@ -1038,7 +1038,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71952 }
71953
71954 nr_pages = 1 << compound_trans_order(hpage);
71955 - atomic_long_add(nr_pages, &mce_bad_pages);
71956 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
71957
71958 /*
71959 * We need/can do nothing about count=0 pages.
71960 @@ -1068,7 +1068,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71961 if (!PageHWPoison(hpage)
71962 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
71963 || (p != hpage && TestSetPageHWPoison(hpage))) {
71964 - atomic_long_sub(nr_pages, &mce_bad_pages);
71965 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71966 return 0;
71967 }
71968 set_page_hwpoison_huge_page(hpage);
71969 @@ -1126,7 +1126,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71970 }
71971 if (hwpoison_filter(p)) {
71972 if (TestClearPageHWPoison(p))
71973 - atomic_long_sub(nr_pages, &mce_bad_pages);
71974 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71975 unlock_page(hpage);
71976 put_page(hpage);
71977 return 0;
71978 @@ -1321,7 +1321,7 @@ int unpoison_memory(unsigned long pfn)
71979 return 0;
71980 }
71981 if (TestClearPageHWPoison(p))
71982 - atomic_long_sub(nr_pages, &mce_bad_pages);
71983 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71984 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
71985 return 0;
71986 }
71987 @@ -1335,7 +1335,7 @@ int unpoison_memory(unsigned long pfn)
71988 */
71989 if (TestClearPageHWPoison(page)) {
71990 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
71991 - atomic_long_sub(nr_pages, &mce_bad_pages);
71992 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71993 freeit = 1;
71994 if (PageHuge(page))
71995 clear_page_hwpoison_huge_page(page);
71996 @@ -1440,7 +1440,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
71997 }
71998 done:
71999 if (!PageHWPoison(hpage))
72000 - atomic_long_add(1 << compound_trans_order(hpage),
72001 + atomic_long_add_unchecked(1 << compound_trans_order(hpage),
72002 &mce_bad_pages);
72003 set_page_hwpoison_huge_page(hpage);
72004 dequeue_hwpoisoned_huge_page(hpage);
72005 @@ -1572,7 +1572,7 @@ int soft_offline_page(struct page *page, int flags)
72006 return ret;
72007
72008 done:
72009 - atomic_long_add(1, &mce_bad_pages);
72010 + atomic_long_add_unchecked(1, &mce_bad_pages);
72011 SetPageHWPoison(page);
72012 /* keep elevated page count for bad page */
72013 return ret;
72014 diff --git a/mm/memory.c b/mm/memory.c
72015 index 5736170..8e04800 100644
72016 --- a/mm/memory.c
72017 +++ b/mm/memory.c
72018 @@ -426,6 +426,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
72019 free_pte_range(tlb, pmd, addr);
72020 } while (pmd++, addr = next, addr != end);
72021
72022 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
72023 start &= PUD_MASK;
72024 if (start < floor)
72025 return;
72026 @@ -440,6 +441,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
72027 pmd = pmd_offset(pud, start);
72028 pud_clear(pud);
72029 pmd_free_tlb(tlb, pmd, start);
72030 +#endif
72031 +
72032 }
72033
72034 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
72035 @@ -459,6 +462,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
72036 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
72037 } while (pud++, addr = next, addr != end);
72038
72039 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
72040 start &= PGDIR_MASK;
72041 if (start < floor)
72042 return;
72043 @@ -473,6 +477,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
72044 pud = pud_offset(pgd, start);
72045 pgd_clear(pgd);
72046 pud_free_tlb(tlb, pud, start);
72047 +#endif
72048 +
72049 }
72050
72051 /*
72052 @@ -1614,12 +1620,6 @@ no_page_table:
72053 return page;
72054 }
72055
72056 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
72057 -{
72058 - return stack_guard_page_start(vma, addr) ||
72059 - stack_guard_page_end(vma, addr+PAGE_SIZE);
72060 -}
72061 -
72062 /**
72063 * __get_user_pages() - pin user pages in memory
72064 * @tsk: task_struct of target task
72065 @@ -1692,10 +1692,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
72066 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
72067 i = 0;
72068
72069 - do {
72070 + while (nr_pages) {
72071 struct vm_area_struct *vma;
72072
72073 - vma = find_extend_vma(mm, start);
72074 + vma = find_vma(mm, start);
72075 if (!vma && in_gate_area(mm, start)) {
72076 unsigned long pg = start & PAGE_MASK;
72077 pgd_t *pgd;
72078 @@ -1743,7 +1743,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
72079 goto next_page;
72080 }
72081
72082 - if (!vma ||
72083 + if (!vma || start < vma->vm_start ||
72084 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
72085 !(vm_flags & vma->vm_flags))
72086 return i ? : -EFAULT;
72087 @@ -1770,11 +1770,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
72088 int ret;
72089 unsigned int fault_flags = 0;
72090
72091 - /* For mlock, just skip the stack guard page. */
72092 - if (foll_flags & FOLL_MLOCK) {
72093 - if (stack_guard_page(vma, start))
72094 - goto next_page;
72095 - }
72096 if (foll_flags & FOLL_WRITE)
72097 fault_flags |= FAULT_FLAG_WRITE;
72098 if (nonblocking)
72099 @@ -1848,7 +1843,7 @@ next_page:
72100 start += PAGE_SIZE;
72101 nr_pages--;
72102 } while (nr_pages && start < vma->vm_end);
72103 - } while (nr_pages);
72104 + }
72105 return i;
72106 }
72107 EXPORT_SYMBOL(__get_user_pages);
72108 @@ -2055,6 +2050,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
72109 page_add_file_rmap(page);
72110 set_pte_at(mm, addr, pte, mk_pte(page, prot));
72111
72112 +#ifdef CONFIG_PAX_SEGMEXEC
72113 + pax_mirror_file_pte(vma, addr, page, ptl);
72114 +#endif
72115 +
72116 retval = 0;
72117 pte_unmap_unlock(pte, ptl);
72118 return retval;
72119 @@ -2089,10 +2088,22 @@ out:
72120 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
72121 struct page *page)
72122 {
72123 +
72124 +#ifdef CONFIG_PAX_SEGMEXEC
72125 + struct vm_area_struct *vma_m;
72126 +#endif
72127 +
72128 if (addr < vma->vm_start || addr >= vma->vm_end)
72129 return -EFAULT;
72130 if (!page_count(page))
72131 return -EINVAL;
72132 +
72133 +#ifdef CONFIG_PAX_SEGMEXEC
72134 + vma_m = pax_find_mirror_vma(vma);
72135 + if (vma_m)
72136 + vma_m->vm_flags |= VM_INSERTPAGE;
72137 +#endif
72138 +
72139 vma->vm_flags |= VM_INSERTPAGE;
72140 return insert_page(vma, addr, page, vma->vm_page_prot);
72141 }
72142 @@ -2178,6 +2189,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
72143 unsigned long pfn)
72144 {
72145 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
72146 + BUG_ON(vma->vm_mirror);
72147
72148 if (addr < vma->vm_start || addr >= vma->vm_end)
72149 return -EFAULT;
72150 @@ -2385,7 +2397,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
72151
72152 BUG_ON(pud_huge(*pud));
72153
72154 - pmd = pmd_alloc(mm, pud, addr);
72155 + pmd = (mm == &init_mm) ?
72156 + pmd_alloc_kernel(mm, pud, addr) :
72157 + pmd_alloc(mm, pud, addr);
72158 if (!pmd)
72159 return -ENOMEM;
72160 do {
72161 @@ -2405,7 +2419,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
72162 unsigned long next;
72163 int err;
72164
72165 - pud = pud_alloc(mm, pgd, addr);
72166 + pud = (mm == &init_mm) ?
72167 + pud_alloc_kernel(mm, pgd, addr) :
72168 + pud_alloc(mm, pgd, addr);
72169 if (!pud)
72170 return -ENOMEM;
72171 do {
72172 @@ -2493,6 +2509,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
72173 copy_user_highpage(dst, src, va, vma);
72174 }
72175
72176 +#ifdef CONFIG_PAX_SEGMEXEC
72177 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
72178 +{
72179 + struct mm_struct *mm = vma->vm_mm;
72180 + spinlock_t *ptl;
72181 + pte_t *pte, entry;
72182 +
72183 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
72184 + entry = *pte;
72185 + if (!pte_present(entry)) {
72186 + if (!pte_none(entry)) {
72187 + BUG_ON(pte_file(entry));
72188 + free_swap_and_cache(pte_to_swp_entry(entry));
72189 + pte_clear_not_present_full(mm, address, pte, 0);
72190 + }
72191 + } else {
72192 + struct page *page;
72193 +
72194 + flush_cache_page(vma, address, pte_pfn(entry));
72195 + entry = ptep_clear_flush(vma, address, pte);
72196 + BUG_ON(pte_dirty(entry));
72197 + page = vm_normal_page(vma, address, entry);
72198 + if (page) {
72199 + update_hiwater_rss(mm);
72200 + if (PageAnon(page))
72201 + dec_mm_counter_fast(mm, MM_ANONPAGES);
72202 + else
72203 + dec_mm_counter_fast(mm, MM_FILEPAGES);
72204 + page_remove_rmap(page);
72205 + page_cache_release(page);
72206 + }
72207 + }
72208 + pte_unmap_unlock(pte, ptl);
72209 +}
72210 +
72211 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
72212 + *
72213 + * the ptl of the lower mapped page is held on entry and is not released on exit
72214 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
72215 + */
72216 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
72217 +{
72218 + struct mm_struct *mm = vma->vm_mm;
72219 + unsigned long address_m;
72220 + spinlock_t *ptl_m;
72221 + struct vm_area_struct *vma_m;
72222 + pmd_t *pmd_m;
72223 + pte_t *pte_m, entry_m;
72224 +
72225 + BUG_ON(!page_m || !PageAnon(page_m));
72226 +
72227 + vma_m = pax_find_mirror_vma(vma);
72228 + if (!vma_m)
72229 + return;
72230 +
72231 + BUG_ON(!PageLocked(page_m));
72232 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72233 + address_m = address + SEGMEXEC_TASK_SIZE;
72234 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72235 + pte_m = pte_offset_map(pmd_m, address_m);
72236 + ptl_m = pte_lockptr(mm, pmd_m);
72237 + if (ptl != ptl_m) {
72238 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72239 + if (!pte_none(*pte_m))
72240 + goto out;
72241 + }
72242 +
72243 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
72244 + page_cache_get(page_m);
72245 + page_add_anon_rmap(page_m, vma_m, address_m);
72246 + inc_mm_counter_fast(mm, MM_ANONPAGES);
72247 + set_pte_at(mm, address_m, pte_m, entry_m);
72248 + update_mmu_cache(vma_m, address_m, entry_m);
72249 +out:
72250 + if (ptl != ptl_m)
72251 + spin_unlock(ptl_m);
72252 + pte_unmap(pte_m);
72253 + unlock_page(page_m);
72254 +}
72255 +
72256 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
72257 +{
72258 + struct mm_struct *mm = vma->vm_mm;
72259 + unsigned long address_m;
72260 + spinlock_t *ptl_m;
72261 + struct vm_area_struct *vma_m;
72262 + pmd_t *pmd_m;
72263 + pte_t *pte_m, entry_m;
72264 +
72265 + BUG_ON(!page_m || PageAnon(page_m));
72266 +
72267 + vma_m = pax_find_mirror_vma(vma);
72268 + if (!vma_m)
72269 + return;
72270 +
72271 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72272 + address_m = address + SEGMEXEC_TASK_SIZE;
72273 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72274 + pte_m = pte_offset_map(pmd_m, address_m);
72275 + ptl_m = pte_lockptr(mm, pmd_m);
72276 + if (ptl != ptl_m) {
72277 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72278 + if (!pte_none(*pte_m))
72279 + goto out;
72280 + }
72281 +
72282 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
72283 + page_cache_get(page_m);
72284 + page_add_file_rmap(page_m);
72285 + inc_mm_counter_fast(mm, MM_FILEPAGES);
72286 + set_pte_at(mm, address_m, pte_m, entry_m);
72287 + update_mmu_cache(vma_m, address_m, entry_m);
72288 +out:
72289 + if (ptl != ptl_m)
72290 + spin_unlock(ptl_m);
72291 + pte_unmap(pte_m);
72292 +}
72293 +
72294 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
72295 +{
72296 + struct mm_struct *mm = vma->vm_mm;
72297 + unsigned long address_m;
72298 + spinlock_t *ptl_m;
72299 + struct vm_area_struct *vma_m;
72300 + pmd_t *pmd_m;
72301 + pte_t *pte_m, entry_m;
72302 +
72303 + vma_m = pax_find_mirror_vma(vma);
72304 + if (!vma_m)
72305 + return;
72306 +
72307 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72308 + address_m = address + SEGMEXEC_TASK_SIZE;
72309 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72310 + pte_m = pte_offset_map(pmd_m, address_m);
72311 + ptl_m = pte_lockptr(mm, pmd_m);
72312 + if (ptl != ptl_m) {
72313 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72314 + if (!pte_none(*pte_m))
72315 + goto out;
72316 + }
72317 +
72318 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
72319 + set_pte_at(mm, address_m, pte_m, entry_m);
72320 +out:
72321 + if (ptl != ptl_m)
72322 + spin_unlock(ptl_m);
72323 + pte_unmap(pte_m);
72324 +}
72325 +
72326 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
72327 +{
72328 + struct page *page_m;
72329 + pte_t entry;
72330 +
72331 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
72332 + goto out;
72333 +
72334 + entry = *pte;
72335 + page_m = vm_normal_page(vma, address, entry);
72336 + if (!page_m)
72337 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
72338 + else if (PageAnon(page_m)) {
72339 + if (pax_find_mirror_vma(vma)) {
72340 + pte_unmap_unlock(pte, ptl);
72341 + lock_page(page_m);
72342 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
72343 + if (pte_same(entry, *pte))
72344 + pax_mirror_anon_pte(vma, address, page_m, ptl);
72345 + else
72346 + unlock_page(page_m);
72347 + }
72348 + } else
72349 + pax_mirror_file_pte(vma, address, page_m, ptl);
72350 +
72351 +out:
72352 + pte_unmap_unlock(pte, ptl);
72353 +}
72354 +#endif
72355 +
72356 /*
72357 * This routine handles present pages, when users try to write
72358 * to a shared page. It is done by copying the page to a new address
72359 @@ -2703,6 +2899,12 @@ gotten:
72360 */
72361 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72362 if (likely(pte_same(*page_table, orig_pte))) {
72363 +
72364 +#ifdef CONFIG_PAX_SEGMEXEC
72365 + if (pax_find_mirror_vma(vma))
72366 + BUG_ON(!trylock_page(new_page));
72367 +#endif
72368 +
72369 if (old_page) {
72370 if (!PageAnon(old_page)) {
72371 dec_mm_counter_fast(mm, MM_FILEPAGES);
72372 @@ -2754,6 +2956,10 @@ gotten:
72373 page_remove_rmap(old_page);
72374 }
72375
72376 +#ifdef CONFIG_PAX_SEGMEXEC
72377 + pax_mirror_anon_pte(vma, address, new_page, ptl);
72378 +#endif
72379 +
72380 /* Free the old page.. */
72381 new_page = old_page;
72382 ret |= VM_FAULT_WRITE;
72383 @@ -3033,6 +3239,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72384 swap_free(entry);
72385 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
72386 try_to_free_swap(page);
72387 +
72388 +#ifdef CONFIG_PAX_SEGMEXEC
72389 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
72390 +#endif
72391 +
72392 unlock_page(page);
72393 if (swapcache) {
72394 /*
72395 @@ -3056,6 +3267,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72396
72397 /* No need to invalidate - it was non-present before */
72398 update_mmu_cache(vma, address, page_table);
72399 +
72400 +#ifdef CONFIG_PAX_SEGMEXEC
72401 + pax_mirror_anon_pte(vma, address, page, ptl);
72402 +#endif
72403 +
72404 unlock:
72405 pte_unmap_unlock(page_table, ptl);
72406 out:
72407 @@ -3075,40 +3291,6 @@ out_release:
72408 }
72409
72410 /*
72411 - * This is like a special single-page "expand_{down|up}wards()",
72412 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
72413 - * doesn't hit another vma.
72414 - */
72415 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
72416 -{
72417 - address &= PAGE_MASK;
72418 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
72419 - struct vm_area_struct *prev = vma->vm_prev;
72420 -
72421 - /*
72422 - * Is there a mapping abutting this one below?
72423 - *
72424 - * That's only ok if it's the same stack mapping
72425 - * that has gotten split..
72426 - */
72427 - if (prev && prev->vm_end == address)
72428 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
72429 -
72430 - expand_downwards(vma, address - PAGE_SIZE);
72431 - }
72432 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
72433 - struct vm_area_struct *next = vma->vm_next;
72434 -
72435 - /* As VM_GROWSDOWN but s/below/above/ */
72436 - if (next && next->vm_start == address + PAGE_SIZE)
72437 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
72438 -
72439 - expand_upwards(vma, address + PAGE_SIZE);
72440 - }
72441 - return 0;
72442 -}
72443 -
72444 -/*
72445 * We enter with non-exclusive mmap_sem (to exclude vma changes,
72446 * but allow concurrent faults), and pte mapped but not yet locked.
72447 * We return with mmap_sem still held, but pte unmapped and unlocked.
72448 @@ -3117,27 +3299,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
72449 unsigned long address, pte_t *page_table, pmd_t *pmd,
72450 unsigned int flags)
72451 {
72452 - struct page *page;
72453 + struct page *page = NULL;
72454 spinlock_t *ptl;
72455 pte_t entry;
72456
72457 - pte_unmap(page_table);
72458 -
72459 - /* Check if we need to add a guard page to the stack */
72460 - if (check_stack_guard_page(vma, address) < 0)
72461 - return VM_FAULT_SIGBUS;
72462 -
72463 - /* Use the zero-page for reads */
72464 if (!(flags & FAULT_FLAG_WRITE)) {
72465 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
72466 vma->vm_page_prot));
72467 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72468 + ptl = pte_lockptr(mm, pmd);
72469 + spin_lock(ptl);
72470 if (!pte_none(*page_table))
72471 goto unlock;
72472 goto setpte;
72473 }
72474
72475 /* Allocate our own private page. */
72476 + pte_unmap(page_table);
72477 +
72478 if (unlikely(anon_vma_prepare(vma)))
72479 goto oom;
72480 page = alloc_zeroed_user_highpage_movable(vma, address);
72481 @@ -3156,6 +3334,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
72482 if (!pte_none(*page_table))
72483 goto release;
72484
72485 +#ifdef CONFIG_PAX_SEGMEXEC
72486 + if (pax_find_mirror_vma(vma))
72487 + BUG_ON(!trylock_page(page));
72488 +#endif
72489 +
72490 inc_mm_counter_fast(mm, MM_ANONPAGES);
72491 page_add_new_anon_rmap(page, vma, address);
72492 setpte:
72493 @@ -3163,6 +3346,12 @@ setpte:
72494
72495 /* No need to invalidate - it was non-present before */
72496 update_mmu_cache(vma, address, page_table);
72497 +
72498 +#ifdef CONFIG_PAX_SEGMEXEC
72499 + if (page)
72500 + pax_mirror_anon_pte(vma, address, page, ptl);
72501 +#endif
72502 +
72503 unlock:
72504 pte_unmap_unlock(page_table, ptl);
72505 return 0;
72506 @@ -3306,6 +3495,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72507 */
72508 /* Only go through if we didn't race with anybody else... */
72509 if (likely(pte_same(*page_table, orig_pte))) {
72510 +
72511 +#ifdef CONFIG_PAX_SEGMEXEC
72512 + if (anon && pax_find_mirror_vma(vma))
72513 + BUG_ON(!trylock_page(page));
72514 +#endif
72515 +
72516 flush_icache_page(vma, page);
72517 entry = mk_pte(page, vma->vm_page_prot);
72518 if (flags & FAULT_FLAG_WRITE)
72519 @@ -3325,6 +3520,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72520
72521 /* no need to invalidate: a not-present page won't be cached */
72522 update_mmu_cache(vma, address, page_table);
72523 +
72524 +#ifdef CONFIG_PAX_SEGMEXEC
72525 + if (anon)
72526 + pax_mirror_anon_pte(vma, address, page, ptl);
72527 + else
72528 + pax_mirror_file_pte(vma, address, page, ptl);
72529 +#endif
72530 +
72531 } else {
72532 if (cow_page)
72533 mem_cgroup_uncharge_page(cow_page);
72534 @@ -3479,6 +3682,12 @@ int handle_pte_fault(struct mm_struct *mm,
72535 if (flags & FAULT_FLAG_WRITE)
72536 flush_tlb_fix_spurious_fault(vma, address);
72537 }
72538 +
72539 +#ifdef CONFIG_PAX_SEGMEXEC
72540 + pax_mirror_pte(vma, address, pte, pmd, ptl);
72541 + return 0;
72542 +#endif
72543 +
72544 unlock:
72545 pte_unmap_unlock(pte, ptl);
72546 return 0;
72547 @@ -3495,6 +3704,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72548 pmd_t *pmd;
72549 pte_t *pte;
72550
72551 +#ifdef CONFIG_PAX_SEGMEXEC
72552 + struct vm_area_struct *vma_m;
72553 +#endif
72554 +
72555 __set_current_state(TASK_RUNNING);
72556
72557 count_vm_event(PGFAULT);
72558 @@ -3506,6 +3719,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72559 if (unlikely(is_vm_hugetlb_page(vma)))
72560 return hugetlb_fault(mm, vma, address, flags);
72561
72562 +#ifdef CONFIG_PAX_SEGMEXEC
72563 + vma_m = pax_find_mirror_vma(vma);
72564 + if (vma_m) {
72565 + unsigned long address_m;
72566 + pgd_t *pgd_m;
72567 + pud_t *pud_m;
72568 + pmd_t *pmd_m;
72569 +
72570 + if (vma->vm_start > vma_m->vm_start) {
72571 + address_m = address;
72572 + address -= SEGMEXEC_TASK_SIZE;
72573 + vma = vma_m;
72574 + } else
72575 + address_m = address + SEGMEXEC_TASK_SIZE;
72576 +
72577 + pgd_m = pgd_offset(mm, address_m);
72578 + pud_m = pud_alloc(mm, pgd_m, address_m);
72579 + if (!pud_m)
72580 + return VM_FAULT_OOM;
72581 + pmd_m = pmd_alloc(mm, pud_m, address_m);
72582 + if (!pmd_m)
72583 + return VM_FAULT_OOM;
72584 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
72585 + return VM_FAULT_OOM;
72586 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
72587 + }
72588 +#endif
72589 +
72590 retry:
72591 pgd = pgd_offset(mm, address);
72592 pud = pud_alloc(mm, pgd, address);
72593 @@ -3547,7 +3788,7 @@ retry:
72594 * run pte_offset_map on the pmd, if an huge pmd could
72595 * materialize from under us from a different thread.
72596 */
72597 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
72598 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
72599 return VM_FAULT_OOM;
72600 /* if an huge pmd materialized from under us just retry later */
72601 if (unlikely(pmd_trans_huge(*pmd)))
72602 @@ -3584,6 +3825,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
72603 spin_unlock(&mm->page_table_lock);
72604 return 0;
72605 }
72606 +
72607 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
72608 +{
72609 + pud_t *new = pud_alloc_one(mm, address);
72610 + if (!new)
72611 + return -ENOMEM;
72612 +
72613 + smp_wmb(); /* See comment in __pte_alloc */
72614 +
72615 + spin_lock(&mm->page_table_lock);
72616 + if (pgd_present(*pgd)) /* Another has populated it */
72617 + pud_free(mm, new);
72618 + else
72619 + pgd_populate_kernel(mm, pgd, new);
72620 + spin_unlock(&mm->page_table_lock);
72621 + return 0;
72622 +}
72623 #endif /* __PAGETABLE_PUD_FOLDED */
72624
72625 #ifndef __PAGETABLE_PMD_FOLDED
72626 @@ -3614,6 +3872,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
72627 spin_unlock(&mm->page_table_lock);
72628 return 0;
72629 }
72630 +
72631 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
72632 +{
72633 + pmd_t *new = pmd_alloc_one(mm, address);
72634 + if (!new)
72635 + return -ENOMEM;
72636 +
72637 + smp_wmb(); /* See comment in __pte_alloc */
72638 +
72639 + spin_lock(&mm->page_table_lock);
72640 +#ifndef __ARCH_HAS_4LEVEL_HACK
72641 + if (pud_present(*pud)) /* Another has populated it */
72642 + pmd_free(mm, new);
72643 + else
72644 + pud_populate_kernel(mm, pud, new);
72645 +#else
72646 + if (pgd_present(*pud)) /* Another has populated it */
72647 + pmd_free(mm, new);
72648 + else
72649 + pgd_populate_kernel(mm, pud, new);
72650 +#endif /* __ARCH_HAS_4LEVEL_HACK */
72651 + spin_unlock(&mm->page_table_lock);
72652 + return 0;
72653 +}
72654 #endif /* __PAGETABLE_PMD_FOLDED */
72655
72656 int make_pages_present(unsigned long addr, unsigned long end)
72657 @@ -3651,7 +3933,7 @@ static int __init gate_vma_init(void)
72658 gate_vma.vm_start = FIXADDR_USER_START;
72659 gate_vma.vm_end = FIXADDR_USER_END;
72660 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
72661 - gate_vma.vm_page_prot = __P101;
72662 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
72663
72664 return 0;
72665 }
72666 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
72667 index 3d64b36..c6ab69c 100644
72668 --- a/mm/mempolicy.c
72669 +++ b/mm/mempolicy.c
72670 @@ -655,6 +655,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
72671 unsigned long vmstart;
72672 unsigned long vmend;
72673
72674 +#ifdef CONFIG_PAX_SEGMEXEC
72675 + struct vm_area_struct *vma_m;
72676 +#endif
72677 +
72678 vma = find_vma(mm, start);
72679 if (!vma || vma->vm_start > start)
72680 return -EFAULT;
72681 @@ -691,9 +695,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
72682 if (err)
72683 goto out;
72684 }
72685 +
72686 err = vma_replace_policy(vma, new_pol);
72687 if (err)
72688 goto out;
72689 +
72690 +#ifdef CONFIG_PAX_SEGMEXEC
72691 + vma_m = pax_find_mirror_vma(vma);
72692 + if (vma_m) {
72693 + err = vma_replace_policy(vma_m, new_pol);
72694 + if (err)
72695 + goto out;
72696 + }
72697 +#endif
72698 +
72699 }
72700
72701 out:
72702 @@ -1147,6 +1162,17 @@ static long do_mbind(unsigned long start, unsigned long len,
72703
72704 if (end < start)
72705 return -EINVAL;
72706 +
72707 +#ifdef CONFIG_PAX_SEGMEXEC
72708 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
72709 + if (end > SEGMEXEC_TASK_SIZE)
72710 + return -EINVAL;
72711 + } else
72712 +#endif
72713 +
72714 + if (end > TASK_SIZE)
72715 + return -EINVAL;
72716 +
72717 if (end == start)
72718 return 0;
72719
72720 @@ -1370,8 +1396,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
72721 */
72722 tcred = __task_cred(task);
72723 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
72724 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
72725 - !capable(CAP_SYS_NICE)) {
72726 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
72727 rcu_read_unlock();
72728 err = -EPERM;
72729 goto out_put;
72730 @@ -1402,6 +1427,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
72731 goto out;
72732 }
72733
72734 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
72735 + if (mm != current->mm &&
72736 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
72737 + mmput(mm);
72738 + err = -EPERM;
72739 + goto out;
72740 + }
72741 +#endif
72742 +
72743 err = do_migrate_pages(mm, old, new,
72744 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
72745
72746 diff --git a/mm/migrate.c b/mm/migrate.c
72747 index 77ed2d7..317d528 100644
72748 --- a/mm/migrate.c
72749 +++ b/mm/migrate.c
72750 @@ -1350,8 +1350,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
72751 */
72752 tcred = __task_cred(task);
72753 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
72754 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
72755 - !capable(CAP_SYS_NICE)) {
72756 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
72757 rcu_read_unlock();
72758 err = -EPERM;
72759 goto out;
72760 diff --git a/mm/mlock.c b/mm/mlock.c
72761 index ef726e8..cd7f1ec 100644
72762 --- a/mm/mlock.c
72763 +++ b/mm/mlock.c
72764 @@ -13,6 +13,7 @@
72765 #include <linux/pagemap.h>
72766 #include <linux/mempolicy.h>
72767 #include <linux/syscalls.h>
72768 +#include <linux/security.h>
72769 #include <linux/sched.h>
72770 #include <linux/export.h>
72771 #include <linux/rmap.h>
72772 @@ -376,7 +377,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
72773 {
72774 unsigned long nstart, end, tmp;
72775 struct vm_area_struct * vma, * prev;
72776 - int error;
72777 + int error = 0;
72778
72779 VM_BUG_ON(start & ~PAGE_MASK);
72780 VM_BUG_ON(len != PAGE_ALIGN(len));
72781 @@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
72782 return -EINVAL;
72783 if (end == start)
72784 return 0;
72785 + if (end > TASK_SIZE)
72786 + return -EINVAL;
72787 +
72788 vma = find_vma(current->mm, start);
72789 if (!vma || vma->vm_start > start)
72790 return -ENOMEM;
72791 @@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
72792 for (nstart = start ; ; ) {
72793 vm_flags_t newflags;
72794
72795 +#ifdef CONFIG_PAX_SEGMEXEC
72796 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72797 + break;
72798 +#endif
72799 +
72800 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
72801
72802 newflags = vma->vm_flags | VM_LOCKED;
72803 @@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
72804 lock_limit >>= PAGE_SHIFT;
72805
72806 /* check against resource limits */
72807 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
72808 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
72809 error = do_mlock(start, len, 1);
72810 up_write(&current->mm->mmap_sem);
72811 @@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
72812 static int do_mlockall(int flags)
72813 {
72814 struct vm_area_struct * vma, * prev = NULL;
72815 - unsigned int def_flags = 0;
72816
72817 if (flags & MCL_FUTURE)
72818 - def_flags = VM_LOCKED;
72819 - current->mm->def_flags = def_flags;
72820 + current->mm->def_flags |= VM_LOCKED;
72821 + else
72822 + current->mm->def_flags &= ~VM_LOCKED;
72823 if (flags == MCL_FUTURE)
72824 goto out;
72825
72826 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
72827 vm_flags_t newflags;
72828
72829 +#ifdef CONFIG_PAX_SEGMEXEC
72830 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72831 + break;
72832 +#endif
72833 +
72834 + BUG_ON(vma->vm_end > TASK_SIZE);
72835 newflags = vma->vm_flags | VM_LOCKED;
72836 if (!(flags & MCL_CURRENT))
72837 newflags &= ~VM_LOCKED;
72838 @@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
72839 lock_limit >>= PAGE_SHIFT;
72840
72841 ret = -ENOMEM;
72842 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
72843 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
72844 capable(CAP_IPC_LOCK))
72845 ret = do_mlockall(flags);
72846 diff --git a/mm/mmap.c b/mm/mmap.c
72847 index ae18a48..86cf99e 100644
72848 --- a/mm/mmap.c
72849 +++ b/mm/mmap.c
72850 @@ -47,6 +47,16 @@
72851 #define arch_rebalance_pgtables(addr, len) (addr)
72852 #endif
72853
72854 +static inline void verify_mm_writelocked(struct mm_struct *mm)
72855 +{
72856 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
72857 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
72858 + up_read(&mm->mmap_sem);
72859 + BUG();
72860 + }
72861 +#endif
72862 +}
72863 +
72864 static void unmap_region(struct mm_struct *mm,
72865 struct vm_area_struct *vma, struct vm_area_struct *prev,
72866 unsigned long start, unsigned long end);
72867 @@ -72,22 +82,32 @@ static void unmap_region(struct mm_struct *mm,
72868 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
72869 *
72870 */
72871 -pgprot_t protection_map[16] = {
72872 +pgprot_t protection_map[16] __read_only = {
72873 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
72874 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
72875 };
72876
72877 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
72878 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
72879 {
72880 - return __pgprot(pgprot_val(protection_map[vm_flags &
72881 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
72882 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
72883 pgprot_val(arch_vm_get_page_prot(vm_flags)));
72884 +
72885 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72886 + if (!(__supported_pte_mask & _PAGE_NX) &&
72887 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
72888 + (vm_flags & (VM_READ | VM_WRITE)))
72889 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
72890 +#endif
72891 +
72892 + return prot;
72893 }
72894 EXPORT_SYMBOL(vm_get_page_prot);
72895
72896 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
72897 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
72898 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
72899 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
72900 /*
72901 * Make sure vm_committed_as in one cacheline and not cacheline shared with
72902 * other variables. It can be updated by several CPUs frequently.
72903 @@ -229,6 +249,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
72904 struct vm_area_struct *next = vma->vm_next;
72905
72906 might_sleep();
72907 + BUG_ON(vma->vm_mirror);
72908 if (vma->vm_ops && vma->vm_ops->close)
72909 vma->vm_ops->close(vma);
72910 if (vma->vm_file) {
72911 @@ -275,6 +296,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
72912 * not page aligned -Ram Gupta
72913 */
72914 rlim = rlimit(RLIMIT_DATA);
72915 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
72916 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
72917 (mm->end_data - mm->start_data) > rlim)
72918 goto out;
72919 @@ -708,6 +730,12 @@ static int
72920 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
72921 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72922 {
72923 +
72924 +#ifdef CONFIG_PAX_SEGMEXEC
72925 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
72926 + return 0;
72927 +#endif
72928 +
72929 if (is_mergeable_vma(vma, file, vm_flags) &&
72930 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
72931 if (vma->vm_pgoff == vm_pgoff)
72932 @@ -727,6 +755,12 @@ static int
72933 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
72934 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72935 {
72936 +
72937 +#ifdef CONFIG_PAX_SEGMEXEC
72938 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
72939 + return 0;
72940 +#endif
72941 +
72942 if (is_mergeable_vma(vma, file, vm_flags) &&
72943 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
72944 pgoff_t vm_pglen;
72945 @@ -769,13 +803,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
72946 struct vm_area_struct *vma_merge(struct mm_struct *mm,
72947 struct vm_area_struct *prev, unsigned long addr,
72948 unsigned long end, unsigned long vm_flags,
72949 - struct anon_vma *anon_vma, struct file *file,
72950 + struct anon_vma *anon_vma, struct file *file,
72951 pgoff_t pgoff, struct mempolicy *policy)
72952 {
72953 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
72954 struct vm_area_struct *area, *next;
72955 int err;
72956
72957 +#ifdef CONFIG_PAX_SEGMEXEC
72958 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
72959 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
72960 +
72961 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
72962 +#endif
72963 +
72964 /*
72965 * We later require that vma->vm_flags == vm_flags,
72966 * so this tests vma->vm_flags & VM_SPECIAL, too.
72967 @@ -791,6 +832,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72968 if (next && next->vm_end == end) /* cases 6, 7, 8 */
72969 next = next->vm_next;
72970
72971 +#ifdef CONFIG_PAX_SEGMEXEC
72972 + if (prev)
72973 + prev_m = pax_find_mirror_vma(prev);
72974 + if (area)
72975 + area_m = pax_find_mirror_vma(area);
72976 + if (next)
72977 + next_m = pax_find_mirror_vma(next);
72978 +#endif
72979 +
72980 /*
72981 * Can it merge with the predecessor?
72982 */
72983 @@ -810,9 +860,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72984 /* cases 1, 6 */
72985 err = vma_adjust(prev, prev->vm_start,
72986 next->vm_end, prev->vm_pgoff, NULL);
72987 - } else /* cases 2, 5, 7 */
72988 +
72989 +#ifdef CONFIG_PAX_SEGMEXEC
72990 + if (!err && prev_m)
72991 + err = vma_adjust(prev_m, prev_m->vm_start,
72992 + next_m->vm_end, prev_m->vm_pgoff, NULL);
72993 +#endif
72994 +
72995 + } else { /* cases 2, 5, 7 */
72996 err = vma_adjust(prev, prev->vm_start,
72997 end, prev->vm_pgoff, NULL);
72998 +
72999 +#ifdef CONFIG_PAX_SEGMEXEC
73000 + if (!err && prev_m)
73001 + err = vma_adjust(prev_m, prev_m->vm_start,
73002 + end_m, prev_m->vm_pgoff, NULL);
73003 +#endif
73004 +
73005 + }
73006 if (err)
73007 return NULL;
73008 khugepaged_enter_vma_merge(prev);
73009 @@ -826,12 +891,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
73010 mpol_equal(policy, vma_policy(next)) &&
73011 can_vma_merge_before(next, vm_flags,
73012 anon_vma, file, pgoff+pglen)) {
73013 - if (prev && addr < prev->vm_end) /* case 4 */
73014 + if (prev && addr < prev->vm_end) { /* case 4 */
73015 err = vma_adjust(prev, prev->vm_start,
73016 addr, prev->vm_pgoff, NULL);
73017 - else /* cases 3, 8 */
73018 +
73019 +#ifdef CONFIG_PAX_SEGMEXEC
73020 + if (!err && prev_m)
73021 + err = vma_adjust(prev_m, prev_m->vm_start,
73022 + addr_m, prev_m->vm_pgoff, NULL);
73023 +#endif
73024 +
73025 + } else { /* cases 3, 8 */
73026 err = vma_adjust(area, addr, next->vm_end,
73027 next->vm_pgoff - pglen, NULL);
73028 +
73029 +#ifdef CONFIG_PAX_SEGMEXEC
73030 + if (!err && area_m)
73031 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
73032 + next_m->vm_pgoff - pglen, NULL);
73033 +#endif
73034 +
73035 + }
73036 if (err)
73037 return NULL;
73038 khugepaged_enter_vma_merge(area);
73039 @@ -940,16 +1020,13 @@ none:
73040 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
73041 struct file *file, long pages)
73042 {
73043 - const unsigned long stack_flags
73044 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
73045 -
73046 mm->total_vm += pages;
73047
73048 if (file) {
73049 mm->shared_vm += pages;
73050 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
73051 mm->exec_vm += pages;
73052 - } else if (flags & stack_flags)
73053 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
73054 mm->stack_vm += pages;
73055 if (flags & (VM_RESERVED|VM_IO))
73056 mm->reserved_vm += pages;
73057 @@ -987,7 +1064,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73058 * (the exception is when the underlying filesystem is noexec
73059 * mounted, in which case we dont add PROT_EXEC.)
73060 */
73061 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
73062 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
73063 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
73064 prot |= PROT_EXEC;
73065
73066 @@ -1013,7 +1090,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73067 /* Obtain the address to map to. we verify (or select) it and ensure
73068 * that it represents a valid section of the address space.
73069 */
73070 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
73071 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
73072 if (addr & ~PAGE_MASK)
73073 return addr;
73074
73075 @@ -1024,6 +1101,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73076 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
73077 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
73078
73079 +#ifdef CONFIG_PAX_MPROTECT
73080 + if (mm->pax_flags & MF_PAX_MPROTECT) {
73081 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
73082 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
73083 + gr_log_rwxmmap(file);
73084 +
73085 +#ifdef CONFIG_PAX_EMUPLT
73086 + vm_flags &= ~VM_EXEC;
73087 +#else
73088 + return -EPERM;
73089 +#endif
73090 +
73091 + }
73092 +
73093 + if (!(vm_flags & VM_EXEC))
73094 + vm_flags &= ~VM_MAYEXEC;
73095 +#else
73096 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
73097 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
73098 +#endif
73099 + else
73100 + vm_flags &= ~VM_MAYWRITE;
73101 + }
73102 +#endif
73103 +
73104 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
73105 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
73106 + vm_flags &= ~VM_PAGEEXEC;
73107 +#endif
73108 +
73109 if (flags & MAP_LOCKED)
73110 if (!can_do_mlock())
73111 return -EPERM;
73112 @@ -1035,6 +1142,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73113 locked += mm->locked_vm;
73114 lock_limit = rlimit(RLIMIT_MEMLOCK);
73115 lock_limit >>= PAGE_SHIFT;
73116 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
73117 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
73118 return -EAGAIN;
73119 }
73120 @@ -1101,6 +1209,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73121 }
73122 }
73123
73124 + if (!gr_acl_handle_mmap(file, prot))
73125 + return -EACCES;
73126 +
73127 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
73128 }
73129
73130 @@ -1177,7 +1288,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
73131 vm_flags_t vm_flags = vma->vm_flags;
73132
73133 /* If it was private or non-writable, the write bit is already clear */
73134 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
73135 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
73136 return 0;
73137
73138 /* The backer wishes to know when pages are first written to? */
73139 @@ -1226,14 +1337,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
73140 unsigned long charged = 0;
73141 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
73142
73143 +#ifdef CONFIG_PAX_SEGMEXEC
73144 + struct vm_area_struct *vma_m = NULL;
73145 +#endif
73146 +
73147 + /*
73148 + * mm->mmap_sem is required to protect against another thread
73149 + * changing the mappings in case we sleep.
73150 + */
73151 + verify_mm_writelocked(mm);
73152 +
73153 /* Clear old maps */
73154 error = -ENOMEM;
73155 -munmap_back:
73156 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73157 if (vma && vma->vm_start < addr + len) {
73158 if (do_munmap(mm, addr, len))
73159 return -ENOMEM;
73160 - goto munmap_back;
73161 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73162 + BUG_ON(vma && vma->vm_start < addr + len);
73163 }
73164
73165 /* Check against address space limit. */
73166 @@ -1282,6 +1403,16 @@ munmap_back:
73167 goto unacct_error;
73168 }
73169
73170 +#ifdef CONFIG_PAX_SEGMEXEC
73171 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
73172 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73173 + if (!vma_m) {
73174 + error = -ENOMEM;
73175 + goto free_vma;
73176 + }
73177 + }
73178 +#endif
73179 +
73180 vma->vm_mm = mm;
73181 vma->vm_start = addr;
73182 vma->vm_end = addr + len;
73183 @@ -1306,6 +1437,19 @@ munmap_back:
73184 error = file->f_op->mmap(file, vma);
73185 if (error)
73186 goto unmap_and_free_vma;
73187 +
73188 +#ifdef CONFIG_PAX_SEGMEXEC
73189 + if (vma_m && (vm_flags & VM_EXECUTABLE))
73190 + added_exe_file_vma(mm);
73191 +#endif
73192 +
73193 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
73194 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
73195 + vma->vm_flags |= VM_PAGEEXEC;
73196 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
73197 + }
73198 +#endif
73199 +
73200 if (vm_flags & VM_EXECUTABLE)
73201 added_exe_file_vma(mm);
73202
73203 @@ -1343,6 +1487,11 @@ munmap_back:
73204 vma_link(mm, vma, prev, rb_link, rb_parent);
73205 file = vma->vm_file;
73206
73207 +#ifdef CONFIG_PAX_SEGMEXEC
73208 + if (vma_m)
73209 + BUG_ON(pax_mirror_vma(vma_m, vma));
73210 +#endif
73211 +
73212 /* Once vma denies write, undo our temporary denial count */
73213 if (correct_wcount)
73214 atomic_inc(&inode->i_writecount);
73215 @@ -1350,6 +1499,7 @@ out:
73216 perf_event_mmap(vma);
73217
73218 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
73219 + track_exec_limit(mm, addr, addr + len, vm_flags);
73220 if (vm_flags & VM_LOCKED) {
73221 if (!mlock_vma_pages_range(vma, addr, addr + len))
73222 mm->locked_vm += (len >> PAGE_SHIFT);
73223 @@ -1371,6 +1521,12 @@ unmap_and_free_vma:
73224 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
73225 charged = 0;
73226 free_vma:
73227 +
73228 +#ifdef CONFIG_PAX_SEGMEXEC
73229 + if (vma_m)
73230 + kmem_cache_free(vm_area_cachep, vma_m);
73231 +#endif
73232 +
73233 kmem_cache_free(vm_area_cachep, vma);
73234 unacct_error:
73235 if (charged)
73236 @@ -1378,6 +1534,44 @@ unacct_error:
73237 return error;
73238 }
73239
73240 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
73241 +{
73242 + if (!vma) {
73243 +#ifdef CONFIG_STACK_GROWSUP
73244 + if (addr > sysctl_heap_stack_gap)
73245 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
73246 + else
73247 + vma = find_vma(current->mm, 0);
73248 + if (vma && (vma->vm_flags & VM_GROWSUP))
73249 + return false;
73250 +#endif
73251 + return true;
73252 + }
73253 +
73254 + if (addr + len > vma->vm_start)
73255 + return false;
73256 +
73257 + if (vma->vm_flags & VM_GROWSDOWN)
73258 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
73259 +#ifdef CONFIG_STACK_GROWSUP
73260 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
73261 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
73262 +#endif
73263 +
73264 + return true;
73265 +}
73266 +
73267 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
73268 +{
73269 + if (vma->vm_start < len)
73270 + return -ENOMEM;
73271 + if (!(vma->vm_flags & VM_GROWSDOWN))
73272 + return vma->vm_start - len;
73273 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
73274 + return vma->vm_start - len - sysctl_heap_stack_gap;
73275 + return -ENOMEM;
73276 +}
73277 +
73278 /* Get an address range which is currently unmapped.
73279 * For shmat() with addr=0.
73280 *
73281 @@ -1404,18 +1598,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
73282 if (flags & MAP_FIXED)
73283 return addr;
73284
73285 +#ifdef CONFIG_PAX_RANDMMAP
73286 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73287 +#endif
73288 +
73289 if (addr) {
73290 addr = PAGE_ALIGN(addr);
73291 - vma = find_vma(mm, addr);
73292 - if (TASK_SIZE - len >= addr &&
73293 - (!vma || addr + len <= vma->vm_start))
73294 - return addr;
73295 + if (TASK_SIZE - len >= addr) {
73296 + vma = find_vma(mm, addr);
73297 + if (check_heap_stack_gap(vma, addr, len))
73298 + return addr;
73299 + }
73300 }
73301 if (len > mm->cached_hole_size) {
73302 - start_addr = addr = mm->free_area_cache;
73303 + start_addr = addr = mm->free_area_cache;
73304 } else {
73305 - start_addr = addr = TASK_UNMAPPED_BASE;
73306 - mm->cached_hole_size = 0;
73307 + start_addr = addr = mm->mmap_base;
73308 + mm->cached_hole_size = 0;
73309 }
73310
73311 full_search:
73312 @@ -1426,34 +1625,40 @@ full_search:
73313 * Start a new search - just in case we missed
73314 * some holes.
73315 */
73316 - if (start_addr != TASK_UNMAPPED_BASE) {
73317 - addr = TASK_UNMAPPED_BASE;
73318 - start_addr = addr;
73319 + if (start_addr != mm->mmap_base) {
73320 + start_addr = addr = mm->mmap_base;
73321 mm->cached_hole_size = 0;
73322 goto full_search;
73323 }
73324 return -ENOMEM;
73325 }
73326 - if (!vma || addr + len <= vma->vm_start) {
73327 - /*
73328 - * Remember the place where we stopped the search:
73329 - */
73330 - mm->free_area_cache = addr + len;
73331 - return addr;
73332 - }
73333 + if (check_heap_stack_gap(vma, addr, len))
73334 + break;
73335 if (addr + mm->cached_hole_size < vma->vm_start)
73336 mm->cached_hole_size = vma->vm_start - addr;
73337 addr = vma->vm_end;
73338 }
73339 +
73340 + /*
73341 + * Remember the place where we stopped the search:
73342 + */
73343 + mm->free_area_cache = addr + len;
73344 + return addr;
73345 }
73346 #endif
73347
73348 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
73349 {
73350 +
73351 +#ifdef CONFIG_PAX_SEGMEXEC
73352 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73353 + return;
73354 +#endif
73355 +
73356 /*
73357 * Is this a new hole at the lowest possible address?
73358 */
73359 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
73360 + if (addr >= mm->mmap_base && addr < mm->free_area_cache)
73361 mm->free_area_cache = addr;
73362 }
73363
73364 @@ -1469,7 +1674,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73365 {
73366 struct vm_area_struct *vma;
73367 struct mm_struct *mm = current->mm;
73368 - unsigned long addr = addr0, start_addr;
73369 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
73370
73371 /* requested length too big for entire address space */
73372 if (len > TASK_SIZE)
73373 @@ -1478,13 +1683,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73374 if (flags & MAP_FIXED)
73375 return addr;
73376
73377 +#ifdef CONFIG_PAX_RANDMMAP
73378 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73379 +#endif
73380 +
73381 /* requesting a specific address */
73382 if (addr) {
73383 addr = PAGE_ALIGN(addr);
73384 - vma = find_vma(mm, addr);
73385 - if (TASK_SIZE - len >= addr &&
73386 - (!vma || addr + len <= vma->vm_start))
73387 - return addr;
73388 + if (TASK_SIZE - len >= addr) {
73389 + vma = find_vma(mm, addr);
73390 + if (check_heap_stack_gap(vma, addr, len))
73391 + return addr;
73392 + }
73393 }
73394
73395 /* check if free_area_cache is useful for us */
73396 @@ -1508,7 +1718,7 @@ try_again:
73397 * return with success:
73398 */
73399 vma = find_vma(mm, addr);
73400 - if (!vma || addr+len <= vma->vm_start)
73401 + if (check_heap_stack_gap(vma, addr, len))
73402 /* remember the address as a hint for next time */
73403 return (mm->free_area_cache = addr);
73404
73405 @@ -1517,8 +1727,8 @@ try_again:
73406 mm->cached_hole_size = vma->vm_start - addr;
73407
73408 /* try just below the current vma->vm_start */
73409 - addr = vma->vm_start-len;
73410 - } while (len < vma->vm_start);
73411 + addr = skip_heap_stack_gap(vma, len);
73412 + } while (!IS_ERR_VALUE(addr));
73413
73414 fail:
73415 /*
73416 @@ -1541,13 +1751,21 @@ fail:
73417 * can happen with large stack limits and large mmap()
73418 * allocations.
73419 */
73420 + mm->mmap_base = TASK_UNMAPPED_BASE;
73421 +
73422 +#ifdef CONFIG_PAX_RANDMMAP
73423 + if (mm->pax_flags & MF_PAX_RANDMMAP)
73424 + mm->mmap_base += mm->delta_mmap;
73425 +#endif
73426 +
73427 + mm->free_area_cache = mm->mmap_base;
73428 mm->cached_hole_size = ~0UL;
73429 - mm->free_area_cache = TASK_UNMAPPED_BASE;
73430 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
73431 /*
73432 * Restore the topdown base:
73433 */
73434 - mm->free_area_cache = mm->mmap_base;
73435 + mm->mmap_base = base;
73436 + mm->free_area_cache = base;
73437 mm->cached_hole_size = ~0UL;
73438
73439 return addr;
73440 @@ -1556,6 +1774,12 @@ fail:
73441
73442 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73443 {
73444 +
73445 +#ifdef CONFIG_PAX_SEGMEXEC
73446 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73447 + return;
73448 +#endif
73449 +
73450 /*
73451 * Is this a new hole at the highest possible address?
73452 */
73453 @@ -1563,8 +1787,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73454 mm->free_area_cache = addr;
73455
73456 /* dont allow allocations above current base */
73457 - if (mm->free_area_cache > mm->mmap_base)
73458 + if (mm->free_area_cache > mm->mmap_base) {
73459 mm->free_area_cache = mm->mmap_base;
73460 + mm->cached_hole_size = ~0UL;
73461 + }
73462 }
73463
73464 unsigned long
73465 @@ -1663,6 +1889,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
73466 return vma;
73467 }
73468
73469 +#ifdef CONFIG_PAX_SEGMEXEC
73470 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
73471 +{
73472 + struct vm_area_struct *vma_m;
73473 +
73474 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
73475 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
73476 + BUG_ON(vma->vm_mirror);
73477 + return NULL;
73478 + }
73479 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
73480 + vma_m = vma->vm_mirror;
73481 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
73482 + BUG_ON(vma->vm_file != vma_m->vm_file);
73483 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
73484 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
73485 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
73486 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
73487 + return vma_m;
73488 +}
73489 +#endif
73490 +
73491 /*
73492 * Verify that the stack growth is acceptable and
73493 * update accounting. This is shared with both the
73494 @@ -1679,6 +1927,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73495 return -ENOMEM;
73496
73497 /* Stack limit test */
73498 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
73499 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
73500 return -ENOMEM;
73501
73502 @@ -1689,6 +1938,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73503 locked = mm->locked_vm + grow;
73504 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
73505 limit >>= PAGE_SHIFT;
73506 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
73507 if (locked > limit && !capable(CAP_IPC_LOCK))
73508 return -ENOMEM;
73509 }
73510 @@ -1718,37 +1968,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73511 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
73512 * vma is the last one with address > vma->vm_end. Have to extend vma.
73513 */
73514 +#ifndef CONFIG_IA64
73515 +static
73516 +#endif
73517 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
73518 {
73519 int error;
73520 + bool locknext;
73521
73522 if (!(vma->vm_flags & VM_GROWSUP))
73523 return -EFAULT;
73524
73525 + /* Also guard against wrapping around to address 0. */
73526 + if (address < PAGE_ALIGN(address+1))
73527 + address = PAGE_ALIGN(address+1);
73528 + else
73529 + return -ENOMEM;
73530 +
73531 /*
73532 * We must make sure the anon_vma is allocated
73533 * so that the anon_vma locking is not a noop.
73534 */
73535 if (unlikely(anon_vma_prepare(vma)))
73536 return -ENOMEM;
73537 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
73538 + if (locknext && anon_vma_prepare(vma->vm_next))
73539 + return -ENOMEM;
73540 vma_lock_anon_vma(vma);
73541 + if (locknext)
73542 + vma_lock_anon_vma(vma->vm_next);
73543
73544 /*
73545 * vma->vm_start/vm_end cannot change under us because the caller
73546 * is required to hold the mmap_sem in read mode. We need the
73547 - * anon_vma lock to serialize against concurrent expand_stacks.
73548 - * Also guard against wrapping around to address 0.
73549 + * anon_vma locks to serialize against concurrent expand_stacks
73550 + * and expand_upwards.
73551 */
73552 - if (address < PAGE_ALIGN(address+4))
73553 - address = PAGE_ALIGN(address+4);
73554 - else {
73555 - vma_unlock_anon_vma(vma);
73556 - return -ENOMEM;
73557 - }
73558 error = 0;
73559
73560 /* Somebody else might have raced and expanded it already */
73561 - if (address > vma->vm_end) {
73562 + 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)
73563 + error = -ENOMEM;
73564 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
73565 unsigned long size, grow;
73566
73567 size = address - vma->vm_start;
73568 @@ -1763,6 +2024,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
73569 }
73570 }
73571 }
73572 + if (locknext)
73573 + vma_unlock_anon_vma(vma->vm_next);
73574 vma_unlock_anon_vma(vma);
73575 khugepaged_enter_vma_merge(vma);
73576 return error;
73577 @@ -1776,6 +2039,8 @@ int expand_downwards(struct vm_area_struct *vma,
73578 unsigned long address)
73579 {
73580 int error;
73581 + bool lockprev = false;
73582 + struct vm_area_struct *prev;
73583
73584 /*
73585 * We must make sure the anon_vma is allocated
73586 @@ -1789,6 +2054,15 @@ int expand_downwards(struct vm_area_struct *vma,
73587 if (error)
73588 return error;
73589
73590 + prev = vma->vm_prev;
73591 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
73592 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
73593 +#endif
73594 + if (lockprev && anon_vma_prepare(prev))
73595 + return -ENOMEM;
73596 + if (lockprev)
73597 + vma_lock_anon_vma(prev);
73598 +
73599 vma_lock_anon_vma(vma);
73600
73601 /*
73602 @@ -1798,9 +2072,17 @@ int expand_downwards(struct vm_area_struct *vma,
73603 */
73604
73605 /* Somebody else might have raced and expanded it already */
73606 - if (address < vma->vm_start) {
73607 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
73608 + error = -ENOMEM;
73609 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
73610 unsigned long size, grow;
73611
73612 +#ifdef CONFIG_PAX_SEGMEXEC
73613 + struct vm_area_struct *vma_m;
73614 +
73615 + vma_m = pax_find_mirror_vma(vma);
73616 +#endif
73617 +
73618 size = vma->vm_end - address;
73619 grow = (vma->vm_start - address) >> PAGE_SHIFT;
73620
73621 @@ -1810,11 +2092,22 @@ int expand_downwards(struct vm_area_struct *vma,
73622 if (!error) {
73623 vma->vm_start = address;
73624 vma->vm_pgoff -= grow;
73625 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
73626 +
73627 +#ifdef CONFIG_PAX_SEGMEXEC
73628 + if (vma_m) {
73629 + vma_m->vm_start -= grow << PAGE_SHIFT;
73630 + vma_m->vm_pgoff -= grow;
73631 + }
73632 +#endif
73633 +
73634 perf_event_mmap(vma);
73635 }
73636 }
73637 }
73638 vma_unlock_anon_vma(vma);
73639 + if (lockprev)
73640 + vma_unlock_anon_vma(prev);
73641 khugepaged_enter_vma_merge(vma);
73642 return error;
73643 }
73644 @@ -1886,6 +2179,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
73645 do {
73646 long nrpages = vma_pages(vma);
73647
73648 +#ifdef CONFIG_PAX_SEGMEXEC
73649 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
73650 + vma = remove_vma(vma);
73651 + continue;
73652 + }
73653 +#endif
73654 +
73655 if (vma->vm_flags & VM_ACCOUNT)
73656 nr_accounted += nrpages;
73657 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
73658 @@ -1931,6 +2231,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
73659 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
73660 vma->vm_prev = NULL;
73661 do {
73662 +
73663 +#ifdef CONFIG_PAX_SEGMEXEC
73664 + if (vma->vm_mirror) {
73665 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
73666 + vma->vm_mirror->vm_mirror = NULL;
73667 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
73668 + vma->vm_mirror = NULL;
73669 + }
73670 +#endif
73671 +
73672 rb_erase(&vma->vm_rb, &mm->mm_rb);
73673 mm->map_count--;
73674 tail_vma = vma;
73675 @@ -1959,14 +2269,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73676 struct vm_area_struct *new;
73677 int err = -ENOMEM;
73678
73679 +#ifdef CONFIG_PAX_SEGMEXEC
73680 + struct vm_area_struct *vma_m, *new_m = NULL;
73681 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
73682 +#endif
73683 +
73684 if (is_vm_hugetlb_page(vma) && (addr &
73685 ~(huge_page_mask(hstate_vma(vma)))))
73686 return -EINVAL;
73687
73688 +#ifdef CONFIG_PAX_SEGMEXEC
73689 + vma_m = pax_find_mirror_vma(vma);
73690 +#endif
73691 +
73692 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73693 if (!new)
73694 goto out_err;
73695
73696 +#ifdef CONFIG_PAX_SEGMEXEC
73697 + if (vma_m) {
73698 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73699 + if (!new_m) {
73700 + kmem_cache_free(vm_area_cachep, new);
73701 + goto out_err;
73702 + }
73703 + }
73704 +#endif
73705 +
73706 /* most fields are the same, copy all, and then fixup */
73707 *new = *vma;
73708
73709 @@ -1979,6 +2308,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73710 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
73711 }
73712
73713 +#ifdef CONFIG_PAX_SEGMEXEC
73714 + if (vma_m) {
73715 + *new_m = *vma_m;
73716 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
73717 + new_m->vm_mirror = new;
73718 + new->vm_mirror = new_m;
73719 +
73720 + if (new_below)
73721 + new_m->vm_end = addr_m;
73722 + else {
73723 + new_m->vm_start = addr_m;
73724 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
73725 + }
73726 + }
73727 +#endif
73728 +
73729 pol = mpol_dup(vma_policy(vma));
73730 if (IS_ERR(pol)) {
73731 err = PTR_ERR(pol);
73732 @@ -2004,6 +2349,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73733 else
73734 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
73735
73736 +#ifdef CONFIG_PAX_SEGMEXEC
73737 + if (!err && vma_m) {
73738 + if (anon_vma_clone(new_m, vma_m))
73739 + goto out_free_mpol;
73740 +
73741 + mpol_get(pol);
73742 + vma_set_policy(new_m, pol);
73743 +
73744 + if (new_m->vm_file) {
73745 + get_file(new_m->vm_file);
73746 + if (vma_m->vm_flags & VM_EXECUTABLE)
73747 + added_exe_file_vma(mm);
73748 + }
73749 +
73750 + if (new_m->vm_ops && new_m->vm_ops->open)
73751 + new_m->vm_ops->open(new_m);
73752 +
73753 + if (new_below)
73754 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
73755 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
73756 + else
73757 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
73758 +
73759 + if (err) {
73760 + if (new_m->vm_ops && new_m->vm_ops->close)
73761 + new_m->vm_ops->close(new_m);
73762 + if (new_m->vm_file) {
73763 + if (vma_m->vm_flags & VM_EXECUTABLE)
73764 + removed_exe_file_vma(mm);
73765 + fput(new_m->vm_file);
73766 + }
73767 + mpol_put(pol);
73768 + }
73769 + }
73770 +#endif
73771 +
73772 /* Success. */
73773 if (!err)
73774 return 0;
73775 @@ -2016,10 +2397,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73776 removed_exe_file_vma(mm);
73777 fput(new->vm_file);
73778 }
73779 - unlink_anon_vmas(new);
73780 out_free_mpol:
73781 mpol_put(pol);
73782 out_free_vma:
73783 +
73784 +#ifdef CONFIG_PAX_SEGMEXEC
73785 + if (new_m) {
73786 + unlink_anon_vmas(new_m);
73787 + kmem_cache_free(vm_area_cachep, new_m);
73788 + }
73789 +#endif
73790 +
73791 + unlink_anon_vmas(new);
73792 kmem_cache_free(vm_area_cachep, new);
73793 out_err:
73794 return err;
73795 @@ -2032,6 +2421,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73796 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73797 unsigned long addr, int new_below)
73798 {
73799 +
73800 +#ifdef CONFIG_PAX_SEGMEXEC
73801 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
73802 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
73803 + if (mm->map_count >= sysctl_max_map_count-1)
73804 + return -ENOMEM;
73805 + } else
73806 +#endif
73807 +
73808 if (mm->map_count >= sysctl_max_map_count)
73809 return -ENOMEM;
73810
73811 @@ -2043,11 +2441,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73812 * work. This now handles partial unmappings.
73813 * Jeremy Fitzhardinge <jeremy@goop.org>
73814 */
73815 +#ifdef CONFIG_PAX_SEGMEXEC
73816 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73817 {
73818 + int ret = __do_munmap(mm, start, len);
73819 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
73820 + return ret;
73821 +
73822 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
73823 +}
73824 +
73825 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73826 +#else
73827 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73828 +#endif
73829 +{
73830 unsigned long end;
73831 struct vm_area_struct *vma, *prev, *last;
73832
73833 + /*
73834 + * mm->mmap_sem is required to protect against another thread
73835 + * changing the mappings in case we sleep.
73836 + */
73837 + verify_mm_writelocked(mm);
73838 +
73839 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
73840 return -EINVAL;
73841
73842 @@ -2122,6 +2539,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73843 /* Fix up all other VM information */
73844 remove_vma_list(mm, vma);
73845
73846 + track_exec_limit(mm, start, end, 0UL);
73847 +
73848 return 0;
73849 }
73850
73851 @@ -2130,6 +2549,13 @@ int vm_munmap(unsigned long start, size_t len)
73852 int ret;
73853 struct mm_struct *mm = current->mm;
73854
73855 +
73856 +#ifdef CONFIG_PAX_SEGMEXEC
73857 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
73858 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
73859 + return -EINVAL;
73860 +#endif
73861 +
73862 down_write(&mm->mmap_sem);
73863 ret = do_munmap(mm, start, len);
73864 up_write(&mm->mmap_sem);
73865 @@ -2143,16 +2569,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
73866 return vm_munmap(addr, len);
73867 }
73868
73869 -static inline void verify_mm_writelocked(struct mm_struct *mm)
73870 -{
73871 -#ifdef CONFIG_DEBUG_VM
73872 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
73873 - WARN_ON(1);
73874 - up_read(&mm->mmap_sem);
73875 - }
73876 -#endif
73877 -}
73878 -
73879 /*
73880 * this is really a simplified "do_mmap". it only handles
73881 * anonymous maps. eventually we may be able to do some
73882 @@ -2166,6 +2582,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73883 struct rb_node ** rb_link, * rb_parent;
73884 pgoff_t pgoff = addr >> PAGE_SHIFT;
73885 int error;
73886 + unsigned long charged;
73887
73888 len = PAGE_ALIGN(len);
73889 if (!len)
73890 @@ -2173,16 +2590,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73891
73892 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
73893
73894 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
73895 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
73896 + flags &= ~VM_EXEC;
73897 +
73898 +#ifdef CONFIG_PAX_MPROTECT
73899 + if (mm->pax_flags & MF_PAX_MPROTECT)
73900 + flags &= ~VM_MAYEXEC;
73901 +#endif
73902 +
73903 + }
73904 +#endif
73905 +
73906 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
73907 if (error & ~PAGE_MASK)
73908 return error;
73909
73910 + charged = len >> PAGE_SHIFT;
73911 +
73912 /*
73913 * mlock MCL_FUTURE?
73914 */
73915 if (mm->def_flags & VM_LOCKED) {
73916 unsigned long locked, lock_limit;
73917 - locked = len >> PAGE_SHIFT;
73918 + locked = charged;
73919 locked += mm->locked_vm;
73920 lock_limit = rlimit(RLIMIT_MEMLOCK);
73921 lock_limit >>= PAGE_SHIFT;
73922 @@ -2199,22 +2630,22 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73923 /*
73924 * Clear old maps. this also does some error checking for us
73925 */
73926 - munmap_back:
73927 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73928 if (vma && vma->vm_start < addr + len) {
73929 if (do_munmap(mm, addr, len))
73930 return -ENOMEM;
73931 - goto munmap_back;
73932 - }
73933 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73934 + BUG_ON(vma && vma->vm_start < addr + len);
73935 + }
73936
73937 /* Check against address space limits *after* clearing old maps... */
73938 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
73939 + if (!may_expand_vm(mm, charged))
73940 return -ENOMEM;
73941
73942 if (mm->map_count > sysctl_max_map_count)
73943 return -ENOMEM;
73944
73945 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
73946 + if (security_vm_enough_memory_mm(mm, charged))
73947 return -ENOMEM;
73948
73949 /* Can we just expand an old private anonymous mapping? */
73950 @@ -2228,7 +2659,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73951 */
73952 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73953 if (!vma) {
73954 - vm_unacct_memory(len >> PAGE_SHIFT);
73955 + vm_unacct_memory(charged);
73956 return -ENOMEM;
73957 }
73958
73959 @@ -2242,11 +2673,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73960 vma_link(mm, vma, prev, rb_link, rb_parent);
73961 out:
73962 perf_event_mmap(vma);
73963 - mm->total_vm += len >> PAGE_SHIFT;
73964 + mm->total_vm += charged;
73965 if (flags & VM_LOCKED) {
73966 if (!mlock_vma_pages_range(vma, addr, addr + len))
73967 - mm->locked_vm += (len >> PAGE_SHIFT);
73968 + mm->locked_vm += charged;
73969 }
73970 + track_exec_limit(mm, addr, addr + len, flags);
73971 return addr;
73972 }
73973
73974 @@ -2304,6 +2736,7 @@ void exit_mmap(struct mm_struct *mm)
73975 while (vma) {
73976 if (vma->vm_flags & VM_ACCOUNT)
73977 nr_accounted += vma_pages(vma);
73978 + vma->vm_mirror = NULL;
73979 vma = remove_vma(vma);
73980 }
73981 vm_unacct_memory(nr_accounted);
73982 @@ -2320,6 +2753,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
73983 struct vm_area_struct * __vma, * prev;
73984 struct rb_node ** rb_link, * rb_parent;
73985
73986 +#ifdef CONFIG_PAX_SEGMEXEC
73987 + struct vm_area_struct *vma_m = NULL;
73988 +#endif
73989 +
73990 + if (security_mmap_addr(vma->vm_start))
73991 + return -EPERM;
73992 +
73993 /*
73994 * The vm_pgoff of a purely anonymous vma should be irrelevant
73995 * until its first write fault, when page's anon_vma and index
73996 @@ -2343,7 +2783,21 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
73997 security_vm_enough_memory_mm(mm, vma_pages(vma)))
73998 return -ENOMEM;
73999
74000 +#ifdef CONFIG_PAX_SEGMEXEC
74001 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
74002 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
74003 + if (!vma_m)
74004 + return -ENOMEM;
74005 + }
74006 +#endif
74007 +
74008 vma_link(mm, vma, prev, rb_link, rb_parent);
74009 +
74010 +#ifdef CONFIG_PAX_SEGMEXEC
74011 + if (vma_m)
74012 + BUG_ON(pax_mirror_vma(vma_m, vma));
74013 +#endif
74014 +
74015 return 0;
74016 }
74017
74018 @@ -2362,6 +2816,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
74019 struct mempolicy *pol;
74020 bool faulted_in_anon_vma = true;
74021
74022 + BUG_ON(vma->vm_mirror);
74023 +
74024 /*
74025 * If anonymous vma has not yet been faulted, update new pgoff
74026 * to match new location, to increase its chance of merging.
74027 @@ -2430,6 +2886,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
74028 return NULL;
74029 }
74030
74031 +#ifdef CONFIG_PAX_SEGMEXEC
74032 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
74033 +{
74034 + struct vm_area_struct *prev_m;
74035 + struct rb_node **rb_link_m, *rb_parent_m;
74036 + struct mempolicy *pol_m;
74037 +
74038 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
74039 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
74040 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
74041 + *vma_m = *vma;
74042 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
74043 + if (anon_vma_clone(vma_m, vma))
74044 + return -ENOMEM;
74045 + pol_m = vma_policy(vma_m);
74046 + mpol_get(pol_m);
74047 + vma_set_policy(vma_m, pol_m);
74048 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
74049 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
74050 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
74051 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
74052 + if (vma_m->vm_file)
74053 + get_file(vma_m->vm_file);
74054 + if (vma_m->vm_ops && vma_m->vm_ops->open)
74055 + vma_m->vm_ops->open(vma_m);
74056 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
74057 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
74058 + vma_m->vm_mirror = vma;
74059 + vma->vm_mirror = vma_m;
74060 + return 0;
74061 +}
74062 +#endif
74063 +
74064 /*
74065 * Return true if the calling process may expand its vm space by the passed
74066 * number of pages
74067 @@ -2441,6 +2930,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
74068
74069 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
74070
74071 +#ifdef CONFIG_PAX_RANDMMAP
74072 + if (mm->pax_flags & MF_PAX_RANDMMAP)
74073 + cur -= mm->brk_gap;
74074 +#endif
74075 +
74076 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
74077 if (cur + npages > lim)
74078 return 0;
74079 return 1;
74080 @@ -2511,6 +3006,22 @@ int install_special_mapping(struct mm_struct *mm,
74081 vma->vm_start = addr;
74082 vma->vm_end = addr + len;
74083
74084 +#ifdef CONFIG_PAX_MPROTECT
74085 + if (mm->pax_flags & MF_PAX_MPROTECT) {
74086 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
74087 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
74088 + return -EPERM;
74089 + if (!(vm_flags & VM_EXEC))
74090 + vm_flags &= ~VM_MAYEXEC;
74091 +#else
74092 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
74093 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
74094 +#endif
74095 + else
74096 + vm_flags &= ~VM_MAYWRITE;
74097 + }
74098 +#endif
74099 +
74100 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
74101 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
74102
74103 diff --git a/mm/mprotect.c b/mm/mprotect.c
74104 index a409926..8b32e6d 100644
74105 --- a/mm/mprotect.c
74106 +++ b/mm/mprotect.c
74107 @@ -23,10 +23,17 @@
74108 #include <linux/mmu_notifier.h>
74109 #include <linux/migrate.h>
74110 #include <linux/perf_event.h>
74111 +
74112 +#ifdef CONFIG_PAX_MPROTECT
74113 +#include <linux/elf.h>
74114 +#include <linux/binfmts.h>
74115 +#endif
74116 +
74117 #include <asm/uaccess.h>
74118 #include <asm/pgtable.h>
74119 #include <asm/cacheflush.h>
74120 #include <asm/tlbflush.h>
74121 +#include <asm/mmu_context.h>
74122
74123 #ifndef pgprot_modify
74124 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
74125 @@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
74126 flush_tlb_range(vma, start, end);
74127 }
74128
74129 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
74130 +/* called while holding the mmap semaphor for writing except stack expansion */
74131 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
74132 +{
74133 + unsigned long oldlimit, newlimit = 0UL;
74134 +
74135 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
74136 + return;
74137 +
74138 + spin_lock(&mm->page_table_lock);
74139 + oldlimit = mm->context.user_cs_limit;
74140 + if ((prot & VM_EXEC) && oldlimit < end)
74141 + /* USER_CS limit moved up */
74142 + newlimit = end;
74143 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
74144 + /* USER_CS limit moved down */
74145 + newlimit = start;
74146 +
74147 + if (newlimit) {
74148 + mm->context.user_cs_limit = newlimit;
74149 +
74150 +#ifdef CONFIG_SMP
74151 + wmb();
74152 + cpus_clear(mm->context.cpu_user_cs_mask);
74153 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
74154 +#endif
74155 +
74156 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
74157 + }
74158 + spin_unlock(&mm->page_table_lock);
74159 + if (newlimit == end) {
74160 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
74161 +
74162 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
74163 + if (is_vm_hugetlb_page(vma))
74164 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
74165 + else
74166 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
74167 + }
74168 +}
74169 +#endif
74170 +
74171 int
74172 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74173 unsigned long start, unsigned long end, unsigned long newflags)
74174 @@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74175 int error;
74176 int dirty_accountable = 0;
74177
74178 +#ifdef CONFIG_PAX_SEGMEXEC
74179 + struct vm_area_struct *vma_m = NULL;
74180 + unsigned long start_m, end_m;
74181 +
74182 + start_m = start + SEGMEXEC_TASK_SIZE;
74183 + end_m = end + SEGMEXEC_TASK_SIZE;
74184 +#endif
74185 +
74186 if (newflags == oldflags) {
74187 *pprev = vma;
74188 return 0;
74189 }
74190
74191 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
74192 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
74193 +
74194 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
74195 + return -ENOMEM;
74196 +
74197 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
74198 + return -ENOMEM;
74199 + }
74200 +
74201 /*
74202 * If we make a private mapping writable we increase our commit;
74203 * but (without finer accounting) cannot reduce our commit if we
74204 @@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74205 }
74206 }
74207
74208 +#ifdef CONFIG_PAX_SEGMEXEC
74209 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
74210 + if (start != vma->vm_start) {
74211 + error = split_vma(mm, vma, start, 1);
74212 + if (error)
74213 + goto fail;
74214 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
74215 + *pprev = (*pprev)->vm_next;
74216 + }
74217 +
74218 + if (end != vma->vm_end) {
74219 + error = split_vma(mm, vma, end, 0);
74220 + if (error)
74221 + goto fail;
74222 + }
74223 +
74224 + if (pax_find_mirror_vma(vma)) {
74225 + error = __do_munmap(mm, start_m, end_m - start_m);
74226 + if (error)
74227 + goto fail;
74228 + } else {
74229 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
74230 + if (!vma_m) {
74231 + error = -ENOMEM;
74232 + goto fail;
74233 + }
74234 + vma->vm_flags = newflags;
74235 + error = pax_mirror_vma(vma_m, vma);
74236 + if (error) {
74237 + vma->vm_flags = oldflags;
74238 + goto fail;
74239 + }
74240 + }
74241 + }
74242 +#endif
74243 +
74244 /*
74245 * First try to merge with previous and/or next vma.
74246 */
74247 @@ -204,9 +307,21 @@ success:
74248 * vm_flags and vm_page_prot are protected by the mmap_sem
74249 * held in write mode.
74250 */
74251 +
74252 +#ifdef CONFIG_PAX_SEGMEXEC
74253 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
74254 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
74255 +#endif
74256 +
74257 vma->vm_flags = newflags;
74258 +
74259 +#ifdef CONFIG_PAX_MPROTECT
74260 + if (mm->binfmt && mm->binfmt->handle_mprotect)
74261 + mm->binfmt->handle_mprotect(vma, newflags);
74262 +#endif
74263 +
74264 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
74265 - vm_get_page_prot(newflags));
74266 + vm_get_page_prot(vma->vm_flags));
74267
74268 if (vma_wants_writenotify(vma)) {
74269 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
74270 @@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74271 end = start + len;
74272 if (end <= start)
74273 return -ENOMEM;
74274 +
74275 +#ifdef CONFIG_PAX_SEGMEXEC
74276 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
74277 + if (end > SEGMEXEC_TASK_SIZE)
74278 + return -EINVAL;
74279 + } else
74280 +#endif
74281 +
74282 + if (end > TASK_SIZE)
74283 + return -EINVAL;
74284 +
74285 if (!arch_validate_prot(prot))
74286 return -EINVAL;
74287
74288 @@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74289 /*
74290 * Does the application expect PROT_READ to imply PROT_EXEC:
74291 */
74292 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
74293 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
74294 prot |= PROT_EXEC;
74295
74296 vm_flags = calc_vm_prot_bits(prot);
74297 @@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74298 if (start > vma->vm_start)
74299 prev = vma;
74300
74301 +#ifdef CONFIG_PAX_MPROTECT
74302 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
74303 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
74304 +#endif
74305 +
74306 for (nstart = start ; ; ) {
74307 unsigned long newflags;
74308
74309 @@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74310
74311 /* newflags >> 4 shift VM_MAY% in place of VM_% */
74312 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
74313 + if (prot & (PROT_WRITE | PROT_EXEC))
74314 + gr_log_rwxmprotect(vma->vm_file);
74315 +
74316 + error = -EACCES;
74317 + goto out;
74318 + }
74319 +
74320 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
74321 error = -EACCES;
74322 goto out;
74323 }
74324 @@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74325 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
74326 if (error)
74327 goto out;
74328 +
74329 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
74330 +
74331 nstart = tmp;
74332
74333 if (nstart < prev->vm_end)
74334 diff --git a/mm/mremap.c b/mm/mremap.c
74335 index cc06d0e..40b5d18 100644
74336 --- a/mm/mremap.c
74337 +++ b/mm/mremap.c
74338 @@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
74339 continue;
74340 pte = ptep_get_and_clear(mm, old_addr, old_pte);
74341 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
74342 +
74343 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
74344 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
74345 + pte = pte_exprotect(pte);
74346 +#endif
74347 +
74348 set_pte_at(mm, new_addr, new_pte, pte);
74349 }
74350
74351 @@ -298,6 +304,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
74352 if (is_vm_hugetlb_page(vma))
74353 goto Einval;
74354
74355 +#ifdef CONFIG_PAX_SEGMEXEC
74356 + if (pax_find_mirror_vma(vma))
74357 + goto Einval;
74358 +#endif
74359 +
74360 /* We can't remap across vm area boundaries */
74361 if (old_len > vma->vm_end - addr)
74362 goto Efault;
74363 @@ -354,20 +365,25 @@ static unsigned long mremap_to(unsigned long addr,
74364 unsigned long ret = -EINVAL;
74365 unsigned long charged = 0;
74366 unsigned long map_flags;
74367 + unsigned long pax_task_size = TASK_SIZE;
74368
74369 if (new_addr & ~PAGE_MASK)
74370 goto out;
74371
74372 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
74373 +#ifdef CONFIG_PAX_SEGMEXEC
74374 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
74375 + pax_task_size = SEGMEXEC_TASK_SIZE;
74376 +#endif
74377 +
74378 + pax_task_size -= PAGE_SIZE;
74379 +
74380 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
74381 goto out;
74382
74383 /* Check if the location we're moving into overlaps the
74384 * old location at all, and fail if it does.
74385 */
74386 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
74387 - goto out;
74388 -
74389 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
74390 + if (addr + old_len > new_addr && new_addr + new_len > addr)
74391 goto out;
74392
74393 ret = do_munmap(mm, new_addr, new_len);
74394 @@ -435,6 +451,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74395 struct vm_area_struct *vma;
74396 unsigned long ret = -EINVAL;
74397 unsigned long charged = 0;
74398 + unsigned long pax_task_size = TASK_SIZE;
74399
74400 down_write(&current->mm->mmap_sem);
74401
74402 @@ -455,6 +472,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74403 if (!new_len)
74404 goto out;
74405
74406 +#ifdef CONFIG_PAX_SEGMEXEC
74407 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
74408 + pax_task_size = SEGMEXEC_TASK_SIZE;
74409 +#endif
74410 +
74411 + pax_task_size -= PAGE_SIZE;
74412 +
74413 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
74414 + old_len > pax_task_size || addr > pax_task_size-old_len)
74415 + goto out;
74416 +
74417 if (flags & MREMAP_FIXED) {
74418 if (flags & MREMAP_MAYMOVE)
74419 ret = mremap_to(addr, old_len, new_addr, new_len);
74420 @@ -503,6 +531,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74421 addr + new_len);
74422 }
74423 ret = addr;
74424 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
74425 goto out;
74426 }
74427 }
74428 @@ -526,7 +555,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74429 goto out;
74430 }
74431
74432 + map_flags = vma->vm_flags;
74433 ret = move_vma(vma, addr, old_len, new_len, new_addr);
74434 + if (!(ret & ~PAGE_MASK)) {
74435 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
74436 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
74437 + }
74438 }
74439 out:
74440 if (ret & ~PAGE_MASK)
74441 diff --git a/mm/nommu.c b/mm/nommu.c
74442 index d4b0c10..ed421b5 100644
74443 --- a/mm/nommu.c
74444 +++ b/mm/nommu.c
74445 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
74446 int sysctl_overcommit_ratio = 50; /* default is 50% */
74447 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
74448 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
74449 -int heap_stack_gap = 0;
74450
74451 atomic_long_t mmap_pages_allocated;
74452
74453 @@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
74454 EXPORT_SYMBOL(find_vma);
74455
74456 /*
74457 - * find a VMA
74458 - * - we don't extend stack VMAs under NOMMU conditions
74459 - */
74460 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
74461 -{
74462 - return find_vma(mm, addr);
74463 -}
74464 -
74465 -/*
74466 * expand a stack to a given address
74467 * - not supported under NOMMU conditions
74468 */
74469 @@ -1551,6 +1541,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
74470
74471 /* most fields are the same, copy all, and then fixup */
74472 *new = *vma;
74473 + INIT_LIST_HEAD(&new->anon_vma_chain);
74474 *region = *vma->vm_region;
74475 new->vm_region = region;
74476
74477 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
74478 index c13ea75..081ab2c 100644
74479 --- a/mm/page_alloc.c
74480 +++ b/mm/page_alloc.c
74481 @@ -340,7 +340,7 @@ out:
74482 * This usage means that zero-order pages may not be compound.
74483 */
74484
74485 -static void free_compound_page(struct page *page)
74486 +void free_compound_page(struct page *page)
74487 {
74488 __free_pages_ok(page, compound_order(page));
74489 }
74490 @@ -697,6 +697,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
74491 int i;
74492 int bad = 0;
74493
74494 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
74495 + unsigned long index = 1UL << order;
74496 +#endif
74497 +
74498 trace_mm_page_free(page, order);
74499 kmemcheck_free_shadow(page, order);
74500
74501 @@ -712,6 +716,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
74502 debug_check_no_obj_freed(page_address(page),
74503 PAGE_SIZE << order);
74504 }
74505 +
74506 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
74507 + for (; index; --index)
74508 + sanitize_highpage(page + index - 1);
74509 +#endif
74510 +
74511 arch_free_page(page, order);
74512 kernel_map_pages(page, 1 << order, 0);
74513
74514 @@ -853,8 +863,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
74515 arch_alloc_page(page, order);
74516 kernel_map_pages(page, 1 << order, 1);
74517
74518 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
74519 if (gfp_flags & __GFP_ZERO)
74520 prep_zero_page(page, order, gfp_flags);
74521 +#endif
74522
74523 if (order && (gfp_flags & __GFP_COMP))
74524 prep_compound_page(page, order);
74525 @@ -3648,7 +3660,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
74526 unsigned long pfn;
74527
74528 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
74529 +#ifdef CONFIG_X86_32
74530 + /* boot failures in VMware 8 on 32bit vanilla since
74531 + this change */
74532 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
74533 +#else
74534 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
74535 +#endif
74536 return 1;
74537 }
74538 return 0;
74539 diff --git a/mm/percpu.c b/mm/percpu.c
74540 index bb4be74..a43ea85 100644
74541 --- a/mm/percpu.c
74542 +++ b/mm/percpu.c
74543 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
74544 static unsigned int pcpu_high_unit_cpu __read_mostly;
74545
74546 /* the address of the first chunk which starts with the kernel static area */
74547 -void *pcpu_base_addr __read_mostly;
74548 +void *pcpu_base_addr __read_only;
74549 EXPORT_SYMBOL_GPL(pcpu_base_addr);
74550
74551 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
74552 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
74553 index 926b466..b23df53 100644
74554 --- a/mm/process_vm_access.c
74555 +++ b/mm/process_vm_access.c
74556 @@ -13,6 +13,7 @@
74557 #include <linux/uio.h>
74558 #include <linux/sched.h>
74559 #include <linux/highmem.h>
74560 +#include <linux/security.h>
74561 #include <linux/ptrace.h>
74562 #include <linux/slab.h>
74563 #include <linux/syscalls.h>
74564 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
74565 size_t iov_l_curr_offset = 0;
74566 ssize_t iov_len;
74567
74568 + return -ENOSYS; // PaX: until properly audited
74569 +
74570 /*
74571 * Work out how many pages of struct pages we're going to need
74572 * when eventually calling get_user_pages
74573 */
74574 for (i = 0; i < riovcnt; i++) {
74575 iov_len = rvec[i].iov_len;
74576 - if (iov_len > 0) {
74577 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
74578 - + iov_len)
74579 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
74580 - / PAGE_SIZE + 1;
74581 - nr_pages = max(nr_pages, nr_pages_iov);
74582 - }
74583 + if (iov_len <= 0)
74584 + continue;
74585 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
74586 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
74587 + nr_pages = max(nr_pages, nr_pages_iov);
74588 }
74589
74590 if (nr_pages == 0)
74591 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
74592 goto free_proc_pages;
74593 }
74594
74595 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
74596 + rc = -EPERM;
74597 + goto put_task_struct;
74598 + }
74599 +
74600 mm = mm_access(task, PTRACE_MODE_ATTACH);
74601 if (!mm || IS_ERR(mm)) {
74602 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
74603 diff --git a/mm/rmap.c b/mm/rmap.c
74604 index aa95e59..b681a63 100644
74605 --- a/mm/rmap.c
74606 +++ b/mm/rmap.c
74607 @@ -168,6 +168,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74608 struct anon_vma *anon_vma = vma->anon_vma;
74609 struct anon_vma_chain *avc;
74610
74611 +#ifdef CONFIG_PAX_SEGMEXEC
74612 + struct anon_vma_chain *avc_m = NULL;
74613 +#endif
74614 +
74615 might_sleep();
74616 if (unlikely(!anon_vma)) {
74617 struct mm_struct *mm = vma->vm_mm;
74618 @@ -177,6 +181,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74619 if (!avc)
74620 goto out_enomem;
74621
74622 +#ifdef CONFIG_PAX_SEGMEXEC
74623 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
74624 + if (!avc_m)
74625 + goto out_enomem_free_avc;
74626 +#endif
74627 +
74628 anon_vma = find_mergeable_anon_vma(vma);
74629 allocated = NULL;
74630 if (!anon_vma) {
74631 @@ -190,6 +200,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74632 /* page_table_lock to protect against threads */
74633 spin_lock(&mm->page_table_lock);
74634 if (likely(!vma->anon_vma)) {
74635 +
74636 +#ifdef CONFIG_PAX_SEGMEXEC
74637 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
74638 +
74639 + if (vma_m) {
74640 + BUG_ON(vma_m->anon_vma);
74641 + vma_m->anon_vma = anon_vma;
74642 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
74643 + avc_m = NULL;
74644 + }
74645 +#endif
74646 +
74647 vma->anon_vma = anon_vma;
74648 anon_vma_chain_link(vma, avc, anon_vma);
74649 allocated = NULL;
74650 @@ -200,12 +222,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74651
74652 if (unlikely(allocated))
74653 put_anon_vma(allocated);
74654 +
74655 +#ifdef CONFIG_PAX_SEGMEXEC
74656 + if (unlikely(avc_m))
74657 + anon_vma_chain_free(avc_m);
74658 +#endif
74659 +
74660 if (unlikely(avc))
74661 anon_vma_chain_free(avc);
74662 }
74663 return 0;
74664
74665 out_enomem_free_avc:
74666 +
74667 +#ifdef CONFIG_PAX_SEGMEXEC
74668 + if (avc_m)
74669 + anon_vma_chain_free(avc_m);
74670 +#endif
74671 +
74672 anon_vma_chain_free(avc);
74673 out_enomem:
74674 return -ENOMEM;
74675 @@ -241,7 +275,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
74676 * Attach the anon_vmas from src to dst.
74677 * Returns 0 on success, -ENOMEM on failure.
74678 */
74679 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
74680 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
74681 {
74682 struct anon_vma_chain *avc, *pavc;
74683 struct anon_vma *root = NULL;
74684 @@ -319,7 +353,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
74685 * the corresponding VMA in the parent process is attached to.
74686 * Returns 0 on success, non-zero on failure.
74687 */
74688 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
74689 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
74690 {
74691 struct anon_vma_chain *avc;
74692 struct anon_vma *anon_vma;
74693 diff --git a/mm/shmem.c b/mm/shmem.c
74694 index d2eeca1..3f160be 100644
74695 --- a/mm/shmem.c
74696 +++ b/mm/shmem.c
74697 @@ -31,7 +31,7 @@
74698 #include <linux/export.h>
74699 #include <linux/swap.h>
74700
74701 -static struct vfsmount *shm_mnt;
74702 +struct vfsmount *shm_mnt;
74703
74704 #ifdef CONFIG_SHMEM
74705 /*
74706 @@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
74707 #define BOGO_DIRENT_SIZE 20
74708
74709 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
74710 -#define SHORT_SYMLINK_LEN 128
74711 +#define SHORT_SYMLINK_LEN 64
74712
74713 struct shmem_xattr {
74714 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
74715 @@ -2594,8 +2594,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
74716 int err = -ENOMEM;
74717
74718 /* Round up to L1_CACHE_BYTES to resist false sharing */
74719 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
74720 - L1_CACHE_BYTES), GFP_KERNEL);
74721 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
74722 if (!sbinfo)
74723 return -ENOMEM;
74724
74725 diff --git a/mm/slab.c b/mm/slab.c
74726 index d066037..5bb78d9 100644
74727 --- a/mm/slab.c
74728 +++ b/mm/slab.c
74729 @@ -164,7 +164,7 @@ static bool pfmemalloc_active __read_mostly;
74730
74731 /* Legal flag mask for kmem_cache_create(). */
74732 #if DEBUG
74733 -# define CREATE_MASK (SLAB_RED_ZONE | \
74734 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
74735 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
74736 SLAB_CACHE_DMA | \
74737 SLAB_STORE_USER | \
74738 @@ -172,7 +172,7 @@ static bool pfmemalloc_active __read_mostly;
74739 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74740 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
74741 #else
74742 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
74743 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
74744 SLAB_CACHE_DMA | \
74745 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
74746 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74747 @@ -322,7 +322,7 @@ struct kmem_list3 {
74748 * Need this for bootstrapping a per node allocator.
74749 */
74750 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
74751 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
74752 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
74753 #define CACHE_CACHE 0
74754 #define SIZE_AC MAX_NUMNODES
74755 #define SIZE_L3 (2 * MAX_NUMNODES)
74756 @@ -423,10 +423,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
74757 if ((x)->max_freeable < i) \
74758 (x)->max_freeable = i; \
74759 } while (0)
74760 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
74761 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
74762 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
74763 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
74764 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
74765 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
74766 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
74767 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
74768 #else
74769 #define STATS_INC_ACTIVE(x) do { } while (0)
74770 #define STATS_DEC_ACTIVE(x) do { } while (0)
74771 @@ -549,7 +549,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
74772 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
74773 */
74774 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
74775 - const struct slab *slab, void *obj)
74776 + const struct slab *slab, const void *obj)
74777 {
74778 u32 offset = (obj - slab->s_mem);
74779 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
74780 @@ -570,12 +570,13 @@ EXPORT_SYMBOL(malloc_sizes);
74781 struct cache_names {
74782 char *name;
74783 char *name_dma;
74784 + char *name_usercopy;
74785 };
74786
74787 static struct cache_names __initdata cache_names[] = {
74788 -#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
74789 +#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
74790 #include <linux/kmalloc_sizes.h>
74791 - {NULL,}
74792 + {NULL}
74793 #undef CACHE
74794 };
74795
74796 @@ -736,6 +737,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
74797 if (unlikely(gfpflags & GFP_DMA))
74798 return csizep->cs_dmacachep;
74799 #endif
74800 +
74801 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74802 + if (unlikely(gfpflags & GFP_USERCOPY))
74803 + return csizep->cs_usercopycachep;
74804 +#endif
74805 +
74806 return csizep->cs_cachep;
74807 }
74808
74809 @@ -1684,7 +1691,7 @@ void __init kmem_cache_init(void)
74810 sizes[INDEX_AC].cs_cachep = __kmem_cache_create(names[INDEX_AC].name,
74811 sizes[INDEX_AC].cs_size,
74812 ARCH_KMALLOC_MINALIGN,
74813 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74814 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74815 NULL);
74816
74817 if (INDEX_AC != INDEX_L3) {
74818 @@ -1692,7 +1699,7 @@ void __init kmem_cache_init(void)
74819 __kmem_cache_create(names[INDEX_L3].name,
74820 sizes[INDEX_L3].cs_size,
74821 ARCH_KMALLOC_MINALIGN,
74822 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74823 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74824 NULL);
74825 }
74826
74827 @@ -1710,7 +1717,7 @@ void __init kmem_cache_init(void)
74828 sizes->cs_cachep = __kmem_cache_create(names->name,
74829 sizes->cs_size,
74830 ARCH_KMALLOC_MINALIGN,
74831 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74832 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74833 NULL);
74834 }
74835 #ifdef CONFIG_ZONE_DMA
74836 @@ -1722,6 +1729,16 @@ void __init kmem_cache_init(void)
74837 SLAB_PANIC,
74838 NULL);
74839 #endif
74840 +
74841 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74842 + sizes->cs_usercopycachep = kmem_cache_create(
74843 + names->name_usercopy,
74844 + sizes->cs_size,
74845 + ARCH_KMALLOC_MINALIGN,
74846 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74847 + NULL);
74848 +#endif
74849 +
74850 sizes++;
74851 names++;
74852 }
74853 @@ -4467,10 +4484,10 @@ static int s_show(struct seq_file *m, void *p)
74854 }
74855 /* cpu stats */
74856 {
74857 - unsigned long allochit = atomic_read(&cachep->allochit);
74858 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
74859 - unsigned long freehit = atomic_read(&cachep->freehit);
74860 - unsigned long freemiss = atomic_read(&cachep->freemiss);
74861 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
74862 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
74863 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
74864 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
74865
74866 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
74867 allochit, allocmiss, freehit, freemiss);
74868 @@ -4729,13 +4746,71 @@ static int __init slab_proc_init(void)
74869 {
74870 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
74871 #ifdef CONFIG_DEBUG_SLAB_LEAK
74872 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
74873 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
74874 #endif
74875 return 0;
74876 }
74877 module_init(slab_proc_init);
74878 #endif
74879
74880 +bool is_usercopy_object(const void *ptr)
74881 +{
74882 + struct page *page;
74883 + struct kmem_cache *cachep;
74884 +
74885 + if (ZERO_OR_NULL_PTR(ptr))
74886 + return false;
74887 +
74888 + if (!slab_is_available())
74889 + return false;
74890 +
74891 + if (!virt_addr_valid(ptr))
74892 + return false;
74893 +
74894 + page = virt_to_head_page(ptr);
74895 +
74896 + if (!PageSlab(page))
74897 + return false;
74898 +
74899 + cachep = page_get_cache(page);
74900 + return cachep->flags & SLAB_USERCOPY;
74901 +}
74902 +
74903 +#ifdef CONFIG_PAX_USERCOPY
74904 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74905 +{
74906 + struct page *page;
74907 + struct kmem_cache *cachep;
74908 + struct slab *slabp;
74909 + unsigned int objnr;
74910 + unsigned long offset;
74911 +
74912 + if (ZERO_OR_NULL_PTR(ptr))
74913 + return "<null>";
74914 +
74915 + if (!virt_addr_valid(ptr))
74916 + return NULL;
74917 +
74918 + page = virt_to_head_page(ptr);
74919 +
74920 + if (!PageSlab(page))
74921 + return NULL;
74922 +
74923 + cachep = page_get_cache(page);
74924 + if (!(cachep->flags & SLAB_USERCOPY))
74925 + return cachep->name;
74926 +
74927 + slabp = page->slab_page;
74928 + objnr = obj_to_index(cachep, slabp, ptr);
74929 + BUG_ON(objnr >= cachep->num);
74930 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
74931 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
74932 + return NULL;
74933 +
74934 + return cachep->name;
74935 +}
74936 +#endif
74937 +
74938 /**
74939 * ksize - get the actual amount of memory allocated for a given object
74940 * @objp: Pointer to the object
74941 diff --git a/mm/slob.c b/mm/slob.c
74942 index 45d4ca7..88943c1 100644
74943 --- a/mm/slob.c
74944 +++ b/mm/slob.c
74945 @@ -159,7 +159,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
74946 /*
74947 * Return the size of a slob block.
74948 */
74949 -static slobidx_t slob_units(slob_t *s)
74950 +static slobidx_t slob_units(const slob_t *s)
74951 {
74952 if (s->units > 0)
74953 return s->units;
74954 @@ -169,7 +169,7 @@ static slobidx_t slob_units(slob_t *s)
74955 /*
74956 * Return the next free slob block pointer after this one.
74957 */
74958 -static slob_t *slob_next(slob_t *s)
74959 +static slob_t *slob_next(const slob_t *s)
74960 {
74961 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
74962 slobidx_t next;
74963 @@ -184,14 +184,14 @@ static slob_t *slob_next(slob_t *s)
74964 /*
74965 * Returns true if s is the last free block in its page.
74966 */
74967 -static int slob_last(slob_t *s)
74968 +static int slob_last(const slob_t *s)
74969 {
74970 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
74971 }
74972
74973 -static void *slob_new_pages(gfp_t gfp, int order, int node)
74974 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
74975 {
74976 - void *page;
74977 + struct page *page;
74978
74979 #ifdef CONFIG_NUMA
74980 if (node != -1)
74981 @@ -203,14 +203,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
74982 if (!page)
74983 return NULL;
74984
74985 - return page_address(page);
74986 + __SetPageSlab(page);
74987 + return page;
74988 }
74989
74990 -static void slob_free_pages(void *b, int order)
74991 +static void slob_free_pages(struct page *sp, int order)
74992 {
74993 if (current->reclaim_state)
74994 current->reclaim_state->reclaimed_slab += 1 << order;
74995 - free_pages((unsigned long)b, order);
74996 + __ClearPageSlab(sp);
74997 + reset_page_mapcount(sp);
74998 + sp->private = 0;
74999 + __free_pages(sp, order);
75000 }
75001
75002 /*
75003 @@ -315,15 +319,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
75004
75005 /* Not enough space: must allocate a new page */
75006 if (!b) {
75007 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
75008 - if (!b)
75009 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
75010 + if (!sp)
75011 return NULL;
75012 - sp = virt_to_page(b);
75013 - __SetPageSlab(sp);
75014 + b = page_address(sp);
75015
75016 spin_lock_irqsave(&slob_lock, flags);
75017 sp->units = SLOB_UNITS(PAGE_SIZE);
75018 sp->freelist = b;
75019 + sp->private = 0;
75020 INIT_LIST_HEAD(&sp->list);
75021 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
75022 set_slob_page_free(sp, slob_list);
75023 @@ -361,9 +365,7 @@ static void slob_free(void *block, int size)
75024 if (slob_page_free(sp))
75025 clear_slob_page_free(sp);
75026 spin_unlock_irqrestore(&slob_lock, flags);
75027 - __ClearPageSlab(sp);
75028 - reset_page_mapcount(sp);
75029 - slob_free_pages(b, 0);
75030 + slob_free_pages(sp, 0);
75031 return;
75032 }
75033
75034 @@ -425,11 +427,10 @@ out:
75035 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
75036 */
75037
75038 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
75039 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
75040 {
75041 - unsigned int *m;
75042 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75043 - void *ret;
75044 + slob_t *m;
75045 + void *ret = NULL;
75046
75047 gfp &= gfp_allowed_mask;
75048
75049 @@ -443,20 +444,23 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
75050
75051 if (!m)
75052 return NULL;
75053 - *m = size;
75054 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
75055 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
75056 + m[0].units = size;
75057 + m[1].units = align;
75058 ret = (void *)m + align;
75059
75060 trace_kmalloc_node(_RET_IP_, ret,
75061 size, size + align, gfp, node);
75062 } else {
75063 unsigned int order = get_order(size);
75064 + struct page *page;
75065
75066 if (likely(order))
75067 gfp |= __GFP_COMP;
75068 - ret = slob_new_pages(gfp, order, node);
75069 - if (ret) {
75070 - struct page *page;
75071 - page = virt_to_page(ret);
75072 + page = slob_new_pages(gfp, order, node);
75073 + if (page) {
75074 + ret = page_address(page);
75075 page->private = size;
75076 }
75077
75078 @@ -464,7 +468,16 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
75079 size, PAGE_SIZE << order, gfp, node);
75080 }
75081
75082 - kmemleak_alloc(ret, size, 1, gfp);
75083 + return ret;
75084 +}
75085 +
75086 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
75087 +{
75088 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75089 + void *ret = __kmalloc_node_align(size, gfp, node, align);
75090 +
75091 + if (!ZERO_OR_NULL_PTR(ret))
75092 + kmemleak_alloc(ret, size, 1, gfp);
75093 return ret;
75094 }
75095 EXPORT_SYMBOL(__kmalloc_node);
75096 @@ -480,15 +493,91 @@ void kfree(const void *block)
75097 kmemleak_free(block);
75098
75099 sp = virt_to_page(block);
75100 - if (PageSlab(sp)) {
75101 + VM_BUG_ON(!PageSlab(sp));
75102 + if (!sp->private) {
75103 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75104 - unsigned int *m = (unsigned int *)(block - align);
75105 - slob_free(m, *m + align);
75106 - } else
75107 + slob_t *m = (slob_t *)(block - align);
75108 + slob_free(m, m[0].units + align);
75109 + } else {
75110 + __ClearPageSlab(sp);
75111 + reset_page_mapcount(sp);
75112 + sp->private = 0;
75113 put_page(sp);
75114 + }
75115 }
75116 EXPORT_SYMBOL(kfree);
75117
75118 +bool is_usercopy_object(const void *ptr)
75119 +{
75120 + if (!slab_is_available())
75121 + return false;
75122 +
75123 + // PAX: TODO
75124 +
75125 + return false;
75126 +}
75127 +
75128 +#ifdef CONFIG_PAX_USERCOPY
75129 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
75130 +{
75131 + struct page *page;
75132 + const slob_t *free;
75133 + const void *base;
75134 + unsigned long flags;
75135 +
75136 + if (ZERO_OR_NULL_PTR(ptr))
75137 + return "<null>";
75138 +
75139 + if (!virt_addr_valid(ptr))
75140 + return NULL;
75141 +
75142 + page = virt_to_head_page(ptr);
75143 + if (!PageSlab(page))
75144 + return NULL;
75145 +
75146 + if (page->private) {
75147 + base = page;
75148 + if (base <= ptr && n <= page->private - (ptr - base))
75149 + return NULL;
75150 + return "<slob>";
75151 + }
75152 +
75153 + /* some tricky double walking to find the chunk */
75154 + spin_lock_irqsave(&slob_lock, flags);
75155 + base = (void *)((unsigned long)ptr & PAGE_MASK);
75156 + free = page->freelist;
75157 +
75158 + while (!slob_last(free) && (void *)free <= ptr) {
75159 + base = free + slob_units(free);
75160 + free = slob_next(free);
75161 + }
75162 +
75163 + while (base < (void *)free) {
75164 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
75165 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
75166 + int offset;
75167 +
75168 + if (ptr < base + align)
75169 + break;
75170 +
75171 + offset = ptr - base - align;
75172 + if (offset >= m) {
75173 + base += size;
75174 + continue;
75175 + }
75176 +
75177 + if (n > m - offset)
75178 + break;
75179 +
75180 + spin_unlock_irqrestore(&slob_lock, flags);
75181 + return NULL;
75182 + }
75183 +
75184 + spin_unlock_irqrestore(&slob_lock, flags);
75185 + return "<slob>";
75186 +}
75187 +#endif
75188 +
75189 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
75190 size_t ksize(const void *block)
75191 {
75192 @@ -499,10 +588,11 @@ size_t ksize(const void *block)
75193 return 0;
75194
75195 sp = virt_to_page(block);
75196 - if (PageSlab(sp)) {
75197 + VM_BUG_ON(!PageSlab(sp));
75198 + if (!sp->private) {
75199 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75200 - unsigned int *m = (unsigned int *)(block - align);
75201 - return SLOB_UNITS(*m) * SLOB_UNIT;
75202 + slob_t *m = (slob_t *)(block - align);
75203 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
75204 } else
75205 return sp->private;
75206 }
75207 @@ -513,8 +603,13 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
75208 {
75209 struct kmem_cache *c;
75210
75211 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75212 + c = __kmalloc_node_align(sizeof(struct kmem_cache),
75213 + GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
75214 +#else
75215 c = slob_alloc(sizeof(struct kmem_cache),
75216 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
75217 +#endif
75218
75219 if (c) {
75220 c->name = name;
75221 @@ -549,23 +644,33 @@ EXPORT_SYMBOL(kmem_cache_destroy);
75222
75223 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
75224 {
75225 - void *b;
75226 + void *b = NULL;
75227
75228 flags &= gfp_allowed_mask;
75229
75230 lockdep_trace_alloc(flags);
75231
75232 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75233 + b = __kmalloc_node_align(c->size, flags, node, c->align);
75234 +#else
75235 if (c->size < PAGE_SIZE) {
75236 b = slob_alloc(c->size, flags, c->align, node);
75237 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
75238 SLOB_UNITS(c->size) * SLOB_UNIT,
75239 flags, node);
75240 } else {
75241 - b = slob_new_pages(flags, get_order(c->size), node);
75242 + struct page *sp;
75243 +
75244 + sp = slob_new_pages(flags, get_order(c->size), node);
75245 + if (sp) {
75246 + b = page_address(sp);
75247 + sp->private = c->size;
75248 + }
75249 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
75250 PAGE_SIZE << get_order(c->size),
75251 flags, node);
75252 }
75253 +#endif
75254
75255 if (c->ctor)
75256 c->ctor(b);
75257 @@ -577,10 +682,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
75258
75259 static void __kmem_cache_free(void *b, int size)
75260 {
75261 - if (size < PAGE_SIZE)
75262 + struct page *sp;
75263 +
75264 + sp = virt_to_page(b);
75265 + BUG_ON(!PageSlab(sp));
75266 + if (!sp->private)
75267 slob_free(b, size);
75268 else
75269 - slob_free_pages(b, get_order(size));
75270 + slob_free_pages(sp, get_order(size));
75271 }
75272
75273 static void kmem_rcu_free(struct rcu_head *head)
75274 @@ -593,17 +702,31 @@ static void kmem_rcu_free(struct rcu_head *head)
75275
75276 void kmem_cache_free(struct kmem_cache *c, void *b)
75277 {
75278 + int size = c->size;
75279 +
75280 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75281 + if (size + c->align < PAGE_SIZE) {
75282 + size += c->align;
75283 + b -= c->align;
75284 + }
75285 +#endif
75286 +
75287 kmemleak_free_recursive(b, c->flags);
75288 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
75289 struct slob_rcu *slob_rcu;
75290 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
75291 - slob_rcu->size = c->size;
75292 + slob_rcu = b + (size - sizeof(struct slob_rcu));
75293 + slob_rcu->size = size;
75294 call_rcu(&slob_rcu->head, kmem_rcu_free);
75295 } else {
75296 - __kmem_cache_free(b, c->size);
75297 + __kmem_cache_free(b, size);
75298 }
75299
75300 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75301 + trace_kfree(_RET_IP_, b);
75302 +#else
75303 trace_kmem_cache_free(_RET_IP_, b);
75304 +#endif
75305 +
75306 }
75307 EXPORT_SYMBOL(kmem_cache_free);
75308
75309 diff --git a/mm/slub.c b/mm/slub.c
75310 index 2fdd96f..1e2f893 100644
75311 --- a/mm/slub.c
75312 +++ b/mm/slub.c
75313 @@ -201,7 +201,7 @@ struct track {
75314
75315 enum track_item { TRACK_ALLOC, TRACK_FREE };
75316
75317 -#ifdef CONFIG_SYSFS
75318 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75319 static int sysfs_slab_add(struct kmem_cache *);
75320 static int sysfs_slab_alias(struct kmem_cache *, const char *);
75321 static void sysfs_slab_remove(struct kmem_cache *);
75322 @@ -525,7 +525,7 @@ static void print_track(const char *s, struct track *t)
75323 if (!t->addr)
75324 return;
75325
75326 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
75327 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
75328 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
75329 #ifdef CONFIG_STACKTRACE
75330 {
75331 @@ -2612,6 +2612,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
75332
75333 page = virt_to_head_page(x);
75334
75335 + BUG_ON(!PageSlab(page));
75336 +
75337 slab_free(s, page, x, _RET_IP_);
75338
75339 trace_kmem_cache_free(_RET_IP_, x);
75340 @@ -2645,7 +2647,7 @@ static int slub_min_objects;
75341 * Merge control. If this is set then no merging of slab caches will occur.
75342 * (Could be removed. This was introduced to pacify the merge skeptics.)
75343 */
75344 -static int slub_nomerge;
75345 +static int slub_nomerge = 1;
75346
75347 /*
75348 * Calculate the order of allocation given an slab object size.
75349 @@ -3098,7 +3100,7 @@ static int kmem_cache_open(struct kmem_cache *s,
75350 else
75351 s->cpu_partial = 30;
75352
75353 - s->refcount = 1;
75354 + atomic_set(&s->refcount, 1);
75355 #ifdef CONFIG_NUMA
75356 s->remote_node_defrag_ratio = 1000;
75357 #endif
75358 @@ -3202,8 +3204,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
75359 void kmem_cache_destroy(struct kmem_cache *s)
75360 {
75361 mutex_lock(&slab_mutex);
75362 - s->refcount--;
75363 - if (!s->refcount) {
75364 + if (atomic_dec_and_test(&s->refcount)) {
75365 list_del(&s->list);
75366 mutex_unlock(&slab_mutex);
75367 if (kmem_cache_close(s)) {
75368 @@ -3232,6 +3233,10 @@ static struct kmem_cache *kmem_cache;
75369 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
75370 #endif
75371
75372 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75373 +static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
75374 +#endif
75375 +
75376 static int __init setup_slub_min_order(char *str)
75377 {
75378 get_option(&str, &slub_min_order);
75379 @@ -3346,6 +3351,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
75380 return kmalloc_dma_caches[index];
75381
75382 #endif
75383 +
75384 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75385 + if (flags & SLAB_USERCOPY)
75386 + return kmalloc_usercopy_caches[index];
75387 +
75388 +#endif
75389 +
75390 return kmalloc_caches[index];
75391 }
75392
75393 @@ -3414,6 +3426,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
75394 EXPORT_SYMBOL(__kmalloc_node);
75395 #endif
75396
75397 +bool is_usercopy_object(const void *ptr)
75398 +{
75399 + struct page *page;
75400 + struct kmem_cache *s;
75401 +
75402 + if (ZERO_OR_NULL_PTR(ptr))
75403 + return false;
75404 +
75405 + if (!slab_is_available())
75406 + return false;
75407 +
75408 + if (!virt_addr_valid(ptr))
75409 + return false;
75410 +
75411 + page = virt_to_head_page(ptr);
75412 +
75413 + if (!PageSlab(page))
75414 + return false;
75415 +
75416 + s = page->slab;
75417 + return s->flags & SLAB_USERCOPY;
75418 +}
75419 +
75420 +#ifdef CONFIG_PAX_USERCOPY
75421 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
75422 +{
75423 + struct page *page;
75424 + struct kmem_cache *s;
75425 + unsigned long offset;
75426 +
75427 + if (ZERO_OR_NULL_PTR(ptr))
75428 + return "<null>";
75429 +
75430 + if (!virt_addr_valid(ptr))
75431 + return NULL;
75432 +
75433 + page = virt_to_head_page(ptr);
75434 +
75435 + if (!PageSlab(page))
75436 + return NULL;
75437 +
75438 + s = page->slab;
75439 + if (!(s->flags & SLAB_USERCOPY))
75440 + return s->name;
75441 +
75442 + offset = (ptr - page_address(page)) % s->size;
75443 + if (offset <= s->object_size && n <= s->object_size - offset)
75444 + return NULL;
75445 +
75446 + return s->name;
75447 +}
75448 +#endif
75449 +
75450 size_t ksize(const void *object)
75451 {
75452 struct page *page;
75453 @@ -3688,7 +3753,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
75454 int node;
75455
75456 list_add(&s->list, &slab_caches);
75457 - s->refcount = -1;
75458 + atomic_set(&s->refcount, -1);
75459
75460 for_each_node_state(node, N_NORMAL_MEMORY) {
75461 struct kmem_cache_node *n = get_node(s, node);
75462 @@ -3808,17 +3873,17 @@ void __init kmem_cache_init(void)
75463
75464 /* Caches that are not of the two-to-the-power-of size */
75465 if (KMALLOC_MIN_SIZE <= 32) {
75466 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
75467 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
75468 caches++;
75469 }
75470
75471 if (KMALLOC_MIN_SIZE <= 64) {
75472 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
75473 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
75474 caches++;
75475 }
75476
75477 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
75478 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
75479 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
75480 caches++;
75481 }
75482
75483 @@ -3860,6 +3925,22 @@ void __init kmem_cache_init(void)
75484 }
75485 }
75486 #endif
75487 +
75488 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75489 + for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
75490 + struct kmem_cache *s = kmalloc_caches[i];
75491 +
75492 + if (s && s->size) {
75493 + char *name = kasprintf(GFP_NOWAIT,
75494 + "usercopy-kmalloc-%d", s->object_size);
75495 +
75496 + BUG_ON(!name);
75497 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
75498 + s->object_size, SLAB_USERCOPY);
75499 + }
75500 + }
75501 +#endif
75502 +
75503 printk(KERN_INFO
75504 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
75505 " CPUs=%d, Nodes=%d\n",
75506 @@ -3886,7 +3967,7 @@ static int slab_unmergeable(struct kmem_cache *s)
75507 /*
75508 * We may have set a slab to be unmergeable during bootstrap.
75509 */
75510 - if (s->refcount < 0)
75511 + if (atomic_read(&s->refcount) < 0)
75512 return 1;
75513
75514 return 0;
75515 @@ -3941,7 +4022,7 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
75516
75517 s = find_mergeable(size, align, flags, name, ctor);
75518 if (s) {
75519 - s->refcount++;
75520 + atomic_inc(&s->refcount);
75521 /*
75522 * Adjust the object sizes so that we clear
75523 * the complete object on kzalloc.
75524 @@ -3950,7 +4031,7 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
75525 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
75526
75527 if (sysfs_slab_alias(s, name)) {
75528 - s->refcount--;
75529 + atomic_dec(&s->refcount);
75530 return NULL;
75531 }
75532 return s;
75533 @@ -4072,7 +4153,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
75534 }
75535 #endif
75536
75537 -#ifdef CONFIG_SYSFS
75538 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75539 static int count_inuse(struct page *page)
75540 {
75541 return page->inuse;
75542 @@ -4459,12 +4540,12 @@ static void resiliency_test(void)
75543 validate_slab_cache(kmalloc_caches[9]);
75544 }
75545 #else
75546 -#ifdef CONFIG_SYSFS
75547 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75548 static void resiliency_test(void) {};
75549 #endif
75550 #endif
75551
75552 -#ifdef CONFIG_SYSFS
75553 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75554 enum slab_stat_type {
75555 SL_ALL, /* All slabs */
75556 SL_PARTIAL, /* Only partially allocated slabs */
75557 @@ -4708,7 +4789,7 @@ SLAB_ATTR_RO(ctor);
75558
75559 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
75560 {
75561 - return sprintf(buf, "%d\n", s->refcount - 1);
75562 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
75563 }
75564 SLAB_ATTR_RO(aliases);
75565
75566 @@ -5279,6 +5360,7 @@ static char *create_unique_id(struct kmem_cache *s)
75567 return name;
75568 }
75569
75570 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75571 static int sysfs_slab_add(struct kmem_cache *s)
75572 {
75573 int err;
75574 @@ -5341,6 +5423,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
75575 kobject_del(&s->kobj);
75576 kobject_put(&s->kobj);
75577 }
75578 +#endif
75579
75580 /*
75581 * Need to buffer aliases during bootup until sysfs becomes
75582 @@ -5354,6 +5437,7 @@ struct saved_alias {
75583
75584 static struct saved_alias *alias_list;
75585
75586 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75587 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
75588 {
75589 struct saved_alias *al;
75590 @@ -5376,6 +5460,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
75591 alias_list = al;
75592 return 0;
75593 }
75594 +#endif
75595
75596 static int __init slab_sysfs_init(void)
75597 {
75598 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
75599 index 1b7e22a..3fcd4f3 100644
75600 --- a/mm/sparse-vmemmap.c
75601 +++ b/mm/sparse-vmemmap.c
75602 @@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
75603 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
75604 if (!p)
75605 return NULL;
75606 - pud_populate(&init_mm, pud, p);
75607 + pud_populate_kernel(&init_mm, pud, p);
75608 }
75609 return pud;
75610 }
75611 @@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
75612 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
75613 if (!p)
75614 return NULL;
75615 - pgd_populate(&init_mm, pgd, p);
75616 + pgd_populate_kernel(&init_mm, pgd, p);
75617 }
75618 return pgd;
75619 }
75620 diff --git a/mm/swap.c b/mm/swap.c
75621 index 7782588..228c784 100644
75622 --- a/mm/swap.c
75623 +++ b/mm/swap.c
75624 @@ -30,6 +30,7 @@
75625 #include <linux/backing-dev.h>
75626 #include <linux/memcontrol.h>
75627 #include <linux/gfp.h>
75628 +#include <linux/hugetlb.h>
75629
75630 #include "internal.h"
75631
75632 @@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
75633
75634 __page_cache_release(page);
75635 dtor = get_compound_page_dtor(page);
75636 + if (!PageHuge(page))
75637 + BUG_ON(dtor != free_compound_page);
75638 (*dtor)(page);
75639 }
75640
75641 diff --git a/mm/swapfile.c b/mm/swapfile.c
75642 index 14e254c..a6af32c 100644
75643 --- a/mm/swapfile.c
75644 +++ b/mm/swapfile.c
75645 @@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
75646
75647 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
75648 /* Activity counter to indicate that a swapon or swapoff has occurred */
75649 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
75650 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
75651
75652 static inline unsigned char swap_count(unsigned char ent)
75653 {
75654 @@ -1603,7 +1603,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
75655 }
75656 filp_close(swap_file, NULL);
75657 err = 0;
75658 - atomic_inc(&proc_poll_event);
75659 + atomic_inc_unchecked(&proc_poll_event);
75660 wake_up_interruptible(&proc_poll_wait);
75661
75662 out_dput:
75663 @@ -1619,8 +1619,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
75664
75665 poll_wait(file, &proc_poll_wait, wait);
75666
75667 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
75668 - seq->poll_event = atomic_read(&proc_poll_event);
75669 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
75670 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
75671 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
75672 }
75673
75674 @@ -1718,7 +1718,7 @@ static int swaps_open(struct inode *inode, struct file *file)
75675 return ret;
75676
75677 seq = file->private_data;
75678 - seq->poll_event = atomic_read(&proc_poll_event);
75679 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
75680 return 0;
75681 }
75682
75683 @@ -2060,7 +2060,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
75684 (frontswap_map) ? "FS" : "");
75685
75686 mutex_unlock(&swapon_mutex);
75687 - atomic_inc(&proc_poll_event);
75688 + atomic_inc_unchecked(&proc_poll_event);
75689 wake_up_interruptible(&proc_poll_wait);
75690
75691 if (S_ISREG(inode->i_mode))
75692 diff --git a/mm/util.c b/mm/util.c
75693 index 8c7265a..c96d884 100644
75694 --- a/mm/util.c
75695 +++ b/mm/util.c
75696 @@ -285,6 +285,12 @@ done:
75697 void arch_pick_mmap_layout(struct mm_struct *mm)
75698 {
75699 mm->mmap_base = TASK_UNMAPPED_BASE;
75700 +
75701 +#ifdef CONFIG_PAX_RANDMMAP
75702 + if (mm->pax_flags & MF_PAX_RANDMMAP)
75703 + mm->mmap_base += mm->delta_mmap;
75704 +#endif
75705 +
75706 mm->get_unmapped_area = arch_get_unmapped_area;
75707 mm->unmap_area = arch_unmap_area;
75708 }
75709 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
75710 index 2bb90b1..ed47e53 100644
75711 --- a/mm/vmalloc.c
75712 +++ b/mm/vmalloc.c
75713 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
75714
75715 pte = pte_offset_kernel(pmd, addr);
75716 do {
75717 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
75718 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
75719 +
75720 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75721 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
75722 + BUG_ON(!pte_exec(*pte));
75723 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
75724 + continue;
75725 + }
75726 +#endif
75727 +
75728 + {
75729 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
75730 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
75731 + }
75732 } while (pte++, addr += PAGE_SIZE, addr != end);
75733 }
75734
75735 @@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
75736 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
75737 {
75738 pte_t *pte;
75739 + int ret = -ENOMEM;
75740
75741 /*
75742 * nr is a running index into the array which helps higher level
75743 @@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
75744 pte = pte_alloc_kernel(pmd, addr);
75745 if (!pte)
75746 return -ENOMEM;
75747 +
75748 + pax_open_kernel();
75749 do {
75750 struct page *page = pages[*nr];
75751
75752 - if (WARN_ON(!pte_none(*pte)))
75753 - return -EBUSY;
75754 - if (WARN_ON(!page))
75755 - return -ENOMEM;
75756 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75757 + if (pgprot_val(prot) & _PAGE_NX)
75758 +#endif
75759 +
75760 + if (WARN_ON(!pte_none(*pte))) {
75761 + ret = -EBUSY;
75762 + goto out;
75763 + }
75764 + if (WARN_ON(!page)) {
75765 + ret = -ENOMEM;
75766 + goto out;
75767 + }
75768 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
75769 (*nr)++;
75770 } while (pte++, addr += PAGE_SIZE, addr != end);
75771 - return 0;
75772 + ret = 0;
75773 +out:
75774 + pax_close_kernel();
75775 + return ret;
75776 }
75777
75778 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
75779 @@ -119,7 +144,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
75780 pmd_t *pmd;
75781 unsigned long next;
75782
75783 - pmd = pmd_alloc(&init_mm, pud, addr);
75784 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
75785 if (!pmd)
75786 return -ENOMEM;
75787 do {
75788 @@ -136,7 +161,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
75789 pud_t *pud;
75790 unsigned long next;
75791
75792 - pud = pud_alloc(&init_mm, pgd, addr);
75793 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
75794 if (!pud)
75795 return -ENOMEM;
75796 do {
75797 @@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
75798 * and fall back on vmalloc() if that fails. Others
75799 * just put it in the vmalloc space.
75800 */
75801 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
75802 +#ifdef CONFIG_MODULES
75803 +#ifdef MODULES_VADDR
75804 unsigned long addr = (unsigned long)x;
75805 if (addr >= MODULES_VADDR && addr < MODULES_END)
75806 return 1;
75807 #endif
75808 +
75809 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75810 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
75811 + return 1;
75812 +#endif
75813 +
75814 +#endif
75815 +
75816 return is_vmalloc_addr(x);
75817 }
75818
75819 @@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
75820
75821 if (!pgd_none(*pgd)) {
75822 pud_t *pud = pud_offset(pgd, addr);
75823 +#ifdef CONFIG_X86
75824 + if (!pud_large(*pud))
75825 +#endif
75826 if (!pud_none(*pud)) {
75827 pmd_t *pmd = pmd_offset(pud, addr);
75828 +#ifdef CONFIG_X86
75829 + if (!pmd_large(*pmd))
75830 +#endif
75831 if (!pmd_none(*pmd)) {
75832 pte_t *ptep, pte;
75833
75834 @@ -329,7 +369,7 @@ static void purge_vmap_area_lazy(void);
75835 * Allocate a region of KVA of the specified size and alignment, within the
75836 * vstart and vend.
75837 */
75838 -static struct vmap_area *alloc_vmap_area(unsigned long size,
75839 +static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
75840 unsigned long align,
75841 unsigned long vstart, unsigned long vend,
75842 int node, gfp_t gfp_mask)
75843 @@ -1328,6 +1368,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
75844 struct vm_struct *area;
75845
75846 BUG_ON(in_interrupt());
75847 +
75848 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75849 + if (flags & VM_KERNEXEC) {
75850 + if (start != VMALLOC_START || end != VMALLOC_END)
75851 + return NULL;
75852 + start = (unsigned long)MODULES_EXEC_VADDR;
75853 + end = (unsigned long)MODULES_EXEC_END;
75854 + }
75855 +#endif
75856 +
75857 if (flags & VM_IOREMAP) {
75858 int bit = fls(size);
75859
75860 @@ -1568,6 +1618,11 @@ void *vmap(struct page **pages, unsigned int count,
75861 if (count > totalram_pages)
75862 return NULL;
75863
75864 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75865 + if (!(pgprot_val(prot) & _PAGE_NX))
75866 + flags |= VM_KERNEXEC;
75867 +#endif
75868 +
75869 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
75870 __builtin_return_address(0));
75871 if (!area)
75872 @@ -1669,6 +1724,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
75873 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
75874 goto fail;
75875
75876 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75877 + if (!(pgprot_val(prot) & _PAGE_NX))
75878 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
75879 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
75880 + else
75881 +#endif
75882 +
75883 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
75884 start, end, node, gfp_mask, caller);
75885 if (!area)
75886 @@ -1842,10 +1904,9 @@ EXPORT_SYMBOL(vzalloc_node);
75887 * For tight control over page level allocator and protection flags
75888 * use __vmalloc() instead.
75889 */
75890 -
75891 void *vmalloc_exec(unsigned long size)
75892 {
75893 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
75894 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
75895 -1, __builtin_return_address(0));
75896 }
75897
75898 @@ -2136,6 +2197,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
75899 unsigned long uaddr = vma->vm_start;
75900 unsigned long usize = vma->vm_end - vma->vm_start;
75901
75902 + BUG_ON(vma->vm_mirror);
75903 +
75904 if ((PAGE_SIZE-1) & (unsigned long)addr)
75905 return -EINVAL;
75906
75907 @@ -2572,7 +2635,7 @@ static int s_show(struct seq_file *m, void *p)
75908 {
75909 struct vm_struct *v = p;
75910
75911 - seq_printf(m, "0x%p-0x%p %7ld",
75912 + seq_printf(m, "0x%pK-0x%pK %7ld",
75913 v->addr, v->addr + v->size, v->size);
75914
75915 if (v->caller)
75916 diff --git a/mm/vmstat.c b/mm/vmstat.c
75917 index df7a674..8b4a4f3 100644
75918 --- a/mm/vmstat.c
75919 +++ b/mm/vmstat.c
75920 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
75921 *
75922 * vm_stat contains the global counters
75923 */
75924 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
75925 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
75926 EXPORT_SYMBOL(vm_stat);
75927
75928 #ifdef CONFIG_SMP
75929 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
75930 v = p->vm_stat_diff[i];
75931 p->vm_stat_diff[i] = 0;
75932 local_irq_restore(flags);
75933 - atomic_long_add(v, &zone->vm_stat[i]);
75934 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
75935 global_diff[i] += v;
75936 #ifdef CONFIG_NUMA
75937 /* 3 seconds idle till flush */
75938 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
75939
75940 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
75941 if (global_diff[i])
75942 - atomic_long_add(global_diff[i], &vm_stat[i]);
75943 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
75944 }
75945
75946 #endif
75947 @@ -1212,10 +1212,20 @@ static int __init setup_vmstat(void)
75948 start_cpu_timer(cpu);
75949 #endif
75950 #ifdef CONFIG_PROC_FS
75951 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
75952 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
75953 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
75954 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
75955 + {
75956 + mode_t gr_mode = S_IRUGO;
75957 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
75958 + gr_mode = S_IRUSR;
75959 +#endif
75960 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
75961 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
75962 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
75963 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
75964 +#else
75965 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
75966 +#endif
75967 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
75968 + }
75969 #endif
75970 return 0;
75971 }
75972 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
75973 index 9096bcb..43ed7bb 100644
75974 --- a/net/8021q/vlan.c
75975 +++ b/net/8021q/vlan.c
75976 @@ -557,8 +557,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
75977 err = -EPERM;
75978 if (!capable(CAP_NET_ADMIN))
75979 break;
75980 - if ((args.u.name_type >= 0) &&
75981 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
75982 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
75983 struct vlan_net *vn;
75984
75985 vn = net_generic(net, vlan_net_id);
75986 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
75987 index 6449bae..8c1f454 100644
75988 --- a/net/9p/trans_fd.c
75989 +++ b/net/9p/trans_fd.c
75990 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
75991 oldfs = get_fs();
75992 set_fs(get_ds());
75993 /* The cast to a user pointer is valid due to the set_fs() */
75994 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
75995 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
75996 set_fs(oldfs);
75997
75998 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
75999 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
76000 index 876fbe8..8bbea9f 100644
76001 --- a/net/atm/atm_misc.c
76002 +++ b/net/atm/atm_misc.c
76003 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
76004 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
76005 return 1;
76006 atm_return(vcc, truesize);
76007 - atomic_inc(&vcc->stats->rx_drop);
76008 + atomic_inc_unchecked(&vcc->stats->rx_drop);
76009 return 0;
76010 }
76011 EXPORT_SYMBOL(atm_charge);
76012 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
76013 }
76014 }
76015 atm_return(vcc, guess);
76016 - atomic_inc(&vcc->stats->rx_drop);
76017 + atomic_inc_unchecked(&vcc->stats->rx_drop);
76018 return NULL;
76019 }
76020 EXPORT_SYMBOL(atm_alloc_charge);
76021 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
76022
76023 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
76024 {
76025 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
76026 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
76027 __SONET_ITEMS
76028 #undef __HANDLE_ITEM
76029 }
76030 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
76031
76032 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
76033 {
76034 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
76035 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
76036 __SONET_ITEMS
76037 #undef __HANDLE_ITEM
76038 }
76039 diff --git a/net/atm/lec.h b/net/atm/lec.h
76040 index a86aff9..3a0d6f6 100644
76041 --- a/net/atm/lec.h
76042 +++ b/net/atm/lec.h
76043 @@ -48,7 +48,7 @@ struct lane2_ops {
76044 const u8 *tlvs, u32 sizeoftlvs);
76045 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
76046 const u8 *tlvs, u32 sizeoftlvs);
76047 -};
76048 +} __no_const;
76049
76050 /*
76051 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
76052 diff --git a/net/atm/mpc.h b/net/atm/mpc.h
76053 index 0919a88..a23d54e 100644
76054 --- a/net/atm/mpc.h
76055 +++ b/net/atm/mpc.h
76056 @@ -33,7 +33,7 @@ struct mpoa_client {
76057 struct mpc_parameters parameters; /* parameters for this client */
76058
76059 const struct net_device_ops *old_ops;
76060 - struct net_device_ops new_ops;
76061 + net_device_ops_no_const new_ops;
76062 };
76063
76064
76065 diff --git a/net/atm/proc.c b/net/atm/proc.c
76066 index 0d020de..011c7bb 100644
76067 --- a/net/atm/proc.c
76068 +++ b/net/atm/proc.c
76069 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
76070 const struct k_atm_aal_stats *stats)
76071 {
76072 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
76073 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
76074 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
76075 - atomic_read(&stats->rx_drop));
76076 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
76077 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
76078 + atomic_read_unchecked(&stats->rx_drop));
76079 }
76080
76081 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
76082 diff --git a/net/atm/resources.c b/net/atm/resources.c
76083 index 23f45ce..c748f1a 100644
76084 --- a/net/atm/resources.c
76085 +++ b/net/atm/resources.c
76086 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
76087 static void copy_aal_stats(struct k_atm_aal_stats *from,
76088 struct atm_aal_stats *to)
76089 {
76090 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
76091 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
76092 __AAL_STAT_ITEMS
76093 #undef __HANDLE_ITEM
76094 }
76095 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
76096 static void subtract_aal_stats(struct k_atm_aal_stats *from,
76097 struct atm_aal_stats *to)
76098 {
76099 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
76100 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
76101 __AAL_STAT_ITEMS
76102 #undef __HANDLE_ITEM
76103 }
76104 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
76105 index 469daab..262851c 100644
76106 --- a/net/batman-adv/bat_iv_ogm.c
76107 +++ b/net/batman-adv/bat_iv_ogm.c
76108 @@ -62,7 +62,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
76109
76110 /* randomize initial seqno to avoid collision */
76111 get_random_bytes(&random_seqno, sizeof(random_seqno));
76112 - atomic_set(&hard_iface->seqno, random_seqno);
76113 + atomic_set_unchecked(&hard_iface->seqno, random_seqno);
76114
76115 hard_iface->packet_len = BATADV_OGM_HLEN;
76116 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
76117 @@ -600,8 +600,8 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
76118
76119 /* change sequence number to network order */
76120 batadv_ogm_packet->seqno =
76121 - htonl((uint32_t)atomic_read(&hard_iface->seqno));
76122 - atomic_inc(&hard_iface->seqno);
76123 + htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
76124 + atomic_inc_unchecked(&hard_iface->seqno);
76125
76126 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
76127 batadv_ogm_packet->tt_crc = htons(bat_priv->tt_crc);
76128 @@ -1001,7 +1001,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
76129 return;
76130
76131 /* could be changed by schedule_own_packet() */
76132 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
76133 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
76134
76135 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
76136 has_directlink_flag = 1;
76137 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
76138 index 282bf6e..4b2603d 100644
76139 --- a/net/batman-adv/hard-interface.c
76140 +++ b/net/batman-adv/hard-interface.c
76141 @@ -320,7 +320,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
76142 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
76143 dev_add_pack(&hard_iface->batman_adv_ptype);
76144
76145 - atomic_set(&hard_iface->frag_seqno, 1);
76146 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
76147 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
76148 hard_iface->net_dev->name);
76149
76150 @@ -443,7 +443,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
76151 /* This can't be called via a bat_priv callback because
76152 * we have no bat_priv yet.
76153 */
76154 - atomic_set(&hard_iface->seqno, 1);
76155 + atomic_set_unchecked(&hard_iface->seqno, 1);
76156 hard_iface->packet_buff = NULL;
76157
76158 return hard_iface;
76159 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
76160 index 21c5357..768be1a 100644
76161 --- a/net/batman-adv/soft-interface.c
76162 +++ b/net/batman-adv/soft-interface.c
76163 @@ -227,7 +227,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
76164
76165 /* set broadcast sequence number */
76166 bcast_packet->seqno =
76167 - htonl(atomic_inc_return(&bat_priv->bcast_seqno));
76168 + htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
76169
76170 batadv_add_bcast_packet_to_list(bat_priv, skb, 1);
76171
76172 @@ -407,7 +407,7 @@ struct net_device *batadv_softif_create(const char *name)
76173 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
76174
76175 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
76176 - atomic_set(&bat_priv->bcast_seqno, 1);
76177 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
76178 atomic_set(&bat_priv->ttvn, 0);
76179 atomic_set(&bat_priv->tt_local_changes, 0);
76180 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
76181 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
76182 index 12635fd..d99d837 100644
76183 --- a/net/batman-adv/types.h
76184 +++ b/net/batman-adv/types.h
76185 @@ -33,8 +33,8 @@ struct batadv_hard_iface {
76186 int16_t if_num;
76187 char if_status;
76188 struct net_device *net_dev;
76189 - atomic_t seqno;
76190 - atomic_t frag_seqno;
76191 + atomic_unchecked_t seqno;
76192 + atomic_unchecked_t frag_seqno;
76193 unsigned char *packet_buff;
76194 int packet_len;
76195 struct kobject *hardif_obj;
76196 @@ -176,7 +176,7 @@ struct batadv_priv {
76197 atomic_t orig_interval; /* uint */
76198 atomic_t hop_penalty; /* uint */
76199 atomic_t log_level; /* uint */
76200 - atomic_t bcast_seqno;
76201 + atomic_unchecked_t bcast_seqno;
76202 atomic_t bcast_queue_left;
76203 atomic_t batman_queue_left;
76204 atomic_t ttvn; /* translation table version number */
76205 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
76206 index 0016464..0ef3e53 100644
76207 --- a/net/batman-adv/unicast.c
76208 +++ b/net/batman-adv/unicast.c
76209 @@ -269,7 +269,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
76210 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
76211 frag2->flags = large_tail;
76212
76213 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
76214 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
76215 frag1->seqno = htons(seqno - 1);
76216 frag2->seqno = htons(seqno);
76217
76218 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
76219 index d5ace1e..231c4bf 100644
76220 --- a/net/bluetooth/hci_sock.c
76221 +++ b/net/bluetooth/hci_sock.c
76222 @@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
76223 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
76224 }
76225
76226 - len = min_t(unsigned int, len, sizeof(uf));
76227 + len = min((size_t)len, sizeof(uf));
76228 if (copy_from_user(&uf, optval, len)) {
76229 err = -EFAULT;
76230 break;
76231 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
76232 index 38c00f1..e9d566e 100644
76233 --- a/net/bluetooth/l2cap_core.c
76234 +++ b/net/bluetooth/l2cap_core.c
76235 @@ -3165,8 +3165,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
76236 break;
76237
76238 case L2CAP_CONF_RFC:
76239 - if (olen == sizeof(rfc))
76240 - memcpy(&rfc, (void *)val, olen);
76241 + if (olen != sizeof(rfc))
76242 + break;
76243 +
76244 + memcpy(&rfc, (void *)val, olen);
76245
76246 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
76247 rfc.mode != chan->mode)
76248 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
76249 index 34bbe1c..451c19b 100644
76250 --- a/net/bluetooth/l2cap_sock.c
76251 +++ b/net/bluetooth/l2cap_sock.c
76252 @@ -467,7 +467,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
76253 struct sock *sk = sock->sk;
76254 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
76255 struct l2cap_options opts;
76256 - int len, err = 0;
76257 + int err = 0;
76258 + size_t len = optlen;
76259 u32 opt;
76260
76261 BT_DBG("sk %p", sk);
76262 @@ -489,7 +490,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
76263 opts.max_tx = chan->max_tx;
76264 opts.txwin_size = chan->tx_win;
76265
76266 - len = min_t(unsigned int, sizeof(opts), optlen);
76267 + len = min(sizeof(opts), len);
76268 if (copy_from_user((char *) &opts, optval, len)) {
76269 err = -EFAULT;
76270 break;
76271 @@ -567,7 +568,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76272 struct bt_security sec;
76273 struct bt_power pwr;
76274 struct l2cap_conn *conn;
76275 - int len, err = 0;
76276 + int err = 0;
76277 + size_t len = optlen;
76278 u32 opt;
76279
76280 BT_DBG("sk %p", sk);
76281 @@ -590,7 +592,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76282
76283 sec.level = BT_SECURITY_LOW;
76284
76285 - len = min_t(unsigned int, sizeof(sec), optlen);
76286 + len = min(sizeof(sec), len);
76287 if (copy_from_user((char *) &sec, optval, len)) {
76288 err = -EFAULT;
76289 break;
76290 @@ -687,7 +689,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76291
76292 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
76293
76294 - len = min_t(unsigned int, sizeof(pwr), optlen);
76295 + len = min(sizeof(pwr), len);
76296 if (copy_from_user((char *) &pwr, optval, len)) {
76297 err = -EFAULT;
76298 break;
76299 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
76300 index 1a17850..65a3129 100644
76301 --- a/net/bluetooth/rfcomm/sock.c
76302 +++ b/net/bluetooth/rfcomm/sock.c
76303 @@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
76304 struct sock *sk = sock->sk;
76305 struct bt_security sec;
76306 int err = 0;
76307 - size_t len;
76308 + size_t len = optlen;
76309 u32 opt;
76310
76311 BT_DBG("sk %p", sk);
76312 @@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
76313
76314 sec.level = BT_SECURITY_LOW;
76315
76316 - len = min_t(unsigned int, sizeof(sec), optlen);
76317 + len = min(sizeof(sec), len);
76318 if (copy_from_user((char *) &sec, optval, len)) {
76319 err = -EFAULT;
76320 break;
76321 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
76322 index 56f1823..da44330 100644
76323 --- a/net/bluetooth/rfcomm/tty.c
76324 +++ b/net/bluetooth/rfcomm/tty.c
76325 @@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
76326 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
76327
76328 spin_lock_irqsave(&dev->port.lock, flags);
76329 - if (dev->port.count > 0) {
76330 + if (atomic_read(&dev->port.count) > 0) {
76331 spin_unlock_irqrestore(&dev->port.lock, flags);
76332 return;
76333 }
76334 @@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
76335 return -ENODEV;
76336
76337 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
76338 - dev->channel, dev->port.count);
76339 + dev->channel, atomic_read(&dev->port.count));
76340
76341 spin_lock_irqsave(&dev->port.lock, flags);
76342 - if (++dev->port.count > 1) {
76343 + if (atomic_inc_return(&dev->port.count) > 1) {
76344 spin_unlock_irqrestore(&dev->port.lock, flags);
76345 return 0;
76346 }
76347 @@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
76348 return;
76349
76350 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
76351 - dev->port.count);
76352 + atomic_read(&dev->port.count));
76353
76354 spin_lock_irqsave(&dev->port.lock, flags);
76355 - if (!--dev->port.count) {
76356 + if (!atomic_dec_return(&dev->port.count)) {
76357 spin_unlock_irqrestore(&dev->port.lock, flags);
76358 if (dev->tty_dev->parent)
76359 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
76360 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
76361 index 5fe2ff3..121d696 100644
76362 --- a/net/bridge/netfilter/ebtables.c
76363 +++ b/net/bridge/netfilter/ebtables.c
76364 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
76365 tmp.valid_hooks = t->table->valid_hooks;
76366 }
76367 mutex_unlock(&ebt_mutex);
76368 - if (copy_to_user(user, &tmp, *len) != 0){
76369 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
76370 BUGPRINT("c2u Didn't work\n");
76371 ret = -EFAULT;
76372 break;
76373 @@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
76374 goto out;
76375 tmp.valid_hooks = t->valid_hooks;
76376
76377 - if (copy_to_user(user, &tmp, *len) != 0) {
76378 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
76379 ret = -EFAULT;
76380 break;
76381 }
76382 @@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
76383 tmp.entries_size = t->table->entries_size;
76384 tmp.valid_hooks = t->table->valid_hooks;
76385
76386 - if (copy_to_user(user, &tmp, *len) != 0) {
76387 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
76388 ret = -EFAULT;
76389 break;
76390 }
76391 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
76392 index 44f270f..1f5602d 100644
76393 --- a/net/caif/cfctrl.c
76394 +++ b/net/caif/cfctrl.c
76395 @@ -10,6 +10,7 @@
76396 #include <linux/spinlock.h>
76397 #include <linux/slab.h>
76398 #include <linux/pkt_sched.h>
76399 +#include <linux/sched.h>
76400 #include <net/caif/caif_layer.h>
76401 #include <net/caif/cfpkt.h>
76402 #include <net/caif/cfctrl.h>
76403 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
76404 memset(&dev_info, 0, sizeof(dev_info));
76405 dev_info.id = 0xff;
76406 cfsrvl_init(&this->serv, 0, &dev_info, false);
76407 - atomic_set(&this->req_seq_no, 1);
76408 - atomic_set(&this->rsp_seq_no, 1);
76409 + atomic_set_unchecked(&this->req_seq_no, 1);
76410 + atomic_set_unchecked(&this->rsp_seq_no, 1);
76411 this->serv.layer.receive = cfctrl_recv;
76412 sprintf(this->serv.layer.name, "ctrl");
76413 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
76414 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
76415 struct cfctrl_request_info *req)
76416 {
76417 spin_lock_bh(&ctrl->info_list_lock);
76418 - atomic_inc(&ctrl->req_seq_no);
76419 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
76420 + atomic_inc_unchecked(&ctrl->req_seq_no);
76421 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
76422 list_add_tail(&req->list, &ctrl->list);
76423 spin_unlock_bh(&ctrl->info_list_lock);
76424 }
76425 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
76426 if (p != first)
76427 pr_warn("Requests are not received in order\n");
76428
76429 - atomic_set(&ctrl->rsp_seq_no,
76430 + atomic_set_unchecked(&ctrl->rsp_seq_no,
76431 p->sequence_no);
76432 list_del(&p->list);
76433 goto out;
76434 diff --git a/net/can/gw.c b/net/can/gw.c
76435 index b54d5e6..91c3b25 100644
76436 --- a/net/can/gw.c
76437 +++ b/net/can/gw.c
76438 @@ -96,7 +96,7 @@ struct cf_mod {
76439 struct {
76440 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
76441 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
76442 - } csumfunc;
76443 + } __no_const csumfunc;
76444 };
76445
76446
76447 diff --git a/net/compat.c b/net/compat.c
76448 index 74ed1d7..3695bd9 100644
76449 --- a/net/compat.c
76450 +++ b/net/compat.c
76451 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
76452 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
76453 __get_user(kmsg->msg_flags, &umsg->msg_flags))
76454 return -EFAULT;
76455 - kmsg->msg_name = compat_ptr(tmp1);
76456 - kmsg->msg_iov = compat_ptr(tmp2);
76457 - kmsg->msg_control = compat_ptr(tmp3);
76458 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
76459 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
76460 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
76461 return 0;
76462 }
76463
76464 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76465
76466 if (kern_msg->msg_namelen) {
76467 if (mode == VERIFY_READ) {
76468 - int err = move_addr_to_kernel(kern_msg->msg_name,
76469 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
76470 kern_msg->msg_namelen,
76471 kern_address);
76472 if (err < 0)
76473 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76474 kern_msg->msg_name = NULL;
76475
76476 tot_len = iov_from_user_compat_to_kern(kern_iov,
76477 - (struct compat_iovec __user *)kern_msg->msg_iov,
76478 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
76479 kern_msg->msg_iovlen);
76480 if (tot_len >= 0)
76481 kern_msg->msg_iov = kern_iov;
76482 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76483
76484 #define CMSG_COMPAT_FIRSTHDR(msg) \
76485 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
76486 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
76487 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
76488 (struct compat_cmsghdr __user *)NULL)
76489
76490 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
76491 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
76492 (ucmlen) <= (unsigned long) \
76493 ((mhdr)->msg_controllen - \
76494 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
76495 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
76496
76497 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
76498 struct compat_cmsghdr __user *cmsg, int cmsg_len)
76499 {
76500 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
76501 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
76502 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
76503 msg->msg_controllen)
76504 return NULL;
76505 return (struct compat_cmsghdr __user *)ptr;
76506 @@ -219,7 +219,7 @@ Efault:
76507
76508 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
76509 {
76510 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
76511 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
76512 struct compat_cmsghdr cmhdr;
76513 struct compat_timeval ctv;
76514 struct compat_timespec cts[3];
76515 @@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
76516
76517 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
76518 {
76519 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
76520 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
76521 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
76522 int fdnum = scm->fp->count;
76523 struct file **fp = scm->fp->fp;
76524 @@ -364,7 +364,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
76525 return -EFAULT;
76526 old_fs = get_fs();
76527 set_fs(KERNEL_DS);
76528 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
76529 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
76530 set_fs(old_fs);
76531
76532 return err;
76533 @@ -425,7 +425,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
76534 len = sizeof(ktime);
76535 old_fs = get_fs();
76536 set_fs(KERNEL_DS);
76537 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
76538 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
76539 set_fs(old_fs);
76540
76541 if (!err) {
76542 @@ -568,7 +568,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76543 case MCAST_JOIN_GROUP:
76544 case MCAST_LEAVE_GROUP:
76545 {
76546 - struct compat_group_req __user *gr32 = (void *)optval;
76547 + struct compat_group_req __user *gr32 = (void __user *)optval;
76548 struct group_req __user *kgr =
76549 compat_alloc_user_space(sizeof(struct group_req));
76550 u32 interface;
76551 @@ -589,7 +589,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76552 case MCAST_BLOCK_SOURCE:
76553 case MCAST_UNBLOCK_SOURCE:
76554 {
76555 - struct compat_group_source_req __user *gsr32 = (void *)optval;
76556 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
76557 struct group_source_req __user *kgsr = compat_alloc_user_space(
76558 sizeof(struct group_source_req));
76559 u32 interface;
76560 @@ -610,7 +610,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76561 }
76562 case MCAST_MSFILTER:
76563 {
76564 - struct compat_group_filter __user *gf32 = (void *)optval;
76565 + struct compat_group_filter __user *gf32 = (void __user *)optval;
76566 struct group_filter __user *kgf;
76567 u32 interface, fmode, numsrc;
76568
76569 @@ -648,7 +648,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
76570 char __user *optval, int __user *optlen,
76571 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
76572 {
76573 - struct compat_group_filter __user *gf32 = (void *)optval;
76574 + struct compat_group_filter __user *gf32 = (void __user *)optval;
76575 struct group_filter __user *kgf;
76576 int __user *koptlen;
76577 u32 interface, fmode, numsrc;
76578 @@ -797,7 +797,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
76579
76580 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
76581 return -EINVAL;
76582 - if (copy_from_user(a, args, nas[call]))
76583 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
76584 return -EFAULT;
76585 a0 = a[0];
76586 a1 = a[1];
76587 diff --git a/net/core/datagram.c b/net/core/datagram.c
76588 index 0337e2b..47914a0 100644
76589 --- a/net/core/datagram.c
76590 +++ b/net/core/datagram.c
76591 @@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
76592 }
76593
76594 kfree_skb(skb);
76595 - atomic_inc(&sk->sk_drops);
76596 + atomic_inc_unchecked(&sk->sk_drops);
76597 sk_mem_reclaim_partial(sk);
76598
76599 return err;
76600 diff --git a/net/core/dev.c b/net/core/dev.c
76601 index 2fb9f59..d9a07df 100644
76602 --- a/net/core/dev.c
76603 +++ b/net/core/dev.c
76604 @@ -1138,9 +1138,13 @@ void dev_load(struct net *net, const char *name)
76605 if (no_module && capable(CAP_NET_ADMIN))
76606 no_module = request_module("netdev-%s", name);
76607 if (no_module && capable(CAP_SYS_MODULE)) {
76608 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
76609 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
76610 +#else
76611 if (!request_module("%s", name))
76612 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
76613 name);
76614 +#endif
76615 }
76616 }
76617 EXPORT_SYMBOL(dev_load);
76618 @@ -1605,7 +1609,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
76619 {
76620 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
76621 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
76622 - atomic_long_inc(&dev->rx_dropped);
76623 + atomic_long_inc_unchecked(&dev->rx_dropped);
76624 kfree_skb(skb);
76625 return NET_RX_DROP;
76626 }
76627 @@ -1615,7 +1619,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
76628 nf_reset(skb);
76629
76630 if (unlikely(!is_skb_forwardable(dev, skb))) {
76631 - atomic_long_inc(&dev->rx_dropped);
76632 + atomic_long_inc_unchecked(&dev->rx_dropped);
76633 kfree_skb(skb);
76634 return NET_RX_DROP;
76635 }
76636 @@ -2071,7 +2075,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
76637
76638 struct dev_gso_cb {
76639 void (*destructor)(struct sk_buff *skb);
76640 -};
76641 +} __no_const;
76642
76643 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
76644
76645 @@ -2928,7 +2932,7 @@ enqueue:
76646
76647 local_irq_restore(flags);
76648
76649 - atomic_long_inc(&skb->dev->rx_dropped);
76650 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
76651 kfree_skb(skb);
76652 return NET_RX_DROP;
76653 }
76654 @@ -3000,7 +3004,7 @@ int netif_rx_ni(struct sk_buff *skb)
76655 }
76656 EXPORT_SYMBOL(netif_rx_ni);
76657
76658 -static void net_tx_action(struct softirq_action *h)
76659 +static void net_tx_action(void)
76660 {
76661 struct softnet_data *sd = &__get_cpu_var(softnet_data);
76662
76663 @@ -3331,7 +3335,7 @@ ncls:
76664 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
76665 } else {
76666 drop:
76667 - atomic_long_inc(&skb->dev->rx_dropped);
76668 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
76669 kfree_skb(skb);
76670 /* Jamal, now you will not able to escape explaining
76671 * me how you were going to use this. :-)
76672 @@ -3898,7 +3902,7 @@ void netif_napi_del(struct napi_struct *napi)
76673 }
76674 EXPORT_SYMBOL(netif_napi_del);
76675
76676 -static void net_rx_action(struct softirq_action *h)
76677 +static void net_rx_action(void)
76678 {
76679 struct softnet_data *sd = &__get_cpu_var(softnet_data);
76680 unsigned long time_limit = jiffies + 2;
76681 @@ -4368,8 +4372,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
76682 else
76683 seq_printf(seq, "%04x", ntohs(pt->type));
76684
76685 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76686 + seq_printf(seq, " %-8s %p\n",
76687 + pt->dev ? pt->dev->name : "", NULL);
76688 +#else
76689 seq_printf(seq, " %-8s %pF\n",
76690 pt->dev ? pt->dev->name : "", pt->func);
76691 +#endif
76692 }
76693
76694 return 0;
76695 @@ -5922,7 +5931,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
76696 } else {
76697 netdev_stats_to_stats64(storage, &dev->stats);
76698 }
76699 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
76700 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
76701 return storage;
76702 }
76703 EXPORT_SYMBOL(dev_get_stats);
76704 diff --git a/net/core/flow.c b/net/core/flow.c
76705 index e318c7e..168b1d0 100644
76706 --- a/net/core/flow.c
76707 +++ b/net/core/flow.c
76708 @@ -61,7 +61,7 @@ struct flow_cache {
76709 struct timer_list rnd_timer;
76710 };
76711
76712 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
76713 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
76714 EXPORT_SYMBOL(flow_cache_genid);
76715 static struct flow_cache flow_cache_global;
76716 static struct kmem_cache *flow_cachep __read_mostly;
76717 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
76718
76719 static int flow_entry_valid(struct flow_cache_entry *fle)
76720 {
76721 - if (atomic_read(&flow_cache_genid) != fle->genid)
76722 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
76723 return 0;
76724 if (fle->object && !fle->object->ops->check(fle->object))
76725 return 0;
76726 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
76727 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
76728 fcp->hash_count++;
76729 }
76730 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
76731 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
76732 flo = fle->object;
76733 if (!flo)
76734 goto ret_object;
76735 @@ -280,7 +280,7 @@ nocache:
76736 }
76737 flo = resolver(net, key, family, dir, flo, ctx);
76738 if (fle) {
76739 - fle->genid = atomic_read(&flow_cache_genid);
76740 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
76741 if (!IS_ERR(flo))
76742 fle->object = flo;
76743 else
76744 diff --git a/net/core/iovec.c b/net/core/iovec.c
76745 index 7e7aeb0..2a998cb 100644
76746 --- a/net/core/iovec.c
76747 +++ b/net/core/iovec.c
76748 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
76749 if (m->msg_namelen) {
76750 if (mode == VERIFY_READ) {
76751 void __user *namep;
76752 - namep = (void __user __force *) m->msg_name;
76753 + namep = (void __force_user *) m->msg_name;
76754 err = move_addr_to_kernel(namep, m->msg_namelen,
76755 address);
76756 if (err < 0)
76757 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
76758 }
76759
76760 size = m->msg_iovlen * sizeof(struct iovec);
76761 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
76762 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
76763 return -EFAULT;
76764
76765 m->msg_iov = iov;
76766 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
76767 index 2c5a0a0..a45f90c 100644
76768 --- a/net/core/rtnetlink.c
76769 +++ b/net/core/rtnetlink.c
76770 @@ -58,7 +58,7 @@ struct rtnl_link {
76771 rtnl_doit_func doit;
76772 rtnl_dumpit_func dumpit;
76773 rtnl_calcit_func calcit;
76774 -};
76775 +} __no_const;
76776
76777 static DEFINE_MUTEX(rtnl_mutex);
76778
76779 diff --git a/net/core/scm.c b/net/core/scm.c
76780 index 040cebe..5b1e312 100644
76781 --- a/net/core/scm.c
76782 +++ b/net/core/scm.c
76783 @@ -203,7 +203,7 @@ EXPORT_SYMBOL(__scm_send);
76784 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
76785 {
76786 struct cmsghdr __user *cm
76787 - = (__force struct cmsghdr __user *)msg->msg_control;
76788 + = (struct cmsghdr __force_user *)msg->msg_control;
76789 struct cmsghdr cmhdr;
76790 int cmlen = CMSG_LEN(len);
76791 int err;
76792 @@ -226,7 +226,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
76793 err = -EFAULT;
76794 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
76795 goto out;
76796 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
76797 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
76798 goto out;
76799 cmlen = CMSG_SPACE(len);
76800 if (msg->msg_controllen < cmlen)
76801 @@ -242,7 +242,7 @@ EXPORT_SYMBOL(put_cmsg);
76802 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
76803 {
76804 struct cmsghdr __user *cm
76805 - = (__force struct cmsghdr __user*)msg->msg_control;
76806 + = (struct cmsghdr __force_user *)msg->msg_control;
76807
76808 int fdmax = 0;
76809 int fdnum = scm->fp->count;
76810 @@ -262,7 +262,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
76811 if (fdnum < fdmax)
76812 fdmax = fdnum;
76813
76814 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
76815 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
76816 i++, cmfptr++)
76817 {
76818 struct socket *sock;
76819 diff --git a/net/core/sock.c b/net/core/sock.c
76820 index a6000fb..d4aee72 100644
76821 --- a/net/core/sock.c
76822 +++ b/net/core/sock.c
76823 @@ -399,7 +399,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76824 struct sk_buff_head *list = &sk->sk_receive_queue;
76825
76826 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
76827 - atomic_inc(&sk->sk_drops);
76828 + atomic_inc_unchecked(&sk->sk_drops);
76829 trace_sock_rcvqueue_full(sk, skb);
76830 return -ENOMEM;
76831 }
76832 @@ -409,7 +409,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76833 return err;
76834
76835 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
76836 - atomic_inc(&sk->sk_drops);
76837 + atomic_inc_unchecked(&sk->sk_drops);
76838 return -ENOBUFS;
76839 }
76840
76841 @@ -429,7 +429,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76842 skb_dst_force(skb);
76843
76844 spin_lock_irqsave(&list->lock, flags);
76845 - skb->dropcount = atomic_read(&sk->sk_drops);
76846 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
76847 __skb_queue_tail(list, skb);
76848 spin_unlock_irqrestore(&list->lock, flags);
76849
76850 @@ -449,7 +449,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
76851 skb->dev = NULL;
76852
76853 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
76854 - atomic_inc(&sk->sk_drops);
76855 + atomic_inc_unchecked(&sk->sk_drops);
76856 goto discard_and_relse;
76857 }
76858 if (nested)
76859 @@ -467,7 +467,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
76860 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
76861 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
76862 bh_unlock_sock(sk);
76863 - atomic_inc(&sk->sk_drops);
76864 + atomic_inc_unchecked(&sk->sk_drops);
76865 goto discard_and_relse;
76866 }
76867
76868 @@ -886,12 +886,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76869 struct timeval tm;
76870 } v;
76871
76872 - int lv = sizeof(int);
76873 - int len;
76874 + unsigned int lv = sizeof(int);
76875 + unsigned int len;
76876
76877 if (get_user(len, optlen))
76878 return -EFAULT;
76879 - if (len < 0)
76880 + if (len > INT_MAX)
76881 return -EINVAL;
76882
76883 memset(&v, 0, sizeof(v));
76884 @@ -1039,11 +1039,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76885
76886 case SO_PEERNAME:
76887 {
76888 - char address[128];
76889 + char address[_K_SS_MAXSIZE];
76890
76891 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
76892 return -ENOTCONN;
76893 - if (lv < len)
76894 + if (lv < len || sizeof address < len)
76895 return -EINVAL;
76896 if (copy_to_user(optval, address, len))
76897 return -EFAULT;
76898 @@ -1091,7 +1091,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76899
76900 if (len > lv)
76901 len = lv;
76902 - if (copy_to_user(optval, &v, len))
76903 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
76904 return -EFAULT;
76905 lenout:
76906 if (put_user(len, optlen))
76907 @@ -2193,7 +2193,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
76908 */
76909 smp_wmb();
76910 atomic_set(&sk->sk_refcnt, 1);
76911 - atomic_set(&sk->sk_drops, 0);
76912 + atomic_set_unchecked(&sk->sk_drops, 0);
76913 }
76914 EXPORT_SYMBOL(sock_init_data);
76915
76916 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
76917 index 9d8755e..26de8bc 100644
76918 --- a/net/core/sock_diag.c
76919 +++ b/net/core/sock_diag.c
76920 @@ -15,20 +15,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
76921
76922 int sock_diag_check_cookie(void *sk, __u32 *cookie)
76923 {
76924 +#ifndef CONFIG_GRKERNSEC_HIDESYM
76925 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
76926 cookie[1] != INET_DIAG_NOCOOKIE) &&
76927 ((u32)(unsigned long)sk != cookie[0] ||
76928 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
76929 return -ESTALE;
76930 else
76931 +#endif
76932 return 0;
76933 }
76934 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
76935
76936 void sock_diag_save_cookie(void *sk, __u32 *cookie)
76937 {
76938 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76939 + cookie[0] = 0;
76940 + cookie[1] = 0;
76941 +#else
76942 cookie[0] = (u32)(unsigned long)sk;
76943 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
76944 +#endif
76945 }
76946 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
76947
76948 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
76949 index a55eecc..dd8428c 100644
76950 --- a/net/decnet/sysctl_net_decnet.c
76951 +++ b/net/decnet/sysctl_net_decnet.c
76952 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
76953
76954 if (len > *lenp) len = *lenp;
76955
76956 - if (copy_to_user(buffer, addr, len))
76957 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
76958 return -EFAULT;
76959
76960 *lenp = len;
76961 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
76962
76963 if (len > *lenp) len = *lenp;
76964
76965 - if (copy_to_user(buffer, devname, len))
76966 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
76967 return -EFAULT;
76968
76969 *lenp = len;
76970 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
76971 index f444ac7..b7bdda9 100644
76972 --- a/net/ipv4/fib_frontend.c
76973 +++ b/net/ipv4/fib_frontend.c
76974 @@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
76975 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76976 fib_sync_up(dev);
76977 #endif
76978 - atomic_inc(&net->ipv4.dev_addr_genid);
76979 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76980 rt_cache_flush(dev_net(dev));
76981 break;
76982 case NETDEV_DOWN:
76983 fib_del_ifaddr(ifa, NULL);
76984 - atomic_inc(&net->ipv4.dev_addr_genid);
76985 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76986 if (ifa->ifa_dev->ifa_list == NULL) {
76987 /* Last address was deleted from this interface.
76988 * Disable IP.
76989 @@ -1062,7 +1062,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
76990 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76991 fib_sync_up(dev);
76992 #endif
76993 - atomic_inc(&net->ipv4.dev_addr_genid);
76994 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76995 rt_cache_flush(dev_net(dev));
76996 break;
76997 case NETDEV_DOWN:
76998 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
76999 index 9633661..4e0bc08 100644
77000 --- a/net/ipv4/fib_semantics.c
77001 +++ b/net/ipv4/fib_semantics.c
77002 @@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
77003 nh->nh_saddr = inet_select_addr(nh->nh_dev,
77004 nh->nh_gw,
77005 nh->nh_parent->fib_scope);
77006 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
77007 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
77008
77009 return nh->nh_saddr;
77010 }
77011 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
77012 index 7880af9..70f92a3 100644
77013 --- a/net/ipv4/inet_hashtables.c
77014 +++ b/net/ipv4/inet_hashtables.c
77015 @@ -18,12 +18,15 @@
77016 #include <linux/sched.h>
77017 #include <linux/slab.h>
77018 #include <linux/wait.h>
77019 +#include <linux/security.h>
77020
77021 #include <net/inet_connection_sock.h>
77022 #include <net/inet_hashtables.h>
77023 #include <net/secure_seq.h>
77024 #include <net/ip.h>
77025
77026 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
77027 +
77028 /*
77029 * Allocate and initialize a new local port bind bucket.
77030 * The bindhash mutex for snum's hash chain must be held here.
77031 @@ -530,6 +533,8 @@ ok:
77032 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
77033 spin_unlock(&head->lock);
77034
77035 + gr_update_task_in_ip_table(current, inet_sk(sk));
77036 +
77037 if (tw) {
77038 inet_twsk_deschedule(tw, death_row);
77039 while (twrefcnt) {
77040 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
77041 index c7527f6..d8bba61 100644
77042 --- a/net/ipv4/inetpeer.c
77043 +++ b/net/ipv4/inetpeer.c
77044 @@ -503,8 +503,8 @@ relookup:
77045 if (p) {
77046 p->daddr = *daddr;
77047 atomic_set(&p->refcnt, 1);
77048 - atomic_set(&p->rid, 0);
77049 - atomic_set(&p->ip_id_count,
77050 + atomic_set_unchecked(&p->rid, 0);
77051 + atomic_set_unchecked(&p->ip_id_count,
77052 (daddr->family == AF_INET) ?
77053 secure_ip_id(daddr->addr.a4) :
77054 secure_ipv6_id(daddr->addr.a6));
77055 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
77056 index 8d07c97..d0812ef 100644
77057 --- a/net/ipv4/ip_fragment.c
77058 +++ b/net/ipv4/ip_fragment.c
77059 @@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
77060 return 0;
77061
77062 start = qp->rid;
77063 - end = atomic_inc_return(&peer->rid);
77064 + end = atomic_inc_return_unchecked(&peer->rid);
77065 qp->rid = end;
77066
77067 rc = qp->q.fragments && (end - start) > max;
77068 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
77069 index 5eea4a8..49819c2 100644
77070 --- a/net/ipv4/ip_sockglue.c
77071 +++ b/net/ipv4/ip_sockglue.c
77072 @@ -1142,7 +1142,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
77073 len = min_t(unsigned int, len, opt->optlen);
77074 if (put_user(len, optlen))
77075 return -EFAULT;
77076 - if (copy_to_user(optval, opt->__data, len))
77077 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
77078 + copy_to_user(optval, opt->__data, len))
77079 return -EFAULT;
77080 return 0;
77081 }
77082 @@ -1273,7 +1274,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
77083 if (sk->sk_type != SOCK_STREAM)
77084 return -ENOPROTOOPT;
77085
77086 - msg.msg_control = optval;
77087 + msg.msg_control = (void __force_kernel *)optval;
77088 msg.msg_controllen = len;
77089 msg.msg_flags = flags;
77090
77091 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
77092 index 67e8a6b..386764d 100644
77093 --- a/net/ipv4/ipconfig.c
77094 +++ b/net/ipv4/ipconfig.c
77095 @@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
77096
77097 mm_segment_t oldfs = get_fs();
77098 set_fs(get_ds());
77099 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
77100 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
77101 set_fs(oldfs);
77102 return res;
77103 }
77104 @@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
77105
77106 mm_segment_t oldfs = get_fs();
77107 set_fs(get_ds());
77108 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
77109 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
77110 set_fs(oldfs);
77111 return res;
77112 }
77113 @@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
77114
77115 mm_segment_t oldfs = get_fs();
77116 set_fs(get_ds());
77117 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
77118 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
77119 set_fs(oldfs);
77120 return res;
77121 }
77122 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
77123 index 97e61ea..cac1bbb 100644
77124 --- a/net/ipv4/netfilter/arp_tables.c
77125 +++ b/net/ipv4/netfilter/arp_tables.c
77126 @@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
77127 #endif
77128
77129 static int get_info(struct net *net, void __user *user,
77130 - const int *len, int compat)
77131 + int len, int compat)
77132 {
77133 char name[XT_TABLE_MAXNAMELEN];
77134 struct xt_table *t;
77135 int ret;
77136
77137 - if (*len != sizeof(struct arpt_getinfo)) {
77138 - duprintf("length %u != %Zu\n", *len,
77139 + if (len != sizeof(struct arpt_getinfo)) {
77140 + duprintf("length %u != %Zu\n", len,
77141 sizeof(struct arpt_getinfo));
77142 return -EINVAL;
77143 }
77144 @@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
77145 info.size = private->size;
77146 strcpy(info.name, name);
77147
77148 - if (copy_to_user(user, &info, *len) != 0)
77149 + if (copy_to_user(user, &info, len) != 0)
77150 ret = -EFAULT;
77151 else
77152 ret = 0;
77153 @@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
77154
77155 switch (cmd) {
77156 case ARPT_SO_GET_INFO:
77157 - ret = get_info(sock_net(sk), user, len, 1);
77158 + ret = get_info(sock_net(sk), user, *len, 1);
77159 break;
77160 case ARPT_SO_GET_ENTRIES:
77161 ret = compat_get_entries(sock_net(sk), user, len);
77162 @@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
77163
77164 switch (cmd) {
77165 case ARPT_SO_GET_INFO:
77166 - ret = get_info(sock_net(sk), user, len, 0);
77167 + ret = get_info(sock_net(sk), user, *len, 0);
77168 break;
77169
77170 case ARPT_SO_GET_ENTRIES:
77171 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
77172 index 170b1fd..6105b91 100644
77173 --- a/net/ipv4/netfilter/ip_tables.c
77174 +++ b/net/ipv4/netfilter/ip_tables.c
77175 @@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
77176 #endif
77177
77178 static int get_info(struct net *net, void __user *user,
77179 - const int *len, int compat)
77180 + int len, int compat)
77181 {
77182 char name[XT_TABLE_MAXNAMELEN];
77183 struct xt_table *t;
77184 int ret;
77185
77186 - if (*len != sizeof(struct ipt_getinfo)) {
77187 - duprintf("length %u != %zu\n", *len,
77188 + if (len != sizeof(struct ipt_getinfo)) {
77189 + duprintf("length %u != %zu\n", len,
77190 sizeof(struct ipt_getinfo));
77191 return -EINVAL;
77192 }
77193 @@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
77194 info.size = private->size;
77195 strcpy(info.name, name);
77196
77197 - if (copy_to_user(user, &info, *len) != 0)
77198 + if (copy_to_user(user, &info, len) != 0)
77199 ret = -EFAULT;
77200 else
77201 ret = 0;
77202 @@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77203
77204 switch (cmd) {
77205 case IPT_SO_GET_INFO:
77206 - ret = get_info(sock_net(sk), user, len, 1);
77207 + ret = get_info(sock_net(sk), user, *len, 1);
77208 break;
77209 case IPT_SO_GET_ENTRIES:
77210 ret = compat_get_entries(sock_net(sk), user, len);
77211 @@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77212
77213 switch (cmd) {
77214 case IPT_SO_GET_INFO:
77215 - ret = get_info(sock_net(sk), user, len, 0);
77216 + ret = get_info(sock_net(sk), user, *len, 0);
77217 break;
77218
77219 case IPT_SO_GET_ENTRIES:
77220 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
77221 index 6232d47..6b88607 100644
77222 --- a/net/ipv4/ping.c
77223 +++ b/net/ipv4/ping.c
77224 @@ -847,7 +847,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
77225 sk_rmem_alloc_get(sp),
77226 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77227 atomic_read(&sp->sk_refcnt), sp,
77228 - atomic_read(&sp->sk_drops), len);
77229 + atomic_read_unchecked(&sp->sk_drops), len);
77230 }
77231
77232 static int ping_seq_show(struct seq_file *seq, void *v)
77233 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
77234 index d23c657..cb69cc2 100644
77235 --- a/net/ipv4/raw.c
77236 +++ b/net/ipv4/raw.c
77237 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
77238 int raw_rcv(struct sock *sk, struct sk_buff *skb)
77239 {
77240 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
77241 - atomic_inc(&sk->sk_drops);
77242 + atomic_inc_unchecked(&sk->sk_drops);
77243 kfree_skb(skb);
77244 return NET_RX_DROP;
77245 }
77246 @@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
77247
77248 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
77249 {
77250 + struct icmp_filter filter;
77251 +
77252 if (optlen > sizeof(struct icmp_filter))
77253 optlen = sizeof(struct icmp_filter);
77254 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
77255 + if (copy_from_user(&filter, optval, optlen))
77256 return -EFAULT;
77257 + raw_sk(sk)->filter = filter;
77258 return 0;
77259 }
77260
77261 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
77262 {
77263 int len, ret = -EFAULT;
77264 + struct icmp_filter filter;
77265
77266 if (get_user(len, optlen))
77267 goto out;
77268 @@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
77269 if (len > sizeof(struct icmp_filter))
77270 len = sizeof(struct icmp_filter);
77271 ret = -EFAULT;
77272 - if (put_user(len, optlen) ||
77273 - copy_to_user(optval, &raw_sk(sk)->filter, len))
77274 + filter = raw_sk(sk)->filter;
77275 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
77276 goto out;
77277 ret = 0;
77278 out: return ret;
77279 @@ -995,7 +999,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
77280 sk_wmem_alloc_get(sp),
77281 sk_rmem_alloc_get(sp),
77282 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77283 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
77284 + atomic_read(&sp->sk_refcnt),
77285 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77286 + NULL,
77287 +#else
77288 + sp,
77289 +#endif
77290 + atomic_read_unchecked(&sp->sk_drops));
77291 }
77292
77293 static int raw_seq_show(struct seq_file *seq, void *v)
77294 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
77295 index 2a1383c..ff99572 100644
77296 --- a/net/ipv4/route.c
77297 +++ b/net/ipv4/route.c
77298 @@ -2523,7 +2523,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
77299
77300 static __net_init int rt_genid_init(struct net *net)
77301 {
77302 - atomic_set(&net->rt_genid, 0);
77303 + atomic_set_unchecked(&net->rt_genid, 0);
77304 get_random_bytes(&net->ipv4.dev_addr_genid,
77305 sizeof(net->ipv4.dev_addr_genid));
77306 return 0;
77307 diff --git a/net/ipv4/tcp_illinois.c b/net/ipv4/tcp_illinois.c
77308 index 813b43a..834857f 100644
77309 --- a/net/ipv4/tcp_illinois.c
77310 +++ b/net/ipv4/tcp_illinois.c
77311 @@ -313,11 +313,13 @@ static void tcp_illinois_info(struct sock *sk, u32 ext,
77312 .tcpv_rttcnt = ca->cnt_rtt,
77313 .tcpv_minrtt = ca->base_rtt,
77314 };
77315 - u64 t = ca->sum_rtt;
77316
77317 - do_div(t, ca->cnt_rtt);
77318 - info.tcpv_rtt = t;
77319 + if (info.tcpv_rttcnt > 0) {
77320 + u64 t = ca->sum_rtt;
77321
77322 + do_div(t, info.tcpv_rttcnt);
77323 + info.tcpv_rtt = t;
77324 + }
77325 nla_put(skb, INET_DIAG_VEGASINFO, sizeof(info), &info);
77326 }
77327 }
77328 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
77329 index d377f48..f19e3ec 100644
77330 --- a/net/ipv4/tcp_input.c
77331 +++ b/net/ipv4/tcp_input.c
77332 @@ -4556,6 +4556,9 @@ int tcp_send_rcvq(struct sock *sk, struct msghdr *msg, size_t size)
77333 struct tcphdr *th;
77334 bool fragstolen;
77335
77336 + if (size == 0)
77337 + return 0;
77338 +
77339 skb = alloc_skb(size + sizeof(*th), sk->sk_allocation);
77340 if (!skb)
77341 goto err;
77342 @@ -4728,7 +4731,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
77343 * simplifies code)
77344 */
77345 static void
77346 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
77347 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
77348 struct sk_buff *head, struct sk_buff *tail,
77349 u32 start, u32 end)
77350 {
77351 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
77352 index db7bfad..bfea796 100644
77353 --- a/net/ipv4/tcp_ipv4.c
77354 +++ b/net/ipv4/tcp_ipv4.c
77355 @@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
77356 EXPORT_SYMBOL(sysctl_tcp_low_latency);
77357
77358
77359 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77360 +extern int grsec_enable_blackhole;
77361 +#endif
77362 +
77363 #ifdef CONFIG_TCP_MD5SIG
77364 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
77365 __be32 daddr, __be32 saddr, const struct tcphdr *th);
77366 @@ -1664,6 +1668,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
77367 return 0;
77368
77369 reset:
77370 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77371 + if (!grsec_enable_blackhole)
77372 +#endif
77373 tcp_v4_send_reset(rsk, skb);
77374 discard:
77375 kfree_skb(skb);
77376 @@ -1764,12 +1771,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
77377 TCP_SKB_CB(skb)->sacked = 0;
77378
77379 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
77380 - if (!sk)
77381 + if (!sk) {
77382 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77383 + ret = 1;
77384 +#endif
77385 goto no_tcp_socket;
77386 -
77387 + }
77388 process:
77389 - if (sk->sk_state == TCP_TIME_WAIT)
77390 + if (sk->sk_state == TCP_TIME_WAIT) {
77391 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77392 + ret = 2;
77393 +#endif
77394 goto do_time_wait;
77395 + }
77396
77397 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
77398 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
77399 @@ -1820,6 +1834,10 @@ no_tcp_socket:
77400 bad_packet:
77401 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
77402 } else {
77403 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77404 + if (!grsec_enable_blackhole || (ret == 1 &&
77405 + (skb->dev->flags & IFF_LOOPBACK)))
77406 +#endif
77407 tcp_v4_send_reset(NULL, skb);
77408 }
77409
77410 @@ -2415,7 +2433,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
77411 0, /* non standard timer */
77412 0, /* open_requests have no inode */
77413 atomic_read(&sk->sk_refcnt),
77414 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77415 + NULL,
77416 +#else
77417 req,
77418 +#endif
77419 len);
77420 }
77421
77422 @@ -2465,7 +2487,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
77423 sock_i_uid(sk),
77424 icsk->icsk_probes_out,
77425 sock_i_ino(sk),
77426 - atomic_read(&sk->sk_refcnt), sk,
77427 + atomic_read(&sk->sk_refcnt),
77428 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77429 + NULL,
77430 +#else
77431 + sk,
77432 +#endif
77433 jiffies_to_clock_t(icsk->icsk_rto),
77434 jiffies_to_clock_t(icsk->icsk_ack.ato),
77435 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
77436 @@ -2493,7 +2520,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
77437 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
77438 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
77439 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
77440 - atomic_read(&tw->tw_refcnt), tw, len);
77441 + atomic_read(&tw->tw_refcnt),
77442 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77443 + NULL,
77444 +#else
77445 + tw,
77446 +#endif
77447 + len);
77448 }
77449
77450 #define TMPSZ 150
77451 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
77452 index 6ff7f10..38de56e 100644
77453 --- a/net/ipv4/tcp_minisocks.c
77454 +++ b/net/ipv4/tcp_minisocks.c
77455 @@ -27,6 +27,10 @@
77456 #include <net/inet_common.h>
77457 #include <net/xfrm.h>
77458
77459 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77460 +extern int grsec_enable_blackhole;
77461 +#endif
77462 +
77463 int sysctl_tcp_syncookies __read_mostly = 1;
77464 EXPORT_SYMBOL(sysctl_tcp_syncookies);
77465
77466 @@ -707,6 +711,10 @@ listen_overflow:
77467
77468 embryonic_reset:
77469 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
77470 +
77471 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77472 + if (!grsec_enable_blackhole)
77473 +#endif
77474 if (!(flg & TCP_FLAG_RST))
77475 req->rsk_ops->send_reset(sk, skb);
77476
77477 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
77478 index 4526fe6..1a34e43 100644
77479 --- a/net/ipv4/tcp_probe.c
77480 +++ b/net/ipv4/tcp_probe.c
77481 @@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
77482 if (cnt + width >= len)
77483 break;
77484
77485 - if (copy_to_user(buf + cnt, tbuf, width))
77486 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
77487 return -EFAULT;
77488 cnt += width;
77489 }
77490 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
77491 index b774a03..3873efe 100644
77492 --- a/net/ipv4/tcp_timer.c
77493 +++ b/net/ipv4/tcp_timer.c
77494 @@ -22,6 +22,10 @@
77495 #include <linux/gfp.h>
77496 #include <net/tcp.h>
77497
77498 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77499 +extern int grsec_lastack_retries;
77500 +#endif
77501 +
77502 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
77503 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
77504 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
77505 @@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
77506 }
77507 }
77508
77509 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77510 + if ((sk->sk_state == TCP_LAST_ACK) &&
77511 + (grsec_lastack_retries > 0) &&
77512 + (grsec_lastack_retries < retry_until))
77513 + retry_until = grsec_lastack_retries;
77514 +#endif
77515 +
77516 if (retransmits_timed_out(sk, retry_until,
77517 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
77518 /* Has it gone just too far? */
77519 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
77520 index 2814f66..fa2b223 100644
77521 --- a/net/ipv4/udp.c
77522 +++ b/net/ipv4/udp.c
77523 @@ -87,6 +87,7 @@
77524 #include <linux/types.h>
77525 #include <linux/fcntl.h>
77526 #include <linux/module.h>
77527 +#include <linux/security.h>
77528 #include <linux/socket.h>
77529 #include <linux/sockios.h>
77530 #include <linux/igmp.h>
77531 @@ -111,6 +112,10 @@
77532 #include <trace/events/skb.h>
77533 #include "udp_impl.h"
77534
77535 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77536 +extern int grsec_enable_blackhole;
77537 +#endif
77538 +
77539 struct udp_table udp_table __read_mostly;
77540 EXPORT_SYMBOL(udp_table);
77541
77542 @@ -569,6 +574,9 @@ found:
77543 return s;
77544 }
77545
77546 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
77547 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
77548 +
77549 /*
77550 * This routine is called by the ICMP module when it gets some
77551 * sort of error condition. If err < 0 then the socket should
77552 @@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
77553 dport = usin->sin_port;
77554 if (dport == 0)
77555 return -EINVAL;
77556 +
77557 + err = gr_search_udp_sendmsg(sk, usin);
77558 + if (err)
77559 + return err;
77560 } else {
77561 if (sk->sk_state != TCP_ESTABLISHED)
77562 return -EDESTADDRREQ;
77563 +
77564 + err = gr_search_udp_sendmsg(sk, NULL);
77565 + if (err)
77566 + return err;
77567 +
77568 daddr = inet->inet_daddr;
77569 dport = inet->inet_dport;
77570 /* Open fast path for connected socket.
77571 @@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
77572 udp_lib_checksum_complete(skb)) {
77573 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77574 IS_UDPLITE(sk));
77575 - atomic_inc(&sk->sk_drops);
77576 + atomic_inc_unchecked(&sk->sk_drops);
77577 __skb_unlink(skb, rcvq);
77578 __skb_queue_tail(&list_kill, skb);
77579 }
77580 @@ -1194,6 +1211,10 @@ try_again:
77581 if (!skb)
77582 goto out;
77583
77584 + err = gr_search_udp_recvmsg(sk, skb);
77585 + if (err)
77586 + goto out_free;
77587 +
77588 ulen = skb->len - sizeof(struct udphdr);
77589 copied = len;
77590 if (copied > ulen)
77591 @@ -1227,7 +1248,7 @@ try_again:
77592 if (unlikely(err)) {
77593 trace_kfree_skb(skb, udp_recvmsg);
77594 if (!peeked) {
77595 - atomic_inc(&sk->sk_drops);
77596 + atomic_inc_unchecked(&sk->sk_drops);
77597 UDP_INC_STATS_USER(sock_net(sk),
77598 UDP_MIB_INERRORS, is_udplite);
77599 }
77600 @@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77601
77602 drop:
77603 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
77604 - atomic_inc(&sk->sk_drops);
77605 + atomic_inc_unchecked(&sk->sk_drops);
77606 kfree_skb(skb);
77607 return -1;
77608 }
77609 @@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
77610 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
77611
77612 if (!skb1) {
77613 - atomic_inc(&sk->sk_drops);
77614 + atomic_inc_unchecked(&sk->sk_drops);
77615 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
77616 IS_UDPLITE(sk));
77617 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77618 @@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
77619 goto csum_error;
77620
77621 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
77622 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77623 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
77624 +#endif
77625 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
77626
77627 /*
77628 @@ -2116,8 +2140,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
77629 sk_wmem_alloc_get(sp),
77630 sk_rmem_alloc_get(sp),
77631 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77632 - atomic_read(&sp->sk_refcnt), sp,
77633 - atomic_read(&sp->sk_drops), len);
77634 + atomic_read(&sp->sk_refcnt),
77635 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77636 + NULL,
77637 +#else
77638 + sp,
77639 +#endif
77640 + atomic_read_unchecked(&sp->sk_drops), len);
77641 }
77642
77643 int udp4_seq_show(struct seq_file *seq, void *v)
77644 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
77645 index b10374d..0baa1f9 100644
77646 --- a/net/ipv6/addrconf.c
77647 +++ b/net/ipv6/addrconf.c
77648 @@ -2144,7 +2144,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
77649 p.iph.ihl = 5;
77650 p.iph.protocol = IPPROTO_IPV6;
77651 p.iph.ttl = 64;
77652 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
77653 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
77654
77655 if (ops->ndo_do_ioctl) {
77656 mm_segment_t oldfs = get_fs();
77657 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
77658 index ba6d13d..6899122 100644
77659 --- a/net/ipv6/ipv6_sockglue.c
77660 +++ b/net/ipv6/ipv6_sockglue.c
77661 @@ -989,7 +989,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
77662 if (sk->sk_type != SOCK_STREAM)
77663 return -ENOPROTOOPT;
77664
77665 - msg.msg_control = optval;
77666 + msg.msg_control = (void __force_kernel *)optval;
77667 msg.msg_controllen = len;
77668 msg.msg_flags = flags;
77669
77670 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
77671 index d7cb045..8c0ded6 100644
77672 --- a/net/ipv6/netfilter/ip6_tables.c
77673 +++ b/net/ipv6/netfilter/ip6_tables.c
77674 @@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
77675 #endif
77676
77677 static int get_info(struct net *net, void __user *user,
77678 - const int *len, int compat)
77679 + int len, int compat)
77680 {
77681 char name[XT_TABLE_MAXNAMELEN];
77682 struct xt_table *t;
77683 int ret;
77684
77685 - if (*len != sizeof(struct ip6t_getinfo)) {
77686 - duprintf("length %u != %zu\n", *len,
77687 + if (len != sizeof(struct ip6t_getinfo)) {
77688 + duprintf("length %u != %zu\n", len,
77689 sizeof(struct ip6t_getinfo));
77690 return -EINVAL;
77691 }
77692 @@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
77693 info.size = private->size;
77694 strcpy(info.name, name);
77695
77696 - if (copy_to_user(user, &info, *len) != 0)
77697 + if (copy_to_user(user, &info, len) != 0)
77698 ret = -EFAULT;
77699 else
77700 ret = 0;
77701 @@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77702
77703 switch (cmd) {
77704 case IP6T_SO_GET_INFO:
77705 - ret = get_info(sock_net(sk), user, len, 1);
77706 + ret = get_info(sock_net(sk), user, *len, 1);
77707 break;
77708 case IP6T_SO_GET_ENTRIES:
77709 ret = compat_get_entries(sock_net(sk), user, len);
77710 @@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77711
77712 switch (cmd) {
77713 case IP6T_SO_GET_INFO:
77714 - ret = get_info(sock_net(sk), user, len, 0);
77715 + ret = get_info(sock_net(sk), user, *len, 0);
77716 break;
77717
77718 case IP6T_SO_GET_ENTRIES:
77719 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
77720 index 4a5f78b..3f22ebe 100644
77721 --- a/net/ipv6/raw.c
77722 +++ b/net/ipv6/raw.c
77723 @@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
77724 {
77725 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
77726 skb_checksum_complete(skb)) {
77727 - atomic_inc(&sk->sk_drops);
77728 + atomic_inc_unchecked(&sk->sk_drops);
77729 kfree_skb(skb);
77730 return NET_RX_DROP;
77731 }
77732 @@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
77733 struct raw6_sock *rp = raw6_sk(sk);
77734
77735 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
77736 - atomic_inc(&sk->sk_drops);
77737 + atomic_inc_unchecked(&sk->sk_drops);
77738 kfree_skb(skb);
77739 return NET_RX_DROP;
77740 }
77741 @@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
77742
77743 if (inet->hdrincl) {
77744 if (skb_checksum_complete(skb)) {
77745 - atomic_inc(&sk->sk_drops);
77746 + atomic_inc_unchecked(&sk->sk_drops);
77747 kfree_skb(skb);
77748 return NET_RX_DROP;
77749 }
77750 @@ -604,7 +604,7 @@ out:
77751 return err;
77752 }
77753
77754 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
77755 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
77756 struct flowi6 *fl6, struct dst_entry **dstp,
77757 unsigned int flags)
77758 {
77759 @@ -916,12 +916,15 @@ do_confirm:
77760 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
77761 char __user *optval, int optlen)
77762 {
77763 + struct icmp6_filter filter;
77764 +
77765 switch (optname) {
77766 case ICMPV6_FILTER:
77767 if (optlen > sizeof(struct icmp6_filter))
77768 optlen = sizeof(struct icmp6_filter);
77769 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
77770 + if (copy_from_user(&filter, optval, optlen))
77771 return -EFAULT;
77772 + raw6_sk(sk)->filter = filter;
77773 return 0;
77774 default:
77775 return -ENOPROTOOPT;
77776 @@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
77777 char __user *optval, int __user *optlen)
77778 {
77779 int len;
77780 + struct icmp6_filter filter;
77781
77782 switch (optname) {
77783 case ICMPV6_FILTER:
77784 @@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
77785 len = sizeof(struct icmp6_filter);
77786 if (put_user(len, optlen))
77787 return -EFAULT;
77788 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
77789 + filter = raw6_sk(sk)->filter;
77790 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
77791 return -EFAULT;
77792 return 0;
77793 default:
77794 @@ -1252,7 +1257,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
77795 0, 0L, 0,
77796 sock_i_uid(sp), 0,
77797 sock_i_ino(sp),
77798 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
77799 + atomic_read(&sp->sk_refcnt),
77800 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77801 + NULL,
77802 +#else
77803 + sp,
77804 +#endif
77805 + atomic_read_unchecked(&sp->sk_drops));
77806 }
77807
77808 static int raw6_seq_show(struct seq_file *seq, void *v)
77809 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
77810 index 7e32d42..5d975ba 100644
77811 --- a/net/ipv6/tcp_ipv6.c
77812 +++ b/net/ipv6/tcp_ipv6.c
77813 @@ -106,6 +106,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
77814 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
77815 }
77816
77817 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77818 +extern int grsec_enable_blackhole;
77819 +#endif
77820 +
77821 static void tcp_v6_hash(struct sock *sk)
77822 {
77823 if (sk->sk_state != TCP_CLOSE) {
77824 @@ -1511,6 +1515,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
77825 return 0;
77826
77827 reset:
77828 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77829 + if (!grsec_enable_blackhole)
77830 +#endif
77831 tcp_v6_send_reset(sk, skb);
77832 discard:
77833 if (opt_skb)
77834 @@ -1592,12 +1599,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
77835 TCP_SKB_CB(skb)->sacked = 0;
77836
77837 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
77838 - if (!sk)
77839 + if (!sk) {
77840 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77841 + ret = 1;
77842 +#endif
77843 goto no_tcp_socket;
77844 + }
77845
77846 process:
77847 - if (sk->sk_state == TCP_TIME_WAIT)
77848 + if (sk->sk_state == TCP_TIME_WAIT) {
77849 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77850 + ret = 2;
77851 +#endif
77852 goto do_time_wait;
77853 + }
77854
77855 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
77856 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
77857 @@ -1646,6 +1661,10 @@ no_tcp_socket:
77858 bad_packet:
77859 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
77860 } else {
77861 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77862 + if (!grsec_enable_blackhole || (ret == 1 &&
77863 + (skb->dev->flags & IFF_LOOPBACK)))
77864 +#endif
77865 tcp_v6_send_reset(NULL, skb);
77866 }
77867
77868 @@ -1857,7 +1876,13 @@ static void get_openreq6(struct seq_file *seq,
77869 uid,
77870 0, /* non standard timer */
77871 0, /* open_requests have no inode */
77872 - 0, req);
77873 + 0,
77874 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77875 + NULL
77876 +#else
77877 + req
77878 +#endif
77879 + );
77880 }
77881
77882 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
77883 @@ -1907,7 +1932,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
77884 sock_i_uid(sp),
77885 icsk->icsk_probes_out,
77886 sock_i_ino(sp),
77887 - atomic_read(&sp->sk_refcnt), sp,
77888 + atomic_read(&sp->sk_refcnt),
77889 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77890 + NULL,
77891 +#else
77892 + sp,
77893 +#endif
77894 jiffies_to_clock_t(icsk->icsk_rto),
77895 jiffies_to_clock_t(icsk->icsk_ack.ato),
77896 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
77897 @@ -1942,7 +1972,13 @@ static void get_timewait6_sock(struct seq_file *seq,
77898 dest->s6_addr32[2], dest->s6_addr32[3], destp,
77899 tw->tw_substate, 0, 0,
77900 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
77901 - atomic_read(&tw->tw_refcnt), tw);
77902 + atomic_read(&tw->tw_refcnt),
77903 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77904 + NULL
77905 +#else
77906 + tw
77907 +#endif
77908 + );
77909 }
77910
77911 static int tcp6_seq_show(struct seq_file *seq, void *v)
77912 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
77913 index 07e2bfe..328dae8 100644
77914 --- a/net/ipv6/udp.c
77915 +++ b/net/ipv6/udp.c
77916 @@ -51,6 +51,10 @@
77917 #include <trace/events/skb.h>
77918 #include "udp_impl.h"
77919
77920 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77921 +extern int grsec_enable_blackhole;
77922 +#endif
77923 +
77924 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
77925 {
77926 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
77927 @@ -395,7 +399,7 @@ try_again:
77928 if (unlikely(err)) {
77929 trace_kfree_skb(skb, udpv6_recvmsg);
77930 if (!peeked) {
77931 - atomic_inc(&sk->sk_drops);
77932 + atomic_inc_unchecked(&sk->sk_drops);
77933 if (is_udp4)
77934 UDP_INC_STATS_USER(sock_net(sk),
77935 UDP_MIB_INERRORS,
77936 @@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77937 return rc;
77938 drop:
77939 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
77940 - atomic_inc(&sk->sk_drops);
77941 + atomic_inc_unchecked(&sk->sk_drops);
77942 kfree_skb(skb);
77943 return -1;
77944 }
77945 @@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
77946 if (likely(skb1 == NULL))
77947 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
77948 if (!skb1) {
77949 - atomic_inc(&sk->sk_drops);
77950 + atomic_inc_unchecked(&sk->sk_drops);
77951 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
77952 IS_UDPLITE(sk));
77953 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77954 @@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
77955 goto discard;
77956
77957 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
77958 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77959 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
77960 +#endif
77961 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
77962
77963 kfree_skb(skb);
77964 @@ -1471,8 +1478,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
77965 0, 0L, 0,
77966 sock_i_uid(sp), 0,
77967 sock_i_ino(sp),
77968 - atomic_read(&sp->sk_refcnt), sp,
77969 - atomic_read(&sp->sk_drops));
77970 + atomic_read(&sp->sk_refcnt),
77971 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77972 + NULL,
77973 +#else
77974 + sp,
77975 +#endif
77976 + atomic_read_unchecked(&sp->sk_drops));
77977 }
77978
77979 int udp6_seq_show(struct seq_file *seq, void *v)
77980 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
77981 index 6b9d5a0..4dffaf1 100644
77982 --- a/net/irda/ircomm/ircomm_tty.c
77983 +++ b/net/irda/ircomm/ircomm_tty.c
77984 @@ -281,16 +281,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77985 add_wait_queue(&self->open_wait, &wait);
77986
77987 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
77988 - __FILE__,__LINE__, tty->driver->name, self->open_count );
77989 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
77990
77991 /* As far as I can see, we protect open_count - Jean II */
77992 spin_lock_irqsave(&self->spinlock, flags);
77993 if (!tty_hung_up_p(filp)) {
77994 extra_count = 1;
77995 - self->open_count--;
77996 + local_dec(&self->open_count);
77997 }
77998 spin_unlock_irqrestore(&self->spinlock, flags);
77999 - self->blocked_open++;
78000 + local_inc(&self->blocked_open);
78001
78002 while (1) {
78003 if (tty->termios->c_cflag & CBAUD) {
78004 @@ -330,7 +330,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
78005 }
78006
78007 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
78008 - __FILE__,__LINE__, tty->driver->name, self->open_count );
78009 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
78010
78011 schedule();
78012 }
78013 @@ -341,13 +341,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
78014 if (extra_count) {
78015 /* ++ is not atomic, so this should be protected - Jean II */
78016 spin_lock_irqsave(&self->spinlock, flags);
78017 - self->open_count++;
78018 + local_inc(&self->open_count);
78019 spin_unlock_irqrestore(&self->spinlock, flags);
78020 }
78021 - self->blocked_open--;
78022 + local_dec(&self->blocked_open);
78023
78024 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
78025 - __FILE__,__LINE__, tty->driver->name, self->open_count);
78026 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
78027
78028 if (!retval)
78029 self->flags |= ASYNC_NORMAL_ACTIVE;
78030 @@ -412,14 +412,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
78031 }
78032 /* ++ is not atomic, so this should be protected - Jean II */
78033 spin_lock_irqsave(&self->spinlock, flags);
78034 - self->open_count++;
78035 + local_inc(&self->open_count);
78036
78037 tty->driver_data = self;
78038 self->tty = tty;
78039 spin_unlock_irqrestore(&self->spinlock, flags);
78040
78041 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
78042 - self->line, self->open_count);
78043 + self->line, local_read(&self->open_count));
78044
78045 /* Not really used by us, but lets do it anyway */
78046 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
78047 @@ -505,7 +505,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
78048 return;
78049 }
78050
78051 - if ((tty->count == 1) && (self->open_count != 1)) {
78052 + if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
78053 /*
78054 * Uh, oh. tty->count is 1, which means that the tty
78055 * structure will be freed. state->count should always
78056 @@ -515,16 +515,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
78057 */
78058 IRDA_DEBUG(0, "%s(), bad serial port count; "
78059 "tty->count is 1, state->count is %d\n", __func__ ,
78060 - self->open_count);
78061 - self->open_count = 1;
78062 + local_read(&self->open_count));
78063 + local_set(&self->open_count, 1);
78064 }
78065
78066 - if (--self->open_count < 0) {
78067 + if (local_dec_return(&self->open_count) < 0) {
78068 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
78069 - __func__, self->line, self->open_count);
78070 - self->open_count = 0;
78071 + __func__, self->line, local_read(&self->open_count));
78072 + local_set(&self->open_count, 0);
78073 }
78074 - if (self->open_count) {
78075 + if (local_read(&self->open_count)) {
78076 spin_unlock_irqrestore(&self->spinlock, flags);
78077
78078 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
78079 @@ -556,7 +556,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
78080 tty->closing = 0;
78081 self->tty = NULL;
78082
78083 - if (self->blocked_open) {
78084 + if (local_read(&self->blocked_open)) {
78085 if (self->close_delay)
78086 schedule_timeout_interruptible(self->close_delay);
78087 wake_up_interruptible(&self->open_wait);
78088 @@ -1008,7 +1008,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
78089 spin_lock_irqsave(&self->spinlock, flags);
78090 self->flags &= ~ASYNC_NORMAL_ACTIVE;
78091 self->tty = NULL;
78092 - self->open_count = 0;
78093 + local_set(&self->open_count, 0);
78094 spin_unlock_irqrestore(&self->spinlock, flags);
78095
78096 wake_up_interruptible(&self->open_wait);
78097 @@ -1355,7 +1355,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
78098 seq_putc(m, '\n');
78099
78100 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
78101 - seq_printf(m, "Open count: %d\n", self->open_count);
78102 + seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
78103 seq_printf(m, "Max data size: %d\n", self->max_data_size);
78104 seq_printf(m, "Max header size: %d\n", self->max_header_size);
78105
78106 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
78107 index cd6f7a9..e63fe89 100644
78108 --- a/net/iucv/af_iucv.c
78109 +++ b/net/iucv/af_iucv.c
78110 @@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
78111
78112 write_lock_bh(&iucv_sk_list.lock);
78113
78114 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
78115 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
78116 while (__iucv_get_sock_by_name(name)) {
78117 sprintf(name, "%08x",
78118 - atomic_inc_return(&iucv_sk_list.autobind_name));
78119 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
78120 }
78121
78122 write_unlock_bh(&iucv_sk_list.lock);
78123 diff --git a/net/key/af_key.c b/net/key/af_key.c
78124 index 34e4185..8823368 100644
78125 --- a/net/key/af_key.c
78126 +++ b/net/key/af_key.c
78127 @@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
78128 static u32 get_acqseq(void)
78129 {
78130 u32 res;
78131 - static atomic_t acqseq;
78132 + static atomic_unchecked_t acqseq;
78133
78134 do {
78135 - res = atomic_inc_return(&acqseq);
78136 + res = atomic_inc_return_unchecked(&acqseq);
78137 } while (!res);
78138 return res;
78139 }
78140 diff --git a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c
78141 index 3bfb34a..69bf48d 100644
78142 --- a/net/l2tp/l2tp_eth.c
78143 +++ b/net/l2tp/l2tp_eth.c
78144 @@ -290,6 +290,7 @@ static int l2tp_eth_create(struct net *net, u32 tunnel_id, u32 session_id, u32 p
78145
78146 out_del_dev:
78147 free_netdev(dev);
78148 + spriv->dev = NULL;
78149 out_del_session:
78150 l2tp_session_delete(session);
78151 out:
78152 diff --git a/net/mac80211/ibss.c b/net/mac80211/ibss.c
78153 index 5746d62..327aa07 100644
78154 --- a/net/mac80211/ibss.c
78155 +++ b/net/mac80211/ibss.c
78156 @@ -1074,7 +1074,7 @@ int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata,
78157 sdata->u.ibss.state = IEEE80211_IBSS_MLME_SEARCH;
78158 sdata->u.ibss.ibss_join_req = jiffies;
78159
78160 - memcpy(sdata->u.ibss.ssid, params->ssid, IEEE80211_MAX_SSID_LEN);
78161 + memcpy(sdata->u.ibss.ssid, params->ssid, params->ssid_len);
78162 sdata->u.ibss.ssid_len = params->ssid_len;
78163
78164 mutex_unlock(&sdata->u.ibss.mtx);
78165 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
78166 index bb61f77..3788d63 100644
78167 --- a/net/mac80211/ieee80211_i.h
78168 +++ b/net/mac80211/ieee80211_i.h
78169 @@ -28,6 +28,7 @@
78170 #include <net/ieee80211_radiotap.h>
78171 #include <net/cfg80211.h>
78172 #include <net/mac80211.h>
78173 +#include <asm/local.h>
78174 #include "key.h"
78175 #include "sta_info.h"
78176 #include "debug.h"
78177 @@ -840,7 +841,7 @@ struct ieee80211_local {
78178 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
78179 spinlock_t queue_stop_reason_lock;
78180
78181 - int open_count;
78182 + local_t open_count;
78183 int monitors, cooked_mntrs;
78184 /* number of interfaces with corresponding FIF_ flags */
78185 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
78186 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
78187 index c93d395..a305570 100644
78188 --- a/net/mac80211/iface.c
78189 +++ b/net/mac80211/iface.c
78190 @@ -454,7 +454,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78191 break;
78192 }
78193
78194 - if (local->open_count == 0) {
78195 + if (local_read(&local->open_count) == 0) {
78196 res = drv_start(local);
78197 if (res)
78198 goto err_del_bss;
78199 @@ -497,7 +497,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78200 break;
78201 }
78202
78203 - if (local->monitors == 0 && local->open_count == 0) {
78204 + if (local->monitors == 0 && local_read(&local->open_count) == 0) {
78205 res = ieee80211_add_virtual_monitor(local);
78206 if (res)
78207 goto err_stop;
78208 @@ -594,7 +594,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78209 mutex_unlock(&local->mtx);
78210
78211 if (coming_up)
78212 - local->open_count++;
78213 + local_inc(&local->open_count);
78214
78215 if (hw_reconf_flags)
78216 ieee80211_hw_config(local, hw_reconf_flags);
78217 @@ -607,7 +607,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78218 err_del_interface:
78219 drv_remove_interface(local, sdata);
78220 err_stop:
78221 - if (!local->open_count)
78222 + if (!local_read(&local->open_count))
78223 drv_stop(local);
78224 err_del_bss:
78225 sdata->bss = NULL;
78226 @@ -736,7 +736,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78227 }
78228
78229 if (going_down)
78230 - local->open_count--;
78231 + local_dec(&local->open_count);
78232
78233 switch (sdata->vif.type) {
78234 case NL80211_IFTYPE_AP_VLAN:
78235 @@ -796,7 +796,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78236
78237 ieee80211_recalc_ps(local, -1);
78238
78239 - if (local->open_count == 0) {
78240 + if (local_read(&local->open_count) == 0) {
78241 if (local->ops->napi_poll)
78242 napi_disable(&local->napi);
78243 ieee80211_clear_tx_pending(local);
78244 @@ -828,7 +828,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78245 }
78246 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
78247
78248 - if (local->monitors == local->open_count && local->monitors > 0)
78249 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
78250 ieee80211_add_virtual_monitor(local);
78251 }
78252
78253 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
78254 index c26e231..8916637 100644
78255 --- a/net/mac80211/main.c
78256 +++ b/net/mac80211/main.c
78257 @@ -166,7 +166,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
78258 local->hw.conf.power_level = power;
78259 }
78260
78261 - if (changed && local->open_count) {
78262 + if (changed && local_read(&local->open_count)) {
78263 ret = drv_config(local, changed);
78264 /*
78265 * Goal:
78266 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
78267 index 5c572e7..ecf75ce 100644
78268 --- a/net/mac80211/pm.c
78269 +++ b/net/mac80211/pm.c
78270 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78271 struct ieee80211_sub_if_data *sdata;
78272 struct sta_info *sta;
78273
78274 - if (!local->open_count)
78275 + if (!local_read(&local->open_count))
78276 goto suspend;
78277
78278 ieee80211_scan_cancel(local);
78279 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78280 cancel_work_sync(&local->dynamic_ps_enable_work);
78281 del_timer_sync(&local->dynamic_ps_timer);
78282
78283 - local->wowlan = wowlan && local->open_count;
78284 + local->wowlan = wowlan && local_read(&local->open_count);
78285 if (local->wowlan) {
78286 int err = drv_suspend(local, wowlan);
78287 if (err < 0) {
78288 @@ -143,7 +143,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78289 drv_remove_interface(local, sdata);
78290
78291 /* stop hardware - this must stop RX */
78292 - if (local->open_count)
78293 + if (local_read(&local->open_count))
78294 ieee80211_stop_device(local);
78295
78296 suspend:
78297 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
78298 index 3313c11..bec9f17 100644
78299 --- a/net/mac80211/rate.c
78300 +++ b/net/mac80211/rate.c
78301 @@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
78302
78303 ASSERT_RTNL();
78304
78305 - if (local->open_count)
78306 + if (local_read(&local->open_count))
78307 return -EBUSY;
78308
78309 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
78310 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
78311 index c97a065..ff61928 100644
78312 --- a/net/mac80211/rc80211_pid_debugfs.c
78313 +++ b/net/mac80211/rc80211_pid_debugfs.c
78314 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
78315
78316 spin_unlock_irqrestore(&events->lock, status);
78317
78318 - if (copy_to_user(buf, pb, p))
78319 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
78320 return -EFAULT;
78321
78322 return p;
78323 diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
78324 index 0cb4ede..884155d 100644
78325 --- a/net/mac80211/rx.c
78326 +++ b/net/mac80211/rx.c
78327 @@ -491,6 +491,11 @@ ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
78328
78329 if (ieee80211_is_action(hdr->frame_control)) {
78330 u8 category;
78331 +
78332 + /* make sure category field is present */
78333 + if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE)
78334 + return RX_DROP_MONITOR;
78335 +
78336 mgmt = (struct ieee80211_mgmt *)hdr;
78337 category = mgmt->u.action.category;
78338 if (category != WLAN_CATEGORY_MESH_ACTION &&
78339 @@ -1426,7 +1431,6 @@ ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
78340 frag = sc & IEEE80211_SCTL_FRAG;
78341
78342 if (likely((!ieee80211_has_morefrags(fc) && frag == 0) ||
78343 - (rx->skb)->len < 24 ||
78344 is_multicast_ether_addr(hdr->addr1))) {
78345 /* not fragmented */
78346 goto out;
78347 @@ -1849,6 +1853,20 @@ ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
78348
78349 hdr = (struct ieee80211_hdr *) skb->data;
78350 hdrlen = ieee80211_hdrlen(hdr->frame_control);
78351 +
78352 + /* make sure fixed part of mesh header is there, also checks skb len */
78353 + if (!pskb_may_pull(rx->skb, hdrlen + 6))
78354 + return RX_DROP_MONITOR;
78355 +
78356 + mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
78357 +
78358 + /* make sure full mesh header is there, also checks skb len */
78359 + if (!pskb_may_pull(rx->skb,
78360 + hdrlen + ieee80211_get_mesh_hdrlen(mesh_hdr)))
78361 + return RX_DROP_MONITOR;
78362 +
78363 + /* reload pointers */
78364 + hdr = (struct ieee80211_hdr *) skb->data;
78365 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
78366
78367 /* frame is in RMC, don't forward */
78368 @@ -1871,9 +1889,12 @@ ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
78369 if (is_multicast_ether_addr(hdr->addr1)) {
78370 mpp_addr = hdr->addr3;
78371 proxied_addr = mesh_hdr->eaddr1;
78372 - } else {
78373 + } else if (mesh_hdr->flags & MESH_FLAGS_AE_A5_A6) {
78374 + /* has_a4 already checked in ieee80211_rx_mesh_check */
78375 mpp_addr = hdr->addr4;
78376 proxied_addr = mesh_hdr->eaddr2;
78377 + } else {
78378 + return RX_DROP_MONITOR;
78379 }
78380
78381 rcu_read_lock();
78382 @@ -2313,6 +2334,10 @@ ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
78383 }
78384 break;
78385 case WLAN_CATEGORY_SELF_PROTECTED:
78386 + if (len < (IEEE80211_MIN_ACTION_SIZE +
78387 + sizeof(mgmt->u.action.u.self_prot.action_code)))
78388 + break;
78389 +
78390 switch (mgmt->u.action.u.self_prot.action_code) {
78391 case WLAN_SP_MESH_PEERING_OPEN:
78392 case WLAN_SP_MESH_PEERING_CLOSE:
78393 @@ -2331,6 +2356,10 @@ ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
78394 }
78395 break;
78396 case WLAN_CATEGORY_MESH_ACTION:
78397 + if (len < (IEEE80211_MIN_ACTION_SIZE +
78398 + sizeof(mgmt->u.action.u.mesh_action.action_code)))
78399 + break;
78400 +
78401 if (!ieee80211_vif_is_mesh(&sdata->vif))
78402 break;
78403 if (mesh_action_is_path_sel(mgmt) &&
78404 @@ -2865,10 +2894,15 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
78405 if (ieee80211_is_data(fc) || ieee80211_is_mgmt(fc))
78406 local->dot11ReceivedFragmentCount++;
78407
78408 - if (ieee80211_is_mgmt(fc))
78409 - err = skb_linearize(skb);
78410 - else
78411 + if (ieee80211_is_mgmt(fc)) {
78412 + /* drop frame if too short for header */
78413 + if (skb->len < ieee80211_hdrlen(fc))
78414 + err = -ENOBUFS;
78415 + else
78416 + err = skb_linearize(skb);
78417 + } else {
78418 err = !pskb_may_pull(skb, ieee80211_hdrlen(fc));
78419 + }
78420
78421 if (err) {
78422 dev_kfree_skb(skb);
78423 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
78424 index c9b52f7..4da1014 100644
78425 --- a/net/mac80211/util.c
78426 +++ b/net/mac80211/util.c
78427 @@ -1251,7 +1251,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
78428 }
78429 #endif
78430 /* everything else happens only if HW was up & running */
78431 - if (!local->open_count)
78432 + if (!local_read(&local->open_count))
78433 goto wake_up;
78434
78435 /*
78436 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
78437 index c19b214..471fad1 100644
78438 --- a/net/netfilter/Kconfig
78439 +++ b/net/netfilter/Kconfig
78440 @@ -872,6 +872,16 @@ config NETFILTER_XT_MATCH_ESP
78441
78442 To compile it as a module, choose M here. If unsure, say N.
78443
78444 +config NETFILTER_XT_MATCH_GRADM
78445 + tristate '"gradm" match support'
78446 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
78447 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
78448 + ---help---
78449 + The gradm match allows to match on grsecurity RBAC being enabled.
78450 + It is useful when iptables rules are applied early on bootup to
78451 + prevent connections to the machine (except from a trusted host)
78452 + while the RBAC system is disabled.
78453 +
78454 config NETFILTER_XT_MATCH_HASHLIMIT
78455 tristate '"hashlimit" match support'
78456 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
78457 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
78458 index 1c5160f..145ae21 100644
78459 --- a/net/netfilter/Makefile
78460 +++ b/net/netfilter/Makefile
78461 @@ -90,6 +90,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
78462 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
78463 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
78464 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
78465 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
78466 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
78467 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
78468 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
78469 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
78470 index 1548df9..98ad9b4 100644
78471 --- a/net/netfilter/ipvs/ip_vs_conn.c
78472 +++ b/net/netfilter/ipvs/ip_vs_conn.c
78473 @@ -557,7 +557,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
78474 /* Increase the refcnt counter of the dest */
78475 atomic_inc(&dest->refcnt);
78476
78477 - conn_flags = atomic_read(&dest->conn_flags);
78478 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
78479 if (cp->protocol != IPPROTO_UDP)
78480 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
78481 flags = cp->flags;
78482 @@ -902,7 +902,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
78483 atomic_set(&cp->refcnt, 1);
78484
78485 atomic_set(&cp->n_control, 0);
78486 - atomic_set(&cp->in_pkts, 0);
78487 + atomic_set_unchecked(&cp->in_pkts, 0);
78488
78489 atomic_inc(&ipvs->conn_count);
78490 if (flags & IP_VS_CONN_F_NO_CPORT)
78491 @@ -1183,7 +1183,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
78492
78493 /* Don't drop the entry if its number of incoming packets is not
78494 located in [0, 8] */
78495 - i = atomic_read(&cp->in_pkts);
78496 + i = atomic_read_unchecked(&cp->in_pkts);
78497 if (i > 8 || i < 0) return 0;
78498
78499 if (!todrop_rate[i]) return 0;
78500 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
78501 index b54ecce..fc5f6cf 100644
78502 --- a/net/netfilter/ipvs/ip_vs_core.c
78503 +++ b/net/netfilter/ipvs/ip_vs_core.c
78504 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
78505 ret = cp->packet_xmit(skb, cp, pd->pp);
78506 /* do not touch skb anymore */
78507
78508 - atomic_inc(&cp->in_pkts);
78509 + atomic_inc_unchecked(&cp->in_pkts);
78510 ip_vs_conn_put(cp);
78511 return ret;
78512 }
78513 @@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
78514 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
78515 pkts = sysctl_sync_threshold(ipvs);
78516 else
78517 - pkts = atomic_add_return(1, &cp->in_pkts);
78518 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78519
78520 if (ipvs->sync_state & IP_VS_STATE_MASTER)
78521 ip_vs_sync_conn(net, cp, pkts);
78522 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
78523 index f51013c..c99ee52 100644
78524 --- a/net/netfilter/ipvs/ip_vs_ctl.c
78525 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
78526 @@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
78527 ip_vs_rs_hash(ipvs, dest);
78528 write_unlock_bh(&ipvs->rs_lock);
78529 }
78530 - atomic_set(&dest->conn_flags, conn_flags);
78531 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
78532
78533 /* bind the service */
78534 if (!dest->svc) {
78535 @@ -2076,7 +2076,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
78536 " %-7s %-6d %-10d %-10d\n",
78537 &dest->addr.in6,
78538 ntohs(dest->port),
78539 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
78540 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
78541 atomic_read(&dest->weight),
78542 atomic_read(&dest->activeconns),
78543 atomic_read(&dest->inactconns));
78544 @@ -2087,7 +2087,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
78545 "%-7s %-6d %-10d %-10d\n",
78546 ntohl(dest->addr.ip),
78547 ntohs(dest->port),
78548 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
78549 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
78550 atomic_read(&dest->weight),
78551 atomic_read(&dest->activeconns),
78552 atomic_read(&dest->inactconns));
78553 @@ -2557,7 +2557,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
78554
78555 entry.addr = dest->addr.ip;
78556 entry.port = dest->port;
78557 - entry.conn_flags = atomic_read(&dest->conn_flags);
78558 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
78559 entry.weight = atomic_read(&dest->weight);
78560 entry.u_threshold = dest->u_threshold;
78561 entry.l_threshold = dest->l_threshold;
78562 @@ -3092,7 +3092,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
78563 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
78564 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
78565 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
78566 - (atomic_read(&dest->conn_flags) &
78567 + (atomic_read_unchecked(&dest->conn_flags) &
78568 IP_VS_CONN_F_FWD_MASK)) ||
78569 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
78570 atomic_read(&dest->weight)) ||
78571 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
78572 index effa10c..9058928 100644
78573 --- a/net/netfilter/ipvs/ip_vs_sync.c
78574 +++ b/net/netfilter/ipvs/ip_vs_sync.c
78575 @@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
78576 cp = cp->control;
78577 if (cp) {
78578 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
78579 - pkts = atomic_add_return(1, &cp->in_pkts);
78580 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78581 else
78582 pkts = sysctl_sync_threshold(ipvs);
78583 ip_vs_sync_conn(net, cp->control, pkts);
78584 @@ -758,7 +758,7 @@ control:
78585 if (!cp)
78586 return;
78587 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
78588 - pkts = atomic_add_return(1, &cp->in_pkts);
78589 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78590 else
78591 pkts = sysctl_sync_threshold(ipvs);
78592 goto sloop;
78593 @@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
78594
78595 if (opt)
78596 memcpy(&cp->in_seq, opt, sizeof(*opt));
78597 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
78598 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
78599 cp->state = state;
78600 cp->old_state = cp->state;
78601 /*
78602 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
78603 index c3c6291..3376d73 100644
78604 --- a/net/netfilter/ipvs/ip_vs_xmit.c
78605 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
78606 @@ -1157,7 +1157,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
78607 else
78608 rc = NF_ACCEPT;
78609 /* do not touch skb anymore */
78610 - atomic_inc(&cp->in_pkts);
78611 + atomic_inc_unchecked(&cp->in_pkts);
78612 goto out;
78613 }
78614
78615 @@ -1278,7 +1278,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
78616 else
78617 rc = NF_ACCEPT;
78618 /* do not touch skb anymore */
78619 - atomic_inc(&cp->in_pkts);
78620 + atomic_inc_unchecked(&cp->in_pkts);
78621 goto out;
78622 }
78623
78624 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
78625 index 2ceec64..a5b8a61 100644
78626 --- a/net/netfilter/nf_conntrack_core.c
78627 +++ b/net/netfilter/nf_conntrack_core.c
78628 @@ -1529,6 +1529,10 @@ err_extend:
78629 #define UNCONFIRMED_NULLS_VAL ((1<<30)+0)
78630 #define DYING_NULLS_VAL ((1<<30)+1)
78631
78632 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78633 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
78634 +#endif
78635 +
78636 static int nf_conntrack_init_net(struct net *net)
78637 {
78638 int ret;
78639 @@ -1542,7 +1546,11 @@ static int nf_conntrack_init_net(struct net *net)
78640 goto err_stat;
78641 }
78642
78643 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78644 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
78645 +#else
78646 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
78647 +#endif
78648 if (!net->ct.slabname) {
78649 ret = -ENOMEM;
78650 goto err_slabname;
78651 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
78652 index 5cfb5be..217c6d8 100644
78653 --- a/net/netfilter/nfnetlink_log.c
78654 +++ b/net/netfilter/nfnetlink_log.c
78655 @@ -70,7 +70,7 @@ struct nfulnl_instance {
78656 };
78657
78658 static DEFINE_SPINLOCK(instances_lock);
78659 -static atomic_t global_seq;
78660 +static atomic_unchecked_t global_seq;
78661
78662 #define INSTANCE_BUCKETS 16
78663 static struct hlist_head instance_table[INSTANCE_BUCKETS];
78664 @@ -523,7 +523,7 @@ __build_packet_message(struct nfulnl_instance *inst,
78665 /* global sequence number */
78666 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
78667 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
78668 - htonl(atomic_inc_return(&global_seq))))
78669 + htonl(atomic_inc_return_unchecked(&global_seq))))
78670 goto nla_put_failure;
78671
78672 if (data_len) {
78673 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
78674 new file mode 100644
78675 index 0000000..6905327
78676 --- /dev/null
78677 +++ b/net/netfilter/xt_gradm.c
78678 @@ -0,0 +1,51 @@
78679 +/*
78680 + * gradm match for netfilter
78681 + * Copyright © Zbigniew Krzystolik, 2010
78682 + *
78683 + * This program is free software; you can redistribute it and/or modify
78684 + * it under the terms of the GNU General Public License; either version
78685 + * 2 or 3 as published by the Free Software Foundation.
78686 + */
78687 +#include <linux/module.h>
78688 +#include <linux/moduleparam.h>
78689 +#include <linux/skbuff.h>
78690 +#include <linux/netfilter/x_tables.h>
78691 +#include <linux/grsecurity.h>
78692 +#include <linux/netfilter/xt_gradm.h>
78693 +
78694 +static bool
78695 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
78696 +{
78697 + const struct xt_gradm_mtinfo *info = par->matchinfo;
78698 + bool retval = false;
78699 + if (gr_acl_is_enabled())
78700 + retval = true;
78701 + return retval ^ info->invflags;
78702 +}
78703 +
78704 +static struct xt_match gradm_mt_reg __read_mostly = {
78705 + .name = "gradm",
78706 + .revision = 0,
78707 + .family = NFPROTO_UNSPEC,
78708 + .match = gradm_mt,
78709 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
78710 + .me = THIS_MODULE,
78711 +};
78712 +
78713 +static int __init gradm_mt_init(void)
78714 +{
78715 + return xt_register_match(&gradm_mt_reg);
78716 +}
78717 +
78718 +static void __exit gradm_mt_exit(void)
78719 +{
78720 + xt_unregister_match(&gradm_mt_reg);
78721 +}
78722 +
78723 +module_init(gradm_mt_init);
78724 +module_exit(gradm_mt_exit);
78725 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
78726 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
78727 +MODULE_LICENSE("GPL");
78728 +MODULE_ALIAS("ipt_gradm");
78729 +MODULE_ALIAS("ip6t_gradm");
78730 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
78731 index 4fe4fb4..87a89e5 100644
78732 --- a/net/netfilter/xt_statistic.c
78733 +++ b/net/netfilter/xt_statistic.c
78734 @@ -19,7 +19,7 @@
78735 #include <linux/module.h>
78736
78737 struct xt_statistic_priv {
78738 - atomic_t count;
78739 + atomic_unchecked_t count;
78740 } ____cacheline_aligned_in_smp;
78741
78742 MODULE_LICENSE("GPL");
78743 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
78744 break;
78745 case XT_STATISTIC_MODE_NTH:
78746 do {
78747 - oval = atomic_read(&info->master->count);
78748 + oval = atomic_read_unchecked(&info->master->count);
78749 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
78750 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
78751 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
78752 if (nval == 0)
78753 ret = !ret;
78754 break;
78755 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
78756 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
78757 if (info->master == NULL)
78758 return -ENOMEM;
78759 - atomic_set(&info->master->count, info->u.nth.count);
78760 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
78761
78762 return 0;
78763 }
78764 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
78765 index 9172179..a4035c4 100644
78766 --- a/net/netlink/af_netlink.c
78767 +++ b/net/netlink/af_netlink.c
78768 @@ -769,7 +769,7 @@ static void netlink_overrun(struct sock *sk)
78769 sk->sk_error_report(sk);
78770 }
78771 }
78772 - atomic_inc(&sk->sk_drops);
78773 + atomic_inc_unchecked(&sk->sk_drops);
78774 }
78775
78776 static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
78777 @@ -2059,7 +2059,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
78778 sk_wmem_alloc_get(s),
78779 nlk->cb,
78780 atomic_read(&s->sk_refcnt),
78781 - atomic_read(&s->sk_drops),
78782 + atomic_read_unchecked(&s->sk_drops),
78783 sock_i_ino(s)
78784 );
78785
78786 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
78787 index 7261eb8..44e8ac6 100644
78788 --- a/net/netrom/af_netrom.c
78789 +++ b/net/netrom/af_netrom.c
78790 @@ -838,6 +838,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
78791 struct sock *sk = sock->sk;
78792 struct nr_sock *nr = nr_sk(sk);
78793
78794 + memset(sax, 0, sizeof(*sax));
78795 lock_sock(sk);
78796 if (peer != 0) {
78797 if (sk->sk_state != TCP_ESTABLISHED) {
78798 @@ -852,7 +853,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
78799 *uaddr_len = sizeof(struct full_sockaddr_ax25);
78800 } else {
78801 sax->fsa_ax25.sax25_family = AF_NETROM;
78802 - sax->fsa_ax25.sax25_ndigis = 0;
78803 sax->fsa_ax25.sax25_call = nr->source_addr;
78804 *uaddr_len = sizeof(struct sockaddr_ax25);
78805 }
78806 diff --git a/net/nfc/llcp/sock.c b/net/nfc/llcp/sock.c
78807 index ddeb9aa..e18fffd 100644
78808 --- a/net/nfc/llcp/sock.c
78809 +++ b/net/nfc/llcp/sock.c
78810 @@ -443,15 +443,11 @@ static int llcp_sock_connect(struct socket *sock, struct sockaddr *_addr,
78811 pr_debug("sock %p sk %p flags 0x%x\n", sock, sk, flags);
78812
78813 if (!addr || len < sizeof(struct sockaddr_nfc) ||
78814 - addr->sa_family != AF_NFC) {
78815 - pr_err("Invalid socket\n");
78816 + addr->sa_family != AF_NFC)
78817 return -EINVAL;
78818 - }
78819
78820 - if (addr->service_name_len == 0 && addr->dsap == 0) {
78821 - pr_err("Missing service name or dsap\n");
78822 + if (addr->service_name_len == 0 && addr->dsap == 0)
78823 return -EINVAL;
78824 - }
78825
78826 pr_debug("addr dev_idx=%u target_idx=%u protocol=%u\n", addr->dev_idx,
78827 addr->target_idx, addr->nfc_protocol);
78828 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
78829 index c5c9e2a..4814ab1 100644
78830 --- a/net/packet/af_packet.c
78831 +++ b/net/packet/af_packet.c
78832 @@ -1689,7 +1689,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
78833
78834 spin_lock(&sk->sk_receive_queue.lock);
78835 po->stats.tp_packets++;
78836 - skb->dropcount = atomic_read(&sk->sk_drops);
78837 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
78838 __skb_queue_tail(&sk->sk_receive_queue, skb);
78839 spin_unlock(&sk->sk_receive_queue.lock);
78840 sk->sk_data_ready(sk, skb->len);
78841 @@ -1698,7 +1698,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
78842 drop_n_acct:
78843 spin_lock(&sk->sk_receive_queue.lock);
78844 po->stats.tp_drops++;
78845 - atomic_inc(&sk->sk_drops);
78846 + atomic_inc_unchecked(&sk->sk_drops);
78847 spin_unlock(&sk->sk_receive_queue.lock);
78848
78849 drop_n_restore:
78850 @@ -2642,6 +2642,7 @@ out:
78851
78852 static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
78853 {
78854 + struct sock_extended_err ee;
78855 struct sock_exterr_skb *serr;
78856 struct sk_buff *skb, *skb2;
78857 int copied, err;
78858 @@ -2663,8 +2664,9 @@ static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
78859 sock_recv_timestamp(msg, sk, skb);
78860
78861 serr = SKB_EXT_ERR(skb);
78862 + ee = serr->ee;
78863 put_cmsg(msg, SOL_PACKET, PACKET_TX_TIMESTAMP,
78864 - sizeof(serr->ee), &serr->ee);
78865 + sizeof ee, &ee);
78866
78867 msg->msg_flags |= MSG_ERRQUEUE;
78868 err = copied;
78869 @@ -3276,7 +3278,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
78870 case PACKET_HDRLEN:
78871 if (len > sizeof(int))
78872 len = sizeof(int);
78873 - if (copy_from_user(&val, optval, len))
78874 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
78875 return -EFAULT;
78876 switch (val) {
78877 case TPACKET_V1:
78878 @@ -3315,7 +3317,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
78879 len = lv;
78880 if (put_user(len, optlen))
78881 return -EFAULT;
78882 - if (copy_to_user(optval, data, len))
78883 + if (len > sizeof(st) || copy_to_user(optval, data, len))
78884 return -EFAULT;
78885 return 0;
78886 }
78887 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
78888 index 5a940db..f0b9c12 100644
78889 --- a/net/phonet/af_phonet.c
78890 +++ b/net/phonet/af_phonet.c
78891 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
78892 {
78893 struct phonet_protocol *pp;
78894
78895 - if (protocol >= PHONET_NPROTO)
78896 + if (protocol < 0 || protocol >= PHONET_NPROTO)
78897 return NULL;
78898
78899 rcu_read_lock();
78900 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
78901 {
78902 int err = 0;
78903
78904 - if (protocol >= PHONET_NPROTO)
78905 + if (protocol < 0 || protocol >= PHONET_NPROTO)
78906 return -EINVAL;
78907
78908 err = proto_register(pp->prot, 1);
78909 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
78910 index 576f22c..bc7a71b 100644
78911 --- a/net/phonet/pep.c
78912 +++ b/net/phonet/pep.c
78913 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
78914
78915 case PNS_PEP_CTRL_REQ:
78916 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
78917 - atomic_inc(&sk->sk_drops);
78918 + atomic_inc_unchecked(&sk->sk_drops);
78919 break;
78920 }
78921 __skb_pull(skb, 4);
78922 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
78923 }
78924
78925 if (pn->rx_credits == 0) {
78926 - atomic_inc(&sk->sk_drops);
78927 + atomic_inc_unchecked(&sk->sk_drops);
78928 err = -ENOBUFS;
78929 break;
78930 }
78931 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
78932 }
78933
78934 if (pn->rx_credits == 0) {
78935 - atomic_inc(&sk->sk_drops);
78936 + atomic_inc_unchecked(&sk->sk_drops);
78937 err = NET_RX_DROP;
78938 break;
78939 }
78940 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
78941 index 0acc943..c727611 100644
78942 --- a/net/phonet/socket.c
78943 +++ b/net/phonet/socket.c
78944 @@ -613,8 +613,13 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
78945 pn->resource, sk->sk_state,
78946 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
78947 sock_i_uid(sk), sock_i_ino(sk),
78948 - atomic_read(&sk->sk_refcnt), sk,
78949 - atomic_read(&sk->sk_drops), &len);
78950 + atomic_read(&sk->sk_refcnt),
78951 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78952 + NULL,
78953 +#else
78954 + sk,
78955 +#endif
78956 + atomic_read_unchecked(&sk->sk_drops), &len);
78957 }
78958 seq_printf(seq, "%*s\n", 127 - len, "");
78959 return 0;
78960 diff --git a/net/rds/cong.c b/net/rds/cong.c
78961 index e5b65ac..f3b6fb7 100644
78962 --- a/net/rds/cong.c
78963 +++ b/net/rds/cong.c
78964 @@ -78,7 +78,7 @@
78965 * finds that the saved generation number is smaller than the global generation
78966 * number, it wakes up the process.
78967 */
78968 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
78969 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
78970
78971 /*
78972 * Congestion monitoring
78973 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
78974 rdsdebug("waking map %p for %pI4\n",
78975 map, &map->m_addr);
78976 rds_stats_inc(s_cong_update_received);
78977 - atomic_inc(&rds_cong_generation);
78978 + atomic_inc_unchecked(&rds_cong_generation);
78979 if (waitqueue_active(&map->m_waitq))
78980 wake_up(&map->m_waitq);
78981 if (waitqueue_active(&rds_poll_waitq))
78982 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
78983
78984 int rds_cong_updated_since(unsigned long *recent)
78985 {
78986 - unsigned long gen = atomic_read(&rds_cong_generation);
78987 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
78988
78989 if (likely(*recent == gen))
78990 return 0;
78991 diff --git a/net/rds/ib.h b/net/rds/ib.h
78992 index 8d2b3d5..227ec5b 100644
78993 --- a/net/rds/ib.h
78994 +++ b/net/rds/ib.h
78995 @@ -128,7 +128,7 @@ struct rds_ib_connection {
78996 /* sending acks */
78997 unsigned long i_ack_flags;
78998 #ifdef KERNEL_HAS_ATOMIC64
78999 - atomic64_t i_ack_next; /* next ACK to send */
79000 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
79001 #else
79002 spinlock_t i_ack_lock; /* protect i_ack_next */
79003 u64 i_ack_next; /* next ACK to send */
79004 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
79005 index a1e1162..265e129 100644
79006 --- a/net/rds/ib_cm.c
79007 +++ b/net/rds/ib_cm.c
79008 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
79009 /* Clear the ACK state */
79010 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
79011 #ifdef KERNEL_HAS_ATOMIC64
79012 - atomic64_set(&ic->i_ack_next, 0);
79013 + atomic64_set_unchecked(&ic->i_ack_next, 0);
79014 #else
79015 ic->i_ack_next = 0;
79016 #endif
79017 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
79018 index 8d19491..05a3e65 100644
79019 --- a/net/rds/ib_recv.c
79020 +++ b/net/rds/ib_recv.c
79021 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
79022 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
79023 int ack_required)
79024 {
79025 - atomic64_set(&ic->i_ack_next, seq);
79026 + atomic64_set_unchecked(&ic->i_ack_next, seq);
79027 if (ack_required) {
79028 smp_mb__before_clear_bit();
79029 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
79030 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
79031 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
79032 smp_mb__after_clear_bit();
79033
79034 - return atomic64_read(&ic->i_ack_next);
79035 + return atomic64_read_unchecked(&ic->i_ack_next);
79036 }
79037 #endif
79038
79039 diff --git a/net/rds/iw.h b/net/rds/iw.h
79040 index 04ce3b1..48119a6 100644
79041 --- a/net/rds/iw.h
79042 +++ b/net/rds/iw.h
79043 @@ -134,7 +134,7 @@ struct rds_iw_connection {
79044 /* sending acks */
79045 unsigned long i_ack_flags;
79046 #ifdef KERNEL_HAS_ATOMIC64
79047 - atomic64_t i_ack_next; /* next ACK to send */
79048 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
79049 #else
79050 spinlock_t i_ack_lock; /* protect i_ack_next */
79051 u64 i_ack_next; /* next ACK to send */
79052 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
79053 index a91e1db..cf3053f 100644
79054 --- a/net/rds/iw_cm.c
79055 +++ b/net/rds/iw_cm.c
79056 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
79057 /* Clear the ACK state */
79058 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
79059 #ifdef KERNEL_HAS_ATOMIC64
79060 - atomic64_set(&ic->i_ack_next, 0);
79061 + atomic64_set_unchecked(&ic->i_ack_next, 0);
79062 #else
79063 ic->i_ack_next = 0;
79064 #endif
79065 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
79066 index 4503335..db566b4 100644
79067 --- a/net/rds/iw_recv.c
79068 +++ b/net/rds/iw_recv.c
79069 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
79070 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
79071 int ack_required)
79072 {
79073 - atomic64_set(&ic->i_ack_next, seq);
79074 + atomic64_set_unchecked(&ic->i_ack_next, seq);
79075 if (ack_required) {
79076 smp_mb__before_clear_bit();
79077 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
79078 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
79079 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
79080 smp_mb__after_clear_bit();
79081
79082 - return atomic64_read(&ic->i_ack_next);
79083 + return atomic64_read_unchecked(&ic->i_ack_next);
79084 }
79085 #endif
79086
79087 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
79088 index edac9ef..16bcb98 100644
79089 --- a/net/rds/tcp.c
79090 +++ b/net/rds/tcp.c
79091 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
79092 int val = 1;
79093
79094 set_fs(KERNEL_DS);
79095 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
79096 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
79097 sizeof(val));
79098 set_fs(oldfs);
79099 }
79100 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
79101 index 1b4fd68..2234175 100644
79102 --- a/net/rds/tcp_send.c
79103 +++ b/net/rds/tcp_send.c
79104 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
79105
79106 oldfs = get_fs();
79107 set_fs(KERNEL_DS);
79108 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
79109 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
79110 sizeof(val));
79111 set_fs(oldfs);
79112 }
79113 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
79114 index 05996d0..5a1dfe0 100644
79115 --- a/net/rxrpc/af_rxrpc.c
79116 +++ b/net/rxrpc/af_rxrpc.c
79117 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
79118 __be32 rxrpc_epoch;
79119
79120 /* current debugging ID */
79121 -atomic_t rxrpc_debug_id;
79122 +atomic_unchecked_t rxrpc_debug_id;
79123
79124 /* count of skbs currently in use */
79125 atomic_t rxrpc_n_skbs;
79126 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
79127 index e4d9cbc..b229649 100644
79128 --- a/net/rxrpc/ar-ack.c
79129 +++ b/net/rxrpc/ar-ack.c
79130 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
79131
79132 _enter("{%d,%d,%d,%d},",
79133 call->acks_hard, call->acks_unacked,
79134 - atomic_read(&call->sequence),
79135 + atomic_read_unchecked(&call->sequence),
79136 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
79137
79138 stop = 0;
79139 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
79140
79141 /* each Tx packet has a new serial number */
79142 sp->hdr.serial =
79143 - htonl(atomic_inc_return(&call->conn->serial));
79144 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
79145
79146 hdr = (struct rxrpc_header *) txb->head;
79147 hdr->serial = sp->hdr.serial;
79148 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
79149 */
79150 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
79151 {
79152 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
79153 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
79154 }
79155
79156 /*
79157 @@ -629,7 +629,7 @@ process_further:
79158
79159 latest = ntohl(sp->hdr.serial);
79160 hard = ntohl(ack.firstPacket);
79161 - tx = atomic_read(&call->sequence);
79162 + tx = atomic_read_unchecked(&call->sequence);
79163
79164 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
79165 latest,
79166 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
79167 goto maybe_reschedule;
79168
79169 send_ACK_with_skew:
79170 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
79171 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
79172 ntohl(ack.serial));
79173 send_ACK:
79174 mtu = call->conn->trans->peer->if_mtu;
79175 @@ -1173,7 +1173,7 @@ send_ACK:
79176 ackinfo.rxMTU = htonl(5692);
79177 ackinfo.jumbo_max = htonl(4);
79178
79179 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
79180 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
79181 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
79182 ntohl(hdr.serial),
79183 ntohs(ack.maxSkew),
79184 @@ -1191,7 +1191,7 @@ send_ACK:
79185 send_message:
79186 _debug("send message");
79187
79188 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
79189 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
79190 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
79191 send_message_2:
79192
79193 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
79194 index a3bbb36..3341fb9 100644
79195 --- a/net/rxrpc/ar-call.c
79196 +++ b/net/rxrpc/ar-call.c
79197 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
79198 spin_lock_init(&call->lock);
79199 rwlock_init(&call->state_lock);
79200 atomic_set(&call->usage, 1);
79201 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
79202 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79203 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
79204
79205 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
79206 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
79207 index 4106ca9..a338d7a 100644
79208 --- a/net/rxrpc/ar-connection.c
79209 +++ b/net/rxrpc/ar-connection.c
79210 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
79211 rwlock_init(&conn->lock);
79212 spin_lock_init(&conn->state_lock);
79213 atomic_set(&conn->usage, 1);
79214 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
79215 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79216 conn->avail_calls = RXRPC_MAXCALLS;
79217 conn->size_align = 4;
79218 conn->header_size = sizeof(struct rxrpc_header);
79219 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
79220 index e7ed43a..6afa140 100644
79221 --- a/net/rxrpc/ar-connevent.c
79222 +++ b/net/rxrpc/ar-connevent.c
79223 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
79224
79225 len = iov[0].iov_len + iov[1].iov_len;
79226
79227 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
79228 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
79229 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
79230
79231 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
79232 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
79233 index 529572f..c758ca7 100644
79234 --- a/net/rxrpc/ar-input.c
79235 +++ b/net/rxrpc/ar-input.c
79236 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
79237 /* track the latest serial number on this connection for ACK packet
79238 * information */
79239 serial = ntohl(sp->hdr.serial);
79240 - hi_serial = atomic_read(&call->conn->hi_serial);
79241 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
79242 while (serial > hi_serial)
79243 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
79244 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
79245 serial);
79246
79247 /* request ACK generation for any ACK or DATA packet that requests
79248 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
79249 index a693aca..81e7293 100644
79250 --- a/net/rxrpc/ar-internal.h
79251 +++ b/net/rxrpc/ar-internal.h
79252 @@ -272,8 +272,8 @@ struct rxrpc_connection {
79253 int error; /* error code for local abort */
79254 int debug_id; /* debug ID for printks */
79255 unsigned int call_counter; /* call ID counter */
79256 - atomic_t serial; /* packet serial number counter */
79257 - atomic_t hi_serial; /* highest serial number received */
79258 + atomic_unchecked_t serial; /* packet serial number counter */
79259 + atomic_unchecked_t hi_serial; /* highest serial number received */
79260 u8 avail_calls; /* number of calls available */
79261 u8 size_align; /* data size alignment (for security) */
79262 u8 header_size; /* rxrpc + security header size */
79263 @@ -346,7 +346,7 @@ struct rxrpc_call {
79264 spinlock_t lock;
79265 rwlock_t state_lock; /* lock for state transition */
79266 atomic_t usage;
79267 - atomic_t sequence; /* Tx data packet sequence counter */
79268 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
79269 u32 abort_code; /* local/remote abort code */
79270 enum { /* current state of call */
79271 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
79272 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
79273 */
79274 extern atomic_t rxrpc_n_skbs;
79275 extern __be32 rxrpc_epoch;
79276 -extern atomic_t rxrpc_debug_id;
79277 +extern atomic_unchecked_t rxrpc_debug_id;
79278 extern struct workqueue_struct *rxrpc_workqueue;
79279
79280 /*
79281 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
79282 index 87f7135..74d3703 100644
79283 --- a/net/rxrpc/ar-local.c
79284 +++ b/net/rxrpc/ar-local.c
79285 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
79286 spin_lock_init(&local->lock);
79287 rwlock_init(&local->services_lock);
79288 atomic_set(&local->usage, 1);
79289 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
79290 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79291 memcpy(&local->srx, srx, sizeof(*srx));
79292 }
79293
79294 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
79295 index e1ac183..b43e10e 100644
79296 --- a/net/rxrpc/ar-output.c
79297 +++ b/net/rxrpc/ar-output.c
79298 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
79299 sp->hdr.cid = call->cid;
79300 sp->hdr.callNumber = call->call_id;
79301 sp->hdr.seq =
79302 - htonl(atomic_inc_return(&call->sequence));
79303 + htonl(atomic_inc_return_unchecked(&call->sequence));
79304 sp->hdr.serial =
79305 - htonl(atomic_inc_return(&conn->serial));
79306 + htonl(atomic_inc_return_unchecked(&conn->serial));
79307 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
79308 sp->hdr.userStatus = 0;
79309 sp->hdr.securityIndex = conn->security_ix;
79310 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
79311 index bebaa43..2644591 100644
79312 --- a/net/rxrpc/ar-peer.c
79313 +++ b/net/rxrpc/ar-peer.c
79314 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
79315 INIT_LIST_HEAD(&peer->error_targets);
79316 spin_lock_init(&peer->lock);
79317 atomic_set(&peer->usage, 1);
79318 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
79319 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79320 memcpy(&peer->srx, srx, sizeof(*srx));
79321
79322 rxrpc_assess_MTU_size(peer);
79323 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
79324 index 38047f7..9f48511 100644
79325 --- a/net/rxrpc/ar-proc.c
79326 +++ b/net/rxrpc/ar-proc.c
79327 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
79328 atomic_read(&conn->usage),
79329 rxrpc_conn_states[conn->state],
79330 key_serial(conn->key),
79331 - atomic_read(&conn->serial),
79332 - atomic_read(&conn->hi_serial));
79333 + atomic_read_unchecked(&conn->serial),
79334 + atomic_read_unchecked(&conn->hi_serial));
79335
79336 return 0;
79337 }
79338 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
79339 index 92df566..87ec1bf 100644
79340 --- a/net/rxrpc/ar-transport.c
79341 +++ b/net/rxrpc/ar-transport.c
79342 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
79343 spin_lock_init(&trans->client_lock);
79344 rwlock_init(&trans->conn_lock);
79345 atomic_set(&trans->usage, 1);
79346 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
79347 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79348
79349 if (peer->srx.transport.family == AF_INET) {
79350 switch (peer->srx.transport_type) {
79351 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
79352 index f226709..0e735a8 100644
79353 --- a/net/rxrpc/rxkad.c
79354 +++ b/net/rxrpc/rxkad.c
79355 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
79356
79357 len = iov[0].iov_len + iov[1].iov_len;
79358
79359 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
79360 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
79361 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
79362
79363 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
79364 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
79365
79366 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
79367
79368 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
79369 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
79370 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
79371
79372 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
79373 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
79374 index 1e2eee8..ce3967e 100644
79375 --- a/net/sctp/proc.c
79376 +++ b/net/sctp/proc.c
79377 @@ -319,7 +319,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
79378 seq_printf(seq,
79379 "%8pK %8pK %-3d %-3d %-2d %-4d "
79380 "%4d %8d %8d %7d %5lu %-5d %5d ",
79381 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
79382 + assoc, sk,
79383 + sctp_sk(sk)->type, sk->sk_state,
79384 assoc->state, hash,
79385 assoc->assoc_id,
79386 assoc->sndbuf_used,
79387 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
79388 index 5e25981..dbda919 100644
79389 --- a/net/sctp/socket.c
79390 +++ b/net/sctp/socket.c
79391 @@ -4630,6 +4630,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
79392 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
79393 if (space_left < addrlen)
79394 return -ENOMEM;
79395 + if (addrlen > sizeof(temp) || addrlen < 0)
79396 + return -EFAULT;
79397 if (copy_to_user(to, &temp, addrlen))
79398 return -EFAULT;
79399 to += addrlen;
79400 diff --git a/net/socket.c b/net/socket.c
79401 index edc3c4a..4b4e4a8 100644
79402 --- a/net/socket.c
79403 +++ b/net/socket.c
79404 @@ -88,6 +88,7 @@
79405 #include <linux/nsproxy.h>
79406 #include <linux/magic.h>
79407 #include <linux/slab.h>
79408 +#include <linux/in.h>
79409
79410 #include <asm/uaccess.h>
79411 #include <asm/unistd.h>
79412 @@ -105,6 +106,8 @@
79413 #include <linux/sockios.h>
79414 #include <linux/atalk.h>
79415
79416 +#include <linux/grsock.h>
79417 +
79418 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
79419 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
79420 unsigned long nr_segs, loff_t pos);
79421 @@ -321,7 +324,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
79422 &sockfs_dentry_operations, SOCKFS_MAGIC);
79423 }
79424
79425 -static struct vfsmount *sock_mnt __read_mostly;
79426 +struct vfsmount *sock_mnt __read_mostly;
79427
79428 static struct file_system_type sock_fs_type = {
79429 .name = "sockfs",
79430 @@ -1209,6 +1212,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
79431 return -EAFNOSUPPORT;
79432 if (type < 0 || type >= SOCK_MAX)
79433 return -EINVAL;
79434 + if (protocol < 0)
79435 + return -EINVAL;
79436
79437 /* Compatibility.
79438
79439 @@ -1340,6 +1345,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
79440 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
79441 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
79442
79443 + if(!gr_search_socket(family, type, protocol)) {
79444 + retval = -EACCES;
79445 + goto out;
79446 + }
79447 +
79448 + if (gr_handle_sock_all(family, type, protocol)) {
79449 + retval = -EACCES;
79450 + goto out;
79451 + }
79452 +
79453 retval = sock_create(family, type, protocol, &sock);
79454 if (retval < 0)
79455 goto out;
79456 @@ -1452,6 +1467,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
79457 if (sock) {
79458 err = move_addr_to_kernel(umyaddr, addrlen, &address);
79459 if (err >= 0) {
79460 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
79461 + err = -EACCES;
79462 + goto error;
79463 + }
79464 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
79465 + if (err)
79466 + goto error;
79467 +
79468 err = security_socket_bind(sock,
79469 (struct sockaddr *)&address,
79470 addrlen);
79471 @@ -1460,6 +1483,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
79472 (struct sockaddr *)
79473 &address, addrlen);
79474 }
79475 +error:
79476 fput_light(sock->file, fput_needed);
79477 }
79478 return err;
79479 @@ -1483,10 +1507,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
79480 if ((unsigned int)backlog > somaxconn)
79481 backlog = somaxconn;
79482
79483 + if (gr_handle_sock_server_other(sock->sk)) {
79484 + err = -EPERM;
79485 + goto error;
79486 + }
79487 +
79488 + err = gr_search_listen(sock);
79489 + if (err)
79490 + goto error;
79491 +
79492 err = security_socket_listen(sock, backlog);
79493 if (!err)
79494 err = sock->ops->listen(sock, backlog);
79495
79496 +error:
79497 fput_light(sock->file, fput_needed);
79498 }
79499 return err;
79500 @@ -1530,6 +1564,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
79501 newsock->type = sock->type;
79502 newsock->ops = sock->ops;
79503
79504 + if (gr_handle_sock_server_other(sock->sk)) {
79505 + err = -EPERM;
79506 + sock_release(newsock);
79507 + goto out_put;
79508 + }
79509 +
79510 + err = gr_search_accept(sock);
79511 + if (err) {
79512 + sock_release(newsock);
79513 + goto out_put;
79514 + }
79515 +
79516 /*
79517 * We don't need try_module_get here, as the listening socket (sock)
79518 * has the protocol module (sock->ops->owner) held.
79519 @@ -1568,6 +1614,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
79520 fd_install(newfd, newfile);
79521 err = newfd;
79522
79523 + gr_attach_curr_ip(newsock->sk);
79524 +
79525 out_put:
79526 fput_light(sock->file, fput_needed);
79527 out:
79528 @@ -1600,6 +1648,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
79529 int, addrlen)
79530 {
79531 struct socket *sock;
79532 + struct sockaddr *sck;
79533 struct sockaddr_storage address;
79534 int err, fput_needed;
79535
79536 @@ -1610,6 +1659,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
79537 if (err < 0)
79538 goto out_put;
79539
79540 + sck = (struct sockaddr *)&address;
79541 +
79542 + if (gr_handle_sock_client(sck)) {
79543 + err = -EACCES;
79544 + goto out_put;
79545 + }
79546 +
79547 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
79548 + if (err)
79549 + goto out_put;
79550 +
79551 err =
79552 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
79553 if (err)
79554 @@ -1964,7 +2024,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
79555 * checking falls down on this.
79556 */
79557 if (copy_from_user(ctl_buf,
79558 - (void __user __force *)msg_sys->msg_control,
79559 + (void __force_user *)msg_sys->msg_control,
79560 ctl_len))
79561 goto out_freectl;
79562 msg_sys->msg_control = ctl_buf;
79563 @@ -2132,7 +2192,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
79564 * kernel msghdr to use the kernel address space)
79565 */
79566
79567 - uaddr = (__force void __user *)msg_sys->msg_name;
79568 + uaddr = (void __force_user *)msg_sys->msg_name;
79569 uaddr_len = COMPAT_NAMELEN(msg);
79570 if (MSG_CMSG_COMPAT & flags) {
79571 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
79572 @@ -2761,7 +2821,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79573 }
79574
79575 ifr = compat_alloc_user_space(buf_size);
79576 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
79577 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
79578
79579 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
79580 return -EFAULT;
79581 @@ -2785,12 +2845,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79582 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
79583
79584 if (copy_in_user(rxnfc, compat_rxnfc,
79585 - (void *)(&rxnfc->fs.m_ext + 1) -
79586 - (void *)rxnfc) ||
79587 + (void __user *)(&rxnfc->fs.m_ext + 1) -
79588 + (void __user *)rxnfc) ||
79589 copy_in_user(&rxnfc->fs.ring_cookie,
79590 &compat_rxnfc->fs.ring_cookie,
79591 - (void *)(&rxnfc->fs.location + 1) -
79592 - (void *)&rxnfc->fs.ring_cookie) ||
79593 + (void __user *)(&rxnfc->fs.location + 1) -
79594 + (void __user *)&rxnfc->fs.ring_cookie) ||
79595 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
79596 sizeof(rxnfc->rule_cnt)))
79597 return -EFAULT;
79598 @@ -2802,12 +2862,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79599
79600 if (convert_out) {
79601 if (copy_in_user(compat_rxnfc, rxnfc,
79602 - (const void *)(&rxnfc->fs.m_ext + 1) -
79603 - (const void *)rxnfc) ||
79604 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
79605 + (const void __user *)rxnfc) ||
79606 copy_in_user(&compat_rxnfc->fs.ring_cookie,
79607 &rxnfc->fs.ring_cookie,
79608 - (const void *)(&rxnfc->fs.location + 1) -
79609 - (const void *)&rxnfc->fs.ring_cookie) ||
79610 + (const void __user *)(&rxnfc->fs.location + 1) -
79611 + (const void __user *)&rxnfc->fs.ring_cookie) ||
79612 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
79613 sizeof(rxnfc->rule_cnt)))
79614 return -EFAULT;
79615 @@ -2877,7 +2937,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
79616 old_fs = get_fs();
79617 set_fs(KERNEL_DS);
79618 err = dev_ioctl(net, cmd,
79619 - (struct ifreq __user __force *) &kifr);
79620 + (struct ifreq __force_user *) &kifr);
79621 set_fs(old_fs);
79622
79623 return err;
79624 @@ -2986,7 +3046,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
79625
79626 old_fs = get_fs();
79627 set_fs(KERNEL_DS);
79628 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
79629 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
79630 set_fs(old_fs);
79631
79632 if (cmd == SIOCGIFMAP && !err) {
79633 @@ -3091,7 +3151,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
79634 ret |= __get_user(rtdev, &(ur4->rt_dev));
79635 if (rtdev) {
79636 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
79637 - r4.rt_dev = (char __user __force *)devname;
79638 + r4.rt_dev = (char __force_user *)devname;
79639 devname[15] = 0;
79640 } else
79641 r4.rt_dev = NULL;
79642 @@ -3317,8 +3377,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
79643 int __user *uoptlen;
79644 int err;
79645
79646 - uoptval = (char __user __force *) optval;
79647 - uoptlen = (int __user __force *) optlen;
79648 + uoptval = (char __force_user *) optval;
79649 + uoptlen = (int __force_user *) optlen;
79650
79651 set_fs(KERNEL_DS);
79652 if (level == SOL_SOCKET)
79653 @@ -3338,7 +3398,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
79654 char __user *uoptval;
79655 int err;
79656
79657 - uoptval = (char __user __force *) optval;
79658 + uoptval = (char __force_user *) optval;
79659
79660 set_fs(KERNEL_DS);
79661 if (level == SOL_SOCKET)
79662 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
79663 index 128494e..775d0e0 100644
79664 --- a/net/sunrpc/sched.c
79665 +++ b/net/sunrpc/sched.c
79666 @@ -240,9 +240,9 @@ static int rpc_wait_bit_killable(void *word)
79667 #ifdef RPC_DEBUG
79668 static void rpc_task_set_debuginfo(struct rpc_task *task)
79669 {
79670 - static atomic_t rpc_pid;
79671 + static atomic_unchecked_t rpc_pid;
79672
79673 - task->tk_pid = atomic_inc_return(&rpc_pid);
79674 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
79675 }
79676 #else
79677 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
79678 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
79679 index 8343737..677025e 100644
79680 --- a/net/sunrpc/xprtrdma/svc_rdma.c
79681 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
79682 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
79683 static unsigned int min_max_inline = 4096;
79684 static unsigned int max_max_inline = 65536;
79685
79686 -atomic_t rdma_stat_recv;
79687 -atomic_t rdma_stat_read;
79688 -atomic_t rdma_stat_write;
79689 -atomic_t rdma_stat_sq_starve;
79690 -atomic_t rdma_stat_rq_starve;
79691 -atomic_t rdma_stat_rq_poll;
79692 -atomic_t rdma_stat_rq_prod;
79693 -atomic_t rdma_stat_sq_poll;
79694 -atomic_t rdma_stat_sq_prod;
79695 +atomic_unchecked_t rdma_stat_recv;
79696 +atomic_unchecked_t rdma_stat_read;
79697 +atomic_unchecked_t rdma_stat_write;
79698 +atomic_unchecked_t rdma_stat_sq_starve;
79699 +atomic_unchecked_t rdma_stat_rq_starve;
79700 +atomic_unchecked_t rdma_stat_rq_poll;
79701 +atomic_unchecked_t rdma_stat_rq_prod;
79702 +atomic_unchecked_t rdma_stat_sq_poll;
79703 +atomic_unchecked_t rdma_stat_sq_prod;
79704
79705 /* Temporary NFS request map and context caches */
79706 struct kmem_cache *svc_rdma_map_cachep;
79707 @@ -110,7 +110,7 @@ static int read_reset_stat(ctl_table *table, int write,
79708 len -= *ppos;
79709 if (len > *lenp)
79710 len = *lenp;
79711 - if (len && copy_to_user(buffer, str_buf, len))
79712 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
79713 return -EFAULT;
79714 *lenp = len;
79715 *ppos += len;
79716 @@ -151,63 +151,63 @@ static ctl_table svcrdma_parm_table[] = {
79717 {
79718 .procname = "rdma_stat_read",
79719 .data = &rdma_stat_read,
79720 - .maxlen = sizeof(atomic_t),
79721 + .maxlen = sizeof(atomic_unchecked_t),
79722 .mode = 0644,
79723 .proc_handler = read_reset_stat,
79724 },
79725 {
79726 .procname = "rdma_stat_recv",
79727 .data = &rdma_stat_recv,
79728 - .maxlen = sizeof(atomic_t),
79729 + .maxlen = sizeof(atomic_unchecked_t),
79730 .mode = 0644,
79731 .proc_handler = read_reset_stat,
79732 },
79733 {
79734 .procname = "rdma_stat_write",
79735 .data = &rdma_stat_write,
79736 - .maxlen = sizeof(atomic_t),
79737 + .maxlen = sizeof(atomic_unchecked_t),
79738 .mode = 0644,
79739 .proc_handler = read_reset_stat,
79740 },
79741 {
79742 .procname = "rdma_stat_sq_starve",
79743 .data = &rdma_stat_sq_starve,
79744 - .maxlen = sizeof(atomic_t),
79745 + .maxlen = sizeof(atomic_unchecked_t),
79746 .mode = 0644,
79747 .proc_handler = read_reset_stat,
79748 },
79749 {
79750 .procname = "rdma_stat_rq_starve",
79751 .data = &rdma_stat_rq_starve,
79752 - .maxlen = sizeof(atomic_t),
79753 + .maxlen = sizeof(atomic_unchecked_t),
79754 .mode = 0644,
79755 .proc_handler = read_reset_stat,
79756 },
79757 {
79758 .procname = "rdma_stat_rq_poll",
79759 .data = &rdma_stat_rq_poll,
79760 - .maxlen = sizeof(atomic_t),
79761 + .maxlen = sizeof(atomic_unchecked_t),
79762 .mode = 0644,
79763 .proc_handler = read_reset_stat,
79764 },
79765 {
79766 .procname = "rdma_stat_rq_prod",
79767 .data = &rdma_stat_rq_prod,
79768 - .maxlen = sizeof(atomic_t),
79769 + .maxlen = sizeof(atomic_unchecked_t),
79770 .mode = 0644,
79771 .proc_handler = read_reset_stat,
79772 },
79773 {
79774 .procname = "rdma_stat_sq_poll",
79775 .data = &rdma_stat_sq_poll,
79776 - .maxlen = sizeof(atomic_t),
79777 + .maxlen = sizeof(atomic_unchecked_t),
79778 .mode = 0644,
79779 .proc_handler = read_reset_stat,
79780 },
79781 {
79782 .procname = "rdma_stat_sq_prod",
79783 .data = &rdma_stat_sq_prod,
79784 - .maxlen = sizeof(atomic_t),
79785 + .maxlen = sizeof(atomic_unchecked_t),
79786 .mode = 0644,
79787 .proc_handler = read_reset_stat,
79788 },
79789 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
79790 index 41cb63b..c4a1489 100644
79791 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
79792 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
79793 @@ -501,7 +501,7 @@ next_sge:
79794 svc_rdma_put_context(ctxt, 0);
79795 goto out;
79796 }
79797 - atomic_inc(&rdma_stat_read);
79798 + atomic_inc_unchecked(&rdma_stat_read);
79799
79800 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
79801 chl_map->ch[ch_no].count -= read_wr.num_sge;
79802 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
79803 dto_q);
79804 list_del_init(&ctxt->dto_q);
79805 } else {
79806 - atomic_inc(&rdma_stat_rq_starve);
79807 + atomic_inc_unchecked(&rdma_stat_rq_starve);
79808 clear_bit(XPT_DATA, &xprt->xpt_flags);
79809 ctxt = NULL;
79810 }
79811 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
79812 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
79813 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
79814 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
79815 - atomic_inc(&rdma_stat_recv);
79816 + atomic_inc_unchecked(&rdma_stat_recv);
79817
79818 /* Build up the XDR from the receive buffers. */
79819 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
79820 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
79821 index 42eb7ba..c887c45 100644
79822 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
79823 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
79824 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
79825 write_wr.wr.rdma.remote_addr = to;
79826
79827 /* Post It */
79828 - atomic_inc(&rdma_stat_write);
79829 + atomic_inc_unchecked(&rdma_stat_write);
79830 if (svc_rdma_send(xprt, &write_wr))
79831 goto err;
79832 return 0;
79833 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
79834 index 73b428b..5f3f8f3 100644
79835 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
79836 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
79837 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
79838 return;
79839
79840 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
79841 - atomic_inc(&rdma_stat_rq_poll);
79842 + atomic_inc_unchecked(&rdma_stat_rq_poll);
79843
79844 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
79845 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
79846 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
79847 }
79848
79849 if (ctxt)
79850 - atomic_inc(&rdma_stat_rq_prod);
79851 + atomic_inc_unchecked(&rdma_stat_rq_prod);
79852
79853 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
79854 /*
79855 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
79856 return;
79857
79858 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
79859 - atomic_inc(&rdma_stat_sq_poll);
79860 + atomic_inc_unchecked(&rdma_stat_sq_poll);
79861 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
79862 if (wc.status != IB_WC_SUCCESS)
79863 /* Close the transport */
79864 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
79865 }
79866
79867 if (ctxt)
79868 - atomic_inc(&rdma_stat_sq_prod);
79869 + atomic_inc_unchecked(&rdma_stat_sq_prod);
79870 }
79871
79872 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
79873 @@ -1266,7 +1266,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
79874 spin_lock_bh(&xprt->sc_lock);
79875 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
79876 spin_unlock_bh(&xprt->sc_lock);
79877 - atomic_inc(&rdma_stat_sq_starve);
79878 + atomic_inc_unchecked(&rdma_stat_sq_starve);
79879
79880 /* See if we can opportunistically reap SQ WR to make room */
79881 sq_cq_reap(xprt);
79882 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
79883 index e3a6e37..be2ea77 100644
79884 --- a/net/sysctl_net.c
79885 +++ b/net/sysctl_net.c
79886 @@ -43,7 +43,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
79887 struct ctl_table *table)
79888 {
79889 /* Allow network administrator to have same access as root. */
79890 - if (capable(CAP_NET_ADMIN)) {
79891 + if (capable_nolog(CAP_NET_ADMIN)) {
79892 int mode = (table->mode >> 6) & 7;
79893 return (mode << 6) | (mode << 3) | mode;
79894 }
79895 diff --git a/net/tipc/link.c b/net/tipc/link.c
79896 index 1c1e615..113e0ae 100644
79897 --- a/net/tipc/link.c
79898 +++ b/net/tipc/link.c
79899 @@ -1171,7 +1171,7 @@ static int link_send_sections_long(struct tipc_port *sender,
79900 struct tipc_msg fragm_hdr;
79901 struct sk_buff *buf, *buf_chain, *prev;
79902 u32 fragm_crs, fragm_rest, hsz, sect_rest;
79903 - const unchar *sect_crs;
79904 + const unchar __user *sect_crs;
79905 int curr_sect;
79906 u32 fragm_no;
79907
79908 @@ -1212,7 +1212,7 @@ again:
79909
79910 if (!sect_rest) {
79911 sect_rest = msg_sect[++curr_sect].iov_len;
79912 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
79913 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
79914 }
79915
79916 if (sect_rest < fragm_rest)
79917 @@ -1231,7 +1231,7 @@ error:
79918 }
79919 } else
79920 skb_copy_to_linear_data_offset(buf, fragm_crs,
79921 - sect_crs, sz);
79922 + (const void __force_kernel *)sect_crs, sz);
79923 sect_crs += sz;
79924 sect_rest -= sz;
79925 fragm_crs += sz;
79926 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
79927 index f2db8a8..9245aa4 100644
79928 --- a/net/tipc/msg.c
79929 +++ b/net/tipc/msg.c
79930 @@ -98,7 +98,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
79931 msg_sect[cnt].iov_len);
79932 else
79933 skb_copy_to_linear_data_offset(*buf, pos,
79934 - msg_sect[cnt].iov_base,
79935 + (const void __force_kernel *)msg_sect[cnt].iov_base,
79936 msg_sect[cnt].iov_len);
79937 pos += msg_sect[cnt].iov_len;
79938 }
79939 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
79940 index 5ed5965..90abe34 100644
79941 --- a/net/tipc/subscr.c
79942 +++ b/net/tipc/subscr.c
79943 @@ -96,7 +96,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
79944 {
79945 struct iovec msg_sect;
79946
79947 - msg_sect.iov_base = (void *)&sub->evt;
79948 + msg_sect.iov_base = (void __force_user *)&sub->evt;
79949 msg_sect.iov_len = sizeof(struct tipc_event);
79950
79951 sub->evt.event = htohl(event, sub->swap);
79952 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
79953 index c5ee4ff..e905948 100644
79954 --- a/net/unix/af_unix.c
79955 +++ b/net/unix/af_unix.c
79956 @@ -789,6 +789,12 @@ static struct sock *unix_find_other(struct net *net,
79957 err = -ECONNREFUSED;
79958 if (!S_ISSOCK(inode->i_mode))
79959 goto put_fail;
79960 +
79961 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
79962 + err = -EACCES;
79963 + goto put_fail;
79964 + }
79965 +
79966 u = unix_find_socket_byinode(inode);
79967 if (!u)
79968 goto put_fail;
79969 @@ -809,6 +815,13 @@ static struct sock *unix_find_other(struct net *net,
79970 if (u) {
79971 struct dentry *dentry;
79972 dentry = unix_sk(u)->path.dentry;
79973 +
79974 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
79975 + err = -EPERM;
79976 + sock_put(u);
79977 + goto fail;
79978 + }
79979 +
79980 if (dentry)
79981 touch_atime(&unix_sk(u)->path);
79982 } else
79983 @@ -842,12 +855,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
79984 */
79985 err = security_path_mknod(&path, dentry, mode, 0);
79986 if (!err) {
79987 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
79988 + err = -EACCES;
79989 + goto out;
79990 + }
79991 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
79992 if (!err) {
79993 res->mnt = mntget(path.mnt);
79994 res->dentry = dget(dentry);
79995 + gr_handle_create(dentry, path.mnt);
79996 }
79997 }
79998 +out:
79999 done_path_create(&path, dentry);
80000 return err;
80001 }
80002 diff --git a/net/wireless/core.h b/net/wireless/core.h
80003 index bc7430b..35349de 100644
80004 --- a/net/wireless/core.h
80005 +++ b/net/wireless/core.h
80006 @@ -28,7 +28,7 @@ struct cfg80211_registered_device {
80007 struct mutex mtx;
80008
80009 /* rfkill support */
80010 - struct rfkill_ops rfkill_ops;
80011 + rfkill_ops_no_const rfkill_ops;
80012 struct rfkill *rfkill;
80013 struct work_struct rfkill_sync;
80014
80015 diff --git a/net/wireless/util.c b/net/wireless/util.c
80016 index 994e2f0..f67aeb1 100644
80017 --- a/net/wireless/util.c
80018 +++ b/net/wireless/util.c
80019 @@ -309,7 +309,7 @@ unsigned int ieee80211_get_hdrlen_from_skb(const struct sk_buff *skb)
80020 }
80021 EXPORT_SYMBOL(ieee80211_get_hdrlen_from_skb);
80022
80023 -static int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr)
80024 +unsigned int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr)
80025 {
80026 int ae = meshhdr->flags & MESH_FLAGS_AE;
80027 /* 7.1.3.5a.2 */
80028 @@ -326,6 +326,7 @@ static int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr)
80029 return 6;
80030 }
80031 }
80032 +EXPORT_SYMBOL(ieee80211_get_mesh_hdrlen);
80033
80034 int ieee80211_data_to_8023(struct sk_buff *skb, const u8 *addr,
80035 enum nl80211_iftype iftype)
80036 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
80037 index b0eb7aa..7d73e82 100644
80038 --- a/net/wireless/wext-core.c
80039 +++ b/net/wireless/wext-core.c
80040 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
80041 */
80042
80043 /* Support for very large requests */
80044 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
80045 - (user_length > descr->max_tokens)) {
80046 + if (user_length > descr->max_tokens) {
80047 /* Allow userspace to GET more than max so
80048 * we can support any size GET requests.
80049 * There is still a limit : -ENOMEM.
80050 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
80051 }
80052 }
80053
80054 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
80055 - /*
80056 - * If this is a GET, but not NOMAX, it means that the extra
80057 - * data is not bounded by userspace, but by max_tokens. Thus
80058 - * set the length to max_tokens. This matches the extra data
80059 - * allocation.
80060 - * The driver should fill it with the number of tokens it
80061 - * provided, and it may check iwp->length rather than having
80062 - * knowledge of max_tokens. If the driver doesn't change the
80063 - * iwp->length, this ioctl just copies back max_token tokens
80064 - * filled with zeroes. Hopefully the driver isn't claiming
80065 - * them to be valid data.
80066 - */
80067 - iwp->length = descr->max_tokens;
80068 - }
80069 -
80070 err = handler(dev, info, (union iwreq_data *) iwp, extra);
80071
80072 iwp->length += essid_compat;
80073 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
80074 index 387848e..a6667a2 100644
80075 --- a/net/xfrm/xfrm_policy.c
80076 +++ b/net/xfrm/xfrm_policy.c
80077 @@ -300,7 +300,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
80078 {
80079 policy->walk.dead = 1;
80080
80081 - atomic_inc(&policy->genid);
80082 + atomic_inc_unchecked(&policy->genid);
80083
80084 if (del_timer(&policy->timer))
80085 xfrm_pol_put(policy);
80086 @@ -584,7 +584,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
80087 hlist_add_head(&policy->bydst, chain);
80088 xfrm_pol_hold(policy);
80089 net->xfrm.policy_count[dir]++;
80090 - atomic_inc(&flow_cache_genid);
80091 + atomic_inc_unchecked(&flow_cache_genid);
80092 rt_genid_bump(net);
80093 if (delpol)
80094 __xfrm_policy_unlink(delpol, dir);
80095 @@ -1533,7 +1533,7 @@ free_dst:
80096 goto out;
80097 }
80098
80099 -static int inline
80100 +static inline int
80101 xfrm_dst_alloc_copy(void **target, const void *src, int size)
80102 {
80103 if (!*target) {
80104 @@ -1545,7 +1545,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
80105 return 0;
80106 }
80107
80108 -static int inline
80109 +static inline int
80110 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
80111 {
80112 #ifdef CONFIG_XFRM_SUB_POLICY
80113 @@ -1557,7 +1557,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
80114 #endif
80115 }
80116
80117 -static int inline
80118 +static inline int
80119 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
80120 {
80121 #ifdef CONFIG_XFRM_SUB_POLICY
80122 @@ -1651,7 +1651,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
80123
80124 xdst->num_pols = num_pols;
80125 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
80126 - xdst->policy_genid = atomic_read(&pols[0]->genid);
80127 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
80128
80129 return xdst;
80130 }
80131 @@ -2352,7 +2352,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
80132 if (xdst->xfrm_genid != dst->xfrm->genid)
80133 return 0;
80134 if (xdst->num_pols > 0 &&
80135 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
80136 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
80137 return 0;
80138
80139 mtu = dst_mtu(dst->child);
80140 @@ -2891,7 +2891,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
80141 sizeof(pol->xfrm_vec[i].saddr));
80142 pol->xfrm_vec[i].encap_family = mp->new_family;
80143 /* flush bundles */
80144 - atomic_inc(&pol->genid);
80145 + atomic_inc_unchecked(&pol->genid);
80146 }
80147 }
80148
80149 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
80150 index ff1720d..ed8475e 100644
80151 --- a/scripts/Makefile.build
80152 +++ b/scripts/Makefile.build
80153 @@ -111,7 +111,7 @@ endif
80154 endif
80155
80156 # Do not include host rules unless needed
80157 -ifneq ($(hostprogs-y)$(hostprogs-m),)
80158 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
80159 include scripts/Makefile.host
80160 endif
80161
80162 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
80163 index 686cb0d..9d653bf 100644
80164 --- a/scripts/Makefile.clean
80165 +++ b/scripts/Makefile.clean
80166 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
80167 __clean-files := $(extra-y) $(always) \
80168 $(targets) $(clean-files) \
80169 $(host-progs) \
80170 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
80171 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
80172 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
80173
80174 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
80175
80176 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
80177 index 1ac414f..38575f7 100644
80178 --- a/scripts/Makefile.host
80179 +++ b/scripts/Makefile.host
80180 @@ -31,6 +31,8 @@
80181 # Note: Shared libraries consisting of C++ files are not supported
80182
80183 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
80184 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
80185 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
80186
80187 # C code
80188 # Executables compiled from a single .c file
80189 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
80190 # Shared libaries (only .c supported)
80191 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
80192 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
80193 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
80194 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
80195 # Remove .so files from "xxx-objs"
80196 host-cobjs := $(filter-out %.so,$(host-cobjs))
80197 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
80198
80199 -#Object (.o) files used by the shared libaries
80200 +# Object (.o) files used by the shared libaries
80201 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
80202 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
80203
80204 # output directory for programs/.o files
80205 # hostprogs-y := tools/build may have been specified. Retrieve directory
80206 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
80207 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
80208 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
80209 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
80210 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
80211 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
80212 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
80213 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
80214
80215 obj-dirs += $(host-objdirs)
80216 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
80217 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
80218 $(call if_changed_dep,host-cshobjs)
80219
80220 +# Compile .c file, create position independent .o file
80221 +# host-cxxshobjs -> .o
80222 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
80223 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
80224 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
80225 + $(call if_changed_dep,host-cxxshobjs)
80226 +
80227 # Link a shared library, based on position independent .o files
80228 # *.o -> .so shared library (host-cshlib)
80229 quiet_cmd_host-cshlib = HOSTLLD -shared $@
80230 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
80231 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
80232 $(call if_changed,host-cshlib)
80233
80234 +# Link a shared library, based on position independent .o files
80235 +# *.o -> .so shared library (host-cxxshlib)
80236 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
80237 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
80238 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
80239 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
80240 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
80241 + $(call if_changed,host-cxxshlib)
80242 +
80243 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
80244 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
80245 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
80246
80247 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
80248 index cb1f50c..cef2a7c 100644
80249 --- a/scripts/basic/fixdep.c
80250 +++ b/scripts/basic/fixdep.c
80251 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
80252 /*
80253 * Lookup a value in the configuration string.
80254 */
80255 -static int is_defined_config(const char *name, int len, unsigned int hash)
80256 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
80257 {
80258 struct item *aux;
80259
80260 @@ -211,10 +211,10 @@ static void clear_config(void)
80261 /*
80262 * Record the use of a CONFIG_* word.
80263 */
80264 -static void use_config(const char *m, int slen)
80265 +static void use_config(const char *m, unsigned int slen)
80266 {
80267 unsigned int hash = strhash(m, slen);
80268 - int c, i;
80269 + unsigned int c, i;
80270
80271 if (is_defined_config(m, slen, hash))
80272 return;
80273 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
80274
80275 static void parse_config_file(const char *map, size_t len)
80276 {
80277 - const int *end = (const int *) (map + len);
80278 + const unsigned int *end = (const unsigned int *) (map + len);
80279 /* start at +1, so that p can never be < map */
80280 - const int *m = (const int *) map + 1;
80281 + const unsigned int *m = (const unsigned int *) map + 1;
80282 const char *p, *q;
80283
80284 for (; m < end; m++) {
80285 @@ -406,7 +406,7 @@ static void print_deps(void)
80286 static void traps(void)
80287 {
80288 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
80289 - int *p = (int *)test;
80290 + unsigned int *p = (unsigned int *)test;
80291
80292 if (*p != INT_CONF) {
80293 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
80294 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
80295 new file mode 100644
80296 index 0000000..008ac1a
80297 --- /dev/null
80298 +++ b/scripts/gcc-plugin.sh
80299 @@ -0,0 +1,17 @@
80300 +#!/bin/bash
80301 +plugincc=`$1 -x c -shared - -o /dev/null -I\`$3 -print-file-name=plugin\`/include 2>&1 <<EOF
80302 +#include "gcc-plugin.h"
80303 +#include "tree.h"
80304 +#include "tm.h"
80305 +#include "rtl.h"
80306 +#ifdef ENABLE_BUILD_WITH_CXX
80307 +#warning $2
80308 +#else
80309 +#warning $1
80310 +#endif
80311 +EOF`
80312 +if [ $? -eq 0 ]
80313 +then
80314 + [[ "$plugincc" =~ "$1" ]] && echo "$1"
80315 + [[ "$plugincc" =~ "$2" ]] && echo "$2"
80316 +fi
80317 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
80318 index b3d907e..a4782ab 100644
80319 --- a/scripts/link-vmlinux.sh
80320 +++ b/scripts/link-vmlinux.sh
80321 @@ -152,7 +152,7 @@ else
80322 fi;
80323
80324 # final build of init/
80325 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
80326 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
80327
80328 kallsymso=""
80329 kallsyms_vmlinux=""
80330 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
80331 index 7ed6864..b6e90e6 100644
80332 --- a/scripts/mod/file2alias.c
80333 +++ b/scripts/mod/file2alias.c
80334 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
80335 unsigned long size, unsigned long id_size,
80336 void *symval)
80337 {
80338 - int i;
80339 + unsigned int i;
80340
80341 if (size % id_size || size < id_size) {
80342 if (cross_build != 0)
80343 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
80344 /* USB is special because the bcdDevice can be matched against a numeric range */
80345 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
80346 static void do_usb_entry(struct usb_device_id *id,
80347 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
80348 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
80349 unsigned char range_lo, unsigned char range_hi,
80350 unsigned char max, struct module *mod)
80351 {
80352 @@ -262,7 +262,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
80353 {
80354 unsigned int devlo, devhi;
80355 unsigned char chi, clo, max;
80356 - int ndigits;
80357 + unsigned int ndigits;
80358
80359 id->match_flags = TO_NATIVE(id->match_flags);
80360 id->idVendor = TO_NATIVE(id->idVendor);
80361 @@ -507,7 +507,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
80362 for (i = 0; i < count; i++) {
80363 const char *id = (char *)devs[i].id;
80364 char acpi_id[sizeof(devs[0].id)];
80365 - int j;
80366 + unsigned int j;
80367
80368 buf_printf(&mod->dev_table_buf,
80369 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
80370 @@ -537,7 +537,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
80371
80372 for (j = 0; j < PNP_MAX_DEVICES; j++) {
80373 const char *id = (char *)card->devs[j].id;
80374 - int i2, j2;
80375 + unsigned int i2, j2;
80376 int dup = 0;
80377
80378 if (!id[0])
80379 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
80380 /* add an individual alias for every device entry */
80381 if (!dup) {
80382 char acpi_id[sizeof(card->devs[0].id)];
80383 - int k;
80384 + unsigned int k;
80385
80386 buf_printf(&mod->dev_table_buf,
80387 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
80388 @@ -888,7 +888,7 @@ static void dmi_ascii_filter(char *d, const char *s)
80389 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
80390 char *alias)
80391 {
80392 - int i, j;
80393 + unsigned int i, j;
80394
80395 sprintf(alias, "dmi*");
80396
80397 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
80398 index 68e9f5e..ac7759b 100644
80399 --- a/scripts/mod/modpost.c
80400 +++ b/scripts/mod/modpost.c
80401 @@ -930,6 +930,7 @@ enum mismatch {
80402 ANY_INIT_TO_ANY_EXIT,
80403 ANY_EXIT_TO_ANY_INIT,
80404 EXPORT_TO_INIT_EXIT,
80405 + DATA_TO_TEXT
80406 };
80407
80408 struct sectioncheck {
80409 @@ -1044,6 +1045,12 @@ const struct sectioncheck sectioncheck[] = {
80410 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
80411 .mismatch = EXPORT_TO_INIT_EXIT,
80412 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
80413 +},
80414 +/* Do not reference code from writable data */
80415 +{
80416 + .fromsec = { DATA_SECTIONS, NULL },
80417 + .tosec = { TEXT_SECTIONS, NULL },
80418 + .mismatch = DATA_TO_TEXT
80419 }
80420 };
80421
80422 @@ -1166,10 +1173,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
80423 continue;
80424 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
80425 continue;
80426 - if (sym->st_value == addr)
80427 - return sym;
80428 /* Find a symbol nearby - addr are maybe negative */
80429 d = sym->st_value - addr;
80430 + if (d == 0)
80431 + return sym;
80432 if (d < 0)
80433 d = addr - sym->st_value;
80434 if (d < distance) {
80435 @@ -1448,6 +1455,14 @@ static void report_sec_mismatch(const char *modname,
80436 tosym, prl_to, prl_to, tosym);
80437 free(prl_to);
80438 break;
80439 + case DATA_TO_TEXT:
80440 +#if 0
80441 + fprintf(stderr,
80442 + "The %s %s:%s references\n"
80443 + "the %s %s:%s%s\n",
80444 + from, fromsec, fromsym, to, tosec, tosym, to_p);
80445 +#endif
80446 + break;
80447 }
80448 fprintf(stderr, "\n");
80449 }
80450 @@ -1682,7 +1697,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
80451 static void check_sec_ref(struct module *mod, const char *modname,
80452 struct elf_info *elf)
80453 {
80454 - int i;
80455 + unsigned int i;
80456 Elf_Shdr *sechdrs = elf->sechdrs;
80457
80458 /* Walk through all sections */
80459 @@ -1780,7 +1795,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
80460 va_end(ap);
80461 }
80462
80463 -void buf_write(struct buffer *buf, const char *s, int len)
80464 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
80465 {
80466 if (buf->size - buf->pos < len) {
80467 buf->size += len + SZ;
80468 @@ -1998,7 +2013,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
80469 if (fstat(fileno(file), &st) < 0)
80470 goto close_write;
80471
80472 - if (st.st_size != b->pos)
80473 + if (st.st_size != (off_t)b->pos)
80474 goto close_write;
80475
80476 tmp = NOFAIL(malloc(b->pos));
80477 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
80478 index 51207e4..f7d603d 100644
80479 --- a/scripts/mod/modpost.h
80480 +++ b/scripts/mod/modpost.h
80481 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
80482
80483 struct buffer {
80484 char *p;
80485 - int pos;
80486 - int size;
80487 + unsigned int pos;
80488 + unsigned int size;
80489 };
80490
80491 void __attribute__((format(printf, 2, 3)))
80492 buf_printf(struct buffer *buf, const char *fmt, ...);
80493
80494 void
80495 -buf_write(struct buffer *buf, const char *s, int len);
80496 +buf_write(struct buffer *buf, const char *s, unsigned int len);
80497
80498 struct module {
80499 struct module *next;
80500 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
80501 index 9dfcd6d..099068e 100644
80502 --- a/scripts/mod/sumversion.c
80503 +++ b/scripts/mod/sumversion.c
80504 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
80505 goto out;
80506 }
80507
80508 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
80509 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
80510 warn("writing sum in %s failed: %s\n",
80511 filename, strerror(errno));
80512 goto out;
80513 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
80514 index 5c11312..72742b5 100644
80515 --- a/scripts/pnmtologo.c
80516 +++ b/scripts/pnmtologo.c
80517 @@ -237,14 +237,14 @@ static void write_header(void)
80518 fprintf(out, " * Linux logo %s\n", logoname);
80519 fputs(" */\n\n", out);
80520 fputs("#include <linux/linux_logo.h>\n\n", out);
80521 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
80522 + fprintf(out, "static unsigned char %s_data[] = {\n",
80523 logoname);
80524 }
80525
80526 static void write_footer(void)
80527 {
80528 fputs("\n};\n\n", out);
80529 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
80530 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
80531 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
80532 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
80533 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
80534 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
80535 fputs("\n};\n\n", out);
80536
80537 /* write logo clut */
80538 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
80539 + fprintf(out, "static unsigned char %s_clut[] = {\n",
80540 logoname);
80541 write_hex_cnt = 0;
80542 for (i = 0; i < logo_clutsize; i++) {
80543 diff --git a/security/Kconfig b/security/Kconfig
80544 index e9c6ac7..e7feb0d 100644
80545 --- a/security/Kconfig
80546 +++ b/security/Kconfig
80547 @@ -4,6 +4,896 @@
80548
80549 menu "Security options"
80550
80551 +menu "Grsecurity"
80552 +
80553 + config ARCH_TRACK_EXEC_LIMIT
80554 + bool
80555 +
80556 + config PAX_KERNEXEC_PLUGIN
80557 + bool
80558 +
80559 + config PAX_PER_CPU_PGD
80560 + bool
80561 +
80562 + config TASK_SIZE_MAX_SHIFT
80563 + int
80564 + depends on X86_64
80565 + default 47 if !PAX_PER_CPU_PGD
80566 + default 42 if PAX_PER_CPU_PGD
80567 +
80568 + config PAX_ENABLE_PAE
80569 + bool
80570 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
80571 +
80572 + config PAX_USERCOPY_SLABS
80573 + bool
80574 +
80575 +config GRKERNSEC
80576 + bool "Grsecurity"
80577 + select CRYPTO
80578 + select CRYPTO_SHA256
80579 + select PROC_FS
80580 + select STOP_MACHINE
80581 + help
80582 + If you say Y here, you will be able to configure many features
80583 + that will enhance the security of your system. It is highly
80584 + recommended that you say Y here and read through the help
80585 + for each option so that you fully understand the features and
80586 + can evaluate their usefulness for your machine.
80587 +
80588 +choice
80589 + prompt "Configuration Method"
80590 + depends on GRKERNSEC
80591 + default GRKERNSEC_CONFIG_CUSTOM
80592 + help
80593 +
80594 +config GRKERNSEC_CONFIG_AUTO
80595 + bool "Automatic"
80596 + help
80597 + If you choose this configuration method, you'll be able to answer a small
80598 + number of simple questions about how you plan to use this kernel.
80599 + The settings of grsecurity and PaX will be automatically configured for
80600 + the highest commonly-used settings within the provided constraints.
80601 +
80602 + If you require additional configuration, custom changes can still be made
80603 + from the "custom configuration" menu.
80604 +
80605 +config GRKERNSEC_CONFIG_CUSTOM
80606 + bool "Custom"
80607 + help
80608 + If you choose this configuration method, you'll be able to configure all
80609 + grsecurity and PaX settings manually. Via this method, no options are
80610 + automatically enabled.
80611 +
80612 +endchoice
80613 +
80614 +choice
80615 + prompt "Usage Type"
80616 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
80617 + default GRKERNSEC_CONFIG_SERVER
80618 + help
80619 +
80620 +config GRKERNSEC_CONFIG_SERVER
80621 + bool "Server"
80622 + help
80623 + Choose this option if you plan to use this kernel on a server.
80624 +
80625 +config GRKERNSEC_CONFIG_DESKTOP
80626 + bool "Desktop"
80627 + help
80628 + Choose this option if you plan to use this kernel on a desktop.
80629 +
80630 +endchoice
80631 +
80632 +choice
80633 + prompt "Virtualization Type"
80634 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
80635 + default GRKERNSEC_CONFIG_VIRT_NONE
80636 + help
80637 +
80638 +config GRKERNSEC_CONFIG_VIRT_NONE
80639 + bool "None"
80640 + help
80641 + Choose this option if this kernel will be run on bare metal.
80642 +
80643 +config GRKERNSEC_CONFIG_VIRT_GUEST
80644 + bool "Guest"
80645 + help
80646 + Choose this option if this kernel will be run as a VM guest.
80647 +
80648 +config GRKERNSEC_CONFIG_VIRT_HOST
80649 + bool "Host"
80650 + help
80651 + Choose this option if this kernel will be run as a VM host.
80652 +
80653 +endchoice
80654 +
80655 +choice
80656 + prompt "Virtualization Hardware"
80657 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
80658 + help
80659 +
80660 +config GRKERNSEC_CONFIG_VIRT_EPT
80661 + bool "EPT/RVI Processor Support"
80662 + depends on X86
80663 + help
80664 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
80665 + hardware virtualization. This allows for additional kernel hardening protections
80666 + to operate without additional performance impact.
80667 +
80668 + To see if your Intel processor supports EPT, see:
80669 + http://ark.intel.com/Products/VirtualizationTechnology
80670 + (Most Core i3/5/7 support EPT)
80671 +
80672 + To see if your AMD processor supports RVI, see:
80673 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
80674 +
80675 +config GRKERNSEC_CONFIG_VIRT_SOFT
80676 + bool "First-gen/No Hardware Virtualization"
80677 + help
80678 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
80679 + support hardware virtualization or doesn't support the EPT/RVI extensions.
80680 +
80681 +endchoice
80682 +
80683 +choice
80684 + prompt "Virtualization Software"
80685 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
80686 + help
80687 +
80688 +config GRKERNSEC_CONFIG_VIRT_XEN
80689 + bool "Xen"
80690 + help
80691 + Choose this option if this kernel is running as a Xen guest or host.
80692 +
80693 +config GRKERNSEC_CONFIG_VIRT_VMWARE
80694 + bool "VMWare"
80695 + help
80696 + Choose this option if this kernel is running as a VMWare guest or host.
80697 +
80698 +config GRKERNSEC_CONFIG_VIRT_KVM
80699 + bool "KVM"
80700 + help
80701 + Choose this option if this kernel is running as a KVM guest or host.
80702 +
80703 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
80704 + bool "VirtualBox"
80705 + help
80706 + Choose this option if this kernel is running as a VirtualBox guest or host.
80707 +
80708 +endchoice
80709 +
80710 +choice
80711 + prompt "Required Priorities"
80712 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
80713 + default GRKERNSEC_CONFIG_PRIORITY_PERF
80714 + help
80715 +
80716 +config GRKERNSEC_CONFIG_PRIORITY_PERF
80717 + bool "Performance"
80718 + help
80719 + Choose this option if performance is of highest priority for this deployment
80720 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
80721 + and freed memory sanitizing will be disabled.
80722 +
80723 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
80724 + bool "Security"
80725 + help
80726 + Choose this option if security is of highest priority for this deployment of
80727 + grsecurity. UDEREF, kernel stack clearing, and freed memory sanitizing will
80728 + be enabled for this kernel. In a worst-case scenario, these features can
80729 + introduce a 20% performance hit (UDEREF on x64 contributing half of this hit).
80730 +
80731 +endchoice
80732 +
80733 +menu "Default Special Groups"
80734 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
80735 +
80736 +config GRKERNSEC_PROC_GID
80737 + int "GID exempted from /proc restrictions"
80738 + default 1001
80739 + help
80740 + Setting this GID determines which group will be exempted from
80741 + grsecurity's /proc restrictions, allowing users of the specified
80742 + group to view network statistics and the existence of other users'
80743 + processes on the system. This GID may also be chosen at boot time
80744 + via "grsec_proc_gid=" on the kernel commandline.
80745 +
80746 +config GRKERNSEC_TPE_UNTRUSTED_GID
80747 + int "GID for TPE-untrusted users"
80748 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
80749 + default 1005
80750 + help
80751 + Setting this GID determines which group untrusted users should
80752 + be added to. These users will be placed under grsecurity's Trusted Path
80753 + Execution mechanism, preventing them from executing their own binaries.
80754 + The users will only be able to execute binaries in directories owned and
80755 + writable only by the root user. If the sysctl option is enabled, a sysctl
80756 + option with name "tpe_gid" is created.
80757 +
80758 +config GRKERNSEC_TPE_TRUSTED_GID
80759 + int "GID for TPE-trusted users"
80760 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
80761 + default 1005
80762 + help
80763 + Setting this GID determines what group TPE restrictions will be
80764 + *disabled* for. If the sysctl option is enabled, a sysctl option
80765 + with name "tpe_gid" is created.
80766 +
80767 +config GRKERNSEC_SYMLINKOWN_GID
80768 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
80769 + depends on GRKERNSEC_CONFIG_SERVER
80770 + default 1006
80771 + help
80772 + Setting this GID determines what group kernel-enforced
80773 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
80774 + is enabled, a sysctl option with name "symlinkown_gid" is created.
80775 +
80776 +
80777 +endmenu
80778 +
80779 +menu "Customize Configuration"
80780 +depends on GRKERNSEC
80781 +
80782 +menu "PaX"
80783 +
80784 +config PAX
80785 + bool "Enable various PaX features"
80786 + default y if GRKERNSEC_CONFIG_AUTO
80787 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
80788 + help
80789 + This allows you to enable various PaX features. PaX adds
80790 + intrusion prevention mechanisms to the kernel that reduce
80791 + the risks posed by exploitable memory corruption bugs.
80792 +
80793 +menu "PaX Control"
80794 + depends on PAX
80795 +
80796 +config PAX_SOFTMODE
80797 + bool 'Support soft mode'
80798 + help
80799 + Enabling this option will allow you to run PaX in soft mode, that
80800 + is, PaX features will not be enforced by default, only on executables
80801 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
80802 + support as they are the only way to mark executables for soft mode use.
80803 +
80804 + Soft mode can be activated by using the "pax_softmode=1" kernel command
80805 + line option on boot. Furthermore you can control various PaX features
80806 + at runtime via the entries in /proc/sys/kernel/pax.
80807 +
80808 +config PAX_EI_PAX
80809 + bool 'Use legacy ELF header marking'
80810 + default y if GRKERNSEC_CONFIG_AUTO
80811 + help
80812 + Enabling this option will allow you to control PaX features on
80813 + a per executable basis via the 'chpax' utility available at
80814 + http://pax.grsecurity.net/. The control flags will be read from
80815 + an otherwise reserved part of the ELF header. This marking has
80816 + numerous drawbacks (no support for soft-mode, toolchain does not
80817 + know about the non-standard use of the ELF header) therefore it
80818 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
80819 + support.
80820 +
80821 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
80822 + support as well, they will override the legacy EI_PAX marks.
80823 +
80824 + If you enable none of the marking options then all applications
80825 + will run with PaX enabled on them by default.
80826 +
80827 +config PAX_PT_PAX_FLAGS
80828 + bool 'Use ELF program header marking'
80829 + default y if GRKERNSEC_CONFIG_AUTO
80830 + help
80831 + Enabling this option will allow you to control PaX features on
80832 + a per executable basis via the 'paxctl' utility available at
80833 + http://pax.grsecurity.net/. The control flags will be read from
80834 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
80835 + has the benefits of supporting both soft mode and being fully
80836 + integrated into the toolchain (the binutils patch is available
80837 + from http://pax.grsecurity.net).
80838 +
80839 + Note that if you enable the legacy EI_PAX marking support as well,
80840 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
80841 +
80842 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
80843 + must make sure that the marks are the same if a binary has both marks.
80844 +
80845 + If you enable none of the marking options then all applications
80846 + will run with PaX enabled on them by default.
80847 +
80848 +config PAX_XATTR_PAX_FLAGS
80849 + bool 'Use filesystem extended attributes marking'
80850 + default y if GRKERNSEC_CONFIG_AUTO
80851 + select CIFS_XATTR if CIFS
80852 + select EXT2_FS_XATTR if EXT2_FS
80853 + select EXT3_FS_XATTR if EXT3_FS
80854 + select EXT4_FS_XATTR if EXT4_FS
80855 + select JFFS2_FS_XATTR if JFFS2_FS
80856 + select REISERFS_FS_XATTR if REISERFS_FS
80857 + select SQUASHFS_XATTR if SQUASHFS
80858 + select TMPFS_XATTR if TMPFS
80859 + select UBIFS_FS_XATTR if UBIFS_FS
80860 + help
80861 + Enabling this option will allow you to control PaX features on
80862 + a per executable basis via the 'setfattr' utility. The control
80863 + flags will be read from the user.pax.flags extended attribute of
80864 + the file. This marking has the benefit of supporting binary-only
80865 + applications that self-check themselves (e.g., skype) and would
80866 + not tolerate chpax/paxctl changes. The main drawback is that
80867 + extended attributes are not supported by some filesystems (e.g.,
80868 + isofs, udf, vfat) so copying files through such filesystems will
80869 + lose the extended attributes and these PaX markings.
80870 +
80871 + Note that if you enable the legacy EI_PAX marking support as well,
80872 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
80873 +
80874 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
80875 + must make sure that the marks are the same if a binary has both marks.
80876 +
80877 + If you enable none of the marking options then all applications
80878 + will run with PaX enabled on them by default.
80879 +
80880 +choice
80881 + prompt 'MAC system integration'
80882 + default PAX_HAVE_ACL_FLAGS
80883 + help
80884 + Mandatory Access Control systems have the option of controlling
80885 + PaX flags on a per executable basis, choose the method supported
80886 + by your particular system.
80887 +
80888 + - "none": if your MAC system does not interact with PaX,
80889 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
80890 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
80891 +
80892 + NOTE: this option is for developers/integrators only.
80893 +
80894 + config PAX_NO_ACL_FLAGS
80895 + bool 'none'
80896 +
80897 + config PAX_HAVE_ACL_FLAGS
80898 + bool 'direct'
80899 +
80900 + config PAX_HOOK_ACL_FLAGS
80901 + bool 'hook'
80902 +endchoice
80903 +
80904 +endmenu
80905 +
80906 +menu "Non-executable pages"
80907 + depends on PAX
80908 +
80909 +config PAX_NOEXEC
80910 + bool "Enforce non-executable pages"
80911 + default y if GRKERNSEC_CONFIG_AUTO
80912 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
80913 + help
80914 + By design some architectures do not allow for protecting memory
80915 + pages against execution or even if they do, Linux does not make
80916 + use of this feature. In practice this means that if a page is
80917 + readable (such as the stack or heap) it is also executable.
80918 +
80919 + There is a well known exploit technique that makes use of this
80920 + fact and a common programming mistake where an attacker can
80921 + introduce code of his choice somewhere in the attacked program's
80922 + memory (typically the stack or the heap) and then execute it.
80923 +
80924 + If the attacked program was running with different (typically
80925 + higher) privileges than that of the attacker, then he can elevate
80926 + his own privilege level (e.g. get a root shell, write to files for
80927 + which he does not have write access to, etc).
80928 +
80929 + Enabling this option will let you choose from various features
80930 + that prevent the injection and execution of 'foreign' code in
80931 + a program.
80932 +
80933 + This will also break programs that rely on the old behaviour and
80934 + expect that dynamically allocated memory via the malloc() family
80935 + of functions is executable (which it is not). Notable examples
80936 + are the XFree86 4.x server, the java runtime and wine.
80937 +
80938 +config PAX_PAGEEXEC
80939 + bool "Paging based non-executable pages"
80940 + default y if GRKERNSEC_CONFIG_AUTO
80941 + 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)
80942 + select S390_SWITCH_AMODE if S390
80943 + select S390_EXEC_PROTECT if S390
80944 + select ARCH_TRACK_EXEC_LIMIT if X86_32
80945 + help
80946 + This implementation is based on the paging feature of the CPU.
80947 + On i386 without hardware non-executable bit support there is a
80948 + variable but usually low performance impact, however on Intel's
80949 + P4 core based CPUs it is very high so you should not enable this
80950 + for kernels meant to be used on such CPUs.
80951 +
80952 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
80953 + with hardware non-executable bit support there is no performance
80954 + impact, on ppc the impact is negligible.
80955 +
80956 + Note that several architectures require various emulations due to
80957 + badly designed userland ABIs, this will cause a performance impact
80958 + but will disappear as soon as userland is fixed. For example, ppc
80959 + userland MUST have been built with secure-plt by a recent toolchain.
80960 +
80961 +config PAX_SEGMEXEC
80962 + bool "Segmentation based non-executable pages"
80963 + default y if GRKERNSEC_CONFIG_AUTO
80964 + depends on PAX_NOEXEC && X86_32
80965 + help
80966 + This implementation is based on the segmentation feature of the
80967 + CPU and has a very small performance impact, however applications
80968 + will be limited to a 1.5 GB address space instead of the normal
80969 + 3 GB.
80970 +
80971 +config PAX_EMUTRAMP
80972 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
80973 + default y if PARISC
80974 + help
80975 + There are some programs and libraries that for one reason or
80976 + another attempt to execute special small code snippets from
80977 + non-executable memory pages. Most notable examples are the
80978 + signal handler return code generated by the kernel itself and
80979 + the GCC trampolines.
80980 +
80981 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
80982 + such programs will no longer work under your kernel.
80983 +
80984 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
80985 + utilities to enable trampoline emulation for the affected programs
80986 + yet still have the protection provided by the non-executable pages.
80987 +
80988 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
80989 + your system will not even boot.
80990 +
80991 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
80992 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
80993 + for the affected files.
80994 +
80995 + NOTE: enabling this feature *may* open up a loophole in the
80996 + protection provided by non-executable pages that an attacker
80997 + could abuse. Therefore the best solution is to not have any
80998 + files on your system that would require this option. This can
80999 + be achieved by not using libc5 (which relies on the kernel
81000 + signal handler return code) and not using or rewriting programs
81001 + that make use of the nested function implementation of GCC.
81002 + Skilled users can just fix GCC itself so that it implements
81003 + nested function calls in a way that does not interfere with PaX.
81004 +
81005 +config PAX_EMUSIGRT
81006 + bool "Automatically emulate sigreturn trampolines"
81007 + depends on PAX_EMUTRAMP && PARISC
81008 + default y
81009 + help
81010 + Enabling this option will have the kernel automatically detect
81011 + and emulate signal return trampolines executing on the stack
81012 + that would otherwise lead to task termination.
81013 +
81014 + This solution is intended as a temporary one for users with
81015 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
81016 + Modula-3 runtime, etc) or executables linked to such, basically
81017 + everything that does not specify its own SA_RESTORER function in
81018 + normal executable memory like glibc 2.1+ does.
81019 +
81020 + On parisc you MUST enable this option, otherwise your system will
81021 + not even boot.
81022 +
81023 + NOTE: this feature cannot be disabled on a per executable basis
81024 + and since it *does* open up a loophole in the protection provided
81025 + by non-executable pages, the best solution is to not have any
81026 + files on your system that would require this option.
81027 +
81028 +config PAX_MPROTECT
81029 + bool "Restrict mprotect()"
81030 + default y if GRKERNSEC_CONFIG_AUTO
81031 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
81032 + help
81033 + Enabling this option will prevent programs from
81034 + - changing the executable status of memory pages that were
81035 + not originally created as executable,
81036 + - making read-only executable pages writable again,
81037 + - creating executable pages from anonymous memory,
81038 + - making read-only-after-relocations (RELRO) data pages writable again.
81039 +
81040 + You should say Y here to complete the protection provided by
81041 + the enforcement of non-executable pages.
81042 +
81043 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
81044 + this feature on a per file basis.
81045 +
81046 +config PAX_MPROTECT_COMPAT
81047 + bool "Use legacy/compat protection demoting (read help)"
81048 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
81049 + depends on PAX_MPROTECT
81050 + help
81051 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
81052 + by sending the proper error code to the application. For some broken
81053 + userland, this can cause problems with Python or other applications. The
81054 + current implementation however allows for applications like clamav to
81055 + detect if JIT compilation/execution is allowed and to fall back gracefully
81056 + to an interpreter-based mode if it does not. While we encourage everyone
81057 + to use the current implementation as-is and push upstream to fix broken
81058 + userland (note that the RWX logging option can assist with this), in some
81059 + environments this may not be possible. Having to disable MPROTECT
81060 + completely on certain binaries reduces the security benefit of PaX,
81061 + so this option is provided for those environments to revert to the old
81062 + behavior.
81063 +
81064 +config PAX_ELFRELOCS
81065 + bool "Allow ELF text relocations (read help)"
81066 + depends on PAX_MPROTECT
81067 + default n
81068 + help
81069 + Non-executable pages and mprotect() restrictions are effective
81070 + in preventing the introduction of new executable code into an
81071 + attacked task's address space. There remain only two venues
81072 + for this kind of attack: if the attacker can execute already
81073 + existing code in the attacked task then he can either have it
81074 + create and mmap() a file containing his code or have it mmap()
81075 + an already existing ELF library that does not have position
81076 + independent code in it and use mprotect() on it to make it
81077 + writable and copy his code there. While protecting against
81078 + the former approach is beyond PaX, the latter can be prevented
81079 + by having only PIC ELF libraries on one's system (which do not
81080 + need to relocate their code). If you are sure this is your case,
81081 + as is the case with all modern Linux distributions, then leave
81082 + this option disabled. You should say 'n' here.
81083 +
81084 +config PAX_ETEXECRELOCS
81085 + bool "Allow ELF ET_EXEC text relocations"
81086 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
81087 + select PAX_ELFRELOCS
81088 + default y
81089 + help
81090 + On some architectures there are incorrectly created applications
81091 + that require text relocations and would not work without enabling
81092 + this option. If you are an alpha, ia64 or parisc user, you should
81093 + enable this option and disable it once you have made sure that
81094 + none of your applications need it.
81095 +
81096 +config PAX_EMUPLT
81097 + bool "Automatically emulate ELF PLT"
81098 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
81099 + default y
81100 + help
81101 + Enabling this option will have the kernel automatically detect
81102 + and emulate the Procedure Linkage Table entries in ELF files.
81103 + On some architectures such entries are in writable memory, and
81104 + become non-executable leading to task termination. Therefore
81105 + it is mandatory that you enable this option on alpha, parisc,
81106 + sparc and sparc64, otherwise your system would not even boot.
81107 +
81108 + NOTE: this feature *does* open up a loophole in the protection
81109 + provided by the non-executable pages, therefore the proper
81110 + solution is to modify the toolchain to produce a PLT that does
81111 + not need to be writable.
81112 +
81113 +config PAX_DLRESOLVE
81114 + bool 'Emulate old glibc resolver stub'
81115 + depends on PAX_EMUPLT && SPARC
81116 + default n
81117 + help
81118 + This option is needed if userland has an old glibc (before 2.4)
81119 + that puts a 'save' instruction into the runtime generated resolver
81120 + stub that needs special emulation.
81121 +
81122 +config PAX_KERNEXEC
81123 + bool "Enforce non-executable kernel pages"
81124 + 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))
81125 + depends on (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
81126 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
81127 + select PAX_KERNEXEC_PLUGIN if X86_64
81128 + help
81129 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
81130 + that is, enabling this option will make it harder to inject
81131 + and execute 'foreign' code in kernel memory itself.
81132 +
81133 +choice
81134 + prompt "Return Address Instrumentation Method"
81135 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
81136 + depends on PAX_KERNEXEC_PLUGIN
81137 + help
81138 + Select the method used to instrument function pointer dereferences.
81139 + Note that binary modules cannot be instrumented by this approach.
81140 +
81141 + Note that the implementation requires a gcc with plugin support,
81142 + i.e., gcc 4.5 or newer. You may need to install the supporting
81143 + headers explicitly in addition to the normal gcc package.
81144 +
81145 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
81146 + bool "bts"
81147 + help
81148 + This method is compatible with binary only modules but has
81149 + a higher runtime overhead.
81150 +
81151 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
81152 + bool "or"
81153 + depends on !PARAVIRT
81154 + help
81155 + This method is incompatible with binary only modules but has
81156 + a lower runtime overhead.
81157 +endchoice
81158 +
81159 +config PAX_KERNEXEC_PLUGIN_METHOD
81160 + string
81161 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
81162 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
81163 + default ""
81164 +
81165 +config PAX_KERNEXEC_MODULE_TEXT
81166 + int "Minimum amount of memory reserved for module code"
81167 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
81168 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
81169 + depends on PAX_KERNEXEC && X86_32 && MODULES
81170 + help
81171 + Due to implementation details the kernel must reserve a fixed
81172 + amount of memory for module code at compile time that cannot be
81173 + changed at runtime. Here you can specify the minimum amount
81174 + in MB that will be reserved. Due to the same implementation
81175 + details this size will always be rounded up to the next 2/4 MB
81176 + boundary (depends on PAE) so the actually available memory for
81177 + module code will usually be more than this minimum.
81178 +
81179 + The default 4 MB should be enough for most users but if you have
81180 + an excessive number of modules (e.g., most distribution configs
81181 + compile many drivers as modules) or use huge modules such as
81182 + nvidia's kernel driver, you will need to adjust this amount.
81183 + A good rule of thumb is to look at your currently loaded kernel
81184 + modules and add up their sizes.
81185 +
81186 +endmenu
81187 +
81188 +menu "Address Space Layout Randomization"
81189 + depends on PAX
81190 +
81191 +config PAX_ASLR
81192 + bool "Address Space Layout Randomization"
81193 + default y if GRKERNSEC_CONFIG_AUTO
81194 + help
81195 + Many if not most exploit techniques rely on the knowledge of
81196 + certain addresses in the attacked program. The following options
81197 + will allow the kernel to apply a certain amount of randomization
81198 + to specific parts of the program thereby forcing an attacker to
81199 + guess them in most cases. Any failed guess will most likely crash
81200 + the attacked program which allows the kernel to detect such attempts
81201 + and react on them. PaX itself provides no reaction mechanisms,
81202 + instead it is strongly encouraged that you make use of Nergal's
81203 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
81204 + (http://www.grsecurity.net/) built-in crash detection features or
81205 + develop one yourself.
81206 +
81207 + By saying Y here you can choose to randomize the following areas:
81208 + - top of the task's kernel stack
81209 + - top of the task's userland stack
81210 + - base address for mmap() requests that do not specify one
81211 + (this includes all libraries)
81212 + - base address of the main executable
81213 +
81214 + It is strongly recommended to say Y here as address space layout
81215 + randomization has negligible impact on performance yet it provides
81216 + a very effective protection.
81217 +
81218 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
81219 + this feature on a per file basis.
81220 +
81221 +config PAX_RANDKSTACK
81222 + bool "Randomize kernel stack base"
81223 + default y if GRKERNSEC_CONFIG_AUTO
81224 + depends on X86_TSC && X86
81225 + help
81226 + By saying Y here the kernel will randomize every task's kernel
81227 + stack on every system call. This will not only force an attacker
81228 + to guess it but also prevent him from making use of possible
81229 + leaked information about it.
81230 +
81231 + Since the kernel stack is a rather scarce resource, randomization
81232 + may cause unexpected stack overflows, therefore you should very
81233 + carefully test your system. Note that once enabled in the kernel
81234 + configuration, this feature cannot be disabled on a per file basis.
81235 +
81236 +config PAX_RANDUSTACK
81237 + bool "Randomize user stack base"
81238 + default y if GRKERNSEC_CONFIG_AUTO
81239 + depends on PAX_ASLR
81240 + help
81241 + By saying Y here the kernel will randomize every task's userland
81242 + stack. The randomization is done in two steps where the second
81243 + one may apply a big amount of shift to the top of the stack and
81244 + cause problems for programs that want to use lots of memory (more
81245 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
81246 + For this reason the second step can be controlled by 'chpax' or
81247 + 'paxctl' on a per file basis.
81248 +
81249 +config PAX_RANDMMAP
81250 + bool "Randomize mmap() base"
81251 + default y if GRKERNSEC_CONFIG_AUTO
81252 + depends on PAX_ASLR
81253 + help
81254 + By saying Y here the kernel will use a randomized base address for
81255 + mmap() requests that do not specify one themselves. As a result
81256 + all dynamically loaded libraries will appear at random addresses
81257 + and therefore be harder to exploit by a technique where an attacker
81258 + attempts to execute library code for his purposes (e.g. spawn a
81259 + shell from an exploited program that is running at an elevated
81260 + privilege level).
81261 +
81262 + Furthermore, if a program is relinked as a dynamic ELF file, its
81263 + base address will be randomized as well, completing the full
81264 + randomization of the address space layout. Attacking such programs
81265 + becomes a guess game. You can find an example of doing this at
81266 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
81267 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
81268 +
81269 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
81270 + feature on a per file basis.
81271 +
81272 +endmenu
81273 +
81274 +menu "Miscellaneous hardening features"
81275 +
81276 +config PAX_MEMORY_SANITIZE
81277 + bool "Sanitize all freed memory"
81278 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
81279 + depends on !HIBERNATION
81280 + help
81281 + By saying Y here the kernel will erase memory pages as soon as they
81282 + are freed. This in turn reduces the lifetime of data stored in the
81283 + pages, making it less likely that sensitive information such as
81284 + passwords, cryptographic secrets, etc stay in memory for too long.
81285 +
81286 + This is especially useful for programs whose runtime is short, long
81287 + lived processes and the kernel itself benefit from this as long as
81288 + they operate on whole memory pages and ensure timely freeing of pages
81289 + that may hold sensitive information.
81290 +
81291 + The tradeoff is performance impact, on a single CPU system kernel
81292 + compilation sees a 3% slowdown, other systems and workloads may vary
81293 + and you are advised to test this feature on your expected workload
81294 + before deploying it.
81295 +
81296 + Note that this feature does not protect data stored in live pages,
81297 + e.g., process memory swapped to disk may stay there for a long time.
81298 +
81299 +config PAX_MEMORY_STACKLEAK
81300 + bool "Sanitize kernel stack"
81301 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
81302 + depends on X86
81303 + help
81304 + By saying Y here the kernel will erase the kernel stack before it
81305 + returns from a system call. This in turn reduces the information
81306 + that a kernel stack leak bug can reveal.
81307 +
81308 + Note that such a bug can still leak information that was put on
81309 + the stack by the current system call (the one eventually triggering
81310 + the bug) but traces of earlier system calls on the kernel stack
81311 + cannot leak anymore.
81312 +
81313 + The tradeoff is performance impact: on a single CPU system kernel
81314 + compilation sees a 1% slowdown, other systems and workloads may vary
81315 + and you are advised to test this feature on your expected workload
81316 + before deploying it.
81317 +
81318 + Note that the full feature requires a gcc with plugin support,
81319 + i.e., gcc 4.5 or newer. You may need to install the supporting
81320 + headers explicitly in addition to the normal gcc package. Using
81321 + older gcc versions means that functions with large enough stack
81322 + frames may leave uninitialized memory behind that may be exposed
81323 + to a later syscall leaking the stack.
81324 +
81325 +config PAX_MEMORY_UDEREF
81326 + bool "Prevent invalid userland pointer dereference"
81327 + default y if GRKERNSEC_CONFIG_AUTO && (X86_32 || (X86_64 && GRKERNSEC_CONFIG_PRIORITY_SECURITY)) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
81328 + depends on X86 && !UML_X86 && !XEN
81329 + select PAX_PER_CPU_PGD if X86_64
81330 + help
81331 + By saying Y here the kernel will be prevented from dereferencing
81332 + userland pointers in contexts where the kernel expects only kernel
81333 + pointers. This is both a useful runtime debugging feature and a
81334 + security measure that prevents exploiting a class of kernel bugs.
81335 +
81336 + The tradeoff is that some virtualization solutions may experience
81337 + a huge slowdown and therefore you should not enable this feature
81338 + for kernels meant to run in such environments. Whether a given VM
81339 + solution is affected or not is best determined by simply trying it
81340 + out, the performance impact will be obvious right on boot as this
81341 + mechanism engages from very early on. A good rule of thumb is that
81342 + VMs running on CPUs without hardware virtualization support (i.e.,
81343 + the majority of IA-32 CPUs) will likely experience the slowdown.
81344 +
81345 +config PAX_REFCOUNT
81346 + bool "Prevent various kernel object reference counter overflows"
81347 + default y if GRKERNSEC_CONFIG_AUTO
81348 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
81349 + help
81350 + By saying Y here the kernel will detect and prevent overflowing
81351 + various (but not all) kinds of object reference counters. Such
81352 + overflows can normally occur due to bugs only and are often, if
81353 + not always, exploitable.
81354 +
81355 + The tradeoff is that data structures protected by an overflowed
81356 + refcount will never be freed and therefore will leak memory. Note
81357 + that this leak also happens even without this protection but in
81358 + that case the overflow can eventually trigger the freeing of the
81359 + data structure while it is still being used elsewhere, resulting
81360 + in the exploitable situation that this feature prevents.
81361 +
81362 + Since this has a negligible performance impact, you should enable
81363 + this feature.
81364 +
81365 +config PAX_USERCOPY
81366 + bool "Harden heap object copies between kernel and userland"
81367 + default y if GRKERNSEC_CONFIG_AUTO
81368 + depends on X86 || PPC || SPARC || ARM
81369 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
81370 + select PAX_USERCOPY_SLABS
81371 + help
81372 + By saying Y here the kernel will enforce the size of heap objects
81373 + when they are copied in either direction between the kernel and
81374 + userland, even if only a part of the heap object is copied.
81375 +
81376 + Specifically, this checking prevents information leaking from the
81377 + kernel heap during kernel to userland copies (if the kernel heap
81378 + object is otherwise fully initialized) and prevents kernel heap
81379 + overflows during userland to kernel copies.
81380 +
81381 + Note that the current implementation provides the strictest bounds
81382 + checks for the SLUB allocator.
81383 +
81384 + Enabling this option also enables per-slab cache protection against
81385 + data in a given cache being copied into/out of via userland
81386 + accessors. Though the whitelist of regions will be reduced over
81387 + time, it notably protects important data structures like task structs.
81388 +
81389 + If frame pointers are enabled on x86, this option will also restrict
81390 + copies into and out of the kernel stack to local variables within a
81391 + single frame.
81392 +
81393 + Since this has a negligible performance impact, you should enable
81394 + this feature.
81395 +
81396 +config PAX_SIZE_OVERFLOW
81397 + bool "Prevent various integer overflows in function size parameters"
81398 + default y if GRKERNSEC_CONFIG_AUTO
81399 + depends on X86
81400 + help
81401 + By saying Y here the kernel recomputes expressions of function
81402 + arguments marked by a size_overflow attribute with double integer
81403 + precision (DImode/TImode for 32/64 bit integer types).
81404 +
81405 + The recomputed argument is checked against TYPE_MAX and an event
81406 + is logged on overflow and the triggering process is killed.
81407 +
81408 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
81409 +
81410 + Note that the implementation requires a gcc with plugin support,
81411 + i.e., gcc 4.5 or newer. You may need to install the supporting
81412 + headers explicitly in addition to the normal gcc package.
81413 +
81414 +config PAX_LATENT_ENTROPY
81415 + bool "Generate some entropy during boot"
81416 + default y if GRKERNSEC_CONFIG_AUTO
81417 + help
81418 + By saying Y here the kernel will instrument early boot code to
81419 + extract some entropy from both original and artificially created
81420 + program state. This will help especially embedded systems where
81421 + there is little 'natural' source of entropy normally. The cost
81422 + is some slowdown of the boot process.
81423 +
81424 + Note that the implementation requires a gcc with plugin support,
81425 + i.e., gcc 4.5 or newer. You may need to install the supporting
81426 + headers explicitly in addition to the normal gcc package.
81427 +
81428 + Note that entropy extracted this way is not cryptographically
81429 + secure!
81430 +
81431 +endmenu
81432 +
81433 +endmenu
81434 +
81435 +source grsecurity/Kconfig
81436 +
81437 +endmenu
81438 +
81439 +endmenu
81440 +
81441 source security/keys/Kconfig
81442
81443 config SECURITY_DMESG_RESTRICT
81444 @@ -103,7 +993,7 @@ config INTEL_TXT
81445 config LSM_MMAP_MIN_ADDR
81446 int "Low address space for LSM to protect from user allocation"
81447 depends on SECURITY && SECURITY_SELINUX
81448 - default 32768 if ARM
81449 + default 32768 if ALPHA || ARM || PARISC || SPARC32
81450 default 65536
81451 help
81452 This is the portion of low virtual memory which should be protected
81453 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
81454 index 8ea39aa..8569ac5 100644
81455 --- a/security/apparmor/lsm.c
81456 +++ b/security/apparmor/lsm.c
81457 @@ -614,7 +614,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
81458 return error;
81459 }
81460
81461 -static struct security_operations apparmor_ops = {
81462 +static struct security_operations apparmor_ops __read_only = {
81463 .name = "apparmor",
81464
81465 .ptrace_access_check = apparmor_ptrace_access_check,
81466 diff --git a/security/commoncap.c b/security/commoncap.c
81467 index 6dbae46..d5611fd 100644
81468 --- a/security/commoncap.c
81469 +++ b/security/commoncap.c
81470 @@ -415,6 +415,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
81471 return 0;
81472 }
81473
81474 +/* returns:
81475 + 1 for suid privilege
81476 + 2 for sgid privilege
81477 + 3 for fscap privilege
81478 +*/
81479 +int is_privileged_binary(const struct dentry *dentry)
81480 +{
81481 + struct cpu_vfs_cap_data capdata;
81482 + struct inode *inode = dentry->d_inode;
81483 +
81484 + if (!inode || S_ISDIR(inode->i_mode))
81485 + return 0;
81486 +
81487 + if (inode->i_mode & S_ISUID)
81488 + return 1;
81489 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
81490 + return 2;
81491 +
81492 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
81493 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
81494 + return 3;
81495 + }
81496 +
81497 + return 0;
81498 +}
81499 +
81500 /*
81501 * Attempt to get the on-exec apply capability sets for an executable file from
81502 * its xattrs and, if present, apply them to the proposed credentials being
81503 @@ -583,6 +609,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
81504 const struct cred *cred = current_cred();
81505 kuid_t root_uid = make_kuid(cred->user_ns, 0);
81506
81507 + if (gr_acl_enable_at_secure())
81508 + return 1;
81509 +
81510 if (!uid_eq(cred->uid, root_uid)) {
81511 if (bprm->cap_effective)
81512 return 1;
81513 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
81514 index e7c99fd..5b2fa24 100644
81515 --- a/security/integrity/ima/ima.h
81516 +++ b/security/integrity/ima/ima.h
81517 @@ -95,8 +95,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
81518 extern spinlock_t ima_queue_lock;
81519
81520 struct ima_h_table {
81521 - atomic_long_t len; /* number of stored measurements in the list */
81522 - atomic_long_t violations;
81523 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
81524 + atomic_long_unchecked_t violations;
81525 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
81526 };
81527 extern struct ima_h_table ima_htable;
81528 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
81529 index 032ff03..c428a74 100644
81530 --- a/security/integrity/ima/ima_api.c
81531 +++ b/security/integrity/ima/ima_api.c
81532 @@ -75,7 +75,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
81533 int result;
81534
81535 /* can overflow, only indicator */
81536 - atomic_long_inc(&ima_htable.violations);
81537 + atomic_long_inc_unchecked(&ima_htable.violations);
81538
81539 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
81540 if (!entry) {
81541 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
81542 index 38477c9..87a60c7 100644
81543 --- a/security/integrity/ima/ima_fs.c
81544 +++ b/security/integrity/ima/ima_fs.c
81545 @@ -28,12 +28,12 @@
81546 static int valid_policy = 1;
81547 #define TMPBUFLEN 12
81548 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
81549 - loff_t *ppos, atomic_long_t *val)
81550 + loff_t *ppos, atomic_long_unchecked_t *val)
81551 {
81552 char tmpbuf[TMPBUFLEN];
81553 ssize_t len;
81554
81555 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
81556 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
81557 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
81558 }
81559
81560 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
81561 index 55a6271..ad829c3 100644
81562 --- a/security/integrity/ima/ima_queue.c
81563 +++ b/security/integrity/ima/ima_queue.c
81564 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
81565 INIT_LIST_HEAD(&qe->later);
81566 list_add_tail_rcu(&qe->later, &ima_measurements);
81567
81568 - atomic_long_inc(&ima_htable.len);
81569 + atomic_long_inc_unchecked(&ima_htable.len);
81570 key = ima_hash_key(entry->digest);
81571 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
81572 return 0;
81573 diff --git a/security/keys/compat.c b/security/keys/compat.c
81574 index 1c26176..64a1ba2 100644
81575 --- a/security/keys/compat.c
81576 +++ b/security/keys/compat.c
81577 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
81578 if (ret == 0)
81579 goto no_payload_free;
81580
81581 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
81582 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
81583
81584 if (iov != iovstack)
81585 kfree(iov);
81586 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
81587 index 3364fbf..1f10f31 100644
81588 --- a/security/keys/keyctl.c
81589 +++ b/security/keys/keyctl.c
81590 @@ -966,7 +966,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
81591 /*
81592 * Copy the iovec data from userspace
81593 */
81594 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
81595 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
81596 unsigned ioc)
81597 {
81598 for (; ioc > 0; ioc--) {
81599 @@ -988,7 +988,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
81600 * If successful, 0 will be returned.
81601 */
81602 long keyctl_instantiate_key_common(key_serial_t id,
81603 - const struct iovec *payload_iov,
81604 + const struct iovec __user *payload_iov,
81605 unsigned ioc,
81606 size_t plen,
81607 key_serial_t ringid)
81608 @@ -1083,7 +1083,7 @@ long keyctl_instantiate_key(key_serial_t id,
81609 [0].iov_len = plen
81610 };
81611
81612 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
81613 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
81614 }
81615
81616 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
81617 @@ -1116,7 +1116,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
81618 if (ret == 0)
81619 goto no_payload_free;
81620
81621 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
81622 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
81623
81624 if (iov != iovstack)
81625 kfree(iov);
81626 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
81627 index 81e7852..2b2ecc3 100644
81628 --- a/security/keys/keyring.c
81629 +++ b/security/keys/keyring.c
81630 @@ -227,16 +227,16 @@ static long keyring_read(const struct key *keyring,
81631 ret = -EFAULT;
81632
81633 for (loop = 0; loop < klist->nkeys; loop++) {
81634 + key_serial_t serial;
81635 key = rcu_deref_link_locked(klist, loop,
81636 keyring);
81637 + serial = key->serial;
81638
81639 tmp = sizeof(key_serial_t);
81640 if (tmp > buflen)
81641 tmp = buflen;
81642
81643 - if (copy_to_user(buffer,
81644 - &key->serial,
81645 - tmp) != 0)
81646 + if (copy_to_user(buffer, &serial, tmp))
81647 goto error;
81648
81649 buflen -= tmp;
81650 diff --git a/security/min_addr.c b/security/min_addr.c
81651 index f728728..6457a0c 100644
81652 --- a/security/min_addr.c
81653 +++ b/security/min_addr.c
81654 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
81655 */
81656 static void update_mmap_min_addr(void)
81657 {
81658 +#ifndef SPARC
81659 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
81660 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
81661 mmap_min_addr = dac_mmap_min_addr;
81662 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
81663 #else
81664 mmap_min_addr = dac_mmap_min_addr;
81665 #endif
81666 +#endif
81667 }
81668
81669 /*
81670 diff --git a/security/security.c b/security/security.c
81671 index 860aeb3..45765c0 100644
81672 --- a/security/security.c
81673 +++ b/security/security.c
81674 @@ -20,6 +20,7 @@
81675 #include <linux/ima.h>
81676 #include <linux/evm.h>
81677 #include <linux/fsnotify.h>
81678 +#include <linux/mm.h>
81679 #include <linux/mman.h>
81680 #include <linux/mount.h>
81681 #include <linux/personality.h>
81682 @@ -32,8 +33,8 @@
81683 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
81684 CONFIG_DEFAULT_SECURITY;
81685
81686 -static struct security_operations *security_ops;
81687 -static struct security_operations default_security_ops = {
81688 +static struct security_operations *security_ops __read_only;
81689 +static struct security_operations default_security_ops __read_only = {
81690 .name = "default",
81691 };
81692
81693 @@ -74,7 +75,9 @@ int __init security_init(void)
81694
81695 void reset_security_ops(void)
81696 {
81697 + pax_open_kernel();
81698 security_ops = &default_security_ops;
81699 + pax_close_kernel();
81700 }
81701
81702 /* Save user chosen LSM */
81703 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
81704 index 6c77f63..7496c76 100644
81705 --- a/security/selinux/hooks.c
81706 +++ b/security/selinux/hooks.c
81707 @@ -95,8 +95,6 @@
81708
81709 #define NUM_SEL_MNT_OPTS 5
81710
81711 -extern struct security_operations *security_ops;
81712 -
81713 /* SECMARK reference count */
81714 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
81715
81716 @@ -5511,7 +5509,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
81717
81718 #endif
81719
81720 -static struct security_operations selinux_ops = {
81721 +static struct security_operations selinux_ops __read_only = {
81722 .name = "selinux",
81723
81724 .ptrace_access_check = selinux_ptrace_access_check,
81725 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
81726 index 65f67cb..3f141ef 100644
81727 --- a/security/selinux/include/xfrm.h
81728 +++ b/security/selinux/include/xfrm.h
81729 @@ -50,7 +50,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
81730
81731 static inline void selinux_xfrm_notify_policyload(void)
81732 {
81733 - atomic_inc(&flow_cache_genid);
81734 + atomic_inc_unchecked(&flow_cache_genid);
81735 rt_genid_bump(&init_net);
81736 }
81737 #else
81738 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
81739 index 8221514..5c4775f 100644
81740 --- a/security/smack/smack_lsm.c
81741 +++ b/security/smack/smack_lsm.c
81742 @@ -3429,7 +3429,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
81743 return 0;
81744 }
81745
81746 -struct security_operations smack_ops = {
81747 +struct security_operations smack_ops __read_only = {
81748 .name = "smack",
81749
81750 .ptrace_access_check = smack_ptrace_access_check,
81751 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
81752 index c2d04a5..e6a1aeb 100644
81753 --- a/security/tomoyo/tomoyo.c
81754 +++ b/security/tomoyo/tomoyo.c
81755 @@ -501,7 +501,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
81756 * tomoyo_security_ops is a "struct security_operations" which is used for
81757 * registering TOMOYO.
81758 */
81759 -static struct security_operations tomoyo_security_ops = {
81760 +static struct security_operations tomoyo_security_ops __read_only = {
81761 .name = "tomoyo",
81762 .cred_alloc_blank = tomoyo_cred_alloc_blank,
81763 .cred_prepare = tomoyo_cred_prepare,
81764 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
81765 index 51d6709..1f3dbe2 100644
81766 --- a/security/yama/Kconfig
81767 +++ b/security/yama/Kconfig
81768 @@ -1,6 +1,6 @@
81769 config SECURITY_YAMA
81770 bool "Yama support"
81771 - depends on SECURITY
81772 + depends on SECURITY && !GRKERNSEC
81773 select SECURITYFS
81774 select SECURITY_PATH
81775 default n
81776 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
81777 index 4cedc69..e59d8a3 100644
81778 --- a/sound/aoa/codecs/onyx.c
81779 +++ b/sound/aoa/codecs/onyx.c
81780 @@ -54,7 +54,7 @@ struct onyx {
81781 spdif_locked:1,
81782 analog_locked:1,
81783 original_mute:2;
81784 - int open_count;
81785 + local_t open_count;
81786 struct codec_info *codec_info;
81787
81788 /* mutex serializes concurrent access to the device
81789 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
81790 struct onyx *onyx = cii->codec_data;
81791
81792 mutex_lock(&onyx->mutex);
81793 - onyx->open_count++;
81794 + local_inc(&onyx->open_count);
81795 mutex_unlock(&onyx->mutex);
81796
81797 return 0;
81798 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
81799 struct onyx *onyx = cii->codec_data;
81800
81801 mutex_lock(&onyx->mutex);
81802 - onyx->open_count--;
81803 - if (!onyx->open_count)
81804 + if (local_dec_and_test(&onyx->open_count))
81805 onyx->spdif_locked = onyx->analog_locked = 0;
81806 mutex_unlock(&onyx->mutex);
81807
81808 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
81809 index ffd2025..df062c9 100644
81810 --- a/sound/aoa/codecs/onyx.h
81811 +++ b/sound/aoa/codecs/onyx.h
81812 @@ -11,6 +11,7 @@
81813 #include <linux/i2c.h>
81814 #include <asm/pmac_low_i2c.h>
81815 #include <asm/prom.h>
81816 +#include <asm/local.h>
81817
81818 /* PCM3052 register definitions */
81819
81820 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
81821 index 08fde00..0bf641a 100644
81822 --- a/sound/core/oss/pcm_oss.c
81823 +++ b/sound/core/oss/pcm_oss.c
81824 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
81825 if (in_kernel) {
81826 mm_segment_t fs;
81827 fs = snd_enter_user();
81828 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
81829 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
81830 snd_leave_user(fs);
81831 } else {
81832 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
81833 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
81834 }
81835 if (ret != -EPIPE && ret != -ESTRPIPE)
81836 break;
81837 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
81838 if (in_kernel) {
81839 mm_segment_t fs;
81840 fs = snd_enter_user();
81841 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
81842 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
81843 snd_leave_user(fs);
81844 } else {
81845 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
81846 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
81847 }
81848 if (ret == -EPIPE) {
81849 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
81850 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
81851 struct snd_pcm_plugin_channel *channels;
81852 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
81853 if (!in_kernel) {
81854 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
81855 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
81856 return -EFAULT;
81857 buf = runtime->oss.buffer;
81858 }
81859 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
81860 }
81861 } else {
81862 tmp = snd_pcm_oss_write2(substream,
81863 - (const char __force *)buf,
81864 + (const char __force_kernel *)buf,
81865 runtime->oss.period_bytes, 0);
81866 if (tmp <= 0)
81867 goto err;
81868 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
81869 struct snd_pcm_runtime *runtime = substream->runtime;
81870 snd_pcm_sframes_t frames, frames1;
81871 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
81872 - char __user *final_dst = (char __force __user *)buf;
81873 + char __user *final_dst = (char __force_user *)buf;
81874 if (runtime->oss.plugin_first) {
81875 struct snd_pcm_plugin_channel *channels;
81876 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
81877 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
81878 xfer += tmp;
81879 runtime->oss.buffer_used -= tmp;
81880 } else {
81881 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
81882 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
81883 runtime->oss.period_bytes, 0);
81884 if (tmp <= 0)
81885 goto err;
81886 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
81887 size1);
81888 size1 /= runtime->channels; /* frames */
81889 fs = snd_enter_user();
81890 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
81891 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
81892 snd_leave_user(fs);
81893 }
81894 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
81895 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
81896 index 91cdf94..4085161 100644
81897 --- a/sound/core/pcm_compat.c
81898 +++ b/sound/core/pcm_compat.c
81899 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
81900 int err;
81901
81902 fs = snd_enter_user();
81903 - err = snd_pcm_delay(substream, &delay);
81904 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
81905 snd_leave_user(fs);
81906 if (err < 0)
81907 return err;
81908 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
81909 index 53b5ada..2db94c8 100644
81910 --- a/sound/core/pcm_native.c
81911 +++ b/sound/core/pcm_native.c
81912 @@ -2780,11 +2780,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
81913 switch (substream->stream) {
81914 case SNDRV_PCM_STREAM_PLAYBACK:
81915 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
81916 - (void __user *)arg);
81917 + (void __force_user *)arg);
81918 break;
81919 case SNDRV_PCM_STREAM_CAPTURE:
81920 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
81921 - (void __user *)arg);
81922 + (void __force_user *)arg);
81923 break;
81924 default:
81925 result = -EINVAL;
81926 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
81927 index 5cf8d65..912a79c 100644
81928 --- a/sound/core/seq/seq_device.c
81929 +++ b/sound/core/seq/seq_device.c
81930 @@ -64,7 +64,7 @@ struct ops_list {
81931 int argsize; /* argument size */
81932
81933 /* operators */
81934 - struct snd_seq_dev_ops ops;
81935 + struct snd_seq_dev_ops *ops;
81936
81937 /* registred devices */
81938 struct list_head dev_list; /* list of devices */
81939 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
81940
81941 mutex_lock(&ops->reg_mutex);
81942 /* copy driver operators */
81943 - ops->ops = *entry;
81944 + ops->ops = entry;
81945 ops->driver |= DRIVER_LOADED;
81946 ops->argsize = argsize;
81947
81948 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
81949 dev->name, ops->id, ops->argsize, dev->argsize);
81950 return -EINVAL;
81951 }
81952 - if (ops->ops.init_device(dev) >= 0) {
81953 + if (ops->ops->init_device(dev) >= 0) {
81954 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
81955 ops->num_init_devices++;
81956 } else {
81957 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
81958 dev->name, ops->id, ops->argsize, dev->argsize);
81959 return -EINVAL;
81960 }
81961 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
81962 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
81963 dev->status = SNDRV_SEQ_DEVICE_FREE;
81964 dev->driver_data = NULL;
81965 ops->num_init_devices--;
81966 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
81967 index 2d5514b..3afae9c 100644
81968 --- a/sound/drivers/mts64.c
81969 +++ b/sound/drivers/mts64.c
81970 @@ -29,6 +29,7 @@
81971 #include <sound/initval.h>
81972 #include <sound/rawmidi.h>
81973 #include <sound/control.h>
81974 +#include <asm/local.h>
81975
81976 #define CARD_NAME "Miditerminal 4140"
81977 #define DRIVER_NAME "MTS64"
81978 @@ -67,7 +68,7 @@ struct mts64 {
81979 struct pardevice *pardev;
81980 int pardev_claimed;
81981
81982 - int open_count;
81983 + local_t open_count;
81984 int current_midi_output_port;
81985 int current_midi_input_port;
81986 u8 mode[MTS64_NUM_INPUT_PORTS];
81987 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
81988 {
81989 struct mts64 *mts = substream->rmidi->private_data;
81990
81991 - if (mts->open_count == 0) {
81992 + if (local_read(&mts->open_count) == 0) {
81993 /* We don't need a spinlock here, because this is just called
81994 if the device has not been opened before.
81995 So there aren't any IRQs from the device */
81996 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
81997
81998 msleep(50);
81999 }
82000 - ++(mts->open_count);
82001 + local_inc(&mts->open_count);
82002
82003 return 0;
82004 }
82005 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
82006 struct mts64 *mts = substream->rmidi->private_data;
82007 unsigned long flags;
82008
82009 - --(mts->open_count);
82010 - if (mts->open_count == 0) {
82011 + if (local_dec_return(&mts->open_count) == 0) {
82012 /* We need the spinlock_irqsave here because we can still
82013 have IRQs at this point */
82014 spin_lock_irqsave(&mts->lock, flags);
82015 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
82016
82017 msleep(500);
82018
82019 - } else if (mts->open_count < 0)
82020 - mts->open_count = 0;
82021 + } else if (local_read(&mts->open_count) < 0)
82022 + local_set(&mts->open_count, 0);
82023
82024 return 0;
82025 }
82026 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
82027 index b953fb4..1999c01 100644
82028 --- a/sound/drivers/opl4/opl4_lib.c
82029 +++ b/sound/drivers/opl4/opl4_lib.c
82030 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
82031 MODULE_DESCRIPTION("OPL4 driver");
82032 MODULE_LICENSE("GPL");
82033
82034 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
82035 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
82036 {
82037 int timeout = 10;
82038 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
82039 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
82040 index 8364855..59f2e2b 100644
82041 --- a/sound/drivers/portman2x4.c
82042 +++ b/sound/drivers/portman2x4.c
82043 @@ -48,6 +48,7 @@
82044 #include <sound/initval.h>
82045 #include <sound/rawmidi.h>
82046 #include <sound/control.h>
82047 +#include <asm/local.h>
82048
82049 #define CARD_NAME "Portman 2x4"
82050 #define DRIVER_NAME "portman"
82051 @@ -85,7 +86,7 @@ struct portman {
82052 struct pardevice *pardev;
82053 int pardev_claimed;
82054
82055 - int open_count;
82056 + local_t open_count;
82057 int mode[PORTMAN_NUM_INPUT_PORTS];
82058 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
82059 };
82060 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
82061 index ea995af..f1bfa37 100644
82062 --- a/sound/firewire/amdtp.c
82063 +++ b/sound/firewire/amdtp.c
82064 @@ -389,7 +389,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
82065 ptr = s->pcm_buffer_pointer + data_blocks;
82066 if (ptr >= pcm->runtime->buffer_size)
82067 ptr -= pcm->runtime->buffer_size;
82068 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
82069 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
82070
82071 s->pcm_period_pointer += data_blocks;
82072 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
82073 @@ -557,7 +557,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
82074 */
82075 void amdtp_out_stream_update(struct amdtp_out_stream *s)
82076 {
82077 - ACCESS_ONCE(s->source_node_id_field) =
82078 + ACCESS_ONCE_RW(s->source_node_id_field) =
82079 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
82080 }
82081 EXPORT_SYMBOL(amdtp_out_stream_update);
82082 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
82083 index b680c5e..061b7a0 100644
82084 --- a/sound/firewire/amdtp.h
82085 +++ b/sound/firewire/amdtp.h
82086 @@ -139,7 +139,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
82087 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
82088 struct snd_pcm_substream *pcm)
82089 {
82090 - ACCESS_ONCE(s->pcm) = pcm;
82091 + ACCESS_ONCE_RW(s->pcm) = pcm;
82092 }
82093
82094 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
82095 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
82096 index d428ffe..751ef78 100644
82097 --- a/sound/firewire/isight.c
82098 +++ b/sound/firewire/isight.c
82099 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
82100 ptr += count;
82101 if (ptr >= runtime->buffer_size)
82102 ptr -= runtime->buffer_size;
82103 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
82104 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
82105
82106 isight->period_counter += count;
82107 if (isight->period_counter >= runtime->period_size) {
82108 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
82109 if (err < 0)
82110 return err;
82111
82112 - ACCESS_ONCE(isight->pcm_active) = true;
82113 + ACCESS_ONCE_RW(isight->pcm_active) = true;
82114
82115 return 0;
82116 }
82117 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
82118 {
82119 struct isight *isight = substream->private_data;
82120
82121 - ACCESS_ONCE(isight->pcm_active) = false;
82122 + ACCESS_ONCE_RW(isight->pcm_active) = false;
82123
82124 mutex_lock(&isight->mutex);
82125 isight_stop_streaming(isight);
82126 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
82127
82128 switch (cmd) {
82129 case SNDRV_PCM_TRIGGER_START:
82130 - ACCESS_ONCE(isight->pcm_running) = true;
82131 + ACCESS_ONCE_RW(isight->pcm_running) = true;
82132 break;
82133 case SNDRV_PCM_TRIGGER_STOP:
82134 - ACCESS_ONCE(isight->pcm_running) = false;
82135 + ACCESS_ONCE_RW(isight->pcm_running) = false;
82136 break;
82137 default:
82138 return -EINVAL;
82139 diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
82140 index 7bd5e33..1fcab12 100644
82141 --- a/sound/isa/cmi8330.c
82142 +++ b/sound/isa/cmi8330.c
82143 @@ -172,7 +172,7 @@ struct snd_cmi8330 {
82144
82145 struct snd_pcm *pcm;
82146 struct snd_cmi8330_stream {
82147 - struct snd_pcm_ops ops;
82148 + snd_pcm_ops_no_const ops;
82149 snd_pcm_open_callback_t open;
82150 void *private_data; /* sb or wss */
82151 } streams[2];
82152 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
82153 index b2b3c01..e1c1e1f 100644
82154 --- a/sound/oss/sb_audio.c
82155 +++ b/sound/oss/sb_audio.c
82156 @@ -903,7 +903,7 @@ sb16_copy_from_user(int dev,
82157 buf16 = (signed short *)(localbuf + localoffs);
82158 while (c)
82159 {
82160 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
82161 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
82162 if (copy_from_user(lbuf8,
82163 userbuf+useroffs + p,
82164 locallen))
82165 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
82166 index 7d8803a..559f8d0 100644
82167 --- a/sound/oss/swarm_cs4297a.c
82168 +++ b/sound/oss/swarm_cs4297a.c
82169 @@ -2621,7 +2621,6 @@ static int __init cs4297a_init(void)
82170 {
82171 struct cs4297a_state *s;
82172 u32 pwr, id;
82173 - mm_segment_t fs;
82174 int rval;
82175 #ifndef CONFIG_BCM_CS4297A_CSWARM
82176 u64 cfg;
82177 @@ -2711,22 +2710,23 @@ static int __init cs4297a_init(void)
82178 if (!rval) {
82179 char *sb1250_duart_present;
82180
82181 +#if 0
82182 + mm_segment_t fs;
82183 fs = get_fs();
82184 set_fs(KERNEL_DS);
82185 -#if 0
82186 val = SOUND_MASK_LINE;
82187 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
82188 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
82189 val = initvol[i].vol;
82190 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
82191 }
82192 + set_fs(fs);
82193 // cs4297a_write_ac97(s, 0x18, 0x0808);
82194 #else
82195 // cs4297a_write_ac97(s, 0x5e, 0x180);
82196 cs4297a_write_ac97(s, 0x02, 0x0808);
82197 cs4297a_write_ac97(s, 0x18, 0x0808);
82198 #endif
82199 - set_fs(fs);
82200
82201 list_add(&s->list, &cs4297a_devs);
82202
82203 diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
82204 index e5a7e19..4049063 100644
82205 --- a/sound/pci/hda/hda_codec.h
82206 +++ b/sound/pci/hda/hda_codec.h
82207 @@ -614,7 +614,7 @@ struct hda_bus_ops {
82208 /* notify power-up/down from codec to controller */
82209 void (*pm_notify)(struct hda_bus *bus);
82210 #endif
82211 -};
82212 +} __no_const;
82213
82214 /* template to pass to the bus constructor */
82215 struct hda_bus_template {
82216 @@ -714,6 +714,7 @@ struct hda_codec_ops {
82217 #endif
82218 void (*reboot_notify)(struct hda_codec *codec);
82219 };
82220 +typedef struct hda_codec_ops __no_const hda_codec_ops_no_const;
82221
82222 /* record for amp information cache */
82223 struct hda_cache_head {
82224 @@ -744,7 +745,7 @@ struct hda_pcm_ops {
82225 struct snd_pcm_substream *substream);
82226 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
82227 struct snd_pcm_substream *substream);
82228 -};
82229 +} __no_const;
82230
82231 /* PCM information for each substream */
82232 struct hda_pcm_stream {
82233 @@ -802,7 +803,7 @@ struct hda_codec {
82234 const char *modelname; /* model name for preset */
82235
82236 /* set by patch */
82237 - struct hda_codec_ops patch_ops;
82238 + hda_codec_ops_no_const patch_ops;
82239
82240 /* PCM to create, set by patch_ops.build_pcms callback */
82241 unsigned int num_pcms;
82242 diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
82243 index 0da778a..bc38b84 100644
82244 --- a/sound/pci/ice1712/ice1712.h
82245 +++ b/sound/pci/ice1712/ice1712.h
82246 @@ -269,7 +269,7 @@ struct snd_ak4xxx_private {
82247 unsigned int mask_flags; /* total mask bits */
82248 struct snd_akm4xxx_ops {
82249 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
82250 - } ops;
82251 + } __no_const ops;
82252 };
82253
82254 struct snd_ice1712_spdif {
82255 @@ -285,7 +285,7 @@ struct snd_ice1712_spdif {
82256 int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
82257 void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
82258 int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
82259 - } ops;
82260 + } __no_const ops;
82261 };
82262
82263
82264 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
82265 index bddc405..2c0733c 100644
82266 --- a/sound/pci/ymfpci/ymfpci.h
82267 +++ b/sound/pci/ymfpci/ymfpci.h
82268 @@ -358,7 +358,7 @@ struct snd_ymfpci {
82269 spinlock_t reg_lock;
82270 spinlock_t voice_lock;
82271 wait_queue_head_t interrupt_sleep;
82272 - atomic_t interrupt_sleep_count;
82273 + atomic_unchecked_t interrupt_sleep_count;
82274 struct snd_info_entry *proc_entry;
82275 const struct firmware *dsp_microcode;
82276 const struct firmware *controller_microcode;
82277 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
82278 index 62b2363..ee77972 100644
82279 --- a/sound/pci/ymfpci/ymfpci_main.c
82280 +++ b/sound/pci/ymfpci/ymfpci_main.c
82281 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
82282 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
82283 break;
82284 }
82285 - if (atomic_read(&chip->interrupt_sleep_count)) {
82286 - atomic_set(&chip->interrupt_sleep_count, 0);
82287 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
82288 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
82289 wake_up(&chip->interrupt_sleep);
82290 }
82291 __end:
82292 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
82293 continue;
82294 init_waitqueue_entry(&wait, current);
82295 add_wait_queue(&chip->interrupt_sleep, &wait);
82296 - atomic_inc(&chip->interrupt_sleep_count);
82297 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
82298 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
82299 remove_wait_queue(&chip->interrupt_sleep, &wait);
82300 }
82301 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
82302 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
82303 spin_unlock(&chip->reg_lock);
82304
82305 - if (atomic_read(&chip->interrupt_sleep_count)) {
82306 - atomic_set(&chip->interrupt_sleep_count, 0);
82307 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
82308 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
82309 wake_up(&chip->interrupt_sleep);
82310 }
82311 }
82312 @@ -2402,7 +2402,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
82313 spin_lock_init(&chip->reg_lock);
82314 spin_lock_init(&chip->voice_lock);
82315 init_waitqueue_head(&chip->interrupt_sleep);
82316 - atomic_set(&chip->interrupt_sleep_count, 0);
82317 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
82318 chip->card = card;
82319 chip->pci = pci;
82320 chip->irq = -1;
82321 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
82322 new file mode 100644
82323 index 0000000..50f2f2f
82324 --- /dev/null
82325 +++ b/tools/gcc/.gitignore
82326 @@ -0,0 +1 @@
82327 +size_overflow_hash.h
82328 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
82329 new file mode 100644
82330 index 0000000..1d09b7e
82331 --- /dev/null
82332 +++ b/tools/gcc/Makefile
82333 @@ -0,0 +1,43 @@
82334 +#CC := gcc
82335 +#PLUGIN_SOURCE_FILES := pax_plugin.c
82336 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
82337 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
82338 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
82339 +
82340 +ifeq ($(PLUGINCC),$(HOSTCC))
82341 +HOSTLIBS := hostlibs
82342 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
82343 +else
82344 +HOSTLIBS := hostcxxlibs
82345 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu++98 -ggdb -Wno-unused-parameter
82346 +endif
82347 +
82348 +$(HOSTLIBS)-y := constify_plugin.so
82349 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
82350 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
82351 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
82352 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
82353 +$(HOSTLIBS)-y += colorize_plugin.so
82354 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
82355 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
82356 +
82357 +always := $($(HOSTLIBS)-y)
82358 +
82359 +constify_plugin-objs := constify_plugin.o
82360 +stackleak_plugin-objs := stackleak_plugin.o
82361 +kallocstat_plugin-objs := kallocstat_plugin.o
82362 +kernexec_plugin-objs := kernexec_plugin.o
82363 +checker_plugin-objs := checker_plugin.o
82364 +colorize_plugin-objs := colorize_plugin.o
82365 +size_overflow_plugin-objs := size_overflow_plugin.o
82366 +latent_entropy_plugin-objs := latent_entropy_plugin.o
82367 +
82368 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
82369 +
82370 +quiet_cmd_build_size_overflow_hash = GENHASH $@
82371 + cmd_build_size_overflow_hash = \
82372 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -d $< -o $@
82373 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
82374 + $(call if_changed,build_size_overflow_hash)
82375 +
82376 +targets += size_overflow_hash.h
82377 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
82378 new file mode 100644
82379 index 0000000..d41b5af
82380 --- /dev/null
82381 +++ b/tools/gcc/checker_plugin.c
82382 @@ -0,0 +1,171 @@
82383 +/*
82384 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
82385 + * Licensed under the GPL v2
82386 + *
82387 + * Note: the choice of the license means that the compilation process is
82388 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82389 + * but for the kernel it doesn't matter since it doesn't link against
82390 + * any of the gcc libraries
82391 + *
82392 + * gcc plugin to implement various sparse (source code checker) features
82393 + *
82394 + * TODO:
82395 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
82396 + *
82397 + * BUGS:
82398 + * - none known
82399 + */
82400 +#include "gcc-plugin.h"
82401 +#include "config.h"
82402 +#include "system.h"
82403 +#include "coretypes.h"
82404 +#include "tree.h"
82405 +#include "tree-pass.h"
82406 +#include "flags.h"
82407 +#include "intl.h"
82408 +#include "toplev.h"
82409 +#include "plugin.h"
82410 +//#include "expr.h" where are you...
82411 +#include "diagnostic.h"
82412 +#include "plugin-version.h"
82413 +#include "tm.h"
82414 +#include "function.h"
82415 +#include "basic-block.h"
82416 +#include "gimple.h"
82417 +#include "rtl.h"
82418 +#include "emit-rtl.h"
82419 +#include "tree-flow.h"
82420 +#include "target.h"
82421 +
82422 +extern void c_register_addr_space (const char *str, addr_space_t as);
82423 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
82424 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
82425 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
82426 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
82427 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
82428 +
82429 +extern void print_gimple_stmt(FILE *, gimple, int, int);
82430 +extern rtx emit_move_insn(rtx x, rtx y);
82431 +
82432 +int plugin_is_GPL_compatible;
82433 +
82434 +static struct plugin_info checker_plugin_info = {
82435 + .version = "201111150100",
82436 +};
82437 +
82438 +#define ADDR_SPACE_KERNEL 0
82439 +#define ADDR_SPACE_FORCE_KERNEL 1
82440 +#define ADDR_SPACE_USER 2
82441 +#define ADDR_SPACE_FORCE_USER 3
82442 +#define ADDR_SPACE_IOMEM 0
82443 +#define ADDR_SPACE_FORCE_IOMEM 0
82444 +#define ADDR_SPACE_PERCPU 0
82445 +#define ADDR_SPACE_FORCE_PERCPU 0
82446 +#define ADDR_SPACE_RCU 0
82447 +#define ADDR_SPACE_FORCE_RCU 0
82448 +
82449 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
82450 +{
82451 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
82452 +}
82453 +
82454 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
82455 +{
82456 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
82457 +}
82458 +
82459 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
82460 +{
82461 + return default_addr_space_valid_pointer_mode(mode, as);
82462 +}
82463 +
82464 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
82465 +{
82466 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
82467 +}
82468 +
82469 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
82470 +{
82471 + return default_addr_space_legitimize_address(x, oldx, mode, as);
82472 +}
82473 +
82474 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
82475 +{
82476 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
82477 + return true;
82478 +
82479 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
82480 + return true;
82481 +
82482 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
82483 + return true;
82484 +
82485 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
82486 + return true;
82487 +
82488 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
82489 + return true;
82490 +
82491 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
82492 + return true;
82493 +
82494 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
82495 + return true;
82496 +
82497 + return subset == superset;
82498 +}
82499 +
82500 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
82501 +{
82502 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
82503 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
82504 +
82505 + return op;
82506 +}
82507 +
82508 +static void register_checker_address_spaces(void *event_data, void *data)
82509 +{
82510 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
82511 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
82512 + c_register_addr_space("__user", ADDR_SPACE_USER);
82513 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
82514 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
82515 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
82516 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
82517 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
82518 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
82519 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
82520 +
82521 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
82522 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
82523 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
82524 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
82525 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
82526 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
82527 + targetm.addr_space.convert = checker_addr_space_convert;
82528 +}
82529 +
82530 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82531 +{
82532 + const char * const plugin_name = plugin_info->base_name;
82533 + const int argc = plugin_info->argc;
82534 + const struct plugin_argument * const argv = plugin_info->argv;
82535 + int i;
82536 +
82537 + if (!plugin_default_version_check(version, &gcc_version)) {
82538 + error(G_("incompatible gcc/plugin versions"));
82539 + return 1;
82540 + }
82541 +
82542 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
82543 +
82544 + for (i = 0; i < argc; ++i)
82545 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
82546 +
82547 + if (TARGET_64BIT == 0)
82548 + return 0;
82549 +
82550 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
82551 +
82552 + return 0;
82553 +}
82554 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
82555 new file mode 100644
82556 index 0000000..846aeb0
82557 --- /dev/null
82558 +++ b/tools/gcc/colorize_plugin.c
82559 @@ -0,0 +1,148 @@
82560 +/*
82561 + * Copyright 2012 by PaX Team <pageexec@freemail.hu>
82562 + * Licensed under the GPL v2
82563 + *
82564 + * Note: the choice of the license means that the compilation process is
82565 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82566 + * but for the kernel it doesn't matter since it doesn't link against
82567 + * any of the gcc libraries
82568 + *
82569 + * gcc plugin to colorize diagnostic output
82570 + *
82571 + */
82572 +
82573 +#include "gcc-plugin.h"
82574 +#include "config.h"
82575 +#include "system.h"
82576 +#include "coretypes.h"
82577 +#include "tree.h"
82578 +#include "tree-pass.h"
82579 +#include "flags.h"
82580 +#include "intl.h"
82581 +#include "toplev.h"
82582 +#include "plugin.h"
82583 +#include "diagnostic.h"
82584 +#include "plugin-version.h"
82585 +#include "tm.h"
82586 +
82587 +int plugin_is_GPL_compatible;
82588 +
82589 +static struct plugin_info colorize_plugin_info = {
82590 + .version = "201203092200",
82591 + .help = NULL,
82592 +};
82593 +
82594 +#define GREEN "\033[32m\033[2m"
82595 +#define LIGHTGREEN "\033[32m\033[1m"
82596 +#define YELLOW "\033[33m\033[2m"
82597 +#define LIGHTYELLOW "\033[33m\033[1m"
82598 +#define RED "\033[31m\033[2m"
82599 +#define LIGHTRED "\033[31m\033[1m"
82600 +#define BLUE "\033[34m\033[2m"
82601 +#define LIGHTBLUE "\033[34m\033[1m"
82602 +#define BRIGHT "\033[m\033[1m"
82603 +#define NORMAL "\033[m"
82604 +
82605 +static diagnostic_starter_fn old_starter;
82606 +static diagnostic_finalizer_fn old_finalizer;
82607 +
82608 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
82609 +{
82610 + const char *color;
82611 + char *newprefix;
82612 +
82613 + switch (diagnostic->kind) {
82614 + case DK_NOTE:
82615 + color = LIGHTBLUE;
82616 + break;
82617 +
82618 + case DK_PEDWARN:
82619 + case DK_WARNING:
82620 + color = LIGHTYELLOW;
82621 + break;
82622 +
82623 + case DK_ERROR:
82624 + case DK_FATAL:
82625 + case DK_ICE:
82626 + case DK_PERMERROR:
82627 + case DK_SORRY:
82628 + color = LIGHTRED;
82629 + break;
82630 +
82631 + default:
82632 + color = NORMAL;
82633 + }
82634 +
82635 + old_starter(context, diagnostic);
82636 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
82637 + return;
82638 + pp_destroy_prefix(context->printer);
82639 + pp_set_prefix(context->printer, newprefix);
82640 +}
82641 +
82642 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
82643 +{
82644 + old_finalizer(context, diagnostic);
82645 +}
82646 +
82647 +static void colorize_arm(void)
82648 +{
82649 + old_starter = diagnostic_starter(global_dc);
82650 + old_finalizer = diagnostic_finalizer(global_dc);
82651 +
82652 + diagnostic_starter(global_dc) = start_colorize;
82653 + diagnostic_finalizer(global_dc) = finalize_colorize;
82654 +}
82655 +
82656 +static unsigned int execute_colorize_rearm(void)
82657 +{
82658 + if (diagnostic_starter(global_dc) == start_colorize)
82659 + return 0;
82660 +
82661 + colorize_arm();
82662 + return 0;
82663 +}
82664 +
82665 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
82666 + .pass = {
82667 + .type = SIMPLE_IPA_PASS,
82668 + .name = "colorize_rearm",
82669 + .gate = NULL,
82670 + .execute = execute_colorize_rearm,
82671 + .sub = NULL,
82672 + .next = NULL,
82673 + .static_pass_number = 0,
82674 + .tv_id = TV_NONE,
82675 + .properties_required = 0,
82676 + .properties_provided = 0,
82677 + .properties_destroyed = 0,
82678 + .todo_flags_start = 0,
82679 + .todo_flags_finish = 0
82680 + }
82681 +};
82682 +
82683 +static void colorize_start_unit(void *gcc_data, void *user_data)
82684 +{
82685 + colorize_arm();
82686 +}
82687 +
82688 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82689 +{
82690 + const char * const plugin_name = plugin_info->base_name;
82691 + struct register_pass_info colorize_rearm_pass_info = {
82692 + .pass = &pass_ipa_colorize_rearm.pass,
82693 + .reference_pass_name = "*free_lang_data",
82694 + .ref_pass_instance_number = 1,
82695 + .pos_op = PASS_POS_INSERT_AFTER
82696 + };
82697 +
82698 + if (!plugin_default_version_check(version, &gcc_version)) {
82699 + error(G_("incompatible gcc/plugin versions"));
82700 + return 1;
82701 + }
82702 +
82703 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
82704 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
82705 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
82706 + return 0;
82707 +}
82708 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
82709 new file mode 100644
82710 index 0000000..92ed719
82711 --- /dev/null
82712 +++ b/tools/gcc/constify_plugin.c
82713 @@ -0,0 +1,331 @@
82714 +/*
82715 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
82716 + * Copyright 2011 by PaX Team <pageexec@freemail.hu>
82717 + * Licensed under the GPL v2, or (at your option) v3
82718 + *
82719 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
82720 + *
82721 + * Homepage:
82722 + * http://www.grsecurity.net/~ephox/const_plugin/
82723 + *
82724 + * Usage:
82725 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
82726 + * $ gcc -fplugin=constify_plugin.so test.c -O2
82727 + */
82728 +
82729 +#include "gcc-plugin.h"
82730 +#include "config.h"
82731 +#include "system.h"
82732 +#include "coretypes.h"
82733 +#include "tree.h"
82734 +#include "tree-pass.h"
82735 +#include "flags.h"
82736 +#include "intl.h"
82737 +#include "toplev.h"
82738 +#include "plugin.h"
82739 +#include "diagnostic.h"
82740 +#include "plugin-version.h"
82741 +#include "tm.h"
82742 +#include "function.h"
82743 +#include "basic-block.h"
82744 +#include "gimple.h"
82745 +#include "rtl.h"
82746 +#include "emit-rtl.h"
82747 +#include "tree-flow.h"
82748 +
82749 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
82750 +
82751 +int plugin_is_GPL_compatible;
82752 +
82753 +static struct plugin_info const_plugin_info = {
82754 + .version = "201205300030",
82755 + .help = "no-constify\tturn off constification\n",
82756 +};
82757 +
82758 +static void deconstify_tree(tree node);
82759 +
82760 +static void deconstify_type(tree type)
82761 +{
82762 + tree field;
82763 +
82764 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
82765 + tree type = TREE_TYPE(field);
82766 +
82767 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
82768 + continue;
82769 + if (!TYPE_READONLY(type))
82770 + continue;
82771 +
82772 + deconstify_tree(field);
82773 + }
82774 + TYPE_READONLY(type) = 0;
82775 + C_TYPE_FIELDS_READONLY(type) = 0;
82776 +}
82777 +
82778 +static void deconstify_tree(tree node)
82779 +{
82780 + tree old_type, new_type, field;
82781 +
82782 + old_type = TREE_TYPE(node);
82783 +
82784 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
82785 +
82786 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
82787 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
82788 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
82789 + DECL_FIELD_CONTEXT(field) = new_type;
82790 +
82791 + deconstify_type(new_type);
82792 +
82793 + TREE_READONLY(node) = 0;
82794 + TREE_TYPE(node) = new_type;
82795 +}
82796 +
82797 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
82798 +{
82799 + tree type;
82800 +
82801 + *no_add_attrs = true;
82802 + if (TREE_CODE(*node) == FUNCTION_DECL) {
82803 + error("%qE attribute does not apply to functions", name);
82804 + return NULL_TREE;
82805 + }
82806 +
82807 + if (TREE_CODE(*node) == VAR_DECL) {
82808 + error("%qE attribute does not apply to variables", name);
82809 + return NULL_TREE;
82810 + }
82811 +
82812 + if (TYPE_P(*node)) {
82813 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
82814 + *no_add_attrs = false;
82815 + else
82816 + error("%qE attribute applies to struct and union types only", name);
82817 + return NULL_TREE;
82818 + }
82819 +
82820 + type = TREE_TYPE(*node);
82821 +
82822 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
82823 + error("%qE attribute applies to struct and union types only", name);
82824 + return NULL_TREE;
82825 + }
82826 +
82827 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
82828 + error("%qE attribute is already applied to the type", name);
82829 + return NULL_TREE;
82830 + }
82831 +
82832 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
82833 + error("%qE attribute used on type that is not constified", name);
82834 + return NULL_TREE;
82835 + }
82836 +
82837 + if (TREE_CODE(*node) == TYPE_DECL) {
82838 + deconstify_tree(*node);
82839 + return NULL_TREE;
82840 + }
82841 +
82842 + return NULL_TREE;
82843 +}
82844 +
82845 +static void constify_type(tree type)
82846 +{
82847 + TYPE_READONLY(type) = 1;
82848 + C_TYPE_FIELDS_READONLY(type) = 1;
82849 +}
82850 +
82851 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
82852 +{
82853 + *no_add_attrs = true;
82854 + if (!TYPE_P(*node)) {
82855 + error("%qE attribute applies to types only", name);
82856 + return NULL_TREE;
82857 + }
82858 +
82859 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
82860 + error("%qE attribute applies to struct and union types only", name);
82861 + return NULL_TREE;
82862 + }
82863 +
82864 + *no_add_attrs = false;
82865 + constify_type(*node);
82866 + return NULL_TREE;
82867 +}
82868 +
82869 +static struct attribute_spec no_const_attr = {
82870 + .name = "no_const",
82871 + .min_length = 0,
82872 + .max_length = 0,
82873 + .decl_required = false,
82874 + .type_required = false,
82875 + .function_type_required = false,
82876 + .handler = handle_no_const_attribute,
82877 +#if BUILDING_GCC_VERSION >= 4007
82878 + .affects_type_identity = true
82879 +#endif
82880 +};
82881 +
82882 +static struct attribute_spec do_const_attr = {
82883 + .name = "do_const",
82884 + .min_length = 0,
82885 + .max_length = 0,
82886 + .decl_required = false,
82887 + .type_required = false,
82888 + .function_type_required = false,
82889 + .handler = handle_do_const_attribute,
82890 +#if BUILDING_GCC_VERSION >= 4007
82891 + .affects_type_identity = true
82892 +#endif
82893 +};
82894 +
82895 +static void register_attributes(void *event_data, void *data)
82896 +{
82897 + register_attribute(&no_const_attr);
82898 + register_attribute(&do_const_attr);
82899 +}
82900 +
82901 +static bool is_fptr(tree field)
82902 +{
82903 + tree ptr = TREE_TYPE(field);
82904 +
82905 + if (TREE_CODE(ptr) != POINTER_TYPE)
82906 + return false;
82907 +
82908 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
82909 +}
82910 +
82911 +static bool walk_struct(tree node)
82912 +{
82913 + tree field;
82914 +
82915 + if (TYPE_FIELDS(node) == NULL_TREE)
82916 + return false;
82917 +
82918 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
82919 + gcc_assert(!TYPE_READONLY(node));
82920 + deconstify_type(node);
82921 + return false;
82922 + }
82923 +
82924 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
82925 + tree type = TREE_TYPE(field);
82926 + enum tree_code code = TREE_CODE(type);
82927 +
82928 + if (node == type)
82929 + return false;
82930 + if (code == RECORD_TYPE || code == UNION_TYPE) {
82931 + if (!(walk_struct(type)))
82932 + return false;
82933 + } else if (!is_fptr(field) && !TREE_READONLY(field))
82934 + return false;
82935 + }
82936 + return true;
82937 +}
82938 +
82939 +static void finish_type(void *event_data, void *data)
82940 +{
82941 + tree type = (tree)event_data;
82942 +
82943 + if (type == NULL_TREE || type == error_mark_node)
82944 + return;
82945 +
82946 + if (TYPE_READONLY(type))
82947 + return;
82948 +
82949 + if (walk_struct(type))
82950 + constify_type(type);
82951 +}
82952 +
82953 +static unsigned int check_local_variables(void);
82954 +
82955 +struct gimple_opt_pass pass_local_variable = {
82956 + {
82957 + .type = GIMPLE_PASS,
82958 + .name = "check_local_variables",
82959 + .gate = NULL,
82960 + .execute = check_local_variables,
82961 + .sub = NULL,
82962 + .next = NULL,
82963 + .static_pass_number = 0,
82964 + .tv_id = TV_NONE,
82965 + .properties_required = 0,
82966 + .properties_provided = 0,
82967 + .properties_destroyed = 0,
82968 + .todo_flags_start = 0,
82969 + .todo_flags_finish = 0
82970 + }
82971 +};
82972 +
82973 +static unsigned int check_local_variables(void)
82974 +{
82975 + tree var;
82976 + referenced_var_iterator rvi;
82977 +
82978 +#if BUILDING_GCC_VERSION == 4005
82979 + FOR_EACH_REFERENCED_VAR(var, rvi) {
82980 +#else
82981 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
82982 +#endif
82983 + tree type = TREE_TYPE(var);
82984 +
82985 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
82986 + continue;
82987 +
82988 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
82989 + continue;
82990 +
82991 + if (!TYPE_READONLY(type))
82992 + continue;
82993 +
82994 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
82995 +// continue;
82996 +
82997 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
82998 +// continue;
82999 +
83000 + if (walk_struct(type)) {
83001 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
83002 + return 1;
83003 + }
83004 + }
83005 + return 0;
83006 +}
83007 +
83008 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83009 +{
83010 + const char * const plugin_name = plugin_info->base_name;
83011 + const int argc = plugin_info->argc;
83012 + const struct plugin_argument * const argv = plugin_info->argv;
83013 + int i;
83014 + bool constify = true;
83015 +
83016 + struct register_pass_info local_variable_pass_info = {
83017 + .pass = &pass_local_variable.pass,
83018 + .reference_pass_name = "*referenced_vars",
83019 + .ref_pass_instance_number = 1,
83020 + .pos_op = PASS_POS_INSERT_AFTER
83021 + };
83022 +
83023 + if (!plugin_default_version_check(version, &gcc_version)) {
83024 + error(G_("incompatible gcc/plugin versions"));
83025 + return 1;
83026 + }
83027 +
83028 + for (i = 0; i < argc; ++i) {
83029 + if (!(strcmp(argv[i].key, "no-constify"))) {
83030 + constify = false;
83031 + continue;
83032 + }
83033 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
83034 + }
83035 +
83036 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
83037 + if (constify) {
83038 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
83039 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
83040 + }
83041 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
83042 +
83043 + return 0;
83044 +}
83045 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
83046 new file mode 100644
83047 index 0000000..02c6bec
83048 --- /dev/null
83049 +++ b/tools/gcc/generate_size_overflow_hash.sh
83050 @@ -0,0 +1,94 @@
83051 +#!/bin/bash
83052 +
83053 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
83054 +
83055 +header1="size_overflow_hash.h"
83056 +database="size_overflow_hash.data"
83057 +n=65536
83058 +
83059 +usage() {
83060 +cat <<EOF
83061 +usage: $0 options
83062 +OPTIONS:
83063 + -h|--help help
83064 + -o header file
83065 + -d database file
83066 + -n hash array size
83067 +EOF
83068 + return 0
83069 +}
83070 +
83071 +while true
83072 +do
83073 + case "$1" in
83074 + -h|--help) usage && exit 0;;
83075 + -n) n=$2; shift 2;;
83076 + -o) header1="$2"; shift 2;;
83077 + -d) database="$2"; shift 2;;
83078 + --) shift 1; break ;;
83079 + *) break ;;
83080 + esac
83081 +done
83082 +
83083 +create_defines() {
83084 + for i in `seq 1 32`
83085 + do
83086 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
83087 + done
83088 + echo >> "$header1"
83089 +}
83090 +
83091 +create_structs () {
83092 + rm -f "$header1"
83093 +
83094 + create_defines
83095 +
83096 + cat "$database" | while read data
83097 + do
83098 + data_array=($data)
83099 + struct_hash_name="${data_array[0]}"
83100 + funcn="${data_array[1]}"
83101 + params="${data_array[2]}"
83102 + next="${data_array[5]}"
83103 +
83104 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
83105 +
83106 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
83107 + echo -en "\t.param\t= " >> "$header1"
83108 + line=
83109 + for param_num in ${params//-/ };
83110 + do
83111 + line="${line}PARAM"$param_num"|"
83112 + done
83113 +
83114 + echo -e "${line%?},\n};\n" >> "$header1"
83115 + done
83116 +}
83117 +
83118 +create_headers () {
83119 + echo "const struct size_overflow_hash * const size_overflow_hash[$n] = {" >> "$header1"
83120 +}
83121 +
83122 +create_array_elements () {
83123 + index=0
83124 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
83125 + do
83126 + data_array=($data)
83127 + i="${data_array[3]}"
83128 + hash="${data_array[4]}"
83129 + while [[ $index -lt $i ]]
83130 + do
83131 + echo -e "\t["$index"]\t= NULL," >> "$header1"
83132 + index=$(($index + 1))
83133 + done
83134 + index=$(($index + 1))
83135 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
83136 + done
83137 + echo '};' >> $header1
83138 +}
83139 +
83140 +create_structs
83141 +create_headers
83142 +create_array_elements
83143 +
83144 +exit 0
83145 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
83146 new file mode 100644
83147 index 0000000..a86e422
83148 --- /dev/null
83149 +++ b/tools/gcc/kallocstat_plugin.c
83150 @@ -0,0 +1,167 @@
83151 +/*
83152 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
83153 + * Licensed under the GPL v2
83154 + *
83155 + * Note: the choice of the license means that the compilation process is
83156 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
83157 + * but for the kernel it doesn't matter since it doesn't link against
83158 + * any of the gcc libraries
83159 + *
83160 + * gcc plugin to find the distribution of k*alloc sizes
83161 + *
83162 + * TODO:
83163 + *
83164 + * BUGS:
83165 + * - none known
83166 + */
83167 +#include "gcc-plugin.h"
83168 +#include "config.h"
83169 +#include "system.h"
83170 +#include "coretypes.h"
83171 +#include "tree.h"
83172 +#include "tree-pass.h"
83173 +#include "flags.h"
83174 +#include "intl.h"
83175 +#include "toplev.h"
83176 +#include "plugin.h"
83177 +//#include "expr.h" where are you...
83178 +#include "diagnostic.h"
83179 +#include "plugin-version.h"
83180 +#include "tm.h"
83181 +#include "function.h"
83182 +#include "basic-block.h"
83183 +#include "gimple.h"
83184 +#include "rtl.h"
83185 +#include "emit-rtl.h"
83186 +
83187 +extern void print_gimple_stmt(FILE *, gimple, int, int);
83188 +
83189 +int plugin_is_GPL_compatible;
83190 +
83191 +static const char * const kalloc_functions[] = {
83192 + "__kmalloc",
83193 + "kmalloc",
83194 + "kmalloc_large",
83195 + "kmalloc_node",
83196 + "kmalloc_order",
83197 + "kmalloc_order_trace",
83198 + "kmalloc_slab",
83199 + "kzalloc",
83200 + "kzalloc_node",
83201 +};
83202 +
83203 +static struct plugin_info kallocstat_plugin_info = {
83204 + .version = "201111150100",
83205 +};
83206 +
83207 +static unsigned int execute_kallocstat(void);
83208 +
83209 +static struct gimple_opt_pass kallocstat_pass = {
83210 + .pass = {
83211 + .type = GIMPLE_PASS,
83212 + .name = "kallocstat",
83213 + .gate = NULL,
83214 + .execute = execute_kallocstat,
83215 + .sub = NULL,
83216 + .next = NULL,
83217 + .static_pass_number = 0,
83218 + .tv_id = TV_NONE,
83219 + .properties_required = 0,
83220 + .properties_provided = 0,
83221 + .properties_destroyed = 0,
83222 + .todo_flags_start = 0,
83223 + .todo_flags_finish = 0
83224 + }
83225 +};
83226 +
83227 +static bool is_kalloc(const char *fnname)
83228 +{
83229 + size_t i;
83230 +
83231 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
83232 + if (!strcmp(fnname, kalloc_functions[i]))
83233 + return true;
83234 + return false;
83235 +}
83236 +
83237 +static unsigned int execute_kallocstat(void)
83238 +{
83239 + basic_block bb;
83240 +
83241 + // 1. loop through BBs and GIMPLE statements
83242 + FOR_EACH_BB(bb) {
83243 + gimple_stmt_iterator gsi;
83244 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
83245 + // gimple match:
83246 + tree fndecl, size;
83247 + gimple call_stmt;
83248 + const char *fnname;
83249 +
83250 + // is it a call
83251 + call_stmt = gsi_stmt(gsi);
83252 + if (!is_gimple_call(call_stmt))
83253 + continue;
83254 + fndecl = gimple_call_fndecl(call_stmt);
83255 + if (fndecl == NULL_TREE)
83256 + continue;
83257 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
83258 + continue;
83259 +
83260 + // is it a call to k*alloc
83261 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
83262 + if (!is_kalloc(fnname))
83263 + continue;
83264 +
83265 + // is the size arg the result of a simple const assignment
83266 + size = gimple_call_arg(call_stmt, 0);
83267 + while (true) {
83268 + gimple def_stmt;
83269 + expanded_location xloc;
83270 + size_t size_val;
83271 +
83272 + if (TREE_CODE(size) != SSA_NAME)
83273 + break;
83274 + def_stmt = SSA_NAME_DEF_STMT(size);
83275 + if (!def_stmt || !is_gimple_assign(def_stmt))
83276 + break;
83277 + if (gimple_num_ops(def_stmt) != 2)
83278 + break;
83279 + size = gimple_assign_rhs1(def_stmt);
83280 + if (!TREE_CONSTANT(size))
83281 + continue;
83282 + xloc = expand_location(gimple_location(def_stmt));
83283 + if (!xloc.file)
83284 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
83285 + size_val = TREE_INT_CST_LOW(size);
83286 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
83287 + break;
83288 + }
83289 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
83290 +//debug_tree(gimple_call_fn(call_stmt));
83291 +//print_node(stderr, "pax", fndecl, 4);
83292 + }
83293 + }
83294 +
83295 + return 0;
83296 +}
83297 +
83298 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83299 +{
83300 + const char * const plugin_name = plugin_info->base_name;
83301 + struct register_pass_info kallocstat_pass_info = {
83302 + .pass = &kallocstat_pass.pass,
83303 + .reference_pass_name = "ssa",
83304 + .ref_pass_instance_number = 1,
83305 + .pos_op = PASS_POS_INSERT_AFTER
83306 + };
83307 +
83308 + if (!plugin_default_version_check(version, &gcc_version)) {
83309 + error(G_("incompatible gcc/plugin versions"));
83310 + return 1;
83311 + }
83312 +
83313 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
83314 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
83315 +
83316 + return 0;
83317 +}
83318 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
83319 new file mode 100644
83320 index 0000000..98011fa
83321 --- /dev/null
83322 +++ b/tools/gcc/kernexec_plugin.c
83323 @@ -0,0 +1,427 @@
83324 +/*
83325 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
83326 + * Licensed under the GPL v2
83327 + *
83328 + * Note: the choice of the license means that the compilation process is
83329 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
83330 + * but for the kernel it doesn't matter since it doesn't link against
83331 + * any of the gcc libraries
83332 + *
83333 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
83334 + *
83335 + * TODO:
83336 + *
83337 + * BUGS:
83338 + * - none known
83339 + */
83340 +#include "gcc-plugin.h"
83341 +#include "config.h"
83342 +#include "system.h"
83343 +#include "coretypes.h"
83344 +#include "tree.h"
83345 +#include "tree-pass.h"
83346 +#include "flags.h"
83347 +#include "intl.h"
83348 +#include "toplev.h"
83349 +#include "plugin.h"
83350 +//#include "expr.h" where are you...
83351 +#include "diagnostic.h"
83352 +#include "plugin-version.h"
83353 +#include "tm.h"
83354 +#include "function.h"
83355 +#include "basic-block.h"
83356 +#include "gimple.h"
83357 +#include "rtl.h"
83358 +#include "emit-rtl.h"
83359 +#include "tree-flow.h"
83360 +
83361 +extern void print_gimple_stmt(FILE *, gimple, int, int);
83362 +extern rtx emit_move_insn(rtx x, rtx y);
83363 +
83364 +int plugin_is_GPL_compatible;
83365 +
83366 +static struct plugin_info kernexec_plugin_info = {
83367 + .version = "201111291120",
83368 + .help = "method=[bts|or]\tinstrumentation method\n"
83369 +};
83370 +
83371 +static unsigned int execute_kernexec_reload(void);
83372 +static unsigned int execute_kernexec_fptr(void);
83373 +static unsigned int execute_kernexec_retaddr(void);
83374 +static bool kernexec_cmodel_check(void);
83375 +
83376 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
83377 +static void (*kernexec_instrument_retaddr)(rtx);
83378 +
83379 +static struct gimple_opt_pass kernexec_reload_pass = {
83380 + .pass = {
83381 + .type = GIMPLE_PASS,
83382 + .name = "kernexec_reload",
83383 + .gate = kernexec_cmodel_check,
83384 + .execute = execute_kernexec_reload,
83385 + .sub = NULL,
83386 + .next = NULL,
83387 + .static_pass_number = 0,
83388 + .tv_id = TV_NONE,
83389 + .properties_required = 0,
83390 + .properties_provided = 0,
83391 + .properties_destroyed = 0,
83392 + .todo_flags_start = 0,
83393 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
83394 + }
83395 +};
83396 +
83397 +static struct gimple_opt_pass kernexec_fptr_pass = {
83398 + .pass = {
83399 + .type = GIMPLE_PASS,
83400 + .name = "kernexec_fptr",
83401 + .gate = kernexec_cmodel_check,
83402 + .execute = execute_kernexec_fptr,
83403 + .sub = NULL,
83404 + .next = NULL,
83405 + .static_pass_number = 0,
83406 + .tv_id = TV_NONE,
83407 + .properties_required = 0,
83408 + .properties_provided = 0,
83409 + .properties_destroyed = 0,
83410 + .todo_flags_start = 0,
83411 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
83412 + }
83413 +};
83414 +
83415 +static struct rtl_opt_pass kernexec_retaddr_pass = {
83416 + .pass = {
83417 + .type = RTL_PASS,
83418 + .name = "kernexec_retaddr",
83419 + .gate = kernexec_cmodel_check,
83420 + .execute = execute_kernexec_retaddr,
83421 + .sub = NULL,
83422 + .next = NULL,
83423 + .static_pass_number = 0,
83424 + .tv_id = TV_NONE,
83425 + .properties_required = 0,
83426 + .properties_provided = 0,
83427 + .properties_destroyed = 0,
83428 + .todo_flags_start = 0,
83429 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
83430 + }
83431 +};
83432 +
83433 +static bool kernexec_cmodel_check(void)
83434 +{
83435 + tree section;
83436 +
83437 + if (ix86_cmodel != CM_KERNEL)
83438 + return false;
83439 +
83440 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
83441 + if (!section || !TREE_VALUE(section))
83442 + return true;
83443 +
83444 + section = TREE_VALUE(TREE_VALUE(section));
83445 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
83446 + return true;
83447 +
83448 + return false;
83449 +}
83450 +
83451 +/*
83452 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
83453 + */
83454 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
83455 +{
83456 + gimple asm_movabs_stmt;
83457 +
83458 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
83459 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
83460 + gimple_asm_set_volatile(asm_movabs_stmt, true);
83461 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
83462 + update_stmt(asm_movabs_stmt);
83463 +}
83464 +
83465 +/*
83466 + * find all asm() stmts that clobber r10 and add a reload of r10
83467 + */
83468 +static unsigned int execute_kernexec_reload(void)
83469 +{
83470 + basic_block bb;
83471 +
83472 + // 1. loop through BBs and GIMPLE statements
83473 + FOR_EACH_BB(bb) {
83474 + gimple_stmt_iterator gsi;
83475 +
83476 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
83477 + // gimple match: __asm__ ("" : : : "r10");
83478 + gimple asm_stmt;
83479 + size_t nclobbers;
83480 +
83481 + // is it an asm ...
83482 + asm_stmt = gsi_stmt(gsi);
83483 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
83484 + continue;
83485 +
83486 + // ... clobbering r10
83487 + nclobbers = gimple_asm_nclobbers(asm_stmt);
83488 + while (nclobbers--) {
83489 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
83490 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
83491 + continue;
83492 + kernexec_reload_fptr_mask(&gsi);
83493 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
83494 + break;
83495 + }
83496 + }
83497 + }
83498 +
83499 + return 0;
83500 +}
83501 +
83502 +/*
83503 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
83504 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
83505 + */
83506 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
83507 +{
83508 + gimple assign_intptr, assign_new_fptr, call_stmt;
83509 + tree intptr, old_fptr, new_fptr, kernexec_mask;
83510 +
83511 + call_stmt = gsi_stmt(*gsi);
83512 + old_fptr = gimple_call_fn(call_stmt);
83513 +
83514 + // create temporary unsigned long variable used for bitops and cast fptr to it
83515 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
83516 + add_referenced_var(intptr);
83517 + mark_sym_for_renaming(intptr);
83518 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
83519 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
83520 + update_stmt(assign_intptr);
83521 +
83522 + // apply logical or to temporary unsigned long and bitmask
83523 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
83524 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
83525 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
83526 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
83527 + update_stmt(assign_intptr);
83528 +
83529 + // cast temporary unsigned long back to a temporary fptr variable
83530 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
83531 + add_referenced_var(new_fptr);
83532 + mark_sym_for_renaming(new_fptr);
83533 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
83534 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
83535 + update_stmt(assign_new_fptr);
83536 +
83537 + // replace call stmt fn with the new fptr
83538 + gimple_call_set_fn(call_stmt, new_fptr);
83539 + update_stmt(call_stmt);
83540 +}
83541 +
83542 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
83543 +{
83544 + gimple asm_or_stmt, call_stmt;
83545 + tree old_fptr, new_fptr, input, output;
83546 + VEC(tree, gc) *inputs = NULL;
83547 + VEC(tree, gc) *outputs = NULL;
83548 +
83549 + call_stmt = gsi_stmt(*gsi);
83550 + old_fptr = gimple_call_fn(call_stmt);
83551 +
83552 + // create temporary fptr variable
83553 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
83554 + add_referenced_var(new_fptr);
83555 + mark_sym_for_renaming(new_fptr);
83556 +
83557 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
83558 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
83559 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
83560 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
83561 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
83562 + VEC_safe_push(tree, gc, inputs, input);
83563 + VEC_safe_push(tree, gc, outputs, output);
83564 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
83565 + gimple_asm_set_volatile(asm_or_stmt, true);
83566 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
83567 + update_stmt(asm_or_stmt);
83568 +
83569 + // replace call stmt fn with the new fptr
83570 + gimple_call_set_fn(call_stmt, new_fptr);
83571 + update_stmt(call_stmt);
83572 +}
83573 +
83574 +/*
83575 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
83576 + */
83577 +static unsigned int execute_kernexec_fptr(void)
83578 +{
83579 + basic_block bb;
83580 +
83581 + // 1. loop through BBs and GIMPLE statements
83582 + FOR_EACH_BB(bb) {
83583 + gimple_stmt_iterator gsi;
83584 +
83585 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
83586 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
83587 + tree fn;
83588 + gimple call_stmt;
83589 +
83590 + // is it a call ...
83591 + call_stmt = gsi_stmt(gsi);
83592 + if (!is_gimple_call(call_stmt))
83593 + continue;
83594 + fn = gimple_call_fn(call_stmt);
83595 + if (TREE_CODE(fn) == ADDR_EXPR)
83596 + continue;
83597 + if (TREE_CODE(fn) != SSA_NAME)
83598 + gcc_unreachable();
83599 +
83600 + // ... through a function pointer
83601 + fn = SSA_NAME_VAR(fn);
83602 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
83603 + continue;
83604 + fn = TREE_TYPE(fn);
83605 + if (TREE_CODE(fn) != POINTER_TYPE)
83606 + continue;
83607 + fn = TREE_TYPE(fn);
83608 + if (TREE_CODE(fn) != FUNCTION_TYPE)
83609 + continue;
83610 +
83611 + kernexec_instrument_fptr(&gsi);
83612 +
83613 +//debug_tree(gimple_call_fn(call_stmt));
83614 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
83615 + }
83616 + }
83617 +
83618 + return 0;
83619 +}
83620 +
83621 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
83622 +static void kernexec_instrument_retaddr_bts(rtx insn)
83623 +{
83624 + rtx btsq;
83625 + rtvec argvec, constraintvec, labelvec;
83626 + int line;
83627 +
83628 + // create asm volatile("btsq $63,(%%rsp)":::)
83629 + argvec = rtvec_alloc(0);
83630 + constraintvec = rtvec_alloc(0);
83631 + labelvec = rtvec_alloc(0);
83632 + line = expand_location(RTL_LOCATION(insn)).line;
83633 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
83634 + MEM_VOLATILE_P(btsq) = 1;
83635 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
83636 + emit_insn_before(btsq, insn);
83637 +}
83638 +
83639 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
83640 +static void kernexec_instrument_retaddr_or(rtx insn)
83641 +{
83642 + rtx orq;
83643 + rtvec argvec, constraintvec, labelvec;
83644 + int line;
83645 +
83646 + // create asm volatile("orq %%r10,(%%rsp)":::)
83647 + argvec = rtvec_alloc(0);
83648 + constraintvec = rtvec_alloc(0);
83649 + labelvec = rtvec_alloc(0);
83650 + line = expand_location(RTL_LOCATION(insn)).line;
83651 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
83652 + MEM_VOLATILE_P(orq) = 1;
83653 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
83654 + emit_insn_before(orq, insn);
83655 +}
83656 +
83657 +/*
83658 + * find all asm level function returns and forcibly set the highest bit of the return address
83659 + */
83660 +static unsigned int execute_kernexec_retaddr(void)
83661 +{
83662 + rtx insn;
83663 +
83664 + // 1. find function returns
83665 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
83666 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
83667 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
83668 + rtx body;
83669 +
83670 + // is it a retn
83671 + if (!JUMP_P(insn))
83672 + continue;
83673 + body = PATTERN(insn);
83674 + if (GET_CODE(body) == PARALLEL)
83675 + body = XVECEXP(body, 0, 0);
83676 + if (GET_CODE(body) != RETURN)
83677 + continue;
83678 + kernexec_instrument_retaddr(insn);
83679 + }
83680 +
83681 +// print_simple_rtl(stderr, get_insns());
83682 +// print_rtl(stderr, get_insns());
83683 +
83684 + return 0;
83685 +}
83686 +
83687 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83688 +{
83689 + const char * const plugin_name = plugin_info->base_name;
83690 + const int argc = plugin_info->argc;
83691 + const struct plugin_argument * const argv = plugin_info->argv;
83692 + int i;
83693 + struct register_pass_info kernexec_reload_pass_info = {
83694 + .pass = &kernexec_reload_pass.pass,
83695 + .reference_pass_name = "ssa",
83696 + .ref_pass_instance_number = 1,
83697 + .pos_op = PASS_POS_INSERT_AFTER
83698 + };
83699 + struct register_pass_info kernexec_fptr_pass_info = {
83700 + .pass = &kernexec_fptr_pass.pass,
83701 + .reference_pass_name = "ssa",
83702 + .ref_pass_instance_number = 1,
83703 + .pos_op = PASS_POS_INSERT_AFTER
83704 + };
83705 + struct register_pass_info kernexec_retaddr_pass_info = {
83706 + .pass = &kernexec_retaddr_pass.pass,
83707 + .reference_pass_name = "pro_and_epilogue",
83708 + .ref_pass_instance_number = 1,
83709 + .pos_op = PASS_POS_INSERT_AFTER
83710 + };
83711 +
83712 + if (!plugin_default_version_check(version, &gcc_version)) {
83713 + error(G_("incompatible gcc/plugin versions"));
83714 + return 1;
83715 + }
83716 +
83717 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
83718 +
83719 + if (TARGET_64BIT == 0)
83720 + return 0;
83721 +
83722 + for (i = 0; i < argc; ++i) {
83723 + if (!strcmp(argv[i].key, "method")) {
83724 + if (!argv[i].value) {
83725 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
83726 + continue;
83727 + }
83728 + if (!strcmp(argv[i].value, "bts")) {
83729 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
83730 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
83731 + } else if (!strcmp(argv[i].value, "or")) {
83732 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
83733 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
83734 + fix_register("r10", 1, 1);
83735 + } else
83736 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
83737 + continue;
83738 + }
83739 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
83740 + }
83741 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
83742 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
83743 +
83744 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
83745 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
83746 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
83747 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
83748 +
83749 + return 0;
83750 +}
83751 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
83752 new file mode 100644
83753 index 0000000..b8008f7
83754 --- /dev/null
83755 +++ b/tools/gcc/latent_entropy_plugin.c
83756 @@ -0,0 +1,295 @@
83757 +/*
83758 + * Copyright 2012 by the PaX Team <pageexec@freemail.hu>
83759 + * Licensed under the GPL v2
83760 + *
83761 + * Note: the choice of the license means that the compilation process is
83762 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
83763 + * but for the kernel it doesn't matter since it doesn't link against
83764 + * any of the gcc libraries
83765 + *
83766 + * gcc plugin to help generate a little bit of entropy from program state,
83767 + * used during boot in the kernel
83768 + *
83769 + * TODO:
83770 + * - add ipa pass to identify not explicitly marked candidate functions
83771 + * - mix in more program state (function arguments/return values, loop variables, etc)
83772 + * - more instrumentation control via attribute parameters
83773 + *
83774 + * BUGS:
83775 + * - LTO needs -flto-partition=none for now
83776 + */
83777 +#include "gcc-plugin.h"
83778 +#include "config.h"
83779 +#include "system.h"
83780 +#include "coretypes.h"
83781 +#include "tree.h"
83782 +#include "tree-pass.h"
83783 +#include "flags.h"
83784 +#include "intl.h"
83785 +#include "toplev.h"
83786 +#include "plugin.h"
83787 +//#include "expr.h" where are you...
83788 +#include "diagnostic.h"
83789 +#include "plugin-version.h"
83790 +#include "tm.h"
83791 +#include "function.h"
83792 +#include "basic-block.h"
83793 +#include "gimple.h"
83794 +#include "rtl.h"
83795 +#include "emit-rtl.h"
83796 +#include "tree-flow.h"
83797 +
83798 +int plugin_is_GPL_compatible;
83799 +
83800 +static tree latent_entropy_decl;
83801 +
83802 +static struct plugin_info latent_entropy_plugin_info = {
83803 + .version = "201207271820",
83804 + .help = NULL
83805 +};
83806 +
83807 +static unsigned int execute_latent_entropy(void);
83808 +static bool gate_latent_entropy(void);
83809 +
83810 +static struct gimple_opt_pass latent_entropy_pass = {
83811 + .pass = {
83812 + .type = GIMPLE_PASS,
83813 + .name = "latent_entropy",
83814 + .gate = gate_latent_entropy,
83815 + .execute = execute_latent_entropy,
83816 + .sub = NULL,
83817 + .next = NULL,
83818 + .static_pass_number = 0,
83819 + .tv_id = TV_NONE,
83820 + .properties_required = PROP_gimple_leh | PROP_cfg,
83821 + .properties_provided = 0,
83822 + .properties_destroyed = 0,
83823 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
83824 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
83825 + }
83826 +};
83827 +
83828 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
83829 +{
83830 + if (TREE_CODE(*node) != FUNCTION_DECL) {
83831 + *no_add_attrs = true;
83832 + error("%qE attribute only applies to functions", name);
83833 + }
83834 + return NULL_TREE;
83835 +}
83836 +
83837 +static struct attribute_spec latent_entropy_attr = {
83838 + .name = "latent_entropy",
83839 + .min_length = 0,
83840 + .max_length = 0,
83841 + .decl_required = true,
83842 + .type_required = false,
83843 + .function_type_required = false,
83844 + .handler = handle_latent_entropy_attribute,
83845 +#if BUILDING_GCC_VERSION >= 4007
83846 + .affects_type_identity = false
83847 +#endif
83848 +};
83849 +
83850 +static void register_attributes(void *event_data, void *data)
83851 +{
83852 + register_attribute(&latent_entropy_attr);
83853 +}
83854 +
83855 +static bool gate_latent_entropy(void)
83856 +{
83857 + tree latent_entropy_attr;
83858 +
83859 + latent_entropy_attr = lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl));
83860 + return latent_entropy_attr != NULL_TREE;
83861 +}
83862 +
83863 +static unsigned HOST_WIDE_INT seed;
83864 +static unsigned HOST_WIDE_INT get_random_const(void)
83865 +{
83866 + seed = (seed >> 1U) ^ (-(seed & 1ULL) & 0xD800000000000000ULL);
83867 + return seed;
83868 +}
83869 +
83870 +static enum tree_code get_op(tree *rhs)
83871 +{
83872 + static enum tree_code op;
83873 + unsigned HOST_WIDE_INT random_const;
83874 +
83875 + random_const = get_random_const();
83876 +
83877 + switch (op) {
83878 + case BIT_XOR_EXPR:
83879 + op = PLUS_EXPR;
83880 + break;
83881 +
83882 + case PLUS_EXPR:
83883 + if (rhs) {
83884 + op = LROTATE_EXPR;
83885 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
83886 + break;
83887 + }
83888 +
83889 + case LROTATE_EXPR:
83890 + default:
83891 + op = BIT_XOR_EXPR;
83892 + break;
83893 + }
83894 + if (rhs)
83895 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
83896 + return op;
83897 +}
83898 +
83899 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
83900 +{
83901 + gimple_stmt_iterator gsi;
83902 + gimple assign;
83903 + tree addxorrol, rhs;
83904 + enum tree_code op;
83905 +
83906 + op = get_op(&rhs);
83907 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
83908 + assign = gimple_build_assign(local_entropy, addxorrol);
83909 + find_referenced_vars_in(assign);
83910 +//debug_bb(bb);
83911 + gsi = gsi_after_labels(bb);
83912 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
83913 + update_stmt(assign);
83914 +}
83915 +
83916 +static void perturb_latent_entropy(basic_block bb, tree rhs)
83917 +{
83918 + gimple_stmt_iterator gsi;
83919 + gimple assign;
83920 + tree addxorrol, temp;
83921 +
83922 + // 1. create temporary copy of latent_entropy
83923 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
83924 + add_referenced_var(temp);
83925 + mark_sym_for_renaming(temp);
83926 +
83927 + // 2. read...
83928 + assign = gimple_build_assign(temp, latent_entropy_decl);
83929 + find_referenced_vars_in(assign);
83930 + gsi = gsi_after_labels(bb);
83931 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83932 + update_stmt(assign);
83933 +
83934 + // 3. ...modify...
83935 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
83936 + assign = gimple_build_assign(temp, addxorrol);
83937 + find_referenced_vars_in(assign);
83938 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83939 + update_stmt(assign);
83940 +
83941 + // 4. ...write latent_entropy
83942 + assign = gimple_build_assign(latent_entropy_decl, temp);
83943 + find_referenced_vars_in(assign);
83944 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83945 + update_stmt(assign);
83946 +}
83947 +
83948 +static unsigned int execute_latent_entropy(void)
83949 +{
83950 + basic_block bb;
83951 + gimple assign;
83952 + gimple_stmt_iterator gsi;
83953 + tree local_entropy;
83954 +
83955 + if (!latent_entropy_decl) {
83956 + struct varpool_node *node;
83957 +
83958 + for (node = varpool_nodes; node; node = node->next) {
83959 + tree var = node->decl;
83960 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
83961 + continue;
83962 + latent_entropy_decl = var;
83963 +// debug_tree(var);
83964 + break;
83965 + }
83966 + if (!latent_entropy_decl) {
83967 +// debug_tree(current_function_decl);
83968 + return 0;
83969 + }
83970 + }
83971 +
83972 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
83973 +
83974 + // 1. create local entropy variable
83975 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
83976 + add_referenced_var(local_entropy);
83977 + mark_sym_for_renaming(local_entropy);
83978 +
83979 + // 2. initialize local entropy variable
83980 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
83981 + if (dom_info_available_p(CDI_DOMINATORS))
83982 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
83983 + gsi = gsi_start_bb(bb);
83984 +
83985 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
83986 +// gimple_set_location(assign, loc);
83987 + find_referenced_vars_in(assign);
83988 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83989 + update_stmt(assign);
83990 + bb = bb->next_bb;
83991 +
83992 + // 3. instrument each BB with an operation on the local entropy variable
83993 + while (bb != EXIT_BLOCK_PTR) {
83994 + perturb_local_entropy(bb, local_entropy);
83995 + bb = bb->next_bb;
83996 + };
83997 +
83998 + // 4. mix local entropy into the global entropy variable
83999 + perturb_latent_entropy(EXIT_BLOCK_PTR->prev_bb, local_entropy);
84000 + return 0;
84001 +}
84002 +
84003 +static void start_unit_callback(void *gcc_data, void *user_data)
84004 +{
84005 +#if BUILDING_GCC_VERSION >= 4007
84006 + seed = get_random_seed(false);
84007 +#else
84008 + sscanf(get_random_seed(false), "%" HOST_WIDE_INT_PRINT "x", &seed);
84009 + seed *= seed;
84010 +#endif
84011 +
84012 + if (in_lto_p)
84013 + return;
84014 +
84015 + // extern u64 latent_entropy
84016 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), unsigned_intDI_type_node);
84017 +
84018 + TREE_STATIC(latent_entropy_decl) = 1;
84019 + TREE_PUBLIC(latent_entropy_decl) = 1;
84020 + TREE_USED(latent_entropy_decl) = 1;
84021 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
84022 + DECL_EXTERNAL(latent_entropy_decl) = 1;
84023 + DECL_ARTIFICIAL(latent_entropy_decl) = 0;
84024 + DECL_INITIAL(latent_entropy_decl) = NULL;
84025 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
84026 +// varpool_finalize_decl(latent_entropy_decl);
84027 +// varpool_mark_needed_node(latent_entropy_decl);
84028 +}
84029 +
84030 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
84031 +{
84032 + const char * const plugin_name = plugin_info->base_name;
84033 + struct register_pass_info latent_entropy_pass_info = {
84034 + .pass = &latent_entropy_pass.pass,
84035 + .reference_pass_name = "optimized",
84036 + .ref_pass_instance_number = 1,
84037 + .pos_op = PASS_POS_INSERT_BEFORE
84038 + };
84039 +
84040 + if (!plugin_default_version_check(version, &gcc_version)) {
84041 + error(G_("incompatible gcc/plugin versions"));
84042 + return 1;
84043 + }
84044 +
84045 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
84046 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
84047 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
84048 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
84049 +
84050 + return 0;
84051 +}
84052 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
84053 new file mode 100644
84054 index 0000000..9332f17
84055 --- /dev/null
84056 +++ b/tools/gcc/size_overflow_hash.data
84057 @@ -0,0 +1,3597 @@
84058 +_000001_hash alloc_dr 2 65495 _000001_hash NULL
84059 +_000002_hash __copy_from_user 3 10918 _000002_hash NULL
84060 +_000003_hash copy_from_user 3 17559 _000003_hash NULL
84061 +_000004_hash __copy_from_user_inatomic 3 4365 _000004_hash NULL
84062 +_000005_hash __copy_from_user_nocache 3 39351 _000005_hash NULL
84063 +_000006_hash __copy_to_user_inatomic 3 19214 _000006_hash NULL
84064 +_000007_hash do_xip_mapping_read 5 60297 _000007_hash NULL
84065 +_000008_hash hugetlbfs_read 3 11268 _000008_hash NULL
84066 +_000009_hash kmalloc 1 60432 _003302_hash NULL nohasharray
84067 +_000010_hash kmalloc_array 1-2 9444 _000010_hash NULL
84068 +_000012_hash __kmalloc_reserve 1 17080 _000012_hash NULL
84069 +_000013_hash kmalloc_slab 1 11917 _000013_hash NULL
84070 +_000014_hash kmemdup 2 64015 _000014_hash NULL
84071 +_000015_hash __krealloc 2 14857 _000340_hash NULL nohasharray
84072 +_000016_hash memdup_user 2 59590 _000016_hash NULL
84073 +_000017_hash module_alloc 1 63630 _000017_hash NULL
84074 +_000018_hash read_default_ldt 2 14302 _000018_hash NULL
84075 +_000019_hash read_kcore 3 63488 _000019_hash NULL
84076 +_000020_hash read_ldt 2 47570 _000020_hash NULL
84077 +_000021_hash read_zero 3 19366 _000021_hash NULL
84078 +_000022_hash __vmalloc_node 1 39308 _000022_hash NULL
84079 +_000023_hash aac_convert_sgraw2 4 51598 _000023_hash NULL
84080 +_000024_hash aa_simple_write_to_buffer 4-3 49683 _000024_hash NULL
84081 +_000025_hash ablkcipher_copy_iv 3 64140 _000025_hash NULL
84082 +_000026_hash ablkcipher_next_slow 3-4 47274 _000026_hash NULL
84083 +_000028_hash acpi_battery_write_alarm 3 1240 _000028_hash NULL
84084 +_000029_hash acpi_os_allocate 1 14892 _000029_hash NULL
84085 +_000030_hash acpi_system_write_wakeup_device 3 34853 _000030_hash NULL
84086 +_000031_hash adu_write 3 30487 _000031_hash NULL
84087 +_000032_hash aer_inject_write 3 52399 _000032_hash NULL
84088 +_000033_hash afs_alloc_flat_call 2-3 36399 _000033_hash NULL
84089 +_000035_hash afs_proc_cells_write 3 61139 _000035_hash NULL
84090 +_000036_hash afs_proc_rootcell_write 3 15822 _000036_hash NULL
84091 +_000037_hash agp_3_5_isochronous_node_enable 3 49465 _000037_hash NULL
84092 +_000038_hash agp_alloc_page_array 1 22554 _000038_hash NULL
84093 +_000039_hash ah_alloc_tmp 2-3 54378 _000039_hash NULL
84094 +_000041_hash ahash_setkey_unaligned 3 33521 _000041_hash NULL
84095 +_000042_hash alg_setkey 3 31485 _000042_hash NULL
84096 +_000043_hash aligned_kmalloc 1 3628 _000043_hash NULL
84097 +_000044_hash alloc_context 1 3194 _000044_hash NULL
84098 +_000045_hash alloc_ep_req 2 54860 _000045_hash NULL
84099 +_000046_hash alloc_fdmem 1 27083 _000046_hash NULL
84100 +_000047_hash alloc_flex_gd 1 57259 _000047_hash NULL
84101 +_000048_hash alloc_sglist 1-3-2 22960 _000048_hash NULL
84102 +_000049_hash __alloc_skb 1 23940 _000049_hash NULL
84103 +_000050_hash aoedev_flush 2 44398 _000050_hash NULL
84104 +_000051_hash append_to_buffer 3 63550 _000051_hash NULL
84105 +_000052_hash asix_read_cmd 5 13245 _000052_hash NULL
84106 +_000053_hash asix_write_cmd 5 58192 _000053_hash NULL
84107 +_000054_hash at76_set_card_command 4 4471 _000054_hash NULL
84108 +_000055_hash ath6kl_add_bss_if_needed 6 24317 _000055_hash NULL
84109 +_000056_hash ath6kl_debug_roam_tbl_event 3 5224 _000056_hash NULL
84110 +_000057_hash ath6kl_mgmt_powersave_ap 6 13791 _000057_hash NULL
84111 +_000058_hash ath6kl_send_go_probe_resp 3 21113 _000058_hash NULL
84112 +_000059_hash ath6kl_set_ap_probe_resp_ies 3 50539 _000059_hash NULL
84113 +_000060_hash ath6kl_set_assoc_req_ies 3 43185 _000060_hash NULL
84114 +_000061_hash ath6kl_wmi_bssinfo_event_rx 3 2275 _000061_hash NULL
84115 +_000062_hash ath6kl_wmi_send_action_cmd 7 58860 _000062_hash NULL
84116 +_000063_hash __ath6kl_wmi_send_mgmt_cmd 7 38971 _000063_hash NULL
84117 +_000064_hash attach_hdlc_protocol 3 19986 _000064_hash NULL
84118 +_000065_hash audio_write 4 54261 _001782_hash NULL nohasharray
84119 +_000066_hash audit_unpack_string 3 13748 _000066_hash NULL
84120 +_000067_hash ax25_setsockopt 5 42740 _000067_hash NULL
84121 +_000068_hash b43_debugfs_write 3 34838 _000068_hash NULL
84122 +_000069_hash b43legacy_debugfs_write 3 28556 _000069_hash NULL
84123 +_000070_hash batadv_hash_new 1 40491 _000070_hash NULL
84124 +_000071_hash batadv_orig_node_add_if 2 18433 _000071_hash NULL
84125 +_000072_hash batadv_orig_node_del_if 2 4 _000072_hash NULL
84126 +_000073_hash batadv_tt_changes_fill_buff 4 40323 _000073_hash NULL
84127 +_000074_hash batadv_tt_realloc_packet_buff 4 49960 _000074_hash NULL
84128 +_000075_hash bch_alloc 1 4593 _000075_hash NULL
84129 +_000076_hash befs_nls2utf 3 17163 _000076_hash NULL
84130 +_000077_hash befs_utf2nls 3 25628 _000077_hash NULL
84131 +_000078_hash bfad_debugfs_write_regrd 3 15218 _000078_hash NULL
84132 +_000079_hash bfad_debugfs_write_regwr 3 61841 _000079_hash NULL
84133 +_000080_hash bio_alloc_map_data 1-2 50782 _000080_hash NULL
84134 +_000082_hash bio_kmalloc 2 54672 _000082_hash NULL
84135 +_000083_hash bitmap_storage_alloc 2 55077 _000083_hash NULL
84136 +_000084_hash blkcipher_copy_iv 3 24075 _000084_hash NULL
84137 +_000085_hash blkcipher_next_slow 3-4 52733 _000085_hash NULL
84138 +_000087_hash bl_pipe_downcall 3 34264 _000087_hash NULL
84139 +_000088_hash bnad_debugfs_write_regrd 3 6706 _000088_hash NULL
84140 +_000089_hash bnad_debugfs_write_regwr 3 57500 _000089_hash NULL
84141 +_000090_hash bnx2fc_cmd_mgr_alloc 2-3 24873 _000090_hash NULL
84142 +_000092_hash bnx2fc_process_unsol_compl 2 15576 _000092_hash NULL
84143 +_000093_hash bnx2_nvram_write 2-4 7790 _000093_hash NULL
84144 +_000095_hash btmrvl_gpiogap_write 3 35053 _000095_hash NULL
84145 +_000096_hash btmrvl_hscfgcmd_write 3 27143 _000096_hash NULL
84146 +_000097_hash btmrvl_hscmd_write 3 27089 _000097_hash NULL
84147 +_000098_hash btmrvl_hsmode_write 3 42252 _000098_hash NULL
84148 +_000099_hash btmrvl_pscmd_write 3 29504 _000099_hash NULL
84149 +_000100_hash btmrvl_psmode_write 3 3703 _000100_hash NULL
84150 +_000101_hash btrfs_alloc_delayed_item 1 11678 _000101_hash NULL
84151 +_000102_hash c4iw_id_table_alloc 3 48163 _000102_hash NULL
84152 +_000103_hash cache_do_downcall 3 6926 _000103_hash NULL
84153 +_000104_hash cachefiles_cook_key 2 33274 _000104_hash NULL
84154 +_000105_hash cachefiles_daemon_write 3 43535 _000105_hash NULL
84155 +_000106_hash capi_write 3 35104 _003607_hash NULL nohasharray
84156 +_000107_hash carl9170_debugfs_write 3 50857 _000107_hash NULL
84157 +_000108_hash cciss_allocate_sg_chain_blocks 2-3 5368 _000108_hash NULL
84158 +_000110_hash cciss_proc_write 3 10259 _000110_hash NULL
84159 +_000111_hash cdrom_read_cdda_old 4 27664 _000111_hash NULL
84160 +_000112_hash ceph_alloc_page_vector 1 18710 _000112_hash NULL
84161 +_000113_hash ceph_buffer_new 1 35974 _000113_hash NULL
84162 +_000114_hash ceph_copy_user_to_page_vector 3-4 656 _000114_hash NULL
84163 +_000116_hash ceph_get_direct_page_vector 2 41917 _000116_hash NULL
84164 +_000117_hash ceph_msg_new 2 5846 _000117_hash NULL
84165 +_000118_hash ceph_setxattr 4 18913 _000118_hash NULL
84166 +_000119_hash cfi_read_pri 3 24366 _000119_hash NULL
84167 +_000120_hash cgroup_write_string 5 10900 _000120_hash NULL
84168 +_000121_hash cgroup_write_X64 5 54514 _000121_hash NULL
84169 +_000122_hash change_xattr 5 61390 _000122_hash NULL
84170 +_000123_hash check_load_and_stores 2 2143 _000123_hash NULL
84171 +_000124_hash cifs_idmap_key_instantiate 3 54503 _000124_hash NULL
84172 +_000125_hash cifs_security_flags_proc_write 3 5484 _000125_hash NULL
84173 +_000126_hash cifs_setxattr 4 23957 _000126_hash NULL
84174 +_000127_hash cifs_spnego_key_instantiate 3 23588 _000127_hash NULL
84175 +_000128_hash cld_pipe_downcall 3 15058 _000128_hash NULL
84176 +_000129_hash clear_refs_write 3 61904 _000129_hash NULL
84177 +_000130_hash clusterip_proc_write 3 44729 _000130_hash NULL
84178 +_000131_hash cm4040_write 3 58079 _000131_hash NULL
84179 +_000132_hash cm_copy_private_data 2 3649 _000132_hash NULL
84180 +_000133_hash cmm_write 3 2896 _000133_hash NULL
84181 +_000134_hash cm_write 3 36858 _000134_hash NULL
84182 +_000135_hash coda_psdev_write 3 1711 _000135_hash NULL
84183 +_000136_hash codec_reg_read_file 3 36280 _000136_hash NULL
84184 +_000137_hash command_file_write 3 31318 _000137_hash NULL
84185 +_000138_hash command_write 3 58841 _000138_hash NULL
84186 +_000139_hash comm_write 3 44537 _001714_hash NULL nohasharray
84187 +_000140_hash concat_writev 3 21451 _000140_hash NULL
84188 +_000141_hash copy_and_check 3 19089 _000141_hash NULL
84189 +_000142_hash copy_from_user_toio 3 31966 _000142_hash NULL
84190 +_000143_hash copy_items 6 50140 _000143_hash NULL
84191 +_000144_hash copy_macs 4 45534 _000144_hash NULL
84192 +_000145_hash __copy_to_user 3 17551 _000145_hash NULL
84193 +_000146_hash copy_vm86_regs_from_user 3 45340 _000146_hash NULL
84194 +_000147_hash core_sys_select 1 47494 _000147_hash NULL
84195 +_000148_hash cosa_write 3 1774 _000148_hash NULL
84196 +_000149_hash cp210x_set_config 4 46447 _000149_hash NULL
84197 +_000150_hash create_entry 2 33479 _000150_hash NULL
84198 +_000151_hash create_queues 2-3 9088 _000151_hash NULL
84199 +_000153_hash create_xattr 5 54106 _000153_hash NULL
84200 +_000154_hash create_xattr_datum 5 33356 _003443_hash NULL nohasharray
84201 +_000155_hash csum_partial_copy_fromiovecend 3-4 9957 _000155_hash NULL
84202 +_000157_hash ctrl_out 3-5 8712 _000157_hash NULL
84203 +_000159_hash cxacru_cm_get_array 4 4412 _000159_hash NULL
84204 +_000160_hash cxgbi_alloc_big_mem 1 4707 _000160_hash NULL
84205 +_000161_hash dac960_user_command_proc_write 3 3071 _000161_hash NULL
84206 +_000162_hash datablob_format 2 39571 _002490_hash NULL nohasharray
84207 +_000163_hash dccp_feat_clone_sp_val 3 11942 _000163_hash NULL
84208 +_000164_hash dccp_setsockopt_ccid 4 30701 _000164_hash NULL
84209 +_000165_hash dccp_setsockopt_cscov 2 37766 _000165_hash NULL
84210 +_000166_hash dccp_setsockopt_service 4 65336 _000166_hash NULL
84211 +_000167_hash ddebug_proc_write 3 18055 _000167_hash NULL
84212 +_000168_hash dev_config 3 8506 _000168_hash NULL
84213 +_000169_hash device_write 3 45156 _000169_hash NULL
84214 +_000170_hash devm_kzalloc 2 4966 _000170_hash NULL
84215 +_000171_hash devres_alloc 2 551 _000171_hash NULL
84216 +_000172_hash dfs_file_write 3 41196 _000172_hash NULL
84217 +_000173_hash direct_entry 3 38836 _000173_hash NULL
84218 +_000174_hash dispatch_ioctl 2 32357 _000174_hash NULL
84219 +_000175_hash dispatch_proc_write 3 44320 _000175_hash NULL
84220 +_000176_hash diva_os_copy_from_user 4 7792 _000176_hash NULL
84221 +_000177_hash dlm_alloc_pagevec 1 54296 _000177_hash NULL
84222 +_000178_hash dlmfs_file_read 3 28385 _000178_hash NULL
84223 +_000179_hash dlmfs_file_write 3 6892 _000179_hash NULL
84224 +_000180_hash dm_read 3 15674 _000180_hash NULL
84225 +_000181_hash dm_write 3 2513 _000181_hash NULL
84226 +_000182_hash __dn_setsockopt 5 13060 _000182_hash NULL
84227 +_000183_hash dns_query 3 9676 _000183_hash NULL
84228 +_000184_hash dns_resolver_instantiate 3 63314 _000184_hash NULL
84229 +_000185_hash do_add_counters 3 3992 _000185_hash NULL
84230 +_000186_hash __do_config_autodelink 3 58763 _000186_hash NULL
84231 +_000187_hash do_ip_setsockopt 5 41852 _000187_hash NULL
84232 +_000188_hash do_ipv6_setsockopt 5 18215 _000188_hash NULL
84233 +_000189_hash do_ip_vs_set_ctl 4 48641 _000189_hash NULL
84234 +_000190_hash do_kimage_alloc 3 64827 _000190_hash NULL
84235 +_000191_hash do_register_entry 4 29478 _000191_hash NULL
84236 +_000192_hash do_tty_write 5 44896 _000192_hash NULL
84237 +_000193_hash do_update_counters 4 2259 _000193_hash NULL
84238 +_000194_hash dsp_write 2 46218 _000194_hash NULL
84239 +_000195_hash dup_to_netobj 3 26363 _000195_hash NULL
84240 +_000196_hash dwc3_link_state_write 3 12641 _000196_hash NULL
84241 +_000197_hash dwc3_mode_write 3 51997 _000197_hash NULL
84242 +_000198_hash dwc3_testmode_write 3 30516 _000198_hash NULL
84243 +_000199_hash ecryptfs_copy_filename 4 11868 _000199_hash NULL
84244 +_000200_hash ecryptfs_miscdev_write 3 26847 _000200_hash NULL
84245 +_000201_hash ecryptfs_send_miscdev 2 64816 _000201_hash NULL
84246 +_000202_hash efx_tsoh_heap_alloc 2 58545 _000202_hash NULL
84247 +_000203_hash emi26_writememory 4 57908 _000203_hash NULL
84248 +_000204_hash emi62_writememory 4 29731 _000204_hash NULL
84249 +_000205_hash encrypted_instantiate 3 3168 _000205_hash NULL
84250 +_000206_hash encrypted_update 3 13414 _000206_hash NULL
84251 +_000207_hash ep0_write 3 14536 _001422_hash NULL nohasharray
84252 +_000208_hash ep_read 3 58813 _000208_hash NULL
84253 +_000209_hash ep_write 3 59008 _000209_hash NULL
84254 +_000210_hash erst_dbg_write 3 46715 _000210_hash NULL
84255 +_000211_hash esp_alloc_tmp 2-3 40558 _000211_hash NULL
84256 +_000213_hash evdev_do_ioctl 2 24459 _000213_hash NULL
84257 +_000214_hash exofs_read_lookup_dev_table 3 17733 _000214_hash NULL
84258 +_000215_hash ext4_kvmalloc 1 14796 _000215_hash NULL
84259 +_000216_hash ezusb_writememory 4 45976 _000216_hash NULL
84260 +_000217_hash fanotify_write 3 64623 _000217_hash NULL
84261 +_000218_hash fd_copyin 3 56247 _000218_hash NULL
84262 +_000219_hash ffs_epfile_io 3 64886 _000219_hash NULL
84263 +_000220_hash ffs_prepare_buffer 2 59892 _000220_hash NULL
84264 +_000221_hash f_hidg_write 3 7932 _000221_hash NULL
84265 +_000222_hash file_read_actor 4 1401 _000222_hash NULL
84266 +_000223_hash fill_write_buffer 3 3142 _000223_hash NULL
84267 +_000224_hash __find_xattr 6 2117 _002425_hash NULL nohasharray
84268 +_000225_hash fl_create 5 56435 _000225_hash NULL
84269 +_000226_hash fs_path_ensure_buf 2 59445 _000226_hash NULL
84270 +_000227_hash ftdi_elan_write 3 57309 _000227_hash NULL
84271 +_000228_hash fw_iso_buffer_alloc 2 13704 _000228_hash NULL
84272 +_000229_hash garmin_write_bulk 3 58191 _000229_hash NULL
84273 +_000230_hash garp_attr_create 3 3883 _000230_hash NULL
84274 +_000231_hash get_arg 3 5694 _000231_hash NULL
84275 +_000232_hash getdqbuf 1 62908 _000232_hash NULL
84276 +_000233_hash get_fdb_entries 3 41916 _000233_hash NULL
84277 +_000234_hash get_fd_set 1 3866 _000234_hash NULL
84278 +_000235_hash get_indirect_ea 4 51869 _000235_hash NULL
84279 +_000236_hash get_registers 3 26187 _000236_hash NULL
84280 +_000237_hash get_scq 2 10897 _000237_hash NULL
84281 +_000238_hash get_server_iovec 2 16804 _000238_hash NULL
84282 +_000239_hash get_ucode_user 3 38202 _000239_hash NULL
84283 +_000240_hash get_user_cpu_mask 2 14861 _000240_hash NULL
84284 +_000241_hash gfs2_alloc_sort_buffer 1 18275 _000241_hash NULL
84285 +_000242_hash gfs2_glock_nq_m 1 20347 _000242_hash NULL
84286 +_000243_hash gigaset_initcs 2 43753 _000243_hash NULL
84287 +_000244_hash gigaset_initdriver 2 1060 _000244_hash NULL
84288 +_000245_hash groups_alloc 1 7614 _000245_hash NULL
84289 +_000246_hash gs_alloc_req 2 58883 _000246_hash NULL
84290 +_000247_hash gs_buf_alloc 2 25067 _000247_hash NULL
84291 +_000248_hash gsm_data_alloc 3 42437 _000248_hash NULL
84292 +_000249_hash gss_pipe_downcall 3 23182 _000249_hash NULL
84293 +_000250_hash handle_request 9 10024 _000250_hash NULL
84294 +_000251_hash hashtab_create 3 33769 _000251_hash NULL
84295 +_000252_hash hcd_buffer_alloc 2 27495 _000252_hash NULL
84296 +_000253_hash hci_sock_setsockopt 5 28993 _000253_hash NULL
84297 +_000254_hash heap_init 2 49617 _000254_hash NULL
84298 +_000255_hash hest_ghes_dev_register 1 46766 _000255_hash NULL
84299 +_000256_hash hidg_alloc_ep_req 2 10159 _000256_hash NULL
84300 +_000257_hash hid_parse_report 3 51737 _000257_hash NULL
84301 +_000258_hash hidraw_get_report 3 45609 _000258_hash NULL
84302 +_000259_hash hidraw_report_event 3 20503 _000259_hash NULL
84303 +_000260_hash hidraw_send_report 3 23449 _000260_hash NULL
84304 +_000261_hash hpfs_translate_name 3 41497 _000261_hash NULL
84305 +_000262_hash hysdn_conf_write 3 52145 _000262_hash NULL
84306 +_000263_hash __i2400mu_send_barker 3 23652 _000263_hash NULL
84307 +_000264_hash i2cdev_read 3 1206 _000264_hash NULL
84308 +_000265_hash i2cdev_write 3 23310 _000265_hash NULL
84309 +_000266_hash i2o_parm_field_get 5 34477 _000266_hash NULL
84310 +_000267_hash i2o_parm_table_get 6 61635 _000267_hash NULL
84311 +_000268_hash ib_copy_from_udata 3 59502 _000268_hash NULL
84312 +_000269_hash ib_ucm_alloc_data 3 36885 _000269_hash NULL
84313 +_000270_hash ib_umad_write 3 47993 _000270_hash NULL
84314 +_000271_hash ib_uverbs_unmarshall_recv 5 12251 _000271_hash NULL
84315 +_000272_hash icn_writecmd 2 38629 _000272_hash NULL
84316 +_000273_hash ide_driver_proc_write 3 32493 _000273_hash NULL
84317 +_000274_hash ide_settings_proc_write 3 35110 _000274_hash NULL
84318 +_000275_hash idetape_chrdev_write 3 53976 _000275_hash NULL
84319 +_000276_hash idmap_pipe_downcall 3 14591 _000276_hash NULL
84320 +_000277_hash ieee80211_build_probe_req 7-5 27660 _000277_hash NULL
84321 +_000278_hash ieee80211_if_write 3 34894 _000278_hash NULL
84322 +_000279_hash if_write 3 51756 _000279_hash NULL
84323 +_000280_hash ilo_write 3 64378 _000280_hash NULL
84324 +_000281_hash ima_write_policy 3 40548 _000281_hash NULL
84325 +_000282_hash init_data_container 1 60709 _000282_hash NULL
84326 +_000283_hash init_send_hfcd 1 34586 _000283_hash NULL
84327 +_000284_hash insert_dent 7 65034 _000284_hash NULL
84328 +_000285_hash interpret_user_input 2 19393 _000285_hash NULL
84329 +_000286_hash int_proc_write 3 39542 _000286_hash NULL
84330 +_000287_hash ioctl_private_iw_point 7 1273 _000287_hash NULL
84331 +_000288_hash iov_iter_copy_from_user 4 31942 _000288_hash NULL
84332 +_000289_hash iov_iter_copy_from_user_atomic 4 56368 _000289_hash NULL
84333 +_000290_hash iowarrior_write 3 18604 _000290_hash NULL
84334 +_000291_hash ipc_alloc 1 1192 _000291_hash NULL
84335 +_000292_hash ipc_rcu_alloc 1 21208 _000292_hash NULL
84336 +_000293_hash ip_options_get_from_user 4 64958 _000293_hash NULL
84337 +_000294_hash ipv6_renew_option 3 38813 _000294_hash NULL
84338 +_000295_hash ip_vs_conn_fill_param_sync 6 29771 _001898_hash NULL nohasharray
84339 +_000296_hash ip_vs_create_timeout_table 2 64478 _000296_hash NULL
84340 +_000297_hash ipw_queue_tx_init 3 49161 _000297_hash NULL
84341 +_000298_hash irda_setsockopt 5 19824 _000298_hash NULL
84342 +_000299_hash irias_new_octseq_value 2 13596 _003821_hash NULL nohasharray
84343 +_000300_hash irnet_ctrl_write 3 24139 _000300_hash NULL
84344 +_000301_hash isdn_add_channels 3 40905 _000301_hash NULL
84345 +_000302_hash isdn_ppp_fill_rq 2 41428 _000302_hash NULL
84346 +_000303_hash isdn_ppp_write 4 29109 _000303_hash NULL
84347 +_000304_hash isdn_read 3 50021 _000304_hash NULL
84348 +_000305_hash isdn_v110_open 3 2418 _000305_hash NULL
84349 +_000306_hash isdn_writebuf_stub 4 52383 _000306_hash NULL
84350 +_000307_hash islpci_mgt_transmit 5 34133 _000307_hash NULL
84351 +_000308_hash iso_callback 3 43208 _000308_hash NULL
84352 +_000309_hash iso_packets_buffer_init 3-4 29061 _000309_hash NULL
84353 +_000310_hash it821x_firmware_command 3 8628 _000310_hash NULL
84354 +_000311_hash iwch_alloc_fastreg_pbl 2 40153 _000311_hash NULL
84355 +_000312_hash iwl_calib_set 3 34400 _003754_hash NULL nohasharray
84356 +_000313_hash jbd2_journal_init_revoke_table 1 36336 _000313_hash NULL
84357 +_000314_hash jffs2_alloc_full_dirent 1 60179 _001158_hash NULL nohasharray
84358 +_000315_hash journal_init_revoke_table 1 56331 _000315_hash NULL
84359 +_000316_hash kcalloc 1-2 27770 _000316_hash NULL
84360 +_000318_hash keyctl_instantiate_key_common 4 47889 _000318_hash NULL
84361 +_000319_hash keyctl_update_key 3 26061 _000319_hash NULL
84362 +_000320_hash __kfifo_alloc 2-3 22173 _000320_hash NULL
84363 +_000322_hash kfifo_copy_from_user 3 5091 _000322_hash NULL
84364 +_000323_hash kmalloc_node 1 50163 _003818_hash NULL nohasharray
84365 +_000324_hash kmalloc_parameter 1 65279 _000324_hash NULL
84366 +_000325_hash kmem_alloc 1 31920 _000325_hash NULL
84367 +_000326_hash kobj_map 2-3 9566 _000326_hash NULL
84368 +_000328_hash kone_receive 4 4690 _000328_hash NULL
84369 +_000329_hash kone_send 4 63435 _000329_hash NULL
84370 +_000330_hash krealloc 2 14908 _000330_hash NULL
84371 +_000331_hash kvmalloc 1 32646 _000331_hash NULL
84372 +_000332_hash kvm_read_guest_atomic 4 10765 _000332_hash NULL
84373 +_000333_hash kvm_read_guest_cached 4 39666 _000333_hash NULL
84374 +_000334_hash kvm_read_guest_page 5 18074 _000334_hash NULL
84375 +_000335_hash kzalloc 1 54740 _000335_hash NULL
84376 +_000336_hash l2cap_sock_setsockopt 5 50207 _000336_hash NULL
84377 +_000337_hash l2cap_sock_setsockopt_old 4 29346 _000337_hash NULL
84378 +_000338_hash lane2_associate_req 4 45398 _000338_hash NULL
84379 +_000339_hash lbs_debugfs_write 3 48413 _000339_hash NULL
84380 +_000340_hash lcd_write 3 14857 _000340_hash &_000015_hash
84381 +_000341_hash ldm_frag_add 2 5611 _000341_hash NULL
84382 +_000342_hash __lgread 4 31668 _000342_hash NULL
84383 +_000343_hash libipw_alloc_txb 1-3-2 27579 _000343_hash NULL
84384 +_000344_hash link_send_sections_long 4 46556 _000344_hash NULL
84385 +_000345_hash listxattr 3 12769 _000345_hash NULL
84386 +_000346_hash load_msg 2 95 _000346_hash NULL
84387 +_000347_hash lpfc_debugfs_dif_err_write 3 17424 _000347_hash NULL
84388 +_000348_hash lp_write 3 9511 _000348_hash NULL
84389 +_000349_hash mb_cache_create 2 17307 _000349_hash NULL
84390 +_000350_hash mce_write 3 26201 _000350_hash NULL
84391 +_000351_hash mcs7830_get_reg 3 33308 _000351_hash NULL
84392 +_000352_hash mcs7830_set_reg 3 31413 _000352_hash NULL
84393 +_000353_hash memcpy_fromiovec 3 55247 _000353_hash NULL
84394 +_000354_hash memcpy_fromiovecend 3-4 2707 _000354_hash NULL
84395 +_000356_hash mempool_resize 2 47983 _002039_hash NULL nohasharray
84396 +_000357_hash mem_rw 3 22085 _000357_hash NULL
84397 +_000358_hash mgmt_control 3 7349 _000358_hash NULL
84398 +_000359_hash mgmt_pending_add 5 46976 _000359_hash NULL
84399 +_000360_hash mlx4_ib_alloc_fast_reg_page_list 2 46119 _000360_hash NULL
84400 +_000361_hash mmc_alloc_sg 1 21504 _000361_hash NULL
84401 +_000362_hash mmc_send_bus_test 4 18285 _000362_hash NULL
84402 +_000363_hash mmc_send_cxd_data 5 38655 _000363_hash NULL
84403 +_000364_hash module_alloc_update_bounds 1 47205 _000364_hash NULL
84404 +_000365_hash move_addr_to_kernel 2 32673 _000365_hash NULL
84405 +_000366_hash mpi_alloc_limb_space 1 23190 _000366_hash NULL
84406 +_000367_hash mpi_resize 2 44674 _000367_hash NULL
84407 +_000368_hash mptctl_getiocinfo 2 28545 _000368_hash NULL
84408 +_000369_hash mtdchar_readoob 4 31200 _000369_hash NULL
84409 +_000370_hash mtdchar_write 3 56831 _002122_hash NULL nohasharray
84410 +_000371_hash mtdchar_writeoob 4 3393 _000371_hash NULL
84411 +_000372_hash mtd_device_parse_register 5 5024 _000372_hash NULL
84412 +_000373_hash mtf_test_write 3 18844 _000373_hash NULL
84413 +_000374_hash mthca_alloc_icm_table 3-4 38268 _002459_hash NULL nohasharray
84414 +_000376_hash mthca_alloc_init 2 21754 _000376_hash NULL
84415 +_000377_hash mthca_array_init 2 39987 _000377_hash NULL
84416 +_000378_hash mthca_buf_alloc 2 35861 _000378_hash NULL
84417 +_000379_hash mtrr_write 3 59622 _000379_hash NULL
84418 +_000380_hash musb_test_mode_write 3 33518 _000380_hash NULL
84419 +_000381_hash mwifiex_get_common_rates 3 17131 _000381_hash NULL
84420 +_000382_hash __mxt_write_reg 3 57326 _000382_hash NULL
84421 +_000383_hash nand_bch_init 2-3 16280 _001439_hash NULL nohasharray
84422 +_000385_hash ncp_file_write 3 3813 _000385_hash NULL
84423 +_000386_hash ncp__vol2io 5 4804 _000386_hash NULL
84424 +_000387_hash nes_alloc_fast_reg_page_list 2 33523 _000387_hash NULL
84425 +_000388_hash nfc_targets_found 3 29886 _000388_hash NULL
84426 +_000389_hash __nf_ct_ext_add_length 3 12364 _000389_hash NULL
84427 +_000390_hash nfs4_acl_new 1 49806 _000390_hash NULL
84428 +_000391_hash nfs4_write_cached_acl 4 15070 _000391_hash NULL
84429 +_000392_hash nfsd_symlink 6 63442 _000392_hash NULL
84430 +_000393_hash nfs_idmap_get_desc 2-4 42990 _000393_hash NULL
84431 +_000395_hash nfs_readdir_make_qstr 3 12509 _000395_hash NULL
84432 +_000396_hash note_last_dentry 3 12285 _000396_hash NULL
84433 +_000397_hash ntfs_copy_from_user 3-5 15072 _000397_hash NULL
84434 +_000399_hash __ntfs_copy_from_user_iovec_inatomic 3-4 38153 _000399_hash NULL
84435 +_000401_hash ntfs_ucstonls 3-5 23097 _000401_hash NULL
84436 +_000403_hash nvme_alloc_iod 1 56027 _000403_hash NULL
84437 +_000404_hash nvram_write 3 3894 _000404_hash NULL
84438 +_000405_hash o2hb_debug_create 4 18744 _000405_hash NULL
84439 +_000406_hash o2net_send_message_vec 4 879 _002013_hash NULL nohasharray
84440 +_000407_hash ocfs2_control_cfu 2 37750 _000407_hash NULL
84441 +_000408_hash oom_adjust_write 3 41116 _000408_hash NULL
84442 +_000409_hash oom_score_adj_write 3 42594 _000409_hash NULL
84443 +_000410_hash oprofilefs_ulong_from_user 3 57251 _000410_hash NULL
84444 +_000411_hash opticon_write 4 60775 _000411_hash NULL
84445 +_000412_hash p9_check_zc_errors 4 15534 _000412_hash NULL
84446 +_000413_hash packet_buffer_init 2 1607 _000413_hash NULL
84447 +_000414_hash packet_setsockopt 5 17662 _000414_hash NULL
84448 +_000415_hash parse_command 2 37079 _000415_hash NULL
84449 +_000416_hash pcbit_writecmd 2 12332 _000416_hash NULL
84450 +_000417_hash pcmcia_replace_cis 3 57066 _000417_hash NULL
84451 +_000418_hash pgctrl_write 3 50453 _000418_hash NULL
84452 +_000419_hash pg_write 3 40766 _000419_hash NULL
84453 +_000420_hash pidlist_allocate 1 64404 _000420_hash NULL
84454 +_000421_hash pipe_iov_copy_from_user 3 23102 _000421_hash NULL
84455 +_000422_hash pipe_iov_copy_to_user 3 3447 _000422_hash NULL
84456 +_000423_hash pkt_add 3 39897 _000423_hash NULL
84457 +_000424_hash pktgen_if_write 3 55628 _000424_hash NULL
84458 +_000425_hash platform_device_add_data 3 310 _000425_hash NULL
84459 +_000426_hash platform_device_add_resources 3 13289 _000426_hash NULL
84460 +_000427_hash pmcraid_copy_sglist 3 38431 _000427_hash NULL
84461 +_000428_hash pm_qos_power_write 3 52513 _000428_hash NULL
84462 +_000429_hash pnpbios_proc_write 3 19758 _000429_hash NULL
84463 +_000430_hash pool_allocate 3 42012 _000430_hash NULL
84464 +_000431_hash posix_acl_alloc 1 48063 _000431_hash NULL
84465 +_000432_hash ppp_cp_parse_cr 4 5214 _000432_hash NULL
84466 +_000433_hash ppp_write 3 34034 _000433_hash NULL
84467 +_000434_hash pp_read 3 33210 _000434_hash NULL
84468 +_000435_hash pp_write 3 39554 _000435_hash NULL
84469 +_000436_hash printer_req_alloc 2 62687 _000436_hash NULL
84470 +_000437_hash printer_write 3 60276 _000437_hash NULL
84471 +_000438_hash prism2_info_scanresults 3 59729 _000438_hash NULL
84472 +_000439_hash prism2_set_genericelement 3 29277 _000439_hash NULL
84473 +_000440_hash __probe_kernel_read 3 61119 _000440_hash NULL
84474 +_000441_hash __probe_kernel_write 3 29842 _000441_hash NULL
84475 +_000442_hash proc_coredump_filter_write 3 25625 _000442_hash NULL
84476 +_000443_hash _proc_do_string 2 6376 _000443_hash NULL
84477 +_000444_hash process_vm_rw_pages 5-6 15954 _000444_hash NULL
84478 +_000446_hash proc_loginuid_write 3 63648 _000446_hash NULL
84479 +_000447_hash proc_pid_attr_write 3 63845 _000447_hash NULL
84480 +_000448_hash proc_scsi_devinfo_write 3 32064 _000448_hash NULL
84481 +_000449_hash proc_scsi_write 3 29142 _000449_hash NULL
84482 +_000450_hash proc_scsi_write_proc 3 267 _000450_hash NULL
84483 +_000451_hash pskb_expand_head 2-3 42881 _000451_hash NULL
84484 +_000453_hash pstore_mkfile 5 50830 _000453_hash NULL
84485 +_000454_hash pti_char_write 3 60960 _000454_hash NULL
84486 +_000455_hash ptrace_writedata 4 45021 _000455_hash NULL
84487 +_000456_hash pt_write 3 40159 _000456_hash NULL
84488 +_000457_hash qdisc_class_hash_alloc 1 18262 _000457_hash NULL
84489 +_000458_hash r3964_write 4 57662 _000458_hash NULL
84490 +_000459_hash raw_seticmpfilter 3 6888 _000459_hash NULL
84491 +_000460_hash raw_setsockopt 5 45800 _000460_hash NULL
84492 +_000461_hash rawv6_seticmpfilter 5 12137 _000461_hash NULL
84493 +_000462_hash ray_cs_essid_proc_write 3 17875 _000462_hash NULL
84494 +_000463_hash rbd_add 3 16366 _000463_hash NULL
84495 +_000464_hash rbd_snap_add 4 19678 _000464_hash NULL
84496 +_000465_hash rdma_set_ib_paths 3 45592 _000465_hash NULL
84497 +_000466_hash rds_page_copy_user 4 35691 _000466_hash NULL
84498 +_000467_hash read 3 9397 _000467_hash NULL
84499 +_000468_hash read_buf 2 20469 _000468_hash NULL
84500 +_000469_hash read_cis_cache 4 29735 _000469_hash NULL
84501 +_000470_hash realloc_buffer 2 25816 _000470_hash NULL
84502 +_000471_hash receive_DataRequest 3 9904 _000471_hash NULL
84503 +_000472_hash recent_mt_proc_write 3 8206 _000472_hash NULL
84504 +_000473_hash regmap_access_read_file 3 37223 _000473_hash NULL
84505 +_000474_hash regmap_bulk_write 4 59049 _000474_hash NULL
84506 +_000475_hash regmap_map_read_file 3 37685 _000475_hash NULL
84507 +_000476_hash regset_tls_set 4 18459 _000476_hash NULL
84508 +_000477_hash reiserfs_add_entry 4 23062 _002792_hash NULL nohasharray
84509 +_000478_hash remote_settings_file_write 3 22987 _000478_hash NULL
84510 +_000479_hash request_key_auth_new 3 38092 _000479_hash NULL
84511 +_000480_hash restore_i387_fxsave 2 17528 _000480_hash NULL
84512 +_000481_hash revalidate 2 19043 _000481_hash NULL
84513 +_000482_hash rfcomm_sock_setsockopt 5 18254 _000482_hash NULL
84514 +_000483_hash rndis_add_response 2 58544 _000483_hash NULL
84515 +_000484_hash rndis_set_oid 4 6547 _000484_hash NULL
84516 +_000485_hash rngapi_reset 3 34366 _002137_hash NULL nohasharray
84517 +_000486_hash roccat_common2_receive 4 50369 _000486_hash NULL
84518 +_000487_hash roccat_common2_send 4 2422 _000487_hash NULL
84519 +_000488_hash rpc_malloc 2 43573 _000488_hash NULL
84520 +_000489_hash rt2x00debug_write_bbp 3 8212 _000489_hash NULL
84521 +_000490_hash rt2x00debug_write_csr 3 64753 _000490_hash NULL
84522 +_000491_hash rt2x00debug_write_eeprom 3 23091 _000491_hash NULL
84523 +_000492_hash rt2x00debug_write_rf 3 38195 _000492_hash NULL
84524 +_000493_hash rt2x00debug_write_rfcsr 3 41473 _000493_hash NULL
84525 +_000494_hash rts51x_read_mem 4 26577 _002730_hash NULL nohasharray
84526 +_000495_hash rts51x_read_status 4 11830 _000495_hash NULL
84527 +_000496_hash rts51x_write_mem 4 17598 _000496_hash NULL
84528 +_000497_hash rw_copy_check_uvector 3 45748 _003716_hash NULL nohasharray
84529 +_000498_hash rxrpc_request_key 3 27235 _000498_hash NULL
84530 +_000499_hash rxrpc_server_keyring 3 16431 _000499_hash NULL
84531 +_000500_hash savemem 3 58129 _000500_hash NULL
84532 +_000501_hash sb16_copy_from_user 10-7-6 55836 _000501_hash NULL
84533 +_000504_hash sched_autogroup_write 3 10984 _000504_hash NULL
84534 +_000505_hash scsi_mode_select 6 37330 _000505_hash NULL
84535 +_000506_hash scsi_tgt_copy_sense 3 26933 _000506_hash NULL
84536 +_000507_hash sctp_auth_create_key 1 51641 _000507_hash NULL
84537 +_000508_hash sctp_getsockopt_delayed_ack 2 9232 _000508_hash NULL
84538 +_000509_hash sctp_getsockopt_local_addrs 2 25178 _000509_hash NULL
84539 +_000510_hash sctp_make_abort_user 3 29654 _000510_hash NULL
84540 +_000511_hash sctp_setsockopt_active_key 3 43755 _000511_hash NULL
84541 +_000512_hash sctp_setsockopt_adaptation_layer 3 26935 _003246_hash NULL nohasharray
84542 +_000513_hash sctp_setsockopt_associnfo 3 51684 _000513_hash NULL
84543 +_000514_hash sctp_setsockopt_auth_chunk 3 30843 _000514_hash NULL
84544 +_000515_hash sctp_setsockopt_auth_key 3 3793 _000515_hash NULL
84545 +_000516_hash sctp_setsockopt_autoclose 3 5775 _000516_hash NULL
84546 +_000517_hash sctp_setsockopt_bindx 3 49870 _000517_hash NULL
84547 +_000518_hash __sctp_setsockopt_connectx 3 46949 _000518_hash NULL
84548 +_000519_hash sctp_setsockopt_context 3 31091 _000519_hash NULL
84549 +_000520_hash sctp_setsockopt_default_send_param 3 49578 _000520_hash NULL
84550 +_000521_hash sctp_setsockopt_delayed_ack 3 40129 _000521_hash NULL
84551 +_000522_hash sctp_setsockopt_del_key 3 42304 _002709_hash NULL nohasharray
84552 +_000523_hash sctp_setsockopt_events 3 18862 _000523_hash NULL
84553 +_000524_hash sctp_setsockopt_hmac_ident 3 11687 _000524_hash NULL
84554 +_000525_hash sctp_setsockopt_initmsg 3 1383 _000525_hash NULL
84555 +_000526_hash sctp_setsockopt_maxburst 3 28041 _000526_hash NULL
84556 +_000527_hash sctp_setsockopt_maxseg 3 11829 _000527_hash NULL
84557 +_000528_hash sctp_setsockopt_peer_addr_params 3 734 _000528_hash NULL
84558 +_000529_hash sctp_setsockopt_peer_primary_addr 3 13440 _000529_hash NULL
84559 +_000530_hash sctp_setsockopt_rtoinfo 3 30941 _000530_hash NULL
84560 +_000531_hash security_context_to_sid_core 2 29248 _000531_hash NULL
84561 +_000532_hash sel_commit_bools_write 3 46077 _000532_hash NULL
84562 +_000533_hash sel_write_avc_cache_threshold 3 2256 _000533_hash NULL
84563 +_000534_hash sel_write_bool 3 46996 _000534_hash NULL
84564 +_000535_hash sel_write_checkreqprot 3 60774 _000535_hash NULL
84565 +_000536_hash sel_write_disable 3 10511 _000536_hash NULL
84566 +_000537_hash sel_write_enforce 3 48998 _000537_hash NULL
84567 +_000538_hash sel_write_load 3 63830 _000538_hash NULL
84568 +_000539_hash send_bulk_static_data 3 61932 _000539_hash NULL
84569 +_000540_hash set_aoe_iflist 2 42737 _000540_hash NULL
84570 +_000541_hash setkey_unaligned 3 39474 _000541_hash NULL
84571 +_000542_hash set_registers 3 53582 _000542_hash NULL
84572 +_000543_hash setsockopt 5 54539 _000543_hash NULL
84573 +_000544_hash setup_req 3 5848 _000544_hash NULL
84574 +_000545_hash setxattr 4 37006 _000545_hash NULL
84575 +_000546_hash sfq_alloc 1 2861 _000546_hash NULL
84576 +_000547_hash sg_kmalloc 1 50240 _000547_hash NULL
84577 +_000548_hash sgl_map_user_pages 2 30610 _000548_hash NULL
84578 +_000549_hash shash_setkey_unaligned 3 8620 _000549_hash NULL
84579 +_000550_hash shmem_xattr_alloc 2 61190 _000550_hash NULL
84580 +_000551_hash sierra_setup_urb 5 46029 _000551_hash NULL
84581 +_000552_hash simple_transaction_get 3 50633 _000552_hash NULL
84582 +_000553_hash simple_write_to_buffer 2-5 3122 _000553_hash NULL
84583 +_000555_hash sisusb_send_bulk_msg 3 17864 _000555_hash NULL
84584 +_000556_hash skb_add_data 3 48363 _000556_hash NULL
84585 +_000557_hash skb_do_copy_data_nocache 5 12465 _000557_hash NULL
84586 +_000558_hash sl_alloc_bufs 2 50380 _000558_hash NULL
84587 +_000559_hash sl_realloc_bufs 2 64086 _000559_hash NULL
84588 +_000560_hash smk_set_cipso 3 20379 _000560_hash NULL
84589 +_000561_hash smk_write_ambient 3 45691 _000561_hash NULL
84590 +_000562_hash smk_write_direct 3 46363 _000562_hash NULL
84591 +_000563_hash smk_write_doi 3 49621 _000563_hash NULL
84592 +_000564_hash smk_write_logging 3 2618 _000564_hash NULL
84593 +_000565_hash smk_write_mapped 3 13519 _000565_hash NULL
84594 +_000566_hash smk_write_netlbladdr 3 42525 _000566_hash NULL
84595 +_000567_hash smk_write_onlycap 3 14400 _000567_hash NULL
84596 +_000568_hash smk_write_rules_list 3 18565 _000568_hash NULL
84597 +_000569_hash snd_ctl_elem_user_tlv 3 11695 _000569_hash NULL
84598 +_000570_hash snd_emu10k1_fx8010_read 5 9605 _000570_hash NULL
84599 +_000571_hash snd_emu10k1_synth_copy_from_user 3-5 9061 _000571_hash NULL
84600 +_000573_hash snd_gus_dram_poke 4 18525 _000573_hash NULL
84601 +_000574_hash snd_hdsp_playback_copy 5 20676 _000574_hash NULL
84602 +_000575_hash snd_info_entry_write 3 63474 _000575_hash NULL
84603 +_000576_hash snd_korg1212_copy_from 6 36169 _000576_hash NULL
84604 +_000577_hash snd_mem_proc_write 3 9786 _000577_hash NULL
84605 +_000578_hash snd_midi_channel_init_set 1 30092 _000578_hash NULL
84606 +_000579_hash snd_midi_event_new 1 9893 _000764_hash NULL nohasharray
84607 +_000580_hash snd_opl4_mem_proc_write 5 9670 _000580_hash NULL
84608 +_000581_hash snd_pcm_aio_read 3 13900 _000581_hash NULL
84609 +_000582_hash snd_pcm_aio_write 3 28738 _000582_hash NULL
84610 +_000583_hash snd_pcm_oss_write1 3 10872 _000583_hash NULL
84611 +_000584_hash snd_pcm_oss_write2 3 27332 _000584_hash NULL
84612 +_000585_hash snd_rawmidi_kernel_write1 4 56847 _000585_hash NULL
84613 +_000586_hash snd_rme9652_playback_copy 5 20970 _000586_hash NULL
84614 +_000587_hash snd_sb_csp_load_user 3 45190 _000587_hash NULL
84615 +_000588_hash snd_usb_ctl_msg 8 8436 _000588_hash NULL
84616 +_000589_hash sock_bindtodevice 3 50942 _000589_hash NULL
84617 +_000590_hash sock_kmalloc 2 62205 _000590_hash NULL
84618 +_000591_hash spidev_ioctl 2 12846 _000591_hash NULL
84619 +_000592_hash spidev_write 3 44510 _000592_hash NULL
84620 +_000593_hash squashfs_read_table 3 16945 _000593_hash NULL
84621 +_000594_hash srpt_alloc_ioctx 2-3 51042 _000594_hash NULL
84622 +_000596_hash srpt_alloc_ioctx_ring 2-4-3 49330 _000596_hash NULL
84623 +_000597_hash st5481_setup_isocpipes 6-4 61340 _000597_hash NULL
84624 +_000598_hash sta_agg_status_write 3 45164 _000598_hash NULL
84625 +_000599_hash svc_setsockopt 5 36876 _000599_hash NULL
84626 +_000600_hash sys_add_key 4 61288 _000600_hash NULL
84627 +_000601_hash sys_modify_ldt 3 18824 _000601_hash NULL
84628 +_000602_hash sys_semtimedop 3 4486 _000602_hash NULL
84629 +_000603_hash sys_setdomainname 2 4373 _000603_hash NULL
84630 +_000604_hash sys_sethostname 2 42962 _000604_hash NULL
84631 +_000605_hash tomoyo_write_self 3 45161 _000605_hash NULL
84632 +_000606_hash tower_write 3 8580 _000606_hash NULL
84633 +_000607_hash tpm_write 3 50798 _000607_hash NULL
84634 +_000608_hash trusted_instantiate 3 4710 _000608_hash NULL
84635 +_000609_hash trusted_update 3 12664 _000609_hash NULL
84636 +_000610_hash tty_buffer_alloc 2 45437 _000610_hash NULL
84637 +_000611_hash __tun_chr_ioctl 4 22300 _000611_hash NULL
84638 +_000612_hash ubi_more_leb_change_data 4 63534 _000612_hash NULL
84639 +_000613_hash ubi_more_update_data 4 39189 _000613_hash NULL
84640 +_000614_hash ubi_resize_volume 2 50172 _000614_hash NULL
84641 +_000615_hash udf_alloc_i_data 2 35786 _000615_hash NULL
84642 +_000616_hash uea_idma_write 3 64139 _000616_hash NULL
84643 +_000617_hash uea_request 4 47613 _000617_hash NULL
84644 +_000618_hash uea_send_modem_cmd 3 3888 _000618_hash NULL
84645 +_000619_hash uio_write 3 43202 _000619_hash NULL
84646 +_000620_hash um_idi_write 3 18293 _000620_hash NULL
84647 +_000621_hash us122l_ctl_msg 8 13330 _000621_hash NULL
84648 +_000622_hash usb_alloc_urb 1 43436 _000622_hash NULL
84649 +_000623_hash usblp_new_writeurb 2 22894 _000623_hash NULL
84650 +_000624_hash usblp_write 3 23178 _000624_hash NULL
84651 +_000625_hash usbtest_alloc_urb 3-5 34446 _000625_hash NULL
84652 +_000627_hash usbtmc_write 3 64340 _000627_hash NULL
84653 +_000628_hash user_instantiate 3 26131 _000628_hash NULL
84654 +_000629_hash user_update 3 41332 _000629_hash NULL
84655 +_000630_hash uwb_rc_cmd_done 4 35892 _000630_hash NULL
84656 +_000631_hash uwb_rc_neh_grok_event 3 55799 _000631_hash NULL
84657 +_000632_hash v9fs_alloc_rdir_buf 2 42150 _000632_hash NULL
84658 +_000633_hash vc_do_resize 3-4 48842 _000633_hash NULL
84659 +_000635_hash vcs_write 3 3910 _000635_hash NULL
84660 +_000636_hash vga_arb_write 3 36112 _000636_hash NULL
84661 +_000637_hash vga_switcheroo_debugfs_write 3 33984 _000637_hash NULL
84662 +_000638_hash vhci_get_user 3 45039 _000638_hash NULL
84663 +_000639_hash video_proc_write 3 6724 _000639_hash NULL
84664 +_000640_hash vlsi_alloc_ring 3-4 57003 _000640_hash NULL
84665 +_000642_hash __vmalloc 1 61168 _000642_hash NULL
84666 +_000643_hash vmalloc_32 1 1135 _000643_hash NULL
84667 +_000644_hash vmalloc_32_user 1 37519 _000644_hash NULL
84668 +_000645_hash vmalloc_exec 1 36132 _000645_hash NULL
84669 +_000646_hash vmalloc_node 1 58700 _000646_hash NULL
84670 +_000647_hash __vmalloc_node_flags 1 30352 _000647_hash NULL
84671 +_000648_hash vmalloc_user 1 32308 _000648_hash NULL
84672 +_000649_hash vol_cdev_direct_write 3 20751 _000649_hash NULL
84673 +_000650_hash vp_request_msix_vectors 2 28849 _000650_hash NULL
84674 +_000651_hash vring_add_indirect 3-4 20737 _000651_hash NULL
84675 +_000653_hash vring_new_virtqueue 1 9671 _000653_hash NULL
84676 +_000654_hash vxge_os_dma_malloc 2 46184 _000654_hash NULL
84677 +_000655_hash vxge_os_dma_malloc_async 3 56348 _000655_hash NULL
84678 +_000656_hash wdm_write 3 53735 _000656_hash NULL
84679 +_000657_hash wiimote_hid_send 3 48528 _000657_hash NULL
84680 +_000658_hash wlc_phy_loadsampletable_nphy 3 64367 _000658_hash NULL
84681 +_000659_hash write 3 62671 _000659_hash NULL
84682 +_000660_hash write_flush 3 50803 _000660_hash NULL
84683 +_000661_hash write_rio 3 54837 _000661_hash NULL
84684 +_000662_hash x25_asy_change_mtu 2 26928 _000662_hash NULL
84685 +_000663_hash xdi_copy_from_user 4 8395 _000663_hash NULL
84686 +_000664_hash xfrm_dst_alloc_copy 3 3034 _000664_hash NULL
84687 +_000665_hash xfrm_user_policy 4 62573 _000665_hash NULL
84688 +_000666_hash xfs_attrmulti_attr_set 4 59346 _000666_hash NULL
84689 +_000667_hash xfs_handle_to_dentry 3 12135 _000667_hash NULL
84690 +_000668_hash xip_file_read 3 58592 _000668_hash NULL
84691 +_000669_hash __xip_file_write 3-4 2733 _000669_hash NULL
84692 +_000671_hash xprt_rdma_allocate 2 31372 _000671_hash NULL
84693 +_000672_hash zd_usb_iowrite16v_async 3 23984 _000672_hash NULL
84694 +_000673_hash zd_usb_read_fw 4 22049 _000673_hash NULL
84695 +_000674_hash zerocopy_sg_from_iovec 3 11828 _000674_hash NULL
84696 +_000675_hash __a2mp_build 3 60987 _000675_hash NULL
84697 +_000677_hash acpi_ex_allocate_name_string 2-1 7685 _001169_hash NULL nohasharray
84698 +_000678_hash acpi_os_allocate_zeroed 1 37422 _000678_hash NULL
84699 +_000679_hash acpi_ut_initialize_buffer 2 47143 _002830_hash NULL nohasharray
84700 +_000680_hash ad7879_spi_xfer 3 36311 _000680_hash NULL
84701 +_000681_hash add_new_gdb 3 27643 _000681_hash NULL
84702 +_000682_hash add_numbered_child 5 14273 _000682_hash NULL
84703 +_000683_hash add_res_range 4 21310 _000683_hash NULL
84704 +_000684_hash addtgt 3 54703 _000684_hash NULL
84705 +_000685_hash add_uuid 4 49831 _000685_hash NULL
84706 +_000686_hash afs_cell_alloc 2 24052 _000686_hash NULL
84707 +_000687_hash aggr_recv_addba_req_evt 4 38037 _000687_hash NULL
84708 +_000688_hash agp_create_memory 1 1075 _000688_hash NULL
84709 +_000689_hash agp_create_user_memory 1 62955 _000689_hash NULL
84710 +_000690_hash alg_setsockopt 5 20985 _000690_hash NULL
84711 +_000691_hash alloc_async 1 14208 _000691_hash NULL
84712 +_000692_hash ___alloc_bootmem_nopanic 1 53626 _000692_hash NULL
84713 +_000693_hash alloc_buf 1 34532 _000693_hash NULL
84714 +_000694_hash alloc_chunk 1 49575 _000694_hash NULL
84715 +_000695_hash alloc_context 1 41283 _000695_hash NULL
84716 +_000696_hash alloc_ctrl_packet 1 44667 _000696_hash NULL
84717 +_000697_hash alloc_data_packet 1 46698 _000697_hash NULL
84718 +_000698_hash alloc_dca_provider 2 59670 _000698_hash NULL
84719 +_000699_hash __alloc_dev_table 2 54343 _000699_hash NULL
84720 +_000700_hash alloc_ep 1 17269 _000700_hash NULL
84721 +_000701_hash __alloc_extent_buffer 3 15093 _000701_hash NULL
84722 +_000702_hash alloc_group_attrs 2 9194 _000727_hash NULL nohasharray
84723 +_000703_hash alloc_large_system_hash 2 22391 _000703_hash NULL
84724 +_000704_hash alloc_netdev_mqs 1 30030 _000704_hash NULL
84725 +_000705_hash __alloc_objio_seg 1 7203 _000705_hash NULL
84726 +_000706_hash alloc_ring 2-4 15345 _000706_hash NULL
84727 +_000707_hash alloc_ring 2-4 39151 _000707_hash NULL
84728 +_000710_hash alloc_session 1-2 64171 _000710_hash NULL
84729 +_000714_hash alloc_skb 1 55439 _000714_hash NULL
84730 +_000715_hash alloc_skb_fclone 1 3467 _000715_hash NULL
84731 +_000716_hash alloc_smp_req 1 51337 _000716_hash NULL
84732 +_000717_hash alloc_smp_resp 1 3566 _000717_hash NULL
84733 +_000718_hash alloc_ts_config 1 45775 _000718_hash NULL
84734 +_000719_hash alloc_upcall 2 62186 _000719_hash NULL
84735 +_000720_hash altera_drscan 2 48698 _000720_hash NULL
84736 +_000721_hash altera_irscan 2 62396 _000721_hash NULL
84737 +_000722_hash altera_set_dr_post 2 54291 _000722_hash NULL
84738 +_000723_hash altera_set_dr_pre 2 64862 _000723_hash NULL
84739 +_000724_hash altera_set_ir_post 2 20948 _000724_hash NULL
84740 +_000725_hash altera_set_ir_pre 2 54103 _000725_hash NULL
84741 +_000726_hash altera_swap_dr 2 50090 _000726_hash NULL
84742 +_000727_hash altera_swap_ir 2 9194 _000727_hash &_000702_hash
84743 +_000728_hash amd_create_gatt_pages 1 20537 _000728_hash NULL
84744 +_000729_hash aoechr_write 3 62883 _003674_hash NULL nohasharray
84745 +_000730_hash applesmc_create_nodes 2 49392 _000730_hash NULL
84746 +_000731_hash array_zalloc 1-2 7519 _000731_hash NULL
84747 +_000733_hash arvo_sysfs_read 6 31617 _000733_hash NULL
84748 +_000734_hash arvo_sysfs_write 6 3311 _000734_hash NULL
84749 +_000735_hash asd_store_update_bios 4 10165 _000735_hash NULL
84750 +_000736_hash ata_host_alloc 2 46094 _000736_hash NULL
84751 +_000737_hash atalk_sendmsg 4 21677 _000737_hash NULL
84752 +_000738_hash ath6kl_cfg80211_connect_event 7-9-8 13443 _000738_hash NULL
84753 +_000739_hash ath6kl_mgmt_tx 9 21153 _000739_hash NULL
84754 +_000740_hash ath6kl_wmi_proc_events_vif 5 42549 _003190_hash NULL nohasharray
84755 +_000741_hash ath6kl_wmi_roam_tbl_event_rx 3 43440 _000741_hash NULL
84756 +_000742_hash ath6kl_wmi_send_mgmt_cmd 7 17347 _000742_hash NULL
84757 +_000743_hash ath_descdma_setup 5 12257 _000743_hash NULL
84758 +_000744_hash ath_rx_edma_init 2 65483 _000744_hash NULL
84759 +_000745_hash ati_create_gatt_pages 1 4722 _003275_hash NULL nohasharray
84760 +_000746_hash audit_expand 2 2098 _000746_hash NULL
84761 +_000747_hash audit_init_entry 1 38644 _000747_hash NULL
84762 +_000748_hash ax25_sendmsg 4 62770 _000748_hash NULL
84763 +_000749_hash b1_alloc_card 1 36155 _000749_hash NULL
84764 +_000750_hash b43_nphy_load_samples 3 36481 _000750_hash NULL
84765 +_000751_hash batadv_orig_hash_add_if 2 10033 _000751_hash NULL
84766 +_000752_hash batadv_orig_hash_del_if 2 48972 _000752_hash NULL
84767 +_000753_hash batadv_tt_append_diff 4 20588 _000753_hash NULL
84768 +_000754_hash batadv_tt_commit_changes 4 2008 _000754_hash NULL
84769 +_000755_hash batadv_tt_prepare_packet_buff 4 1280 _000755_hash NULL
84770 +_000756_hash bio_copy_user_iov 4 37660 _000756_hash NULL
84771 +_000757_hash __bio_map_kern 3 47379 _000757_hash NULL
84772 +_000758_hash bitmap_resize 2 33054 _000758_hash NULL
84773 +_000759_hash blk_check_plugged 3 50736 _000759_hash NULL
84774 +_000760_hash blk_register_region 1-2 51424 _000760_hash NULL
84775 +_000762_hash bm_entry_write 3 28338 _000762_hash NULL
84776 +_000763_hash bm_realloc_pages 2 9431 _000763_hash NULL
84777 +_000764_hash bm_register_write 3 9893 _000764_hash &_000579_hash
84778 +_000765_hash bm_status_write 3 12964 _000765_hash NULL
84779 +_000766_hash br_mdb_rehash 2 42643 _000766_hash NULL
84780 +_000767_hash btmrvl_sdio_host_to_card 3 12152 _000767_hash NULL
84781 +_000768_hash btrfs_copy_from_user 1-3 43806 _000768_hash NULL
84782 +_000770_hash btrfs_insert_delayed_dir_index 4 63720 _000770_hash NULL
84783 +_000771_hash __btrfs_map_block 3 49839 _000771_hash NULL
84784 +_000772_hash c4iw_init_resource 2-3 30393 _000772_hash NULL
84785 +_000774_hash cache_downcall 3 13666 _000774_hash NULL
84786 +_000775_hash cache_slow_downcall 2 8570 _000775_hash NULL
84787 +_000776_hash caif_seqpkt_sendmsg 4 22961 _000776_hash NULL
84788 +_000777_hash caif_stream_sendmsg 4 9110 _000777_hash NULL
84789 +_000778_hash carl9170_cmd_buf 3 950 _000778_hash NULL
84790 +_000779_hash cdev_add 2-3 38176 _000779_hash NULL
84791 +_000781_hash cdrom_read_cdda 4 50478 _000781_hash NULL
84792 +_000782_hash ceph_dns_resolve_name 2 62488 _000782_hash NULL
84793 +_000783_hash ceph_msgpool_get 2 54258 _000783_hash NULL
84794 +_000784_hash cfg80211_connect_result 4-6 56515 _000784_hash NULL
84795 +_000786_hash cfg80211_disconnected 4 57 _000786_hash NULL
84796 +_000787_hash cfg80211_inform_bss 8 19332 _000787_hash NULL
84797 +_000788_hash cfg80211_inform_bss_frame 4 41078 _000788_hash NULL
84798 +_000789_hash cfg80211_mlme_register_mgmt 5 19852 _000789_hash NULL
84799 +_000790_hash cfg80211_roamed_bss 4-6 50198 _000790_hash NULL
84800 +_000792_hash cgroup_file_write 3 52417 _000792_hash NULL
84801 +_000793_hash cifs_readdata_alloc 1 26360 _000793_hash NULL
84802 +_000794_hash cifs_readv_from_socket 3 19109 _000794_hash NULL
84803 +_000795_hash cifs_writedata_alloc 1 32880 _003097_hash NULL nohasharray
84804 +_000796_hash cnic_alloc_dma 3 34641 _000796_hash NULL
84805 +_000797_hash cnic_init_id_tbl 2 41354 _000797_hash NULL
84806 +_000798_hash configfs_write_file 3 61621 _000798_hash NULL
84807 +_000799_hash construct_key 3 11329 _000799_hash NULL
84808 +_000800_hash context_alloc 3 24645 _000800_hash NULL
84809 +_000801_hash copy_to_user 3 57835 _000801_hash NULL
84810 +_000802_hash cp210x_get_config 4 56229 _000802_hash NULL
84811 +_000803_hash create_attr_set 1 22861 _000803_hash NULL
84812 +_000804_hash create_bounce_buffer 3 39155 _000804_hash NULL
84813 +_000805_hash create_gpadl_header 2 19064 _000805_hash NULL
84814 +_000806_hash _create_sg_bios 4 31244 _000806_hash NULL
84815 +_000807_hash cryptd_alloc_instance 2-3 18048 _000807_hash NULL
84816 +_000809_hash crypto_ahash_setkey 3 55134 _000809_hash NULL
84817 +_000810_hash crypto_alloc_instance2 3 25277 _000810_hash NULL
84818 +_000811_hash crypto_shash_setkey 3 60483 _000811_hash NULL
84819 +_000812_hash cxgb_alloc_mem 1 24007 _000812_hash NULL
84820 +_000813_hash cxgbi_device_portmap_create 3 25747 _000813_hash NULL
84821 +_000814_hash cxgbi_device_register 1-2 36746 _000814_hash NULL
84822 +_000816_hash __cxio_init_resource_fifo 3 23447 _000816_hash NULL
84823 +_000817_hash dccp_sendmsg 4 56058 _000817_hash NULL
84824 +_000818_hash ddp_make_gl 1 12179 _000818_hash NULL
84825 +_000819_hash depth_write 3 3021 _000819_hash NULL
84826 +_000820_hash dev_irnet_write 3 11398 _000820_hash NULL
84827 +_000821_hash dev_set_alias 3 50084 _000821_hash NULL
84828 +_000822_hash dev_write 3 7708 _000822_hash NULL
84829 +_000823_hash dfs_global_file_write 3 6112 _000823_hash NULL
84830 +_000824_hash dgram_sendmsg 4 45679 _000824_hash NULL
84831 +_000825_hash disconnect 4 32521 _000825_hash NULL
84832 +_000826_hash dma_attach 6-7 50831 _000826_hash NULL
84833 +_000828_hash dma_declare_coherent_memory 4-2 14244 _000828_hash NULL
84834 +_000829_hash dn_sendmsg 4 38390 _000829_hash NULL
84835 +_000830_hash dn_setsockopt 5 314 _000830_hash NULL
84836 +_000831_hash do_arpt_set_ctl 4 51053 _000831_hash NULL
84837 +_000832_hash do_dccp_setsockopt 5 54377 _003195_hash NULL nohasharray
84838 +_000833_hash do_ip6t_set_ctl 4 60040 _000833_hash NULL
84839 +_000834_hash do_ipt_set_ctl 4 56238 _000834_hash NULL
84840 +_000835_hash do_jffs2_setxattr 5 25910 _000835_hash NULL
84841 +_000836_hash do_msgsnd 4 1387 _000836_hash NULL
84842 +_000837_hash do_pselect 1 62061 _000837_hash NULL
84843 +_000838_hash do_raw_setsockopt 5 55215 _000838_hash NULL
84844 +_000839_hash do_readv_writev 4 51849 _000839_hash NULL
84845 +_000840_hash do_sync 1 9604 _000840_hash NULL
84846 +_000841_hash dup_array 3 33551 _000841_hash NULL
84847 +_000842_hash ecryptfs_decode_and_decrypt_filename 5 10379 _000842_hash NULL
84848 +_000843_hash ecryptfs_encrypt_and_encode_filename 6 2109 _000843_hash NULL
84849 +_000844_hash ecryptfs_send_message_locked 2 31801 _000844_hash NULL
84850 +_000845_hash edac_device_alloc_ctl_info 1 5941 _000845_hash NULL
84851 +_000846_hash edac_mc_alloc 4 3611 _000846_hash NULL
84852 +_000847_hash edac_pci_alloc_ctl_info 1 63388 _000847_hash NULL
84853 +_000848_hash efivar_create_sysfs_entry 2 19485 _000848_hash NULL
84854 +_000849_hash enable_write 3 30456 _000849_hash NULL
84855 +_000850_hash enclosure_register 3 57412 _000850_hash NULL
84856 +_000851_hash enlarge_skb 2 44248 _002839_hash NULL nohasharray
84857 +_000852_hash evdev_ioctl_handler 2 21705 _000852_hash NULL
84858 +_000853_hash ext4_kvzalloc 1 47605 _000853_hash NULL
84859 +_000854_hash extend_netdev_table 2 21453 _000854_hash NULL
84860 +_000855_hash fcoe_ctlr_device_add 3 1793 _000855_hash NULL
84861 +_000856_hash fd_do_readv 3 51297 _000856_hash NULL
84862 +_000857_hash fd_do_writev 3 29329 _000857_hash NULL
84863 +_000858_hash __feat_register_sp 6 64712 _000858_hash NULL
84864 +_000859_hash __ffs_ep0_read_events 3 48868 _000859_hash NULL
84865 +_000860_hash ffs_ep0_write 3 9438 _000860_hash NULL
84866 +_000861_hash ffs_epfile_read 3 18775 _000861_hash NULL
84867 +_000862_hash ffs_epfile_write 3 48014 _000862_hash NULL
84868 +_000863_hash fib_info_hash_alloc 1 9075 _000863_hash NULL
84869 +_000864_hash fillonedir 3 41746 _000864_hash NULL
84870 +_000865_hash fs_devrw_entry 3 11924 _000865_hash NULL
84871 +_000866_hash fs_path_prepare_for_add 2 61854 _000866_hash NULL
84872 +_000867_hash fuse_fill_write_pages 4 53682 _000867_hash NULL
84873 +_000868_hash fw_device_op_ioctl 2 11595 _000868_hash NULL
84874 +_000869_hash fw_iso_buffer_init 3 54582 _000869_hash NULL
84875 +_000870_hash fw_node_create 2 9559 _000870_hash NULL
84876 +_000871_hash garmin_read_process 3 27509 _000871_hash NULL
84877 +_000872_hash garp_request_join 4 7471 _000872_hash NULL
84878 +_000873_hash generic_perform_write 3 54832 _000873_hash NULL
84879 +_000874_hash gen_pool_add_virt 4 39913 _000874_hash NULL
84880 +_000875_hash get_derived_key 4 61100 _000875_hash NULL
84881 +_000876_hash get_new_cssid 2 51665 _000876_hash NULL
84882 +_000877_hash getxattr 4 24398 _003758_hash NULL nohasharray
84883 +_000878_hash gsm_control_reply 4 53333 _000878_hash NULL
84884 +_000879_hash hcd_alloc_coherent 5 55862 _000879_hash NULL
84885 +_000880_hash hci_sock_sendmsg 4 37420 _000880_hash NULL
84886 +_000881_hash hidraw_ioctl 2 63658 _000881_hash NULL
84887 +_000882_hash hidraw_write 3 31536 _000882_hash NULL
84888 +_000883_hash hid_register_field 2-3 4874 _000883_hash NULL
84889 +_000885_hash hid_report_raw_event 4 2762 _000885_hash NULL
84890 +_000886_hash hpi_alloc_control_cache 1 35351 _000886_hash NULL
84891 +_000887_hash hugetlbfs_read_actor 2-5-4 34547 _000887_hash NULL
84892 +_000890_hash hvc_alloc 4 12579 _000890_hash NULL
84893 +_000891_hash __hwahc_dev_set_key 5 46328 _000891_hash NULL
84894 +_000892_hash i2400m_zrealloc_2x 3 54166 _001549_hash NULL nohasharray
84895 +_000893_hash ib_alloc_device 1 26483 _000893_hash NULL
84896 +_000894_hash ib_create_send_mad 5 1196 _000894_hash NULL
84897 +_000895_hash ibmasm_new_command 2 25714 _000895_hash NULL
84898 +_000896_hash ib_send_cm_drep 3 50186 _000896_hash NULL
84899 +_000897_hash ib_send_cm_mra 4 60202 _003063_hash NULL nohasharray
84900 +_000898_hash ib_send_cm_rtu 3 63138 _000898_hash NULL
84901 +_000899_hash ide_core_cp_entry 3 22636 _000899_hash NULL
84902 +_000900_hash ieee80211_if_write_smps 3 35550 _000900_hash NULL
84903 +_000901_hash ieee80211_if_write_tkip_mic_test 3 58748 _000901_hash NULL
84904 +_000902_hash ieee80211_if_write_tsf 3 36077 _000902_hash NULL
84905 +_000903_hash ieee80211_if_write_uapsd_max_sp_len 3 14233 _000903_hash NULL
84906 +_000904_hash ieee80211_if_write_uapsd_queues 3 51526 _000904_hash NULL
84907 +_000905_hash ieee80211_key_alloc 3 19065 _000905_hash NULL
84908 +_000906_hash ieee80211_send_probe_req 6-4 6924 _000906_hash NULL
84909 +_000907_hash ieee80211_skb_resize 3 50211 _000907_hash NULL
84910 +_000908_hash if_spi_host_to_card 4 62890 _000908_hash NULL
84911 +_000909_hash if_writecmd 2 815 _000909_hash NULL
84912 +_000910_hash init_bch 1-2 64130 _000910_hash NULL
84913 +_000912_hash init_ipath 1 48187 _000912_hash NULL
84914 +_000913_hash init_list_set 2-3 39188 _000913_hash NULL
84915 +_000915_hash init_q 4 132 _000915_hash NULL
84916 +_000916_hash init_state 2 60165 _000916_hash NULL
84917 +_000917_hash init_tag_map 3 57515 _000917_hash NULL
84918 +_000918_hash input_ff_create 2 21240 _000918_hash NULL
84919 +_000919_hash input_mt_init_slots 2 31183 _000919_hash NULL
84920 +_000920_hash interfaces 2 38859 _000920_hash NULL
84921 +_000921_hash int_hardware_entry 3 36833 _000921_hash NULL
84922 +_000922_hash int_hw_irq_en 3 46776 _000922_hash NULL
84923 +_000923_hash int_tasklet_entry 3 52500 _000923_hash NULL
84924 +_000924_hash ioat2_alloc_ring 2 11172 _000924_hash NULL
84925 +_000925_hash ip_generic_getfrag 3-4 12187 _000925_hash NULL
84926 +_000927_hash ip_options_get_alloc 1 7448 _000927_hash NULL
84927 +_000928_hash ipr_alloc_ucode_buffer 1 40199 _000928_hash NULL
84928 +_000929_hash ip_set_alloc 1 57953 _000929_hash NULL
84929 +_000930_hash ip_setsockopt 5 33487 _000930_hash NULL
84930 +_000931_hash ipv6_flowlabel_opt 3 58135 _001179_hash NULL nohasharray
84931 +_000932_hash ipv6_renew_options 5 28867 _000932_hash NULL
84932 +_000933_hash ipv6_setsockopt 5 29871 _000933_hash NULL
84933 +_000934_hash ipxrtr_route_packet 4 54036 _000934_hash NULL
84934 +_000935_hash irda_sendmsg 4 4388 _000935_hash NULL
84935 +_000936_hash irda_sendmsg_dgram 4 38563 _000936_hash NULL
84936 +_000937_hash irda_sendmsg_ultra 4 42047 _000937_hash NULL
84937 +_000938_hash irias_add_octseq_attrib 4 29983 _000938_hash NULL
84938 +_000939_hash irq_alloc_generic_chip 2 26650 _000939_hash NULL
84939 +_000940_hash iscsi_alloc_session 3 49390 _000940_hash NULL
84940 +_000941_hash iscsi_create_conn 2 50425 _000941_hash NULL
84941 +_000942_hash iscsi_create_endpoint 1 15193 _000942_hash NULL
84942 +_000943_hash iscsi_create_iface 5 38510 _000943_hash NULL
84943 +_000944_hash iscsi_decode_text_input 4 58292 _000944_hash NULL
84944 +_000945_hash iscsi_pool_init 2-4 54913 _000945_hash NULL
84945 +_000947_hash iscsit_dump_data_payload 2 38683 _000947_hash NULL
84946 +_000948_hash isdn_write 3 45863 _000948_hash NULL
84947 +_000949_hash isku_receive 4 54130 _000949_hash NULL
84948 +_000950_hash islpci_mgt_transaction 5 23610 _000950_hash NULL
84949 +_000951_hash iso_alloc_urb 4-5 45206 _000951_hash NULL
84950 +_000952_hash iso_sched_alloc 1 13377 _003325_hash NULL nohasharray
84951 +_000953_hash iwl_trans_txq_alloc 3 36147 _000953_hash NULL
84952 +_000954_hash ixgbe_alloc_q_vector 4-6 24439 _000954_hash NULL
84953 +_000956_hash jbd2_journal_init_revoke 2 51088 _000956_hash NULL
84954 +_000957_hash jffs2_write_dirent 5 37311 _000957_hash NULL
84955 +_000958_hash journal_init_revoke 2 56933 _000958_hash NULL
84956 +_000959_hash keyctl_instantiate_key 3 41855 _000959_hash NULL
84957 +_000960_hash keyctl_instantiate_key_iov 3 16969 _000960_hash NULL
84958 +_000961_hash __kfifo_from_user 3 20399 _000961_hash NULL
84959 +_000962_hash kimage_crash_alloc 3 3233 _000962_hash NULL
84960 +_000963_hash kimage_normal_alloc 3 31140 _000963_hash NULL
84961 +_000964_hash kmem_realloc 2 37489 _000964_hash NULL
84962 +_000965_hash kmem_zalloc 1 11510 _000965_hash NULL
84963 +_000966_hash koneplus_sysfs_read 6 42792 _000966_hash NULL
84964 +_000967_hash kvm_kvzalloc 1 52894 _000967_hash NULL
84965 +_000968_hash kvm_read_guest_page_mmu 6 37611 _000968_hash NULL
84966 +_000969_hash kvm_set_irq_routing 3 48704 _000969_hash NULL
84967 +_000970_hash kvm_write_guest_cached 4 11106 _000970_hash NULL
84968 +_000971_hash kvm_write_guest_page 5 63555 _002812_hash NULL nohasharray
84969 +_000972_hash kzalloc_node 1 24352 _000972_hash NULL
84970 +_000973_hash l2cap_skbuff_fromiovec 3-4 35003 _000973_hash NULL
84971 +_000975_hash l2tp_ip_sendmsg 4 50411 _000975_hash NULL
84972 +_000976_hash l2tp_session_create 1 25286 _000976_hash NULL
84973 +_000977_hash lc_create 3 48662 _000977_hash NULL
84974 +_000978_hash leaf_dealloc 3 29566 _000978_hash NULL
84975 +_000979_hash linear_conf 2 23485 _003837_hash NULL nohasharray
84976 +_000980_hash llc_ui_sendmsg 4 24987 _000980_hash NULL
84977 +_000981_hash load_module 2 60056 _003010_hash NULL nohasharray
84978 +_000982_hash lpfc_sli4_queue_alloc 3 62646 _000982_hash NULL
84979 +_000983_hash mdiobus_alloc_size 1 52259 _000983_hash NULL
84980 +_000984_hash mempool_create_node 1 3191 _000984_hash NULL
84981 +_000985_hash mem_read 3 57631 _000985_hash NULL
84982 +_000986_hash memstick_alloc_host 1 142 _000986_hash NULL
84983 +_000987_hash mem_swapout_entry 3 32586 _000987_hash NULL
84984 +_000988_hash mem_write 3 22232 _000988_hash NULL
84985 +_000989_hash mesh_table_alloc 1 22305 _000989_hash NULL
84986 +_000990_hash mfd_add_devices 4 16668 _000990_hash NULL
84987 +_000991_hash mISDN_sock_sendmsg 4 41035 _000991_hash NULL
84988 +_000992_hash mlx4_init_icm_table 4-5 2151 _000992_hash NULL
84989 +_000994_hash mmc_alloc_host 1 48097 _000994_hash NULL
84990 +_000995_hash mmc_test_alloc_mem 2-3 28102 _000995_hash NULL
84991 +_000997_hash mon_bin_ioctl 3 2771 _000997_hash NULL
84992 +_000998_hash mpi_alloc 1 18094 _000998_hash NULL
84993 +_000999_hash mpihelp_mul_karatsuba_case 5-3 23918 _003061_hash NULL nohasharray
84994 +_001000_hash __mptctl_ioctl 2 15875 _001000_hash NULL
84995 +_001001_hash mtd_concat_create 2 14416 _001001_hash NULL
84996 +_001002_hash mthca_alloc_cq_buf 3 46512 _001002_hash NULL
84997 +_001003_hash mvumi_alloc_mem_resource 3 47750 _001003_hash NULL
84998 +_001004_hash mwifiex_11n_create_rx_reorder_tbl 4 63806 _001004_hash NULL
84999 +_001005_hash mwifiex_alloc_sdio_mpa_buffers 2-3 60961 _001005_hash NULL
85000 +_001007_hash mwl8k_cmd_set_beacon 4 23110 _001007_hash NULL
85001 +_001008_hash neigh_hash_alloc 1 17595 _001008_hash NULL
85002 +_001009_hash __netdev_alloc_skb 2 18595 _001009_hash NULL
85003 +_001010_hash __netlink_change_ngroups 2 46156 _001010_hash NULL
85004 +_001011_hash netlink_sendmsg 4 33708 _001236_hash NULL nohasharray
85005 +_001012_hash netxen_alloc_sds_rings 2 13417 _001012_hash NULL
85006 +_001013_hash new_bind_ctl 2 35324 _001013_hash NULL
85007 +_001014_hash new_dir 3 31919 _001014_hash NULL
85008 +_001015_hash new_tape_buffer 2 32866 _001015_hash NULL
85009 +_001016_hash nfc_llcp_build_tlv 3 19536 _001016_hash NULL
85010 +_001017_hash nfc_llcp_send_i_frame 3 59130 _001017_hash NULL
85011 +_001018_hash nf_ct_ext_create 3 51232 _001018_hash NULL
85012 +_001019_hash nfs4_alloc_pages 1 48426 _001019_hash NULL
85013 +_001020_hash nfs4_alloc_slots 1 2454 _003345_hash NULL nohasharray
85014 +_001021_hash nfsctl_transaction_write 3 64800 _001021_hash NULL
85015 +_001022_hash nfs_fscache_get_super_cookie 3 44355 _001850_hash NULL nohasharray
85016 +_001023_hash nfs_idmap_request_key 3 30208 _001023_hash NULL
85017 +_001024_hash nfs_pgarray_set 2 1085 _001024_hash NULL
85018 +_001025_hash nl_pid_hash_zalloc 1 23314 _001025_hash NULL
85019 +_001026_hash nr_sendmsg 4 53656 _001026_hash NULL
85020 +_001027_hash nsm_create_handle 4 38060 _001027_hash NULL
85021 +_001028_hash ntfs_copy_from_user_iovec 3-6 49829 _001028_hash NULL
85022 +_001030_hash ntfs_file_buffered_write 4-6 41442 _001030_hash NULL
85023 +_001032_hash __ntfs_malloc 1 34022 _001032_hash NULL
85024 +_001033_hash nvme_alloc_queue 3 46865 _001033_hash NULL
85025 +_001034_hash nvme_map_user_pages 3-4 41093 _001639_hash NULL nohasharray
85026 +_001036_hash ocfs2_acl_from_xattr 2 21604 _001036_hash NULL
85027 +_001037_hash ocfs2_control_message 3 19564 _001037_hash NULL
85028 +_001038_hash _ore_get_io_state 3-5-4 2166 _001038_hash NULL
85029 +_001041_hash orinoco_set_key 5-7 17878 _001041_hash NULL
85030 +_001043_hash osdmap_set_max_osd 2 57630 _002267_hash NULL nohasharray
85031 +_001044_hash _osd_realloc_seg 3 54352 _001044_hash NULL
85032 +_001045_hash osst_execute 7-6 17607 _001045_hash NULL
85033 +_001046_hash osst_write 3 31581 _001046_hash NULL
85034 +_001047_hash otp_read 2-5-4 10594 _001047_hash NULL
85035 +_001050_hash ovs_vport_alloc 1 33475 _001050_hash NULL
85036 +_001051_hash p54_parse_rssical 3 64493 _001051_hash NULL
85037 +_001052_hash p9_client_zc_rpc 7 14345 _001052_hash NULL
85038 +_001053_hash packet_sendmsg_spkt 4 28885 _001053_hash NULL
85039 +_001054_hash pair_device 4 61175 _003161_hash NULL nohasharray
85040 +_001055_hash pccard_store_cis 6 18176 _001055_hash NULL
85041 +_001056_hash pci_add_cap_save_buffer 3 3426 _001056_hash NULL
85042 +_001057_hash pcnet32_realloc_rx_ring 3 36598 _001057_hash NULL
85043 +_001058_hash pcnet32_realloc_tx_ring 3 38428 _001058_hash NULL
85044 +_001059_hash pcpu_mem_zalloc 1 22948 _001059_hash NULL
85045 +_001060_hash pep_sendmsg 4 62524 _001060_hash NULL
85046 +_001061_hash pfkey_sendmsg 4 47394 _001061_hash NULL
85047 +_001062_hash pidlist_resize 2 496 _001062_hash NULL
85048 +_001063_hash pin_code_reply 4 46510 _001063_hash NULL
85049 +_001064_hash ping_getfrag 3-4 8360 _001064_hash NULL
85050 +_001066_hash pipe_set_size 2 5204 _001066_hash NULL
85051 +_001067_hash pkt_bio_alloc 1 48284 _001067_hash NULL
85052 +_001068_hash platform_create_bundle 4-6 12785 _001068_hash NULL
85053 +_001070_hash pm8001_store_update_fw 4 55716 _001070_hash NULL
85054 +_001071_hash pmcraid_alloc_sglist 1 9864 _001071_hash NULL
85055 +_001072_hash pn533_dep_link_up 5 22154 _001072_hash NULL
85056 +_001073_hash pn533_init_target_frame 3 65438 _001073_hash NULL
85057 +_001074_hash pnp_alloc 1 24869 _001538_hash NULL nohasharray
85058 +_001075_hash pn_sendmsg 4 12640 _001075_hash NULL
85059 +_001076_hash pppoe_sendmsg 4 48039 _001076_hash NULL
85060 +_001077_hash pppol2tp_sendmsg 4 56420 _001077_hash NULL
85061 +_001078_hash prism2_info_hostscanresults 3 39657 _001078_hash NULL
85062 +_001079_hash process_vm_rw 3-5 47533 _001079_hash NULL
85063 +_001081_hash process_vm_rw_single_vec 1-2 26213 _001081_hash NULL
85064 +_001083_hash proc_write 3 51003 _001083_hash NULL
85065 +_001084_hash profile_load 3 58267 _001084_hash NULL
85066 +_001085_hash profile_remove 3 8556 _001085_hash NULL
85067 +_001086_hash profile_replace 3 14652 _001086_hash NULL
85068 +_001087_hash pscsi_get_bio 1 56103 _001087_hash NULL
85069 +_001088_hash __pskb_copy 2 9038 _001088_hash NULL
85070 +_001089_hash __pskb_pull_tail 2 60287 _001089_hash NULL
85071 +_001090_hash qla4xxx_alloc_work 2 44813 _001090_hash NULL
85072 +_001091_hash qlcnic_alloc_msix_entries 2 46160 _001091_hash NULL
85073 +_001092_hash qlcnic_alloc_sds_rings 2 26795 _001092_hash NULL
85074 +_001093_hash queue_received_packet 5 9657 _001093_hash NULL
85075 +_001094_hash raw_send_hdrinc 4 58803 _001094_hash NULL
85076 +_001095_hash raw_sendmsg 4 23078 _003316_hash NULL nohasharray
85077 +_001096_hash rawsock_sendmsg 4 60010 _001096_hash NULL
85078 +_001097_hash rawv6_send_hdrinc 3 35425 _001097_hash NULL
85079 +_001098_hash rawv6_setsockopt 5 56165 _001098_hash NULL
85080 +_001099_hash rb_alloc 1 3102 _001099_hash NULL
85081 +_001100_hash rbd_alloc_coll 1 33678 _001100_hash NULL
85082 +_001101_hash rbd_create_rw_ops 1 55297 _001101_hash NULL
85083 +_001102_hash rds_ib_inc_copy_to_user 3 55007 _001102_hash NULL
85084 +_001103_hash rds_iw_inc_copy_to_user 3 29214 _001103_hash NULL
85085 +_001104_hash rds_message_alloc 1 10517 _001104_hash NULL
85086 +_001105_hash rds_message_copy_from_user 3 45510 _001105_hash NULL
85087 +_001106_hash rds_message_inc_copy_to_user 3 26540 _001106_hash NULL
85088 +_001107_hash regcache_rbtree_insert_to_block 5 58009 _001107_hash NULL
85089 +_001108_hash _regmap_raw_write 4 42652 _001108_hash NULL
85090 +_001109_hash regmap_register_patch 3 21681 _001109_hash NULL
85091 +_001110_hash relay_alloc_page_array 1 52735 _001110_hash NULL
85092 +_001111_hash remove_uuid 4 64505 _001111_hash NULL
85093 +_001112_hash reshape_ring 2 29147 _001112_hash NULL
85094 +_001113_hash RESIZE_IF_NEEDED 2 56286 _001113_hash NULL
85095 +_001114_hash resize_info_buffer 2 62889 _001114_hash NULL
85096 +_001115_hash resize_stripes 2 61650 _001115_hash NULL
85097 +_001116_hash rfcomm_sock_sendmsg 4 37661 _003661_hash NULL nohasharray
85098 +_001117_hash roccat_common2_send_with_status 4 50343 _001117_hash NULL
85099 +_001118_hash rose_sendmsg 4 20249 _001118_hash NULL
85100 +_001119_hash rsc_mgr_init 3 16299 _001119_hash NULL
85101 +_001120_hash rxrpc_send_data 5 21553 _001120_hash NULL
85102 +_001121_hash rxrpc_setsockopt 5 50286 _001121_hash NULL
85103 +_001122_hash savu_sysfs_read 6 49473 _001122_hash NULL
85104 +_001124_hash sco_send_frame 3 41815 _001124_hash NULL
85105 +_001125_hash scsi_dispatch_cmd_entry 3 49848 _001125_hash NULL
85106 +_001126_hash scsi_host_alloc 2 63041 _001126_hash NULL
85107 +_001127_hash scsi_tgt_kspace_exec 8 9522 _001127_hash NULL
85108 +_001128_hash sctp_sendmsg 4 61919 _001128_hash NULL
85109 +_001129_hash sctp_setsockopt 5 44788 _001129_hash NULL
85110 +_001130_hash sctp_setsockopt_connectx 3 6073 _001130_hash NULL
85111 +_001131_hash sctp_setsockopt_connectx_old 3 22631 _001131_hash NULL
85112 +_001132_hash sctp_tsnmap_grow 2 32784 _001132_hash NULL
85113 +_001133_hash sctp_tsnmap_init 2 36446 _001133_hash NULL
85114 +_001134_hash sctp_user_addto_chunk 2-3 62047 _001134_hash NULL
85115 +_001136_hash security_context_to_sid 2 19839 _001136_hash NULL
85116 +_001137_hash security_context_to_sid_default 2 3492 _003841_hash NULL nohasharray
85117 +_001138_hash security_context_to_sid_force 2 20724 _001138_hash NULL
85118 +_001139_hash self_check_write 5 50856 _001139_hash NULL
85119 +_001140_hash selinux_transaction_write 3 59038 _001140_hash NULL
85120 +_001141_hash sel_write_access 3 51704 _001141_hash NULL
85121 +_001142_hash sel_write_create 3 11353 _001142_hash NULL
85122 +_001143_hash sel_write_member 3 28800 _001143_hash NULL
85123 +_001144_hash sel_write_relabel 3 55195 _001144_hash NULL
85124 +_001145_hash sel_write_user 3 45060 _001145_hash NULL
85125 +_001146_hash __seq_open_private 3 40715 _001146_hash NULL
85126 +_001147_hash serverworks_create_gatt_pages 1 46582 _001147_hash NULL
85127 +_001148_hash set_connectable 4 56458 _001148_hash NULL
85128 +_001149_hash set_dev_class 4 39645 _001921_hash NULL nohasharray
85129 +_001150_hash set_discoverable 4 48141 _001150_hash NULL
85130 +_001151_hash set_fd_set 1 35249 _001151_hash NULL
85131 +_001152_hash setkey 3 14987 _001152_hash NULL
85132 +_001153_hash set_le 4 30581 _001153_hash NULL
85133 +_001154_hash set_link_security 4 4502 _001154_hash NULL
85134 +_001155_hash set_local_name 4 55757 _001155_hash NULL
85135 +_001156_hash set_powered 4 12129 _001156_hash NULL
85136 +_001157_hash set_ssp 4 62411 _001157_hash NULL
85137 +_001158_hash sg_build_sgat 3 60179 _001158_hash &_000314_hash
85138 +_001159_hash sg_read_oxfer 3 51724 _001159_hash NULL
85139 +_001160_hash shmem_xattr_set 4 11843 _001160_hash NULL
85140 +_001161_hash simple_alloc_urb 3 60420 _001161_hash NULL
85141 +_001162_hash sisusb_send_bridge_packet 2 11649 _001162_hash NULL
85142 +_001163_hash sisusb_send_packet 2 20891 _001163_hash NULL
85143 +_001164_hash sisusb_write_mem_bulk 4 29678 _001164_hash NULL
85144 +_001165_hash skb_add_data_nocache 4 4682 _001165_hash NULL
85145 +_001166_hash skb_copy_datagram_from_iovec 2-5-4 52014 _001166_hash NULL
85146 +_001169_hash skb_copy_expand 2-3 7685 _001169_hash &_000677_hash
85147 +_001171_hash skb_copy_to_page_nocache 6 58624 _001171_hash NULL
85148 +_001172_hash __skb_cow 2 39254 _001172_hash NULL
85149 +_001173_hash skb_cow_data 2 11565 _001173_hash NULL
85150 +_001174_hash skb_pad 2 17302 _001174_hash NULL
85151 +_001175_hash skb_realloc_headroom 2 19516 _001175_hash NULL
85152 +_001176_hash sk_chk_filter 2 42095 _001176_hash NULL
85153 +_001177_hash skcipher_sendmsg 4 30290 _001177_hash NULL
85154 +_001178_hash sl_change_mtu 2 7396 _001178_hash NULL
85155 +_001179_hash slhc_init 1-2 58135 _001179_hash &_000931_hash
85156 +_001181_hash sm501_create_subdev 3-4 48668 _001245_hash NULL nohasharray
85157 +_001183_hash smk_user_access 3 24440 _001183_hash NULL
85158 +_001184_hash smk_write_cipso2 3 1021 _001184_hash NULL
85159 +_001185_hash smk_write_cipso 3 17989 _001185_hash NULL
85160 +_001186_hash smk_write_load2 3 52155 _001186_hash NULL
85161 +_001187_hash smk_write_load 3 26829 _001187_hash NULL
85162 +_001188_hash smk_write_load_self2 3 591 _001188_hash NULL
85163 +_001189_hash smk_write_load_self 3 7958 _001189_hash NULL
85164 +_001190_hash snapshot_write 3 28351 _001190_hash NULL
85165 +_001191_hash snd_ac97_pcm_assign 2 30218 _001191_hash NULL
85166 +_001192_hash snd_card_create 4 64418 _001529_hash NULL nohasharray
85167 +_001193_hash snd_emux_create_port 3 42533 _001193_hash NULL
85168 +_001194_hash snd_gus_dram_write 4 38784 _001194_hash NULL
85169 +_001195_hash snd_midi_channel_alloc_set 1 28153 _001195_hash NULL
85170 +_001196_hash _snd_pcm_lib_alloc_vmalloc_buffer 2 17820 _001196_hash NULL
85171 +_001197_hash snd_pcm_oss_sync1 2 45298 _001197_hash NULL
85172 +_001198_hash snd_pcm_oss_write 3 38108 _001198_hash NULL
85173 +_001199_hash snd_pcm_plugin_build 5 25505 _001199_hash NULL
85174 +_001200_hash snd_rawmidi_kernel_write 3 25106 _001200_hash NULL
85175 +_001201_hash snd_rawmidi_write 3 28008 _001201_hash NULL
85176 +_001202_hash snd_rme32_playback_copy 5 43732 _001202_hash NULL
85177 +_001203_hash snd_rme96_playback_copy 5 13111 _001203_hash NULL
85178 +_001204_hash snd_seq_device_new 4 31753 _001204_hash NULL
85179 +_001205_hash snd_seq_oss_readq_new 2 14283 _001205_hash NULL
85180 +_001206_hash snd_vx_create 4 40948 _001206_hash NULL
85181 +_001207_hash sock_setsockopt 5 50088 _001207_hash NULL
85182 +_001208_hash sound_write 3 5102 _001208_hash NULL
85183 +_001209_hash _sp2d_alloc 1-3-2 16944 _001209_hash NULL
85184 +_001212_hash spi_alloc_master 2 45223 _001212_hash NULL
85185 +_001213_hash spidev_message 3 5518 _001213_hash NULL
85186 +_001214_hash spi_register_board_info 2 35651 _001214_hash NULL
85187 +_001215_hash squashfs_cache_init 2 41656 _001215_hash NULL
85188 +_001216_hash squashfs_read_data 6 59440 _001216_hash NULL
85189 +_001217_hash squashfs_read_fragment_index_table 4 2506 _001217_hash NULL
85190 +_001218_hash squashfs_read_id_index_table 4 61961 _001218_hash NULL
85191 +_001219_hash squashfs_read_inode_lookup_table 4 64739 _001219_hash NULL
85192 +_001220_hash srp_alloc_iu 2 44227 _001220_hash NULL
85193 +_001221_hash srp_iu_pool_alloc 2 17920 _001221_hash NULL
85194 +_001222_hash srp_ring_alloc 2 26760 _001222_hash NULL
85195 +_001226_hash start_isoc_chain 2 565 _001226_hash NULL
85196 +_001227_hash st_write 3 16874 _001227_hash NULL
85197 +_001228_hash svc_pool_map_alloc_arrays 2 47181 _001228_hash NULL
85198 +_001229_hash symtab_init 2 61050 _001229_hash NULL
85199 +_001230_hash sys_bind 3 10799 _001230_hash NULL
85200 +_001231_hash sys_connect 3 15291 _003816_hash NULL nohasharray
85201 +_001232_hash sys_flistxattr 3 41407 _001232_hash NULL
85202 +_001233_hash sys_fsetxattr 4 49736 _001233_hash NULL
85203 +_001234_hash sysfs_write_file 3 57116 _001234_hash NULL
85204 +_001235_hash sys_ipc 3 4889 _001235_hash NULL
85205 +_001236_hash sys_keyctl 4 33708 _001236_hash &_001011_hash
85206 +_001237_hash sys_listxattr 3 27833 _001237_hash NULL
85207 +_001238_hash sys_llistxattr 3 4532 _001238_hash NULL
85208 +_001239_hash sys_lsetxattr 4 61177 _001239_hash NULL
85209 +_001240_hash sys_mq_timedsend 3 57661 _001240_hash NULL
85210 +_001241_hash sys_sched_setaffinity 2 32046 _001241_hash NULL
85211 +_001242_hash sys_select 1 38827 _001242_hash NULL
85212 +_001243_hash sys_semop 3 39457 _001243_hash NULL
85213 +_001244_hash sys_sendto 6 20809 _001244_hash NULL
85214 +_001245_hash sys_setgroups 1 48668 _001245_hash &_001181_hash
85215 +_001246_hash sys_setgroups16 1 48882 _001246_hash NULL
85216 +_001247_hash sys_setxattr 4 37880 _001247_hash NULL
85217 +_001248_hash t4_alloc_mem 1 32342 _001248_hash NULL
85218 +_001249_hash tcf_hash_create 4 54360 _001249_hash NULL
85219 +_001250_hash tcp_send_rcvq 3 11316 _001250_hash NULL
85220 +_001251_hash __team_options_register 3 63941 _001251_hash NULL
85221 +_001252_hash test_unaligned_bulk 3 52333 _001252_hash NULL
85222 +_001253_hash tifm_alloc_adapter 1 10903 _001253_hash NULL
85223 +_001254_hash timeout_write 3 50991 _001254_hash NULL
85224 +_001255_hash timeradd_entry 3 49850 _001255_hash NULL
85225 +_001256_hash tipc_link_send_sections_fast 4 37920 _001256_hash NULL
85226 +_001257_hash tipc_subseq_alloc 1 5957 _001257_hash NULL
85227 +_001258_hash tnode_alloc 1 49407 _001258_hash NULL
85228 +_001259_hash tomoyo_commit_ok 2 20167 _001259_hash NULL
85229 +_001260_hash tomoyo_scan_bprm 2-4 15642 _003488_hash NULL nohasharray
85230 +_001262_hash tps6586x_writes 3 58689 _001262_hash NULL
85231 +_001263_hash tty_buffer_find 2 2443 _001263_hash NULL
85232 +_001264_hash tty_write 3 5494 _001264_hash NULL
85233 +_001265_hash ubifs_setxattr 4 59650 _001477_hash NULL nohasharray
85234 +_001266_hash ubi_self_check_all_ff 4 41959 _001266_hash NULL
85235 +_001267_hash udf_sb_alloc_partition_maps 2 62313 _001267_hash NULL
85236 +_001268_hash udplite_getfrag 3-4 14479 _001268_hash NULL
85237 +_001270_hash ulong_write_file 3 26485 _001270_hash NULL
85238 +_001271_hash unix_stream_sendmsg 4 61455 _001271_hash NULL
85239 +_001272_hash unlink_queued 3-4 645 _001272_hash NULL
85240 +_001273_hash update_pmkid 4 2481 _001273_hash NULL
85241 +_001274_hash usb_alloc_coherent 2 65444 _001274_hash NULL
85242 +_001275_hash vc_resize 2-3 3585 _001275_hash NULL
85243 +_001277_hash vhci_write 3 2224 _001277_hash NULL
85244 +_001278_hash __vhost_add_used_n 3 26554 _001278_hash NULL
85245 +_001279_hash virtqueue_add_buf 3-4 59470 _001279_hash NULL
85246 +_001281_hash vmalloc 1 15464 _001281_hash NULL
85247 +_001282_hash vol_cdev_write 3 40915 _001282_hash NULL
85248 +_001283_hash vxge_device_register 4 7752 _001283_hash NULL
85249 +_001284_hash __vxge_hw_blockpool_malloc 2 5786 _001284_hash NULL
85250 +_001285_hash __vxge_hw_channel_allocate 3 55462 _001285_hash NULL
85251 +_001286_hash vzalloc 1 47421 _001286_hash NULL
85252 +_001287_hash vzalloc_node 1 23424 _001287_hash NULL
85253 +_001288_hash wa_nep_queue 2 8858 _001288_hash NULL
85254 +_001289_hash __wa_xfer_setup_segs 2 56725 _001289_hash NULL
85255 +_001290_hash wiphy_new 2 2482 _001290_hash NULL
85256 +_001291_hash wm8350_block_write 3 19727 _001291_hash NULL
85257 +_001292_hash wpan_phy_alloc 1 48056 _001292_hash NULL
85258 +_001293_hash write_flush_pipefs 3 2021 _001293_hash NULL
85259 +_001294_hash write_flush_procfs 3 44011 _001294_hash NULL
85260 +_001295_hash wusb_ccm_mac 7 32199 _001295_hash NULL
85261 +_001296_hash x25_sendmsg 4 12487 _001296_hash NULL
85262 +_001297_hash xfrm_hash_alloc 1 10997 _001297_hash NULL
85263 +_001298_hash _xfs_buf_get_pages 2 46811 _001298_hash NULL
85264 +_001299_hash xfs_da_grow_inode_int 3 21785 _001299_hash NULL
85265 +_001300_hash xfs_dir_cilookup_result 3 64288 _003160_hash NULL nohasharray
85266 +_001301_hash xfs_idata_realloc 2 26199 _001301_hash NULL
85267 +_001302_hash xfs_iext_add_indirect_multi 3 32400 _001302_hash NULL
85268 +_001303_hash xfs_iext_inline_to_direct 2 12384 _001303_hash NULL
85269 +_001304_hash xfs_iformat_local 4 49472 _001304_hash NULL
85270 +_001305_hash xfs_iroot_realloc 2 46826 _001305_hash NULL
85271 +_001306_hash xhci_alloc_stream_info 3 63902 _001306_hash NULL
85272 +_001307_hash xlog_recover_add_to_trans 4 62839 _001307_hash NULL
85273 +_001308_hash xprt_alloc 2 1475 _001308_hash NULL
85274 +_001309_hash xt_alloc_table_info 1 57903 _001309_hash NULL
85275 +_001310_hash _zd_iowrite32v_async_locked 3 39034 _001310_hash NULL
85276 +_001311_hash zd_usb_iowrite16v 3 49744 _001311_hash NULL
85277 +_001312_hash a2mp_send 4 41615 _001312_hash NULL
85278 +_001313_hash acpi_ds_build_internal_package_obj 3 58271 _001313_hash NULL
85279 +_001314_hash acpi_system_read_event 3 55362 _001314_hash NULL
85280 +_001315_hash acpi_ut_create_buffer_object 1 42030 _001315_hash NULL
85281 +_001316_hash acpi_ut_create_package_object 1 17594 _001316_hash NULL
85282 +_001317_hash acpi_ut_create_string_object 1 15360 _001317_hash NULL
85283 +_001318_hash ad7879_spi_multi_read 3 8218 _001318_hash NULL
85284 +_001319_hash add_child 4 45201 _001319_hash NULL
85285 +_001320_hash add_port 2 54941 _001320_hash NULL
85286 +_001321_hash adu_read 3 24177 _001321_hash NULL
85287 +_001322_hash afs_cell_create 2 27346 _001322_hash NULL
85288 +_001323_hash agp_allocate_memory 2 58761 _001323_hash NULL
85289 +_001324_hash agp_generic_alloc_user 1 9470 _001324_hash NULL
85290 +_001325_hash alc_auto_create_extra_outs 2 18975 _001325_hash NULL
85291 +_001326_hash alloc_agpphysmem_i8xx 1 39427 _001326_hash NULL
85292 +_001327_hash allocate_cnodes 1 5329 _001327_hash NULL
85293 +_001328_hash ___alloc_bootmem 1 11410 _001328_hash NULL
85294 +_001329_hash __alloc_bootmem_low_node 2 25726 _001662_hash NULL nohasharray
85295 +_001330_hash __alloc_bootmem_node 2 1992 _001330_hash NULL
85296 +_001331_hash __alloc_bootmem_node_nopanic 2 6432 _001331_hash NULL
85297 +_001332_hash __alloc_bootmem_nopanic 1 65397 _001332_hash NULL
85298 +_001333_hash alloc_candev 1-2 7776 _001333_hash NULL
85299 +_001335_hash _alloc_cdb_cont 2 23609 _001335_hash NULL
85300 +_001336_hash alloc_dummy_extent_buffer 2 56374 _001336_hash NULL
85301 +_001337_hash ____alloc_ei_netdev 1 51475 _001337_hash NULL
85302 +_001338_hash alloc_etherdev_mqs 1 36450 _001338_hash NULL
85303 +_001339_hash alloc_extent_buffer 3 52824 _001339_hash NULL
85304 +_001340_hash alloc_fcdev 1 18780 _001340_hash NULL
85305 +_001341_hash alloc_fddidev 1 15382 _001341_hash NULL
85306 +_001342_hash _alloc_get_attr_desc 2 470 _001342_hash NULL
85307 +_001343_hash alloc_hippi_dev 1 51320 _001343_hash NULL
85308 +_001344_hash alloc_irdadev 1 19140 _001344_hash NULL
85309 +_001345_hash alloc_ldt 2 21972 _001345_hash NULL
85310 +_001346_hash alloc_ltalkdev 1 38071 _001346_hash NULL
85311 +_001347_hash alloc_one_pg_vec_page 1 10747 _001347_hash NULL
85312 +_001348_hash alloc_orinocodev 1 21371 _001348_hash NULL
85313 +_001349_hash alloc_ring 2-4 18278 _001349_hash NULL
85314 +_001351_hash _alloc_set_attr_list 4 48991 _001351_hash NULL
85315 +_001353_hash alloc_tx 2 32143 _001353_hash NULL
85316 +_001354_hash alloc_wr 1-2 24635 _001354_hash NULL
85317 +_001356_hash async_setkey 3 35521 _001356_hash NULL
85318 +_001357_hash ata_host_alloc_pinfo 3 17325 _001357_hash NULL
85319 +_001360_hash ath6kl_connect_event 7-9-8 14267 _001360_hash NULL
85320 +_001361_hash ath6kl_fwlog_block_read 3 49836 _001361_hash NULL
85321 +_001362_hash ath6kl_fwlog_read 3 32101 _001362_hash NULL
85322 +_001363_hash ath9k_wmi_cmd 4 327 _001363_hash NULL
85323 +_001364_hash ath_rx_init 2 43564 _001364_hash NULL
85324 +_001365_hash ath_tx_init 2 60515 _001365_hash NULL
85325 +_001366_hash atm_alloc_charge 2 19517 _001914_hash NULL nohasharray
85326 +_001367_hash atm_get_addr 3 31221 _001367_hash NULL
85327 +_001368_hash audit_log_n_hex 3 45617 _001368_hash NULL
85328 +_001369_hash audit_log_n_string 3 31705 _001369_hash NULL
85329 +_001370_hash ax25_output 2 22736 _001370_hash NULL
85330 +_001371_hash bcsp_prepare_pkt 3 12961 _001371_hash NULL
85331 +_001372_hash bdx_rxdb_create 1 46525 _001372_hash NULL
85332 +_001373_hash bdx_tx_db_init 2 41719 _001373_hash NULL
85333 +_001374_hash bio_map_kern 3 64751 _001374_hash NULL
85334 +_001375_hash bits_to_user 2-3 47733 _001375_hash NULL
85335 +_001377_hash __blk_queue_init_tags 2 9778 _001377_hash NULL
85336 +_001378_hash blk_queue_resize_tags 2 28670 _001378_hash NULL
85337 +_001379_hash blk_rq_map_user_iov 5 16772 _001379_hash NULL
85338 +_001380_hash bm_init 2 13529 _001380_hash NULL
85339 +_001381_hash brcmf_alloc_wdev 1 60347 _001381_hash NULL
85340 +_001382_hash __btrfs_buffered_write 3 35311 _002735_hash NULL nohasharray
85341 +_001383_hash btrfs_insert_dir_item 4 59304 _001383_hash NULL
85342 +_001384_hash btrfs_map_block 3 64379 _001384_hash NULL
85343 +_001385_hash bt_skb_alloc 1 6404 _001385_hash NULL
85344 +_001386_hash c4_add_card 3 54968 _001386_hash NULL
85345 +_001387_hash cache_read 3 24790 _001387_hash NULL
85346 +_001388_hash cache_write 3 13589 _001388_hash NULL
85347 +_001389_hash calc_hmac 3 32010 _001389_hash NULL
85348 +_001390_hash capinc_tty_write 3 28539 _001390_hash NULL
85349 +_001391_hash ccid_getsockopt_builtin_ccids 2 53634 _001391_hash NULL
85350 +_001392_hash ceph_copy_page_vector_to_user 3-4 31270 _001392_hash NULL
85351 +_001394_hash ceph_parse_server_name 2 60318 _001394_hash NULL
85352 +_001395_hash ceph_read_dir 3 17005 _001395_hash NULL
85353 +_001396_hash cfg80211_roamed 5-7 32632 _001396_hash NULL
85354 +_001398_hash cfpkt_add_body 3 44630 _001398_hash NULL
85355 +_001399_hash cfpkt_create_pfx 1-2 23594 _001399_hash NULL
85356 +_001401_hash cmd_complete 6 51629 _001401_hash NULL
85357 +_001402_hash cmtp_add_msgpart 4 9252 _001402_hash NULL
85358 +_001403_hash cmtp_send_interopmsg 7 376 _001403_hash NULL
85359 +_001404_hash coda_psdev_read 3 35029 _001404_hash NULL
85360 +_001405_hash construct_key_and_link 4 8321 _001405_hash NULL
85361 +_001406_hash copy_counters_to_user 5 17027 _001406_hash NULL
85362 +_001407_hash copy_entries_to_user 1 52367 _001407_hash NULL
85363 +_001408_hash copy_from_buf 2-4 27308 _001408_hash NULL
85364 +_001410_hash copy_oldmem_page 3-1 26164 _001410_hash NULL
85365 +_001411_hash copy_to_user_fromio 3 57432 _001411_hash NULL
85366 +_001412_hash cryptd_hash_setkey 3 42781 _001412_hash NULL
85367 +_001413_hash crypto_authenc_esn_setkey 3 6985 _001413_hash NULL
85368 +_001414_hash crypto_authenc_setkey 3 80 _001414_hash NULL
85369 +_001415_hash cxgb3_get_cpl_reply_skb 2 10620 _001415_hash NULL
85370 +_001416_hash cxgbi_ddp_reserve 4 30091 _001416_hash NULL
85371 +_001417_hash cxio_init_resource_fifo 3 28764 _001417_hash NULL
85372 +_001418_hash cxio_init_resource_fifo_random 3 47151 _001418_hash NULL
85373 +_001419_hash datablob_hmac_append 3 40038 _001419_hash NULL
85374 +_001420_hash datablob_hmac_verify 4 24786 _001420_hash NULL
85375 +_001421_hash dataflash_read_fact_otp 3-2 33204 _001421_hash NULL
85376 +_001422_hash dataflash_read_user_otp 3-2 14536 _001422_hash &_000207_hash
85377 +_001423_hash dccp_feat_register_sp 5 17914 _001423_hash NULL
85378 +_001424_hash dccp_setsockopt 5 60367 _001424_hash NULL
85379 +_001425_hash __dev_alloc_skb 1 28681 _001425_hash NULL
85380 +_001426_hash disk_expand_part_tbl 2 30561 _001426_hash NULL
85381 +_001427_hash diva_os_alloc_message_buffer 1 64568 _001427_hash NULL
85382 +_001428_hash diva_os_copy_to_user 4 48508 _001428_hash NULL
85383 +_001429_hash diva_os_malloc 2 16406 _001429_hash NULL
85384 +_001430_hash dmam_declare_coherent_memory 4-2 43679 _001430_hash NULL
85385 +_001431_hash dm_vcalloc 1-2 16814 _001431_hash NULL
85386 +_001433_hash dn_alloc_skb 2 6631 _001433_hash NULL
85387 +_001434_hash do_proc_readlink 3 14096 _001434_hash NULL
85388 +_001435_hash do_readlink 2 43518 _001435_hash NULL
85389 +_001436_hash __do_replace 5 37227 _001436_hash NULL
85390 +_001437_hash do_sigpending 2 9766 _001437_hash NULL
85391 +_001438_hash drbd_bm_resize 2 20522 _001438_hash NULL
85392 +_001439_hash drbd_setsockopt 5 16280 _001439_hash &_000383_hash
85393 +_001440_hash dump_midi 3 51040 _001440_hash NULL
85394 +_001441_hash ecryptfs_filldir 3 6622 _001441_hash NULL
85395 +_001442_hash ecryptfs_send_message 2 18322 _001442_hash NULL
85396 +_001443_hash ep0_read 3 38095 _001443_hash NULL
85397 +_001444_hash evdev_ioctl 2 22371 _001444_hash NULL
85398 +_001445_hash ext4_add_new_descs 3 19509 _001445_hash NULL
85399 +_001446_hash fat_ioctl_filldir 3 36621 _001446_hash NULL
85400 +_001447_hash _fc_frame_alloc 1 43568 _001447_hash NULL
85401 +_001448_hash fc_host_post_vendor_event 3 30903 _001448_hash NULL
85402 +_001449_hash fd_copyout 3 59323 _001449_hash NULL
85403 +_001450_hash f_hidg_read 3 6238 _001450_hash NULL
85404 +_001451_hash filldir 3 55137 _001451_hash NULL
85405 +_001452_hash filldir64 3 46469 _001452_hash NULL
85406 +_001453_hash find_skb 2 20431 _001453_hash NULL
85407 +_001454_hash from_buffer 3 18625 _001454_hash NULL
85408 +_001455_hash fsm_init 2 16134 _001455_hash NULL
85409 +_001456_hash fs_path_add 3 15648 _001456_hash NULL
85410 +_001457_hash fs_path_add_from_extent_buffer 4 27702 _001457_hash NULL
85411 +_001458_hash fuse_perform_write 4 18457 _001458_hash NULL
85412 +_001459_hash gem_alloc_skb 2 51715 _001459_hash NULL
85413 +_001460_hash generic_file_buffered_write 4 25464 _001460_hash NULL
85414 +_001461_hash gen_pool_add 3 21776 _001461_hash NULL
85415 +_001462_hash get_packet 3 41914 _001462_hash NULL
85416 +_001463_hash get_packet 3 5747 _001463_hash NULL
85417 +_001464_hash get_packet_pg 4 28023 _001464_hash NULL
85418 +_001465_hash get_skb 2 63008 _001465_hash NULL
85419 +_001466_hash get_subdir 3 62581 _001466_hash NULL
85420 +_001467_hash gsm_control_message 4 18209 _001467_hash NULL
85421 +_001468_hash gsm_control_modem 3 55303 _001468_hash NULL
85422 +_001469_hash gsm_control_rls 3 3353 _001469_hash NULL
85423 +_001470_hash handle_received_packet 3 22457 _001470_hash NULL
85424 +_001471_hash hash_setkey 3 48310 _001471_hash NULL
85425 +_001472_hash hdlcdrv_register 2 6792 _001472_hash NULL
85426 +_001473_hash hiddev_ioctl 2 36816 _001473_hash NULL
85427 +_001474_hash hid_input_report 4 32458 _001474_hash NULL
85428 +_001475_hash hidp_queue_report 3 1881 _001475_hash NULL
85429 +_001476_hash __hidp_send_ctrl_message 4 28303 _001476_hash NULL
85430 +_001477_hash hidraw_read 3 59650 _001477_hash &_001265_hash
85431 +_001478_hash HiSax_readstatus 2 15752 _001478_hash NULL
85432 +_001480_hash __hwahc_op_set_gtk 4 42038 _001480_hash NULL
85433 +_001481_hash __hwahc_op_set_ptk 5 36510 _001481_hash NULL
85434 +_001482_hash hycapi_rx_capipkt 3 11602 _001482_hash NULL
85435 +_001483_hash i2400m_net_rx 5 27170 _001483_hash NULL
85436 +_001484_hash ib_copy_to_udata 3 27525 _001484_hash NULL
85437 +_001485_hash idetape_chrdev_read 3 2097 _001485_hash NULL
85438 +_001486_hash ieee80211_alloc_hw 1 43829 _001486_hash NULL
85439 +_001487_hash ieee80211_bss_info_update 4 13991 _001487_hash NULL
85440 +_001488_hash igmpv3_newpack 2 35912 _001488_hash NULL
85441 +_001489_hash ilo_read 3 32531 _001489_hash NULL
85442 +_001490_hash init_map_ipmac 3-4 63896 _001490_hash NULL
85443 +_001492_hash init_tid_tabs 2-4-3 13252 _001492_hash NULL
85444 +_001495_hash iowarrior_read 3 53483 _001495_hash NULL
85445 +_001496_hash ip_options_get 4 56538 _001496_hash NULL
85446 +_001497_hash ipv6_getsockopt_sticky 5 56711 _001497_hash NULL
85447 +_001498_hash ipwireless_send_packet 4 8328 _001498_hash NULL
85448 +_001499_hash ipx_sendmsg 4 1362 _001499_hash NULL
85449 +_001500_hash irq_domain_add_linear 2 29236 _001500_hash NULL
85450 +_001501_hash iscsi_conn_setup 2 35159 _001501_hash NULL
85451 +_001502_hash iscsi_create_session 3 51647 _001502_hash NULL
85452 +_001503_hash iscsi_host_alloc 2 36671 _001503_hash NULL
85453 +_001504_hash iscsi_if_send_reply 7 52219 _001504_hash NULL
85454 +_001505_hash iscsi_offload_mesg 5 58425 _001505_hash NULL
85455 +_001506_hash iscsi_ping_comp_event 5 38263 _001506_hash NULL
85456 +_001507_hash iscsi_post_host_event 4 13473 _001507_hash NULL
85457 +_001508_hash iscsi_recv_pdu 4 16755 _001508_hash NULL
85458 +_001509_hash iscsi_session_setup 4-5 196 _001509_hash NULL
85459 +_001511_hash iscsit_find_cmd_from_itt_or_dump 3 17194 _003122_hash NULL nohasharray
85460 +_001512_hash isdn_net_ciscohdlck_alloc_skb 2 55209 _001951_hash NULL nohasharray
85461 +_001513_hash isdn_ppp_ccp_xmit_reset 6 63297 _001513_hash NULL
85462 +_001514_hash isdn_ppp_read 4 50356 _001514_hash NULL
85463 +_001515_hash isdn_ppp_skb_push 2 5236 _001515_hash NULL
85464 +_001516_hash isku_sysfs_read 6 58806 _001516_hash NULL
85465 +_001517_hash isku_sysfs_write 6 49767 _001517_hash NULL
85466 +_001520_hash jbd2_alloc 1 41359 _001520_hash NULL
85467 +_001521_hash jffs2_do_link 6 42048 _001521_hash NULL
85468 +_001522_hash jffs2_do_unlink 4 62020 _001522_hash NULL
85469 +_001523_hash jffs2_security_setxattr 4 62107 _001523_hash NULL
85470 +_001524_hash jffs2_trusted_setxattr 4 17048 _001524_hash NULL
85471 +_001525_hash jffs2_user_setxattr 4 10182 _001525_hash NULL
85472 +_001526_hash joydev_ioctl_common 2 49359 _001526_hash NULL
85473 +_001527_hash kernel_setsockopt 5 35913 _001527_hash NULL
85474 +_001528_hash keyctl_describe_key 3 36853 _001528_hash NULL
85475 +_001529_hash keyctl_get_security 3 64418 _001529_hash &_001192_hash
85476 +_001530_hash keyring_read 3 13438 _001530_hash NULL
85477 +_001531_hash kfifo_copy_to_user 3 20646 _001531_hash NULL
85478 +_001532_hash kmem_zalloc_large 1 56128 _001532_hash NULL
85479 +_001533_hash kmp_init 2 41373 _001533_hash NULL
85480 +_001534_hash koneplus_sysfs_write 6 35993 _001534_hash NULL
85481 +_001535_hash kvm_clear_guest_page 4 2308 _001535_hash NULL
85482 +_001536_hash kvm_read_nested_guest_page 5 13337 _001536_hash NULL
85483 +_001537_hash _l2_alloc_skb 1 11883 _001537_hash NULL
85484 +_001538_hash l2cap_create_basic_pdu 3 24869 _001538_hash &_001074_hash
85485 +_001539_hash l2cap_create_connless_pdu 3 37327 _001539_hash NULL
85486 +_001540_hash l2cap_create_iframe_pdu 3 40055 _001540_hash NULL
85487 +_001541_hash l3_alloc_skb 1 32289 _001541_hash NULL
85488 +_001542_hash __lgwrite 4 57669 _001542_hash NULL
85489 +_001543_hash libfc_host_alloc 2 7917 _001543_hash NULL
85490 +_001544_hash llc_alloc_frame 4 64366 _001544_hash NULL
85491 +_001545_hash llcp_sock_sendmsg 4 1092 _001545_hash NULL
85492 +_001546_hash mac_drv_rx_init 2 48898 _001546_hash NULL
85493 +_001547_hash macvtap_get_user 4 28185 _001547_hash NULL
85494 +_001548_hash mdc800_device_read 3 22896 _001548_hash NULL
85495 +_001549_hash memcpy_toiovec 3 54166 _001549_hash &_000892_hash
85496 +_001550_hash memcpy_toiovecend 3-4 19736 _001550_hash NULL
85497 +_001552_hash mempool_create 1 29437 _001552_hash NULL
85498 +_001553_hash mgmt_event 4 12810 _001553_hash NULL
85499 +_001554_hash mgt_set_varlen 4 60916 _001554_hash NULL
85500 +_001555_hash mI_alloc_skb 1 24770 _001555_hash NULL
85501 +_001556_hash mlx4_en_create_rx_ring 3 62498 _001556_hash NULL
85502 +_001557_hash mlx4_en_create_tx_ring 4 48501 _001557_hash NULL
85503 +_001558_hash mlx4_init_cmpt_table 3 11569 _001558_hash NULL
85504 +_001559_hash mon_bin_get_event 4 52863 _001559_hash NULL
85505 +_001560_hash mousedev_read 3 47123 _001560_hash NULL
85506 +_001561_hash move_addr_to_user 2 2868 _001561_hash NULL
85507 +_001562_hash mpihelp_mul 5-3 27805 _001562_hash NULL
85508 +_001564_hash mpi_set_buffer 3 65294 _001564_hash NULL
85509 +_001565_hash mptctl_ioctl 2 12355 _001565_hash NULL
85510 +_001566_hash msnd_fifo_alloc 2 23179 _001566_hash NULL
85511 +_001567_hash mtdswap_init 2 55719 _001567_hash NULL
85512 +_001568_hash mthca_alloc_resize_buf 3 60394 _001568_hash NULL
85513 +_001569_hash mthca_init_cq 2 60011 _001569_hash NULL
85514 +_001570_hash nci_skb_alloc 2 49757 _001570_hash NULL
85515 +_001571_hash neigh_hash_grow 2 17283 _001571_hash NULL
85516 +_001572_hash netdev_alloc_skb 2 62437 _001572_hash NULL
85517 +_001573_hash __netdev_alloc_skb_ip_align 2 55067 _001573_hash NULL
85518 +_001574_hash netlink_change_ngroups 2 16457 _001574_hash NULL
85519 +_001575_hash new_skb 1 21148 _001575_hash NULL
85520 +_001576_hash nfc_alloc_recv_skb 1 10244 _001576_hash NULL
85521 +_001577_hash nfcwilink_skb_alloc 1 16167 _001577_hash NULL
85522 +_001578_hash __nf_nat_mangle_tcp_packet 5-7 8190 _001578_hash NULL
85523 +_001580_hash nf_nat_mangle_udp_packet 5-7 13321 _001580_hash NULL
85524 +_001582_hash nfqnl_mangle 4-2 36226 _001582_hash NULL
85525 +_001583_hash nfs4_realloc_slot_table 2 22859 _001583_hash NULL
85526 +_001584_hash nfs_idmap_get_key 2 39616 _001584_hash NULL
85527 +_001585_hash nfs_readdata_alloc 2 65015 _001585_hash NULL
85528 +_001586_hash nfs_writedata_alloc 2 12133 _001586_hash NULL
85529 +_001587_hash nfulnl_alloc_skb 2 65207 _001587_hash NULL
85530 +_001588_hash ni65_alloc_mem 3 10664 _001588_hash NULL
85531 +_001589_hash nsm_get_handle 4 52089 _001589_hash NULL
85532 +_001590_hash ntfs_malloc_nofs 1 49572 _001590_hash NULL
85533 +_001591_hash ntfs_malloc_nofs_nofail 1 63631 _001591_hash NULL
85534 +_001592_hash nvme_create_queue 3 170 _001592_hash NULL
85535 +_001593_hash ocfs2_control_write 3 54737 _001593_hash NULL
85536 +_001595_hash orinoco_add_extscan_result 3 18207 _001595_hash NULL
85537 +_001596_hash osd_req_read_sg_kern 5 6378 _001596_hash NULL
85538 +_001597_hash osd_req_write_sg_kern 5 10514 _001597_hash NULL
85539 +_001599_hash override_release 2 52032 _001599_hash NULL
85540 +_001600_hash p9_client_read 5 19750 _001600_hash NULL
85541 +_001601_hash packet_snd 3 13634 _001601_hash NULL
85542 +_001602_hash pcbit_stat 2 27364 _001602_hash NULL
85543 +_001603_hash pcpu_extend_area_map 2 12589 _001603_hash NULL
85544 +_001604_hash pep_alloc_skb 3 46303 _001604_hash NULL
85545 +_001605_hash pg_read 3 17276 _001605_hash NULL
85546 +_001606_hash picolcd_debug_eeprom_read 3 14549 _001606_hash NULL
85547 +_001607_hash pkt_alloc_packet_data 1 37928 _001607_hash NULL
85548 +_001608_hash pmcraid_build_passthrough_ioadls 2 62034 _001608_hash NULL
85549 +_001609_hash pn_raw_send 2 54330 _001609_hash NULL
85550 +_001610_hash posix_clock_register 2 5662 _001610_hash NULL
85551 +_001611_hash printer_read 3 54851 _001611_hash NULL
85552 +_001612_hash __proc_file_read 3 54978 _001612_hash NULL
85553 +_001613_hash pskb_may_pull 2 22546 _001613_hash NULL
85554 +_001614_hash __pskb_pull 2 42602 _001614_hash NULL
85555 +_001615_hash ptp_read 4 63251 _001615_hash NULL
85556 +_001616_hash pt_read 3 49136 _001616_hash NULL
85557 +_001617_hash put_cmsg 4 36589 _001617_hash NULL
85558 +_001618_hash px_raw_event 4 49371 _001618_hash NULL
85559 +_001619_hash qla4xxx_post_aen_work 3 46953 _001619_hash NULL
85560 +_001620_hash qla4xxx_post_ping_evt_work 4 8074 _001819_hash NULL nohasharray
85561 +_001621_hash raid5_resize 2 63306 _001621_hash NULL
85562 +_001622_hash rawv6_sendmsg 4 20080 _001622_hash NULL
85563 +_001623_hash rds_message_map_pages 2 31487 _001623_hash NULL
85564 +_001624_hash rds_sendmsg 4 40976 _001624_hash NULL
85565 +_001625_hash read_flush 3 43851 _001625_hash NULL
85566 +_001626_hash read_profile 3 27859 _001626_hash NULL
85567 +_001627_hash read_vmcore 3 26501 _001627_hash NULL
85568 +_001628_hash redirected_tty_write 3 65297 _001628_hash NULL
85569 +_001629_hash refill_pool 2 19477 _001629_hash NULL
85570 +_001630_hash __register_chrdev 2-3 54223 _001630_hash NULL
85571 +_001632_hash regmap_raw_write 4 53803 _001632_hash NULL
85572 +_001633_hash reiserfs_allocate_list_bitmaps 3 21732 _001633_hash NULL
85573 +_001634_hash reiserfs_resize 2 34377 _001634_hash NULL
85574 +_001635_hash request_key_auth_read 3 24109 _001635_hash NULL
85575 +_001636_hash rfcomm_wmalloc 2 58090 _001636_hash NULL
85576 +_001637_hash rfkill_fop_read 3 54711 _001637_hash NULL
85577 +_001638_hash rng_dev_read 3 41581 _001638_hash NULL
85578 +_001639_hash roccat_read 3 41093 _001639_hash &_001034_hash
85579 +_001640_hash rx 4 57944 _001640_hash NULL
85580 +_001641_hash rxrpc_client_sendmsg 5 23236 _001641_hash NULL
85581 +_001642_hash rxrpc_kernel_send_data 3 60083 _001642_hash NULL
85582 +_001643_hash rxrpc_server_sendmsg 4 37331 _001643_hash NULL
85583 +_001644_hash savu_sysfs_write 6 42273 _001644_hash NULL
85584 +_001645_hash sco_sock_sendmsg 4 62542 _001645_hash NULL
85585 +_001646_hash scsi_nl_send_vendor_msg 5 16394 _001646_hash NULL
85586 +_001647_hash scsi_register 2 49094 _001647_hash NULL
85587 +_001648_hash sctp_datamsg_from_user 4 55342 _001648_hash NULL
85588 +_001649_hash sctp_getsockopt_events 2 3607 _001649_hash NULL
85589 +_001650_hash sctp_getsockopt_maxburst 2 42941 _001650_hash NULL
85590 +_001651_hash sctp_getsockopt_maxseg 2 10737 _001651_hash NULL
85591 +_001652_hash sctp_make_chunk 4 12986 _001652_hash NULL
85592 +_001653_hash sctpprobe_read 3 17741 _001653_hash NULL
85593 +_001654_hash sctp_tsnmap_mark 2 35929 _001654_hash NULL
85594 +_001655_hash sctp_ulpevent_new 1 33377 _001655_hash NULL
85595 +_001656_hash sdhci_alloc_host 2 7509 _001656_hash NULL
85596 +_001657_hash selinux_inode_post_setxattr 4 26037 _001657_hash NULL
85597 +_001658_hash selinux_inode_setsecurity 4 18148 _001658_hash NULL
85598 +_001659_hash selinux_inode_setxattr 4 10708 _001659_hash NULL
85599 +_001660_hash selinux_secctx_to_secid 2 63744 _001660_hash NULL
85600 +_001661_hash selinux_setprocattr 4 55611 _001661_hash NULL
85601 +_001662_hash sel_write_context 3 25726 _001662_hash &_001329_hash
85602 +_001663_hash send_command 4 10832 _001663_hash NULL
85603 +_001664_hash seq_copy_in_user 3 18543 _001664_hash NULL
85604 +_001665_hash seq_open_net 4 8968 _001779_hash NULL nohasharray
85605 +_001666_hash seq_open_private 3 61589 _001666_hash NULL
85606 +_001667_hash set_arg 3 42824 _001667_hash NULL
85607 +_001668_hash sg_read 3 25799 _001668_hash NULL
85608 +_001669_hash shash_async_setkey 3 10720 _003506_hash NULL nohasharray
85609 +_001670_hash shash_compat_setkey 3 12267 _001670_hash NULL
85610 +_001671_hash shmem_setxattr 4 55867 _001671_hash NULL
85611 +_001672_hash simple_read_from_buffer 2-5 55957 _001672_hash NULL
85612 +_001674_hash sisusb_clear_vram 2-3 57466 _001674_hash NULL
85613 +_001676_hash sisusbcon_do_font_op 9 52271 _001676_hash NULL
85614 +_001677_hash sisusb_copy_memory 4 35016 _001677_hash NULL
85615 +_001678_hash sisusb_write 3 44834 _001678_hash NULL
85616 +_001680_hash skb_cow 2 26138 _001680_hash NULL
85617 +_001681_hash skb_cow_head 2 52495 _001681_hash NULL
85618 +_001682_hash skb_make_writable 2 24783 _001682_hash NULL
85619 +_001683_hash skb_padto 2 50759 _001683_hash NULL
85620 +_001684_hash sk_stream_alloc_skb 2 57622 _001684_hash NULL
85621 +_001685_hash smk_write_access2 3 19170 _001685_hash NULL
85622 +_001686_hash smk_write_access 3 49561 _001686_hash NULL
85623 +_001687_hash snd_es1938_capture_copy 5 25930 _001687_hash NULL
85624 +_001688_hash snd_gus_dram_peek 4 9062 _001688_hash NULL
85625 +_001689_hash snd_hdsp_capture_copy 5 4011 _001689_hash NULL
85626 +_001690_hash snd_korg1212_copy_to 6 92 _001690_hash NULL
85627 +_001691_hash snd_opl4_mem_proc_read 5 63774 _001691_hash NULL
85628 +_001692_hash snd_pcm_oss_read1 3 63771 _001692_hash NULL
85629 +_001693_hash snd_pcm_plugin_alloc 2 12580 _001693_hash NULL
85630 +_001694_hash snd_rawmidi_kernel_read1 4 36740 _001694_hash NULL
85631 +_001695_hash snd_rme9652_capture_copy 5 10287 _001695_hash NULL
85632 +_001696_hash sock_alloc_send_pskb 2 21246 _001696_hash NULL
85633 +_001697_hash sock_rmalloc 2 59740 _002491_hash NULL nohasharray
85634 +_001698_hash sock_wmalloc 2 16472 _001698_hash NULL
85635 +_001699_hash solos_param_store 4 34755 _001699_hash NULL
85636 +_001702_hash srp_target_alloc 3 37288 _001702_hash NULL
85637 +_001703_hash store_ifalias 4 35088 _001703_hash NULL
85638 +_001704_hash store_msg 3 56417 _001704_hash NULL
85639 +_001705_hash str_to_user 2 11411 _001705_hash NULL
85640 +_001706_hash subbuf_read_actor 3 2071 _001706_hash NULL
85641 +_001707_hash sys_fgetxattr 4 25166 _001707_hash NULL
85642 +_001708_hash sys_gethostname 2 49698 _001708_hash NULL
85643 +_001709_hash sys_getxattr 4 37418 _001709_hash NULL
85644 +_001710_hash sys_init_module 2 36047 _001710_hash NULL
85645 +_001711_hash sys_kexec_load 2 14222 _001711_hash NULL
85646 +_001712_hash sys_lgetxattr 4 45531 _001712_hash NULL
85647 +_001713_hash syslog_print 2 307 _001713_hash NULL
85648 +_001714_hash sys_msgsnd 3 44537 _001714_hash &_000139_hash
85649 +_001715_hash sys_process_vm_readv 3-5 19090 _003104_hash NULL nohasharray
85650 +_001717_hash sys_process_vm_writev 3-5 4928 _001717_hash NULL
85651 +_001719_hash sys_pselect6 1 57449 _001719_hash NULL
85652 +_001720_hash sys_sched_getaffinity 2 60033 _001720_hash NULL
85653 +_001721_hash sys_setsockopt 5 35320 _001721_hash NULL
85654 +_001722_hash t3_init_l2t 1 8261 _001722_hash NULL
85655 +_001723_hash t4vf_pktgl_to_skb 2 39005 _001723_hash NULL
85656 +_001724_hash tcp_collapse 5-6 63294 _001724_hash NULL
85657 +_001726_hash tcp_sendmsg 4 30296 _001726_hash NULL
85658 +_001727_hash team_options_register 3 20091 _001727_hash NULL
85659 +_001728_hash tipc_buf_acquire 1 60437 _001728_hash NULL
85660 +_001729_hash tipc_cfg_reply_alloc 1 27606 _001729_hash NULL
85661 +_001730_hash tipc_send2name 6 16809 _001730_hash NULL
85662 +_001731_hash tipc_send2port 5 63935 _001731_hash NULL
85663 +_001732_hash tipc_send 4 51238 _001732_hash NULL
85664 +_001733_hash tnode_new 3 44757 _002769_hash NULL nohasharray
85665 +_001734_hash tomoyo_read_self 3 33539 _001734_hash NULL
85666 +_001735_hash tomoyo_update_domain 2 5498 _001735_hash NULL
85667 +_001736_hash tomoyo_update_policy 2 40458 _001736_hash NULL
85668 +_001737_hash tpm_read 3 50344 _001737_hash NULL
85669 +_001738_hash TSS_rawhmac 3 17486 _001738_hash NULL
85670 +_001739_hash __tty_buffer_request_room 2 27700 _001739_hash NULL
85671 +_001740_hash tun_get_user 4 39099 _001740_hash NULL
85672 +_001741_hash ubi_dump_flash 4 46381 _001741_hash NULL
85673 +_001742_hash ubi_io_write 4-5 15870 _003453_hash NULL nohasharray
85674 +_001744_hash udp_setsockopt 5 25985 _001744_hash NULL
85675 +_001745_hash udpv6_setsockopt 5 18487 _001745_hash NULL
85676 +_001746_hash uio_read 3 49300 _001746_hash NULL
85677 +_001747_hash ulog_alloc_skb 1 23427 _001747_hash NULL
85678 +_001748_hash unix_dgram_sendmsg 4 45699 _001748_hash NULL
85679 +_001749_hash unlink1 3 63059 _001749_hash NULL
85680 +_001751_hash usbdev_read 3 45114 _001751_hash NULL
85681 +_001752_hash usblp_ioctl 2 30203 _001752_hash NULL
85682 +_001753_hash usblp_read 3 57342 _003832_hash NULL nohasharray
85683 +_001754_hash usbtmc_read 3 32377 _001754_hash NULL
85684 +_001755_hash _usb_writeN_sync 4 31682 _001755_hash NULL
85685 +_001756_hash user_read 3 51881 _001756_hash NULL
85686 +_001757_hash vcs_read 3 8017 _001757_hash NULL
85687 +_001758_hash vdma_mem_alloc 1 6171 _001758_hash NULL
85688 +_001759_hash venus_create 4 20555 _001759_hash NULL
85689 +_001760_hash venus_link 5 32165 _001760_hash NULL
85690 +_001761_hash venus_lookup 4 8121 _001761_hash NULL
85691 +_001762_hash venus_mkdir 4 8967 _001762_hash NULL
85692 +_001763_hash venus_remove 4 59781 _001763_hash NULL
85693 +_001764_hash venus_rename 4-5 17707 _003784_hash NULL nohasharray
85694 +_001766_hash venus_rmdir 4 45564 _001766_hash NULL
85695 +_001767_hash venus_symlink 4-6 23570 _001767_hash NULL
85696 +_001769_hash vfs_readlink 3 54368 _001769_hash NULL
85697 +_001770_hash vfs_readv 3 38011 _001770_hash NULL
85698 +_001771_hash vfs_writev 3 25278 _001771_hash NULL
85699 +_001772_hash vga_arb_read 3 4886 _001772_hash NULL
85700 +_001773_hash vgacon_adjust_height 2 28124 _001773_hash NULL
85701 +_001774_hash vhci_put_user 4 12604 _001774_hash NULL
85702 +_001775_hash vhost_add_used_n 3 10760 _001775_hash NULL
85703 +_001776_hash virtnet_send_command 5-6 61993 _001776_hash NULL
85704 +_001778_hash vmbus_establish_gpadl 3 4495 _001778_hash NULL
85705 +_001779_hash vol_cdev_read 3 8968 _001779_hash &_001665_hash
85706 +_001780_hash wdm_read 3 6549 _001780_hash NULL
85707 +_001781_hash write_adapter_mem 3 3234 _001781_hash NULL
85708 +_001782_hash wusb_prf 7 54261 _001782_hash &_000065_hash
85709 +_001783_hash xdi_copy_to_user 4 48900 _001783_hash NULL
85710 +_001784_hash xfs_buf_associate_memory 3 17915 _001784_hash NULL
85711 +_001785_hash xfs_buf_get_maps 2 4581 _001785_hash NULL
85712 +_001786_hash xfs_buf_get_uncached 2 51477 _001786_hash NULL
85713 +_001787_hash xfs_buf_item_get_format 2 189 _001787_hash NULL
85714 +_001788_hash xfs_buf_map_from_irec 5 2368 _002641_hash NULL nohasharray
85715 +_001789_hash xfs_dir2_block_to_sf 3 37868 _001789_hash NULL
85716 +_001790_hash xfs_dir2_leaf_getdents 3 23841 _001790_hash NULL
85717 +_001791_hash xfs_dir2_sf_addname_hard 3 54254 _001791_hash NULL
85718 +_001792_hash xfs_efd_init 3 5463 _001792_hash NULL
85719 +_001793_hash xfs_efi_init 2 5476 _001793_hash NULL
85720 +_001794_hash xfs_iext_realloc_direct 2 20521 _001794_hash NULL
85721 +_001795_hash xfs_iext_realloc_indirect 2 59211 _001795_hash NULL
85722 +_001796_hash xfs_inumbers_fmt 3 12817 _001796_hash NULL
85723 +_001797_hash xhci_alloc_streams 5 37586 _001797_hash NULL
85724 +_001798_hash xlog_recover_add_to_cont_trans 4 44102 _001798_hash NULL
85725 +_001799_hash xz_dec_lzma2_create 2 36353 _002713_hash NULL nohasharray
85726 +_001800_hash _zd_iowrite32v_locked 3 44725 _001800_hash NULL
85727 +_001801_hash a2mp_chan_alloc_skb_cb 2 27159 _001801_hash NULL
85728 +_001802_hash aat2870_reg_read_file 3 12221 _001802_hash NULL
85729 +_001803_hash add_partition 2 55588 _001803_hash NULL
85730 +_001804_hash add_sctp_bind_addr 3 12269 _001804_hash NULL
85731 +_001805_hash _add_sg_continuation_descriptor 3 54721 _001805_hash NULL
85732 +_001806_hash afs_cell_lookup 2 8482 _001806_hash NULL
85733 +_001807_hash afs_send_simple_reply 3 63940 _001807_hash NULL
85734 +_001808_hash agp_allocate_memory_wrap 1 16576 _001808_hash NULL
85735 +_001809_hash __alloc_bootmem 1 31498 _001809_hash NULL
85736 +_001810_hash __alloc_bootmem_low 1 43423 _003425_hash NULL nohasharray
85737 +_001811_hash __alloc_bootmem_node_high 2 65076 _001811_hash NULL
85738 +_001812_hash alloc_cc770dev 1 48186 _001812_hash NULL
85739 +_001813_hash __alloc_ei_netdev 1 29338 _001813_hash NULL
85740 +_001814_hash __alloc_eip_netdev 1 51549 _001814_hash NULL
85741 +_001815_hash alloc_libipw 1 22708 _001815_hash NULL
85742 +_001816_hash _alloc_mISDN_skb 3 52232 _001816_hash NULL
85743 +_001817_hash alloc_pg_vec 2 8533 _001817_hash NULL
85744 +_001818_hash alloc_sja1000dev 1 17868 _001818_hash NULL
85745 +_001819_hash alloc_targets 2 8074 _001819_hash &_001620_hash
85746 +_001822_hash ath6kl_disconnect_timeout_read 3 3650 _001822_hash NULL
85747 +_001823_hash ath6kl_endpoint_stats_read 3 41554 _001823_hash NULL
85748 +_001824_hash ath6kl_fwlog_mask_read 3 2050 _001824_hash NULL
85749 +_001825_hash ath6kl_keepalive_read 3 44303 _001825_hash NULL
85750 +_001826_hash ath6kl_listen_int_read 3 10355 _001826_hash NULL
85751 +_001827_hash ath6kl_lrssi_roam_read 3 61022 _001827_hash NULL
85752 +_001828_hash ath6kl_regdump_read 3 14393 _001828_hash NULL
85753 +_001829_hash ath6kl_regread_read 3 25884 _001829_hash NULL
85754 +_001830_hash ath6kl_regwrite_read 3 48747 _001830_hash NULL
85755 +_001831_hash ath6kl_roam_table_read 3 26166 _001831_hash NULL
85756 +_001832_hash ath9k_debugfs_read_buf 3 25316 _001832_hash NULL
85757 +_001833_hash ath9k_multi_regread 4 65056 _001833_hash NULL
85758 +_001834_hash ath_rxbuf_alloc 2 24745 _001834_hash NULL
85759 +_001835_hash atk_debugfs_ggrp_read 3 29522 _001835_hash NULL
85760 +_001836_hash audit_log_n_untrustedstring 3 9548 _001836_hash NULL
85761 +_001837_hash ax25_send_frame 2 19964 _001837_hash NULL
85762 +_001838_hash b43_debugfs_read 3 24425 _001838_hash NULL
85763 +_001839_hash b43legacy_debugfs_read 3 2473 _001839_hash NULL
85764 +_001840_hash batadv_bla_is_backbone_gw 3 58488 _001840_hash NULL
85765 +_001841_hash batadv_check_management_packet 3 52993 _001841_hash NULL
85766 +_001842_hash batadv_check_unicast_packet 2 10866 _001842_hash NULL
85767 +_001843_hash batadv_interface_rx 4 8568 _001843_hash NULL
85768 +_001844_hash batadv_skb_head_push 2 11360 _001844_hash NULL
85769 +_001845_hash bchannel_get_rxbuf 2 37213 _001845_hash NULL
85770 +_001846_hash bcm_recvmsg 4 43992 _001846_hash NULL
85771 +_001847_hash bfad_debugfs_read 3 13119 _001847_hash NULL
85772 +_001848_hash bfad_debugfs_read_regrd 3 57830 _001848_hash NULL
85773 +_001849_hash blk_init_tags 1 30592 _001849_hash NULL
85774 +_001850_hash blk_queue_init_tags 2 44355 _001850_hash &_001022_hash
85775 +_001851_hash blk_rq_map_kern 4 47004 _001851_hash NULL
85776 +_001852_hash bm_entry_read 3 10976 _001852_hash NULL
85777 +_001853_hash bm_status_read 3 19583 _001853_hash NULL
85778 +_001854_hash bnad_debugfs_read 3 50665 _001854_hash NULL
85779 +_001855_hash bnad_debugfs_read_regrd 3 51308 _001855_hash NULL
85780 +_001856_hash bnx2i_send_nl_mesg 4 53353 _001856_hash NULL
85781 +_001857_hash brcmf_debugfs_sdio_counter_read 3 58369 _001857_hash NULL
85782 +_001858_hash brcmf_sdio_assert_info 4 52653 _001858_hash NULL
85783 +_001859_hash brcmf_sdio_dump_console 4 37455 _001859_hash NULL
85784 +_001860_hash brcmf_sdio_trap_info 4 48510 _001860_hash NULL
85785 +_001861_hash btmrvl_curpsmode_read 3 46939 _001861_hash NULL
85786 +_001862_hash btmrvl_gpiogap_read 3 4718 _001862_hash NULL
85787 +_001863_hash btmrvl_hscfgcmd_read 3 56303 _001863_hash NULL
85788 +_001864_hash btmrvl_hscmd_read 3 1614 _001864_hash NULL
85789 +_001865_hash btmrvl_hsmode_read 3 1647 _001865_hash NULL
85790 +_001866_hash btmrvl_hsstate_read 3 920 _001866_hash NULL
85791 +_001867_hash btmrvl_pscmd_read 3 24308 _001867_hash NULL
85792 +_001868_hash btmrvl_psmode_read 3 22395 _001868_hash NULL
85793 +_001869_hash btmrvl_psstate_read 3 50683 _001869_hash NULL
85794 +_001870_hash btmrvl_txdnldready_read 3 413 _001870_hash NULL
85795 +_001871_hash btrfs_add_link 5 9973 _001871_hash NULL
85796 +_001872_hash __btrfs_direct_write 4 22273 _001872_hash NULL
85797 +_001873_hash btrfs_discard_extent 2 38547 _001873_hash NULL
85798 +_001874_hash btrfs_file_aio_write 4 21520 _001874_hash NULL
85799 +_001875_hash btrfs_find_create_tree_block 3 55812 _001875_hash NULL
85800 +_001876_hash btrfsic_map_block 2 56751 _001876_hash NULL
85801 +_001877_hash cache_read_pipefs 3 47615 _001877_hash NULL
85802 +_001878_hash cache_read_procfs 3 52882 _001878_hash NULL
85803 +_001879_hash cache_write_pipefs 3 48270 _001879_hash NULL
85804 +_001880_hash cache_write_procfs 3 22491 _001880_hash NULL
85805 +_001881_hash caif_stream_recvmsg 4 13173 _001881_hash NULL
85806 +_001882_hash carl9170_alloc 1 27 _001882_hash NULL
85807 +_001883_hash carl9170_debugfs_read 3 47738 _001883_hash NULL
85808 +_001884_hash ceph_msgpool_init 4 34599 _001884_hash NULL
85809 +_001885_hash cfpkt_add_trail 3 27260 _001885_hash NULL
85810 +_001886_hash cfpkt_create 1 18197 _001886_hash NULL
85811 +_001887_hash cfpkt_pad_trail 2 55511 _003606_hash NULL nohasharray
85812 +_001888_hash cfpkt_split 2 47541 _001888_hash NULL
85813 +_001889_hash cgroup_read_s64 5 19570 _001889_hash NULL
85814 +_001890_hash cgroup_read_u64 5 45532 _001890_hash NULL
85815 +_001891_hash channel_type_read 3 47308 _001891_hash NULL
85816 +_001892_hash check_header 2 56930 _001892_hash NULL
85817 +_001893_hash codec_list_read_file 3 24910 _001893_hash NULL
85818 +_001894_hash configfs_read_file 3 1683 _001894_hash NULL
85819 +_001895_hash console_store 4 36007 _001895_hash NULL
85820 +_001896_hash cpuset_common_file_read 5 8800 _001896_hash NULL
85821 +_001897_hash create_subvol 4 30836 _001897_hash NULL
85822 +_001898_hash cxio_hal_init_resource 2-7-6 29771 _001898_hash &_000295_hash
85823 +_001901_hash cxio_hal_init_rhdl_resource 1 25104 _001901_hash NULL
85824 +_001902_hash dai_list_read_file 3 25421 _001902_hash NULL
85825 +_001903_hash dapm_bias_read_file 3 64715 _001903_hash NULL
85826 +_001904_hash dapm_widget_power_read_file 3 59950 _001983_hash NULL nohasharray
85827 +_001907_hash dbgfs_frame 3 45917 _001907_hash NULL
85828 +_001908_hash dbgfs_state 3 38894 _001908_hash NULL
85829 +_001909_hash dccp_manip_pkt 2 30229 _001909_hash NULL
85830 +_001910_hash ddp_ppod_write_idata 5 25610 _001910_hash NULL
85831 +_001911_hash debugfs_read 3 62535 _001911_hash NULL
85832 +_001912_hash debug_output 3 18575 _001912_hash NULL
85833 +_001913_hash debug_read 3 19322 _001913_hash NULL
85834 +_001914_hash dev_alloc_skb 1 19517 _001914_hash &_001366_hash
85835 +_001915_hash dfs_file_read 3 18116 _001915_hash NULL
85836 +_001916_hash diva_alloc_dma_map 2 23798 _001916_hash NULL
85837 +_001917_hash diva_xdi_write 4 63975 _001917_hash NULL
85838 +_001918_hash dma_memcpy_pg_to_iovec 6 1725 _001918_hash NULL
85839 +_001919_hash dma_memcpy_to_iovec 5 12173 _001919_hash NULL
85840 +_001920_hash dma_show_regs 3 35266 _001920_hash NULL
85841 +_001921_hash dm_exception_table_init 2 39645 _001921_hash &_001149_hash
85842 +_001922_hash dn_nsp_do_disc 2-6 49474 _001922_hash NULL
85843 +_001924_hash dn_recvmsg 4 17213 _001924_hash NULL
85844 +_001925_hash dns_resolver_read 3 54658 _001925_hash NULL
85845 +_001926_hash do_msgrcv 4 5590 _001926_hash NULL
85846 +_001927_hash do_syslog 3 56807 _001927_hash NULL
85847 +_001928_hash dpcm_state_read_file 3 65489 _001928_hash NULL
85848 +_001929_hash dsp_cmx_send_member 2 15625 _001929_hash NULL
85849 +_001930_hash fallback_on_nodma_alloc 2 35332 _001930_hash NULL
85850 +_001931_hash fc_frame_alloc 2 1596 _001931_hash NULL
85851 +_001932_hash fc_frame_alloc_fill 2 59394 _001932_hash NULL
85852 +_001933_hash filter_read 3 61692 _001933_hash NULL
85853 +_001934_hash __finish_unordered_dir 4 33198 _001934_hash NULL
85854 +_001935_hash format_devstat_counter 3 32550 _001935_hash NULL
85855 +_001936_hash fragmentation_threshold_read 3 61718 _001936_hash NULL
85856 +_001937_hash fuse_conn_limit_read 3 20084 _001937_hash NULL
85857 +_001938_hash fuse_conn_waiting_read 3 49762 _001938_hash NULL
85858 +_001939_hash fuse_file_aio_write 4 46399 _001939_hash NULL
85859 +_001940_hash generic_readlink 3 32654 _001940_hash NULL
85860 +_001941_hash gre_manip_pkt 2 38785 _001941_hash NULL
85861 +_001942_hash handle_eviocgbit 3 44193 _001942_hash NULL
85862 +_001943_hash handle_response 5 55951 _001943_hash NULL
85863 +_001944_hash handle_response_icmp 7 39574 _001944_hash NULL
85864 +_001945_hash hash_recvmsg 4 50924 _001945_hash NULL
85865 +_001946_hash hci_send_cmd 3 43810 _001946_hash NULL
85866 +_001947_hash hci_si_event 3 1404 _001947_hash NULL
85867 +_001948_hash help 4 14971 _001948_hash NULL
85868 +_001949_hash hfcpci_empty_bfifo 4 62323 _001949_hash NULL
85869 +_001950_hash hidp_send_ctrl_message 4 43702 _001950_hash NULL
85870 +_001951_hash ht40allow_map_read 3 55209 _001951_hash &_001512_hash
85871 +_001952_hash hwflags_read 3 52318 _001952_hash NULL
85872 +_001953_hash hysdn_conf_read 3 42324 _001953_hash NULL
85873 +_001954_hash hysdn_sched_rx 3 60533 _001954_hash NULL
85874 +_001955_hash i2400m_rx_stats_read 3 57706 _001955_hash NULL
85875 +_001956_hash i2400m_tx_stats_read 3 28527 _001956_hash NULL
85876 +_001957_hash icmp_manip_pkt 2 48801 _001957_hash NULL
85877 +_001958_hash idmouse_read 3 63374 _001958_hash NULL
85878 +_001959_hash ieee80211_if_read 3 6785 _001959_hash NULL
85879 +_001960_hash ieee80211_rx_bss_info 3 61630 _001960_hash NULL
85880 +_001961_hash ikconfig_read_current 3 1658 _001961_hash NULL
85881 +_001962_hash il3945_sta_dbgfs_stats_table_read 3 48802 _001962_hash NULL
85882 +_001963_hash il3945_ucode_general_stats_read 3 46111 _001963_hash NULL
85883 +_001964_hash il3945_ucode_rx_stats_read 3 3048 _001964_hash NULL
85884 +_001965_hash il3945_ucode_tx_stats_read 3 36016 _001965_hash NULL
85885 +_001966_hash il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 _001966_hash NULL
85886 +_001967_hash il4965_rs_sta_dbgfs_scale_table_read 3 38564 _001967_hash NULL
85887 +_001968_hash il4965_rs_sta_dbgfs_stats_table_read 3 49206 _001968_hash NULL
85888 +_001969_hash il4965_ucode_general_stats_read 3 56277 _001969_hash NULL
85889 +_001970_hash il4965_ucode_rx_stats_read 3 61948 _001970_hash NULL
85890 +_001971_hash il4965_ucode_tx_stats_read 3 12064 _001971_hash NULL
85891 +_001972_hash il_dbgfs_chain_noise_read 3 38044 _001972_hash NULL
85892 +_001973_hash il_dbgfs_channels_read 3 25005 _001973_hash NULL
85893 +_001974_hash il_dbgfs_disable_ht40_read 3 42386 _001974_hash NULL
85894 +_001975_hash il_dbgfs_fh_reg_read 3 40993 _001975_hash NULL
85895 +_001976_hash il_dbgfs_force_reset_read 3 57517 _001976_hash NULL
85896 +_001977_hash il_dbgfs_interrupt_read 3 3351 _001977_hash NULL
85897 +_001978_hash il_dbgfs_missed_beacon_read 3 59956 _001978_hash NULL
85898 +_001979_hash il_dbgfs_nvm_read 3 12288 _001979_hash NULL
85899 +_001980_hash il_dbgfs_power_save_status_read 3 43165 _001980_hash NULL
85900 +_001981_hash il_dbgfs_qos_read 3 33615 _001981_hash NULL
85901 +_001982_hash il_dbgfs_rxon_filter_flags_read 3 19281 _001982_hash NULL
85902 +_001983_hash il_dbgfs_rxon_flags_read 3 59950 _001983_hash &_001904_hash
85903 +_001984_hash il_dbgfs_rx_queue_read 3 11221 _001984_hash NULL
85904 +_001985_hash il_dbgfs_rx_stats_read 3 15243 _001985_hash NULL
85905 +_001986_hash il_dbgfs_sensitivity_read 3 2370 _001986_hash NULL
85906 +_001987_hash il_dbgfs_sram_read 3 62296 _001987_hash NULL
85907 +_001988_hash il_dbgfs_stations_read 3 21532 _001988_hash NULL
85908 +_001989_hash il_dbgfs_status_read 3 58388 _001989_hash NULL
85909 +_001990_hash il_dbgfs_tx_queue_read 3 55668 _001990_hash NULL
85910 +_001991_hash il_dbgfs_tx_stats_read 3 32913 _001991_hash NULL
85911 +_001992_hash ima_show_htable_value 2 57136 _001992_hash NULL
85912 +_001994_hash intel_fake_agp_alloc_by_type 1 1 _001994_hash NULL
85913 +_001995_hash ip4ip6_err 5 36772 _001995_hash NULL
85914 +_001996_hash ip6_append_data 4-5 36490 _003601_hash NULL nohasharray
85915 +_001997_hash ip6ip6_err 5 18308 _001997_hash NULL
85916 +_001998_hash __ip_append_data 7-8 36191 _001998_hash NULL
85917 +_001999_hash ip_vs_icmp_xmit 4 59624 _001999_hash NULL
85918 +_002000_hash ip_vs_icmp_xmit_v6 4 20464 _002000_hash NULL
85919 +_002001_hash ipw_write 3 59807 _002001_hash NULL
85920 +_002002_hash irda_recvmsg_stream 4 35280 _002002_hash NULL
85921 +_002003_hash irq_domain_add_simple 2 46734 _002003_hash NULL
85922 +_002004_hash __iscsi_complete_pdu 4 10726 _002004_hash NULL
85923 +_002005_hash iscsi_nop_out_rsp 4 51117 _002005_hash NULL
85924 +_002006_hash iscsi_tcp_conn_setup 2 16376 _002006_hash NULL
85925 +_002007_hash iwl_dbgfs_bt_traffic_read 3 35534 _002007_hash NULL
85926 +_002008_hash iwl_dbgfs_calib_disabled_read 3 22649 _002008_hash NULL
85927 +_002009_hash iwl_dbgfs_chain_noise_read 3 46355 _002009_hash NULL
85928 +_002010_hash iwl_dbgfs_channels_read 3 6784 _002010_hash NULL
85929 +_002011_hash iwl_dbgfs_current_sleep_command_read 3 2081 _002011_hash NULL
85930 +_002012_hash iwl_dbgfs_disable_ht40_read 3 35761 _002012_hash NULL
85931 +_002013_hash iwl_dbgfs_fh_reg_read 3 879 _002013_hash &_000406_hash
85932 +_002014_hash iwl_dbgfs_interrupt_read 3 23574 _002014_hash NULL
85933 +_002015_hash iwl_dbgfs_log_event_read 3 2107 _002015_hash NULL
85934 +_002016_hash iwl_dbgfs_missed_beacon_read 3 50584 _002016_hash NULL
85935 +_002017_hash iwl_dbgfs_nvm_read 3 23845 _002017_hash NULL
85936 +_002018_hash iwl_dbgfs_plcp_delta_read 3 55407 _002018_hash NULL
85937 +_002019_hash iwl_dbgfs_power_save_status_read 3 54392 _002019_hash NULL
85938 +_002020_hash iwl_dbgfs_protection_mode_read 3 13943 _002020_hash NULL
85939 +_002021_hash iwl_dbgfs_qos_read 3 11753 _002021_hash NULL
85940 +_002022_hash iwl_dbgfs_reply_tx_error_read 3 19205 _002022_hash NULL
85941 +_002023_hash iwl_dbgfs_rf_reset_read 3 26512 _002023_hash NULL
85942 +_002024_hash iwl_dbgfs_rx_handlers_read 3 18708 _002024_hash NULL
85943 +_002025_hash iwl_dbgfs_rxon_filter_flags_read 3 28832 _002025_hash NULL
85944 +_002026_hash iwl_dbgfs_rxon_flags_read 3 20795 _002026_hash NULL
85945 +_002027_hash iwl_dbgfs_rx_queue_read 3 19943 _002027_hash NULL
85946 +_002028_hash iwl_dbgfs_sensitivity_read 3 63116 _002731_hash NULL nohasharray
85947 +_002029_hash iwl_dbgfs_sleep_level_override_read 3 3038 _002029_hash NULL
85948 +_002030_hash iwl_dbgfs_sram_read 3 44505 _002030_hash NULL
85949 +_002031_hash iwl_dbgfs_stations_read 3 9309 _002031_hash NULL
85950 +_002032_hash iwl_dbgfs_status_read 3 5171 _002032_hash NULL
85951 +_002033_hash iwl_dbgfs_temperature_read 3 29224 _002033_hash NULL
85952 +_002034_hash iwl_dbgfs_thermal_throttling_read 3 38779 _002034_hash NULL
85953 +_002035_hash iwl_dbgfs_tx_queue_read 3 4635 _002035_hash NULL
85954 +_002036_hash iwl_dbgfs_ucode_bt_stats_read 3 42820 _002036_hash NULL
85955 +_002037_hash iwl_dbgfs_ucode_general_stats_read 3 49199 _002037_hash NULL
85956 +_002038_hash iwl_dbgfs_ucode_rx_stats_read 3 58023 _002038_hash NULL
85957 +_002039_hash iwl_dbgfs_ucode_tracing_read 3 47983 _002039_hash &_000356_hash
85958 +_002040_hash iwl_dbgfs_ucode_tx_stats_read 3 31611 _002040_hash NULL
85959 +_002041_hash iwl_dbgfs_wowlan_sram_read 3 540 _002041_hash NULL
85960 +_002042_hash joydev_ioctl 2 33343 _002042_hash NULL
85961 +_002043_hash kernel_readv 3 35617 _002043_hash NULL
85962 +_002044_hash key_algorithm_read 3 57946 _002044_hash NULL
85963 +_002045_hash key_icverrors_read 3 20895 _002045_hash NULL
85964 +_002046_hash key_key_read 3 3241 _002046_hash NULL
85965 +_002047_hash key_replays_read 3 62746 _002047_hash NULL
85966 +_002048_hash key_rx_spec_read 3 12736 _002048_hash NULL
85967 +_002049_hash key_tx_spec_read 3 4862 _002049_hash NULL
85968 +_002050_hash __kfifo_to_user 3 36555 _002568_hash NULL nohasharray
85969 +_002051_hash __kfifo_to_user_r 3 39123 _002051_hash NULL
85970 +_002052_hash kmem_zalloc_greedy 2-3 65268 _002052_hash NULL
85971 +_002054_hash l1oip_socket_recv 6 56537 _002054_hash NULL
85972 +_002055_hash l2cap_build_cmd 4 48676 _002055_hash NULL
85973 +_002056_hash l2cap_chan_send 3 49995 _002056_hash NULL
85974 +_002057_hash l2cap_segment_sdu 4 48772 _002057_hash NULL
85975 +_002058_hash l2down_create 4 21755 _002058_hash NULL
85976 +_002059_hash l2tp_xmit_skb 3 42672 _002059_hash NULL
85977 +_002060_hash l2up_create 3 6430 _002060_hash NULL
85978 +_002061_hash lbs_debugfs_read 3 30721 _002061_hash NULL
85979 +_002062_hash lbs_dev_info 3 51023 _002062_hash NULL
85980 +_002063_hash lbs_host_sleep_read 3 31013 _002063_hash NULL
85981 +_002064_hash lbs_rdbbp_read 3 45805 _002064_hash NULL
85982 +_002065_hash lbs_rdmac_read 3 418 _002065_hash NULL
85983 +_002066_hash lbs_rdrf_read 3 41431 _002066_hash NULL
85984 +_002067_hash lbs_sleepparams_read 3 10840 _002067_hash NULL
85985 +_002068_hash lbs_threshold_read 5 21046 _002068_hash NULL
85986 +_002069_hash ldisc_receive 4 41516 _002069_hash NULL
85987 +_002070_hash libfc_vport_create 2 4415 _002070_hash NULL
85988 +_002073_hash lkdtm_debugfs_read 3 45752 _002073_hash NULL
85989 +_002074_hash llcp_sock_recvmsg 4 13556 _002074_hash NULL
85990 +_002075_hash long_retry_limit_read 3 59766 _002075_hash NULL
85991 +_002076_hash lpfc_debugfs_dif_err_read 3 36303 _002076_hash NULL
85992 +_002077_hash lpfc_debugfs_read 3 16566 _002077_hash NULL
85993 +_002078_hash lpfc_idiag_baracc_read 3 58466 _002972_hash NULL nohasharray
85994 +_002079_hash lpfc_idiag_ctlacc_read 3 33943 _002079_hash NULL
85995 +_002080_hash lpfc_idiag_drbacc_read 3 15948 _002080_hash NULL
85996 +_002081_hash lpfc_idiag_extacc_read 3 48301 _002081_hash NULL
85997 +_002082_hash lpfc_idiag_mbxacc_read 3 28061 _002082_hash NULL
85998 +_002083_hash lpfc_idiag_pcicfg_read 3 50334 _002083_hash NULL
85999 +_002084_hash lpfc_idiag_queacc_read 3 13950 _002084_hash NULL
86000 +_002085_hash lpfc_idiag_queinfo_read 3 55662 _002085_hash NULL
86001 +_002086_hash lro_gen_skb 6 2644 _002086_hash NULL
86002 +_002087_hash mac80211_format_buffer 2 41010 _002087_hash NULL
86003 +_002088_hash macvtap_alloc_skb 2-4-3 50629 _002088_hash NULL
86004 +_002091_hash macvtap_put_user 4 55609 _002091_hash NULL
86005 +_002092_hash macvtap_sendmsg 4 30629 _002092_hash NULL
86006 +_002093_hash mangle_packet 6-8 27864 _002093_hash NULL
86007 +_002095_hash manip_pkt 3 7741 _002095_hash NULL
86008 +_002096_hash mempool_create_kmalloc_pool 1 41650 _002096_hash NULL
86009 +_002097_hash mempool_create_page_pool 1 30189 _002097_hash NULL
86010 +_002098_hash mempool_create_slab_pool 1 62907 _002098_hash NULL
86011 +_002099_hash mgmt_device_found 10 14146 _002099_hash NULL
86012 +_002100_hash minstrel_stats_read 3 17290 _002100_hash NULL
86013 +_002101_hash mmc_ext_csd_read 3 13205 _002101_hash NULL
86014 +_002102_hash mon_bin_read 3 6841 _002102_hash NULL
86015 +_002103_hash mon_stat_read 3 25238 _002103_hash NULL
86016 +_002105_hash mqueue_read_file 3 6228 _002105_hash NULL
86017 +_002106_hash mwifiex_debug_read 3 53074 _002106_hash NULL
86018 +_002107_hash mwifiex_getlog_read 3 54269 _002107_hash NULL
86019 +_002108_hash mwifiex_info_read 3 53447 _002108_hash NULL
86020 +_002109_hash mwifiex_rdeeprom_read 3 51429 _002109_hash NULL
86021 +_002110_hash mwifiex_regrdwr_read 3 34472 _002110_hash NULL
86022 +_002111_hash named_prepare_buf 2 24532 _002111_hash NULL
86023 +_002112_hash nci_send_cmd 3 58206 _002112_hash NULL
86024 +_002113_hash netdev_alloc_skb_ip_align 2 40811 _002113_hash NULL
86025 +_002114_hash netpoll_send_udp 3 58955 _002114_hash NULL
86026 +_002115_hash nfcwilink_send_bts_cmd 3 10802 _002115_hash NULL
86027 +_002116_hash nf_nat_mangle_tcp_packet 5-7 8643 _002116_hash NULL
86028 +_002119_hash nfsd_vfs_read 6 62605 _002616_hash NULL nohasharray
86029 +_002120_hash nfsd_vfs_write 6 54577 _002120_hash NULL
86030 +_002121_hash nfs_idmap_lookup_id 2 10660 _002121_hash NULL
86031 +_002122_hash ntfs_rl_realloc 3 56831 _002122_hash &_000370_hash
86032 +_002123_hash ntfs_rl_realloc_nofail 3 32173 _002123_hash NULL
86033 +_002124_hash o2hb_debug_read 3 37851 _002124_hash NULL
86034 +_002125_hash o2net_debug_read 3 52105 _002125_hash NULL
86035 +_002126_hash ocfs2_control_read 3 56405 _002126_hash NULL
86036 +_002127_hash ocfs2_debug_read 3 14507 _002127_hash NULL
86037 +_002128_hash oom_adjust_read 3 25127 _002128_hash NULL
86038 +_002129_hash oom_score_adj_read 3 39921 _002426_hash NULL nohasharray
86039 +_002130_hash oprofilefs_str_to_user 3 42182 _002130_hash NULL
86040 +_002131_hash oprofilefs_ulong_to_user 3 11582 _002131_hash NULL
86041 +_002132_hash osd_req_add_get_attr_list 3 49278 _002132_hash NULL
86042 +_002133_hash _osd_req_list_objects 6 4204 _002133_hash NULL
86043 +_002134_hash osd_req_read_kern 5 59990 _002134_hash NULL
86044 +_002135_hash osd_req_write_kern 5 53486 _002135_hash NULL
86045 +_002136_hash osst_read 3 40237 _002136_hash NULL
86046 +_002137_hash p54_alloc_skb 3 34366 _002137_hash &_000485_hash
86047 +_002138_hash p54_init_common 1 23850 _002138_hash NULL
86048 +_002139_hash packet_alloc_skb 2-5-4 62602 _002139_hash NULL
86049 +_002142_hash packet_sendmsg 4 24954 _002142_hash NULL
86050 +_002143_hash page_readlink 3 23346 _002143_hash NULL
86051 +_002144_hash pcf50633_write_block 3 2124 _002144_hash NULL
86052 +_002145_hash pcpu_alloc_alloc_info 1-2 45813 _002145_hash NULL
86053 +_002147_hash pep_indicate 5 38611 _002147_hash NULL
86054 +_002148_hash pep_reply 5 50582 _002148_hash NULL
86055 +_002149_hash pipe_handler_request 5 50774 _003582_hash NULL nohasharray
86056 +_002150_hash platform_list_read_file 3 34734 _002150_hash NULL
86057 +_002151_hash pm860x_bulk_write 3 43875 _002151_hash NULL
86058 +_002152_hash pm_qos_power_read 3 55891 _002152_hash NULL
86059 +_002153_hash port_show_regs 3 5904 _002153_hash NULL
86060 +_002154_hash proc_coredump_filter_read 3 39153 _002154_hash NULL
86061 +_002155_hash proc_fdinfo_read 3 62043 _002155_hash NULL
86062 +_002156_hash proc_file_read 3 53905 _002156_hash NULL
86063 +_002157_hash proc_info_read 3 63344 _002157_hash NULL
86064 +_002158_hash proc_loginuid_read 3 15631 _002158_hash NULL
86065 +_002159_hash proc_pid_attr_read 3 10173 _002159_hash NULL
86066 +_002160_hash proc_pid_readlink 3 52186 _002160_hash NULL
86067 +_002161_hash proc_read 3 43614 _002161_hash NULL
86068 +_002162_hash proc_self_readlink 3 38094 _002162_hash NULL
86069 +_002163_hash proc_sessionid_read 3 6911 _002299_hash NULL nohasharray
86070 +_002164_hash provide_user_output 3 41105 _002164_hash NULL
86071 +_002165_hash pskb_network_may_pull 2 35336 _002165_hash NULL
86072 +_002166_hash pskb_pull 2 65005 _002166_hash NULL
86073 +_002167_hash pstore_file_read 3 57288 _002167_hash NULL
86074 +_002168_hash ql_process_mac_rx_page 4 15543 _002168_hash NULL
86075 +_002169_hash ql_process_mac_rx_skb 4 6689 _002169_hash NULL
86076 +_002170_hash queues_read 3 24877 _002170_hash NULL
86077 +_002171_hash raw_recvmsg 4 17277 _002171_hash NULL
86078 +_002172_hash rcname_read 3 25919 _002172_hash NULL
86079 +_002173_hash read_4k_modal_eeprom 3 30212 _002173_hash NULL
86080 +_002174_hash read_9287_modal_eeprom 3 59327 _002174_hash NULL
86081 +_002175_hash reada_find_extent 2 63486 _002175_hash NULL
86082 +_002176_hash read_def_modal_eeprom 3 14041 _002176_hash NULL
86083 +_002177_hash read_enabled_file_bool 3 37744 _002177_hash NULL
86084 +_002178_hash read_file_ani 3 23161 _002178_hash NULL
86085 +_002179_hash read_file_antenna 3 13574 _002179_hash NULL
86086 +_002180_hash read_file_base_eeprom 3 42168 _002180_hash NULL
86087 +_002181_hash read_file_beacon 3 32595 _002181_hash NULL
86088 +_002182_hash read_file_blob 3 57406 _002182_hash NULL
86089 +_002183_hash read_file_bool 3 4180 _002183_hash NULL
86090 +_002184_hash read_file_credit_dist_stats 3 54367 _002184_hash NULL
86091 +_002185_hash read_file_debug 3 58256 _002185_hash NULL
86092 +_002186_hash read_file_disable_ani 3 6536 _002186_hash NULL
86093 +_002187_hash read_file_dma 3 9530 _002187_hash NULL
86094 +_002188_hash read_file_dump_nfcal 3 18766 _002188_hash NULL
86095 +_002189_hash read_file_frameerrors 3 64001 _002189_hash NULL
86096 +_002190_hash read_file_interrupt 3 61742 _002197_hash NULL nohasharray
86097 +_002191_hash read_file_misc 3 9948 _002191_hash NULL
86098 +_002192_hash read_file_modal_eeprom 3 39909 _002192_hash NULL
86099 +_002193_hash read_file_queue 3 40895 _002193_hash NULL
86100 +_002194_hash read_file_rcstat 3 22854 _002194_hash NULL
86101 +_002195_hash read_file_recv 3 48232 _002195_hash NULL
86102 +_002196_hash read_file_regidx 3 33370 _002196_hash NULL
86103 +_002197_hash read_file_regval 3 61742 _002197_hash &_002190_hash
86104 +_002198_hash read_file_reset 3 52310 _002198_hash NULL
86105 +_002199_hash read_file_rx_chainmask 3 41605 _002199_hash NULL
86106 +_002200_hash read_file_slot 3 50111 _002200_hash NULL
86107 +_002201_hash read_file_stations 3 35795 _002201_hash NULL
86108 +_002202_hash read_file_tgt_int_stats 3 20697 _002202_hash NULL
86109 +_002203_hash read_file_tgt_rx_stats 3 33944 _002203_hash NULL
86110 +_002204_hash read_file_tgt_stats 3 8959 _002204_hash NULL
86111 +_002205_hash read_file_tgt_tx_stats 3 51847 _002205_hash NULL
86112 +_002206_hash read_file_tx_chainmask 3 3829 _002206_hash NULL
86113 +_002207_hash read_file_war_stats 3 292 _002207_hash NULL
86114 +_002208_hash read_file_xmit 3 21487 _002208_hash NULL
86115 +_002209_hash read_flush_pipefs 3 20171 _002209_hash NULL
86116 +_002210_hash read_flush_procfs 3 27642 _002210_hash NULL
86117 +_002211_hash read_from_oldmem 2 3337 _002211_hash NULL
86118 +_002212_hash read_oldmem 3 55658 _002212_hash NULL
86119 +_002213_hash receive_packet 2 12367 _002213_hash NULL
86120 +_002214_hash regmap_name_read_file 3 39379 _002214_hash NULL
86121 +_002215_hash repair_io_failure 4 4815 _002215_hash NULL
86122 +_002216_hash request_key_and_link 4 42693 _002216_hash NULL
86123 +_002217_hash res_counter_read 4 33499 _002217_hash NULL
86124 +_002218_hash rfcomm_tty_write 3 51603 _002218_hash NULL
86125 +_002219_hash rs_sta_dbgfs_rate_scale_data_read 3 47165 _002219_hash NULL
86126 +_002220_hash rs_sta_dbgfs_scale_table_read 3 40262 _002220_hash NULL
86127 +_002221_hash rs_sta_dbgfs_stats_table_read 3 56573 _002221_hash NULL
86128 +_002222_hash rts_threshold_read 3 44384 _002222_hash NULL
86129 +_002223_hash rxrpc_sendmsg 4 29049 _002223_hash NULL
86130 +_002224_hash scrub_setup_recheck_block 3-4 56245 _002224_hash NULL
86131 +_002226_hash scsi_adjust_queue_depth 3 12802 _002226_hash NULL
86132 +_002227_hash sctp_make_abort 3 34459 _002227_hash NULL
86133 +_002228_hash sctp_make_asconf 3 4078 _002228_hash NULL
86134 +_002229_hash sctp_make_asconf_ack 3 31726 _002229_hash NULL
86135 +_002230_hash sctp_make_datafrag_empty 3 34737 _002230_hash NULL
86136 +_002231_hash sctp_make_fwdtsn 3 53265 _002231_hash NULL
86137 +_002232_hash sctp_make_heartbeat_ack 4 34411 _002232_hash NULL
86138 +_002233_hash sctp_make_init 4 58401 _002233_hash NULL
86139 +_002234_hash sctp_make_init_ack 4 3335 _002234_hash NULL
86140 +_002235_hash sctp_make_op_error_space 3 5528 _002235_hash NULL
86141 +_002236_hash sctp_manip_pkt 2 40620 _002236_hash NULL
86142 +_002237_hash selinux_inode_notifysecctx 3 36896 _002237_hash NULL
86143 +_002238_hash sel_read_avc_cache_threshold 3 33942 _002238_hash NULL
86144 +_002239_hash sel_read_avc_hash_stats 3 1984 _002239_hash NULL
86145 +_002240_hash sel_read_bool 3 24236 _002240_hash NULL
86146 +_002241_hash sel_read_checkreqprot 3 33068 _002241_hash NULL
86147 +_002242_hash sel_read_class 3 12669 _002960_hash NULL nohasharray
86148 +_002243_hash sel_read_enforce 3 2828 _002243_hash NULL
86149 +_002244_hash sel_read_handle_status 3 56139 _002244_hash NULL
86150 +_002245_hash sel_read_handle_unknown 3 57933 _002245_hash NULL
86151 +_002246_hash sel_read_initcon 3 32362 _002246_hash NULL
86152 +_002247_hash sel_read_mls 3 25369 _002247_hash NULL
86153 +_002248_hash sel_read_perm 3 42302 _002248_hash NULL
86154 +_002249_hash sel_read_policy 3 55947 _002249_hash NULL
86155 +_002250_hash sel_read_policycap 3 28544 _002250_hash NULL
86156 +_002251_hash sel_read_policyvers 3 55 _002827_hash NULL nohasharray
86157 +_002252_hash send_mpa_reject 3 7135 _002252_hash NULL
86158 +_002253_hash send_mpa_reply 3 32372 _002253_hash NULL
86159 +_002254_hash send_msg 4 37323 _002254_hash NULL
86160 +_002255_hash send_packet 4 52960 _002255_hash NULL
86161 +_002256_hash set_rxd_buffer_pointer 8 9950 _002256_hash NULL
86162 +_002257_hash sge_rx 3 50594 _002257_hash NULL
86163 +_002258_hash short_retry_limit_read 3 4687 _002258_hash NULL
86164 +_002259_hash simple_attr_read 3 24738 _002259_hash NULL
86165 +_002260_hash simple_transaction_read 3 17076 _002260_hash NULL
86166 +_002261_hash sisusbcon_bmove 5-7-6 21873 _002261_hash NULL
86167 +_002264_hash sisusbcon_clear 3-5-4 64329 _002264_hash NULL
86168 +_002267_hash sisusbcon_putcs 3 57630 _002267_hash &_001043_hash
86169 +_002268_hash sisusbcon_scroll 5-3-2 31315 _002268_hash NULL
86170 +_002269_hash sisusbcon_scroll_area 3-4 25899 _002269_hash NULL
86171 +_002271_hash skb_copy_datagram_const_iovec 2-5-4 48102 _002271_hash NULL
86172 +_002274_hash skb_copy_datagram_iovec 2-4 5806 _002274_hash NULL
86173 +_002276_hash skb_gro_header_slow 2 34958 _002276_hash NULL
86174 +_002277_hash smk_read_ambient 3 61220 _002277_hash NULL
86175 +_002278_hash smk_read_direct 3 15803 _002278_hash NULL
86176 +_002279_hash smk_read_doi 3 30813 _002279_hash NULL
86177 +_002280_hash smk_read_logging 3 37804 _002280_hash NULL
86178 +_002281_hash smk_read_mapped 3 7562 _002281_hash NULL
86179 +_002282_hash smk_read_onlycap 3 3855 _002282_hash NULL
86180 +_002283_hash smp_build_cmd 3 45853 _002283_hash NULL
86181 +_002284_hash snapshot_read 3 22601 _002284_hash NULL
86182 +_002285_hash snd_cs4281_BA0_read 5 6847 _002285_hash NULL
86183 +_002286_hash snd_cs4281_BA1_read 5 20323 _002286_hash NULL
86184 +_002287_hash snd_cs46xx_io_read 5 45734 _002287_hash NULL
86185 +_002288_hash snd_gus_dram_read 4 56686 _002288_hash NULL
86186 +_002289_hash snd_mixart_BA0_read 5 45069 _002289_hash NULL
86187 +_002290_hash snd_mixart_BA1_read 5 5082 _002290_hash NULL
86188 +_002291_hash snd_pcm_oss_read 3 28317 _002291_hash NULL
86189 +_002292_hash snd_pcm_plug_alloc 2 42339 _002292_hash NULL
86190 +_002293_hash snd_rawmidi_kernel_read 3 4328 _002293_hash NULL
86191 +_002294_hash snd_rawmidi_read 3 56337 _002294_hash NULL
86192 +_002295_hash snd_rme32_capture_copy 5 39653 _002295_hash NULL
86193 +_002296_hash snd_rme96_capture_copy 5 58484 _002296_hash NULL
86194 +_002297_hash snd_soc_hw_bulk_write_raw 4 14245 _002297_hash NULL
86195 +_002298_hash sock_alloc_send_skb 2 23720 _002298_hash NULL
86196 +_002299_hash spi_show_regs 3 6911 _002299_hash &_002163_hash
86197 +_002300_hash sta_agg_status_read 3 14058 _002300_hash NULL
86198 +_002301_hash sta_connected_time_read 3 17435 _002301_hash NULL
86199 +_002302_hash sta_flags_read 3 56710 _002302_hash NULL
86200 +_002303_hash sta_ht_capa_read 3 10366 _002303_hash NULL
86201 +_002304_hash sta_last_seq_ctrl_read 3 19106 _002304_hash NULL
86202 +_002305_hash sta_num_ps_buf_frames_read 3 1488 _002305_hash NULL
86203 +_002306_hash st_read 3 51251 _002306_hash NULL
86204 +_002307_hash supply_map_read_file 3 10608 _002307_hash NULL
86205 +_002308_hash sysfs_read_file 3 42113 _002308_hash NULL
86206 +_002309_hash sys_preadv 3 17100 _002309_hash NULL
86207 +_002310_hash sys_pwritev 3 41722 _002310_hash NULL
86208 +_002311_hash sys_readv 3 50664 _002311_hash NULL
86209 +_002312_hash sys_rt_sigpending 2 24961 _002312_hash NULL
86210 +_002313_hash sys_writev 3 28384 _002313_hash NULL
86211 +_002314_hash tcf_csum_skb_nextlayer 3 64025 _002314_hash NULL
86212 +_002315_hash tcp_fragment 3 20436 _002315_hash NULL
86213 +_002316_hash tcp_manip_pkt 2 14202 _002316_hash NULL
86214 +_002317_hash teiup_create 3 43201 _002317_hash NULL
86215 +_002318_hash test_iso_queue 5 62534 _002318_hash NULL
86216 +_002319_hash tg3_run_loopback 2 30093 _002319_hash NULL
86217 +_002320_hash tipc_msg_build 4 12326 _002320_hash NULL
86218 +_002321_hash TSS_authhmac 3 12839 _002321_hash NULL
86219 +_002322_hash TSS_checkhmac1 5 31429 _002322_hash NULL
86220 +_002323_hash TSS_checkhmac2 5-7 40520 _002323_hash NULL
86221 +_002325_hash tty_audit_log 8 47280 _002325_hash NULL
86222 +_002326_hash tty_buffer_request_room 2 23228 _002326_hash NULL
86223 +_002327_hash tty_insert_flip_string_fixed_flag 4 37428 _002327_hash NULL
86224 +_002328_hash tty_insert_flip_string_flags 4 30969 _002328_hash NULL
86225 +_002329_hash tty_prepare_flip_string 3 39955 _002329_hash NULL
86226 +_002330_hash tty_prepare_flip_string_flags 4 59240 _002330_hash NULL
86227 +_002331_hash tun_alloc_skb 2-4-3 41216 _002331_hash NULL
86228 +_002334_hash tun_sendmsg 4 10337 _002334_hash NULL
86229 +_002335_hash u32_array_read 3 2219 _002335_hash NULL
86230 +_002336_hash ubi_io_write_data 4-5 40305 _002336_hash NULL
86231 +_002338_hash udplite_manip_pkt 2 62433 _002338_hash NULL
86232 +_002339_hash udp_manip_pkt 2 50770 _002339_hash NULL
86233 +_002340_hash uhci_debug_read 3 5911 _002340_hash NULL
86234 +_002341_hash um_idi_read 3 850 _002341_hash NULL
86235 +_002342_hash unix_seqpacket_sendmsg 4 27893 _002342_hash NULL
86236 +_002343_hash unix_stream_recvmsg 4 35210 _002343_hash NULL
86237 +_002344_hash unlink_simple 3 47506 _002344_hash NULL
86238 +_002345_hash use_pool 2 64607 _002345_hash NULL
86239 +_002346_hash v9fs_fid_readn 4 60544 _002346_hash NULL
86240 +_002347_hash v9fs_file_read 3 40858 _002347_hash NULL
86241 +_002348_hash vhci_read 3 47878 _002348_hash NULL
86242 +_002349_hash vhost_add_used_and_signal_n 4 8038 _002349_hash NULL
86243 +_002350_hash vmbus_open 2-3 12154 _002350_hash NULL
86244 +_002352_hash vxge_rx_alloc 3 52024 _002352_hash NULL
86245 +_002353_hash waiters_read 3 40902 _002353_hash NULL
86246 +_002354_hash wm8994_bulk_write 3 13615 _002354_hash NULL
86247 +_002355_hash write_pbl 4 59583 _002355_hash NULL
86248 +_002356_hash wusb_prf_256 7 29203 _002356_hash NULL
86249 +_002357_hash wusb_prf_64 7 51065 _002357_hash NULL
86250 +_002358_hash _xfs_buf_alloc 3 38058 _002358_hash NULL
86251 +_002359_hash xfs_buf_read_uncached 3 42844 _002359_hash NULL
86252 +_002360_hash xfs_file_buffered_aio_write 4 11492 _002360_hash NULL
86253 +_002361_hash xfs_iext_add 3 41422 _002361_hash NULL
86254 +_002362_hash xfs_iext_remove_direct 3 40744 _002362_hash NULL
86255 +_002363_hash xfs_readdir 3 41200 _002363_hash NULL
86256 +_002364_hash xfs_trans_get_efd 3 51148 _002364_hash NULL
86257 +_002365_hash xfs_trans_get_efi 2 7898 _002365_hash NULL
86258 +_002366_hash xlog_bread_offset 3 60030 _002366_hash NULL
86259 +_002367_hash xlog_get_bp 2 23229 _002367_hash NULL
86260 +_002368_hash xz_dec_init 2 29029 _002368_hash NULL
86261 +_002369_hash aac_change_queue_depth 2 825 _002369_hash NULL
86262 +_002370_hash add_rx_skb 3 8257 _002370_hash NULL
86263 +_002371_hash afs_extract_data 5 50261 _002371_hash NULL
86264 +_002372_hash arcmsr_adjust_disk_queue_depth 2 16756 _002372_hash NULL
86265 +_002373_hash atalk_recvmsg 4 22053 _002373_hash NULL
86266 +_002374_hash ath6kl_buf_alloc 1 57304 _002374_hash NULL
86267 +_002376_hash atomic_read_file 3 16227 _002376_hash NULL
86268 +_002377_hash ax25_recvmsg 4 64441 _002377_hash NULL
86269 +_002378_hash batadv_add_packet 3 12136 _002378_hash NULL
86270 +_002379_hash batadv_iv_ogm_aggregate_new 2 54761 _002379_hash NULL
86271 +_002380_hash batadv_tt_response_fill_table 1 39236 _002380_hash NULL
86272 +_002381_hash beiscsi_process_async_pdu 7 39834 _002381_hash NULL
86273 +_002382_hash bioset_create 1 5580 _002382_hash NULL
86274 +_002383_hash bioset_integrity_create 2 62708 _002383_hash NULL
86275 +_002384_hash biovec_create_pools 2 9575 _002384_hash NULL
86276 +_002385_hash bnx2fc_process_l2_frame_compl 3 65072 _002385_hash NULL
86277 +_002386_hash brcmf_sdbrcm_died_dump 3 15841 _002386_hash NULL
86278 +_002387_hash brcmu_pkt_buf_get_skb 1 5556 _002387_hash NULL
86279 +_002388_hash br_send_bpdu 3 29669 _002388_hash NULL
86280 +_002389_hash btrfs_error_discard_extent 2 50444 _002389_hash NULL
86281 +_002390_hash __btrfs_free_reserved_extent 2 31207 _002390_hash NULL
86282 +_002391_hash btrfsic_cmp_log_and_dev_bytenr 2 49628 _002391_hash NULL
86283 +_002392_hash btrfsic_create_link_to_next_block 4 58246 _002392_hash NULL
86284 +_002393_hash btrfs_init_new_buffer 4 55761 _002393_hash NULL
86285 +_002394_hash btrfs_mksubvol 3 58240 _002394_hash NULL
86286 +_002395_hash bt_skb_send_alloc 2 6581 _002395_hash NULL
86287 +_002396_hash bt_sock_recvmsg 4 12316 _002396_hash NULL
86288 +_002397_hash bt_sock_stream_recvmsg 4 52518 _002397_hash NULL
86289 +_002398_hash c4iw_reject_cr 3 28174 _002398_hash NULL
86290 +_002399_hash caif_seqpkt_recvmsg 4 32241 _002399_hash NULL
86291 +_002400_hash carl9170_rx_copy_data 2 21656 _002400_hash NULL
86292 +_002401_hash cfpkt_append 3 61206 _002401_hash NULL
86293 +_002402_hash cfpkt_setlen 2 49343 _002402_hash NULL
86294 +_002403_hash cgroup_file_read 3 28804 _002403_hash NULL
86295 +_002404_hash cosa_net_setup_rx 2 38594 _002404_hash NULL
86296 +_002405_hash cpu_type_read 3 36540 _002405_hash NULL
86297 +_002406_hash cxgb4_pktgl_to_skb 2 61899 _002406_hash NULL
86298 +_002408_hash dccp_recvmsg 4 16056 _002408_hash NULL
86299 +_002409_hash ddp_clear_map 4 46152 _002409_hash NULL
86300 +_002410_hash ddp_set_map 4 751 _002410_hash NULL
86301 +_002411_hash depth_read 3 31112 _002411_hash NULL
86302 +_002412_hash dfs_global_file_read 3 7787 _002412_hash NULL
86303 +_002413_hash dgram_recvmsg 4 23104 _002413_hash NULL
86304 +_002414_hash diva_init_dma_map 3 58336 _002414_hash NULL
86305 +_002415_hash divas_write 3 63901 _002415_hash NULL
86306 +_002416_hash dma_push_rx 2 39973 _002416_hash NULL
86307 +_002417_hash dma_skb_copy_datagram_iovec 3-5 21516 _002417_hash NULL
86308 +_002419_hash dm_table_create 3 35687 _002419_hash NULL
86309 +_002420_hash dn_alloc_send_pskb 2 4465 _002420_hash NULL
86310 +_002421_hash dn_nsp_return_disc 2 60296 _002421_hash NULL
86311 +_002422_hash dn_nsp_send_disc 2 23469 _002422_hash NULL
86312 +_002423_hash dsp_tone_hw_message 3 17678 _002423_hash NULL
86313 +_002424_hash e1000_check_copybreak 3 62448 _002424_hash NULL
86314 +_002425_hash enable_read 3 2117 _002425_hash &_000224_hash
86315 +_002426_hash exofs_read_kern 6 39921 _002426_hash &_002129_hash
86316 +_002427_hash fast_rx_path 3 59214 _002427_hash NULL
86317 +_002428_hash fc_change_queue_depth 2 36841 _002428_hash NULL
86318 +_002429_hash fc_fcp_frame_alloc 2 12624 _002429_hash NULL
86319 +_002430_hash fcoe_ctlr_send_keep_alive 3 15308 _002430_hash NULL
86320 +_002431_hash frequency_read 3 64031 _003698_hash NULL nohasharray
86321 +_002432_hash ftdi_process_packet 5 45005 _002432_hash NULL
86322 +_002433_hash fuse_conn_congestion_threshold_read 3 51028 _002433_hash NULL
86323 +_002434_hash fuse_conn_max_background_read 3 10855 _002434_hash NULL
86324 +_002435_hash fwnet_incoming_packet 3 40380 _002435_hash NULL
86325 +_002436_hash fwnet_pd_new 4 39947 _003402_hash NULL nohasharray
86326 +_002437_hash get_alua_req 3 4166 _002437_hash NULL
86327 +_002438_hash get_rdac_req 3 45882 _002438_hash NULL
86328 +_002439_hash got_frame 2 16028 _002439_hash NULL
86329 +_002440_hash gsm_mux_rx_netchar 3 33336 _002440_hash NULL
86330 +_002441_hash hci_sock_recvmsg 4 7072 _002441_hash NULL
86331 +_002442_hash hdlcdev_rx 3 997 _002442_hash NULL
86332 +_002443_hash hdlc_empty_fifo 2 18397 _002443_hash NULL
86333 +_002444_hash hfc_empty_fifo 2 57972 _002444_hash NULL
86334 +_002445_hash hfcpci_empty_fifo 4 2427 _002445_hash NULL
86335 +_002446_hash hfcsusb_rx_frame 3 52745 _002446_hash NULL
86336 +_002447_hash hidp_output_raw_report 3 5629 _002447_hash NULL
86337 +_002448_hash hpsa_change_queue_depth 2 15449 _002448_hash NULL
86338 +_002449_hash hptiop_adjust_disk_queue_depth 2 20122 _002449_hash NULL
86339 +_002450_hash hscx_empty_fifo 2 13360 _002450_hash NULL
86340 +_002451_hash hysdn_rx_netpkt 3 16136 _002451_hash NULL
86341 +_002452_hash i2o_pool_alloc 4 55485 _002452_hash NULL
86342 +_002453_hash ide_queue_pc_tail 5 11673 _002453_hash NULL
86343 +_002454_hash ide_raw_taskfile 4 42355 _002454_hash NULL
86344 +_002455_hash idetape_queue_rw_tail 3 29562 _002455_hash NULL
86345 +_002456_hash ieee80211_amsdu_to_8023s 5 15561 _002456_hash NULL
86346 +_002457_hash ieee80211_fragment 4 33112 _002457_hash NULL
86347 +_002458_hash ieee80211_if_read_aid 3 9705 _002458_hash NULL
86348 +_002459_hash ieee80211_if_read_auto_open_plinks 3 38268 _002459_hash &_000374_hash
86349 +_002460_hash ieee80211_if_read_ave_beacon 3 64924 _002460_hash NULL
86350 +_002461_hash ieee80211_if_read_bssid 3 35161 _002461_hash NULL
86351 +_002462_hash ieee80211_if_read_channel_type 3 23884 _002462_hash NULL
86352 +_002463_hash ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 _002463_hash NULL
86353 +_002464_hash ieee80211_if_read_dot11MeshForwarding 3 13940 _002464_hash NULL
86354 +_002465_hash ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 _002465_hash NULL
86355 +_002466_hash ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 _002466_hash NULL
86356 +_002467_hash ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 _002467_hash NULL
86357 +_002468_hash ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 _002468_hash NULL
86358 +_002469_hash ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 _002469_hash NULL
86359 +_002470_hash ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 _002470_hash NULL
86360 +_002471_hash ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 _002471_hash NULL
86361 +_002472_hash ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 _002472_hash NULL
86362 +_002473_hash ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 _002473_hash NULL
86363 +_002474_hash ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 _002474_hash NULL
86364 +_002475_hash ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 _002475_hash NULL
86365 +_002476_hash ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 _002476_hash NULL
86366 +_002477_hash ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 _002477_hash NULL
86367 +_002478_hash ieee80211_if_read_dot11MeshMaxRetries 3 12756 _002478_hash NULL
86368 +_002479_hash ieee80211_if_read_dot11MeshRetryTimeout 3 52168 _002479_hash NULL
86369 +_002480_hash ieee80211_if_read_dot11MeshTTL 3 58307 _002480_hash NULL
86370 +_002481_hash ieee80211_if_read_dropped_frames_congestion 3 32603 _002481_hash NULL
86371 +_002482_hash ieee80211_if_read_dropped_frames_no_route 3 33383 _002482_hash NULL
86372 +_002483_hash ieee80211_if_read_dropped_frames_ttl 3 44500 _002483_hash NULL
86373 +_002484_hash ieee80211_if_read_drop_unencrypted 3 37053 _002484_hash NULL
86374 +_002485_hash ieee80211_if_read_dtim_count 3 38419 _002485_hash NULL
86375 +_002486_hash ieee80211_if_read_element_ttl 3 18869 _002486_hash NULL
86376 +_002487_hash ieee80211_if_read_estab_plinks 3 32533 _002487_hash NULL
86377 +_002488_hash ieee80211_if_read_flags 3 57470 _002919_hash NULL nohasharray
86378 +_002489_hash ieee80211_if_read_fwded_frames 3 36520 _002489_hash NULL
86379 +_002490_hash ieee80211_if_read_fwded_mcast 3 39571 _002490_hash &_000162_hash
86380 +_002491_hash ieee80211_if_read_fwded_unicast 3 59740 _002491_hash &_001697_hash
86381 +_002492_hash ieee80211_if_read_ht_opmode 3 29044 _002492_hash NULL
86382 +_002493_hash ieee80211_if_read_last_beacon 3 31257 _002493_hash NULL
86383 +_002494_hash ieee80211_if_read_min_discovery_timeout 3 13946 _002494_hash NULL
86384 +_002495_hash ieee80211_if_read_num_buffered_multicast 3 12716 _002495_hash NULL
86385 +_002496_hash ieee80211_if_read_num_mcast_sta 3 12419 _002496_hash NULL
86386 +_002497_hash ieee80211_if_read_num_sta_ps 3 34722 _002497_hash NULL
86387 +_002498_hash ieee80211_if_read_path_refresh_time 3 25545 _002498_hash NULL
86388 +_002499_hash ieee80211_if_read_peer 3 45233 _002499_hash NULL
86389 +_002500_hash ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 _002500_hash NULL
86390 +_002501_hash ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 _002501_hash NULL
86391 +_002502_hash ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 _002502_hash NULL
86392 +_002503_hash ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 _002503_hash NULL
86393 +_002504_hash ieee80211_if_read_rssi_threshold 3 49260 _002504_hash NULL
86394 +_002505_hash ieee80211_if_read_smps 3 27416 _002505_hash NULL
86395 +_002506_hash ieee80211_if_read_state 3 9813 _002707_hash NULL nohasharray
86396 +_002507_hash ieee80211_if_read_tkip_mic_test 3 19565 _002507_hash NULL
86397 +_002508_hash ieee80211_if_read_tsf 3 16420 _002508_hash NULL
86398 +_002509_hash ieee80211_if_read_uapsd_max_sp_len 3 15067 _002509_hash NULL
86399 +_002510_hash ieee80211_if_read_uapsd_queues 3 55150 _002510_hash NULL
86400 +_002511_hash ieee80211_mgmt_tx 9 46860 _002511_hash NULL
86401 +_002512_hash ieee80211_probereq_get 4-6 29069 _002512_hash NULL
86402 +_002514_hash ieee80211_rx_mgmt_beacon 3 24430 _002514_hash NULL
86403 +_002515_hash ieee80211_rx_mgmt_probe_resp 3 6918 _002515_hash NULL
86404 +_002516_hash ieee80211_send_auth 5 24121 _002516_hash NULL
86405 +_002517_hash ieee80211_set_probe_resp 3 10077 _002517_hash NULL
86406 +_002518_hash ieee80211_tdls_mgmt 8 9581 _002518_hash NULL
86407 +_002519_hash ima_show_htable_violations 3 10619 _002519_hash NULL
86408 +_002520_hash ima_show_measurements_count 3 23536 _002520_hash NULL
86409 +_002521_hash insert_one_name 7 61668 _002521_hash NULL
86410 +_002522_hash ip6_ufo_append_data 5-7-6 4780 _002522_hash NULL
86411 +_002525_hash ip_append_data 5-6 16942 _002525_hash NULL
86412 +_002526_hash ip_make_skb 5-6 13129 _002526_hash NULL
86413 +_002527_hash ip_nat_sdp_port 6 52938 _002527_hash NULL
86414 +_002528_hash ip_nat_sip_expect 7 45693 _002528_hash NULL
86415 +_002529_hash ipr_change_queue_depth 2 6431 _002529_hash NULL
86416 +_002530_hash ip_recv_error 3 23109 _002530_hash NULL
86417 +_002531_hash ip_ufo_append_data 6-8-7 12775 _002531_hash NULL
86418 +_002534_hash ipv6_recv_error 3 56347 _002534_hash NULL
86419 +_002535_hash ipv6_recv_rxpmtu 3 7142 _002535_hash NULL
86420 +_002536_hash ipw_packet_received_skb 2 1230 _002536_hash NULL
86421 +_002537_hash ipx_recvmsg 4 44366 _002537_hash NULL
86422 +_002538_hash irda_recvmsg_dgram 4 32631 _002538_hash NULL
86423 +_002539_hash iscsi_change_queue_depth 2 23416 _002539_hash NULL
86424 +_002540_hash iscsi_complete_pdu 4 48372 _002540_hash NULL
86425 +_002541_hash iwch_reject_cr 3 23901 _002541_hash NULL
86426 +_002542_hash ixgb_check_copybreak 3 5847 _002542_hash NULL
86427 +_002543_hash key_conf_hw_key_idx_read 3 25003 _002543_hash NULL
86428 +_002544_hash key_conf_keyidx_read 3 42443 _002544_hash NULL
86429 +_002545_hash key_conf_keylen_read 3 49758 _002545_hash NULL
86430 +_002546_hash key_flags_read 3 25931 _002546_hash NULL
86431 +_002547_hash key_ifindex_read 3 31411 _002547_hash NULL
86432 +_002548_hash key_tx_rx_count_read 3 44742 _002548_hash NULL
86433 +_002549_hash kmsg_read 3 46514 _002549_hash NULL
86434 +_002550_hash l1oip_socket_parse 4 4507 _002550_hash NULL
86435 +_002551_hash l2cap_send_cmd 4 14548 _002551_hash NULL
86436 +_002552_hash l2cap_sock_sendmsg 4 63427 _002552_hash NULL
86437 +_002553_hash l2tp_ip6_recvmsg 4 62874 _002553_hash NULL
86438 +_002554_hash l2tp_ip6_sendmsg 4 7461 _002554_hash NULL
86439 +_002555_hash l2tp_ip_recvmsg 4 22681 _002555_hash NULL
86440 +_002556_hash lbs_bcnmiss_read 3 8678 _002556_hash NULL
86441 +_002557_hash lbs_failcount_read 3 31063 _002557_hash NULL
86442 +_002558_hash lbs_highrssi_read 3 64089 _002558_hash NULL
86443 +_002559_hash lbs_highsnr_read 3 5931 _002559_hash NULL
86444 +_002560_hash lbs_lowrssi_read 3 32242 _002560_hash NULL
86445 +_002561_hash lbs_lowsnr_read 3 29571 _002561_hash NULL
86446 +_002563_hash llc_ui_recvmsg 4 3826 _002563_hash NULL
86447 +_002564_hash lowpan_fragment_xmit 3-4 22095 _002564_hash NULL
86448 +_002566_hash lpfc_change_queue_depth 2 25905 _002566_hash NULL
86449 +_002568_hash macvtap_do_read 4 36555 _002568_hash &_002050_hash
86450 +_002569_hash mangle_sdp_packet 9 36279 _002569_hash NULL
86451 +_002570_hash map_addr 6 4666 _002570_hash NULL
86452 +_002571_hash mcs_unwrap_fir 3 25733 _002571_hash NULL
86453 +_002572_hash mcs_unwrap_mir 3 9455 _002572_hash NULL
86454 +_002573_hash megaraid_change_queue_depth 2 64815 _002573_hash NULL
86455 +_002574_hash megasas_change_queue_depth 2 32747 _002574_hash NULL
86456 +_002575_hash mld_newpack 2 50950 _002575_hash NULL
86457 +_002576_hash mptscsih_change_queue_depth 2 26036 _002576_hash NULL
86458 +_002577_hash named_distribute 4 48544 _002577_hash NULL
86459 +_002578_hash NCR_700_change_queue_depth 2 31742 _002578_hash NULL
86460 +_002579_hash netlink_recvmsg 4 61600 _002579_hash NULL
86461 +_002580_hash nfc_alloc_send_skb 4 3167 _002580_hash NULL
86462 +_002581_hash nf_nat_ftp 5 47948 _002581_hash NULL
86463 +_002582_hash nfsctl_transaction_read 3 48250 _002582_hash NULL
86464 +_002583_hash nfsd_read 5 19568 _002583_hash NULL
86465 +_002584_hash nfsd_read_file 6 62241 _002584_hash NULL
86466 +_002585_hash nfsd_write 6 54809 _002585_hash NULL
86467 +_002586_hash nfs_map_group_to_gid 3 15892 _002586_hash NULL
86468 +_002587_hash nfs_map_name_to_uid 3 51132 _002587_hash NULL
86469 +_002588_hash nr_recvmsg 4 12649 _002588_hash NULL
86470 +_002589_hash ntfs_rl_append 2-4 6037 _002589_hash NULL
86471 +_002591_hash ntfs_rl_insert 2-4 4931 _002591_hash NULL
86472 +_002593_hash ntfs_rl_replace 2-4 14136 _002593_hash NULL
86473 +_002595_hash ntfs_rl_split 2-4 52328 _002595_hash NULL
86474 +_002597_hash osd_req_list_collection_objects 5 36664 _002597_hash NULL
86475 +_002598_hash osd_req_list_partition_objects 5 56464 _002598_hash NULL
86476 +_002599_hash osd_req_read_sg 5 47905 _002599_hash NULL
86477 +_002600_hash osd_req_write_sg 5 50908 _002600_hash NULL
86478 +_002602_hash p54_download_eeprom 4 43842 _002602_hash NULL
86479 +_002604_hash packet_recv_error 3 16669 _002604_hash NULL
86480 +_002605_hash packet_recvmsg 4 47700 _002605_hash NULL
86481 +_002606_hash pep_recvmsg 4 19402 _002606_hash NULL
86482 +_002607_hash pfkey_recvmsg 4 53604 _002607_hash NULL
86483 +_002608_hash ping_recvmsg 4 25597 _002608_hash NULL
86484 +_002609_hash pmcraid_change_queue_depth 2 9116 _002609_hash NULL
86485 +_002610_hash pn_recvmsg 4 30887 _002610_hash NULL
86486 +_002611_hash pointer_size_read 3 51863 _002611_hash NULL
86487 +_002612_hash power_read 3 15939 _002612_hash NULL
86488 +_002613_hash pppoe_recvmsg 4 15073 _002613_hash NULL
86489 +_002614_hash pppol2tp_recvmsg 4 57742 _002993_hash NULL nohasharray
86490 +_002615_hash ppp_tx_cp 5 62044 _002615_hash NULL
86491 +_002616_hash prism2_send_mgmt 4 62605 _002616_hash &_002119_hash
86492 +_002617_hash prism2_sta_send_mgmt 5 43916 _002617_hash NULL
86493 +_002618_hash prison_create 1 43623 _002618_hash NULL
86494 +_002619_hash qla2x00_adjust_sdev_qdepth_up 2 20097 _002619_hash NULL
86495 +_002620_hash qla2x00_change_queue_depth 2 24742 _002620_hash NULL
86496 +_002621_hash _queue_data 4 54983 _002621_hash NULL
86497 +_002622_hash raw_recvmsg 4 52529 _002622_hash NULL
86498 +_002623_hash rawsock_recvmsg 4 12144 _002623_hash NULL
86499 +_002624_hash rawv6_recvmsg 4 30265 _002624_hash NULL
86500 +_002625_hash rds_tcp_data_recv 3 53476 _002625_hash NULL
86501 +_002626_hash reada_add_block 2 54247 _002626_hash NULL
86502 +_002627_hash readahead_tree_block 3 36285 _002627_hash NULL
86503 +_002628_hash reada_tree_block_flagged 3 18402 _002628_hash NULL
86504 +_002629_hash read_dma 3 55086 _002629_hash NULL
86505 +_002630_hash read_fifo 3 826 _002630_hash NULL
86506 +_002631_hash read_tree_block 3 841 _002631_hash NULL
86507 +_002632_hash receive_copy 3 12216 _002632_hash NULL
86508 +_002633_hash recover_peb 6-7 29238 _002633_hash NULL
86509 +_002635_hash recv_msg 4 48709 _002635_hash NULL
86510 +_002636_hash recv_stream 4 30138 _002636_hash NULL
86511 +_002637_hash _req_append_segment 2 41031 _002637_hash NULL
86512 +_002638_hash request_key_async 4 6990 _002638_hash NULL
86513 +_002639_hash request_key_async_with_auxdata 4 46624 _002639_hash NULL
86514 +_002640_hash request_key_with_auxdata 4 24515 _002640_hash NULL
86515 +_002641_hash rose_recvmsg 4 2368 _002641_hash &_001788_hash
86516 +_002642_hash rtl8169_try_rx_copy 3 705 _002642_hash NULL
86517 +_002643_hash _rtl92s_firmware_downloadcode 3 14021 _002643_hash NULL
86518 +_002644_hash rx_data 4 60442 _002644_hash NULL
86519 +_002645_hash rxrpc_recvmsg 4 26233 _002645_hash NULL
86520 +_002646_hash sas_change_queue_depth 2 18555 _002646_hash NULL
86521 +_002647_hash scsi_activate_tcq 2 42640 _002647_hash NULL
86522 +_002648_hash scsi_deactivate_tcq 2 47086 _002648_hash NULL
86523 +_002649_hash scsi_execute 5 33596 _002649_hash NULL
86524 +_002650_hash _scsih_adjust_queue_depth 2 1083 _002650_hash NULL
86525 +_002651_hash scsi_init_shared_tag_map 2 59812 _002651_hash NULL
86526 +_002652_hash scsi_track_queue_full 2 44239 _002652_hash NULL
86527 +_002653_hash sctp_abort_pkt_new 5 55218 _002653_hash NULL
86528 +_002654_hash sctp_make_abort_violation 4 27959 _002654_hash NULL
86529 +_002655_hash sctp_make_op_error 5-6 7057 _002655_hash NULL
86530 +_002657_hash sctp_recvmsg 4 23265 _002657_hash NULL
86531 +_002658_hash send_stream 4 3397 _002658_hash NULL
86532 +_002659_hash sis190_try_rx_copy 3 57069 _002659_hash NULL
86533 +_002664_hash skb_copy_and_csum_datagram_iovec 2 24466 _002664_hash NULL
86534 +_002666_hash skge_rx_get 3 40598 _002666_hash NULL
86535 +_002667_hash smp_send_cmd 3 512 _002667_hash NULL
86536 +_002668_hash snd_gf1_mem_proc_dump 5 16926 _003499_hash NULL nohasharray
86537 +_002669_hash sta_dev_read 3 14782 _002669_hash NULL
86538 +_002670_hash sta_inactive_ms_read 3 25690 _002670_hash NULL
86539 +_002671_hash sta_last_signal_read 3 31818 _002671_hash NULL
86540 +_002672_hash stats_dot11ACKFailureCount_read 3 45558 _002672_hash NULL
86541 +_002673_hash stats_dot11FCSErrorCount_read 3 28154 _002673_hash NULL
86542 +_002674_hash stats_dot11RTSFailureCount_read 3 43948 _002674_hash NULL
86543 +_002675_hash stats_dot11RTSSuccessCount_read 3 33065 _002675_hash NULL
86544 +_002676_hash storvsc_connect_to_vsp 2 22 _002676_hash NULL
86545 +_002677_hash sys_msgrcv 3 959 _002677_hash NULL
86546 +_002678_hash sys_syslog 3 10746 _002678_hash NULL
86547 +_002679_hash tcf_csum_ipv4_icmp 3 9258 _002679_hash NULL
86548 +_002680_hash tcf_csum_ipv4_igmp 3 60446 _002680_hash NULL
86549 +_002681_hash tcf_csum_ipv4_tcp 4 39713 _002681_hash NULL
86550 +_002682_hash tcf_csum_ipv4_udp 4 30777 _002682_hash NULL
86551 +_002683_hash tcf_csum_ipv6_icmp 4 11738 _002683_hash NULL
86552 +_002684_hash tcf_csum_ipv6_tcp 4 54877 _002684_hash NULL
86553 +_002685_hash tcf_csum_ipv6_udp 4 25241 _002685_hash NULL
86554 +_002686_hash tcm_loop_change_queue_depth 2 42454 _002686_hash NULL
86555 +_002687_hash tcp_copy_to_iovec 3 28344 _002687_hash NULL
86556 +_002688_hash tcp_mark_head_lost 2 35895 _002688_hash NULL
86557 +_002689_hash tcp_match_skb_to_sack 4 23568 _002689_hash NULL
86558 +_002690_hash timeout_read 3 47915 _002690_hash NULL
86559 +_002691_hash tipc_multicast 5 49144 _002691_hash NULL
86560 +_002692_hash tipc_port_recv_sections 4 42890 _002692_hash NULL
86561 +_002693_hash tipc_port_reject_sections 5 55229 _002693_hash NULL
86562 +_002694_hash total_ps_buffered_read 3 16365 _002694_hash NULL
86563 +_002695_hash tso_fragment 3 29050 _002695_hash NULL
86564 +_002696_hash tty_insert_flip_string 3 34042 _002696_hash NULL
86565 +_002698_hash tun_put_user 4 59849 _002698_hash NULL
86566 +_002699_hash twa_change_queue_depth 2 48808 _002699_hash NULL
86567 +_002700_hash tw_change_queue_depth 2 11116 _002700_hash NULL
86568 +_002701_hash twl_change_queue_depth 2 41342 _002701_hash NULL
86569 +_002702_hash ubi_eba_atomic_leb_change 5 60379 _002702_hash NULL
86570 +_002703_hash ubi_eba_write_leb 5-6 36029 _002703_hash NULL
86571 +_002705_hash ubi_eba_write_leb_st 5 44343 _002705_hash NULL
86572 +_002706_hash udp_recvmsg 4 42558 _002706_hash NULL
86573 +_002707_hash udpv6_recvmsg 4 9813 _002707_hash &_002506_hash
86574 +_002708_hash udpv6_sendmsg 4 22316 _002708_hash NULL
86575 +_002709_hash ulong_read_file 3 42304 _002709_hash &_000522_hash
86576 +_002710_hash unix_dgram_recvmsg 4 14952 _002710_hash NULL
86577 +_002711_hash user_power_read 3 39414 _002711_hash NULL
86578 +_002712_hash v9fs_direct_read 3 45546 _002712_hash NULL
86579 +_002713_hash v9fs_file_readn 4 36353 _002713_hash &_001799_hash
86580 +_002714_hash vcc_recvmsg 4 37198 _002714_hash NULL
86581 +_002715_hash velocity_rx_copy 2 34583 _002715_hash NULL
86582 +_002716_hash W6692_empty_Bfifo 2 47804 _002716_hash NULL
86583 +_002717_hash wep_iv_read 3 54744 _002717_hash NULL
86584 +_002718_hash x25_recvmsg 4 42777 _002718_hash NULL
86585 +_002719_hash xfs_buf_get_map 3 24522 _002719_hash NULL
86586 +_002720_hash xfs_file_aio_write 4 33234 _002720_hash NULL
86587 +_002721_hash xfs_iext_insert 3 18667 _002741_hash NULL nohasharray
86588 +_002722_hash xfs_iext_remove 3 50909 _002722_hash NULL
86589 +_002723_hash xlog_do_recovery_pass 3 21618 _002723_hash NULL
86590 +_002724_hash xlog_find_verify_log_record 2 18870 _002724_hash NULL
86591 +_002725_hash zd_mac_rx 3 38296 _002725_hash NULL
86592 +_002726_hash aircable_process_packet 5 46639 _002726_hash NULL
86593 +_002727_hash ath6kl_wmi_get_new_buf 1 52304 _002727_hash NULL
86594 +_002728_hash batadv_iv_ogm_queue_add 3 46319 _002728_hash NULL
86595 +_002729_hash batadv_receive_client_update_packet 3 41578 _002729_hash NULL
86596 +_002730_hash batadv_receive_server_sync_packet 3 26577 _002730_hash &_000494_hash
86597 +_002731_hash brcmf_alloc_pkt_and_read 2 63116 _002731_hash &_002028_hash
86598 +_002732_hash brcmf_sdcard_recv_buf 6 38179 _002732_hash NULL
86599 +_002733_hash brcmf_sdcard_rwdata 5 65041 _002733_hash NULL
86600 +_002734_hash brcmf_sdcard_send_buf 6 7713 _002734_hash NULL
86601 +_002735_hash brcmf_sdio_forensic_read 3 35311 _002735_hash &_001382_hash
86602 +_002736_hash btrfs_alloc_free_block 3 8986 _002736_hash NULL
86603 +_002737_hash btrfs_free_and_pin_reserved_extent 2 53016 _002737_hash NULL
86604 +_002738_hash btrfs_free_reserved_extent 2 9867 _002738_hash NULL
86605 +_002739_hash carl9170_handle_mpdu 3 11056 _002739_hash NULL
86606 +_002740_hash do_trimming 3 26952 _002740_hash NULL
86607 +_002741_hash edge_tty_recv 4 18667 _002741_hash &_002721_hash
86608 +_002742_hash fwnet_receive_packet 9 50537 _002742_hash NULL
86609 +_002743_hash gigaset_if_receive 3 4861 _002743_hash NULL
86610 +_002744_hash gsm_dlci_data 3 14155 _002744_hash NULL
86611 +_002745_hash handle_rx_packet 3 58993 _002745_hash NULL
86612 +_002746_hash HDLC_irq 2 8709 _002746_hash NULL
86613 +_002747_hash hdlc_rpr_irq 2 10240 _002747_hash NULL
86614 +_002749_hash ifx_spi_insert_flip_string 3 51752 _002749_hash NULL
86615 +_002753_hash ip_nat_sdp_media 8 23386 _002753_hash NULL
86616 +_002754_hash ip_send_unicast_reply 6 38714 _002754_hash NULL
86617 +_002756_hash ipwireless_network_packet_received 4 51277 _002756_hash NULL
86618 +_002757_hash ipwireless_tty_received 3 49154 _002757_hash NULL
86619 +_002758_hash iscsi_iser_recv 4 41948 _002758_hash NULL
86620 +_002759_hash l2cap_bredr_sig_cmd 3 49065 _002759_hash NULL
86621 +_002760_hash l2cap_sock_alloc_skb_cb 2 33532 _002760_hash NULL
86622 +_002761_hash l2cap_sock_recvmsg 4 59886 _002761_hash NULL
86623 +_002762_hash llcp_allocate_pdu 3 19866 _002762_hash NULL
86624 +_002763_hash macvtap_recvmsg 4 63949 _002763_hash NULL
86625 +_002764_hash osd_req_list_dev_partitions 4 60027 _002764_hash NULL
86626 +_002765_hash osd_req_list_partition_collections 5 38223 _002765_hash NULL
86627 +_002766_hash osst_do_scsi 4 44410 _002766_hash NULL
86628 +_002767_hash ping_sendmsg 4 3782 _002767_hash NULL
86629 +_002768_hash ppp_cp_event 6 2965 _002768_hash NULL
86630 +_002769_hash pty_write 3 44757 _002769_hash &_001733_hash
86631 +_002770_hash push_rx 3 28939 _002770_hash NULL
86632 +_002772_hash qla2x00_handle_queue_full 2 24365 _002772_hash NULL
86633 +_002773_hash qla4xxx_change_queue_depth 2 1268 _002773_hash NULL
86634 +_002774_hash rfcomm_sock_recvmsg 4 22227 _002774_hash NULL
86635 +_002775_hash scsi_execute_req 5 42088 _002775_hash NULL
86636 +_002776_hash _scsih_change_queue_depth 2 26230 _002776_hash NULL
86637 +_002777_hash sctp_sf_abort_violation 6 38380 _002777_hash NULL
86638 +_002778_hash send_to_tty 3 45141 _002778_hash NULL
86639 +_002780_hash sky2_receive 2 13407 _002780_hash NULL
86640 +_002781_hash spi_execute 5 28736 _002781_hash NULL
86641 +_002782_hash submit_inquiry 3 42108 _002782_hash NULL
86642 +_002783_hash tcp_dma_try_early_copy 3 4457 _002783_hash NULL
86643 +_002784_hash tcp_sacktag_walk 6 49703 _002784_hash NULL
86644 +_002785_hash tcp_write_xmit 2 64602 _002785_hash NULL
86645 +_002786_hash ti_recv 4 22027 _002786_hash NULL
86646 +_002787_hash tun_do_read 4 50800 _002787_hash NULL
86647 +_002788_hash ubi_leb_change 4 10289 _002788_hash NULL
86648 +_002789_hash ubi_leb_write 4-5 5478 _002789_hash NULL
86649 +_002791_hash udp_sendmsg 4 4492 _002791_hash NULL
86650 +_002792_hash unix_seqpacket_recvmsg 4 23062 _002792_hash &_000477_hash
86651 +_002793_hash v9fs_cached_file_read 3 2514 _002793_hash NULL
86652 +_002794_hash write_leb 5 36957 _002794_hash NULL
86653 +_002795_hash xfs_buf_read_map 3 40226 _002795_hash NULL
86654 +_002796_hash xfs_trans_get_buf_map 4 2927 _002796_hash NULL
86655 +_002797_hash xlog_do_log_recovery 3 17550 _002797_hash NULL
86656 +_002798_hash ath6kl_wmi_add_wow_pattern_cmd 4 12842 _002798_hash NULL
86657 +_002799_hash ath6kl_wmi_beginscan_cmd 8 25462 _002799_hash NULL
86658 +_002800_hash ath6kl_wmi_send_probe_response_cmd 6 31728 _002800_hash NULL
86659 +_002801_hash ath6kl_wmi_set_appie_cmd 5 39266 _002801_hash NULL
86660 +_002802_hash ath6kl_wmi_set_ie_cmd 6 37260 _002802_hash NULL
86661 +_002803_hash ath6kl_wmi_startscan_cmd 8 33674 _002803_hash NULL
86662 +_002804_hash ath6kl_wmi_test_cmd 3 27312 _002804_hash NULL
86663 +_002805_hash brcmf_sdbrcm_membytes 3-5 37324 _002805_hash NULL
86664 +_002807_hash brcmf_sdbrcm_read_control 3 22721 _002807_hash NULL
86665 +_002808_hash brcmf_tx_frame 3 20978 _002808_hash NULL
86666 +_002809_hash __carl9170_rx 3 56784 _002809_hash NULL
86667 +_002810_hash ch_do_scsi 4 31171 _002810_hash NULL
86668 +_002811_hash dbg_leb_change 4 23555 _002811_hash NULL
86669 +_002812_hash dbg_leb_write 4-5 63555 _002812_hash &_000971_hash
86670 +_002814_hash gluebi_write 3 27905 _002814_hash NULL
86671 +_002815_hash hdlc_irq_one 2 3944 _002815_hash NULL
86672 +_002819_hash iser_rcv_completion 2 8048 _002819_hash NULL
86673 +_002820_hash lock_loop 1 61681 _002820_hash NULL
86674 +_002821_hash process_rcvd_data 3 6679 _002821_hash NULL
86675 +_002822_hash brcmf_sdbrcm_bus_txctl 3 42492 _002822_hash NULL
86676 +_002823_hash carl9170_rx 3 13272 _002823_hash NULL
86677 +_002824_hash carl9170_rx_stream 3 1334 _002824_hash NULL
86678 +_002826_hash mpt_lan_receive_post_turbo 2 13592 _002826_hash NULL
86679 +_002827_hash padzero 1 55 _002827_hash &_002251_hash
86680 +_002828_hash scsi_mode_sense 5 16835 _002828_hash NULL
86681 +_002829_hash scsi_vpd_inquiry 4 30040 _002829_hash NULL
86682 +_002830_hash ses_recv_diag 4 47143 _002830_hash &_000679_hash
86683 +_002831_hash ses_send_diag 4 64527 _002831_hash NULL
86684 +_002832_hash tcp_push_one 2 48816 _002832_hash NULL
86685 +_002833_hash __tcp_push_pending_frames 2 48148 _002833_hash NULL
86686 +_002834_hash trim_bitmaps 3 24158 _002834_hash NULL
86687 +_002835_hash tun_recvmsg 4 48463 _002835_hash NULL
86688 +_002836_hash ubifs_leb_change 4 17789 _002836_hash NULL
86689 +_002837_hash ubifs_leb_write 4-5 22679 _002837_hash NULL
86690 +_002839_hash xfs_buf_readahead_map 3 44248 _002839_hash &_000851_hash
86691 +_002840_hash xfs_trans_read_buf_map 5 37487 _002840_hash NULL
86692 +_002841_hash xlog_do_recover 3 59789 _002841_hash NULL
86693 +_002842_hash btrfs_trim_block_group 3 28963 _002842_hash NULL
86694 +_002843_hash do_write_orph_node 2 64343 _002843_hash NULL
86695 +_002844_hash fix_unclean_leb 3 23188 _002844_hash NULL
86696 +_002845_hash fixup_leb 3 43256 _002845_hash NULL
86697 +_002846_hash recover_head 3 17904 _002846_hash NULL
86698 +_002847_hash scsi_get_vpd_page 4 51951 _002847_hash NULL
86699 +_002848_hash sd_do_mode_sense 5 11507 _002848_hash NULL
86700 +_002849_hash tcp_push 3 10680 _002849_hash NULL
86701 +_002850_hash ubifs_wbuf_write_nolock 3 64946 _002850_hash NULL
86702 +_002851_hash ubifs_write_node 3-5 11258 _002851_hash NULL
86703 +_002852_hash ubifs_recover_leb 3 60639 _002852_hash NULL
86704 +_002853_hash write_head 4 30481 _002853_hash NULL
86705 +_002854_hash write_node 4 33121 _002854_hash NULL
86706 +_002855_hash ubifs_recover_log_leb 3 12079 _002855_hash NULL
86707 +_002856_hash replay_log_leb 3 18704 _002856_hash NULL
86708 +_002857_hash alloc_cpu_rmap 1 65363 _002857_hash NULL
86709 +_002858_hash alloc_ebda_hpc 1-2 50046 _002858_hash NULL
86710 +_002860_hash alloc_sched_domains 1 28972 _002860_hash NULL
86711 +_002861_hash amthi_read 4 45831 _002861_hash NULL
86712 +_002862_hash bcm_char_read 3 31750 _002862_hash NULL
86713 +_002863_hash BcmCopySection 5 2035 _002863_hash NULL
86714 +_002864_hash buffer_from_user 3 51826 _002864_hash NULL
86715 +_002865_hash buffer_to_user 3 35439 _002865_hash NULL
86716 +_002866_hash card_send_command 3 40757 _002866_hash NULL
86717 +_002867_hash chd_dec_fetch_cdata 3 50926 _002867_hash NULL
86718 +_002868_hash copy_nodes_to_user 2 63807 _002868_hash NULL
86719 +_002869_hash create_log 2 8225 _002869_hash NULL
86720 +_002870_hash crystalhd_create_dio_pool 2 3427 _002870_hash NULL
86721 +_002871_hash crystalhd_user_data 3 18407 _002871_hash NULL
86722 +_002872_hash do_pages_stat 2 4437 _002872_hash NULL
86723 +_002873_hash do_read_log_to_user 4 3236 _002873_hash NULL
86724 +_002874_hash do_write_log_from_user 3 39362 _002874_hash NULL
86725 +_002875_hash evm_read_key 3 54674 _002875_hash NULL
86726 +_002876_hash evm_write_key 3 27715 _002876_hash NULL
86727 +_002877_hash fir16_create 3 5574 _002877_hash NULL
86728 +_002878_hash get_nodes 3 39012 _002878_hash NULL
86729 +_002879_hash __iio_allocate_kfifo 2-3 55738 _002879_hash NULL
86730 +_002881_hash __iio_allocate_sw_ring_buffer 3 4843 _002881_hash NULL
86731 +_002882_hash iio_debugfs_read_reg 3 60908 _002882_hash NULL
86732 +_002883_hash iio_debugfs_write_reg 3 22742 _002883_hash NULL
86733 +_002884_hash iio_device_alloc 1 41440 _002884_hash NULL
86734 +_002885_hash iio_event_chrdev_read 3 54757 _002885_hash NULL
86735 +_002886_hash iio_read_first_n_kfifo 2 57910 _002886_hash NULL
86736 +_002887_hash iio_read_first_n_sw_rb 2 51911 _002887_hash NULL
86737 +_002888_hash ioapic_setup_resources 1 35255 _002888_hash NULL
86738 +_002889_hash keymap_store 4 45406 _002889_hash NULL
86739 +_002890_hash line6_alloc_sysex_buffer 4 28225 _002890_hash NULL
86740 +_002891_hash line6_dumpreq_initbuf 3 53123 _002891_hash NULL
86741 +_002892_hash line6_midibuf_init 2 52425 _002892_hash NULL
86742 +_002893_hash _malloc 1 54077 _002893_hash NULL
86743 +_002894_hash mei_read 3 6507 _002894_hash NULL
86744 +_002895_hash mei_write 3 4005 _002895_hash NULL
86745 +_002896_hash msg_set 3 51725 _002896_hash NULL
86746 +_002897_hash newpart 6 47485 _002897_hash NULL
86747 +_002898_hash OS_kmalloc 1 36909 _002898_hash NULL
86748 +_002899_hash OS_mem_token_alloc 1 14276 _002899_hash NULL
86749 +_002900_hash packet_came 3 18072 _002900_hash NULL
86750 +_002901_hash pcpu_alloc_bootmem 2 62074 _002901_hash NULL
86751 +_002902_hash pcpu_build_alloc_info 1-3-2 41443 _002902_hash NULL
86752 +_002905_hash pcpu_get_vm_areas 3 50085 _002905_hash NULL
86753 +_002906_hash resource_from_user 3 30341 _002906_hash NULL
86754 +_002907_hash rtsx_read_cfg_seq 3-5 48139 _002907_hash NULL
86755 +_002909_hash rtsx_write_cfg_seq 3-5 27485 _002909_hash NULL
86756 +_002911_hash sca3000_read_data 4 57064 _002911_hash NULL
86757 +_002912_hash sca3000_read_first_n_hw_rb 2 11479 _002912_hash NULL
86758 +_002913_hash send_midi_async 3 57463 _002913_hash NULL
86759 +_002914_hash sep_create_dcb_dmatables_context 6 37551 _002914_hash NULL
86760 +_002915_hash sep_create_dcb_dmatables_context_kernel 6 49728 _002915_hash NULL
86761 +_002916_hash sep_create_msgarea_context 4 33829 _002916_hash NULL
86762 +_002917_hash sep_lli_table_secure_dma 2-3 64042 _002917_hash NULL
86763 +_002919_hash sep_lock_user_pages 2-3 57470 _002919_hash &_002488_hash
86764 +_002921_hash sep_prepare_input_output_dma_table_in_dcb 4-5-2-3 63087 _002921_hash NULL
86765 +_002923_hash sep_read 3 17161 _002923_hash NULL
86766 +_002924_hash TransmitTcb 4 12989 _002924_hash NULL
86767 +_002925_hash ValidateDSDParamsChecksum 3 63654 _002925_hash NULL
86768 +_002926_hash Wb35Reg_BurstWrite 4 62327 _002926_hash NULL
86769 +_002927_hash alloc_irq_cpu_rmap 1 28459 _002927_hash NULL
86770 +_002928_hash InterfaceTransmitPacket 3 42058 _002928_hash NULL
86771 +_002929_hash line6_dumpreq_init 3 34473 _002929_hash NULL
86772 +_002931_hash pcpu_embed_first_chunk 1-3-2 24224 _002931_hash NULL
86773 +_002933_hash pcpu_fc_alloc 2 11818 _002933_hash NULL
86774 +_002934_hash pcpu_page_first_chunk 1 20712 _002934_hash NULL
86775 +_002935_hash pod_alloc_sysex_buffer 3 31651 _002935_hash NULL
86776 +_002936_hash r8712_usbctrl_vendorreq 6 48489 _002936_hash NULL
86777 +_002937_hash r871x_set_wpa_ie 3 7000 _002937_hash NULL
86778 +_002938_hash sep_prepare_input_dma_table 2-3 2009 _002938_hash NULL
86779 +_002940_hash sep_prepare_input_output_dma_table 2-4-3 63429 _002940_hash NULL
86780 +_002943_hash sys_get_mempolicy 3 30379 _002943_hash NULL
86781 +_002944_hash sys_mbind 5 7990 _002944_hash NULL
86782 +_002945_hash sys_migrate_pages 2 39825 _002945_hash NULL
86783 +_002946_hash sys_move_pages 2 42626 _002946_hash NULL
86784 +_002947_hash sys_set_mempolicy 3 32608 _002947_hash NULL
86785 +_002948_hash variax_alloc_sysex_buffer 3 15237 _002948_hash NULL
86786 +_002949_hash vme_user_read 3 55338 _002949_hash NULL
86787 +_002950_hash vme_user_write 3 15587 _002950_hash NULL
86788 +_002954_hash variax_set_raw2 4 32374 _002954_hash NULL
86789 +_002955_hash copy_in_user 3 57502 _002955_hash NULL
86790 +_002956_hash __earlyonly_bootmem_alloc 2 23824 _002956_hash NULL
86791 +_002957_hash rfc4106_set_key 3 54519 _002957_hash NULL
86792 +_002958_hash sparse_early_usemaps_alloc_pgdat_section 2 62304 _002958_hash NULL
86793 +_002959_hash sparse_early_usemaps_alloc_node 4 9269 _002959_hash NULL
86794 +_002960_hash sparse_mem_maps_populate_node 4 12669 _002960_hash &_002242_hash
86795 +_002961_hash vmemmap_alloc_block 1 43245 _002961_hash NULL
86796 +_002962_hash sparse_early_mem_maps_alloc_node 4 36971 _002962_hash NULL
86797 +_002963_hash vmemmap_alloc_block_buf 1 61126 _002963_hash NULL
86798 +_002964_hash alloc_mr 1 45935 _002964_hash NULL
86799 +_002965_hash atomic_counters_read 3 48827 _002965_hash NULL
86800 +_002966_hash atomic_stats_read 3 36228 _002966_hash NULL
86801 +_002967_hash capabilities_read 3 58457 _002967_hash NULL
86802 +_002968_hash compat_core_sys_select 1 65285 _002968_hash NULL
86803 +_002969_hash compat_dccp_setsockopt 5 51263 _002969_hash NULL
86804 +_002970_hash compat_do_arpt_set_ctl 4 12184 _002970_hash NULL
86805 +_002971_hash compat_do_ip6t_set_ctl 4 3184 _002971_hash NULL
86806 +_002972_hash compat_do_ipt_set_ctl 4 58466 _002972_hash &_002078_hash
86807 +_002973_hash compat_filldir 3 32999 _002973_hash NULL
86808 +_002974_hash compat_filldir64 3 35354 _002974_hash NULL
86809 +_002975_hash compat_fillonedir 3 15620 _002975_hash NULL
86810 +_002976_hash compat_ip_setsockopt 5 13870 _003094_hash NULL nohasharray
86811 +_002977_hash compat_ipv6_setsockopt 5 20468 _002977_hash NULL
86812 +_002978_hash compat_mpctl_ioctl 2 45671 _002978_hash NULL
86813 +_002979_hash compat_raw_setsockopt 5 30634 _002979_hash NULL
86814 +_002980_hash compat_rawv6_setsockopt 5 4967 _002980_hash NULL
86815 +_002981_hash compat_rw_copy_check_uvector 3 22001 _003263_hash NULL nohasharray
86816 +_002982_hash compat_sock_setsockopt 5 23 _002982_hash NULL
86817 +_002983_hash compat_sys_get_mempolicy 3 31109 _002983_hash NULL
86818 +_002984_hash compat_sys_kexec_load 2 35674 _002984_hash NULL
86819 +_002985_hash compat_sys_keyctl 4 9639 _002985_hash NULL
86820 +_002986_hash compat_sys_mbind 5 36256 _002986_hash NULL
86821 +_002987_hash compat_sys_migrate_pages 2 3157 _002987_hash NULL
86822 +_002988_hash compat_sys_move_pages 2 5861 _002988_hash NULL
86823 +_002989_hash compat_sys_mq_timedsend 3 31060 _002989_hash NULL
86824 +_002990_hash compat_sys_msgrcv 2 7482 _002990_hash NULL
86825 +_002991_hash compat_sys_msgsnd 2 10738 _002991_hash NULL
86826 +_002992_hash compat_sys_semtimedop 3 3606 _002992_hash NULL
86827 +_002993_hash compat_sys_set_mempolicy 3 57742 _002993_hash &_002614_hash
86828 +_002994_hash __copy_in_user 3 34790 _002994_hash NULL
86829 +_002995_hash dev_counters_read 3 19216 _002995_hash NULL
86830 +_002996_hash dev_names_read 3 38509 _002996_hash NULL
86831 +_002997_hash driver_names_read 3 60399 _002997_hash NULL
86832 +_002998_hash driver_stats_read 3 8944 _002998_hash NULL
86833 +_002999_hash evdev_ioctl_compat 2 13851 _002999_hash NULL
86834 +_003000_hash evtchn_read 3 3569 _003000_hash NULL
86835 +_003001_hash evtchn_write 3 43278 _003001_hash NULL
86836 +_003002_hash fat_compat_ioctl_filldir 3 36328 _003002_hash NULL
86837 +_003003_hash flash_read 3 57843 _003003_hash NULL
86838 +_003004_hash flash_write 3 62354 _003004_hash NULL
86839 +_003005_hash fw_device_op_compat_ioctl 2 42804 _003005_hash NULL
86840 +_003006_hash gather_array 3 56641 _003006_hash NULL
86841 +_003007_hash ghash_async_setkey 3 60001 _003007_hash NULL
86842 +_003008_hash gntdev_alloc_map 2 35145 _003008_hash NULL
86843 +_003009_hash gnttab_map 2 56439 _003009_hash NULL
86844 +_003010_hash gru_alloc_gts 2-3 60056 _003010_hash &_000981_hash
86845 +_003012_hash hiddev_compat_ioctl 2 41255 _003012_hash NULL
86846 +_003013_hash init_cdev 1 8274 _003013_hash NULL
86847 +_003014_hash init_per_cpu 1 17880 _003014_hash NULL
86848 +_003015_hash ipath_create_cq 2 45586 _003015_hash NULL
86849 +_003016_hash ipath_get_base_info 3 7043 _003016_hash NULL
86850 +_003017_hash ipath_init_qp_table 2 25167 _003017_hash NULL
86851 +_003018_hash ipath_resize_cq 2 712 _003018_hash NULL
86852 +_003019_hash joydev_compat_ioctl 2 8765 _003019_hash NULL
86853 +_003020_hash mon_bin_compat_ioctl 3 50234 _003020_hash NULL
86854 +_003021_hash options_write 3 47243 _003021_hash NULL
86855 +_003022_hash portcntrs_1_read 3 47253 _003022_hash NULL
86856 +_003023_hash portcntrs_2_read 3 56586 _003023_hash NULL
86857 +_003024_hash portnames_read 3 41958 _003024_hash NULL
86858 +_003025_hash ptc_proc_write 3 12076 _003025_hash NULL
86859 +_003026_hash put_cmsg_compat 4 35937 _003026_hash NULL
86860 +_003027_hash qib_alloc_devdata 2 51819 _003027_hash NULL
86861 +_003028_hash qib_alloc_fast_reg_page_list 2 10507 _003028_hash NULL
86862 +_003029_hash qib_cdev_init 1 34778 _003029_hash NULL
86863 +_003030_hash qib_create_cq 2 27497 _003030_hash NULL
86864 +_003031_hash qib_diag_write 3 62133 _003031_hash NULL
86865 +_003032_hash qib_get_base_info 3 11369 _003032_hash NULL
86866 +_003033_hash qib_resize_cq 2 53090 _003033_hash NULL
86867 +_003034_hash qsfp_1_read 3 21915 _003034_hash NULL
86868 +_003035_hash qsfp_2_read 3 31491 _003035_hash NULL
86869 +_003036_hash queue_reply 3 22416 _003036_hash NULL
86870 +_003037_hash spidev_compat_ioctl 2 63778 _003037_hash NULL
86871 +_003038_hash split 2 11691 _003038_hash NULL
86872 +_003039_hash stats_read_ul 3 32751 _003039_hash NULL
86873 +_003040_hash sys32_ipc 3 7238 _003040_hash NULL
86874 +_003041_hash sys32_rt_sigpending 2 25814 _003041_hash NULL
86875 +_003042_hash tunables_read 3 36385 _003042_hash NULL
86876 +_003043_hash tunables_write 3 59563 _003043_hash NULL
86877 +_003044_hash xenbus_file_write 3 6282 _003044_hash NULL
86878 +_003045_hash xlbd_reserve_minors 1-2 18365 _003045_hash NULL
86879 +_003047_hash xpc_kmalloc_cacheline_aligned 1 42895 _003047_hash NULL
86880 +_003048_hash xpc_kzalloc_cacheline_aligned 1 65433 _003048_hash NULL
86881 +_003049_hash xsd_read 3 15653 _003049_hash NULL
86882 +_003050_hash compat_do_readv_writev 4 49102 _003050_hash NULL
86883 +_003051_hash compat_keyctl_instantiate_key_iov 3 57431 _003088_hash NULL nohasharray
86884 +_003052_hash compat_process_vm_rw 3-5 22254 _003052_hash NULL
86885 +_003054_hash compat_sys_select 1 16131 _003054_hash NULL
86886 +_003055_hash compat_sys_setsockopt 5 3326 _003055_hash NULL
86887 +_003056_hash compat_udp_setsockopt 5 38840 _003056_hash NULL
86888 +_003057_hash compat_udpv6_setsockopt 5 42981 _003057_hash NULL
86889 +_003058_hash do_compat_pselect 1 10398 _003058_hash NULL
86890 +_003059_hash gnttab_expand 1 15817 _003059_hash NULL
86891 +_003060_hash ipath_cdev_init 1 37752 _003060_hash NULL
86892 +_003061_hash ipath_reg_phys_mr 3 23918 _003061_hash &_000999_hash
86893 +_003062_hash qib_alloc_fast_reg_mr 2 12526 _003062_hash NULL
86894 +_003063_hash qib_reg_phys_mr 3 60202 _003063_hash &_000897_hash
86895 +_003064_hash compat_readv 3 30273 _003064_hash NULL
86896 +_003065_hash compat_sys_process_vm_readv 3-5 15374 _003065_hash NULL
86897 +_003067_hash compat_sys_process_vm_writev 3-5 41194 _003067_hash NULL
86898 +_003069_hash compat_sys_pselect6 1 14105 _003069_hash NULL
86899 +_003070_hash compat_writev 3 60063 _003070_hash NULL
86900 +_003071_hash get_free_entries 1 46030 _003071_hash NULL
86901 +_003072_hash compat_sys_preadv64 3 24283 _003072_hash NULL
86902 +_003073_hash compat_sys_pwritev64 3 51151 _003073_hash NULL
86903 +_003074_hash compat_sys_readv 3 20911 _003074_hash NULL
86904 +_003075_hash compat_sys_writev 3 5784 _003075_hash NULL
86905 +_003076_hash gnttab_alloc_grant_references 1 18240 _003076_hash NULL
86906 +_003077_hash compat_sys_preadv 3 583 _003077_hash NULL
86907 +_003078_hash compat_sys_pwritev 3 17886 _003078_hash NULL
86908 +_003079_hash aes_decrypt_fail_read 3 54815 _003079_hash NULL
86909 +_003080_hash aes_decrypt_interrupt_read 3 19910 _003080_hash NULL
86910 +_003081_hash aes_decrypt_packets_read 3 10155 _003081_hash NULL
86911 +_003082_hash aes_encrypt_fail_read 3 32562 _003082_hash NULL
86912 +_003083_hash aes_encrypt_interrupt_read 3 39919 _003083_hash NULL
86913 +_003084_hash aes_encrypt_packets_read 3 48666 _003084_hash NULL
86914 +_003085_hash agp_remap 2 30665 _003085_hash NULL
86915 +_003086_hash alloc_apertures 1 56561 _003086_hash NULL
86916 +_003087_hash allocate_probes 1 40204 _003087_hash NULL
86917 +_003088_hash alloc_ftrace_hash 1 57431 _003088_hash &_003051_hash
86918 +_003089_hash alloc_page_cgroup 1 2919 _003089_hash NULL
86919 +_003090_hash __alloc_preds 2 9492 _003090_hash NULL
86920 +_003091_hash __alloc_pred_stack 2 26687 _003091_hash NULL
86921 +_003092_hash alloc_sched_domains 1 47756 _003092_hash NULL
86922 +_003093_hash alloc_trace_probe 6 38720 _003093_hash NULL
86923 +_003094_hash alloc_trace_uprobe 3 13870 _003094_hash &_002976_hash
86924 +_003095_hash ath6kl_sdio_alloc_prep_scat_req 2 51986 _003095_hash NULL
86925 +_003096_hash ath6kl_usb_post_recv_transfers 2 32892 _003096_hash NULL
86926 +_003097_hash ath6kl_usb_submit_ctrl_in 6 32880 _003097_hash &_000795_hash
86927 +_003098_hash ath6kl_usb_submit_ctrl_out 6 9978 _003098_hash NULL
86928 +_003099_hash av7110_ipack_init 2 46655 _003099_hash NULL
86929 +_003100_hash av7110_vbi_write 3 34384 _003100_hash NULL
86930 +_003101_hash bin_uuid 3 28999 _003101_hash NULL
86931 +_003102_hash blk_dropped_read 3 4168 _003102_hash NULL
86932 +_003103_hash blk_msg_write 3 13655 _003103_hash NULL
86933 +_003104_hash brcmf_usbdev_qinit 2 19090 _003104_hash &_001715_hash
86934 +_003105_hash brcmf_usb_dl_cmd 4 53130 _003105_hash NULL
86935 +_003106_hash ci_ll_init 3 12930 _003106_hash NULL
86936 +_003107_hash ci_ll_write 4 3740 _003107_hash NULL
86937 +_003108_hash conf_read 3 55786 _003108_hash NULL
86938 +_003109_hash __copy_from_user_inatomic_nocache 3 49921 _003109_hash NULL
86939 +_003110_hash cx24116_writeregN 4 41975 _003110_hash NULL
86940 +_003111_hash cyttsp_probe 4 1940 _003111_hash NULL
86941 +_003112_hash dccpprobe_read 3 52549 _003112_hash NULL
86942 +_003113_hash ddb_input_read 3 9743 _003113_hash NULL
86943 +_003114_hash ddb_output_write 3 31902 _003114_hash NULL
86944 +_003115_hash __devres_alloc 2 25598 _003115_hash NULL
86945 +_003116_hash dma_rx_errors_read 3 52045 _003116_hash NULL
86946 +_003117_hash dma_rx_requested_read 3 65354 _003117_hash NULL
86947 +_003118_hash dma_tx_errors_read 3 46060 _003118_hash NULL
86948 +_003119_hash dma_tx_requested_read 3 16110 _003203_hash NULL nohasharray
86949 +_003120_hash do_dmabuf_dirty_sou 7 3017 _003120_hash NULL
86950 +_003121_hash do_surface_dirty_sou 7 39678 _003121_hash NULL
86951 +_003122_hash driver_state_read 3 17194 _003122_hash &_001511_hash
86952 +_003123_hash drm_agp_bind_pages 3 56748 _003123_hash NULL
86953 +_003124_hash drm_buffer_alloc 2 44405 _003124_hash NULL
86954 +_003125_hash drm_calloc_large 1-2 65421 _003125_hash NULL
86955 +_003127_hash drm_fb_helper_init 3-4 19044 _003127_hash NULL
86956 +_003129_hash drm_ht_create 2 18853 _003129_hash NULL
86957 +_003130_hash drm_ioctl 2 42813 _003130_hash NULL
86958 +_003131_hash drm_malloc_ab 1-2 16831 _003131_hash NULL
86959 +_003133_hash drm_mode_crtc_set_gamma_size 2 31881 _003133_hash NULL
86960 +_003134_hash drm_plane_init 6 28731 _003134_hash NULL
86961 +_003135_hash drm_property_create 4 51239 _003135_hash NULL
86962 +_003136_hash drm_property_create_blob 2 7414 _003136_hash NULL
86963 +_003137_hash drm_vblank_init 2 11362 _003137_hash NULL
86964 +_003138_hash drm_vmalloc_dma 1 14550 _003138_hash NULL
86965 +_003139_hash dvb_aplay 3 56296 _003139_hash NULL
86966 +_003140_hash dvb_ca_en50221_init 4 45718 _003140_hash NULL
86967 +_003141_hash dvb_ca_en50221_io_write 3 43533 _003141_hash NULL
86968 +_003142_hash dvb_dmxdev_set_buffer_size 2 55643 _003142_hash NULL
86969 +_003143_hash dvbdmx_write 3 19423 _003143_hash NULL
86970 +_003144_hash dvb_dvr_set_buffer_size 2 9840 _003144_hash NULL
86971 +_003145_hash dvb_net_sec 3 37884 _003145_hash NULL
86972 +_003146_hash dvb_play 3 50814 _003146_hash NULL
86973 +_003147_hash dvb_ringbuffer_pkt_read_user 2-5-3 4303 _003147_hash NULL
86974 +_003150_hash dvb_ringbuffer_read_user 3 56702 _003150_hash NULL
86975 +_003151_hash dvb_usercopy 2 14036 _003151_hash NULL
86976 +_003152_hash dw210x_op_rw 6 39915 _003152_hash NULL
86977 +_003153_hash edt_ft5x06_debugfs_raw_data_read 3 28002 _003153_hash NULL
86978 +_003154_hash em_canid_change 3 14150 _003154_hash NULL
86979 +_003155_hash event_calibration_read 3 21083 _003155_hash NULL
86980 +_003156_hash event_enable_read 3 7074 _003156_hash NULL
86981 +_003157_hash event_filter_read 3 23494 _003157_hash NULL
86982 +_003158_hash event_filter_write 3 56609 _003158_hash NULL
86983 +_003159_hash event_heart_beat_read 3 48961 _003159_hash NULL
86984 +_003160_hash event_id_read 3 64288 _003160_hash &_001300_hash
86985 +_003161_hash event_oom_late_read 3 61175 _003161_hash &_001054_hash
86986 +_003162_hash event_phy_transmit_error_read 3 10471 _003162_hash NULL
86987 +_003163_hash event_rx_mem_empty_read 3 40363 _003163_hash NULL
86988 +_003164_hash event_rx_mismatch_read 3 38518 _003164_hash NULL
86989 +_003165_hash event_rx_pool_read 3 25792 _003165_hash NULL
86990 +_003166_hash event_tx_stuck_read 3 19305 _003166_hash NULL
86991 +_003167_hash excessive_retries_read 3 60425 _003167_hash NULL
86992 +_003168_hash flexcop_device_kmalloc 1 54793 _003168_hash NULL
86993 +_003169_hash fm_send_cmd 5 39639 _003169_hash NULL
86994 +_003170_hash __fprog_create 2 41263 _003170_hash NULL
86995 +_003171_hash fq_codel_zalloc 1 15378 _003171_hash NULL
86996 +_003172_hash ftrace_pid_write 3 39710 _003172_hash NULL
86997 +_003173_hash ftrace_profile_read 3 21327 _003173_hash NULL
86998 +_003174_hash fw_stats_raw_read 3 1369 _003174_hash NULL
86999 +_003175_hash get_info 3 55681 _003175_hash NULL
87000 +_003176_hash __get_vm_area_node 1 55305 _003176_hash NULL
87001 +_003177_hash gpio_power_read 3 36059 _003177_hash NULL
87002 +_003178_hash h5_prepare_pkt 4 12085 _003178_hash NULL
87003 +_003179_hash hsc_msg_alloc 1 60990 _003179_hash NULL
87004 +_003180_hash hsc_write 3 55875 _003180_hash NULL
87005 +_003181_hash hsi_alloc_controller 1 41802 _003181_hash NULL
87006 +_003182_hash hsi_register_board_info 2 13820 _003182_hash NULL
87007 +_003183_hash hugetlb_cgroup_read 5 49259 _003183_hash NULL
87008 +_003184_hash i915_cache_sharing_read 3 24775 _003184_hash NULL
87009 +_003185_hash i915_cache_sharing_write 3 57961 _003185_hash NULL
87010 +_003186_hash i915_max_freq_read 3 20581 _003186_hash NULL
87011 +_003187_hash i915_max_freq_write 3 11350 _003187_hash NULL
87012 +_003188_hash i915_min_freq_read 3 38470 _003188_hash NULL
87013 +_003189_hash i915_min_freq_write 3 10981 _003189_hash NULL
87014 +_003190_hash i915_ring_stop_read 3 42549 _003190_hash &_000740_hash
87015 +_003191_hash i915_ring_stop_write 3 59010 _003191_hash NULL
87016 +_003192_hash i915_wedged_read 3 35474 _003192_hash NULL
87017 +_003193_hash i915_wedged_write 3 47771 _003193_hash NULL
87018 +_003194_hash ieee802154_alloc_device 1 13767 _003194_hash NULL
87019 +_003195_hash intel_sdvo_write_cmd 4 54377 _003195_hash &_000832_hash
87020 +_003196_hash isr_cmd_cmplt_read 3 53439 _003196_hash NULL
87021 +_003197_hash isr_commands_read 3 41398 _003197_hash NULL
87022 +_003198_hash isr_decrypt_done_read 3 49490 _003198_hash NULL
87023 +_003199_hash isr_dma0_done_read 3 8574 _003199_hash NULL
87024 +_003200_hash isr_dma1_done_read 3 48159 _003200_hash NULL
87025 +_003201_hash isr_fiqs_read 3 34687 _003201_hash NULL
87026 +_003202_hash isr_host_acknowledges_read 3 54136 _003202_hash NULL
87027 +_003203_hash isr_hw_pm_mode_changes_read 3 16110 _003203_hash &_003119_hash
87028 +_003204_hash isr_irqs_read 3 9181 _003204_hash NULL
87029 +_003205_hash isr_low_rssi_read 3 64789 _003205_hash NULL
87030 +_003206_hash isr_pci_pm_read 3 30271 _003206_hash NULL
87031 +_003207_hash isr_rx_headers_read 3 38325 _003207_hash NULL
87032 +_003208_hash isr_rx_mem_overflow_read 3 43025 _003208_hash NULL
87033 +_003209_hash isr_rx_procs_read 3 31804 _003209_hash NULL
87034 +_003210_hash isr_rx_rdys_read 3 35283 _003210_hash NULL
87035 +_003211_hash isr_tx_exch_complete_read 3 16103 _003211_hash NULL
87036 +_003212_hash isr_tx_procs_read 3 23084 _003212_hash NULL
87037 +_003213_hash isr_wakeups_read 3 49607 _003213_hash NULL
87038 +_003214_hash LoadBitmap 2 19658 _003214_hash NULL
87039 +_003215_hash mem_cgroup_read 5 22461 _003215_hash NULL
87040 +_003216_hash mic_calc_failure_read 3 59700 _003216_hash NULL
87041 +_003217_hash mic_rx_pkts_read 3 27972 _003217_hash NULL
87042 +_003218_hash __module_alloc 1 50004 _003218_hash NULL
87043 +_003219_hash module_alloc_update_bounds_rw 1 63233 _003219_hash NULL
87044 +_003220_hash module_alloc_update_bounds_rx 1 58634 _003220_hash NULL
87045 +_003221_hash mwifiex_usb_submit_rx_urb 2 54558 _003221_hash NULL
87046 +_003222_hash nfc_hci_hcp_message_tx 6 14534 _003222_hash NULL
87047 +_003223_hash nfc_hci_set_param 5 40697 _003223_hash NULL
87048 +_003224_hash nfc_shdlc_alloc_skb 2 12741 _003224_hash NULL
87049 +_003225_hash opera1_xilinx_rw 5 31453 _003225_hash NULL
87050 +_003226_hash persistent_ram_vmap 1-2 709 _003226_hash NULL
87051 +_003228_hash prctl_set_mm 3 64538 _003228_hash NULL
87052 +_003229_hash probe_kernel_write 3 17481 _003229_hash NULL
87053 +_003230_hash proc_fault_inject_read 3 36802 _003230_hash NULL
87054 +_003231_hash proc_fault_inject_write 3 21058 _003231_hash NULL
87055 +_003232_hash ps_pspoll_max_apturn_read 3 6699 _003232_hash NULL
87056 +_003233_hash ps_pspoll_timeouts_read 3 11776 _003233_hash NULL
87057 +_003234_hash ps_pspoll_utilization_read 3 5361 _003234_hash NULL
87058 +_003235_hash ps_upsd_max_apturn_read 3 19918 _003235_hash NULL
87059 +_003236_hash ps_upsd_max_sptime_read 3 63362 _003236_hash NULL
87060 +_003237_hash ps_upsd_timeouts_read 3 28924 _003237_hash NULL
87061 +_003238_hash ps_upsd_utilization_read 3 51669 _003238_hash NULL
87062 +_003239_hash ptp_filter_init 2 36780 _003239_hash NULL
87063 +_003240_hash pwr_disable_ps_read 3 13176 _003240_hash NULL
87064 +_003241_hash pwr_elp_enter_read 3 5324 _003241_hash NULL
87065 +_003242_hash pwr_enable_ps_read 3 17686 _003242_hash NULL
87066 +_003243_hash pwr_fix_tsf_ps_read 3 26627 _003243_hash NULL
87067 +_003244_hash pwr_missing_bcns_read 3 25824 _003244_hash NULL
87068 +_003245_hash pwr_power_save_off_read 3 18355 _003245_hash NULL
87069 +_003246_hash pwr_ps_enter_read 3 26935 _003246_hash &_000512_hash
87070 +_003247_hash pwr_rcvd_awake_beacons_read 3 50505 _003247_hash NULL
87071 +_003248_hash pwr_rcvd_beacons_read 3 52836 _003248_hash NULL
87072 +_003249_hash pwr_tx_without_ps_read 3 48423 _003249_hash NULL
87073 +_003250_hash pwr_tx_with_ps_read 3 60851 _003250_hash NULL
87074 +_003251_hash pwr_wake_on_host_read 3 26321 _003251_hash NULL
87075 +_003252_hash pwr_wake_on_timer_exp_read 3 22640 _003252_hash NULL
87076 +_003253_hash rb_simple_read 3 45972 _003253_hash NULL
87077 +_003254_hash read_file_dfs 3 43145 _003254_hash NULL
87078 +_003255_hash retry_count_read 3 52129 _003255_hash NULL
87079 +_003256_hash rx_dropped_read 3 44799 _003256_hash NULL
87080 +_003257_hash rx_fcs_err_read 3 62844 _003257_hash NULL
87081 +_003258_hash rx_hdr_overflow_read 3 64407 _003258_hash NULL
87082 +_003259_hash rx_hw_stuck_read 3 57179 _003259_hash NULL
87083 +_003260_hash rx_out_of_mem_read 3 10157 _003260_hash NULL
87084 +_003261_hash rx_path_reset_read 3 23801 _003261_hash NULL
87085 +_003262_hash rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 _003262_hash NULL
87086 +_003263_hash rxpipe_descr_host_int_trig_rx_data_read 3 22001 _003263_hash &_002981_hash
87087 +_003264_hash rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 _003264_hash NULL
87088 +_003265_hash rxpipe_rx_prep_beacon_drop_read 3 2403 _003265_hash NULL
87089 +_003266_hash rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 _003266_hash NULL
87090 +_003267_hash rx_reset_counter_read 3 58001 _003267_hash NULL
87091 +_003268_hash rx_xfr_hint_trig_read 3 40283 _003268_hash NULL
87092 +_003269_hash saa7146_vmalloc_build_pgtable 2 19780 _003269_hash NULL
87093 +_003270_hash sched_feat_write 3 55202 _003270_hash NULL
87094 +_003271_hash sd_alloc_ctl_entry 1 29708 _003271_hash NULL
87095 +_003272_hash shmem_pread_fast 3 34147 _003272_hash NULL
87096 +_003273_hash shmem_pread_slow 3 3198 _003273_hash NULL
87097 +_003274_hash shmem_pwrite_slow 3 31741 _003274_hash NULL
87098 +_003275_hash show_header 3 4722 _003275_hash &_000745_hash
87099 +_003276_hash stack_max_size_read 3 1445 _003276_hash NULL
87100 +_003277_hash subsystem_filter_read 3 62310 _003277_hash NULL
87101 +_003278_hash subsystem_filter_write 3 13022 _003278_hash NULL
87102 +_003279_hash swap_cgroup_swapon 2 13614 _003279_hash NULL
87103 +_003280_hash system_enable_read 3 25815 _003280_hash NULL
87104 +_003281_hash tda10048_writeregbulk 4 11050 _003281_hash NULL
87105 +_003282_hash tlbflush_read_file 3 64661 _003282_hash NULL
87106 +_003283_hash trace_options_core_read 3 47390 _003283_hash NULL
87107 +_003284_hash trace_options_read 3 11419 _003284_hash NULL
87108 +_003285_hash trace_parser_get_init 2 31379 _003285_hash NULL
87109 +_003286_hash traceprobe_probes_write 3 64969 _003286_hash NULL
87110 +_003287_hash trace_seq_to_user 3 65398 _003287_hash NULL
87111 +_003288_hash tracing_buffers_read 3 11124 _003288_hash NULL
87112 +_003289_hash tracing_clock_write 3 27961 _003289_hash NULL
87113 +_003290_hash tracing_cpumask_read 3 7010 _003290_hash NULL
87114 +_003291_hash tracing_ctrl_read 3 46922 _003291_hash NULL
87115 +_003292_hash tracing_entries_read 3 8345 _003292_hash NULL
87116 +_003293_hash tracing_max_lat_read 3 8890 _003293_hash NULL
87117 +_003294_hash tracing_read_dyn_info 3 45468 _003294_hash NULL
87118 +_003295_hash tracing_readme_read 3 16493 _003295_hash NULL
87119 +_003296_hash tracing_saved_cmdlines_read 3 21434 _003296_hash NULL
87120 +_003297_hash tracing_set_trace_read 3 44122 _003297_hash NULL
87121 +_003298_hash tracing_set_trace_write 3 57096 _003298_hash NULL
87122 +_003299_hash tracing_stats_read 3 34537 _003299_hash NULL
87123 +_003300_hash tracing_total_entries_read 3 62817 _003300_hash NULL
87124 +_003301_hash tracing_trace_options_write 3 153 _003301_hash NULL
87125 +_003302_hash tstats_write 3 60432 _003302_hash &_000009_hash
87126 +_003303_hash ttm_bo_fbdev_io 4 9805 _003303_hash NULL
87127 +_003304_hash ttm_bo_io 5 47000 _003304_hash NULL
87128 +_003305_hash ttm_dma_page_pool_free 2 34135 _003305_hash NULL
87129 +_003306_hash ttm_page_pool_free 2 61661 _003306_hash NULL
87130 +_003307_hash ttusb2_msg 4 3100 _003307_hash NULL
87131 +_003308_hash tx_internal_desc_overflow_read 3 47300 _003308_hash NULL
87132 +_003309_hash tx_queue_len_read 3 1463 _003309_hash NULL
87133 +_003310_hash tx_queue_status_read 3 44978 _003310_hash NULL
87134 +_003311_hash u_memcpya 2-3 30139 _003311_hash NULL
87135 +_003313_hash usb_allocate_stream_buffers 3 8964 _003313_hash NULL
87136 +_003314_hash vifs_state_read 3 33762 _003314_hash NULL
87137 +_003315_hash vmalloc_to_sg 2 58354 _003315_hash NULL
87138 +_003316_hash vm_map_ram 2 23078 _003316_hash &_001095_hash
87139 +_003317_hash vmw_execbuf_process 5 22885 _003317_hash NULL
87140 +_003318_hash vmw_fifo_reserve 2 12141 _003318_hash NULL
87141 +_003319_hash vmw_kms_present 9 38130 _003319_hash NULL
87142 +_003320_hash vmw_kms_readback 6 5727 _003320_hash NULL
87143 +_003321_hash wep_addr_key_count_read 3 20174 _003321_hash NULL
87144 +_003322_hash wep_decrypt_fail_read 3 58567 _003322_hash NULL
87145 +_003323_hash wep_default_key_count_read 3 43035 _003323_hash NULL
87146 +_003324_hash wep_interrupt_read 3 41492 _003324_hash NULL
87147 +_003325_hash wep_key_not_found_read 3 13377 _003325_hash &_000952_hash
87148 +_003326_hash wep_packets_read 3 18751 _003326_hash NULL
87149 +_003327_hash wl1251_cmd_template_set 4 6172 _003327_hash NULL
87150 +_003328_hash wl1271_format_buffer 2 20834 _003328_hash NULL
87151 +_003329_hash wl1271_rx_filter_alloc_field 5 46721 _003329_hash NULL
87152 +_003330_hash wl12xx_cmd_build_probe_req 6-8 54946 _003330_hash NULL
87153 +_003332_hash wlcore_alloc_hw 1 7785 _003332_hash NULL
87154 +_003333_hash aggr_size_rx_size_read 3 33526 _003333_hash NULL
87155 +_003334_hash aggr_size_tx_agg_vs_rate_read 3 21438 _003334_hash NULL
87156 +_003335_hash alloc_and_copy_ftrace_hash 1 29368 _003335_hash NULL
87157 +_003336_hash alloc_bulk_urbs_generic 5 12127 _003336_hash NULL
87158 +_003337_hash alloc_ieee80211 1 20063 _003337_hash NULL
87159 +_003338_hash alloc_ieee80211_rsl 1 34564 _003338_hash NULL
87160 +_003339_hash alloc_perm_bits 2 1532 _003339_hash NULL
87161 +_003340_hash alloc_private 2 22399 _003340_hash NULL
87162 +_003341_hash alloc_rtllib 1 51136 _003341_hash NULL
87163 +_003342_hash alloc_rx_desc_ring 2 18016 _003342_hash NULL
87164 +_003343_hash arcfb_write 3 8702 _003343_hash NULL
87165 +_003344_hash ath6kl_usb_bmi_read 3 48745 _003344_hash NULL
87166 +_003345_hash ath6kl_usb_bmi_write 3 2454 _003345_hash &_001020_hash
87167 +_003346_hash ath6kl_usb_ctrl_msg_exchange 4 33327 _003346_hash NULL
87168 +_003347_hash au0828_init_isoc 2-3 61917 _003347_hash NULL
87169 +_003349_hash auok190xfb_write 3 37001 _003349_hash NULL
87170 +_003350_hash beacon_interval_read 3 7091 _003350_hash NULL
87171 +_003351_hash brcmf_usb_attach 1-2 44656 _003351_hash NULL
87172 +_003353_hash broadsheetfb_write 3 39976 _003353_hash NULL
87173 +_003354_hash broadsheet_spiflash_rewrite_sector 2 54864 _003354_hash NULL
87174 +_003355_hash ci13xxx_add_device 3 14456 _003355_hash NULL
87175 +_003356_hash cmpk_message_handle_tx 4 54024 _003356_hash NULL
87176 +_003357_hash comedi_alloc_subdevices 2 29207 _003357_hash NULL
87177 +_003358_hash comedi_buf_alloc 3 24822 _003358_hash NULL
87178 +_003359_hash comedi_read 3 13199 _003359_hash NULL
87179 +_003360_hash comedi_write 3 47926 _003360_hash NULL
87180 +_003361_hash create_trace_probe 1 20175 _003361_hash NULL
87181 +_003362_hash create_trace_uprobe 1 13184 _003362_hash NULL
87182 +_003363_hash cx18_copy_buf_to_user 4 22735 _003363_hash NULL
87183 +_003364_hash cx231xx_init_bulk 2-3 47024 _003364_hash NULL
87184 +_003366_hash cx231xx_init_isoc 2-3 56453 _003366_hash NULL
87185 +_003368_hash cx231xx_init_vbi_isoc 2-3 28053 _003368_hash NULL
87186 +_003370_hash da9052_group_write 3 4534 _003370_hash NULL
87187 +_003371_hash debug_debug1_read 3 8856 _003371_hash NULL
87188 +_003372_hash debug_debug2_read 3 30526 _003372_hash NULL
87189 +_003373_hash debug_debug3_read 3 56894 _003373_hash NULL
87190 +_003374_hash debug_debug4_read 3 61367 _003374_hash NULL
87191 +_003375_hash debug_debug5_read 3 2291 _003375_hash NULL
87192 +_003376_hash debug_debug6_read 3 33168 _003376_hash NULL
87193 +_003377_hash dev_read 3 56369 _003377_hash NULL
87194 +_003378_hash do_dmabuf_dirty_ldu 6 52241 _003378_hash NULL
87195 +_003379_hash drm_compat_ioctl 2 51717 _003379_hash NULL
87196 +_003380_hash drm_mode_create_tv_properties 2 23122 _003380_hash NULL
87197 +_003381_hash drm_property_create_bitmask 5 30195 _003381_hash NULL
87198 +_003382_hash drm_property_create_enum 5 29201 _003382_hash NULL
87199 +_003383_hash dsp_buffer_alloc 2 11684 _003383_hash NULL
87200 +_003384_hash dt3155_alloc_coherent 2 58073 _003384_hash NULL
87201 +_003385_hash dtim_interval_read 3 654 _003385_hash NULL
87202 +_003386_hash dvb_audio_write 3 51275 _003386_hash NULL
87203 +_003387_hash dvb_ca_en50221_io_ioctl 2 26490 _003387_hash NULL
87204 +_003388_hash dvb_ca_write 3 41171 _003388_hash NULL
87205 +_003389_hash dvb_demux_ioctl 2 42733 _003389_hash NULL
87206 +_003390_hash dvb_dmxdev_buffer_read 4 20682 _003390_hash NULL
87207 +_003391_hash dvb_dvr_ioctl 2 49182 _003391_hash NULL
87208 +_003392_hash dvb_generic_ioctl 2 21810 _003392_hash NULL
87209 +_003393_hash dvb_net_ioctl 2 61559 _003393_hash NULL
87210 +_003394_hash dvb_net_sec_callback 2 28786 _003394_hash NULL
87211 +_003396_hash dvb_video_write 3 754 _003396_hash NULL
87212 +_003397_hash dynamic_ps_timeout_read 3 10110 _003397_hash NULL
87213 +_003398_hash easycap_alsa_vmalloc 2 14426 _003398_hash NULL
87214 +_003399_hash em28xx_alloc_isoc 4 46892 _003399_hash NULL
87215 +_003400_hash error_error_bar_retry_read 3 64305 _003400_hash NULL
87216 +_003401_hash error_error_frame_cts_nul_flid_read 3 17262 _003401_hash NULL
87217 +_003402_hash error_error_frame_read 3 39947 _003402_hash &_002436_hash
87218 +_003403_hash error_error_null_Frame_tx_start_read 3 55024 _003403_hash NULL
87219 +_003404_hash error_error_numll_frame_cts_start_read 3 47781 _003404_hash NULL
87220 +_003405_hash ext_sd_execute_read_data 9 48589 _003405_hash NULL
87221 +_003406_hash ext_sd_execute_write_data 9 8175 _003406_hash NULL
87222 +_003407_hash fast_user_write 5 20494 _003407_hash NULL
87223 +_003408_hash f_audio_buffer_alloc 1 41110 _003408_hash NULL
87224 +_003409_hash fb_alloc_cmap_gfp 2 20792 _003409_hash NULL
87225 +_003410_hash fbcon_do_set_font 2-3 4079 _003410_hash NULL
87226 +_003412_hash fb_read 3 33506 _003412_hash NULL
87227 +_003413_hash fb_sys_read 3 13778 _003413_hash NULL
87228 +_003414_hash fb_sys_write 3 33130 _003414_hash NULL
87229 +_003415_hash fb_write 3 46924 _003415_hash NULL
87230 +_003416_hash firmwareUpload 3 32794 _003416_hash NULL
87231 +_003417_hash fmc_send_cmd 5 20435 _003417_hash NULL
87232 +_003418_hash fops_read 3 40672 _003418_hash NULL
87233 +_003419_hash forced_ps_read 3 31685 _003419_hash NULL
87234 +_003420_hash frame_alloc 4 15981 _003420_hash NULL
87235 +_003421_hash framebuffer_alloc 1 59145 _003421_hash NULL
87236 +_003422_hash ftrace_write 3 29551 _003422_hash NULL
87237 +_003423_hash fw_download_code 3 13249 _003423_hash NULL
87238 +_003424_hash fwSendNullPacket 2 54618 _003424_hash NULL
87239 +_003425_hash gdm_wimax_netif_rx 3 43423 _003425_hash &_001810_hash
87240 +_003426_hash get_vm_area 1 18080 _003426_hash NULL
87241 +_003427_hash __get_vm_area 1 61599 _003427_hash NULL
87242 +_003428_hash get_vm_area_caller 1 10527 _003428_hash NULL
87243 +_003429_hash __get_vm_area_caller 1 56416 _003828_hash NULL nohasharray
87244 +_003430_hash gspca_dev_probe2 4 59833 _003430_hash NULL
87245 +_003431_hash hdpvr_read 3 9273 _003431_hash NULL
87246 +_003432_hash hecubafb_write 3 26942 _003432_hash NULL
87247 +_003433_hash i915_compat_ioctl 2 3656 _003433_hash NULL
87248 +_003434_hash i915_gem_execbuffer_relocate_slow 7 25355 _003434_hash NULL
87249 +_003435_hash ieee80211_alloc_txb 1-2 52477 _003435_hash NULL
87250 +_003437_hash ieee80211_authentication_req 3 63973 _003437_hash NULL
87251 +_003438_hash ieee80211_wx_set_gen_ie 3 51399 _003438_hash NULL
87252 +_003439_hash ieee80211_wx_set_gen_ie_rsl 3 3521 _003458_hash NULL nohasharray
87253 +_003440_hash intel_sdvo_set_value 4 2311 _003440_hash NULL
87254 +_003441_hash ir_lirc_transmit_ir 3 64403 _003441_hash NULL
87255 +_003442_hash irq_blk_threshold_read 3 33666 _003442_hash NULL
87256 +_003443_hash irq_pkt_threshold_read 3 33356 _003443_hash &_000154_hash
87257 +_003444_hash irq_timeout_read 3 54653 _003444_hash NULL
87258 +_003445_hash ivtv_buf_copy_from_user 4 25502 _003445_hash NULL
87259 +_003446_hash ivtv_copy_buf_to_user 4 6159 _003446_hash NULL
87260 +_003447_hash ivtvfb_write 3 40023 _003447_hash NULL
87261 +_003448_hash kgdb_hex2mem 3 24755 _003448_hash NULL
87262 +_003449_hash lirc_buffer_init 2-3 53282 _003449_hash NULL
87263 +_003451_hash lirc_write 3 20604 _003451_hash NULL
87264 +_003452_hash mce_request_packet 3 1073 _003452_hash NULL
87265 +_003453_hash media_entity_init 2-4 15870 _003453_hash &_001742_hash
87266 +_003455_hash mem_fw_gen_free_mem_blks_read 3 11413 _003455_hash NULL
87267 +_003456_hash mem_fwlog_free_mem_blks_read 3 59616 _003456_hash NULL
87268 +_003457_hash mem_rx_free_mem_blks_read 3 675 _003457_hash NULL
87269 +_003458_hash mem_tx_free_mem_blks_read 3 3521 _003458_hash &_003439_hash
87270 +_003459_hash metronomefb_write 3 8823 _003459_hash NULL
87271 +_003460_hash mga_compat_ioctl 2 52170 _003460_hash NULL
87272 +_003461_hash mmio_read 4 40348 _003461_hash NULL
87273 +_003462_hash netlink_send 5 38434 _003462_hash NULL
87274 +_003463_hash nfc_hci_execute_cmd 5 43882 _003463_hash NULL
87275 +_003464_hash nfc_hci_send_event 5 21452 _003464_hash NULL
87276 +_003465_hash nfc_hci_send_response 5 56462 _003465_hash NULL
87277 +_003466_hash ni_gpct_device_construct 5 610 _003466_hash NULL
87278 +_003467_hash nouveau_compat_ioctl 2 28305 _003467_hash NULL
87279 +_003468_hash odev_update 2 50169 _003468_hash NULL
87280 +_003469_hash opera1_usb_i2c_msgxfer 4 64521 _003469_hash NULL
87281 +_003470_hash OSDSetBlock 2-4 38986 _003470_hash NULL
87282 +_003472_hash oz_add_farewell 5 20652 _003472_hash NULL
87283 +_003473_hash oz_cdev_read 3 20659 _003473_hash NULL
87284 +_003474_hash oz_cdev_write 3 33852 _003474_hash NULL
87285 +_003475_hash oz_ep_alloc 2 5587 _003475_hash NULL
87286 +_003476_hash oz_events_read 3 47535 _003476_hash NULL
87287 +_003477_hash persistent_ram_buffer_map 1-2 11332 _003477_hash NULL
87288 +_003479_hash pipeline_cs_rx_packet_in_read 3 37089 _003479_hash NULL
87289 +_003480_hash pipeline_cs_rx_packet_out_read 3 58926 _003480_hash NULL
87290 +_003481_hash pipeline_csum_to_rx_xfer_swi_read 3 15403 _003481_hash NULL
87291 +_003482_hash pipeline_dec_packet_in_fifo_full_read 3 33052 _003482_hash NULL
87292 +_003483_hash pipeline_dec_packet_in_read 3 47076 _003483_hash NULL
87293 +_003484_hash pipeline_dec_packet_out_read 3 54052 _003484_hash NULL
87294 +_003485_hash pipeline_defrag_to_csum_swi_read 3 63037 _003485_hash NULL
87295 +_003486_hash pipeline_enc_rx_stat_fifo_int_read 3 7107 _003486_hash NULL
87296 +_003487_hash pipeline_enc_tx_stat_fifo_int_read 3 14680 _003487_hash NULL
87297 +_003488_hash pipeline_hs_tx_stat_fifo_int_read 3 15642 _003488_hash &_001260_hash
87298 +_003489_hash pipeline_pipeline_fifo_full_read 3 34095 _003489_hash NULL
87299 +_003490_hash pipeline_post_proc_swi_read 3 24108 _003490_hash NULL
87300 +_003491_hash pipeline_pre_proc_swi_read 3 3898 _003491_hash NULL
87301 +_003492_hash pipeline_pre_to_defrag_swi_read 3 56321 _003492_hash NULL
87302 +_003493_hash pipeline_rx_complete_stat_fifo_int_read 3 40671 _003493_hash NULL
87303 +_003494_hash pipeline_sec_frag_swi_read 3 30294 _003494_hash NULL
87304 +_003495_hash pipeline_tcp_rx_stat_fifo_int_read 3 26745 _003495_hash NULL
87305 +_003496_hash pipeline_tcp_tx_stat_fifo_int_read 3 32589 _003496_hash NULL
87306 +_003497_hash play_iframe 3 8219 _003497_hash NULL
87307 +_003498_hash probes_write 3 29711 _003498_hash NULL
87308 +_003499_hash psb_unlocked_ioctl 2 16926 _003499_hash &_002668_hash
87309 +_003500_hash ps_poll_ps_poll_max_ap_turn_read 3 53140 _003500_hash NULL
87310 +_003501_hash ps_poll_ps_poll_timeouts_read 3 5934 _003501_hash NULL
87311 +_003502_hash ps_poll_ps_poll_utilization_read 3 39383 _003502_hash NULL
87312 +_003503_hash ps_poll_upsd_max_ap_turn_read 3 42050 _003503_hash NULL
87313 +_003504_hash ps_poll_upsd_timeouts_read 3 36755 _003504_hash NULL
87314 +_003505_hash ps_poll_upsd_utilization_read 3 28519 _003505_hash NULL
87315 +_003506_hash pvr2_ioread_read 3 10720 _003506_hash &_001669_hash
87316 +_003507_hash pvr2_ioread_set_sync_key 3 59882 _003507_hash NULL
87317 +_003508_hash pvr2_stream_buffer_count 2 33719 _003508_hash NULL
87318 +_003509_hash pwr_connection_out_of_sync_read 3 35061 _003509_hash NULL
87319 +_003510_hash pwr_cont_miss_bcns_spread_read 3 39250 _003515_hash NULL nohasharray
87320 +_003511_hash pwr_missing_bcns_cnt_read 3 45113 _003511_hash NULL
87321 +_003512_hash pwr_rcvd_awake_bcns_cnt_read 3 12632 _003512_hash NULL
87322 +_003513_hash pwr_rcvd_bcns_cnt_read 3 4774 _003513_hash NULL
87323 +_003514_hash qc_capture 3 19298 _003514_hash NULL
87324 +_003515_hash r128_compat_ioctl 2 39250 _003515_hash &_003510_hash
87325 +_003516_hash radeon_compat_ioctl 2 59150 _003516_hash NULL
87326 +_003517_hash radeon_kms_compat_ioctl 2 51371 _003517_hash NULL
87327 +_003518_hash Realloc 2 34961 _003518_hash NULL
87328 +_003519_hash redrat3_transmit_ir 3 64244 _003519_hash NULL
87329 +_003520_hash reg_w_buf 3 27724 _003520_hash NULL
87330 +_003521_hash reg_w_ixbuf 4 34736 _003521_hash NULL
87331 +_003522_hash rtllib_alloc_txb 1-2 21687 _003522_hash NULL
87332 +_003524_hash rtllib_authentication_req 3 26713 _003524_hash NULL
87333 +_003525_hash rtllib_wx_set_gen_ie 3 59808 _003525_hash NULL
87334 +_003526_hash rts51x_transfer_data_partial 6 5735 _003526_hash NULL
87335 +_003527_hash rvmalloc 1 46873 _003527_hash NULL
87336 +_003528_hash rx_decrypt_key_not_found_read 3 37820 _003528_hash NULL
87337 +_003529_hash rx_defrag_called_read 3 1897 _003529_hash NULL
87338 +_003530_hash rx_defrag_decrypt_failed_read 3 41411 _003530_hash NULL
87339 +_003531_hash rx_defrag_init_called_read 3 35935 _003531_hash NULL
87340 +_003532_hash rx_defrag_in_process_called_read 3 59338 _003532_hash NULL
87341 +_003533_hash rx_defrag_need_decrypt_read 3 42253 _003533_hash NULL
87342 +_003534_hash rx_defrag_need_defrag_read 3 28117 _003534_hash NULL
87343 +_003535_hash rx_defrag_tkip_called_read 3 21031 _003535_hash NULL
87344 +_003536_hash rx_filter_accum_arp_pend_requests_read 3 11003 _003536_hash NULL
87345 +_003537_hash rx_filter_arp_filter_read 3 61914 _003537_hash NULL
87346 +_003538_hash rx_filter_beacon_filter_read 3 49279 _003538_hash NULL
87347 +_003539_hash rx_filter_data_filter_read 3 30098 _003539_hash NULL
87348 +_003540_hash rx_filter_dup_filter_read 3 37238 _003540_hash NULL
87349 +_003541_hash rx_filter_ibss_filter_read 3 50167 _003541_hash NULL
87350 +_003542_hash rx_filter_max_arp_queue_dep_read 3 5851 _003542_hash NULL
87351 +_003543_hash rx_filter_mc_filter_read 3 25712 _003543_hash NULL
87352 +_003544_hash rx_filter_protection_filter_read 3 39282 _003544_hash NULL
87353 +_003545_hash rx_rate_rx_frames_per_rates_read 3 7282 _003545_hash NULL
87354 +_003546_hash rx_rx_beacon_early_term_read 3 21559 _003546_hash NULL
87355 +_003547_hash rx_rx_checksum_result_read 3 50617 _003547_hash NULL
87356 +_003548_hash rx_rx_cmplt_read 3 14753 _003548_hash NULL
87357 +_003549_hash rx_rx_cmplt_task_read 3 35226 _003549_hash NULL
87358 +_003550_hash rx_rx_defrag_end_read 3 505 _003550_hash NULL
87359 +_003551_hash rx_rx_defrag_read 3 2010 _003551_hash NULL
87360 +_003552_hash rx_rx_done_read 3 65217 _003552_hash NULL
87361 +_003553_hash rx_rx_dropped_frame_read 3 23748 _003553_hash NULL
87362 +_003554_hash rx_rx_frame_checksum_read 3 40140 _003554_hash NULL
87363 +_003555_hash rx_rx_hdr_overflow_read 3 35002 _003555_hash NULL
87364 +_003556_hash rx_rx_out_of_mpdu_nodes_read 3 64668 _003556_hash NULL
87365 +_003557_hash rx_rx_phy_hdr_read 3 20950 _003557_hash NULL
87366 +_003558_hash rx_rx_pre_complt_read 3 41653 _003558_hash NULL
87367 +_003559_hash rx_rx_timeout_read 3 62389 _003559_hash NULL
87368 +_003560_hash rx_rx_timeout_wa_read 3 50204 _003560_hash NULL
87369 +_003561_hash rx_rx_tkip_replays_read 3 60193 _003561_hash NULL
87370 +_003562_hash rx_rx_wa_ba_not_expected_read 3 61341 _003562_hash NULL
87371 +_003563_hash rx_rx_wa_density_dropped_frame_read 3 26095 _003563_hash NULL
87372 +_003564_hash rx_streaming_always_read 3 49401 _003564_hash NULL
87373 +_003565_hash rx_streaming_interval_read 3 55291 _003565_hash NULL
87374 +_003566_hash saa7164_buffer_alloc_user 2 9627 _003566_hash NULL
87375 +_003567_hash send_control_msg 6 48498 _003567_hash NULL
87376 +_003568_hash SendTxCommandPacket 3 42901 _003568_hash NULL
87377 +_003569_hash setup_window 2-7-5-4 59178 _003569_hash NULL
87378 +_003573_hash shmem_pwrite_fast 3 46842 _003573_hash NULL
87379 +_003574_hash sleep_auth_read 3 19159 _003574_hash NULL
87380 +_003575_hash sn9c102_read 3 29305 _003575_hash NULL
87381 +_003576_hash snd_pcm_alloc_vmalloc_buffer 2 44595 _003576_hash NULL
87382 +_003577_hash split_scan_timeout_read 3 20029 _003577_hash NULL
87383 +_003578_hash stk_prepare_sio_buffers 2 57168 _003578_hash NULL
87384 +_003579_hash store_debug_level 3 35652 _003579_hash NULL
87385 +_003580_hash suspend_dtim_interval_read 3 64971 _003580_hash NULL
87386 +_003581_hash sys_prctl 4 8766 _003581_hash NULL
87387 +_003582_hash tm6000_read_write_usb 7 50774 _003582_hash &_002149_hash
87388 +_003583_hash tracing_read_pipe 3 35312 _003583_hash NULL
87389 +_003584_hash ts_read 3 44687 _003584_hash NULL
87390 +_003585_hash ts_write 3 64336 _003585_hash NULL
87391 +_003586_hash tt3650_ci_msg 4 57219 _003586_hash NULL
87392 +_003587_hash ttm_object_device_init 2 10321 _003587_hash NULL
87393 +_003588_hash ttm_object_file_init 2 27804 _003588_hash NULL
87394 +_003589_hash tx_frag_bad_mblk_num_read 3 28064 _003589_hash NULL
87395 +_003590_hash tx_frag_cache_hit_read 3 29639 _003590_hash NULL
87396 +_003591_hash tx_frag_cache_miss_read 3 28394 _003591_hash NULL
87397 +_003592_hash tx_frag_called_read 3 1748 _003592_hash NULL
87398 +_003593_hash tx_frag_failed_read 3 43540 _003593_hash NULL
87399 +_003594_hash tx_frag_init_called_read 3 48377 _003594_hash NULL
87400 +_003595_hash tx_frag_in_process_called_read 3 1290 _003595_hash NULL
87401 +_003596_hash tx_frag_key_not_found_read 3 22971 _003596_hash NULL
87402 +_003597_hash tx_frag_mpdu_alloc_failed_read 3 41167 _003597_hash NULL
87403 +_003598_hash tx_frag_need_fragmentation_read 3 50153 _003598_hash NULL
87404 +_003599_hash tx_frag_tkip_called_read 3 31575 _003599_hash NULL
87405 +_003600_hash tx_tx_burst_programmed_read 3 20320 _003600_hash NULL
87406 +_003601_hash tx_tx_checksum_result_read 3 36490 _003601_hash &_001996_hash
87407 +_003602_hash tx_tx_cmplt_read 3 35854 _003602_hash NULL
87408 +_003603_hash tx_tx_data_prepared_read 3 43497 _003603_hash NULL
87409 +_003604_hash tx_tx_data_programmed_read 3 36871 _003604_hash NULL
87410 +_003605_hash tx_tx_done_data_read 3 6799 _003605_hash NULL
87411 +_003606_hash tx_tx_done_int_template_read 3 55511 _003606_hash &_001887_hash
87412 +_003607_hash tx_tx_done_template_read 3 35104 _003607_hash &_000106_hash
87413 +_003608_hash tx_tx_exch_expiry_read 3 8749 _003608_hash NULL
87414 +_003609_hash tx_tx_exch_pending_read 3 53018 _003609_hash NULL
87415 +_003610_hash tx_tx_exch_read 3 52986 _003610_hash NULL
87416 +_003611_hash tx_tx_frame_checksum_read 3 41553 _003611_hash NULL
87417 +_003612_hash tx_tx_imm_resp_read 3 55964 _003612_hash NULL
87418 +_003613_hash tx_tx_prepared_descs_read 3 9221 _003613_hash NULL
87419 +_003614_hash tx_tx_retry_data_read 3 1926 _003614_hash NULL
87420 +_003615_hash tx_tx_retry_template_read 3 57623 _003615_hash NULL
87421 +_003616_hash tx_tx_start_data_read 3 53219 _003616_hash NULL
87422 +_003617_hash tx_tx_start_fw_gen_read 3 58648 _003617_hash NULL
87423 +_003618_hash tx_tx_start_int_templates_read 3 58324 _003618_hash NULL
87424 +_003619_hash tx_tx_start_null_frame_read 3 6281 _003619_hash NULL
87425 +_003620_hash tx_tx_starts_read 3 3617 _003620_hash NULL
87426 +_003621_hash tx_tx_start_templates_read 3 17164 _003621_hash NULL
87427 +_003622_hash tx_tx_template_prepared_read 3 30424 _003622_hash NULL
87428 +_003623_hash tx_tx_template_programmed_read 3 30461 _003623_hash NULL
87429 +_003624_hash udi_log_event 3 58105 _003624_hash NULL
87430 +_003625_hash udl_prime_create 2 57159 _003625_hash NULL
87431 +_003626_hash uf_create_device_nodes 2 24948 _003626_hash NULL
87432 +_003627_hash uf_sme_queue_message 3 15697 _003627_hash NULL
87433 +_003628_hash ufx_alloc_urb_list 3 10349 _003628_hash NULL
87434 +_003629_hash unifi_net_data_malloc 3 24716 _003629_hash NULL
87435 +_003630_hash unifi_read 3 14899 _003630_hash NULL
87436 +_003631_hash unifi_write 3 65012 _003631_hash NULL
87437 +_003632_hash usb_buffer_alloc 2 36276 _003632_hash NULL
87438 +_003633_hash usbvision_rvmalloc 1 19655 _003633_hash NULL
87439 +_003634_hash usbvision_v4l2_read 3 34386 _003634_hash NULL
87440 +_003635_hash uvc_alloc_buffers 2-3 9656 _003635_hash NULL
87441 +_003637_hash uvc_alloc_entity 3-4 20836 _003637_hash NULL
87442 +_003639_hash uvc_debugfs_stats_read 3 56651 _003639_hash NULL
87443 +_003640_hash uvc_simplify_fraction 3 31303 _003640_hash NULL
87444 +_003641_hash v4l2_ctrl_new 7 24927 _003641_hash NULL
87445 +_003642_hash v4l2_event_subscribe 3 53687 _003642_hash NULL
87446 +_003643_hash v4l_stk_read 3 39672 _003643_hash NULL
87447 +_003644_hash __vb2_perform_fileio 3 63033 _003644_hash NULL
87448 +_003645_hash vfd_write 3 14717 _003645_hash NULL
87449 +_003646_hash vfio_config_do_rw 3 46091 _003646_hash NULL
87450 +_003647_hash vfio_msi_enable 2 20906 _003647_hash NULL
87451 +_003648_hash viafb_dvp0_proc_write 3 23023 _003648_hash NULL
87452 +_003649_hash viafb_dvp1_proc_write 3 48864 _003649_hash NULL
87453 +_003650_hash viafb_vt1636_proc_write 3 16018 _003650_hash NULL
87454 +_003651_hash __videobuf_alloc_vb 1 27062 _003651_hash NULL
87455 +_003652_hash __videobuf_alloc_vb 1 5665 _003652_hash NULL
87456 +_003653_hash __videobuf_copy_to_user 4 15423 _003653_hash NULL
87457 +_003654_hash videobuf_dma_init_kernel 3 6963 _003654_hash NULL
87458 +_003655_hash videobuf_pages_to_sg 2 3708 _003655_hash NULL
87459 +_003656_hash videobuf_vmalloc_to_sg 2 4548 _003656_hash NULL
87460 +_003657_hash video_usercopy 2 62151 _003657_hash NULL
87461 +_003658_hash virtscsi_alloc_tgt 2 6643 _003658_hash NULL
87462 +_003659_hash vmw_cursor_update_image 3-4 16332 _003659_hash NULL
87463 +_003661_hash vmw_framebuffer_dmabuf_dirty 6 37661 _003661_hash &_001116_hash
87464 +_003662_hash vmw_framebuffer_surface_dirty 6 48132 _003662_hash NULL
87465 +_003663_hash vmw_gmr2_bind 3 21305 _003663_hash NULL
87466 +_003664_hash vmw_unlocked_ioctl 2 19212 _003664_hash NULL
87467 +_003665_hash w9966_v4l_read 3 31148 _003665_hash NULL
87468 +_003666_hash wl1273_fm_fops_write 3 60621 _003666_hash NULL
87469 +_003667_hash zoran_write 3 22404 _003667_hash NULL
87470 +_003668_hash alloc_vm_area 1 15989 _003668_hash NULL
87471 +_003669_hash cx18_copy_mdl_to_user 4 45549 _003669_hash NULL
87472 +_003670_hash dlfb_ops_write 3 64150 _003670_hash NULL
87473 +_003671_hash dvb_demux_read 3 13981 _003671_hash NULL
87474 +_003672_hash dvb_dmxdev_read_sec 4 7892 _003672_hash NULL
87475 +_003673_hash dvb_dvr_read 3 17073 _003673_hash NULL
87476 +_003674_hash em28xx_init_isoc 4 62883 _003674_hash &_000729_hash
87477 +_003675_hash fb_alloc_cmap 2 6554 _003675_hash NULL
87478 +_003676_hash gspca_dev_probe 4 2570 _003676_hash NULL
87479 +_003677_hash ieee80211_auth_challenge 3 18810 _003677_hash NULL
87480 +_003678_hash ieee80211_rtl_auth_challenge 3 61897 _003678_hash NULL
87481 +_003679_hash init_pci_cap_msi_perm 2 59033 _003679_hash NULL
87482 +_003680_hash __ioremap_caller 1-2 21800 _003680_hash NULL
87483 +_003682_hash ivtv_read 3 57796 _003682_hash NULL
87484 +_003683_hash ivtv_v4l2_write 3 39226 _003683_hash NULL
87485 +_003684_hash mce_async_out 3 58056 _003684_hash NULL
87486 +_003685_hash mce_flush_rx_buffer 2 14976 _003685_hash NULL
87487 +_003686_hash ms_read_multiple_pages 4-5 8052 _003686_hash NULL
87488 +_003688_hash ms_write_multiple_pages 5-6 10362 _003688_hash NULL
87489 +_003690_hash nfc_hci_send_cmd 5 55714 _003690_hash NULL
87490 +_003691_hash persistent_ram_new 1-2 40501 _003691_hash NULL
87491 +_003693_hash picolcd_fb_write 3 2318 _003693_hash NULL
87492 +_003694_hash process_bulk_data_command 4 38906 _003694_hash NULL
87493 +_003695_hash pvr2_v4l2_read 3 18006 _003695_hash NULL
87494 +_003696_hash qcam_read 3 13977 _003696_hash NULL
87495 +_003697_hash register_unifi_sdio 2 55239 _003697_hash NULL
87496 +_003698_hash resize_async_buffer 4 64031 _003698_hash &_002431_hash
87497 +_003699_hash rtllib_auth_challenge 3 12493 _003699_hash NULL
87498 +_003702_hash stk_allocate_buffers 2 16291 _003702_hash NULL
87499 +_003703_hash subdev_ioctl 2 28417 _003703_hash NULL
87500 +_003704_hash _sys_packet_req 4 46793 _003704_hash NULL
87501 +_003705_hash tm6000_i2c_recv_regs16 5 2949 _003705_hash NULL
87502 +_003706_hash tm6000_i2c_recv_regs 5 46215 _003706_hash NULL
87503 +_003707_hash tm6000_i2c_send_regs 5 20250 _003707_hash NULL
87504 +_003708_hash tt3650_ci_msg_locked 4 8013 _003708_hash NULL
87505 +_003709_hash ufx_ops_write 3 54848 _003709_hash NULL
87506 +_003710_hash update_macheader 7 1775 _003710_hash NULL
87507 +_003711_hash usbdux_attach_common 4 51764 _003750_hash NULL nohasharray
87508 +_003712_hash usbduxfast_attach_common 4 52538 _003712_hash NULL
87509 +_003713_hash usbduxsigma_attach_common 4 40847 _003713_hash NULL
87510 +_003714_hash uvc_v4l2_ioctl 2 8411 _003714_hash NULL
87511 +_003715_hash v4l2_ctrl_new_int_menu 4 41151 _003715_hash NULL
87512 +_003716_hash v4l2_ctrl_new_std 5 45748 _003716_hash &_000497_hash
87513 +_003717_hash v4l2_ctrl_new_std_menu 4 6221 _003717_hash NULL
87514 +_003718_hash vb2_read 3 42703 _003718_hash NULL
87515 +_003719_hash vb2_write 3 31948 _003719_hash NULL
87516 +_003720_hash vfio_pci_set_msi_trigger 3-4 26507 _003720_hash NULL
87517 +_003722_hash viafb_iga1_odev_proc_write 3 36241 _003722_hash NULL
87518 +_003723_hash viafb_iga2_odev_proc_write 3 2363 _003723_hash NULL
87519 +_003724_hash __videobuf_alloc_cached 1 12740 _003724_hash NULL
87520 +_003725_hash __videobuf_alloc_uncached 1 55711 _003725_hash NULL
87521 +_003726_hash __videobuf_copy_stream 4 44769 _003726_hash NULL
87522 +_003727_hash videobuf_read_one 3 31637 _003727_hash NULL
87523 +_003728_hash video_ioctl2 2 21380 _003728_hash NULL
87524 +_003729_hash vmap 2 15025 _003729_hash NULL
87525 +_003730_hash vmw_cursor_update_dmabuf 3-4 32045 _003730_hash NULL
87526 +_003732_hash vmw_gmr_bind 3 44130 _003732_hash NULL
87527 +_003733_hash xd_read_multiple_pages 4-5 11422 _003733_hash NULL
87528 +_003735_hash xd_write_multiple_pages 5-6 53633 _003735_hash NULL
87529 +_003737_hash xenfb_write 3 43412 _003737_hash NULL
87530 +_003738_hash arch_gnttab_map_shared 3 41306 _003738_hash NULL
87531 +_003739_hash arch_gnttab_map_status 3 49812 _003739_hash NULL
87532 +_003740_hash bttv_read 3 11432 _003740_hash NULL
87533 +_003741_hash cx18_read 3 23699 _003741_hash NULL
87534 +_003742_hash cx2341x_ctrl_new_menu 3 49700 _003742_hash NULL
87535 +_003743_hash cx2341x_ctrl_new_std 4 57061 _003743_hash NULL
87536 +_003744_hash cx25821_video_ioctl 2 30188 _003744_hash NULL
87537 +_003745_hash dt3155_read 3 59226 _003745_hash NULL
87538 +_003746_hash ioremap_cache 1-2 47189 _003746_hash NULL
87539 +_003748_hash ioremap_nocache 1-2 2439 _003748_hash NULL
87540 +_003750_hash ioremap_prot 1-2 51764 _003750_hash &_003711_hash
87541 +_003752_hash ioremap_wc 1-2 62695 _003752_hash NULL
87542 +_003754_hash ivtv_read_pos 3 34400 _003754_hash &_000312_hash
87543 +_003755_hash mcam_v4l_read 3 36513 _003755_hash NULL
87544 +_003756_hash ms_rw_multi_sector 3-4 7459 _003756_hash NULL
87545 +_003758_hash pvr2_v4l2_ioctl 2 24398 _003758_hash &_000877_hash
87546 +_003759_hash ramoops_init_prz 5 12134 _003759_hash NULL
87547 +_003761_hash ttm_bo_kmap_ttm 3 5922 _003761_hash NULL
87548 +_003762_hash uf_ap_process_data_pdu 7 25860 _003762_hash NULL
87549 +_003763_hash vb2_fop_read 3 24080 _003763_hash NULL
87550 +_003764_hash vb2_fop_write 3 30420 _003764_hash NULL
87551 +_003765_hash videobuf_read_stream 3 14956 _003765_hash NULL
87552 +_003766_hash video_read 3 28148 _003766_hash NULL
87553 +_003767_hash vmw_du_crtc_cursor_set 4-5 28479 _003767_hash NULL
87554 +_003769_hash xd_rw 3-4 49020 _003769_hash NULL
87555 +_003771_hash zoran_ioctl 2 30465 _003771_hash NULL
87556 +_003772_hash zr364xx_read 3 2354 _003772_hash NULL
87557 +_003773_hash acpi_os_ioremap 1-2 49523 _003773_hash NULL
87558 +_003775_hash au0828_v4l2_read 3 40220 _003775_hash NULL
87559 +_003776_hash ca91cx42_alloc_resource 2 10502 _003776_hash NULL
87560 +_003778_hash cx18_read_pos 3 4683 _003778_hash NULL
87561 +_003779_hash cx18_v4l2_read 3 21196 _003779_hash NULL
87562 +_003780_hash cx231xx_v4l2_read 3 55014 _003780_hash NULL
87563 +_003781_hash devm_ioremap_nocache 2-3 2036 _003781_hash NULL
87564 +_003783_hash do_test 1 15766 _003783_hash NULL
87565 +_003784_hash __einj_error_trigger 1 17707 _003784_hash &_001764_hash
87566 +_003785_hash em28xx_v4l2_read 3 16701 _003785_hash NULL
87567 +_003786_hash init_chip_wc_pat 2 62768 _003786_hash NULL
87568 +_003787_hash intel_render_ring_init_dri 2-3 45446 _003787_hash NULL
87569 +_003789_hash io_mapping_create_wc 1-2 1354 _003789_hash NULL
87570 +_003791_hash iommu_map_mmio_space 1 30919 _003791_hash NULL
87571 +_003792_hash ioremap 1-2 23172 _003792_hash NULL
87572 +_003794_hash ivtv_v4l2_read 3 1964 _003794_hash NULL
87573 +_003795_hash mga_ioremap 1-2 8571 _003795_hash NULL
87574 +_003797_hash mpeg_read 3 6708 _003797_hash NULL
87575 +_003798_hash msix_map_region 3 3411 _003798_hash NULL
87576 +_003799_hash ms_rw 3-4 17220 _003799_hash NULL
87577 +_003801_hash pci_iomap 3 47575 _003801_hash NULL
87578 +_003802_hash pd_video_read 3 24510 _003802_hash NULL
87579 +_003803_hash sfi_map_memory 1-2 5183 _003803_hash NULL
87580 +_003805_hash solo_enc_read 3 33553 _003805_hash NULL
87581 +_003806_hash solo_v4l2_read 3 59247 _003806_hash NULL
87582 +_003807_hash timblogiw_read 3 48305 _003807_hash NULL
87583 +_003808_hash tm6000_read 3 4151 _003808_hash NULL
87584 +_003809_hash tsi148_alloc_resource 2 24563 _003809_hash NULL
87585 +_003810_hash ttm_bo_ioremap 2-3 31082 _003810_hash NULL
87586 +_003812_hash ttm_bo_kmap 3-2 60118 _003812_hash NULL
87587 +_003813_hash vb2_vmalloc_get_userptr 3 31374 _003813_hash NULL
87588 +_003814_hash vbi_read 3 63673 _003814_hash NULL
87589 +_003815_hash viacam_read 3 54526 _003815_hash NULL
87590 +_003816_hash xlate_dev_mem_ptr 1 15291 _003816_hash &_001231_hash
87591 +_003817_hash a4t_cs_init 3 27734 _003817_hash NULL
87592 +_003818_hash aac_nark_ioremap 2 50163 _003818_hash &_000323_hash
87593 +_003819_hash aac_rkt_ioremap 2 3333 _003819_hash NULL
87594 +_003820_hash aac_rx_ioremap 2 52410 _003820_hash NULL
87595 +_003821_hash aac_sa_ioremap 2 13596 _003821_hash &_000299_hash
87596 +_003822_hash aac_src_ioremap 2 41688 _003822_hash NULL
87597 +_003823_hash aac_srcv_ioremap 2 6659 _003823_hash NULL
87598 +_003824_hash acpi_map 1-2 58725 _003824_hash NULL
87599 +_003826_hash acpi_os_read_memory 1-3 54186 _003826_hash NULL
87600 +_003828_hash acpi_os_write_memory 1-3 56416 _003828_hash &_003429_hash
87601 +_003830_hash atyfb_setup_generic 3 49151 _003830_hash NULL
87602 +_003831_hash ca91cx42_master_set 4 23146 _003831_hash NULL
87603 +_003832_hash check_mirror 1-2 57342 _003832_hash &_001753_hash
87604 +_003834_hash cycx_setup 4 47562 _003834_hash NULL
87605 +_003835_hash devm_ioremap 2-3 29235 _003835_hash NULL
87606 +_003837_hash divasa_remap_pci_bar 3-4 23485 _003837_hash &_000979_hash
87607 +_003839_hash doc_probe 1 23285 _003839_hash NULL
87608 +_003840_hash DoC_Probe 1 57534 _003840_hash NULL
87609 +_003841_hash efi_ioremap 1-2 3492 _003841_hash &_001137_hash
87610 +_003843_hash ems_pcmcia_add_card 2 62627 _003843_hash NULL
87611 +_003844_hash isp1760_register 1-2 628 _003844_hash NULL
87612 +_003846_hash mid_get_vbt_data_r0 2 10876 _003846_hash NULL
87613 +_003847_hash mid_get_vbt_data_r10 2 6308 _003847_hash NULL
87614 +_003848_hash mid_get_vbt_data_r1 2 26170 _003848_hash NULL
87615 +_003849_hash mthca_map_reg 2-3 5664 _003849_hash NULL
87616 +_003851_hash mthca_setup_cmd_doorbells 2 53954 _003851_hash NULL
87617 +_003852_hash netxen_nic_map_indirect_address_128M 2 42257 _003852_hash NULL
87618 +_003853_hash pcim_iomap 3 58334 _003853_hash NULL
87619 +_003854_hash persistent_ram_iomap 1-2 47156 _003854_hash NULL
87620 +_003856_hash read_vbt_r0 1 503 _003856_hash NULL
87621 +_003857_hash read_vbt_r10 1 60679 _003857_hash NULL
87622 +_003858_hash register_device 2-3 60015 _003858_hash NULL
87623 +_003860_hash remap_pci_mem 1-2 15966 _003860_hash NULL
87624 +_003862_hash rtl_port_map 1-2 2385 _003862_hash NULL
87625 +_003864_hash sfi_map_table 1 5462 _003864_hash NULL
87626 +_003865_hash sriov_enable_migration 2 14889 _003865_hash NULL
87627 +_003866_hash ssb_bus_scan 2 36578 _003866_hash NULL
87628 +_003867_hash ssb_ioremap 2 5228 _003867_hash NULL
87629 +_003868_hash tpci200_slot_map_space 2 3848 _003868_hash NULL
87630 +_003869_hash tpm_tis_init 2-3 15304 _003869_hash NULL
87631 +_003871_hash tsi148_master_set 4 14685 _003871_hash NULL
87632 +_003872_hash acpi_os_map_memory 1-2 11161 _003872_hash NULL
87633 +_003874_hash com90xx_found 3 13974 _003874_hash NULL
87634 +_003875_hash netxen_nic_hw_read_wx_128M 2 26858 _003875_hash NULL
87635 +_003876_hash netxen_nic_hw_write_wx_128M 2 33488 _003876_hash NULL
87636 +_003877_hash sfi_check_table 1 6772 _003877_hash NULL
87637 +_003878_hash sfi_sysfs_install_table 1 51688 _003878_hash NULL
87638 +_003879_hash sriov_enable 2 59689 _003879_hash NULL
87639 +_003880_hash ssb_bus_register 3 65183 _003880_hash NULL
87640 +_003881_hash acpi_ex_system_memory_space_handler 2 31192 _003881_hash NULL
87641 +_003882_hash acpi_tb_check_xsdt 1 21862 _003882_hash NULL
87642 +_003883_hash acpi_tb_install_table 1 12988 _003883_hash NULL
87643 +_003884_hash acpi_tb_parse_root_table 1 53455 _003884_hash NULL
87644 +_003885_hash check_vendor_extension 1 3254 _003885_hash NULL
87645 +_003886_hash pci_enable_sriov 2 35745 _003886_hash NULL
87646 +_003887_hash ssb_bus_pcmciabus_register 3 56020 _003887_hash NULL
87647 +_003888_hash ssb_bus_ssbbus_register 2 2217 _003888_hash NULL
87648 +_003889_hash lpfc_sli_probe_sriov_nr_virtfn 2 26004 _003889_hash NULL
87649 +_003890_hash alloc_vm_area 1 36149 _003890_hash NULL
87650 +_003891_hash cma_create_area 2 38642 _003891_hash NULL
87651 +_003893_hash fbcon_prepare_logo 5 6246 _003893_hash NULL
87652 +_003894_hash io_mapping_map_wc 2 19284 _003894_hash NULL
87653 +_003895_hash nfs_dns_resolve_name 3 25036 _003895_hash NULL
87654 +_003896_hash nfs_parse_server_name 2 1899 _003896_hash NULL
87655 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
87656 new file mode 100644
87657 index 0000000..244559e
87658 --- /dev/null
87659 +++ b/tools/gcc/size_overflow_plugin.c
87660 @@ -0,0 +1,1879 @@
87661 +/*
87662 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
87663 + * Licensed under the GPL v2, or (at your option) v3
87664 + *
87665 + * Homepage:
87666 + * http://www.grsecurity.net/~ephox/overflow_plugin/
87667 + *
87668 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
87669 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
87670 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
87671 + *
87672 + * Usage:
87673 + * $ 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
87674 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
87675 + */
87676 +
87677 +#include "gcc-plugin.h"
87678 +#include "config.h"
87679 +#include "system.h"
87680 +#include "coretypes.h"
87681 +#include "tree.h"
87682 +#include "tree-pass.h"
87683 +#include "intl.h"
87684 +#include "plugin-version.h"
87685 +#include "tm.h"
87686 +#include "toplev.h"
87687 +#include "function.h"
87688 +#include "tree-flow.h"
87689 +#include "plugin.h"
87690 +#include "gimple.h"
87691 +#include "c-common.h"
87692 +#include "diagnostic.h"
87693 +#include "cfgloop.h"
87694 +
87695 +#if BUILDING_GCC_VERSION >= 4007
87696 +#include "c-tree.h"
87697 +#else
87698 +#define C_DECL_IMPLICIT(EXP) DECL_LANG_FLAG_2 (EXP)
87699 +#endif
87700 +
87701 +struct size_overflow_hash {
87702 + const struct size_overflow_hash * const next;
87703 + const char * const name;
87704 + const unsigned int param;
87705 +};
87706 +
87707 +#include "size_overflow_hash.h"
87708 +
87709 +enum marked {
87710 + MARKED_NO, MARKED_YES, MARKED_NOT_INTENTIONAL
87711 +};
87712 +
87713 +#define __unused __attribute__((__unused__))
87714 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
87715 +#define NAME_LEN(node) IDENTIFIER_LENGTH(DECL_NAME(node))
87716 +#define BEFORE_STMT true
87717 +#define AFTER_STMT false
87718 +#define CREATE_NEW_VAR NULL_TREE
87719 +#define CODES_LIMIT 32
87720 +#define MAX_PARAM 32
87721 +#define MY_STMT GF_PLF_1
87722 +#define NO_CAST_CHECK GF_PLF_2
87723 +
87724 +#if BUILDING_GCC_VERSION == 4005
87725 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
87726 +#endif
87727 +
87728 +int plugin_is_GPL_compatible;
87729 +void debug_gimple_stmt(gimple gs);
87730 +
87731 +static tree expand(struct pointer_set_t *visited, tree lhs);
87732 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs);
87733 +static tree report_size_overflow_decl;
87734 +static const_tree const_char_ptr_type_node;
87735 +static unsigned int handle_function(void);
87736 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
87737 +static tree get_size_overflow_type(gimple stmt, const_tree node);
87738 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, tree size_overflow_type, tree rhs1, tree rhs2, tree __unused rhs3);
87739 +
87740 +static struct plugin_info size_overflow_plugin_info = {
87741 + .version = "20120930beta",
87742 + .help = "no-size-overflow\tturn off size overflow checking\n",
87743 +};
87744 +
87745 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
87746 +{
87747 + unsigned int arg_count;
87748 + enum tree_code code = TREE_CODE(*node);
87749 +
87750 + switch (code) {
87751 + case FUNCTION_DECL:
87752 + arg_count = type_num_arguments(TREE_TYPE(*node));
87753 + break;
87754 + case FUNCTION_TYPE:
87755 + case METHOD_TYPE:
87756 + arg_count = type_num_arguments(*node);
87757 + break;
87758 + default:
87759 + *no_add_attrs = true;
87760 + error("%s: %qE attribute only applies to functions", __func__, name);
87761 + return NULL_TREE;
87762 + }
87763 +
87764 + for (; args; args = TREE_CHAIN(args)) {
87765 + tree position = TREE_VALUE(args);
87766 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
87767 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
87768 + *no_add_attrs = true;
87769 + }
87770 + }
87771 + return NULL_TREE;
87772 +}
87773 +
87774 +static const char* get_asm_name(tree node)
87775 +{
87776 + return IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME(node));
87777 +}
87778 +
87779 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
87780 +{
87781 + unsigned int arg_count, arg_num;
87782 + enum tree_code code = TREE_CODE(*node);
87783 +
87784 + switch (code) {
87785 + case FUNCTION_DECL:
87786 + arg_count = type_num_arguments(TREE_TYPE(*node));
87787 + break;
87788 + case FUNCTION_TYPE:
87789 + case METHOD_TYPE:
87790 + arg_count = type_num_arguments(*node);
87791 + break;
87792 + case FIELD_DECL:
87793 + arg_num = TREE_INT_CST_LOW(TREE_VALUE(args));
87794 + if (arg_num != 0) {
87795 + *no_add_attrs = true;
87796 + error("%s: %qE attribute parameter can only be 0 in structure fields", __func__, name);
87797 + }
87798 + return NULL_TREE;
87799 + default:
87800 + *no_add_attrs = true;
87801 + error("%qE attribute only applies to functions", name);
87802 + return NULL_TREE;
87803 + }
87804 +
87805 + for (; args; args = TREE_CHAIN(args)) {
87806 + tree position = TREE_VALUE(args);
87807 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) > arg_count ) {
87808 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
87809 + *no_add_attrs = true;
87810 + }
87811 + }
87812 + return NULL_TREE;
87813 +}
87814 +
87815 +static struct attribute_spec size_overflow_attr = {
87816 + .name = "size_overflow",
87817 + .min_length = 1,
87818 + .max_length = -1,
87819 + .decl_required = true,
87820 + .type_required = false,
87821 + .function_type_required = false,
87822 + .handler = handle_size_overflow_attribute,
87823 +#if BUILDING_GCC_VERSION >= 4007
87824 + .affects_type_identity = false
87825 +#endif
87826 +};
87827 +
87828 +static struct attribute_spec intentional_overflow_attr = {
87829 + .name = "intentional_overflow",
87830 + .min_length = 1,
87831 + .max_length = -1,
87832 + .decl_required = true,
87833 + .type_required = false,
87834 + .function_type_required = false,
87835 + .handler = handle_intentional_overflow_attribute,
87836 +#if BUILDING_GCC_VERSION >= 4007
87837 + .affects_type_identity = false
87838 +#endif
87839 +};
87840 +
87841 +static void register_attributes(void __unused *event_data, void __unused *data)
87842 +{
87843 + register_attribute(&size_overflow_attr);
87844 + register_attribute(&intentional_overflow_attr);
87845 +}
87846 +
87847 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
87848 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
87849 +{
87850 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
87851 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
87852 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
87853 +
87854 + unsigned int m = 0x57559429;
87855 + unsigned int n = 0x5052acdb;
87856 + const unsigned int *key4 = (const unsigned int *)key;
87857 + unsigned int h = len;
87858 + unsigned int k = len + seed + n;
87859 + unsigned long long p;
87860 +
87861 + while (len >= 8) {
87862 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
87863 + len -= 8;
87864 + }
87865 + if (len >= 4) {
87866 + cwmixb(key4[0]) key4 += 1;
87867 + len -= 4;
87868 + }
87869 + if (len)
87870 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
87871 + cwmixb(h ^ (k + n));
87872 + return k ^ h;
87873 +
87874 +#undef cwfold
87875 +#undef cwmixa
87876 +#undef cwmixb
87877 +}
87878 +
87879 +static inline unsigned int get_hash_num(const char *fndecl, const char *tree_codes, unsigned int len, unsigned int seed)
87880 +{
87881 + unsigned int fn = CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
87882 + unsigned int codes = CrapWow(tree_codes, len, seed) & 0xffff;
87883 + return fn ^ codes;
87884 +}
87885 +
87886 +static inline tree get_original_function_decl(tree fndecl)
87887 +{
87888 + if (DECL_ABSTRACT_ORIGIN(fndecl))
87889 + return DECL_ABSTRACT_ORIGIN(fndecl);
87890 + return fndecl;
87891 +}
87892 +
87893 +static inline gimple get_def_stmt(const_tree node)
87894 +{
87895 + gcc_assert(node != NULL_TREE);
87896 + gcc_assert(TREE_CODE(node) == SSA_NAME);
87897 + return SSA_NAME_DEF_STMT(node);
87898 +}
87899 +
87900 +static unsigned char get_tree_code(const_tree type)
87901 +{
87902 + switch (TREE_CODE(type)) {
87903 + case ARRAY_TYPE:
87904 + return 0;
87905 + case BOOLEAN_TYPE:
87906 + return 1;
87907 + case ENUMERAL_TYPE:
87908 + return 2;
87909 + case FUNCTION_TYPE:
87910 + return 3;
87911 + case INTEGER_TYPE:
87912 + return 4;
87913 + case POINTER_TYPE:
87914 + return 5;
87915 + case RECORD_TYPE:
87916 + return 6;
87917 + case UNION_TYPE:
87918 + return 7;
87919 + case VOID_TYPE:
87920 + return 8;
87921 + case REAL_TYPE:
87922 + return 9;
87923 + case VECTOR_TYPE:
87924 + return 10;
87925 + case REFERENCE_TYPE:
87926 + return 11;
87927 + case OFFSET_TYPE:
87928 + return 12;
87929 + case COMPLEX_TYPE:
87930 + return 13;
87931 + default:
87932 + debug_tree((tree)type);
87933 + gcc_unreachable();
87934 + }
87935 +}
87936 +
87937 +static size_t add_type_codes(const_tree type, unsigned char *tree_codes, size_t len)
87938 +{
87939 + gcc_assert(type != NULL_TREE);
87940 +
87941 + while (type && len < CODES_LIMIT) {
87942 + tree_codes[len] = get_tree_code(type);
87943 + len++;
87944 + type = TREE_TYPE(type);
87945 + }
87946 + return len;
87947 +}
87948 +
87949 +static unsigned int get_function_decl(const_tree fndecl, unsigned char *tree_codes)
87950 +{
87951 + const_tree arg, result, arg_field, type = TREE_TYPE(fndecl);
87952 + enum tree_code code = TREE_CODE(type);
87953 + size_t len = 0;
87954 +
87955 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
87956 +
87957 + arg = TYPE_ARG_TYPES(type);
87958 + // skip builtins __builtin_constant_p
87959 + if (!arg && DECL_BUILT_IN(fndecl))
87960 + return 0;
87961 +
87962 + if (TREE_CODE_CLASS(code) == tcc_type)
87963 + result = type;
87964 + else
87965 + result = DECL_RESULT(fndecl);
87966 +
87967 + gcc_assert(result != NULL_TREE);
87968 + len = add_type_codes(TREE_TYPE(result), tree_codes, len);
87969 +
87970 + if (arg == NULL_TREE) {
87971 + gcc_assert(CODE_CONTAINS_STRUCT(TREE_CODE(fndecl), TS_DECL_NON_COMMON));
87972 + arg_field = DECL_ARGUMENT_FLD(fndecl);
87973 + if (arg_field == NULL_TREE)
87974 + return 0;
87975 + arg = TREE_TYPE(arg_field);
87976 + len = add_type_codes(arg, tree_codes, len);
87977 + gcc_assert(len != 0);
87978 + return len;
87979 + }
87980 +
87981 + gcc_assert(arg != NULL_TREE && TREE_CODE(arg) == TREE_LIST);
87982 + while (arg && len < CODES_LIMIT) {
87983 + len = add_type_codes(TREE_VALUE(arg), tree_codes, len);
87984 + arg = TREE_CHAIN(arg);
87985 + }
87986 +
87987 + gcc_assert(len != 0);
87988 + return len;
87989 +}
87990 +
87991 +static const struct size_overflow_hash *get_function_hash(tree fndecl)
87992 +{
87993 + unsigned int hash;
87994 + const struct size_overflow_hash *entry;
87995 + unsigned char tree_codes[CODES_LIMIT];
87996 + size_t len;
87997 + const char *func_name = get_asm_name(fndecl);
87998 +
87999 + len = get_function_decl(fndecl, tree_codes);
88000 + if (len == 0)
88001 + return NULL;
88002 +
88003 + hash = get_hash_num(func_name, (const char*) tree_codes, len, 0);
88004 +
88005 + entry = size_overflow_hash[hash];
88006 + while (entry) {
88007 + if (!strcmp(entry->name, func_name))
88008 + return entry;
88009 + entry = entry->next;
88010 + }
88011 +
88012 + return NULL;
88013 +}
88014 +
88015 +static void check_arg_type(const_tree arg)
88016 +{
88017 + const_tree type = TREE_TYPE(arg);
88018 + enum tree_code code = TREE_CODE(type);
88019 +
88020 + gcc_assert(code == INTEGER_TYPE || code == ENUMERAL_TYPE ||
88021 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
88022 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
88023 +}
88024 +
88025 +static int find_arg_number(const_tree arg, tree func)
88026 +{
88027 + tree var;
88028 + unsigned int argnum = 1;
88029 +
88030 + if (TREE_CODE(arg) == SSA_NAME)
88031 + arg = SSA_NAME_VAR(arg);
88032 +
88033 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
88034 + if (strcmp(NAME(arg), NAME(var))) {
88035 + argnum++;
88036 + continue;
88037 + }
88038 + check_arg_type(var);
88039 + return argnum;
88040 + }
88041 + gcc_unreachable();
88042 +}
88043 +
88044 +static tree create_new_var(tree type)
88045 +{
88046 + tree new_var = create_tmp_var(type, "cicus");
88047 +
88048 + add_referenced_var(new_var);
88049 + mark_sym_for_renaming(new_var);
88050 + return new_var;
88051 +}
88052 +
88053 +static gimple create_binary_assign(enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
88054 +{
88055 + gimple assign;
88056 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
88057 + tree type = TREE_TYPE(rhs1);
88058 + tree lhs = create_new_var(type);
88059 +
88060 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
88061 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
88062 +
88063 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
88064 + update_stmt(assign);
88065 + gimple_set_plf(assign, MY_STMT, true);
88066 + return assign;
88067 +}
88068 +
88069 +static bool is_bool(const_tree node)
88070 +{
88071 + const_tree type;
88072 +
88073 + if (node == NULL_TREE)
88074 + return false;
88075 +
88076 + type = TREE_TYPE(node);
88077 + if (!INTEGRAL_TYPE_P(type))
88078 + return false;
88079 + if (TREE_CODE(type) == BOOLEAN_TYPE)
88080 + return true;
88081 + if (TYPE_PRECISION(type) == 1)
88082 + return true;
88083 + return false;
88084 +}
88085 +
88086 +static tree cast_a_tree(tree type, tree var)
88087 +{
88088 + gcc_assert(type != NULL_TREE);
88089 + gcc_assert(var != NULL_TREE);
88090 + gcc_assert(fold_convertible_p(type, var));
88091 +
88092 + return fold_convert(type, var);
88093 +}
88094 +
88095 +static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before)
88096 +{
88097 + gimple assign;
88098 +
88099 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
88100 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
88101 + gcc_unreachable();
88102 +
88103 + if (lhs == CREATE_NEW_VAR)
88104 + lhs = create_new_var(dst_type);
88105 +
88106 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
88107 +
88108 + if (!gsi_end_p(*gsi)) {
88109 + location_t loc = gimple_location(gsi_stmt(*gsi));
88110 + gimple_set_location(assign, loc);
88111 + }
88112 +
88113 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
88114 +
88115 + if (before)
88116 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
88117 + else
88118 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
88119 + update_stmt(assign);
88120 + gimple_set_plf(assign, MY_STMT, true);
88121 +
88122 + return assign;
88123 +}
88124 +
88125 +static tree cast_to_new_size_overflow_type(gimple stmt, tree new_rhs1, tree size_overflow_type, bool before)
88126 +{
88127 + const_gimple assign;
88128 + gimple_stmt_iterator gsi;
88129 +
88130 + if (new_rhs1 == NULL_TREE)
88131 + return NULL_TREE;
88132 +
88133 + if (!useless_type_conversion_p(TREE_TYPE(new_rhs1), size_overflow_type)) {
88134 + gsi = gsi_for_stmt(stmt);
88135 + assign = build_cast_stmt(size_overflow_type, new_rhs1, CREATE_NEW_VAR, &gsi, before);
88136 + return gimple_get_lhs(assign);
88137 + }
88138 + return new_rhs1;
88139 +}
88140 +
88141 +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)
88142 +{
88143 + tree size_overflow_type = get_size_overflow_type(stmt, node);
88144 +
88145 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88146 +
88147 + if (new_rhs2 != NULL_TREE)
88148 + new_rhs2 = cast_to_new_size_overflow_type(stmt, new_rhs2, size_overflow_type, BEFORE_STMT);
88149 +
88150 + if (new_rhs3 != NULL_TREE)
88151 + new_rhs3 = cast_to_new_size_overflow_type(stmt, new_rhs3, size_overflow_type, BEFORE_STMT);
88152 +
88153 + return dup_assign(visited, stmt, size_overflow_type, new_rhs1, new_rhs2, new_rhs3);
88154 +}
88155 +
88156 +
88157 +static tree create_assign(struct pointer_set_t *visited, gimple oldstmt, tree rhs1, bool before)
88158 +{
88159 + tree size_overflow_type, lhs;
88160 + gimple stmt;
88161 + gimple_stmt_iterator gsi;
88162 +
88163 + if (rhs1 == NULL_TREE) {
88164 + debug_gimple_stmt(oldstmt);
88165 + error("%s: rhs1 is NULL_TREE", __func__);
88166 + gcc_unreachable();
88167 + }
88168 +
88169 + if (gimple_code(oldstmt) == GIMPLE_ASM)
88170 + lhs = rhs1;
88171 + else
88172 + lhs = gimple_get_lhs(oldstmt);
88173 +
88174 + gsi = gsi_for_stmt(oldstmt);
88175 + pointer_set_insert(visited, oldstmt);
88176 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
88177 + basic_block next_bb, cur_bb;
88178 + const_edge e;
88179 +
88180 + gcc_assert(before == false);
88181 + gcc_assert(stmt_can_throw_internal(oldstmt));
88182 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
88183 + gcc_assert(!gsi_end_p(gsi));
88184 +
88185 + cur_bb = gimple_bb(oldstmt);
88186 + next_bb = cur_bb->next_bb;
88187 + e = find_edge(cur_bb, next_bb);
88188 + gcc_assert(e != NULL);
88189 + gcc_assert(e->flags & EDGE_FALLTHRU);
88190 +
88191 + gsi = gsi_after_labels(next_bb);
88192 + gcc_assert(!gsi_end_p(gsi));
88193 +
88194 + before = true;
88195 + oldstmt = gsi_stmt(gsi);
88196 + }
88197 +
88198 + size_overflow_type = get_size_overflow_type(oldstmt, lhs);
88199 +
88200 + stmt = build_cast_stmt(size_overflow_type, rhs1, CREATE_NEW_VAR, &gsi, before);
88201 + gimple_set_plf(stmt, MY_STMT, true);
88202 + return gimple_get_lhs(stmt);
88203 +}
88204 +
88205 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, tree size_overflow_type, tree rhs1, tree rhs2, tree __unused rhs3)
88206 +{
88207 + gimple stmt;
88208 + gimple_stmt_iterator gsi;
88209 + tree new_var, lhs = gimple_get_lhs(oldstmt);
88210 +
88211 + if (gimple_plf(oldstmt, MY_STMT))
88212 + return lhs;
88213 +
88214 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
88215 + rhs1 = gimple_assign_rhs1(oldstmt);
88216 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
88217 + }
88218 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
88219 + rhs2 = gimple_assign_rhs2(oldstmt);
88220 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
88221 + }
88222 +
88223 + stmt = gimple_copy(oldstmt);
88224 + gimple_set_location(stmt, gimple_location(oldstmt));
88225 + gimple_set_plf(stmt, MY_STMT, true);
88226 +
88227 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
88228 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
88229 +
88230 + if (is_bool(lhs))
88231 + new_var = SSA_NAME_VAR(lhs);
88232 + else
88233 + new_var = create_new_var(size_overflow_type);
88234 + new_var = make_ssa_name(new_var, stmt);
88235 + gimple_set_lhs(stmt, new_var);
88236 +
88237 + if (rhs1 != NULL_TREE) {
88238 + if (!gimple_assign_cast_p(oldstmt))
88239 + rhs1 = cast_a_tree(size_overflow_type, rhs1);
88240 + gimple_assign_set_rhs1(stmt, rhs1);
88241 + }
88242 +
88243 + if (rhs2 != NULL_TREE)
88244 + gimple_assign_set_rhs2(stmt, rhs2);
88245 +#if BUILDING_GCC_VERSION >= 4007
88246 + if (rhs3 != NULL_TREE)
88247 + gimple_assign_set_rhs3(stmt, rhs3);
88248 +#endif
88249 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
88250 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
88251 +
88252 + gsi = gsi_for_stmt(oldstmt);
88253 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
88254 + update_stmt(stmt);
88255 + pointer_set_insert(visited, oldstmt);
88256 + return gimple_get_lhs(stmt);
88257 +}
88258 +
88259 +static gimple overflow_create_phi_node(gimple oldstmt, tree result)
88260 +{
88261 + basic_block bb;
88262 + gimple phi;
88263 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
88264 +
88265 + bb = gsi_bb(gsi);
88266 +
88267 + phi = create_phi_node(result, bb);
88268 + gsi = gsi_last(phi_nodes(bb));
88269 + gsi_remove(&gsi, false);
88270 +
88271 + gsi = gsi_for_stmt(oldstmt);
88272 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
88273 + gimple_set_bb(phi, bb);
88274 + gimple_set_plf(phi, MY_STMT, true);
88275 + return phi;
88276 +}
88277 +
88278 +static basic_block create_a_first_bb(void)
88279 +{
88280 + basic_block first_bb;
88281 +
88282 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
88283 + if (dom_info_available_p(CDI_DOMINATORS))
88284 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR);
88285 + return first_bb;
88286 +}
88287 +
88288 +static tree cast_old_phi_arg(gimple oldstmt, tree size_overflow_type, tree arg, tree new_var, unsigned int i)
88289 +{
88290 + basic_block bb;
88291 + const_gimple newstmt;
88292 + gimple_stmt_iterator gsi;
88293 + bool before = BEFORE_STMT;
88294 +
88295 + if (TREE_CODE(arg) == SSA_NAME && gimple_code(get_def_stmt(arg)) != GIMPLE_NOP) {
88296 + gsi = gsi_for_stmt(get_def_stmt(arg));
88297 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, AFTER_STMT);
88298 + return gimple_get_lhs(newstmt);
88299 + }
88300 +
88301 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
88302 + gsi = gsi_after_labels(bb);
88303 + if (bb->index == 0) {
88304 + bb = create_a_first_bb();
88305 + gsi = gsi_start_bb(bb);
88306 + }
88307 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, before);
88308 + return gimple_get_lhs(newstmt);
88309 +}
88310 +
88311 +static const_gimple handle_new_phi_arg(const_tree arg, tree new_var, tree new_rhs)
88312 +{
88313 + gimple newstmt;
88314 + gimple_stmt_iterator gsi;
88315 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
88316 + gimple def_newstmt = get_def_stmt(new_rhs);
88317 +
88318 + gsi_insert = gsi_insert_after;
88319 + gsi = gsi_for_stmt(def_newstmt);
88320 +
88321 + switch (gimple_code(get_def_stmt(arg))) {
88322 + case GIMPLE_PHI:
88323 + newstmt = gimple_build_assign(new_var, new_rhs);
88324 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
88325 + gsi_insert = gsi_insert_before;
88326 + break;
88327 + case GIMPLE_ASM:
88328 + case GIMPLE_CALL:
88329 + newstmt = gimple_build_assign(new_var, new_rhs);
88330 + break;
88331 + case GIMPLE_ASSIGN:
88332 + newstmt = gimple_build_assign(new_var, gimple_get_lhs(def_newstmt));
88333 + break;
88334 + default:
88335 + /* unknown gimple_code (handle_build_new_phi_arg) */
88336 + gcc_unreachable();
88337 + }
88338 +
88339 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
88340 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
88341 + gimple_set_plf(newstmt, MY_STMT, true);
88342 + update_stmt(newstmt);
88343 + return newstmt;
88344 +}
88345 +
88346 +static tree build_new_phi_arg(struct pointer_set_t *visited, tree size_overflow_type, tree arg, tree new_var)
88347 +{
88348 + const_gimple newstmt;
88349 + gimple def_stmt;
88350 + tree new_rhs;
88351 +
88352 + new_rhs = expand(visited, arg);
88353 + if (new_rhs == NULL_TREE)
88354 + return NULL_TREE;
88355 +
88356 + def_stmt = get_def_stmt(new_rhs);
88357 + if (gimple_code(def_stmt) == GIMPLE_NOP)
88358 + return NULL_TREE;
88359 + new_rhs = cast_to_new_size_overflow_type(def_stmt, new_rhs, size_overflow_type, AFTER_STMT);
88360 +
88361 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
88362 + return gimple_get_lhs(newstmt);
88363 +}
88364 +
88365 +static tree build_new_phi(struct pointer_set_t *visited, tree orig_result)
88366 +{
88367 + gimple phi, oldstmt = get_def_stmt(orig_result);
88368 + tree new_result, size_overflow_type;
88369 + unsigned int i;
88370 + unsigned int n = gimple_phi_num_args(oldstmt);
88371 +
88372 + size_overflow_type = get_size_overflow_type(oldstmt, orig_result);
88373 +
88374 + new_result = create_new_var(size_overflow_type);
88375 +
88376 + pointer_set_insert(visited, oldstmt);
88377 + phi = overflow_create_phi_node(oldstmt, new_result);
88378 + for (i = 0; i < n; i++) {
88379 + tree arg, lhs;
88380 +
88381 + arg = gimple_phi_arg_def(oldstmt, i);
88382 + if (is_gimple_constant(arg))
88383 + arg = cast_a_tree(size_overflow_type, arg);
88384 + lhs = build_new_phi_arg(visited, size_overflow_type, arg, new_result);
88385 + if (lhs == NULL_TREE)
88386 + lhs = cast_old_phi_arg(oldstmt, size_overflow_type, arg, new_result, i);
88387 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
88388 + }
88389 +
88390 + update_stmt(phi);
88391 + return gimple_phi_result(phi);
88392 +}
88393 +
88394 +static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
88395 +{
88396 + const_gimple assign;
88397 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
88398 + tree origtype = TREE_TYPE(orig_rhs);
88399 +
88400 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
88401 +
88402 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
88403 + return gimple_get_lhs(assign);
88404 +}
88405 +
88406 +static void change_rhs1(gimple stmt, tree new_rhs1)
88407 +{
88408 + tree assign_rhs;
88409 + const_tree rhs = gimple_assign_rhs1(stmt);
88410 +
88411 + assign_rhs = change_assign_rhs(stmt, rhs, new_rhs1);
88412 + gimple_assign_set_rhs1(stmt, assign_rhs);
88413 + update_stmt(stmt);
88414 +}
88415 +
88416 +static bool check_mode_type(const_gimple stmt)
88417 +{
88418 + const_tree lhs = gimple_get_lhs(stmt);
88419 + const_tree lhs_type = TREE_TYPE(lhs);
88420 + const_tree rhs_type = TREE_TYPE(gimple_assign_rhs1(stmt));
88421 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
88422 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
88423 +
88424 + if (rhs_mode == lhs_mode && TYPE_UNSIGNED(rhs_type) == TYPE_UNSIGNED(lhs_type))
88425 + return false;
88426 +
88427 + if (rhs_mode == SImode && lhs_mode == DImode && (TYPE_UNSIGNED(rhs_type) || !TYPE_UNSIGNED(lhs_type)))
88428 + return false;
88429 +
88430 + return true;
88431 +}
88432 +
88433 +static bool check_undefined_integer_operation(const_gimple stmt)
88434 +{
88435 + const_gimple def_stmt;
88436 + const_tree lhs = gimple_get_lhs(stmt);
88437 + const_tree rhs1 = gimple_assign_rhs1(stmt);
88438 + const_tree rhs1_type = TREE_TYPE(rhs1);
88439 + const_tree lhs_type = TREE_TYPE(lhs);
88440 +
88441 + if (TYPE_MODE(rhs1_type) != TYPE_MODE(lhs_type) || TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
88442 + return false;
88443 +
88444 + def_stmt = get_def_stmt(rhs1);
88445 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN)
88446 + return false;
88447 +
88448 + if (gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
88449 + return false;
88450 + return true;
88451 +}
88452 +
88453 +static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
88454 +{
88455 + const_tree rhs1, lhs, rhs1_type, lhs_type;
88456 + enum machine_mode lhs_mode, rhs_mode;
88457 + gimple def_stmt = get_def_stmt(no_const_rhs);
88458 +
88459 + if (!gimple_assign_cast_p(def_stmt))
88460 + return false;
88461 +
88462 + rhs1 = gimple_assign_rhs1(def_stmt);
88463 + lhs = gimple_get_lhs(def_stmt);
88464 + rhs1_type = TREE_TYPE(rhs1);
88465 + lhs_type = TREE_TYPE(lhs);
88466 + rhs_mode = TYPE_MODE(rhs1_type);
88467 + lhs_mode = TYPE_MODE(lhs_type);
88468 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
88469 + return false;
88470 +
88471 + return true;
88472 +}
88473 +
88474 +static tree handle_unary_rhs(struct pointer_set_t *visited, gimple stmt)
88475 +{
88476 + tree size_overflow_type, lhs = gimple_get_lhs(stmt);
88477 + tree new_rhs1, rhs1 = gimple_assign_rhs1(stmt);
88478 + const_tree rhs1_type = TREE_TYPE(rhs1);
88479 + const_tree lhs_type = TREE_TYPE(lhs);
88480 +
88481 + new_rhs1 = expand(visited, rhs1);
88482 +
88483 + if (new_rhs1 == NULL_TREE || TREE_CODE(rhs1_type) == POINTER_TYPE)
88484 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88485 +
88486 + if (gimple_plf(stmt, MY_STMT))
88487 + return lhs;
88488 +
88489 + if (gimple_plf(stmt, NO_CAST_CHECK))
88490 + return follow_overflow_type_and_dup(visited, stmt, rhs1, new_rhs1, NULL_TREE, NULL_TREE);
88491 +
88492 + if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
88493 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
88494 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88495 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
88496 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88497 + }
88498 +
88499 + if (!gimple_assign_cast_p(stmt) || check_undefined_integer_operation(stmt))
88500 + return follow_overflow_type_and_dup(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
88501 +
88502 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
88503 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88504 +
88505 + change_rhs1(stmt, new_rhs1);
88506 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
88507 +
88508 + rhs1 = gimple_assign_rhs1(stmt);
88509 + rhs1_type = TREE_TYPE(rhs1);
88510 + if (TYPE_UNSIGNED(rhs1_type) != TYPE_UNSIGNED(lhs_type))
88511 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
88512 +
88513 + if (!check_mode_type(stmt))
88514 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88515 +
88516 + size_overflow_type = get_size_overflow_type(stmt, lhs);
88517 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88518 +
88519 + check_size_overflow(stmt, size_overflow_type, new_rhs1, lhs, BEFORE_STMT);
88520 +
88521 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88522 +}
88523 +
88524 +static tree handle_unary_ops(struct pointer_set_t *visited, tree lhs)
88525 +{
88526 + gimple def_stmt = get_def_stmt(lhs);
88527 + tree rhs1 = gimple_assign_rhs1(def_stmt);
88528 +
88529 + if (is_gimple_constant(rhs1))
88530 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88531 +
88532 + gcc_assert(TREE_CODE(rhs1) != COND_EXPR);
88533 + switch (TREE_CODE(rhs1)) {
88534 + case SSA_NAME:
88535 + return handle_unary_rhs(visited, def_stmt);
88536 + case ARRAY_REF:
88537 + case BIT_FIELD_REF:
88538 + case ADDR_EXPR:
88539 + case COMPONENT_REF:
88540 + case INDIRECT_REF:
88541 +#if BUILDING_GCC_VERSION >= 4006
88542 + case MEM_REF:
88543 +#endif
88544 + case PARM_DECL:
88545 + case TARGET_MEM_REF:
88546 + case VAR_DECL:
88547 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88548 +
88549 + default:
88550 + debug_gimple_stmt(def_stmt);
88551 + debug_tree(rhs1);
88552 + gcc_unreachable();
88553 + }
88554 +}
88555 +
88556 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
88557 +{
88558 + gimple cond_stmt;
88559 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
88560 +
88561 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
88562 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
88563 + update_stmt(cond_stmt);
88564 +}
88565 +
88566 +static tree create_string_param(tree string)
88567 +{
88568 + tree i_type, a_type;
88569 + const int length = TREE_STRING_LENGTH(string);
88570 +
88571 + gcc_assert(length > 0);
88572 +
88573 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
88574 + a_type = build_array_type(char_type_node, i_type);
88575 +
88576 + TREE_TYPE(string) = a_type;
88577 + TREE_CONSTANT(string) = 1;
88578 + TREE_READONLY(string) = 1;
88579 +
88580 + return build1(ADDR_EXPR, ptr_type_node, string);
88581 +}
88582 +
88583 +static void insert_cond_result(basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
88584 +{
88585 + gimple func_stmt;
88586 + const_gimple def_stmt;
88587 + const_tree loc_line;
88588 + tree loc_file, ssa_name, current_func;
88589 + expanded_location xloc;
88590 + char ssa_name_buf[256];
88591 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
88592 +
88593 + def_stmt = get_def_stmt(arg);
88594 + xloc = expand_location(gimple_location(def_stmt));
88595 +
88596 + if (!gimple_has_location(def_stmt)) {
88597 + xloc = expand_location(gimple_location(stmt));
88598 + if (!gimple_has_location(stmt))
88599 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
88600 + }
88601 +
88602 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
88603 +
88604 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
88605 + loc_file = create_string_param(loc_file);
88606 +
88607 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
88608 + current_func = create_string_param(current_func);
88609 +
88610 + snprintf(ssa_name_buf, 256, "%s_%u (%s)\n", NAME(SSA_NAME_VAR(arg)), SSA_NAME_VERSION(arg), min ? "min" : "max");
88611 + ssa_name = build_string(256, ssa_name_buf);
88612 + ssa_name = create_string_param(ssa_name);
88613 +
88614 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
88615 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
88616 +
88617 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
88618 +}
88619 +
88620 +static void __unused print_the_code_insertions(const_gimple stmt)
88621 +{
88622 + location_t loc = gimple_location(stmt);
88623 +
88624 + inform(loc, "Integer size_overflow check applied here.");
88625 +}
88626 +
88627 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value, bool before, bool min)
88628 +{
88629 + basic_block cond_bb, join_bb, bb_true;
88630 + edge e;
88631 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
88632 +
88633 + cond_bb = gimple_bb(stmt);
88634 + if (before)
88635 + gsi_prev(&gsi);
88636 + if (gsi_end_p(gsi))
88637 + e = split_block_after_labels(cond_bb);
88638 + else
88639 + e = split_block(cond_bb, gsi_stmt(gsi));
88640 + cond_bb = e->src;
88641 + join_bb = e->dest;
88642 + e->flags = EDGE_FALSE_VALUE;
88643 + e->probability = REG_BR_PROB_BASE;
88644 +
88645 + bb_true = create_empty_bb(cond_bb);
88646 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
88647 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
88648 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
88649 +
88650 + if (dom_info_available_p(CDI_DOMINATORS)) {
88651 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
88652 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
88653 + }
88654 +
88655 + if (current_loops != NULL) {
88656 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
88657 + add_bb_to_loop(bb_true, cond_bb->loop_father);
88658 + }
88659 +
88660 + insert_cond(cond_bb, arg, cond_code, type_value);
88661 + insert_cond_result(bb_true, stmt, arg, min);
88662 +
88663 +// print_the_code_insertions(stmt);
88664 +}
88665 +
88666 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
88667 +{
88668 + const_tree rhs_type = TREE_TYPE(rhs);
88669 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
88670 +
88671 + gcc_assert(rhs_type != NULL_TREE);
88672 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
88673 + return;
88674 +
88675 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == BOOLEAN_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
88676 +
88677 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
88678 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
88679 +
88680 + gcc_assert(!TREE_OVERFLOW(type_max));
88681 +
88682 + cast_rhs_type = TREE_TYPE(cast_rhs);
88683 + type_max_type = TREE_TYPE(type_max);
88684 + type_min_type = TREE_TYPE(type_min);
88685 + gcc_assert(useless_type_conversion_p(cast_rhs_type, type_max_type));
88686 + gcc_assert(useless_type_conversion_p(type_max_type, type_min_type));
88687 +
88688 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max, before, false);
88689 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min, before, true);
88690 +}
88691 +
88692 +static tree get_size_overflow_type_for_intentional_overflow(gimple def_stmt, tree change_rhs)
88693 +{
88694 + gimple change_rhs_def_stmt;
88695 + tree lhs = gimple_get_lhs(def_stmt);
88696 + tree lhs_type = TREE_TYPE(lhs);
88697 + tree rhs1_type = TREE_TYPE(gimple_assign_rhs1(def_stmt));
88698 + tree rhs2_type = TREE_TYPE(gimple_assign_rhs2(def_stmt));
88699 +
88700 + if (change_rhs == NULL_TREE)
88701 + return get_size_overflow_type(def_stmt, lhs);
88702 +
88703 + change_rhs_def_stmt = get_def_stmt(change_rhs);
88704 +
88705 + if (TREE_CODE_CLASS(gimple_assign_rhs_code(def_stmt)) == tcc_comparison)
88706 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
88707 +
88708 + if (gimple_assign_rhs_code(def_stmt) == LSHIFT_EXPR)
88709 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
88710 +
88711 + if (gimple_assign_rhs_code(def_stmt) == RSHIFT_EXPR)
88712 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
88713 +
88714 + if (!useless_type_conversion_p(lhs_type, rhs1_type) || !useless_type_conversion_p(rhs1_type, rhs2_type)) {
88715 + debug_gimple_stmt(def_stmt);
88716 + gcc_unreachable();
88717 + }
88718 +
88719 + return get_size_overflow_type(def_stmt, lhs);
88720 +}
88721 +
88722 +static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
88723 +{
88724 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
88725 + return false;
88726 + if (!is_gimple_constant(rhs))
88727 + return false;
88728 + return true;
88729 +}
88730 +
88731 +static tree get_cast_def_stmt_rhs(const_tree new_rhs)
88732 +{
88733 + gimple def_stmt;
88734 +
88735 + def_stmt = get_def_stmt(new_rhs);
88736 + // get_size_overflow_type
88737 + if (LONG_TYPE_SIZE != GET_MODE_BITSIZE(SImode))
88738 + gcc_assert(gimple_assign_cast_p(def_stmt));
88739 + return gimple_assign_rhs1(def_stmt);
88740 +}
88741 +
88742 +static tree cast_to_int_TI_type_and_check(gimple stmt, tree new_rhs)
88743 +{
88744 + gimple_stmt_iterator gsi;
88745 + const_gimple cast_stmt;
88746 + gimple def_stmt;
88747 + enum machine_mode mode = TYPE_MODE(TREE_TYPE(new_rhs));
88748 +
88749 + if (mode != TImode && mode != DImode) {
88750 + def_stmt = get_def_stmt(new_rhs);
88751 + gcc_assert(gimple_assign_cast_p(def_stmt));
88752 + new_rhs = gimple_assign_rhs1(def_stmt);
88753 + mode = TYPE_MODE(TREE_TYPE(new_rhs));
88754 + }
88755 +
88756 + gcc_assert(mode == TImode || mode == DImode);
88757 +
88758 + if (mode == TYPE_MODE(intTI_type_node) && useless_type_conversion_p(TREE_TYPE(new_rhs), intTI_type_node))
88759 + return new_rhs;
88760 +
88761 + gsi = gsi_for_stmt(stmt);
88762 + cast_stmt = build_cast_stmt(intTI_type_node, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
88763 + new_rhs = gimple_get_lhs(cast_stmt);
88764 +
88765 + if (mode == DImode)
88766 + return new_rhs;
88767 +
88768 + check_size_overflow(stmt, intTI_type_node, new_rhs, new_rhs, BEFORE_STMT);
88769 +
88770 + return new_rhs;
88771 +}
88772 +
88773 +static bool is_an_integer_trunction(const_gimple stmt)
88774 +{
88775 + gimple rhs1_def_stmt, rhs2_def_stmt;
88776 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1;
88777 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode;
88778 + const_tree rhs1 = gimple_assign_rhs1(stmt);
88779 + const_tree rhs2 = gimple_assign_rhs2(stmt);
88780 + enum machine_mode rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1));
88781 + enum machine_mode rhs2_mode = TYPE_MODE(TREE_TYPE(rhs2));
88782 +
88783 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
88784 + return false;
88785 +
88786 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
88787 +
88788 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR || rhs1_mode != SImode || rhs2_mode != SImode)
88789 + return false;
88790 +
88791 + rhs1_def_stmt = get_def_stmt(rhs1);
88792 + rhs2_def_stmt = get_def_stmt(rhs2);
88793 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
88794 + return false;
88795 +
88796 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
88797 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
88798 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
88799 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
88800 + if (rhs1_def_stmt_rhs1_mode != DImode || rhs2_def_stmt_rhs1_mode != DImode)
88801 + return false;
88802 +
88803 + gimple_set_plf(rhs1_def_stmt, NO_CAST_CHECK, true);
88804 + gimple_set_plf(rhs2_def_stmt, NO_CAST_CHECK, true);
88805 + return true;
88806 +}
88807 +
88808 +static tree handle_integer_truncation(struct pointer_set_t *visited, const_tree lhs)
88809 +{
88810 + tree new_rhs1, new_rhs2;
88811 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
88812 + tree new_rhs1_def_stmt_rhs1_type, new_rhs2_def_stmt_rhs1_type;
88813 + gimple assign, stmt = get_def_stmt(lhs);
88814 + tree rhs1 = gimple_assign_rhs1(stmt);
88815 + tree rhs2 = gimple_assign_rhs2(stmt);
88816 +
88817 + if (!is_an_integer_trunction(stmt))
88818 + return NULL_TREE;
88819 +
88820 + new_rhs1 = expand(visited, rhs1);
88821 + new_rhs2 = expand(visited, rhs2);
88822 +
88823 + new_rhs1_def_stmt_rhs1 = get_cast_def_stmt_rhs(new_rhs1);
88824 + new_rhs2_def_stmt_rhs1 = get_cast_def_stmt_rhs(new_rhs2);
88825 +
88826 + new_rhs1_def_stmt_rhs1_type = TREE_TYPE(new_rhs1_def_stmt_rhs1);
88827 + new_rhs2_def_stmt_rhs1_type = TREE_TYPE(new_rhs2_def_stmt_rhs1);
88828 +
88829 + if (!useless_type_conversion_p(new_rhs1_def_stmt_rhs1_type, new_rhs2_def_stmt_rhs1_type)) {
88830 + new_rhs1_def_stmt_rhs1 = cast_to_int_TI_type_and_check(stmt, new_rhs1_def_stmt_rhs1);
88831 + new_rhs2_def_stmt_rhs1 = cast_to_int_TI_type_and_check(stmt, new_rhs2_def_stmt_rhs1);
88832 + }
88833 +
88834 + assign = create_binary_assign(MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
88835 + new_lhs = gimple_get_lhs(assign);
88836 + check_size_overflow(assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
88837 +
88838 + return follow_overflow_type_and_dup(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
88839 +}
88840 +
88841 +static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
88842 +{
88843 + const_gimple def_stmt;
88844 +
88845 + if (TREE_CODE(rhs) != SSA_NAME)
88846 + return false;
88847 +
88848 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
88849 + return false;
88850 +
88851 + def_stmt = get_def_stmt(rhs);
88852 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
88853 + return false;
88854 +
88855 + return true;
88856 +}
88857 +
88858 +static tree handle_intentional_overflow(struct pointer_set_t *visited, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs1, tree new_rhs2)
88859 +{
88860 + tree new_rhs, size_overflow_type, orig_rhs;
88861 + void (*gimple_assign_set_rhs)(gimple, tree);
88862 + tree rhs1 = gimple_assign_rhs1(stmt);
88863 + tree rhs2 = gimple_assign_rhs2(stmt);
88864 + tree lhs = gimple_get_lhs(stmt);
88865 +
88866 + if (change_rhs == NULL_TREE)
88867 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88868 +
88869 + if (new_rhs2 == NULL_TREE) {
88870 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs1);
88871 + new_rhs2 = cast_a_tree(size_overflow_type, rhs2);
88872 + orig_rhs = rhs1;
88873 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
88874 + } else {
88875 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs2);
88876 + new_rhs1 = cast_a_tree(size_overflow_type, rhs1);
88877 + orig_rhs = rhs2;
88878 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
88879 + }
88880 +
88881 + change_rhs = cast_to_new_size_overflow_type(stmt, change_rhs, size_overflow_type, BEFORE_STMT);
88882 +
88883 + if (check_overflow)
88884 + check_size_overflow(stmt, size_overflow_type, change_rhs, orig_rhs, BEFORE_STMT);
88885 +
88886 + new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
88887 + gimple_assign_set_rhs(stmt, new_rhs);
88888 + update_stmt(stmt);
88889 +
88890 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88891 +}
88892 +
88893 +static tree handle_binary_ops(struct pointer_set_t *visited, tree lhs)
88894 +{
88895 + tree rhs1, rhs2, new_lhs;
88896 + gimple def_stmt = get_def_stmt(lhs);
88897 + tree new_rhs1 = NULL_TREE;
88898 + tree new_rhs2 = NULL_TREE;
88899 +
88900 + rhs1 = gimple_assign_rhs1(def_stmt);
88901 + rhs2 = gimple_assign_rhs2(def_stmt);
88902 +
88903 + /* no DImode/TImode division in the 32/64 bit kernel */
88904 + switch (gimple_assign_rhs_code(def_stmt)) {
88905 + case RDIV_EXPR:
88906 + case TRUNC_DIV_EXPR:
88907 + case CEIL_DIV_EXPR:
88908 + case FLOOR_DIV_EXPR:
88909 + case ROUND_DIV_EXPR:
88910 + case TRUNC_MOD_EXPR:
88911 + case CEIL_MOD_EXPR:
88912 + case FLOOR_MOD_EXPR:
88913 + case ROUND_MOD_EXPR:
88914 + case EXACT_DIV_EXPR:
88915 + case POINTER_PLUS_EXPR:
88916 + case BIT_AND_EXPR:
88917 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88918 + default:
88919 + break;
88920 + }
88921 +
88922 + new_lhs = handle_integer_truncation(visited, lhs);
88923 + if (new_lhs != NULL_TREE)
88924 + return new_lhs;
88925 +
88926 + if (TREE_CODE(rhs1) == SSA_NAME)
88927 + new_rhs1 = expand(visited, rhs1);
88928 + if (TREE_CODE(rhs2) == SSA_NAME)
88929 + new_rhs2 = expand(visited, rhs2);
88930 +
88931 + if (is_a_neg_overflow(def_stmt, rhs2))
88932 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs1, new_rhs1, NULL_TREE);
88933 + if (is_a_neg_overflow(def_stmt, rhs1))
88934 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs2, NULL_TREE, new_rhs2);
88935 +
88936 + if (is_a_constant_overflow(def_stmt, rhs2))
88937 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, new_rhs1, NULL_TREE);
88938 + if (is_a_constant_overflow(def_stmt, rhs1))
88939 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, NULL_TREE, new_rhs2);
88940 +
88941 + return follow_overflow_type_and_dup(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
88942 +}
88943 +
88944 +#if BUILDING_GCC_VERSION >= 4007
88945 +static tree get_new_rhs(struct pointer_set_t *visited, tree size_overflow_type, tree rhs)
88946 +{
88947 + if (is_gimple_constant(rhs))
88948 + return cast_a_tree(size_overflow_type, rhs);
88949 + if (TREE_CODE(rhs) != SSA_NAME)
88950 + return NULL_TREE;
88951 + return expand(visited, rhs);
88952 +}
88953 +
88954 +static tree handle_ternary_ops(struct pointer_set_t *visited, tree lhs)
88955 +{
88956 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
88957 + gimple def_stmt = get_def_stmt(lhs);
88958 +
88959 + size_overflow_type = get_size_overflow_type(def_stmt, lhs);
88960 +
88961 + rhs1 = gimple_assign_rhs1(def_stmt);
88962 + rhs2 = gimple_assign_rhs2(def_stmt);
88963 + rhs3 = gimple_assign_rhs3(def_stmt);
88964 + new_rhs1 = get_new_rhs(visited, size_overflow_type, rhs1);
88965 + new_rhs2 = get_new_rhs(visited, size_overflow_type, rhs2);
88966 + new_rhs3 = get_new_rhs(visited, size_overflow_type, rhs3);
88967 +
88968 + return follow_overflow_type_and_dup(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
88969 +}
88970 +#endif
88971 +
88972 +static tree get_size_overflow_type(gimple stmt, const_tree node)
88973 +{
88974 + const_tree type;
88975 +
88976 + gcc_assert(node != NULL_TREE);
88977 +
88978 + type = TREE_TYPE(node);
88979 +
88980 + if (gimple_plf(stmt, MY_STMT))
88981 + return TREE_TYPE(node);
88982 +
88983 + switch (TYPE_MODE(type)) {
88984 + case QImode:
88985 + return (TYPE_UNSIGNED(type)) ? unsigned_intHI_type_node : intHI_type_node;
88986 + case HImode:
88987 + return (TYPE_UNSIGNED(type)) ? unsigned_intSI_type_node : intSI_type_node;
88988 + case SImode:
88989 + return (TYPE_UNSIGNED(type)) ? unsigned_intDI_type_node : intDI_type_node;
88990 + case DImode:
88991 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
88992 + return (TYPE_UNSIGNED(type)) ? unsigned_intDI_type_node : intDI_type_node;
88993 + return (TYPE_UNSIGNED(type)) ? unsigned_intTI_type_node : intTI_type_node;
88994 + default:
88995 + debug_tree((tree)node);
88996 + error("%s: unsupported gcc configuration.", __func__);
88997 + gcc_unreachable();
88998 + }
88999 +}
89000 +
89001 +static tree expand_visited(gimple def_stmt)
89002 +{
89003 + const_gimple next_stmt;
89004 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
89005 +
89006 + gsi_next(&gsi);
89007 + next_stmt = gsi_stmt(gsi);
89008 +
89009 + gcc_assert(gimple_plf((gimple)next_stmt, MY_STMT));
89010 +
89011 + switch (gimple_code(next_stmt)) {
89012 + case GIMPLE_ASSIGN:
89013 + return gimple_get_lhs(next_stmt);
89014 + case GIMPLE_PHI:
89015 + return gimple_phi_result(next_stmt);
89016 + case GIMPLE_CALL:
89017 + return gimple_call_lhs(next_stmt);
89018 + default:
89019 + return NULL_TREE;
89020 + }
89021 +}
89022 +
89023 +static tree expand(struct pointer_set_t *visited, tree lhs)
89024 +{
89025 + gimple def_stmt;
89026 + enum tree_code code = TREE_CODE(TREE_TYPE(lhs));
89027 +
89028 + if (is_gimple_constant(lhs))
89029 + return NULL_TREE;
89030 +
89031 + if (TREE_CODE(lhs) == ADDR_EXPR)
89032 + return NULL_TREE;
89033 +
89034 + if (code == REAL_TYPE)
89035 + return NULL_TREE;
89036 +
89037 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE || code == ENUMERAL_TYPE);
89038 +
89039 +
89040 + def_stmt = get_def_stmt(lhs);
89041 +
89042 + if (!def_stmt)
89043 + return NULL_TREE;
89044 +
89045 + if (gimple_plf(def_stmt, MY_STMT))
89046 + return lhs;
89047 +
89048 + if (pointer_set_contains(visited, def_stmt))
89049 + return expand_visited(def_stmt);
89050 +
89051 + switch (gimple_code(def_stmt)) {
89052 + case GIMPLE_NOP:
89053 + return NULL_TREE;
89054 + case GIMPLE_PHI:
89055 + return build_new_phi(visited, lhs);
89056 + case GIMPLE_CALL:
89057 + case GIMPLE_ASM:
89058 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
89059 + case GIMPLE_ASSIGN:
89060 + switch (gimple_num_ops(def_stmt)) {
89061 + case 2:
89062 + return handle_unary_ops(visited, lhs);
89063 + case 3:
89064 + return handle_binary_ops(visited, lhs);
89065 +#if BUILDING_GCC_VERSION >= 4007
89066 + case 4:
89067 + return handle_ternary_ops(visited, lhs);
89068 +#endif
89069 + }
89070 + default:
89071 + debug_gimple_stmt(def_stmt);
89072 + error("%s: unknown gimple code", __func__);
89073 + gcc_unreachable();
89074 + }
89075 +}
89076 +
89077 +static void change_function_arg(gimple stmt, const_tree origarg, unsigned int argnum, tree newarg)
89078 +{
89079 + const_gimple assign;
89080 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
89081 + tree origtype = TREE_TYPE(origarg);
89082 +
89083 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
89084 +
89085 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
89086 +
89087 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
89088 + update_stmt(stmt);
89089 +}
89090 +
89091 +static bool get_function_arg(unsigned int* argnum, const_tree fndecl)
89092 +{
89093 + const char *origid;
89094 + tree arg;
89095 + const_tree origarg;
89096 +
89097 + if (!DECL_ABSTRACT_ORIGIN(fndecl))
89098 + return true;
89099 +
89100 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
89101 + while (origarg && *argnum) {
89102 + (*argnum)--;
89103 + origarg = TREE_CHAIN(origarg);
89104 + }
89105 +
89106 + gcc_assert(*argnum == 0);
89107 +
89108 + gcc_assert(origarg != NULL_TREE);
89109 + origid = NAME(origarg);
89110 + *argnum = 0;
89111 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
89112 + if (!strcmp(origid, NAME(arg)))
89113 + return true;
89114 + (*argnum)++;
89115 + }
89116 + return false;
89117 +}
89118 +
89119 +static bool skip_types(const_tree var)
89120 +{
89121 + switch (TREE_CODE(var)) {
89122 + case ADDR_EXPR:
89123 +#if BUILDING_GCC_VERSION >= 4006
89124 + case MEM_REF:
89125 +#endif
89126 + case ARRAY_REF:
89127 + case BIT_FIELD_REF:
89128 + case INDIRECT_REF:
89129 + case TARGET_MEM_REF:
89130 + case VAR_DECL:
89131 + return true;
89132 + default:
89133 + break;
89134 + }
89135 + return false;
89136 +}
89137 +
89138 +static bool walk_phi(struct pointer_set_t *visited, const_tree result)
89139 +{
89140 + gimple phi = get_def_stmt(result);
89141 + unsigned int i, n = gimple_phi_num_args(phi);
89142 +
89143 + if (!phi)
89144 + return false;
89145 +
89146 + pointer_set_insert(visited, phi);
89147 + for (i = 0; i < n; i++) {
89148 + const_tree arg = gimple_phi_arg_def(phi, i);
89149 + if (pre_expand(visited, arg))
89150 + return true;
89151 + }
89152 + return false;
89153 +}
89154 +
89155 +static bool walk_unary_ops(struct pointer_set_t *visited, const_tree lhs)
89156 +{
89157 + gimple def_stmt = get_def_stmt(lhs);
89158 + const_tree rhs;
89159 +
89160 + if (!def_stmt)
89161 + return false;
89162 +
89163 + rhs = gimple_assign_rhs1(def_stmt);
89164 + if (pre_expand(visited, rhs))
89165 + return true;
89166 + return false;
89167 +}
89168 +
89169 +static bool walk_binary_ops(struct pointer_set_t *visited, const_tree lhs)
89170 +{
89171 + bool rhs1_found, rhs2_found;
89172 + gimple def_stmt = get_def_stmt(lhs);
89173 + const_tree rhs1, rhs2;
89174 +
89175 + if (!def_stmt)
89176 + return false;
89177 +
89178 + rhs1 = gimple_assign_rhs1(def_stmt);
89179 + rhs2 = gimple_assign_rhs2(def_stmt);
89180 + rhs1_found = pre_expand(visited, rhs1);
89181 + rhs2_found = pre_expand(visited, rhs2);
89182 +
89183 + return rhs1_found || rhs2_found;
89184 +}
89185 +
89186 +static const_tree search_field_decl(const_tree comp_ref)
89187 +{
89188 + const_tree field = NULL_TREE;
89189 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
89190 +
89191 + for (i = 0; i < len; i++) {
89192 + field = TREE_OPERAND(comp_ref, i);
89193 + if (TREE_CODE(field) == FIELD_DECL)
89194 + break;
89195 + }
89196 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
89197 + return field;
89198 +}
89199 +
89200 +static enum marked mark_status(const_tree fndecl, unsigned int argnum)
89201 +{
89202 + const_tree attr, p;
89203 +
89204 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(fndecl));
89205 + if (!attr || !TREE_VALUE(attr))
89206 + return MARKED_NO;
89207 +
89208 + p = TREE_VALUE(attr);
89209 + if (!TREE_INT_CST_LOW(TREE_VALUE(p)))
89210 + return MARKED_NOT_INTENTIONAL;
89211 +
89212 + do {
89213 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(p)))
89214 + return MARKED_YES;
89215 + p = TREE_CHAIN(p);
89216 + } while (p);
89217 +
89218 + return MARKED_NO;
89219 +}
89220 +
89221 +static void print_missing_msg(tree func, unsigned int argnum)
89222 +{
89223 + unsigned int new_hash;
89224 + size_t len;
89225 + unsigned char tree_codes[CODES_LIMIT];
89226 + location_t loc = DECL_SOURCE_LOCATION(func);
89227 + const char *curfunc = get_asm_name(func);
89228 +
89229 + len = get_function_decl(func, tree_codes);
89230 + new_hash = get_hash_num(curfunc, (const char *) tree_codes, len, 0);
89231 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, new_hash);
89232 +}
89233 +
89234 +static unsigned int search_missing_attribute(const_tree arg)
89235 +{
89236 + const_tree type = TREE_TYPE(arg);
89237 + tree func = get_original_function_decl(current_function_decl);
89238 + unsigned int argnum;
89239 + const struct size_overflow_hash *hash;
89240 +
89241 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
89242 +
89243 + if (TREE_CODE(type) == POINTER_TYPE)
89244 + return 0;
89245 +
89246 + argnum = find_arg_number(arg, func);
89247 + if (argnum == 0)
89248 + return 0;
89249 +
89250 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(func)))
89251 + return argnum;
89252 +
89253 + hash = get_function_hash(func);
89254 + if (!hash || !(hash->param & (1U << argnum))) {
89255 + print_missing_msg(func, argnum);
89256 + return 0;
89257 + }
89258 + return argnum;
89259 +}
89260 +
89261 +static bool is_already_marked(const_tree lhs)
89262 +{
89263 + unsigned int argnum;
89264 + const_tree fndecl;
89265 +
89266 + argnum = search_missing_attribute(lhs);
89267 + fndecl = get_original_function_decl(current_function_decl);
89268 + if (argnum && mark_status(fndecl, argnum) == MARKED_YES)
89269 + return true;
89270 + return false;
89271 +}
89272 +
89273 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs)
89274 +{
89275 + const_gimple def_stmt;
89276 +
89277 + if (is_gimple_constant(lhs))
89278 + return false;
89279 +
89280 + if (skip_types(lhs))
89281 + return false;
89282 +
89283 + if (TREE_CODE(lhs) == PARM_DECL)
89284 + return is_already_marked(lhs);
89285 +
89286 + if (TREE_CODE(lhs) == COMPONENT_REF) {
89287 + const_tree field, attr;
89288 +
89289 + field = search_field_decl(lhs);
89290 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(field));
89291 + if (!attr || !TREE_VALUE(attr))
89292 + return false;
89293 + return true;
89294 + }
89295 +
89296 + def_stmt = get_def_stmt(lhs);
89297 +
89298 + if (!def_stmt)
89299 + return false;
89300 +
89301 + if (pointer_set_contains(visited, def_stmt))
89302 + return false;
89303 +
89304 + switch (gimple_code(def_stmt)) {
89305 + case GIMPLE_NOP:
89306 + if (TREE_CODE(SSA_NAME_VAR(lhs)) == PARM_DECL)
89307 + return is_already_marked(lhs);
89308 + return false;
89309 + case GIMPLE_PHI:
89310 + return walk_phi(visited, lhs);
89311 + case GIMPLE_CALL:
89312 + case GIMPLE_ASM:
89313 + return false;
89314 + case GIMPLE_ASSIGN:
89315 + switch (gimple_num_ops(def_stmt)) {
89316 + case 2:
89317 + return walk_unary_ops(visited, lhs);
89318 + case 3:
89319 + return walk_binary_ops(visited, lhs);
89320 + }
89321 + default:
89322 + debug_gimple_stmt((gimple)def_stmt);
89323 + error("%s: unknown gimple code", __func__);
89324 + gcc_unreachable();
89325 + }
89326 +}
89327 +
89328 +static bool search_attributes(tree fndecl, const_tree arg, unsigned int argnum)
89329 +{
89330 + struct pointer_set_t *visited;
89331 + bool is_found;
89332 + enum marked is_marked;
89333 + location_t loc;
89334 +
89335 + visited = pointer_set_create();
89336 + is_found = pre_expand(visited, arg);
89337 + pointer_set_destroy(visited);
89338 +
89339 + is_marked = mark_status(fndecl, argnum + 1);
89340 + if ((is_found && is_marked == MARKED_YES) || is_marked == MARKED_NOT_INTENTIONAL)
89341 + return true;
89342 +
89343 + if (is_found) {
89344 + loc = DECL_SOURCE_LOCATION(fndecl);
89345 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", get_asm_name(fndecl), argnum + 1);
89346 + return true;
89347 + }
89348 + return false;
89349 +}
89350 +
89351 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
89352 +{
89353 + struct pointer_set_t *visited;
89354 + tree arg, newarg;
89355 + bool match;
89356 +
89357 + match = get_function_arg(&argnum, fndecl);
89358 + if (!match)
89359 + return;
89360 + gcc_assert(gimple_call_num_args(stmt) > argnum);
89361 + arg = gimple_call_arg(stmt, argnum);
89362 + if (arg == NULL_TREE)
89363 + return;
89364 +
89365 + if (is_gimple_constant(arg))
89366 + return;
89367 +
89368 + if (search_attributes(fndecl, arg, argnum))
89369 + return;
89370 +
89371 + if (TREE_CODE(arg) != SSA_NAME)
89372 + return;
89373 +
89374 + check_arg_type(arg);
89375 +
89376 + visited = pointer_set_create();
89377 + newarg = expand(visited, arg);
89378 + pointer_set_destroy(visited);
89379 +
89380 + if (newarg == NULL_TREE)
89381 + return;
89382 +
89383 + change_function_arg(stmt, arg, argnum, newarg);
89384 +
89385 + check_size_overflow(stmt, TREE_TYPE(newarg), newarg, arg, BEFORE_STMT);
89386 +}
89387 +
89388 +static void handle_function_by_attribute(gimple stmt, const_tree attr, tree fndecl)
89389 +{
89390 + tree p = TREE_VALUE(attr);
89391 + do {
89392 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
89393 + p = TREE_CHAIN(p);
89394 + } while (p);
89395 +}
89396 +
89397 +static void handle_function_by_hash(gimple stmt, tree fndecl)
89398 +{
89399 + tree orig_fndecl;
89400 + unsigned int num;
89401 + const struct size_overflow_hash *hash;
89402 +
89403 + orig_fndecl = get_original_function_decl(fndecl);
89404 + if (C_DECL_IMPLICIT(orig_fndecl))
89405 + return;
89406 + hash = get_function_hash(orig_fndecl);
89407 + if (!hash)
89408 + return;
89409 +
89410 + for (num = 1; num <= MAX_PARAM; num++)
89411 + if (hash->param & (1U << num))
89412 + handle_function_arg(stmt, fndecl, num - 1);
89413 +}
89414 +
89415 +static void set_plf_false(void)
89416 +{
89417 + basic_block bb;
89418 +
89419 + FOR_ALL_BB(bb) {
89420 + gimple_stmt_iterator si;
89421 +
89422 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
89423 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
89424 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
89425 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
89426 + }
89427 +}
89428 +
89429 +static unsigned int handle_function(void)
89430 +{
89431 + basic_block next, bb = ENTRY_BLOCK_PTR->next_bb;
89432 +
89433 + set_plf_false();
89434 +
89435 + do {
89436 + gimple_stmt_iterator gsi;
89437 + next = bb->next_bb;
89438 +
89439 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
89440 + tree fndecl, attr;
89441 + gimple stmt = gsi_stmt(gsi);
89442 +
89443 + if (!(is_gimple_call(stmt)))
89444 + continue;
89445 + fndecl = gimple_call_fndecl(stmt);
89446 + if (fndecl == NULL_TREE)
89447 + continue;
89448 + if (gimple_call_num_args(stmt) == 0)
89449 + continue;
89450 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
89451 + if (!attr || !TREE_VALUE(attr))
89452 + handle_function_by_hash(stmt, fndecl);
89453 + else
89454 + handle_function_by_attribute(stmt, attr, fndecl);
89455 + gsi = gsi_for_stmt(stmt);
89456 + next = gimple_bb(stmt)->next_bb;
89457 + }
89458 + bb = next;
89459 + } while (bb);
89460 + return 0;
89461 +}
89462 +
89463 +static struct gimple_opt_pass size_overflow_pass = {
89464 + .pass = {
89465 + .type = GIMPLE_PASS,
89466 + .name = "size_overflow",
89467 + .gate = NULL,
89468 + .execute = handle_function,
89469 + .sub = NULL,
89470 + .next = NULL,
89471 + .static_pass_number = 0,
89472 + .tv_id = TV_NONE,
89473 + .properties_required = PROP_cfg | PROP_referenced_vars,
89474 + .properties_provided = 0,
89475 + .properties_destroyed = 0,
89476 + .todo_flags_start = 0,
89477 + .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
89478 + }
89479 +};
89480 +
89481 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
89482 +{
89483 + tree fntype;
89484 +
89485 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
89486 +
89487 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
89488 + fntype = build_function_type_list(void_type_node,
89489 + const_char_ptr_type_node,
89490 + unsigned_type_node,
89491 + const_char_ptr_type_node,
89492 + const_char_ptr_type_node,
89493 + NULL_TREE);
89494 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
89495 +
89496 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
89497 + TREE_PUBLIC(report_size_overflow_decl) = 1;
89498 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
89499 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
89500 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
89501 +}
89502 +
89503 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
89504 +{
89505 + int i;
89506 + const char * const plugin_name = plugin_info->base_name;
89507 + const int argc = plugin_info->argc;
89508 + const struct plugin_argument * const argv = plugin_info->argv;
89509 + bool enable = true;
89510 +
89511 + struct register_pass_info size_overflow_pass_info = {
89512 + .pass = &size_overflow_pass.pass,
89513 + .reference_pass_name = "ssa",
89514 + .ref_pass_instance_number = 1,
89515 + .pos_op = PASS_POS_INSERT_AFTER
89516 + };
89517 +
89518 + if (!plugin_default_version_check(version, &gcc_version)) {
89519 + error(G_("incompatible gcc/plugin versions"));
89520 + return 1;
89521 + }
89522 +
89523 + for (i = 0; i < argc; ++i) {
89524 + if (!strcmp(argv[i].key, "no-size-overflow")) {
89525 + enable = false;
89526 + continue;
89527 + }
89528 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
89529 + }
89530 +
89531 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
89532 + if (enable) {
89533 + register_callback("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
89534 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
89535 + }
89536 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
89537 +
89538 + return 0;
89539 +}
89540 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
89541 new file mode 100644
89542 index 0000000..38d2014
89543 --- /dev/null
89544 +++ b/tools/gcc/stackleak_plugin.c
89545 @@ -0,0 +1,313 @@
89546 +/*
89547 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
89548 + * Licensed under the GPL v2
89549 + *
89550 + * Note: the choice of the license means that the compilation process is
89551 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
89552 + * but for the kernel it doesn't matter since it doesn't link against
89553 + * any of the gcc libraries
89554 + *
89555 + * gcc plugin to help implement various PaX features
89556 + *
89557 + * - track lowest stack pointer
89558 + *
89559 + * TODO:
89560 + * - initialize all local variables
89561 + *
89562 + * BUGS:
89563 + * - none known
89564 + */
89565 +#include "gcc-plugin.h"
89566 +#include "config.h"
89567 +#include "system.h"
89568 +#include "coretypes.h"
89569 +#include "tree.h"
89570 +#include "tree-pass.h"
89571 +#include "flags.h"
89572 +#include "intl.h"
89573 +#include "toplev.h"
89574 +#include "plugin.h"
89575 +//#include "expr.h" where are you...
89576 +#include "diagnostic.h"
89577 +#include "plugin-version.h"
89578 +#include "tm.h"
89579 +#include "function.h"
89580 +#include "basic-block.h"
89581 +#include "gimple.h"
89582 +#include "rtl.h"
89583 +#include "emit-rtl.h"
89584 +
89585 +extern void print_gimple_stmt(FILE *, gimple, int, int);
89586 +
89587 +int plugin_is_GPL_compatible;
89588 +
89589 +static int track_frame_size = -1;
89590 +static const char track_function[] = "pax_track_stack";
89591 +static const char check_function[] = "pax_check_alloca";
89592 +static bool init_locals;
89593 +
89594 +static struct plugin_info stackleak_plugin_info = {
89595 + .version = "201203140940",
89596 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
89597 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
89598 +};
89599 +
89600 +static bool gate_stackleak_track_stack(void);
89601 +static unsigned int execute_stackleak_tree_instrument(void);
89602 +static unsigned int execute_stackleak_final(void);
89603 +
89604 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
89605 + .pass = {
89606 + .type = GIMPLE_PASS,
89607 + .name = "stackleak_tree_instrument",
89608 + .gate = gate_stackleak_track_stack,
89609 + .execute = execute_stackleak_tree_instrument,
89610 + .sub = NULL,
89611 + .next = NULL,
89612 + .static_pass_number = 0,
89613 + .tv_id = TV_NONE,
89614 + .properties_required = PROP_gimple_leh | PROP_cfg,
89615 + .properties_provided = 0,
89616 + .properties_destroyed = 0,
89617 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
89618 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
89619 + }
89620 +};
89621 +
89622 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
89623 + .pass = {
89624 + .type = RTL_PASS,
89625 + .name = "stackleak_final",
89626 + .gate = gate_stackleak_track_stack,
89627 + .execute = execute_stackleak_final,
89628 + .sub = NULL,
89629 + .next = NULL,
89630 + .static_pass_number = 0,
89631 + .tv_id = TV_NONE,
89632 + .properties_required = 0,
89633 + .properties_provided = 0,
89634 + .properties_destroyed = 0,
89635 + .todo_flags_start = 0,
89636 + .todo_flags_finish = TODO_dump_func
89637 + }
89638 +};
89639 +
89640 +static bool gate_stackleak_track_stack(void)
89641 +{
89642 + return track_frame_size >= 0;
89643 +}
89644 +
89645 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
89646 +{
89647 + gimple check_alloca;
89648 + tree fntype, fndecl, alloca_size;
89649 +
89650 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
89651 + fndecl = build_fn_decl(check_function, fntype);
89652 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
89653 +
89654 + // insert call to void pax_check_alloca(unsigned long size)
89655 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
89656 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
89657 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
89658 +}
89659 +
89660 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
89661 +{
89662 + gimple track_stack;
89663 + tree fntype, fndecl;
89664 +
89665 + fntype = build_function_type_list(void_type_node, NULL_TREE);
89666 + fndecl = build_fn_decl(track_function, fntype);
89667 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
89668 +
89669 + // insert call to void pax_track_stack(void)
89670 + track_stack = gimple_build_call(fndecl, 0);
89671 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
89672 +}
89673 +
89674 +#if BUILDING_GCC_VERSION == 4005
89675 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
89676 +{
89677 + tree fndecl;
89678 +
89679 + if (!is_gimple_call(stmt))
89680 + return false;
89681 + fndecl = gimple_call_fndecl(stmt);
89682 + if (!fndecl)
89683 + return false;
89684 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
89685 + return false;
89686 +// print_node(stderr, "pax", fndecl, 4);
89687 + return DECL_FUNCTION_CODE(fndecl) == code;
89688 +}
89689 +#endif
89690 +
89691 +static bool is_alloca(gimple stmt)
89692 +{
89693 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
89694 + return true;
89695 +
89696 +#if BUILDING_GCC_VERSION >= 4007
89697 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
89698 + return true;
89699 +#endif
89700 +
89701 + return false;
89702 +}
89703 +
89704 +static unsigned int execute_stackleak_tree_instrument(void)
89705 +{
89706 + basic_block bb, entry_bb;
89707 + bool prologue_instrumented = false, is_leaf = true;
89708 +
89709 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
89710 +
89711 + // 1. loop through BBs and GIMPLE statements
89712 + FOR_EACH_BB(bb) {
89713 + gimple_stmt_iterator gsi;
89714 +
89715 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
89716 + gimple stmt;
89717 +
89718 + stmt = gsi_stmt(gsi);
89719 +
89720 + if (is_gimple_call(stmt))
89721 + is_leaf = false;
89722 +
89723 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
89724 + if (!is_alloca(stmt))
89725 + continue;
89726 +
89727 + // 2. insert stack overflow check before each __builtin_alloca call
89728 + stackleak_check_alloca(&gsi);
89729 +
89730 + // 3. insert track call after each __builtin_alloca call
89731 + stackleak_add_instrumentation(&gsi);
89732 + if (bb == entry_bb)
89733 + prologue_instrumented = true;
89734 + }
89735 + }
89736 +
89737 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
89738 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
89739 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
89740 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
89741 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
89742 + return 0;
89743 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
89744 + return 0;
89745 +
89746 + // 4. insert track call at the beginning
89747 + if (!prologue_instrumented) {
89748 + gimple_stmt_iterator gsi;
89749 +
89750 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
89751 + if (dom_info_available_p(CDI_DOMINATORS))
89752 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
89753 + gsi = gsi_start_bb(bb);
89754 + stackleak_add_instrumentation(&gsi);
89755 + }
89756 +
89757 + return 0;
89758 +}
89759 +
89760 +static unsigned int execute_stackleak_final(void)
89761 +{
89762 + rtx insn;
89763 +
89764 + if (cfun->calls_alloca)
89765 + return 0;
89766 +
89767 + // keep calls only if function frame is big enough
89768 + if (get_frame_size() >= track_frame_size)
89769 + return 0;
89770 +
89771 + // 1. find pax_track_stack calls
89772 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
89773 + // 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))
89774 + rtx body;
89775 +
89776 + if (!CALL_P(insn))
89777 + continue;
89778 + body = PATTERN(insn);
89779 + if (GET_CODE(body) != CALL)
89780 + continue;
89781 + body = XEXP(body, 0);
89782 + if (GET_CODE(body) != MEM)
89783 + continue;
89784 + body = XEXP(body, 0);
89785 + if (GET_CODE(body) != SYMBOL_REF)
89786 + continue;
89787 + if (strcmp(XSTR(body, 0), track_function))
89788 + continue;
89789 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
89790 + // 2. delete call
89791 + insn = delete_insn_and_edges(insn);
89792 +#if BUILDING_GCC_VERSION >= 4007
89793 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
89794 + insn = delete_insn_and_edges(insn);
89795 +#endif
89796 + }
89797 +
89798 +// print_simple_rtl(stderr, get_insns());
89799 +// print_rtl(stderr, get_insns());
89800 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
89801 +
89802 + return 0;
89803 +}
89804 +
89805 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
89806 +{
89807 + const char * const plugin_name = plugin_info->base_name;
89808 + const int argc = plugin_info->argc;
89809 + const struct plugin_argument * const argv = plugin_info->argv;
89810 + int i;
89811 + struct register_pass_info stackleak_tree_instrument_pass_info = {
89812 + .pass = &stackleak_tree_instrument_pass.pass,
89813 +// .reference_pass_name = "tree_profile",
89814 + .reference_pass_name = "optimized",
89815 + .ref_pass_instance_number = 1,
89816 + .pos_op = PASS_POS_INSERT_BEFORE
89817 + };
89818 + struct register_pass_info stackleak_final_pass_info = {
89819 + .pass = &stackleak_final_rtl_opt_pass.pass,
89820 + .reference_pass_name = "final",
89821 + .ref_pass_instance_number = 1,
89822 + .pos_op = PASS_POS_INSERT_BEFORE
89823 + };
89824 +
89825 + if (!plugin_default_version_check(version, &gcc_version)) {
89826 + error(G_("incompatible gcc/plugin versions"));
89827 + return 1;
89828 + }
89829 +
89830 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
89831 +
89832 + for (i = 0; i < argc; ++i) {
89833 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
89834 + if (!argv[i].value) {
89835 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
89836 + continue;
89837 + }
89838 + track_frame_size = atoi(argv[i].value);
89839 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
89840 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
89841 + continue;
89842 + }
89843 + if (!strcmp(argv[i].key, "initialize-locals")) {
89844 + if (argv[i].value) {
89845 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
89846 + continue;
89847 + }
89848 + init_locals = true;
89849 + continue;
89850 + }
89851 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
89852 + }
89853 +
89854 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
89855 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
89856 +
89857 + return 0;
89858 +}
89859 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
89860 index 6789d78..4afd019e 100644
89861 --- a/tools/perf/util/include/asm/alternative-asm.h
89862 +++ b/tools/perf/util/include/asm/alternative-asm.h
89863 @@ -5,4 +5,7 @@
89864
89865 #define altinstruction_entry #
89866
89867 + .macro pax_force_retaddr rip=0, reload=0
89868 + .endm
89869 +
89870 #endif
89871 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
89872 index d617f69..6b445d2 100644
89873 --- a/virt/kvm/kvm_main.c
89874 +++ b/virt/kvm/kvm_main.c
89875 @@ -75,7 +75,7 @@ LIST_HEAD(vm_list);
89876
89877 static cpumask_var_t cpus_hardware_enabled;
89878 static int kvm_usage_count = 0;
89879 -static atomic_t hardware_enable_failed;
89880 +static atomic_unchecked_t hardware_enable_failed;
89881
89882 struct kmem_cache *kvm_vcpu_cache;
89883 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
89884 @@ -715,7 +715,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
89885 /* We can read the guest memory with __xxx_user() later on. */
89886 if (user_alloc &&
89887 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
89888 - !access_ok(VERIFY_WRITE,
89889 + !__access_ok(VERIFY_WRITE,
89890 (void __user *)(unsigned long)mem->userspace_addr,
89891 mem->memory_size)))
89892 goto out;
89893 @@ -2304,7 +2304,7 @@ static void hardware_enable_nolock(void *junk)
89894
89895 if (r) {
89896 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
89897 - atomic_inc(&hardware_enable_failed);
89898 + atomic_inc_unchecked(&hardware_enable_failed);
89899 printk(KERN_INFO "kvm: enabling virtualization on "
89900 "CPU%d failed\n", cpu);
89901 }
89902 @@ -2358,10 +2358,10 @@ static int hardware_enable_all(void)
89903
89904 kvm_usage_count++;
89905 if (kvm_usage_count == 1) {
89906 - atomic_set(&hardware_enable_failed, 0);
89907 + atomic_set_unchecked(&hardware_enable_failed, 0);
89908 on_each_cpu(hardware_enable_nolock, NULL, 1);
89909
89910 - if (atomic_read(&hardware_enable_failed)) {
89911 + if (atomic_read_unchecked(&hardware_enable_failed)) {
89912 hardware_disable_all_nolock();
89913 r = -EBUSY;
89914 }
89915 @@ -2722,7 +2722,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
89916 kvm_arch_vcpu_put(vcpu);
89917 }
89918
89919 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
89920 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
89921 struct module *module)
89922 {
89923 int r;
89924 @@ -2785,7 +2785,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
89925 if (!vcpu_align)
89926 vcpu_align = __alignof__(struct kvm_vcpu);
89927 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
89928 - 0, NULL);
89929 + SLAB_USERCOPY, NULL);
89930 if (!kvm_vcpu_cache) {
89931 r = -ENOMEM;
89932 goto out_free_3;
89933 @@ -2795,9 +2795,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
89934 if (r)
89935 goto out_free;
89936
89937 - kvm_chardev_ops.owner = module;
89938 - kvm_vm_fops.owner = module;
89939 - kvm_vcpu_fops.owner = module;
89940 + pax_open_kernel();
89941 + *(void **)&kvm_chardev_ops.owner = module;
89942 + *(void **)&kvm_vm_fops.owner = module;
89943 + *(void **)&kvm_vcpu_fops.owner = module;
89944 + pax_close_kernel();
89945
89946 r = misc_register(&kvm_dev);
89947 if (r) {